FinanceRealFundMapper.xml 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.dayou.mapper.FinanceRealFundMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.dayou.entity.FinanceRealFund">
  6. <result column="id" property="id" />
  7. <result column="deleted" property="deleted" />
  8. <result column="modified" property="modified" />
  9. <result column="created" property="created" />
  10. <result column="payer" property="payer" />
  11. <result column="payer_bank" property="payerBank" />
  12. <result column="payer_account" property="payerAccount" />
  13. <result column="amount" property="amount" />
  14. <result column="pay_datetime" property="payDatetime" />
  15. <result column="remark" property="remark" />
  16. <result column="creator_id" property="creatorId" />
  17. </resultMap>
  18. <!-- 通用查询结果列 -->
  19. <sql id="Base_Column_List">
  20. id,
  21. deleted,
  22. modified,
  23. created,
  24. payer, payer_bank, payer_account, amount, pay_datetime, remark, creator_id
  25. </sql>
  26. <sql id="pageListSql">
  27. SELECT
  28. frf.id,
  29. frf.created,
  30. frf.payer,
  31. frf.payer_bank,
  32. frf.payer_account,
  33. frf.amount,
  34. frf.pay_datetime,
  35. frf.remark,
  36. frf.creator_id,
  37. u.name AS creator,
  38. ifnull(t.ca,0) AS claimAmount,
  39. ( frf.amount - ifnull(t.ca,0) ) AS notClaimAmount
  40. FROM
  41. finance_real_fund frf
  42. LEFT JOIN user u ON u.id = frf.creator_id
  43. LEFT JOIN ( SELECT real_fund_id, sum(ifnull(claim_amount,0)) ca FROM finance_claim WHERE deleted = 0 GROUP BY real_fund_id ) t ON t.real_fund_id = frf.id
  44. WHERE
  45. frf.deleted = 0
  46. <if test="vo!=null and vo.notFinished">
  47. and ifnull(t.ca,0) &lt; frf.amount
  48. </if>
  49. <if test="vo!=null and !vo.notFinished">
  50. and ifnull(t.ca,0) &gt;= frf.amount
  51. </if>
  52. <if test="keyword!=null and keyword!='' ">
  53. and (
  54. frf.payer like concat ('%',#{keyword},'%')
  55. or frf.payer_bank like concat('%',#{keyword},'%')
  56. or u.name like concat('%',#{keyword},'%')
  57. or frf.payer_account like concat('%',#{keyword},'%')
  58. or frf.amount like concat('%',#{keyword},'%')
  59. or frf.remark like concat('%',#{keyword},'%')
  60. )
  61. </if>
  62. <if test="vo!=null and vo.startDate!=null and vo.startDate!=''">
  63. and frf.pay_datetime &gt;= #{vo.startDate}
  64. </if>
  65. <if test="vo!=null and vo.endDate!=null and vo.endDate!=''">
  66. and frf.pay_datetime &lt;= #{vo.endDate}
  67. </if>
  68. <if test="vo!=null and vo.xStartDate!=null and vo.xStartDate!=''">
  69. and frf.created &gt;= #{vo.xStartDate}
  70. </if>
  71. <if test="vo!=null and vo.xEndDate!=null and vo.xEndDate!=''">
  72. and frf.created &lt;= #{vo.xEndDate}
  73. </if>
  74. </sql>
  75. <sql id="pageListSql1">
  76. SELECT
  77. #{userId} as userId,
  78. frf.id,
  79. frf.created,
  80. frf.payer,
  81. frf.payer_bank,
  82. frf.payer_account,
  83. frf.amount,
  84. frf.pay_datetime,
  85. frf.remark,
  86. frf.creator_id,
  87. u.name AS creator,
  88. ifnull(t.ca,0) AS claimAmount,
  89. ( frf.amount - ifnull(t.ca,0) ) AS notClaimAmount
  90. FROM
  91. finance_real_fund frf
  92. LEFT JOIN user u ON u.id = frf.creator_id
  93. LEFT JOIN ( SELECT real_fund_id, sum(ifnull(claim_amount,0)) ca FROM finance_claim WHERE deleted = 0 GROUP BY real_fund_id ) t ON t.real_fund_id = frf.id
  94. WHERE
  95. frf.deleted = 0
  96. <if test="vo!=null and vo.notFinished">
  97. and ifnull(t.ca,0) &lt; frf.amount
  98. </if>
  99. <if test="vo!=null and !vo.notFinished">
  100. and ifnull(t.ca,0) &gt;= frf.amount
  101. </if>
  102. <if test="keyword!=null and keyword!='' ">
  103. and (
  104. frf.payer like concat ('%',#{keyword},'%')
  105. or frf.payer_bank like concat('%',#{keyword},'%')
  106. or u.name like concat('%',#{keyword},'%')
  107. or frf.payer_account like concat('%',#{keyword},'%')
  108. or frf.amount like concat('%',#{keyword},'%')
  109. or frf.remark like concat('%',#{keyword},'%')
  110. )
  111. </if>
  112. <if test="vo!=null and vo.startDate!=null and vo.startDate!=''">
  113. and frf.pay_datetime &gt;= #{vo.startDate}
  114. </if>
  115. <if test="vo!=null and vo.endDate!=null and vo.endDate!=''">
  116. and frf.pay_datetime &lt;= #{vo.endDate}
  117. </if>
  118. <if test="vo!=null and vo.xStartDate!=null and vo.xStartDate!=''">
  119. and frf.created &gt;= #{vo.xStartDate}
  120. </if>
  121. <if test="vo!=null and vo.xEndDate!=null and vo.xEndDate!=''">
  122. and frf.created &lt;= #{vo.xEndDate}
  123. </if>
  124. ORDER BY
  125. ifnull(t.ca,0) ASC ,frf.created DESC
  126. </sql>
  127. <resultMap id="realAmountClaimMap" type="com.dayou.vo.FinanceRealFundVO">
  128. <result column="userId" property="userId" />
  129. <result column="id" property="id" />
  130. <result column="created" property="created" />
  131. <result column="payer" property="payer" />
  132. <result column="payer_bank" property="payerBank" />
  133. <result column="payer_account" property="payerAccount" />
  134. <result column="amount" property="amount" />
  135. <result column="pay_datetime" property="payDatetime" />
  136. <result column="remark" property="remark" />
  137. <result column="creator_id" property="creatorId" />
  138. <result column="creator" property="creator" />
  139. <result column="claimAmount" property="claimAmount" />
  140. <result column="notClaimAmount" property="notClaimAmount" />
  141. <collection property="recommends" select="findRecommends" ofType="java.lang.String" column="{amount=amount,userId=userId}" />
  142. </resultMap>
  143. <select id="getPage" parameterType="com.dayou.entity.FinanceRealFund" resultType="com.dayou.vo.FinanceRealFundVO">
  144. <include refid="pageListSql" />
  145. ORDER BY
  146. ifnull(t.ca,0) ASC ,frf.created DESC
  147. </select>
  148. <select id="claimPage" resultMap="realAmountClaimMap">
  149. SELECT
  150. #{userId} as userId,
  151. frf.id,
  152. frf.created,
  153. frf.payer,
  154. frf.payer_bank,
  155. frf.payer_account,
  156. frf.amount,
  157. frf.pay_datetime,
  158. frf.remark,
  159. frf.creator_id,
  160. u.name AS creator,
  161. ifnull(t.ca,0) AS claimAmount,
  162. ( frf.amount - ifnull(t.ca,0) ) AS notClaimAmount
  163. FROM
  164. finance_real_fund frf
  165. LEFT JOIN user u ON u.id = frf.creator_id
  166. LEFT JOIN ( SELECT real_fund_id, sum(ifnull(claim_amount,0)) ca FROM finance_claim WHERE deleted = 0 GROUP BY real_fund_id ) t ON t.real_fund_id = frf.id
  167. WHERE
  168. frf.deleted = 0
  169. <if test="vo!=null and vo.notFinished">
  170. and ifnull(t.ca,0) &lt; frf.amount
  171. </if>
  172. <if test="vo!=null and !vo.notFinished">
  173. and ifnull(t.ca,0) &gt;= frf.amount
  174. </if>
  175. <if test="keyword!=null and keyword!='' ">
  176. and (
  177. frf.payer like concat ('%',#{keyword},'%')
  178. or frf.payer_bank like concat('%',#{keyword},'%')
  179. or u.name like concat('%',#{keyword},'%')
  180. or frf.payer_account like concat('%',#{keyword},'%')
  181. or frf.amount like concat('%',#{keyword},'%')
  182. or frf.remark like concat('%',#{keyword},'%')
  183. )
  184. </if>
  185. <if test="vo!=null and vo.startDate!=null and vo.startDate!=''">
  186. and frf.pay_datetime &gt;= #{vo.startDate}
  187. </if>
  188. <if test="vo!=null and vo.endDate!=null and vo.endDate!=''">
  189. and frf.pay_datetime &lt;= #{vo.endDate}
  190. </if>
  191. <if test="vo!=null and vo.xStartDate!=null and vo.xStartDate!=''">
  192. and frf.created &gt;= #{vo.xStartDate}
  193. </if>
  194. <if test="vo!=null and vo.xEndDate!=null and vo.xEndDate!=''">
  195. and frf.created &lt;= #{vo.xEndDate}
  196. </if>
  197. ORDER BY
  198. frf.created DESC
  199. </select>
  200. <select id="findRecommends" resultType="java.lang.String">
  201. SELECT
  202. tt1.business_type
  203. FROM
  204. (
  205. SELECT
  206. order_fund.real_amount,
  207. order_fund.business_type,
  208. temp.invoiceAmount
  209. FROM
  210. (
  211. SELECT
  212. order_fund_id,
  213. sum( real_amount ) AS invoiceAmount
  214. FROM
  215. finance_invoice
  216. WHERE
  217. state = '已开票'
  218. AND deleted = 0
  219. AND production_fund_id IS NULL
  220. <if test="userId!=null">
  221. and apply_id = #{userId}
  222. </if>
  223. GROUP BY
  224. order_fund_id UNION ALL
  225. SELECT
  226. order_fund_id,
  227. sum( real_amount ) AS invoiceAmount
  228. FROM
  229. finance_invoice
  230. WHERE
  231. state = '已开票'
  232. AND deleted = 0
  233. AND production_fund_id IS NOT NULL
  234. <if test="userId!=null">
  235. and apply_id = #{userId}
  236. </if>
  237. GROUP BY
  238. production_fund_id
  239. ) temp
  240. LEFT JOIN order_fund ON order_fund.id = temp.order_fund_id
  241. ) tt1
  242. WHERE
  243. tt1.invoiceAmount = #{amount}
  244. AND tt1.real_amount IS NULL
  245. </select>
  246. <select id="getNotClaimAmount" parameterType="java.lang.Long" resultType="java.math.BigDecimal">
  247. SELECT ( frf.amount -( SELECT ifnull( sum( claim_amount ), 0 ) AS ca FROM finance_claim WHERE deleted = 0 AND real_fund_id = #{realFundId} )
  248. ) AS notClaimAmount
  249. FROM
  250. finance_real_fund frf
  251. WHERE
  252. frf.id = #{realFundId}
  253. AND frf.deleted = 0
  254. </select>
  255. <sql id="majorOverdueSql">
  256. SELECT
  257. DATEDIFF(
  258. CURDATE(),
  259. DATE( mp.repertory_out_time )) AS overdueDay,
  260. pf.production,
  261. m.allot_type,
  262. m.order_id,
  263. m.business_object_type,
  264. u.NAME AS clientManager,
  265. u1.NAME AS principal,
  266. cc1.NAME AS clientName,
  267. cc2.NAME AS clientSubName,
  268. pf.production_should_amount as shouldAmount,
  269. mp.*
  270. FROM
  271. ( SELECT business_id, production_no,
  272. ( CASE production_type WHEN 'STATEMENT' THEN '意见书' WHEN 'REPORT' THEN '报告' WHEN 'LETTER' THEN '复评函' ELSE '' END ) production,
  273. production_type
  274. , production_should_amount, real_amount FROM production_fund WHERE business_type = 'MAJOR_BUSINESS'
  275. AND deleted = 0 and production_should_amount is not null and production_should_amount!=0 and real_amount is null) pf
  276. inner join
  277. (
  278. SELECT
  279. id,
  280. major_id,
  281. report_no,
  282. production as productionType,
  283. NAME,
  284. evaluate_amount,
  285. repertory_out_time,
  286. standard_amount
  287. FROM
  288. major_production mp
  289. WHERE
  290. deleted = 0
  291. AND repertory_out_time IS NOT NULL
  292. ) mp
  293. ON ( mp.major_id = pf.business_id AND mp.report_no = pf.production_no and mp.productionType = pf.production_type )
  294. LEFT JOIN major m ON m.id = mp.major_id
  295. LEFT JOIN user u ON u.id = m.client_manager_id
  296. LEFT JOIN user u1 ON u1.id = m.principal_id
  297. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_id
  298. LEFT JOIN customer_company cc2 ON cc2.id = m.clientele_sub_id
  299. LEFT JOIN production_return AS `return` ON `return`.deleted = 0 AND business_type = 'MAJOR_BUSINESS' AND `return`.status = 'APPROVE' AND `return`.business_id = mp.major_id AND `return`.production_id = mp.id AND `return`.production_no = mp.report_no
  300. <where>
  301. and mp.repertory_out_time>'2024-01-01 00:00:00'
  302. # 退产品后超期也不预警,所以审核通过的退产品记录必须为null
  303. AND `return`.id IS NULL
  304. <if test="overdueVO!=null and overdueVO.overdueMin!=null">
  305. AND DATEDIFF(CURDATE(),DATE( mp.repertory_out_time )) >= #{overdueVO.overdueMin}
  306. </if>
  307. <if test="overdueVO!=null and overdueVO.overdueMax!=null">
  308. AND DATEDIFF(CURDATE(),DATE( mp.repertory_out_time )) &lt;= #{overdueVO.overdueMax}
  309. </if>
  310. <if test="overdueVO!=null and overdueVO.orderId!=null and overdueVO.orderId!=''">
  311. and m.order_id = #{overdueVO.orderId}
  312. </if>
  313. <if test="overdueVO!=null and overdueVO.reportNo!=null and overdueVO.reportNo!=''">
  314. and mp.report_no like concat ('%',#{overdueVO.reportNo},'%')
  315. </if>
  316. <if test="overdueVO!=null and overdueVO.principal!=null and overdueVO.principal!=''">
  317. and u1.NAME like concat ('%',#{overdueVO.principal},'%')
  318. </if>
  319. <if test="overdueVO!=null and overdueVO.userIds!=null and overdueVO.userIds.size!=0">
  320. and m.client_manager_id in
  321. <foreach collection="overdueVO.userIds" open="(" close=")" separator="," item="userId">
  322. #{userId}
  323. </foreach>
  324. </if>
  325. </where>
  326. order by overdueDay ASC
  327. </sql>
  328. <select id="overdueMajor" parameterType="com.dayou.vo.MajorProdOverdueVO" resultType="com.dayou.vo.MajorProdOverdueVO">
  329. <include refid="majorOverdueSql" />
  330. </select>
  331. <select id="overdueMajorExport" parameterType="com.dayou.vo.MajorProdOverdueVO" resultType="com.dayou.vo.MajorProdOverdueVO">
  332. <include refid="majorOverdueSql" />
  333. </select>
  334. <resultMap id="settleeMajorProductionVOMap" type="com.dayou.vo.SettleMajorProductionVO">
  335. <id property="id" column="id" />
  336. <result property="id" column="id" />
  337. <result property="claimAmount" column="claim_amount" />
  338. <result property="orderId" column="order_id" />
  339. <result property="reportNo" column="report_no" />
  340. <result property="claimDate" column="claimDate" />
  341. <result property="saveFileDate" column="save_file_date" />
  342. <result property="settleDate" column="settleDate" />
  343. <result property="deliveryDate" column="deliveryDate" />
  344. <result property="name" column="name" />
  345. <result property="bailor" column="bailor" />
  346. <result property="evaluateAmount" column="evaluate_amount" />
  347. <result property="principal" column="principal" />
  348. <result property="clientManager" column="clientManager" />
  349. <result property="clientName" column="clientName" />
  350. <result property="clientSubName" column="clientSubName" />
  351. <result property="evaluateDepartmentName" column="evaluateDepartmentName" />
  352. <result property="marketDepartmentName" column="marketDepartmentName" />
  353. <result property="payDateTime" column="pay_datetime" />
  354. <result property="members" column="members" />
  355. <!-- <collection property="invoices" ofType="com.dayou.vo.SettleProInvoiceVo">-->
  356. <!-- <result property="invoiceDate" column="invoiceDate" />-->
  357. <!-- <result property="invoiceUser" column="invoiceUser" />-->
  358. <!-- <result property="invoiceNo" column="invoiceNo" />-->
  359. <!-- </collection>-->
  360. </resultMap>
  361. <sql id="majorEvaluatorSettleSql">
  362. SELECT
  363. fc.id,
  364. fc.claim_amount,
  365. m.order_id,
  366. mp.report_no,
  367. fc.claim_datetime as claimDate,
  368. mp.save_file_date,
  369. IF
  370. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  371. mp.name,
  372. m.bailor,
  373. m.members,
  374. mp.evaluate_amount,
  375. u.name AS principal,
  376. u1.name AS clientManager,
  377. cc.name AS clientName,
  378. cc1.name AS clientSubName,
  379. d.name AS evaluateDepartmentName,
  380. (
  381. SELECT
  382. GROUP_CONCAT( name )
  383. FROM
  384. department
  385. WHERE
  386. id IN (
  387. SELECT
  388. department_id
  389. FROM
  390. post
  391. WHERE
  392. id IN ( SELECT post_id FROM user_post WHERE user_id = m.client_manager_id ))) AS marketDepartmentName,
  393. frf.pay_datetime
  394. FROM
  395. (
  396. SELECT
  397. id,
  398. claim_amount,
  399. order_fund_id,
  400. production_fund_id,
  401. claim_datetime,
  402. real_fund_id
  403. FROM
  404. finance_claim
  405. WHERE
  406. deleted = 0
  407. AND production_fund_id IS NOT NULL
  408. ) fc
  409. INNER JOIN ( SELECT id, pay_datetime FROM finance_real_fund WHERE deleted = 0
  410. <if test="settleVO!=null and settleVO.payStartDate!=null and settleVO.payStartDate!='' ">
  411. AND pay_datetime &gt;= #{settleVO.payStartDate}
  412. </if>
  413. <if test="settleVO!=null and settleVO.payEndDate!=null and settleVO.payEndDate!='' ">
  414. AND pay_datetime &lt;= #{settleVO.payEndDate}
  415. </if>
  416. ) frf ON frf.id = fc.real_fund_id
  417. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no ,production_type FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  418. INNER JOIN (
  419. SELECT
  420. id,
  421. major_id,
  422. NAME,
  423. report_no,
  424. production,
  425. evaluate_amount,
  426. save_file_date,
  427. fund.real_amount
  428. FROM
  429. major_production mpr
  430. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  431. WHERE
  432. fund.real_amount IS NOT NULL
  433. AND mpr.save_file_date IS NOT NULL
  434. ) mp ON (mp.report_no = pf.production_no and mp.major_id = pf.business_id and mp.production = pf.production_type)
  435. LEFT JOIN major m ON m.id = mp.major_id
  436. LEFT JOIN user u ON u.id = m.principal_id
  437. LEFT JOIN user u1 ON u1.id = m.client_manager_id
  438. LEFT JOIN customer_company cc ON cc.id = m.clientele_id
  439. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_sub_id
  440. LEFT JOIN department d ON d.id = m.department_id
  441. <where>
  442. m.financial is not null
  443. <if test="keyword!=null and keyword!='' ">
  444. and (
  445. mp.report_no like concat ('%',#{keyword},'%')
  446. or fc.claim_amount =#{keyword}
  447. or m.order_id like concat('%',#{keyword},'%')
  448. or u.name like concat('%',#{keyword},'%')
  449. or u1.name like concat('%',#{keyword},'%')
  450. )
  451. </if>
  452. <if test="settleVO!=null and settleVO.startDate!=null and settleVO.startDate!='' ">
  453. AND (select IF
  454. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date )) &gt;= #{settleVO.startDate}
  455. </if>
  456. <if test="settleVO!=null and settleVO.endDate!=null and settleVO.endDate!='' ">
  457. AND (select IF
  458. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date )) &lt;= #{settleVO.endDate}
  459. </if>
  460. <if test="settleVO!=null and settleVO.evaluateDepartmentName!=null and settleVO.evaluateDepartmentName!=''">
  461. and d.name = #{settleVO.evaluateDepartmentName}
  462. </if>
  463. </where>
  464. order by fc.claim_datetime ASC
  465. </sql>
  466. <select id="majorEvaluatorSettleProd" parameterType="com.dayou.vo.SettleMajorProductionVO" resultMap="settleeMajorProductionVOMap">
  467. <include refid="majorEvaluatorSettleSql" />
  468. </select>
  469. <select id="majorEvaluatorSettleExport" parameterType="com.dayou.vo.SettleMajorProductionVO" resultMap="settleeMajorProductionVOMap">
  470. <include refid="majorEvaluatorSettleSql" />
  471. </select>
  472. <sql id="majorMarketerSettleSql">
  473. SELECT
  474. fc.id,
  475. fc.claim_amount,
  476. m.order_id,
  477. mp.report_no,
  478. fc.claim_datetime AS claimDate,
  479. mp.delivery_date AS deliveryDate,
  480. IF
  481. ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date ) AS settleDate,
  482. mp.NAME,
  483. m.bailor,
  484. m.members,
  485. mp.evaluate_amount,
  486. u.NAME AS principal,
  487. u1.NAME AS clientManager,
  488. cc.NAME AS clientName,
  489. cc1.NAME AS clientSubName,
  490. d.NAME AS evaluateDepartmentName,
  491. (
  492. SELECT
  493. GROUP_CONCAT( NAME )
  494. FROM
  495. department
  496. WHERE
  497. id IN (
  498. SELECT
  499. department_id
  500. FROM
  501. post
  502. WHERE
  503. id IN ( SELECT post_id FROM user_post WHERE user_id = m.client_manager_id and deleted = 0 ))) AS marketDepartmentName,
  504. frf.pay_datetime
  505. FROM
  506. (
  507. SELECT
  508. id,
  509. claim_amount,
  510. order_fund_id,
  511. production_fund_id,
  512. claim_datetime,
  513. real_fund_id
  514. FROM
  515. finance_claim
  516. WHERE
  517. deleted = 0
  518. AND production_fund_id IS NOT NULL
  519. ) fc
  520. INNER JOIN ( SELECT id, pay_datetime FROM finance_real_fund WHERE deleted = 0
  521. <if test="settleVO!=null and settleVO.payStartDate!=null and settleVO.payStartDate!='' ">
  522. AND pay_datetime &gt;= #{settleVO.payStartDate}
  523. </if>
  524. <if test="settleVO!=null and settleVO.payEndDate!=null and settleVO.payEndDate!='' ">
  525. AND pay_datetime &lt;= #{settleVO.payEndDate}
  526. </if>
  527. ) frf ON frf.id = fc.real_fund_id
  528. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no ,production_type FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  529. INNER JOIN (
  530. SELECT
  531. id,
  532. major_id,
  533. NAME,
  534. report_no,
  535. production,
  536. evaluate_amount,
  537. delivery_date,
  538. fund.real_amount
  539. FROM
  540. major_production mpr
  541. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  542. WHERE
  543. fund.real_amount IS NOT NULL
  544. AND mpr.delivery_date IS NOT NULL
  545. ) mp ON (mp.report_no = pf.production_no and mp.major_id = pf.business_id and mp.production = pf.production_type )
  546. LEFT JOIN major m ON m.id = mp.major_id
  547. LEFT JOIN user u ON u.id = m.principal_id
  548. LEFT JOIN user u1 ON u1.id = m.client_manager_id
  549. LEFT JOIN customer_company cc ON cc.id = m.clientele_id
  550. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_sub_id
  551. LEFT JOIN department d ON d.id = m.department_id
  552. <where>
  553. m.financial is not null
  554. <if test="keyword!=null and keyword!='' ">
  555. and (
  556. mp.report_no like concat ('%',#{keyword},'%')
  557. or fc.claim_amount =#{keyword}
  558. or m.order_id like concat('%',#{keyword},'%')
  559. or u.name like concat('%',#{keyword},'%')
  560. or u1.name like concat('%',#{keyword},'%')
  561. )
  562. </if>
  563. <if test="settleVO!=null and settleVO.startDate!=null and settleVO.startDate!='' ">
  564. AND (select IF
  565. ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date )) &gt;= #{settleVO.startDate}
  566. </if>
  567. <if test="settleVO!=null and settleVO.endDate!=null and settleVO.endDate!='' ">
  568. AND (select IF
  569. ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date )) &lt;= #{settleVO.endDate}
  570. </if>
  571. </where>
  572. order by fc.claim_datetime ASC
  573. </sql>
  574. <select id="majorMarketerSettleProd" parameterType="com.dayou.vo.SettleMajorProductionVO" resultMap="settleeMajorProductionVOMap">
  575. <include refid="majorMarketerSettleSql" />
  576. </select>
  577. <select id="majorMarketSettleExport" parameterType="com.dayou.vo.SettleMajorProductionVO" resultMap="settleeMajorProductionVOMap">
  578. <include refid="majorMarketerSettleSql" />
  579. </select>
  580. <select id="majorEvaluatorCommission" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  581. SELECT mpa.user_id as id, u.name as userName, sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )) AS commissionTotalAmount
  582. FROM
  583. (
  584. SELECT
  585. claim_amount,
  586. order_fund_id,
  587. production_fund_id,
  588. claim_datetime
  589. FROM
  590. finance_claim
  591. WHERE
  592. deleted = 0
  593. AND production_fund_id IS NOT NULL
  594. ) fc
  595. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  596. INNER JOIN (
  597. SELECT
  598. id,
  599. major_id,
  600. NAME,
  601. report_no,
  602. production,
  603. evaluate_amount,
  604. save_file_date,
  605. fund.real_amount
  606. FROM
  607. major_production mpr
  608. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  609. WHERE
  610. fund.real_amount IS NOT NULL
  611. AND mpr.save_file_date IS NOT NULL
  612. ) mp ON mp.report_no = pf.production_no
  613. LEFT JOIN (select * from major where financial is not null) m ON m.id = mp.major_id
  614. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  615. cd.business_id = m.id
  616. AND cd.production_id = mp.id )
  617. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  618. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  619. LEFT JOIN ( SELECT major_id, major_production_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'EVALUATE'
  620. ) mpa ON ( mpa.major_id = m.id AND mpa.major_production_id = mp.id)
  621. LEFT JOIN user u ON u.id = mpa.user_id
  622. <where>
  623. (select IF
  624. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date )) &gt;= #{vo.startDate}
  625. AND (select IF
  626. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date )) &lt;= #{vo.endDate}
  627. <if test="vo!=null and vo.userIds!=null and vo.userIds.size!=0">
  628. and mpa.user_id in
  629. <foreach collection="vo.userIds" open="(" close=")" separator="," item="userId">
  630. #{userId}
  631. </foreach>
  632. </if>
  633. </where>
  634. GROUP BY
  635. mpa.user_id
  636. having 1=1
  637. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  638. and u.name like concat ('%',#{vo.userName},'%')
  639. </if>
  640. order by commissionTotalAmount DESC
  641. </select>
  642. <select id="majorEvaluatorCommissionDetail" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  643. SELECT
  644. mp.id,
  645. fc.claim_amount as realAmount,
  646. mp.report_no,
  647. IF
  648. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  649. mp.NAME,
  650. mp.created,
  651. dd.NAME AS businessCate,
  652. bcr.min_ratio AS ratio,
  653. mpa.user_id,
  654. mpa.ratio AS allotRatio,
  655. ( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ) AS commissionAmount,
  656. ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
  657. u.name as userName
  658. FROM
  659. (
  660. SELECT
  661. claim_amount,
  662. order_fund_id,
  663. production_fund_id,
  664. claim_datetime
  665. FROM
  666. finance_claim
  667. WHERE
  668. deleted = 0
  669. AND production_fund_id IS NOT NULL
  670. ) fc
  671. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no,production_type FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  672. INNER JOIN (
  673. SELECT
  674. id,
  675. major_id,
  676. NAME,
  677. report_no,
  678. production,
  679. evaluate_amount,
  680. save_file_date,
  681. fund.real_amount,
  682. created
  683. FROM
  684. major_production mpr
  685. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  686. WHERE
  687. fund.real_amount IS NOT NULL
  688. AND mpr.save_file_date IS NOT NULL
  689. ) mp ON (mp.report_no = pf.production_no and mp.production = pf.production_type)
  690. LEFT JOIN major m ON m.id = mp.major_id
  691. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  692. cd.business_id = m.id
  693. AND cd.production_id = mp.id )
  694. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  695. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  696. LEFT JOIN ( SELECT major_id, major_production_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'EVALUATE' ) mpa ON ( mpa.major_id = m.id AND mpa.major_production_id = mp.id)
  697. LEFT JOIN user u on u.id = mpa.user_id
  698. WHERE
  699. m.financial is not null and
  700. mpa.user_id = #{vo.userId} and
  701. (select IF
  702. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date )) &gt;= #{vo.startDate}
  703. AND (select IF
  704. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date )) &lt;= #{vo.endDate}
  705. order by settleDate DESC
  706. </select>
  707. <select id="majorEvaluatorTotalAmountExport" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  708. SELECT mpa.user_id as id, u.name as userName, ROUND(sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )),2) AS commissionTotalAmount,
  709. '评估人员' as userType,
  710. '大中型业务' as businessType,
  711. #{vo.startDate} as startDate,
  712. #{vo.endDate} as endDate
  713. FROM
  714. (
  715. SELECT
  716. claim_amount,
  717. order_fund_id,
  718. production_fund_id,
  719. claim_datetime
  720. FROM
  721. finance_claim
  722. WHERE
  723. deleted = 0
  724. AND production_fund_id IS NOT NULL
  725. AND claim_datetime &gt;= #{vo.startDate}
  726. AND claim_datetime &lt;= #{vo.endDate}
  727. ) fc
  728. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  729. INNER JOIN (
  730. SELECT
  731. id,
  732. major_id,
  733. NAME,
  734. report_no,
  735. production,
  736. evaluate_amount,
  737. save_file_date,
  738. fund.real_amount
  739. FROM
  740. major_production mpr
  741. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  742. WHERE
  743. fund.real_amount IS NOT NULL
  744. AND mpr.save_file_date IS NOT NULL
  745. ) mp ON mp.report_no = pf.production_no
  746. LEFT JOIN major m ON m.id = mp.major_id
  747. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  748. cd.business_id = m.id
  749. AND cd.production_id = mp.id )
  750. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  751. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  752. LEFT JOIN ( SELECT major_id, major_production_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'EVALUATE'
  753. ) mpa ON ( mpa.major_id = m.id AND mpa.major_production_id = mp.id)
  754. LEFT JOIN user u ON u.id = mpa.user_id
  755. GROUP BY
  756. mpa.user_id
  757. </select>
  758. <select id="evaluatorUserDetailExport" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  759. SELECT
  760. mp.id,
  761. ROUND(fc.claim_amount,2) as realAmount,
  762. mp.report_no,
  763. IF
  764. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  765. mp.NAME,
  766. mp.created,
  767. dd.NAME AS businessCate,
  768. ROUND(bcr.min_ratio,2) AS ratio,
  769. mpa.user_id,
  770. ROUND(mpa.ratio*100,2) AS allotRatio,
  771. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ),2) AS commissionAmount,
  772. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) ),2) AS totalAmount,
  773. u.name as userName
  774. FROM
  775. (
  776. SELECT
  777. claim_amount,
  778. order_fund_id,
  779. production_fund_id,
  780. claim_datetime
  781. FROM
  782. finance_claim
  783. WHERE
  784. deleted = 0
  785. AND production_fund_id IS NOT NULL
  786. AND claim_datetime &gt;= #{vo.startDate}
  787. AND claim_datetime &lt;= #{vo.endDate}
  788. ) fc
  789. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  790. INNER JOIN (
  791. SELECT
  792. id,
  793. major_id,
  794. NAME,
  795. report_no,
  796. production,
  797. evaluate_amount,
  798. save_file_date,
  799. fund.real_amount,
  800. created
  801. FROM
  802. major_production mpr
  803. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  804. WHERE
  805. fund.real_amount IS NOT NULL
  806. AND mpr.save_file_date IS NOT NULL
  807. ) mp ON mp.report_no = pf.production_no
  808. LEFT JOIN major m ON m.id = mp.major_id
  809. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  810. cd.business_id = m.id
  811. AND cd.production_id = mp.id )
  812. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  813. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  814. LEFT JOIN ( SELECT major_id, major_production_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'EVALUATE' ) mpa ON ( mpa.major_id = m.id AND mpa.major_production_id = mp.id)
  815. LEFT JOIN user u on u.id = mpa.user_id
  816. <where>
  817. <if test="vo!=null and vo.userId!=null">
  818. and mpa.user_id = #{vo.userId}
  819. </if>
  820. </where>
  821. order by mpa.user_id
  822. </select>
  823. <select id="majorMarketCommission" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  824. SELECT mpa.user_id as id, u.name as userName, sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )) AS commissionTotalAmount
  825. FROM
  826. (
  827. SELECT
  828. claim_amount,
  829. order_fund_id,
  830. production_fund_id,
  831. claim_datetime
  832. FROM
  833. finance_claim
  834. WHERE
  835. deleted = 0
  836. AND production_fund_id IS NOT NULL
  837. ) fc
  838. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  839. INNER JOIN (
  840. SELECT
  841. id,
  842. major_id,
  843. NAME,
  844. report_no,
  845. production,
  846. evaluate_amount,
  847. delivery_date,
  848. fund.real_amount
  849. FROM
  850. major_production mpr
  851. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  852. WHERE
  853. fund.real_amount IS NOT NULL
  854. AND mpr.delivery_date IS NOT NULL
  855. ) mp ON mp.report_no = pf.production_no
  856. LEFT JOIN (select * from major where financial is not null) m ON m.id = mp.major_id
  857. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  858. cd.business_id = m.id
  859. AND cd.production_id = mp.id )
  860. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  861. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  862. LEFT JOIN ( SELECT major_id, major_production_id,declare_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'MARKET'
  863. ) mpa ON ( mpa.major_id = m.id AND cd.id = mpa.declare_id AND (mpa.major_production_id is null or mpa.major_production_id = mp.id ))
  864. LEFT JOIN user u ON u.id = mpa.user_id
  865. <where>
  866. (select IF
  867. ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date )) &gt;= #{vo.startDate}
  868. AND (select IF
  869. ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date )) &lt;= #{vo.endDate}
  870. <if test="vo!=null and vo.userIds!=null and vo.userIds.size!=0">
  871. and mpa.user_id in
  872. <foreach collection="vo.userIds" open="(" close=")" separator="," item="userId">
  873. #{userId}
  874. </foreach>
  875. </if>
  876. </where>
  877. GROUP BY
  878. mpa.user_id
  879. having 1=1
  880. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  881. and u.name like concat ('%',#{vo.userName},'%')
  882. </if>
  883. order by commissionTotalAmount DESC
  884. </select>
  885. <select id="majorMarketCommissionDetail" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  886. SELECT
  887. mp.id,
  888. fc.claim_amount as realAmount,
  889. mp.report_no,
  890. IF
  891. ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date ) AS settleDate,
  892. mp.NAME,
  893. mp.created,
  894. dd.NAME AS businessCate,
  895. bcr.min_ratio AS ratio,
  896. mpa.user_id,
  897. mpa.ratio AS allotRatio,
  898. ( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ) AS commissionAmount,
  899. ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
  900. u.name as userName
  901. FROM
  902. (
  903. SELECT
  904. claim_amount,
  905. order_fund_id,
  906. production_fund_id,
  907. claim_datetime
  908. FROM
  909. finance_claim
  910. WHERE
  911. deleted = 0
  912. AND production_fund_id IS NOT NULL
  913. ) fc
  914. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no,production_type FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  915. INNER JOIN (
  916. SELECT
  917. id,
  918. major_id,
  919. NAME,
  920. report_no,
  921. production,
  922. evaluate_amount,
  923. delivery_date,
  924. fund.real_amount,
  925. created
  926. FROM
  927. major_production mpr
  928. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  929. WHERE
  930. fund.real_amount IS NOT NULL
  931. AND mpr.delivery_date IS NOT NULL
  932. ) mp ON (mp.report_no = pf.production_no and mp.production = pf.production_type)
  933. LEFT JOIN major m ON m.id = mp.major_id
  934. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  935. cd.business_id = m.id
  936. AND cd.production_id = mp.id )
  937. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  938. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  939. LEFT JOIN ( SELECT major_id, major_production_id, user_id, ratio,declare_id FROM major_production_allot WHERE deleted = 0 AND user_type = 'MARKET' ) mpa ON ( mpa.major_id = m.id AND cd.id = mpa.declare_id AND (mpa.major_production_id is null or mpa.major_production_id = mp.id ))
  940. LEFT JOIN user u on u.id = mpa.user_id
  941. WHERE
  942. m.financial is not null and
  943. mpa.user_id = #{vo.userId} and
  944. (select IF
  945. ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date )) &gt;= #{vo.startDate}
  946. AND (select IF
  947. ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date )) &lt;= #{vo.endDate}
  948. order by settleDate DESC
  949. </select>
  950. <select id="majorMarketTotalAmountExport" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  951. SELECT mpa.user_id as id, u.name as userName, ROUND(sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )),2) AS commissionTotalAmount,
  952. '市场人员' as userType,
  953. '大中型业务' as businessType,
  954. #{vo.startDate} as startDate,
  955. #{vo.endDate} as endDate
  956. FROM
  957. (
  958. SELECT
  959. claim_amount,
  960. order_fund_id,
  961. production_fund_id,
  962. claim_datetime
  963. FROM
  964. finance_claim
  965. WHERE
  966. deleted = 0
  967. AND production_fund_id IS NOT NULL
  968. AND claim_datetime &gt;= #{vo.startDate}
  969. AND claim_datetime &lt;= #{vo.endDate}
  970. ) fc
  971. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  972. INNER JOIN (
  973. SELECT
  974. id,
  975. major_id,
  976. NAME,
  977. report_no,
  978. production,
  979. evaluate_amount,
  980. delivery_date,
  981. fund.real_amount
  982. FROM
  983. major_production mpr
  984. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  985. WHERE
  986. fund.real_amount IS NOT NULL
  987. AND mpr.delivery_date IS NOT NULL
  988. ) mp ON mp.report_no = pf.production_no
  989. LEFT JOIN major m ON m.id = mp.major_id
  990. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  991. cd.business_id = m.id
  992. AND cd.production_id = mp.id )
  993. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  994. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  995. LEFT JOIN ( SELECT major_id, major_production_id,declare_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'MARKET'
  996. ) mpa ON ( mpa.major_id = m.id AND cd.id = mpa.declare_id AND (mpa.major_production_id is null or mpa.major_production_id = mp.id ))
  997. LEFT JOIN user u ON u.id = mpa.user_id
  998. GROUP BY
  999. mpa.user_id
  1000. order by commissionTotalAmount DESC
  1001. </select>
  1002. <select id="marketUserDetailExport" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  1003. SELECT
  1004. mp.id,
  1005. ROUND(fc.claim_amount,2) as realAmount,
  1006. mp.report_no,
  1007. IF
  1008. ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date ) AS settleDate,
  1009. mp.NAME,
  1010. mp.created,
  1011. dd.NAME AS businessCate,
  1012. ROUND(bcr.min_ratio,2) AS ratio,
  1013. mpa.user_id,
  1014. ROUND(mpa.ratio*100,2) AS allotRatio,
  1015. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ),2) AS commissionAmount,
  1016. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) ),2) AS totalAmount,
  1017. u.name as userName
  1018. FROM
  1019. (
  1020. SELECT
  1021. claim_amount,
  1022. order_fund_id,
  1023. production_fund_id,
  1024. claim_datetime
  1025. FROM
  1026. finance_claim
  1027. WHERE
  1028. deleted = 0
  1029. AND production_fund_id IS NOT NULL
  1030. AND claim_datetime &gt;= #{vo.startDate}
  1031. AND claim_datetime &lt;= #{vo.endDate}
  1032. ) fc
  1033. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  1034. INNER JOIN (
  1035. SELECT
  1036. id,
  1037. major_id,
  1038. NAME,
  1039. report_no,
  1040. production,
  1041. evaluate_amount,
  1042. delivery_date,
  1043. fund.real_amount,
  1044. created
  1045. FROM
  1046. major_production mpr
  1047. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  1048. WHERE
  1049. fund.real_amount IS NOT NULL
  1050. AND mpr.delivery_date IS NOT NULL
  1051. ) mp ON mp.report_no = pf.production_no
  1052. LEFT JOIN major m ON m.id = mp.major_id
  1053. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1054. cd.business_id = m.id
  1055. AND cd.production_id = mp.id )
  1056. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1057. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1058. LEFT JOIN ( SELECT major_id, major_production_id, user_id, ratio,declare_id FROM major_production_allot WHERE deleted = 0 AND user_type = 'MARKET' ) mpa ON ( mpa.major_id = m.id AND cd.id = mpa.declare_id AND (mpa.major_production_id is null or mpa.major_production_id = mp.id ))
  1059. LEFT JOIN user u on u.id = mpa.user_id
  1060. <where>
  1061. <if test="vo!=null and vo.userId!=null">
  1062. and mpa.user_id = #{vo.userId}
  1063. </if>
  1064. </where>
  1065. order by mpa.user_id
  1066. </select>
  1067. <sql id="personalOverdueSql">
  1068. SELECT
  1069. DATEDIFF(
  1070. CURDATE(),
  1071. DATE ( pp.rot )) AS overdueDay,
  1072. p.*,
  1073. pt.acreage,
  1074. pt.price,
  1075. pt.amount,
  1076. cc1.NAME AS clientName,
  1077. cc2.NAME AS clientSubName,
  1078. cl1.NAME AS contactName,
  1079. cl1.mobile AS contactTel,
  1080. u.NAME AS clientManager,
  1081. u1.NAME AS outwardStaffName,
  1082. u2.NAME AS inwardStaffName,
  1083. u3.NAME AS pricingStaffName,
  1084. pp.rot
  1085. FROM
  1086. (
  1087. SELECT
  1088. id,
  1089. location,
  1090. order_id,
  1091. agent,
  1092. bailorA,
  1093. bailorB,
  1094. clientele_id,
  1095. clientele_sub_id,
  1096. clientele_contact_id,
  1097. client_manager_id,
  1098. outward_staff,
  1099. inward_staff,
  1100. pricing_staff
  1101. FROM
  1102. personal
  1103. WHERE
  1104. deleted = 0
  1105. ) p
  1106. inner JOIN personal_target pt ON pt.personal_id = p.id
  1107. inner JOIN ( SELECT business_id, should_amount, real_amount FROM order_fund WHERE business_type = 'PERSONAL_BUSINESS' AND deleted = 0 AND real_amount IS NULL ) ofu ON ofu.business_id = p.id
  1108. inner JOIN ( SELECT target_id,( repertory_out_time ) rot FROM personal_production WHERE repertory_out_time IS NOT NULL GROUP BY target_id ) pp ON pp.target_id = pt.id
  1109. LEFT JOIN customer_company cc1 ON cc1.id = p.clientele_id
  1110. LEFT JOIN customer_company cc2 ON cc2.id = p.clientele_sub_id
  1111. LEFT JOIN customer_linkman cl1 ON cl1.id = p.clientele_contact_id
  1112. LEFT JOIN `user` u ON u.id = p.client_manager_id
  1113. LEFT JOIN `user` u1 ON u1.id = p.outward_staff
  1114. LEFT JOIN `user` u2 ON u2.id = p.inward_staff
  1115. LEFT JOIN `user` u3 ON u3.id = p.pricing_staff
  1116. LEFT JOIN production_return AS `return` ON `return`.deleted = 0 AND business_type = 'PERSONAL_BUSINESS' AND `return`.status = 'APPROVE' AND `return`.business_id = p.id AND `return`.production_id IS NULL
  1117. <where>
  1118. AND pp.rot>'2024-01-01 00:00:00'
  1119. AND `return`.id IS NULL
  1120. <if test="overdueVO!=null and overdueVO.overdueMin!=null">
  1121. AND DATEDIFF(CURDATE(),DATE ( pp.rot )) >= #{overdueVO.overdueMin}
  1122. </if>
  1123. <if test="overdueVO!=null and overdueVO.overdueMax!=null">
  1124. AND DATEDIFF(CURDATE(),DATE( pp.rot )) &lt;= #{overdueVO.overdueMax}
  1125. </if>
  1126. <if test="overdueVO!=null and overdueVO.orderId!=null and overdueVO.orderId!=''">
  1127. and p.order_id = #{overdueVO.orderId}
  1128. </if>
  1129. <if test="overdueVO!=null and overdueVO.userIds!=null and overdueVO.userIds.size!=0">
  1130. and p.client_manager_id in
  1131. <foreach collection="overdueVO.userIds" open="(" close=")" separator="," item="userId">
  1132. #{userId}
  1133. </foreach>
  1134. </if>
  1135. </where>
  1136. ORDER BY
  1137. overdueDay ASC
  1138. </sql>
  1139. <select id="overduePersonal" parameterType="com.dayou.vo.PersonalOverdueVO" resultType="com.dayou.vo.PersonalOverdueVO">
  1140. <include refid="personalOverdueSql" />
  1141. </select>
  1142. <select id="overduePersonalList" parameterType="com.dayou.vo.PersonalOverdueVO" resultType="com.dayou.vo.PersonalOverdueVO">
  1143. <include refid="personalOverdueSql" />
  1144. </select>
  1145. <!--资产评估人员提成计算-->
  1146. <select id="assetsEvaluatorCommission" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  1147. SELECT bpd.member_id as id,
  1148. u.name as userName,
  1149. SUM(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1150. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  1151. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  1152. )) AS allCommissionTotalAmount,
  1153. SUM(IF(ap.save_file_date IS NOT NULL, (IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1154. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  1155. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  1156. )), 0)) AS commissionTotalAmount
  1157. FROM
  1158. (
  1159. SELECT
  1160. claim_amount,
  1161. order_fund_id,
  1162. production_fund_id,
  1163. claim_datetime
  1164. FROM
  1165. finance_claim
  1166. WHERE
  1167. deleted = 0
  1168. AND production_fund_id IS NOT NULL
  1169. AND claim_datetime &gt;= #{vo.startDate}
  1170. AND claim_datetime &lt;= #{vo.endDate}
  1171. UNION ALL
  1172. SELECT
  1173. allot_amount AS claim_amount,
  1174. order_fund_id,
  1175. production_fund_id,
  1176. created AS claim_datetime
  1177. FROM
  1178. order_fund_allot
  1179. WHERE
  1180. deleted = 0
  1181. AND created &gt;= #{vo.startDate}
  1182. AND created &lt;= #{vo.endDate}
  1183. ) fc
  1184. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type =
  1185. 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id
  1186. )
  1187. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, save_file_date, created FROM
  1188. assets_production
  1189. WHERE deleted = 0) ap ON ap.production_no = pf.production_no
  1190. LEFT JOIN assets a ON a.id = ap.business_id
  1191. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id, ratio, defined_low_limit_amount FROM
  1192. commission_declare WHERE
  1193. business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1194. cd.business_id = a.id
  1195. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1196. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1197. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1198. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution FROM
  1199. business_performance_distribution WHERE deleted = 0
  1200. AND user_type = '评估人员'
  1201. ) bpd ON ( bpd.business_id = a.id AND bpd.report_no = ap.production_no)
  1202. LEFT JOIN user u ON u.id = bpd.member_id
  1203. GROUP BY
  1204. bpd.member_id
  1205. having 1=1
  1206. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  1207. and u.name like concat ('%',#{vo.userName},'%')
  1208. </if>
  1209. order by commissionTotalAmount DESC
  1210. </select>
  1211. <!--资产评估人员提成计算详情-->
  1212. <select id="assetsEvaluatorCommissionDetail" resultType="com.dayou.vo.UserCommissionProdAssetsVO">
  1213. SELECT
  1214. ap.id,
  1215. fc.claim_amount as realAmount,
  1216. ap.production_no AS reportNo,
  1217. IF
  1218. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1219. ap.assets_name AS name,
  1220. ap.created,
  1221. dd.name AS businessCate,
  1222. IFNULL(cd.ratio,bcr.min_ratio) AS ratio,
  1223. cd.defined_low_limit_amount AS lowLimitAmount,
  1224. bpd.member_id,
  1225. bpd.performance_distribution AS allotRatio,
  1226. IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1227. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  1228. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  1229. ) AS commissionAmount,
  1230. IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1231. fc.claim_amount * (cd.ratio / 100),
  1232. cd.defined_low_limit_amount * (cd.ratio / 100)
  1233. ) AS totalAmount,
  1234. u.name AS userName,
  1235. pf.modified AS realFundDateTime
  1236. FROM
  1237. (
  1238. SELECT
  1239. claim_amount,
  1240. order_fund_id,
  1241. production_fund_id,
  1242. claim_datetime
  1243. FROM
  1244. finance_claim
  1245. WHERE
  1246. deleted = 0
  1247. AND production_fund_id IS NOT NULL
  1248. AND claim_datetime &gt;= #{vo.startDate}
  1249. AND claim_datetime &lt;= #{vo.endDate}
  1250. UNION ALL
  1251. SELECT
  1252. allot_amount AS claim_amount,
  1253. order_fund_id,
  1254. production_fund_id,
  1255. created AS claim_datetime
  1256. FROM
  1257. order_fund_allot
  1258. WHERE
  1259. deleted = 0
  1260. AND created &gt;= #{vo.startDate}
  1261. AND created &lt;= #{vo.endDate}
  1262. ) fc
  1263. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no,modified FROM production_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  1264. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, save_file_date, created FROM assets_production WHERE deleted = 0) ap ON ap.production_no = pf.production_no
  1265. LEFT JOIN assets a ON a.id = ap.business_id
  1266. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id, ratio,defined_low_limit_amount FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1267. cd.business_id = a.id
  1268. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1269. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1270. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1271. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution FROM business_performance_distribution WHERE deleted = 0 AND user_type = '评估人员' ) bpd ON ( bpd.business_id = a.id AND bpd.report_no = ap.production_no)
  1272. LEFT JOIN user u on u.id = bpd.member_id
  1273. WHERE
  1274. bpd.member_id = #{vo.userId}
  1275. order by settleDate DESC
  1276. </select>
  1277. <!--资产评估人员合计导出-->
  1278. <select id="assetsEvaluatorTotalAmountExport" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  1279. SELECT bpd.member_id as id,
  1280. u.name as userName,
  1281. ROUND(SUM(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1282. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  1283. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  1284. )), 2) AS allCommissionTotalAmount,
  1285. ROUND(SUM(IF(ap.save_file_date IS NOT NULL, (IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1286. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  1287. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  1288. )), 0)), 2) AS commissionTotalAmount,
  1289. '评估人员' as userType,
  1290. '资产业务' as businessType,
  1291. #{vo.startDate} as startDate,
  1292. #{vo.endDate} as endDate
  1293. FROM (SELECT claim_amount,
  1294. order_fund_id,
  1295. production_fund_id,
  1296. claim_datetime
  1297. FROM finance_claim
  1298. WHERE deleted = 0
  1299. AND production_fund_id IS NOT NULL
  1300. AND claim_datetime &gt;= #{vo.startDate}
  1301. AND claim_datetime &lt;= #{vo.endDate}
  1302. UNION ALL
  1303. SELECT allot_amount AS claim_amount,
  1304. order_fund_id,
  1305. production_fund_id,
  1306. created AS claim_datetime
  1307. FROM order_fund_allot
  1308. WHERE deleted = 0
  1309. AND created &gt;= #{vo.startDate}
  1310. AND created &lt;= #{vo.endDate}) fc
  1311. INNER JOIN (SELECT id, order_fund_id, business_id, production_no
  1312. FROM production_fund
  1313. WHERE business_type = 'ASSET_BUSINESS'
  1314. AND deleted = 0) pf
  1315. ON (pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id)
  1316. INNER JOIN (SELECT id,
  1317. business_id,
  1318. assets_name,
  1319. production_no,
  1320. production_type,
  1321. save_file_date,
  1322. created
  1323. FROM assets_production
  1324. WHERE deleted = 0) ap ON ap.production_no = pf.production_no
  1325. LEFT JOIN assets a ON a.id = ap.business_id
  1326. INNER JOIN (SELECT id, business_id, production_id, commission_rate_id, defined_low_limit_amount, ratio
  1327. FROM commission_declare
  1328. WHERE business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE'
  1329. AND deleted = 0
  1330. AND declare_result = '审核通过') cd ON (
  1331. cd.business_id = a.id
  1332. AND (cd.production_id IS NULL OR cd.production_id = ap.id))
  1333. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1334. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1335. LEFT JOIN (SELECT business_id, report_no, member_id, performance_distribution
  1336. FROM business_performance_distribution
  1337. WHERE deleted = 0
  1338. AND user_type = '评估人员') bpd
  1339. ON (bpd.business_id = a.id AND bpd.report_no = ap.production_no)
  1340. LEFT JOIN user u ON u.id = bpd.member_id
  1341. GROUP BY bpd.member_id
  1342. </select>
  1343. <!--资产评估人员提成信息导出-->
  1344. <select id="assetsEvaluatorUserDetailExport" resultType="com.dayou.vo.UserCommissionProdAssetsVO">
  1345. SELECT
  1346. ap.id,
  1347. ROUND(fc.claim_amount,2) as realAmount,
  1348. ap.production_no AS reportNo,
  1349. IF
  1350. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1351. ap.assets_name AS name,
  1352. ap.created,
  1353. dd.NAME AS businessCate,
  1354. IFNULL(cd.ratio,bcr.min_ratio) AS ratio,
  1355. cd.defined_low_limit_amount AS lowLimitAmount,
  1356. ROUND(bcr.min_ratio,2) AS ratio,
  1357. bpd.member_id AS userId,
  1358. ROUND(bpd.performance_distribution,2) AS allotRatio,
  1359. ROUND(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1360. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  1361. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  1362. ),2) AS commissionAmount,
  1363. ROUND(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1364. fc.claim_amount * (cd.ratio / 100),
  1365. cd.defined_low_limit_amount * (cd.ratio / 100)
  1366. ),2) AS totalAmount,
  1367. u.name as userName,
  1368. pf.modified AS realFundDateTime
  1369. FROM
  1370. (
  1371. SELECT
  1372. claim_amount,
  1373. order_fund_id,
  1374. production_fund_id,
  1375. claim_datetime
  1376. FROM
  1377. finance_claim
  1378. WHERE
  1379. deleted = 0
  1380. AND production_fund_id IS NOT NULL
  1381. AND claim_datetime &gt;= #{vo.startDate}
  1382. AND claim_datetime &lt;= #{vo.endDate}
  1383. UNION ALL
  1384. SELECT
  1385. allot_amount AS claim_amount,
  1386. order_fund_id,
  1387. production_fund_id,
  1388. created AS claim_datetime
  1389. FROM
  1390. order_fund_allot
  1391. WHERE
  1392. deleted = 0
  1393. AND created &gt;= #{vo.startDate}
  1394. AND created &lt;= #{vo.endDate}
  1395. ) fc
  1396. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no,modified FROM production_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  1397. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, save_file_date, created FROM assets_production WHERE deleted = 0 ) ap ON ap.production_no = pf.production_no
  1398. LEFT JOIN assets a ON a.id = ap.business_id
  1399. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id, ratio, defined_low_limit_amount FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1400. cd.business_id = a.id
  1401. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1402. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1403. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1404. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution FROM business_performance_distribution WHERE deleted = 0 AND user_type = '评估人员' ) bpd ON ( bpd.business_id = a.id AND bpd.report_no = ap.production_no)
  1405. LEFT JOIN user u on u.id = bpd.member_id
  1406. <where>
  1407. <if test="vo!=null and vo.userId!=null">
  1408. and bpd.member_id = #{vo.userId}
  1409. </if>
  1410. </where>
  1411. order by bpd.member_id
  1412. </select>
  1413. <!--资产市场人员提成计算-->
  1414. <select id="assetsMarketCommission" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  1415. SELECT bpd.member_id as id,
  1416. u.name as userName,
  1417. SUM(( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100))) AS commissionTotalAmount
  1418. FROM
  1419. (
  1420. SELECT
  1421. claim_amount,
  1422. order_fund_id,
  1423. production_fund_id,
  1424. claim_datetime
  1425. FROM
  1426. finance_claim
  1427. WHERE
  1428. deleted = 0
  1429. AND production_fund_id IS NOT NULL
  1430. AND claim_datetime &gt;= #{vo.startDate}
  1431. AND claim_datetime &lt;= #{vo.endDate}
  1432. UNION ALL SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime FROM order_fund_allot WHERE deleted = 0
  1433. AND created &gt;= #{vo.startDate}
  1434. AND created &lt;= #{vo.endDate}
  1435. ) fc
  1436. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  1437. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, save_file_date, created FROM assets_production WHERE deleted = 0 AND delivery = TRUE ) ap ON ap.production_no = pf.production_no
  1438. LEFT JOIN assets a ON a.id = ap.business_id
  1439. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_ASSET_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1440. cd.business_id = a.id
  1441. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1442. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1443. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1444. LEFT JOIN ( SELECT business_id, report_no,declare_id, member_id, performance_distribution FROM business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员'
  1445. ) bpd ON ( bpd.business_id = a.id AND cd.id = bpd.declare_id AND (bpd.report_no is null or bpd.report_no = ap.production_no ))
  1446. LEFT JOIN user u ON u.id = bpd.member_id
  1447. GROUP BY
  1448. bpd.member_id
  1449. having 1=1
  1450. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  1451. and u.name like concat ('%',#{vo.userName},'%')
  1452. </if>
  1453. order by commissionTotalAmount DESC
  1454. </select>
  1455. <!--资产市场人员提成计算详情-->
  1456. <select id="assetsMarketCommissionDetail" resultType="com.dayou.vo.UserCommissionProdVO">
  1457. SELECT
  1458. ap.id,
  1459. fc.claim_amount as realAmount,
  1460. ap.production_no AS reportNo,
  1461. IF
  1462. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1463. ap.assets_name AS name,
  1464. ap.created,
  1465. dd.NAME AS businessCate,
  1466. bcr.min_ratio AS ratio,
  1467. bpd.member_id AS userId,
  1468. bpd.performance_distribution AS allotRatio,
  1469. ( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100) ) AS commissionAmount,
  1470. ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
  1471. u.name as userName
  1472. FROM
  1473. (
  1474. SELECT
  1475. claim_amount,
  1476. order_fund_id,
  1477. production_fund_id,
  1478. claim_datetime
  1479. FROM
  1480. finance_claim
  1481. WHERE
  1482. deleted = 0
  1483. AND production_fund_id IS NOT NULL
  1484. AND claim_datetime &gt;= #{vo.startDate}
  1485. AND claim_datetime &lt;= #{vo.endDate}
  1486. UNION ALL
  1487. SELECT
  1488. allot_amount AS claim_amount,
  1489. order_fund_id,
  1490. production_fund_id,
  1491. created AS claim_datetime
  1492. FROM
  1493. order_fund_allot
  1494. WHERE
  1495. deleted = 0
  1496. AND created &gt;= #{vo.startDate}
  1497. AND created &lt;= #{vo.endDate}
  1498. ) fc
  1499. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  1500. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, save_file_date, created FROM assets_production WHERE deleted = 0 AND delivery = TRUE ) ap ON ap.production_no = pf.production_no
  1501. LEFT JOIN assets a ON a.id = ap.business_id
  1502. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_ASSET_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1503. cd.business_id = a.id
  1504. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1505. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1506. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1507. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution,declare_id FROM business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员' ) bpd
  1508. ON ( bpd.business_id = a.id AND cd.id = bpd.declare_id AND (bpd.report_no is null or bpd.report_no = ap.production_no ))
  1509. LEFT JOIN user u on u.id = bpd.member_id
  1510. WHERE
  1511. bpd.member_id = #{vo.userId}
  1512. order by settleDate DESC
  1513. </select>
  1514. <!--资产市场人员提成合计导出-->
  1515. <select id="assetsMarketTotalAmountExport" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  1516. SELECT bpd.member_id as id,
  1517. u.name as userName,
  1518. ROUND(SUM((fc.claim_amount * (bcr.min_ratio / 100) * (bpd.performance_distribution / 100))),
  1519. 2) AS commissionTotalAmount,
  1520. '市场人员' as userType,
  1521. '资产业务' as businessType,
  1522. #{vo.startDate} as startDate,
  1523. #{vo.endDate} as endDate
  1524. FROM (SELECT claim_amount,
  1525. order_fund_id,
  1526. production_fund_id,
  1527. claim_datetime
  1528. FROM finance_claim
  1529. WHERE deleted = 0
  1530. AND production_fund_id IS NOT NULL
  1531. AND claim_datetime &gt;= #{vo.startDate}
  1532. AND claim_datetime &lt;= #{vo.endDate}
  1533. UNION ALL
  1534. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime
  1535. FROM order_fund_allot
  1536. WHERE deleted = 0
  1537. AND created &gt;= #{vo.startDate}
  1538. AND created &lt;= #{vo.endDate}) fc
  1539. INNER JOIN (SELECT id, order_fund_id, business_id, production_no
  1540. FROM production_fund
  1541. WHERE business_type = 'ASSET_BUSINESS'
  1542. AND deleted = 0) pf
  1543. ON (pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id)
  1544. INNER JOIN (SELECT id,
  1545. business_id,
  1546. assets_name,
  1547. production_no,
  1548. production_type,
  1549. save_file_date,
  1550. created
  1551. FROM assets_production
  1552. WHERE deleted = 0
  1553. AND delivery = true) ap ON ap.production_no = pf.production_no
  1554. LEFT JOIN assets a ON a.id = ap.business_id
  1555. INNER JOIN (SELECT id, business_id, production_id, commission_rate_id
  1556. FROM commission_declare
  1557. WHERE business_type = 'COMMISSION_DECLARE_ASSET_MARKET'
  1558. AND deleted = 0
  1559. AND declare_result = '审核通过') cd ON (
  1560. cd.business_id = a.id
  1561. AND (cd.production_id IS NULL OR cd.production_id = ap.id))
  1562. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1563. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1564. LEFT JOIN (SELECT business_id, report_no, declare_id, member_id, performance_distribution
  1565. FROM business_performance_distribution
  1566. WHERE deleted = 0
  1567. AND user_type = '市场人员') bpd ON (bpd.business_id = a.id AND cd.id = bpd.declare_id AND
  1568. (bpd.report_no is null or bpd.report_no = ap.production_no))
  1569. LEFT JOIN user u ON u.id = bpd.member_id
  1570. GROUP BY bpd.member_id
  1571. ORDER BY commissionTotalAmount DESC
  1572. </select>
  1573. <!--资产市场人员提成信息导出-->
  1574. <select id="assetsMarketUserDetailExport" resultType="com.dayou.vo.UserCommissionProdVO">
  1575. SELECT
  1576. ap.id,
  1577. ROUND(fc.claim_amount,2) as realAmount,
  1578. ap.production_no AS reportNo,
  1579. IF
  1580. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1581. ap.assets_name AS name,
  1582. ap.created,
  1583. dd.`name` AS businessCate,
  1584. ROUND(bcr.min_ratio,2) AS ratio,
  1585. bpd.member_id AS userId,
  1586. ROUND(bpd.performance_distribution,2) AS allotRatio,
  1587. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100) ),2) AS
  1588. commissionAmount,
  1589. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) ),2) AS totalAmount,
  1590. u.name as userName
  1591. FROM
  1592. (
  1593. SELECT
  1594. claim_amount,
  1595. order_fund_id,
  1596. production_fund_id,
  1597. claim_datetime
  1598. FROM
  1599. finance_claim
  1600. WHERE
  1601. deleted = 0
  1602. AND production_fund_id IS NOT NULL
  1603. AND claim_datetime &gt;= #{vo.startDate}
  1604. AND claim_datetime &lt;= #{vo.endDate}
  1605. UNION ALL
  1606. SELECT
  1607. allot_amount AS claim_amount,
  1608. order_fund_id,
  1609. production_fund_id,
  1610. created AS claim_datetime
  1611. FROM
  1612. order_fund_allot
  1613. WHERE
  1614. deleted = 0
  1615. AND created &gt;= #{vo.startDate}
  1616. AND created &lt;= #{vo.endDate}
  1617. ) fc
  1618. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type =
  1619. 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id
  1620. )
  1621. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, save_file_date, created FROM
  1622. assets_production WHERE deleted = 0 AND delivery = true ) ap ON ap.production_no = pf.production_no
  1623. LEFT JOIN assets a ON a.id = ap.business_id
  1624. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE
  1625. business_type = 'COMMISSION_DECLARE_ASSET_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1626. cd.business_id = a.id
  1627. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1628. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1629. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1630. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution, declare_id FROM
  1631. business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员' ) bpd
  1632. ON ( bpd.business_id = a.id AND cd.id = bpd.declare_id AND (bpd.report_no is null or bpd.report_no =
  1633. ap.production_no ))
  1634. LEFT JOIN user u on u.id = bpd.member_id
  1635. <where>
  1636. <if test="vo!=null and vo.userId!=null">
  1637. and bpd.member_id = #{vo.userId}
  1638. </if>
  1639. </where>
  1640. order by bpd.member_id
  1641. </select>
  1642. <!--资产收款逾期查询Sql-->
  1643. <sql id="assetsOverdueSql">
  1644. SELECT
  1645. DATEDIFF(CURDATE(), DATE( ap.repertory_out_time )) AS overdueDay,
  1646. a.allot_type,
  1647. a.order_id,
  1648. a.assets_business_gener,
  1649. u.name AS clientManager,
  1650. u1.name AS principal,
  1651. cc1.name AS clientName,
  1652. cc2.name AS clientSubName,
  1653. pf.production_should_amount,
  1654. `of`.should_amount,
  1655. pf.standard_amount,
  1656. a.name as projectName,
  1657. ap.*
  1658. FROM
  1659. (
  1660. SELECT
  1661. id,
  1662. business_id,
  1663. production_no,
  1664. ( CASE production_type WHEN 'STATEMENT' THEN '意见书' WHEN 'REPORT' THEN '评估报告' WHEN 'LETTER' THEN '意见函' WHEN 'CONSULT' THEN '咨询报告' ELSE '' END ) productionType,
  1665. evaluate_amount,
  1666. repertory_out_time
  1667. FROM
  1668. assets_production ap
  1669. WHERE
  1670. deleted = 0
  1671. AND repertory_out_time IS NOT NULL
  1672. AND production_type != 'STATEMENT'
  1673. ) ap
  1674. LEFT JOIN ( SELECT id, business_id, production_no, production_should_amount, real_amount, standard_amount FROM production_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) pf
  1675. ON ( ap.business_id = pf.business_id AND ap.production_no = pf.production_no )
  1676. LEFT JOIN ( SELECT id, business_id,should_amount FROM order_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) `of` ON `of`.business_id = ap.business_id
  1677. LEFT JOIN assets a ON a.id = ap.business_id
  1678. LEFT JOIN user u ON u.id = a.client_manager_id
  1679. LEFT JOIN user u1 ON u1.id = a.principal_id
  1680. LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_id
  1681. LEFT JOIN customer_company cc2 ON cc2.id = a.clientele_sub_id
  1682. LEFT JOIN production_return AS `return` ON `return`.deleted = 0 AND business_type = 'ASSET_BUSINESS' AND `return`.status = 'APPROVE' AND `return`.business_id = ap.business_id AND `return`.production_id = ap.id AND `return`.production_no = ap.production_no
  1683. WHERE
  1684. ap.productionType != 'STATEMENT'
  1685. AND ( pf.production_no IS NULL OR pf.real_amount IS NULL )
  1686. # 退产品后超期也不预警,所以审核通过的退产品记录必须为null
  1687. AND `return`.id IS NULL
  1688. and ap.repertory_out_time>'2024-01-01 00:00:00'
  1689. <if test="overdueVO!=null and overdueVO.overdueMin!=null">
  1690. AND DATEDIFF(CURDATE(),DATE( ap.repertory_out_time )) &gt;= #{overdueVO.overdueMin}
  1691. </if>
  1692. <if test="overdueVO!=null and overdueVO.overdueMax!=null">
  1693. AND DATEDIFF(CURDATE(),DATE( ap.repertory_out_time )) &lt;= #{overdueVO.overdueMax}
  1694. </if>
  1695. <if test="overdueVO!=null and overdueVO.orderId!=null and overdueVO.orderId!=''">
  1696. and a.order_id = #{overdueVO.orderId}
  1697. </if>
  1698. <if test="overdueVO!=null and overdueVO.productionNo!=null and overdueVO.productionNo!=''">
  1699. and ap.production_no like concat ('%',#{overdueVO.productionNo},'%')
  1700. </if>
  1701. <if test="overdueVO!=null and overdueVO.principal!=null and overdueVO.principal!=''">
  1702. and u1.name like concat ('%',#{overdueVO.principal},'%')
  1703. </if>
  1704. <if test="overdueVO!=null and overdueVO.userIds!=null and overdueVO.userIds.size!=0">
  1705. and a.client_manager_id in
  1706. <foreach collection="overdueVO.userIds" open="(" close=")" separator="," item="userId">
  1707. #{userId}
  1708. </foreach>
  1709. </if>
  1710. order by overdueDay asc
  1711. </sql>
  1712. <!--资产收款逾期列表-->
  1713. <select id="overdueAssets" resultType="com.dayou.vo.AssetsProdOverdueVO">
  1714. <include refid="assetsOverdueSql" />
  1715. </select>
  1716. <!--资产收款逾期列表导出-->
  1717. <select id="overdueAssetsExport" resultType="com.dayou.vo.AssetsProdOverdueVO">
  1718. <include refid="assetsOverdueSql" />
  1719. </select>
  1720. <resultMap id="settleAssetsProductionVOMap" type="com.dayou.vo.SettleAssetsProductionVO">
  1721. <id property="id" column="id" />
  1722. <result property="id" column="id" />
  1723. <result property="claimAmount" column="claim_amount" />
  1724. <result property="orderId" column="order_id" />
  1725. <result property="projectName" column="name" />
  1726. <result property="productionNo" column="production_no" />
  1727. <result property="claimDate" column="claimDate" />
  1728. <result property="saveFileDate" column="save_file_date" />
  1729. <result property="settleDate" column="settleDate" />
  1730. <result property="deliveryDate" column="deliveryDate" />
  1731. <result property="projectName" column="projectName" />
  1732. <result property="bailor" column="bailor" />
  1733. <result property="evaluateAmount" column="evaluate_amount" />
  1734. <result property="principal" column="principal" />
  1735. <result property="clientManager" column="clientManager" />
  1736. <result property="clientName" column="clientName" />
  1737. <result property="clientSubName" column="clientSubName" />
  1738. <result property="evaluateDepartmentName" column="evaluateDepartmentName" />
  1739. <result property="marketDepartmentName" column="marketDepartmentName" />
  1740. <result property="payDateTime" column="pay_datetime" />
  1741. <result property="members" column="members" />
  1742. <collection property="invoices" ofType="com.dayou.vo.SettleProInvoiceVo">
  1743. <result property="invoiceDate" column="invoiceDate" />
  1744. <result property="invoiceUser" column="invoiceUser" />
  1745. <result property="invoiceNo" column="invoiceNo" />
  1746. </collection>
  1747. </resultMap>
  1748. <!--资产市场人员结算项目Sql-->
  1749. <sql id="assetsMarketerSettleSql">
  1750. SELECT
  1751. fc.id,
  1752. fc.claim_amount,
  1753. a.order_id,
  1754. ap.production_no,
  1755. fc.claim_datetime AS claimDate,
  1756. ap.delivery_date AS deliveryDate,
  1757. ap.save_file_date,
  1758. IF
  1759. ( fc.claim_datetime > ap.delivery_date, fc.claim_datetime, ap.delivery_date ) AS settleDate,
  1760. ap.assets_name AS projectName,
  1761. a.bailor,
  1762. a.name,
  1763. a.members,
  1764. ap.evaluate_amount,
  1765. u.NAME AS principal,
  1766. u1.NAME AS clientManager,
  1767. cc.NAME AS clientName,
  1768. cc1.NAME AS clientSubName,
  1769. d.NAME AS evaluateDepartmentName,
  1770. (
  1771. SELECT
  1772. GROUP_CONCAT( department.NAME )
  1773. FROM
  1774. department
  1775. WHERE
  1776. id IN (
  1777. SELECT
  1778. department_id
  1779. FROM
  1780. post
  1781. WHERE
  1782. id IN ( SELECT post_id FROM user_post WHERE user_id = a.client_manager_id ))) AS marketDepartmentName,
  1783. invoice.NAME AS invoiceUser,
  1784. invoice.real_make_date AS invoiceDate,
  1785. invoice.tax_no AS invoiceNo,
  1786. frf.pay_datetime
  1787. FROM
  1788. (
  1789. SELECT
  1790. id,
  1791. claim_amount,
  1792. order_fund_id,
  1793. production_fund_id,
  1794. claim_datetime,
  1795. real_fund_id
  1796. FROM
  1797. finance_claim
  1798. WHERE
  1799. deleted = 0
  1800. AND production_fund_id IS NOT NULL
  1801. ) fc
  1802. inner join (
  1803. select id,pay_datetime from finance_real_fund
  1804. where deleted = 0
  1805. <if test="settleVO!=null and settleVO.payStartDate!=null and settleVO.payStartDate!='' ">
  1806. AND pay_datetime &gt;= #{settleVO.payStartDate}
  1807. </if>
  1808. <if test="settleVO!=null and settleVO.payEndDate!=null and settleVO.payEndDate!='' ">
  1809. AND pay_datetime &lt;= #{settleVO.payEndDate}
  1810. </if>
  1811. ) frf on frf.id = fc.real_fund_id
  1812. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type =
  1813. 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id
  1814. )
  1815. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, evaluate_amount,
  1816. delivery_date, save_file_date FROM assets_production WHERE deleted = 0 AND delivery = true ) ap ON ap.production_no =
  1817. pf.production_no
  1818. LEFT JOIN assets a ON a.id = ap.business_id
  1819. LEFT JOIN user u ON u.id = a.principal_id
  1820. LEFT JOIN user u1 ON u1.id = a.client_manager_id
  1821. LEFT JOIN customer_company cc ON cc.id = a.clientele_id
  1822. LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_sub_id
  1823. LEFT JOIN department d ON d.id = a.department_id
  1824. LEFT JOIN (
  1825. SELECT real_make_date, name, tax_no, order_fund_id, production_fund_id
  1826. FROM finance_invoice, user
  1827. WHERE maker_id = user.id
  1828. AND finance_invoice.deleted = 0
  1829. AND state = '已开票' order by user.created desc limit 1
  1830. ) AS invoice ON IF(invoice.production_fund_id IS NOT NULL ,invoice.order_fund_id = pf.order_fund_id AND invoice.production_fund_id = pf.id,invoice.order_fund_id = pf.order_fund_id)
  1831. <where>
  1832. IF( fc.claim_datetime > ap.delivery_date, fc.claim_datetime, ap.delivery_date ) &gt;= #{settleVO.startDate}
  1833. AND IF( fc.claim_datetime > ap.delivery_date, fc.claim_datetime, ap.delivery_date ) &lt;= #{settleVO.endDate}
  1834. <if test="keyword!=null and keyword!='' ">
  1835. and (
  1836. a.order_id = #{keyword}
  1837. or ap.production_no like concat ('%',#{keyword},'%')
  1838. or u.name like concat ('%',#{keyword},'%')
  1839. or u1.name like concat ('%',#{keyword},'%')
  1840. )
  1841. </if>
  1842. </where>
  1843. order by fc.claim_datetime ASC
  1844. </sql>
  1845. <!--资产结算项目查询-->
  1846. <select id="assetsMarketSettleProd" resultMap="settleAssetsProductionVOMap">
  1847. <include refid="assetsMarketerSettleSql" />
  1848. </select>
  1849. <!--资产结算项目导出-->
  1850. <select id="assetsMarketSettleExport" resultMap="settleAssetsProductionVOMap">
  1851. <include refid="assetsMarketerSettleSql" />
  1852. </select>
  1853. <!--资产评估人员结算项目Sql-->
  1854. <sql id="assetsEvaluatorSettleSql">
  1855. SELECT
  1856. fc.id,
  1857. fc.claim_amount,
  1858. a.order_id,
  1859. ap.production_no,
  1860. fc.claim_datetime as claimDate,
  1861. ap.save_file_date,
  1862. IF( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1863. IF(ap.assets_name IS NOT NULL, ap.assets_name, a.name ) AS projectName,
  1864. a.bailor,
  1865. a.members,
  1866. ap.evaluate_amount,
  1867. u.name AS principal,
  1868. u1.name AS clientManager,
  1869. cc.name AS clientName,
  1870. cc1.name AS clientSubName,
  1871. d.name AS evaluateDepartmentName,
  1872. (
  1873. SELECT
  1874. GROUP_CONCAT( NAME )
  1875. FROM
  1876. department
  1877. WHERE
  1878. id IN (
  1879. SELECT
  1880. department_id
  1881. FROM
  1882. post
  1883. WHERE
  1884. id IN ( SELECT post_id FROM user_post WHERE user_id = a.client_manager_id ))) AS marketDepartmentName,
  1885. invoice.name AS invoiceUser,
  1886. invoice.real_make_date AS invoiceDate,
  1887. invoice.tax_no AS invoiceNo,
  1888. frf.pay_datetime
  1889. FROM
  1890. (
  1891. SELECT
  1892. id,
  1893. claim_amount,
  1894. order_fund_id,
  1895. production_fund_id,
  1896. claim_datetime,
  1897. real_fund_id
  1898. FROM
  1899. finance_claim
  1900. WHERE
  1901. deleted = 0
  1902. AND production_fund_id IS NOT NULL
  1903. ) fc
  1904. inner join (
  1905. select id,pay_datetime from finance_real_fund
  1906. where deleted = 0
  1907. <if test="settleVO!=null and settleVO.payStartDate!=null and settleVO.payStartDate!='' ">
  1908. AND pay_datetime &gt;= #{settleVO.payStartDate}
  1909. </if>
  1910. <if test="settleVO!=null and settleVO.payEndDate!=null and settleVO.payEndDate!='' ">
  1911. AND pay_datetime &lt;= #{settleVO.payEndDate}
  1912. </if>
  1913. ) frf on frf.id = fc.real_fund_id
  1914. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  1915. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, evaluate_amount, save_file_date FROM assets_production WHERE deleted = 0 AND save_file_date IS NOT NULL ) ap ON ap.production_no = pf.production_no
  1916. LEFT JOIN assets a ON a.id = ap.business_id
  1917. LEFT JOIN user u ON u.id = a.principal_id
  1918. LEFT JOIN user u1 ON u1.id = a.client_manager_id
  1919. LEFT JOIN customer_company cc ON cc.id = a.clientele_id
  1920. LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_sub_id
  1921. LEFT JOIN department d ON d.id = a.department_id
  1922. LEFT JOIN (
  1923. SELECT real_make_date, name, tax_no, order_fund_id, production_fund_id
  1924. FROM finance_invoice, user
  1925. WHERE maker_id = user.id
  1926. AND finance_invoice.deleted = 0
  1927. AND state = '已开票' order by user.created desc limit 1
  1928. ) AS invoice ON IF(invoice.production_fund_id IS NOT NULL ,invoice.order_fund_id = pf.order_fund_id AND invoice.production_fund_id = pf.id,invoice.order_fund_id = pf.order_fund_id)
  1929. <where>
  1930. AND IF( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) &gt;= #{settleVO.startDate}
  1931. AND IF( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) &lt;= #{settleVO.endDate}
  1932. <if test="keyword!=null and keyword!='' ">
  1933. and (
  1934. a.order_id = #{keyword}
  1935. or ap.production_no like concat ('%',#{keyword},'%')
  1936. or u.name like concat ('%',#{keyword},'%')
  1937. or u1.name like concat ('%',#{keyword},'%')
  1938. )
  1939. </if>
  1940. </where>
  1941. order by fc.claim_datetime ASC
  1942. </sql>
  1943. <!--资产评估人员结算项目查询-->
  1944. <select id="assetsEvaluatorSettleProd" resultMap="settleAssetsProductionVOMap">
  1945. <include refid="assetsEvaluatorSettleSql" />
  1946. </select>
  1947. <!--资产评估人员结算项目导出-->
  1948. <select id="assetsEvaluatorSettleExport" resultMap="settleAssetsProductionVOMap">
  1949. <include refid="assetsEvaluatorSettleSql" />
  1950. </select>
  1951. <select id="exportList" parameterType="com.dayou.entity.FinanceRealFund" resultType="com.dayou.dto.FinanceRealFundExportDTO">
  1952. <include refid="pageListSql" />
  1953. ORDER BY frf.pay_datetime DESC
  1954. </select>
  1955. <sql id="realAmountClaimedSQL">
  1956. SELECT
  1957. claimd.id,
  1958. fr.amount,
  1959. fr.payer,
  1960. fr.pay_datetime,
  1961. fr.remark,
  1962. claimd.claimAmount,
  1963. claimd.claimDate,
  1964. u.NAME AS creator,
  1965. u1.NAME AS claimUser,
  1966. (fr.amount-claimd.claimAmount) as notClaimAmount
  1967. FROM
  1968. (
  1969. SELECT
  1970. frf.id,
  1971. sum( fc.claim_amount ) claimAmount,
  1972. max( fc.claim_datetime ) claimDate,
  1973. fc.claim_user_id
  1974. FROM
  1975. finance_claim fc
  1976. LEFT JOIN finance_real_fund frf ON frf.id = fc.real_fund_id
  1977. WHERE
  1978. frf.deleted = 0
  1979. AND fc.deleted = 0
  1980. GROUP BY
  1981. frf.id
  1982. ) claimd
  1983. LEFT JOIN finance_real_fund fr ON fr.id = claimd.id
  1984. LEFT JOIN user u ON u.id = fr.creator_id
  1985. LEFT JOIN user u1 ON u1.id = claimd.claim_user_id
  1986. <where>
  1987. <if test="keyword!=null and keyword!='' ">
  1988. and (
  1989. fr.payer like concat ('%',#{keyword},'%')
  1990. or u1.name like concat('%',#{keyword},'%')
  1991. or claimd.claimAmount = #{keyword}
  1992. or fr.amount = #{keyword}
  1993. or fr.remark like concat('%',#{keyword},'%')
  1994. )
  1995. </if>
  1996. <if test="vo!=null and vo.startDate!=null and vo.startDate!=''">
  1997. and fr.pay_datetime &gt;= #{vo.startDate}
  1998. </if>
  1999. <if test="vo!=null and vo.endDate!=null and vo.endDate!=''">
  2000. and fr.pay_datetime &lt;= #{vo.endDate}
  2001. </if>
  2002. <if test="vo!=null and vo.xStartDate!=null and vo.xStartDate!=''">
  2003. and claimd.claimDate &gt;= #{vo.xStartDate}
  2004. </if>
  2005. <if test="vo!=null and vo.xEndDate!=null and vo.xEndDate!=''">
  2006. and claimd.claimDate &lt;= #{vo.xEndDate}
  2007. </if>
  2008. </where>
  2009. ORDER BY
  2010. claimd.claimDate DESC
  2011. </sql>
  2012. <select id="realAmountClaimed" parameterType="com.dayou.vo.FinanceRealFundVO" resultType="com.dayou.vo.FinanceRealFundVO">
  2013. <include refid="realAmountClaimedSQL" />
  2014. </select>
  2015. <select id="realClaimedExport" parameterType="com.dayou.vo.FinanceRealFundVO" resultType="com.dayou.dto.FinanceRealFundExportDTO">
  2016. <include refid="realAmountClaimedSQL" />
  2017. </select>
  2018. <select id="financeRealFundNotClaimExport" parameterType="com.dayou.entity.FinanceRealFund" resultType="com.dayou.dto.FinanceRealNotClaimDTO">
  2019. <include refid="pageListSql" />
  2020. ORDER BY
  2021. ifnull(t.ca,0) ASC ,frf.created DESC
  2022. </select>
  2023. </mapper>