FinanceRealFundMapper.xml 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488
  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. <select id="getPage" parameterType="com.dayou.entity.FinanceRealFund" resultType="com.dayou.vo.FinanceRealFundVO">
  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="keyword!=null and keyword!='' ">
  47. and (
  48. frf.payer like concat ('%',#{keyword},'%')
  49. or frf.payer_bank like concat('%',#{keyword},'%')
  50. or u.name like concat('%',#{keyword},'%')
  51. or frf.payer_account like concat('%',#{keyword},'%')
  52. or frf.amount like concat('%',#{keyword},'%')
  53. or frf.remark like concat('%',#{keyword},'%')
  54. )
  55. </if>
  56. <if test="vo!=null and vo.startDate!=null and vo.startDate!=''">
  57. and frf.pay_datetime &gt;= #{vo.startDate}
  58. </if>
  59. <if test="vo!=null and vo.endDate!=null and vo.endDate!=''">
  60. and frf.pay_datetime &lt;= #{vo.endDate}
  61. </if>
  62. <if test="vo!=null and vo.xStartDate!=null and vo.xStartDate!=''">
  63. and frf.created &gt;= #{vo.xStartDate}
  64. </if>
  65. <if test="vo!=null and vo.xEndDate!=null and vo.xEndDate!=''">
  66. and frf.created &lt;= #{vo.xEndDate}
  67. </if>
  68. ORDER BY
  69. frf.created DESC
  70. </select>
  71. <select id="getNotClaimAmount" parameterType="java.lang.Long" resultType="java.math.BigDecimal">
  72. SELECT ( frf.amount -( SELECT ifnull( sum( claim_amount ), 0 ) AS ca FROM finance_claim WHERE deleted = 0 AND real_fund_id = #{realFundId} )
  73. ) AS notClaimAmount
  74. FROM
  75. finance_real_fund frf
  76. WHERE
  77. frf.id = #{realFundId}
  78. AND frf.deleted = 0
  79. </select>
  80. <sql id="majorOverdueSql">
  81. SELECT
  82. DATEDIFF(
  83. CURDATE(),
  84. DATE( mp.repertory_out_time )) AS overdueDay,
  85. m.allot_type,
  86. m.order_id,
  87. m.business_object_type,
  88. u.NAME AS clientManager,
  89. u1.NAME AS principal,
  90. cc1.NAME AS clientName,
  91. cc2.NAME AS clientSubName,
  92. pf.production_should_amount,
  93. of.should_amount,
  94. mp.*
  95. FROM
  96. (
  97. SELECT
  98. id,
  99. major_id,
  100. report_no,
  101. ( CASE production WHEN 'STATEMENT' THEN '意见书' WHEN 'REPORT' THEN '报告' WHEN 'LETTER' THEN '复评函' ELSE '' END ) production,
  102. NAME,
  103. evaluate_amount,
  104. repertory_out_time,
  105. standard_amount
  106. FROM
  107. major_production mp
  108. WHERE
  109. deleted = 0
  110. AND repertory_out_time IS NOT NULL and production != 'STATEMENT'
  111. ) mp
  112. LEFT JOIN ( SELECT business_id, production_no, production_should_amount, real_amount FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( mp.major_id = pf.business_id AND mp.report_no = pf.production_no )
  113. left join ( SELECT business_id,should_amount FROM order_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) of ON of.business_id = mp.major_id
  114. LEFT JOIN major m ON m.id = mp.major_id
  115. LEFT JOIN user u ON u.id = m.client_manager_id
  116. LEFT JOIN user u1 ON u1.id = m.principal_id
  117. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_id
  118. LEFT JOIN customer_company cc2 ON cc2.id = m.clientele_sub_id
  119. WHERE
  120. mp.production != 'STATEMENT'
  121. AND ( pf.production_no IS NULL OR pf.real_amount IS NULL )
  122. AND DATEDIFF(CURDATE(),DATE( mp.repertory_out_time )) &gt;= #{overdueVO.overdueMin}
  123. <if test="overdueVO!=null and overdueVO.overdueMax!=null">
  124. AND DATEDIFF(CURDATE(),DATE( mp.repertory_out_time )) &lt;= #{overdueVO.overdueMax}
  125. </if>
  126. <if test="overdueVO!=null and overdueVO.orderId!=null and overdueVO.orderId!=''">
  127. and m.order_id = #{overdueVO.orderId}
  128. </if>
  129. <if test="overdueVO!=null and overdueVO.reportNo!=null and overdueVO.reportNo!=''">
  130. and mp.report_no like concat ('%',#{overdueVO.reportNo},'%')
  131. </if>
  132. <if test="overdueVO!=null and overdueVO.principal!=null and overdueVO.principal!=''">
  133. and u1.NAME like concat ('%',#{overdueVO.principal},'%')
  134. </if>
  135. order by overdueDay desc
  136. </sql>
  137. <select id="overdueMajor" parameterType="com.dayou.vo.MajorProdOverdueVO" resultType="com.dayou.vo.MajorProdOverdueVO">
  138. <include refid="majorOverdueSql" />
  139. </select>
  140. <select id="overdueMajorExport" parameterType="com.dayou.vo.MajorProdOverdueVO" resultType="com.dayou.vo.MajorProdOverdueVO">
  141. <include refid="majorOverdueSql" />
  142. </select>
  143. <sql id="majorEvaluatorSettleSql">
  144. SELECT
  145. mp.id,
  146. fc.claim_amount,
  147. m.order_id,
  148. mp.report_no,
  149. fc.claim_datetime as claimDate,
  150. mp.save_file_date,
  151. IF
  152. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  153. mp.NAME,
  154. m.bailor,
  155. mp.evaluate_amount,
  156. u.NAME AS principal,
  157. u1.NAME AS clientManager,
  158. cc.NAME AS clientName,
  159. cc1.NAME AS clientSubName,
  160. d.NAME AS evaluateDepartmentName,
  161. (
  162. SELECT
  163. GROUP_CONCAT( NAME )
  164. FROM
  165. department
  166. WHERE
  167. id IN (
  168. SELECT
  169. department_id
  170. FROM
  171. post
  172. WHERE
  173. id IN ( SELECT post_id FROM user_post WHERE user_id = m.client_manager_id ))) AS marketDepartmentName
  174. FROM
  175. (
  176. SELECT
  177. claim_amount,
  178. order_fund_id,
  179. production_fund_id,
  180. claim_datetime
  181. FROM
  182. finance_claim
  183. WHERE
  184. deleted = 0
  185. AND production_fund_id IS NOT NULL
  186. AND claim_datetime &gt;= #{settleVO.startDate}
  187. AND claim_datetime &lt;= #{settleVO.endDate} UNION ALL
  188. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime FROM order_fund_allot WHERE deleted = 0
  189. AND created &gt;= #{settleVO.startDate}
  190. AND created &lt;= #{settleVO.endDate}
  191. ) fc
  192. 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 )
  193. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, evaluate_amount, save_file_date FROM major_production WHERE deleted = 0 AND save_file_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  194. LEFT JOIN major m ON m.id = mp.major_id
  195. LEFT JOIN user u ON u.id = m.principal_id
  196. LEFT JOIN user u1 ON u1.id = m.client_manager_id
  197. LEFT JOIN customer_company cc ON cc.id = m.clientele_id
  198. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_sub_id
  199. LEFT JOIN department d ON d.id = m.department_id
  200. <where>
  201. <if test="settleVO!=null and settleVO.orderId!=null and settleVO.orderId!='' ">
  202. and m.order_id = #{settleVO.orderId}
  203. </if>
  204. <if test="settleVO!=null and settleVO.reportNo!=null and settleVO.reportNo!='' ">
  205. and mp.report_no like concat ('%',#{settleVO.reportNo},'%')
  206. </if>
  207. <if test="settleVO!=null and settleVO.principal!=null and settleVO.principal!='' ">
  208. and u.name like concat ('%',#{settleVO.principal},'%')
  209. </if>
  210. <if test="settleVO!=null and settleVO.clientManager!=null and settleVO.clientManager!='' ">
  211. and u1.name like concat ('%',#{settleVO.clientManager},'%')
  212. </if>
  213. </where>
  214. order by settleDate DESC
  215. </sql>
  216. <select id="majorEvaluatorSettleProd" parameterType="com.dayou.vo.SettleMajorProductionVO" resultType="com.dayou.vo.SettleMajorProductionVO">
  217. <include refid="majorEvaluatorSettleSql" />
  218. </select>
  219. <select id="majorEvaluatorSettleExport" parameterType="com.dayou.vo.SettleMajorProductionVO" resultType="com.dayou.vo.SettleMajorProductionVO">
  220. <include refid="majorEvaluatorSettleSql" />
  221. </select>
  222. <sql id="majorMarketerSettleSql">
  223. SELECT
  224. mp.id,
  225. fc.claim_amount,
  226. m.order_id,
  227. mp.report_no,
  228. fc.claim_datetime,
  229. mp.delivery_date,
  230. IF
  231. ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date ) AS settleDate,
  232. mp.NAME,
  233. m.bailor,
  234. mp.evaluate_amount,
  235. u.NAME AS principal,
  236. u1.NAME AS clientManager,
  237. cc.NAME AS clientName,
  238. cc1.NAME AS clientSubName,
  239. d.NAME AS evaluateDepartmentName,
  240. (
  241. SELECT
  242. GROUP_CONCAT( NAME )
  243. FROM
  244. department
  245. WHERE
  246. id IN (
  247. SELECT
  248. department_id
  249. FROM
  250. post
  251. WHERE
  252. id IN ( SELECT post_id FROM user_post WHERE user_id = m.client_manager_id ))) AS marketDepartmentName
  253. FROM
  254. (
  255. SELECT
  256. claim_amount,
  257. order_fund_id,
  258. production_fund_id,
  259. claim_datetime
  260. FROM
  261. finance_claim
  262. WHERE
  263. deleted = 0
  264. AND production_fund_id IS NOT NULL
  265. AND claim_datetime &gt;= #{settleVO.startDate}
  266. AND claim_datetime &lt;= #{settleVO.endDate} UNION ALL
  267. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime FROM order_fund_allot WHERE deleted = 0
  268. AND created &gt;= #{settleVO.startDate}
  269. AND created &lt;= #{settleVO.endDate}
  270. ) fc
  271. 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 )
  272. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, evaluate_amount, delivery_date FROM major_production WHERE deleted = 0 AND delivery_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  273. LEFT JOIN major m ON m.id = mp.major_id
  274. LEFT JOIN user u ON u.id = m.principal_id
  275. LEFT JOIN user u1 ON u1.id = m.client_manager_id
  276. LEFT JOIN customer_company cc ON cc.id = m.clientele_id
  277. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_sub_id
  278. LEFT JOIN department d ON d.id = m.department_id
  279. <where>
  280. <if test="settleVO!=null and settleVO.orderId!=null and settleVO.orderId!='' ">
  281. and m.order_id = #{settleVO.orderId}
  282. </if>
  283. <if test="settleVO!=null and settleVO.reportNo!=null and settleVO.reportNo!='' ">
  284. and mp.report_no like concat ('%',#{settleVO.reportNo},'%')
  285. </if>
  286. <if test="settleVO!=null and settleVO.principal!=null and settleVO.principal!='' ">
  287. and u.name like concat ('%',#{settleVO.principal},'%')
  288. </if>
  289. <if test="settleVO!=null and settleVO.clientManager!=null and settleVO.clientManager!='' ">
  290. and u1.name like concat ('%',#{settleVO.clientManager},'%')
  291. </if>
  292. </where>
  293. order by settleDate DESC
  294. </sql>
  295. <select id="majorMarketerSettleProd" parameterType="com.dayou.vo.SettleMajorProductionVO" resultType="com.dayou.vo.SettleMajorProductionVO">
  296. <include refid="majorMarketerSettleSql" />
  297. </select>
  298. <select id="majorMarketSettleExport" parameterType="com.dayou.vo.SettleMajorProductionVO" resultType="com.dayou.vo.SettleMajorProductionVO">
  299. <include refid="majorMarketerSettleSql" />
  300. </select>
  301. <select id="majorEvaluatorCommission" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  302. SELECT mpa.user_id as id, u.name as userName, sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )) AS commissionTotalAmount
  303. FROM
  304. (
  305. SELECT
  306. claim_amount,
  307. order_fund_id,
  308. production_fund_id,
  309. claim_datetime
  310. FROM
  311. finance_claim
  312. WHERE
  313. deleted = 0
  314. AND production_fund_id IS NOT NULL
  315. AND claim_datetime &gt;= #{vo.startDate}
  316. AND claim_datetime &lt;= #{vo.endDate}
  317. UNION ALL
  318. SELECT
  319. allot_amount AS claim_amount,
  320. order_fund_id,
  321. production_fund_id,
  322. created AS claim_datetime
  323. FROM
  324. order_fund_allot
  325. WHERE
  326. deleted = 0
  327. AND created &gt;= #{vo.startDate}
  328. AND created &lt;= #{vo.endDate}
  329. ) fc
  330. 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 )
  331. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, save_file_date, created FROM major_production WHERE deleted = 0 AND save_file_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  332. LEFT JOIN major m ON m.id = mp.major_id
  333. 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 (
  334. cd.business_id = m.id
  335. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  336. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  337. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  338. LEFT JOIN ( SELECT major_id, major_production_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'EVALUATE'
  339. ) mpa ON ( mpa.major_id = m.id AND mpa.major_production_id = mp.id)
  340. LEFT JOIN user u ON u.id = mpa.user_id
  341. GROUP BY
  342. mpa.user_id
  343. having 1=1
  344. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  345. and u.name like concat ('%',#{vo.userName},'%')
  346. </if>
  347. order by commissionTotalAmount DESC
  348. </select>
  349. <select id="majorEvaluatorCommissionDetail" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  350. SELECT
  351. mp.id,
  352. fc.claim_amount as realAmount,
  353. mp.report_no,
  354. IF
  355. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  356. mp.NAME,
  357. mp.created,
  358. dd.NAME AS businessCate,
  359. bcr.min_ratio AS ratio,
  360. mpa.user_id,
  361. mpa.ratio AS allotRatio,
  362. ( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ) AS commissionAmount,
  363. ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
  364. u.name as userName
  365. FROM
  366. (
  367. SELECT
  368. claim_amount,
  369. order_fund_id,
  370. production_fund_id,
  371. claim_datetime
  372. FROM
  373. finance_claim
  374. WHERE
  375. deleted = 0
  376. AND production_fund_id IS NOT NULL
  377. AND claim_datetime &gt;= #{vo.startDate}
  378. AND claim_datetime &lt;= #{vo.endDate}
  379. UNION ALL
  380. SELECT
  381. allot_amount AS claim_amount,
  382. order_fund_id,
  383. production_fund_id,
  384. created AS claim_datetime
  385. FROM
  386. order_fund_allot
  387. WHERE
  388. deleted = 0
  389. AND created &gt;= #{vo.startDate}
  390. AND created &lt;= #{vo.endDate}
  391. ) fc
  392. 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 )
  393. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, save_file_date, created FROM major_production WHERE deleted = 0 AND save_file_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  394. LEFT JOIN major m ON m.id = mp.major_id
  395. 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 (
  396. cd.business_id = m.id
  397. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  398. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  399. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  400. 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)
  401. LEFT JOIN user u on u.id = mpa.user_id
  402. WHERE
  403. mpa.user_id = #{vo.userId}
  404. order by settleDate DESC
  405. </select>
  406. <select id="majorEvaluatorTotalAmountExport" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  407. SELECT mpa.user_id as id, u.name as userName, ROUND(sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )),2) AS commissionTotalAmount,
  408. '评估人员' as userType,
  409. '大中型业务' as businessType,
  410. #{vo.startDate} as startDate,
  411. #{vo.endDate} as endDate
  412. FROM
  413. (
  414. SELECT
  415. claim_amount,
  416. order_fund_id,
  417. production_fund_id,
  418. claim_datetime
  419. FROM
  420. finance_claim
  421. WHERE
  422. deleted = 0
  423. AND production_fund_id IS NOT NULL
  424. AND claim_datetime &gt;= #{vo.startDate}
  425. AND claim_datetime &lt;= #{vo.endDate}
  426. UNION ALL
  427. SELECT
  428. allot_amount AS claim_amount,
  429. order_fund_id,
  430. production_fund_id,
  431. created AS claim_datetime
  432. FROM
  433. order_fund_allot
  434. WHERE
  435. deleted = 0
  436. AND created &gt;= #{vo.startDate}
  437. AND created &lt;= #{vo.endDate}
  438. ) fc
  439. 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 )
  440. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, save_file_date, created FROM major_production WHERE deleted = 0 AND save_file_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  441. LEFT JOIN major m ON m.id = mp.major_id
  442. 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 (
  443. cd.business_id = m.id
  444. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  445. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  446. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  447. LEFT JOIN ( SELECT major_id, major_production_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'EVALUATE'
  448. ) mpa ON ( mpa.major_id = m.id AND mpa.major_production_id = mp.id)
  449. LEFT JOIN user u ON u.id = mpa.user_id
  450. GROUP BY
  451. mpa.user_id
  452. </select>
  453. <select id="evaluatorUserDetailExport" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  454. SELECT
  455. mp.id,
  456. ROUND(fc.claim_amount,2) as realAmount,
  457. mp.report_no,
  458. IF
  459. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  460. mp.NAME,
  461. mp.created,
  462. dd.NAME AS businessCate,
  463. ROUND(bcr.min_ratio,2) AS ratio,
  464. mpa.user_id,
  465. ROUND(mpa.ratio*100,2) AS allotRatio,
  466. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ),2) AS commissionAmount,
  467. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) ),2) AS totalAmount,
  468. u.name as userName
  469. FROM
  470. (
  471. SELECT
  472. claim_amount,
  473. order_fund_id,
  474. production_fund_id,
  475. claim_datetime
  476. FROM
  477. finance_claim
  478. WHERE
  479. deleted = 0
  480. AND production_fund_id IS NOT NULL
  481. AND claim_datetime &gt;= #{vo.startDate}
  482. AND claim_datetime &lt;= #{vo.endDate}
  483. UNION ALL
  484. SELECT
  485. allot_amount AS claim_amount,
  486. order_fund_id,
  487. production_fund_id,
  488. created AS claim_datetime
  489. FROM
  490. order_fund_allot
  491. WHERE
  492. deleted = 0
  493. AND created &gt;= #{vo.startDate}
  494. AND created &lt;= #{vo.endDate}
  495. ) fc
  496. 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 )
  497. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, save_file_date, created FROM major_production WHERE deleted = 0 AND save_file_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  498. LEFT JOIN major m ON m.id = mp.major_id
  499. 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 (
  500. cd.business_id = m.id
  501. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  502. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  503. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  504. 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)
  505. LEFT JOIN user u on u.id = mpa.user_id
  506. <where>
  507. <if test="vo!=null and vo.userId!=null">
  508. and mpa.user_id = #{vo.userId}
  509. </if>
  510. </where>
  511. order by mpa.user_id
  512. </select>
  513. <select id="majorMarketCommission" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  514. SELECT mpa.user_id as id, u.name as userName, sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )) AS commissionTotalAmount
  515. FROM
  516. (
  517. SELECT
  518. claim_amount,
  519. order_fund_id,
  520. production_fund_id,
  521. claim_datetime
  522. FROM
  523. finance_claim
  524. WHERE
  525. deleted = 0
  526. AND production_fund_id IS NOT NULL
  527. AND claim_datetime &gt;= #{vo.startDate}
  528. AND claim_datetime &lt;= #{vo.endDate}
  529. 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
  530. AND created &gt;= #{vo.startDate}
  531. AND created &lt;= #{vo.endDate}
  532. ) fc
  533. 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 )
  534. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, save_file_date, created FROM major_production WHERE deleted = 0 AND delivery_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  535. LEFT JOIN major m ON m.id = mp.major_id
  536. 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 (
  537. cd.business_id = m.id
  538. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  539. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  540. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  541. LEFT JOIN ( SELECT major_id, major_production_id,declare_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'MARKET'
  542. ) 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 ))
  543. LEFT JOIN user u ON u.id = mpa.user_id
  544. GROUP BY
  545. mpa.user_id
  546. having 1=1
  547. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  548. and u.name like concat ('%',#{vo.userName},'%')
  549. </if>
  550. order by commissionTotalAmount DESC
  551. </select>
  552. <select id="majorMarketCommissionDetail" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  553. SELECT
  554. mp.id,
  555. fc.claim_amount as realAmount,
  556. mp.report_no,
  557. IF
  558. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  559. mp.NAME,
  560. mp.created,
  561. dd.NAME AS businessCate,
  562. bcr.min_ratio AS ratio,
  563. mpa.user_id,
  564. mpa.ratio AS allotRatio,
  565. ( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ) AS commissionAmount,
  566. ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
  567. u.name as userName
  568. FROM
  569. (
  570. SELECT
  571. claim_amount,
  572. order_fund_id,
  573. production_fund_id,
  574. claim_datetime
  575. FROM
  576. finance_claim
  577. WHERE
  578. deleted = 0
  579. AND production_fund_id IS NOT NULL
  580. AND claim_datetime &gt;= #{vo.startDate}
  581. AND claim_datetime &lt;= #{vo.endDate}
  582. UNION ALL
  583. SELECT
  584. allot_amount AS claim_amount,
  585. order_fund_id,
  586. production_fund_id,
  587. created AS claim_datetime
  588. FROM
  589. order_fund_allot
  590. WHERE
  591. deleted = 0
  592. AND created &gt;= #{vo.startDate}
  593. AND created &lt;= #{vo.endDate}
  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 ( SELECT id, major_id, NAME, report_no, production, save_file_date, created FROM major_production WHERE deleted = 0 AND delivery_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  597. LEFT JOIN major m ON m.id = mp.major_id
  598. 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 (
  599. cd.business_id = m.id
  600. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  601. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  602. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  603. 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 ))
  604. LEFT JOIN user u on u.id = mpa.user_id
  605. WHERE
  606. mpa.user_id = #{vo.userId}
  607. order by settleDate DESC
  608. </select>
  609. <select id="majorMarketTotalAmountExport" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  610. SELECT mpa.user_id as id, u.name as userName, ROUND(sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )),2) AS commissionTotalAmount,
  611. '市场人员' as userType,
  612. '大中型业务' as businessType,
  613. #{vo.startDate} as startDate,
  614. #{vo.endDate} as endDate
  615. FROM
  616. (
  617. SELECT
  618. claim_amount,
  619. order_fund_id,
  620. production_fund_id,
  621. claim_datetime
  622. FROM
  623. finance_claim
  624. WHERE
  625. deleted = 0
  626. AND production_fund_id IS NOT NULL
  627. AND claim_datetime &gt;= #{vo.startDate}
  628. AND claim_datetime &lt;= #{vo.endDate}
  629. UNION ALL
  630. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime FROM order_fund_allot WHERE deleted = 0
  631. AND created &gt;= #{vo.startDate}
  632. AND created &lt;= #{vo.endDate}
  633. ) fc
  634. 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 )
  635. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, save_file_date, created FROM major_production WHERE deleted = 0 AND delivery_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  636. LEFT JOIN major m ON m.id = mp.major_id
  637. 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 (
  638. cd.business_id = m.id
  639. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  640. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  641. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  642. LEFT JOIN ( SELECT major_id, major_production_id,declare_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'MARKET'
  643. ) 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 ))
  644. LEFT JOIN user u ON u.id = mpa.user_id
  645. GROUP BY
  646. mpa.user_id
  647. order by commissionTotalAmount DESC
  648. </select>
  649. <select id="marketUserDetailExport" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  650. SELECT
  651. mp.id,
  652. ROUND(fc.claim_amount,2) as realAmount,
  653. mp.report_no,
  654. IF
  655. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  656. mp.NAME,
  657. mp.created,
  658. dd.NAME AS businessCate,
  659. ROUND(bcr.min_ratio,2) AS ratio,
  660. mpa.user_id,
  661. ROUND(mpa.ratio*100,2) AS allotRatio,
  662. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ),2) AS commissionAmount,
  663. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) ),2) AS totalAmount,
  664. u.name as userName
  665. FROM
  666. (
  667. SELECT
  668. claim_amount,
  669. order_fund_id,
  670. production_fund_id,
  671. claim_datetime
  672. FROM
  673. finance_claim
  674. WHERE
  675. deleted = 0
  676. AND production_fund_id IS NOT NULL
  677. AND claim_datetime &gt;= #{vo.startDate}
  678. AND claim_datetime &lt;= #{vo.endDate}
  679. UNION ALL
  680. SELECT
  681. allot_amount AS claim_amount,
  682. order_fund_id,
  683. production_fund_id,
  684. created AS claim_datetime
  685. FROM
  686. order_fund_allot
  687. WHERE
  688. deleted = 0
  689. AND created &gt;= #{vo.startDate}
  690. AND created &lt;= #{vo.endDate}
  691. ) fc
  692. 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 )
  693. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, save_file_date, created FROM major_production WHERE deleted = 0 AND delivery_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  694. LEFT JOIN major m ON m.id = mp.major_id
  695. 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 (
  696. cd.business_id = m.id
  697. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  698. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  699. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  700. 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 ))
  701. LEFT JOIN user u on u.id = mpa.user_id
  702. <where>
  703. <if test="vo!=null and vo.userId!=null">
  704. and mpa.user_id = #{vo.userId}
  705. </if>
  706. </where>
  707. order by mpa.user_id
  708. </select>
  709. <select id="overduePersonal" parameterType="com.dayou.vo.PersonalProdOverdueVO" resultType="com.dayou.vo.PersonalProdOverdueVO">
  710. </select>
  711. <!--资产评估人员提成计算-->
  712. <select id="assetsEvaluatorCommission" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  713. SELECT bpd.member_id as id,
  714. u.name as userName,
  715. SUM(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  716. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  717. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  718. )) AS commissionTotalAmount
  719. FROM
  720. (
  721. SELECT
  722. claim_amount,
  723. order_fund_id,
  724. production_fund_id,
  725. claim_datetime
  726. FROM
  727. finance_claim
  728. WHERE
  729. deleted = 0
  730. AND production_fund_id IS NOT NULL
  731. AND claim_datetime &gt;= #{vo.startDate}
  732. AND claim_datetime &lt;= #{vo.endDate}
  733. UNION ALL
  734. SELECT
  735. allot_amount AS claim_amount,
  736. order_fund_id,
  737. production_fund_id,
  738. created AS claim_datetime
  739. FROM
  740. order_fund_allot
  741. WHERE
  742. deleted = 0
  743. AND created &gt;= #{vo.startDate}
  744. AND created &lt;= #{vo.endDate}
  745. ) fc
  746. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type =
  747. 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id
  748. )
  749. INNER JOIN ( SELECT id, business_id, project_name, production_no, production_type, save_file_date, created FROM
  750. assets_production
  751. WHERE deleted = 0 AND save_file_date IS NOT NULL ) ap ON ap.production_no = pf.production_no
  752. LEFT JOIN assets a ON a.id = ap.business_id
  753. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id, ratio, defined_low_limit_amount FROM
  754. commission_declare WHERE
  755. business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  756. cd.business_id = a.id
  757. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  758. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  759. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  760. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution FROM
  761. business_performance_distribution WHERE deleted = 0
  762. AND user_type = '评估人员'
  763. ) bpd ON ( bpd.business_id = a.id AND bpd.report_no = ap.production_no)
  764. LEFT JOIN user u ON u.id = bpd.member_id
  765. GROUP BY
  766. bpd.member_id
  767. # ,
  768. # u.name,
  769. # commissionTotalAmount
  770. having 1=1
  771. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  772. and u.name like concat ('%',#{vo.userName},'%')
  773. </if>
  774. order by commissionTotalAmount DESC
  775. </select>
  776. <!--资产评估人员提成计算详情-->
  777. <select id="assetsEvaluatorCommissionDetail" resultType="com.dayou.vo.UserCommissionProdVO">
  778. SELECT
  779. ap.id,
  780. fc.claim_amount as realAmount,
  781. ap.production_no AS reportNo,
  782. IF
  783. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  784. ap.project_name AS name,
  785. ap.created,
  786. dd.NAME AS businessCate,
  787. bcr.min_ratio AS ratio,
  788. bpd.member_id,
  789. bpd.performance_distribution AS allotRatio,
  790. IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  791. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  792. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  793. ) AS commissionAmount,
  794. IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  795. fc.claim_amount * (cd.ratio / 100),
  796. cd.defined_low_limit_amount * (cd.ratio / 100)
  797. ) AS totalAmount,
  798. u.name as userName
  799. FROM
  800. (
  801. SELECT
  802. claim_amount,
  803. order_fund_id,
  804. production_fund_id,
  805. claim_datetime
  806. FROM
  807. finance_claim
  808. WHERE
  809. deleted = 0
  810. AND production_fund_id IS NOT NULL
  811. AND claim_datetime &gt;= #{vo.startDate}
  812. AND claim_datetime &lt;= #{vo.endDate}
  813. UNION ALL
  814. SELECT
  815. allot_amount AS claim_amount,
  816. order_fund_id,
  817. production_fund_id,
  818. created AS claim_datetime
  819. FROM
  820. order_fund_allot
  821. WHERE
  822. deleted = 0
  823. AND created &gt;= #{vo.startDate}
  824. AND created &lt;= #{vo.endDate}
  825. ) fc
  826. 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 )
  827. INNER JOIN ( SELECT id, business_id, project_name, production_no, production_type, save_file_date, created FROM assets_production WHERE deleted = 0 AND save_file_date IS NOT NULL ) ap ON ap.production_no = pf.production_no
  828. LEFT JOIN assets a ON a.id = ap.business_id
  829. 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 (
  830. cd.business_id = a.id
  831. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  832. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  833. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  834. 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)
  835. LEFT JOIN user u on u.id = bpd.member_id
  836. WHERE
  837. bpd.member_id = #{vo.userId}
  838. order by settleDate DESC
  839. </select>
  840. <!--资产评估人员合计导出-->
  841. <select id="assetsEvaluatorTotalAmountExport" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  842. SELECT bpd.member_id as id,
  843. u.name as userName,
  844. ROUND(SUM(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  845. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  846. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  847. )), 2) AS commissionTotalAmount,
  848. '评估人员' as userType,
  849. '资产业务' as businessType,
  850. #{vo.startDate} as startDate,
  851. #{vo.endDate} as endDate
  852. FROM (SELECT claim_amount,
  853. order_fund_id,
  854. production_fund_id,
  855. claim_datetime
  856. FROM finance_claim
  857. WHERE deleted = 0
  858. AND production_fund_id IS NOT NULL
  859. AND claim_datetime &gt;= #{vo.startDate}
  860. AND claim_datetime &lt;= #{vo.endDate}
  861. UNION ALL
  862. SELECT allot_amount AS claim_amount,
  863. order_fund_id,
  864. production_fund_id,
  865. created AS claim_datetime
  866. FROM order_fund_allot
  867. WHERE deleted = 0
  868. AND created &gt;= #{vo.startDate}
  869. AND created &lt;= #{vo.endDate}) fc
  870. INNER JOIN (SELECT id, order_fund_id, business_id, production_no
  871. FROM production_fund
  872. WHERE business_type = 'ASSET_BUSINESS'
  873. AND deleted = 0) pf
  874. ON (pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id)
  875. INNER JOIN (SELECT id,
  876. business_id,
  877. project_name,
  878. production_no,
  879. production_type,
  880. save_file_date,
  881. created
  882. FROM assets_production
  883. WHERE deleted = 0
  884. AND save_file_date IS NOT NULL) ap ON ap.production_no = pf.production_no
  885. LEFT JOIN assets a ON a.id = ap.business_id
  886. INNER JOIN (SELECT id, business_id, production_id, commission_rate_id, defined_low_limit_amount, ratio
  887. FROM commission_declare
  888. WHERE business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE'
  889. AND deleted = 0
  890. AND declare_result = '审核通过') cd ON (
  891. cd.business_id = a.id
  892. AND (cd.production_id IS NULL OR cd.production_id = ap.id))
  893. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  894. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  895. LEFT JOIN (SELECT business_id, report_no, member_id, performance_distribution
  896. FROM business_performance_distribution
  897. WHERE deleted = 0
  898. AND user_type = '评估人员') bpd
  899. ON (bpd.business_id = a.id AND bpd.report_no = ap.production_no)
  900. LEFT JOIN user u ON u.id = bpd.member_id
  901. GROUP BY bpd.member_id
  902. </select>
  903. <!--资产评估人员提成信息导出-->
  904. <select id="assetsEvaluatorUserDetailExport" resultType="com.dayou.vo.UserCommissionProdVO">
  905. SELECT
  906. ap.id,
  907. ROUND(fc.claim_amount,2) as realAmount,
  908. ap.production_no AS reportNo,
  909. IF
  910. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  911. ap.project_name AS name,
  912. ap.created,
  913. dd.NAME AS businessCate,
  914. ROUND(bcr.min_ratio,2) AS ratio,
  915. bpd.member_id AS userId,
  916. ROUND(bpd.performance_distribution,2) AS allotRatio,
  917. ROUND(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  918. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  919. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  920. ),2) AS commissionAmount,
  921. ROUND(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  922. fc.claim_amount * (cd.ratio / 100),
  923. cd.defined_low_limit_amount * (cd.ratio / 100)
  924. ),2) AS totalAmount,
  925. u.name as userName
  926. FROM
  927. (
  928. SELECT
  929. claim_amount,
  930. order_fund_id,
  931. production_fund_id,
  932. claim_datetime
  933. FROM
  934. finance_claim
  935. WHERE
  936. deleted = 0
  937. AND production_fund_id IS NOT NULL
  938. AND claim_datetime &gt;= #{vo.startDate}
  939. AND claim_datetime &lt;= #{vo.endDate}
  940. UNION ALL
  941. SELECT
  942. allot_amount AS claim_amount,
  943. order_fund_id,
  944. production_fund_id,
  945. created AS claim_datetime
  946. FROM
  947. order_fund_allot
  948. WHERE
  949. deleted = 0
  950. AND created &gt;= #{vo.startDate}
  951. AND created &lt;= #{vo.endDate}
  952. ) fc
  953. 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 )
  954. INNER JOIN ( SELECT id, business_id, project_name, production_no, production_type, save_file_date, created FROM assets_production WHERE deleted = 0 AND save_file_date IS NOT NULL ) ap ON ap.production_no = pf.production_no
  955. LEFT JOIN assets a ON a.id = ap.business_id
  956. 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 (
  957. cd.business_id = a.id
  958. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  959. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  960. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  961. 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)
  962. LEFT JOIN user u on u.id = bpd.member_id
  963. <where>
  964. <if test="vo!=null and vo.userId!=null">
  965. and bpd.member_id = #{vo.userId}
  966. </if>
  967. </where>
  968. order by bpd.member_id
  969. </select>
  970. <!--资产市场人员提成计算-->
  971. <select id="assetsMarketCommission" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  972. SELECT bpd.member_id as id,
  973. u.name as userName,
  974. SUM(( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100))) AS commissionTotalAmount
  975. FROM
  976. (
  977. SELECT
  978. claim_amount,
  979. order_fund_id,
  980. production_fund_id,
  981. claim_datetime
  982. FROM
  983. finance_claim
  984. WHERE
  985. deleted = 0
  986. AND production_fund_id IS NOT NULL
  987. AND claim_datetime &gt;= #{vo.startDate}
  988. AND claim_datetime &lt;= #{vo.endDate}
  989. 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
  990. AND created &gt;= #{vo.startDate}
  991. AND created &lt;= #{vo.endDate}
  992. ) fc
  993. 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 )
  994. INNER JOIN ( SELECT id, business_id, project_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
  995. LEFT JOIN assets a ON a.id = ap.business_id
  996. 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 (
  997. cd.business_id = a.id
  998. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  999. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1000. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1001. LEFT JOIN ( SELECT business_id, report_no,declare_id, member_id, performance_distribution FROM business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员'
  1002. ) 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 ))
  1003. LEFT JOIN user u ON u.id = bpd.member_id
  1004. GROUP BY
  1005. bpd.member_id
  1006. having 1=1
  1007. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  1008. and u.name like concat ('%',#{vo.userName},'%')
  1009. </if>
  1010. order by commissionTotalAmount DESC
  1011. </select>
  1012. <!--资产市场人员提成计算详情-->
  1013. <select id="assetsMarketCommissionDetail" resultType="com.dayou.vo.UserCommissionProdVO">
  1014. SELECT
  1015. ap.id,
  1016. fc.claim_amount as realAmount,
  1017. ap.production_no AS reportNo,
  1018. IF
  1019. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1020. ap.project_name AS name,
  1021. ap.created,
  1022. dd.NAME AS businessCate,
  1023. bcr.min_ratio AS ratio,
  1024. bpd.member_id AS userId,
  1025. bpd.performance_distribution AS allotRatio,
  1026. ( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100) ) AS commissionAmount,
  1027. ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
  1028. u.name as userName
  1029. FROM
  1030. (
  1031. SELECT
  1032. claim_amount,
  1033. order_fund_id,
  1034. production_fund_id,
  1035. claim_datetime
  1036. FROM
  1037. finance_claim
  1038. WHERE
  1039. deleted = 0
  1040. AND production_fund_id IS NOT NULL
  1041. AND claim_datetime &gt;= #{vo.startDate}
  1042. AND claim_datetime &lt;= #{vo.endDate}
  1043. UNION ALL
  1044. SELECT
  1045. allot_amount AS claim_amount,
  1046. order_fund_id,
  1047. production_fund_id,
  1048. created AS claim_datetime
  1049. FROM
  1050. order_fund_allot
  1051. WHERE
  1052. deleted = 0
  1053. AND created &gt;= #{vo.startDate}
  1054. AND created &lt;= #{vo.endDate}
  1055. ) fc
  1056. 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 )
  1057. INNER JOIN ( SELECT id, business_id, project_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
  1058. LEFT JOIN assets a ON a.id = ap.business_id
  1059. 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 (
  1060. cd.business_id = a.id
  1061. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1062. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1063. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1064. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution,declare_id FROM business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员' ) bpd
  1065. 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 ))
  1066. LEFT JOIN user u on u.id = bpd.member_id
  1067. WHERE
  1068. bpd.member_id = #{vo.userId}
  1069. order by settleDate DESC
  1070. </select>
  1071. <!--资产市场人员提成合计导出-->
  1072. <select id="assetsMarketTotalAmountExport" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  1073. SELECT bpd.member_id as id,
  1074. u.name as userName,
  1075. ROUND(SUM((fc.claim_amount * (bcr.min_ratio / 100) * (bpd.performance_distribution / 100))),
  1076. 2) AS commissionTotalAmount,
  1077. '市场人员' as userType,
  1078. '资产业务' as businessType,
  1079. #{vo.startDate} as startDate,
  1080. #{vo.endDate} as endDate
  1081. FROM (SELECT claim_amount,
  1082. order_fund_id,
  1083. production_fund_id,
  1084. claim_datetime
  1085. FROM finance_claim
  1086. WHERE deleted = 0
  1087. AND production_fund_id IS NOT NULL
  1088. AND claim_datetime &gt;= #{vo.startDate}
  1089. AND claim_datetime &lt;= #{vo.endDate}
  1090. UNION ALL
  1091. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime
  1092. FROM order_fund_allot
  1093. WHERE deleted = 0
  1094. AND created &gt;= #{vo.startDate}
  1095. AND created &lt;= #{vo.endDate}) fc
  1096. INNER JOIN (SELECT id, order_fund_id, business_id, production_no
  1097. FROM production_fund
  1098. WHERE business_type = 'ASSET_BUSINESS'
  1099. AND deleted = 0) pf
  1100. ON (pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id)
  1101. INNER JOIN (SELECT id,
  1102. business_id,
  1103. project_name,
  1104. production_no,
  1105. production_type,
  1106. save_file_date,
  1107. created
  1108. FROM assets_production
  1109. WHERE deleted = 0
  1110. AND delivery = true) ap ON ap.production_no = pf.production_no
  1111. LEFT JOIN assets a ON a.id = ap.business_id
  1112. INNER JOIN (SELECT id, business_id, production_id, commission_rate_id
  1113. FROM commission_declare
  1114. WHERE business_type = 'COMMISSION_DECLARE_ASSET_MARKET'
  1115. AND deleted = 0
  1116. AND declare_result = '审核通过') cd ON (
  1117. cd.business_id = a.id
  1118. AND (cd.production_id IS NULL OR cd.production_id = ap.id))
  1119. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1120. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1121. LEFT JOIN (SELECT business_id, report_no, declare_id, member_id, performance_distribution
  1122. FROM business_performance_distribution
  1123. WHERE deleted = 0
  1124. AND user_type = '市场人员') bpd ON (bpd.business_id = a.id AND cd.id = bpd.declare_id AND
  1125. (bpd.report_no is null or bpd.report_no = ap.production_no))
  1126. LEFT JOIN user u ON u.id = bpd.member_id
  1127. GROUP BY bpd.member_id
  1128. ORDER BY commissionTotalAmount DESC
  1129. </select>
  1130. <!--资产市场人员提成信息导出-->
  1131. <select id="assetsMarketUserDetailExport" resultType="com.dayou.vo.UserCommissionProdVO">
  1132. SELECT
  1133. ap.id,
  1134. ROUND(fc.claim_amount,2) as realAmount,
  1135. ap.production_no AS reportNo,
  1136. IF
  1137. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1138. ap.project_name AS name,
  1139. ap.created,
  1140. dd.`name` AS businessCate,
  1141. ROUND(bcr.min_ratio,2) AS ratio,
  1142. bpd.member_id AS userId,
  1143. ROUND(bpd.performance_distribution,2) AS allotRatio,
  1144. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100) ),2) AS
  1145. commissionAmount,
  1146. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) ),2) AS totalAmount,
  1147. u.name as userName
  1148. FROM
  1149. (
  1150. SELECT
  1151. claim_amount,
  1152. order_fund_id,
  1153. production_fund_id,
  1154. claim_datetime
  1155. FROM
  1156. finance_claim
  1157. WHERE
  1158. deleted = 0
  1159. AND production_fund_id IS NOT NULL
  1160. AND claim_datetime &gt;= #{vo.startDate}
  1161. AND claim_datetime &lt;= #{vo.endDate}
  1162. UNION ALL
  1163. SELECT
  1164. allot_amount AS claim_amount,
  1165. order_fund_id,
  1166. production_fund_id,
  1167. created AS claim_datetime
  1168. FROM
  1169. order_fund_allot
  1170. WHERE
  1171. deleted = 0
  1172. AND created &gt;= #{vo.startDate}
  1173. AND created &lt;= #{vo.endDate}
  1174. ) fc
  1175. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type =
  1176. 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id
  1177. )
  1178. INNER JOIN ( SELECT id, business_id, project_name, production_no, production_type, save_file_date, created FROM
  1179. assets_production WHERE deleted = 0 AND delivery = true ) ap ON ap.production_no = pf.production_no
  1180. LEFT JOIN assets a ON a.id = ap.business_id
  1181. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE
  1182. business_type = 'COMMISSION_DECLARE_ASSET_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1183. cd.business_id = a.id
  1184. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1185. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1186. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1187. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution, declare_id FROM
  1188. business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员' ) bpd
  1189. ON ( bpd.business_id = a.id AND cd.id = bpd.declare_id AND (bpd.report_no is null or bpd.report_no =
  1190. ap.production_no ))
  1191. LEFT JOIN user u on u.id = bpd.member_id
  1192. <where>
  1193. <if test="vo!=null and vo.userId!=null">
  1194. and bpd.member_id = #{vo.userId}
  1195. </if>
  1196. </where>
  1197. order by bpd.member_id
  1198. </select>
  1199. <!--资产收款逾期查询Sql-->
  1200. <sql id="assetsOverdueSql">
  1201. SELECT
  1202. DATEDIFF(CURDATE(), DATE( ap.repertory_out_time )) AS overdueDay,
  1203. a.allot_type,
  1204. a.order_id,
  1205. a.assets_business_gener,
  1206. u.name AS clientManager,
  1207. u1.name AS principal,
  1208. cc1.name AS clientName,
  1209. cc2.name AS clientSubName,
  1210. pf.production_should_amount,
  1211. `of`.should_amount,
  1212. pf.standard_amount,
  1213. ap.*
  1214. FROM
  1215. (
  1216. SELECT
  1217. id,
  1218. business_id,
  1219. production_no,
  1220. ( CASE production_type WHEN 'STATEMENT' THEN '意见书' WHEN 'REPORT' THEN '评估报告' WHEN 'LETTER' THEN '意见函' WHEN 'CONSULT' THEN '咨询报告' ELSE '' END ) productionType,
  1221. project_name,
  1222. evaluate_amount,
  1223. repertory_out_time
  1224. FROM
  1225. assets_production ap
  1226. WHERE
  1227. deleted = 0
  1228. AND repertory_out_time IS NOT NULL
  1229. AND production_type != 'STATEMENT'
  1230. ) ap
  1231. LEFT JOIN ( SELECT business_id, production_no, production_should_amount, real_amount, standard_amount FROM production_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) pf
  1232. ON ( ap.business_id = pf.business_id AND ap.production_no = pf.production_no )
  1233. LEFT JOIN ( SELECT business_id,should_amount FROM order_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) `of` ON `of`.business_id = ap.business_id
  1234. LEFT JOIN assets a ON a.id = ap.business_id
  1235. LEFT JOIN user u ON u.id = a.client_manager_id
  1236. LEFT JOIN user u1 ON u1.id = a.principal_id
  1237. LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_id
  1238. LEFT JOIN customer_company cc2 ON cc2.id = a.clientele_sub_id
  1239. WHERE
  1240. ap.productionType != 'STATEMENT'
  1241. AND ( pf.production_no IS NULL OR pf.real_amount IS NULL )
  1242. AND DATEDIFF(CURDATE(),DATE( ap.repertory_out_time )) &gt;= #{overdueVO.overdueMin}
  1243. <if test="overdueVO!=null and overdueVO.overdueMax!=null">
  1244. AND DATEDIFF(CURDATE(),DATE( ap.repertory_out_time )) &lt;= #{overdueVO.overdueMax}
  1245. </if>
  1246. <if test="overdueVO!=null and overdueVO.orderId!=null and overdueVO.orderId!=''">
  1247. and a.order_id = #{overdueVO.orderId}
  1248. </if>
  1249. <if test="overdueVO!=null and overdueVO.productionNo!=null and overdueVO.productionNo!=''">
  1250. and ap.production_no like concat ('%',#{overdueVO.productionNo},'%')
  1251. </if>
  1252. <if test="overdueVO!=null and overdueVO.principal!=null and overdueVO.principal!=''">
  1253. and u1.name like concat ('%',#{overdueVO.principal},'%')
  1254. </if>
  1255. order by overdueDay desc
  1256. </sql>
  1257. <!--资产收款逾期列表-->
  1258. <select id="overdueAssets" resultType="com.dayou.vo.AssetsProdOverdueVO">
  1259. <include refid="assetsOverdueSql" />
  1260. </select>
  1261. <!--资产收款逾期列表导出-->
  1262. <select id="overdueAssetsExport" resultType="com.dayou.vo.AssetsProdOverdueVO">
  1263. <include refid="assetsOverdueSql" />
  1264. </select>
  1265. <!--资产市场人员结算项目Sql-->
  1266. <sql id="assetsMarketerSettleSql">
  1267. SELECT
  1268. ap.id,
  1269. fc.claim_amount,
  1270. a.order_id,
  1271. ap.production_no,
  1272. fc.claim_datetime as claimDate,
  1273. ap.delivery_date,
  1274. ap.save_file_date,
  1275. IF
  1276. ( fc.claim_datetime > ap.delivery_date, fc.claim_datetime, ap.delivery_date ) AS settleDate,
  1277. ap.project_name,
  1278. a.bailor,
  1279. ap.evaluate_amount,
  1280. u.name AS principal,
  1281. u1.name AS clientManager,
  1282. cc.name AS clientName,
  1283. cc1.name AS clientSubName,
  1284. d.name AS evaluateDepartmentName,
  1285. (
  1286. SELECT
  1287. GROUP_CONCAT( department.name )
  1288. FROM
  1289. department
  1290. WHERE
  1291. id IN (
  1292. SELECT
  1293. department_id
  1294. FROM
  1295. post
  1296. WHERE
  1297. id IN ( SELECT post_id FROM user_post WHERE user_id = a.client_manager_id ))) AS marketDepartmentName
  1298. FROM
  1299. (
  1300. SELECT
  1301. claim_amount,
  1302. order_fund_id,
  1303. production_fund_id,
  1304. claim_datetime
  1305. FROM
  1306. finance_claim
  1307. WHERE
  1308. deleted = 0
  1309. AND production_fund_id IS NOT NULL
  1310. AND claim_datetime &gt;= #{settleVO.startDate}
  1311. AND claim_datetime &lt;= #{settleVO.endDate} UNION ALL
  1312. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime FROM
  1313. order_fund_allot WHERE deleted = 0
  1314. AND created &gt;= #{settleVO.startDate}
  1315. AND created &lt;= #{settleVO.endDate}
  1316. ) fc
  1317. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type =
  1318. 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id
  1319. )
  1320. INNER JOIN ( SELECT id, business_id, project_name, production_no, production_type, evaluate_amount,
  1321. delivery_date, save_file_date FROM assets_production WHERE deleted = 0 AND delivery = true ) ap ON ap.production_no =
  1322. pf.production_no
  1323. LEFT JOIN assets a ON a.id = ap.business_id
  1324. LEFT JOIN user u ON u.id = a.principal_id
  1325. LEFT JOIN user u1 ON u1.id = a.client_manager_id
  1326. LEFT JOIN customer_company cc ON cc.id = a.clientele_id
  1327. LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_sub_id
  1328. LEFT JOIN department d ON d.id = a.department_id
  1329. <where>
  1330. <if test="settleVO!=null and settleVO.orderId!=null and settleVO.orderId!='' ">
  1331. and a.order_id = #{settleVO.orderId}
  1332. </if>
  1333. <if test="settleVO!=null and settleVO.productionNo!=null and settleVO.productionNo!='' ">
  1334. and ap.report_no like concat ('%',#{settleVO.productionNo},'%')
  1335. </if>
  1336. <if test="settleVO!=null and settleVO.principal!=null and settleVO.principal!='' ">
  1337. and u.name like concat ('%',#{settleVO.principal},'%')
  1338. </if>
  1339. <if test="settleVO!=null and settleVO.clientManager!=null and settleVO.clientManager!='' ">
  1340. and u1.name like concat ('%',#{settleVO.clientManager},'%')
  1341. </if>
  1342. </where>
  1343. order by settleDate DESC
  1344. </sql>
  1345. <!--资产结算项目查询-->
  1346. <select id="assetsMarketSettleProd" resultType="com.dayou.vo.SettleAssetsProductionVO">
  1347. <include refid="assetsMarketerSettleSql" />
  1348. </select>
  1349. <!--资产结算项目导出-->
  1350. <select id="assetsMarketSettleExport" resultType="com.dayou.vo.SettleAssetsProductionVO">
  1351. <include refid="assetsMarketerSettleSql" />
  1352. </select>
  1353. <!--资产评估人员结算项目Sql-->
  1354. <sql id="assetsEvaluatorSettleSql">
  1355. SELECT
  1356. ap.id,
  1357. fc.claim_amount,
  1358. a.order_id,
  1359. ap.production_no,
  1360. fc.claim_datetime as claimDate,
  1361. ap.save_file_date,
  1362. IF
  1363. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1364. ap.project_name,
  1365. a.bailor,
  1366. ap.evaluate_amount,
  1367. u.name AS principal,
  1368. u1.name AS clientManager,
  1369. cc.name AS clientName,
  1370. cc1.name AS clientSubName,
  1371. d.name AS evaluateDepartmentName,
  1372. (
  1373. SELECT
  1374. GROUP_CONCAT( NAME )
  1375. FROM
  1376. department
  1377. WHERE
  1378. id IN (
  1379. SELECT
  1380. department_id
  1381. FROM
  1382. post
  1383. WHERE
  1384. id IN ( SELECT post_id FROM user_post WHERE user_id = a.client_manager_id ))) AS marketDepartmentName
  1385. FROM
  1386. (
  1387. SELECT
  1388. claim_amount,
  1389. order_fund_id,
  1390. production_fund_id,
  1391. claim_datetime
  1392. FROM
  1393. finance_claim
  1394. WHERE
  1395. deleted = 0
  1396. AND production_fund_id IS NOT NULL
  1397. AND claim_datetime &gt;= #{settleVO.startDate}
  1398. AND claim_datetime &lt;= #{settleVO.endDate} UNION ALL
  1399. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime FROM order_fund_allot WHERE deleted = 0
  1400. AND created &gt;= #{settleVO.startDate}
  1401. AND created &lt;= #{settleVO.endDate}
  1402. ) fc
  1403. 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 )
  1404. INNER JOIN ( SELECT id, business_id, project_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
  1405. LEFT JOIN assets a ON a.id = ap.business_id
  1406. LEFT JOIN user u ON u.id = a.principal_id
  1407. LEFT JOIN user u1 ON u1.id = a.client_manager_id
  1408. LEFT JOIN customer_company cc ON cc.id = a.clientele_id
  1409. LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_sub_id
  1410. LEFT JOIN department d ON d.id = a.department_id
  1411. <where>
  1412. <if test="settleVO!=null and settleVO.orderId!=null and settleVO.orderId!='' ">
  1413. and a.order_id = #{settleVO.orderId}
  1414. </if>
  1415. <if test="settleVO!=null and settleVO.productionNo!=null and settleVO.productionNo!='' ">
  1416. and ap.production_no like concat ('%',#{settleVO.productionNo},'%')
  1417. </if>
  1418. <if test="settleVO!=null and settleVO.principal!=null and settleVO.principal!='' ">
  1419. and u.name like concat ('%',#{settleVO.principal},'%')
  1420. </if>
  1421. <if test="settleVO!=null and settleVO.clientManager!=null and settleVO.clientManager!='' ">
  1422. and u1.name like concat ('%',#{settleVO.clientManager},'%')
  1423. </if>
  1424. </where>
  1425. order by settleDate DESC
  1426. </sql>
  1427. <!--资产评估人员结算项目查询-->
  1428. <select id="assetsEvaluatorSettleProd" resultType="com.dayou.vo.SettleAssetsProductionVO">
  1429. <include refid="assetsEvaluatorSettleSql" />
  1430. </select>
  1431. <!--资产评估人员结算项目导出-->
  1432. <select id="assetsEvaluatorSettleExport" resultType="com.dayou.vo.SettleAssetsProductionVO">
  1433. <include refid="assetsEvaluatorSettleSql" />
  1434. </select>
  1435. </mapper>