FinanceRealFundMapper.xml 78 KB

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