FinanceRealFundMapper.xml 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490
  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, assets_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.UserCommissionProdAssetsVO">
  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.assets_name AS name,
  785. ap.created,
  786. dd.name AS businessCate,
  787. IFNULL(cd.ratio,bcr.min_ratio) AS ratio,
  788. cd.defined_low_limit_amount AS lowLimitAmount,
  789. bpd.member_id,
  790. bpd.performance_distribution AS allotRatio,
  791. IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  792. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  793. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  794. ) AS commissionAmount,
  795. IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  796. fc.claim_amount * (cd.ratio / 100),
  797. cd.defined_low_limit_amount * (cd.ratio / 100)
  798. ) AS totalAmount,
  799. u.name as userName
  800. FROM
  801. (
  802. SELECT
  803. claim_amount,
  804. order_fund_id,
  805. production_fund_id,
  806. claim_datetime
  807. FROM
  808. finance_claim
  809. WHERE
  810. deleted = 0
  811. AND production_fund_id IS NOT NULL
  812. AND claim_datetime &gt;= #{vo.startDate}
  813. AND claim_datetime &lt;= #{vo.endDate}
  814. UNION ALL
  815. SELECT
  816. allot_amount AS claim_amount,
  817. order_fund_id,
  818. production_fund_id,
  819. created AS claim_datetime
  820. FROM
  821. order_fund_allot
  822. WHERE
  823. deleted = 0
  824. AND created &gt;= #{vo.startDate}
  825. AND created &lt;= #{vo.endDate}
  826. ) fc
  827. 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 )
  828. 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
  829. LEFT JOIN assets a ON a.id = ap.business_id
  830. 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 (
  831. cd.business_id = a.id
  832. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  833. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  834. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  835. 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)
  836. LEFT JOIN user u on u.id = bpd.member_id
  837. WHERE
  838. bpd.member_id = #{vo.userId}
  839. order by settleDate DESC
  840. </select>
  841. <!--资产评估人员合计导出-->
  842. <select id="assetsEvaluatorTotalAmountExport" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  843. SELECT bpd.member_id as id,
  844. u.name as userName,
  845. ROUND(SUM(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  846. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  847. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  848. )), 2) AS commissionTotalAmount,
  849. '评估人员' as userType,
  850. '资产业务' as businessType,
  851. #{vo.startDate} as startDate,
  852. #{vo.endDate} as endDate
  853. FROM (SELECT claim_amount,
  854. order_fund_id,
  855. production_fund_id,
  856. claim_datetime
  857. FROM finance_claim
  858. WHERE deleted = 0
  859. AND production_fund_id IS NOT NULL
  860. AND claim_datetime &gt;= #{vo.startDate}
  861. AND claim_datetime &lt;= #{vo.endDate}
  862. UNION ALL
  863. SELECT allot_amount AS claim_amount,
  864. order_fund_id,
  865. production_fund_id,
  866. created AS claim_datetime
  867. FROM order_fund_allot
  868. WHERE deleted = 0
  869. AND created &gt;= #{vo.startDate}
  870. AND created &lt;= #{vo.endDate}) fc
  871. INNER JOIN (SELECT id, order_fund_id, business_id, production_no
  872. FROM production_fund
  873. WHERE business_type = 'ASSET_BUSINESS'
  874. AND deleted = 0) pf
  875. ON (pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id)
  876. INNER JOIN (SELECT id,
  877. business_id,
  878. assets_name,
  879. production_no,
  880. production_type,
  881. save_file_date,
  882. created
  883. FROM assets_production
  884. WHERE deleted = 0
  885. AND save_file_date IS NOT NULL) ap ON ap.production_no = pf.production_no
  886. LEFT JOIN assets a ON a.id = ap.business_id
  887. INNER JOIN (SELECT id, business_id, production_id, commission_rate_id, defined_low_limit_amount, ratio
  888. FROM commission_declare
  889. WHERE business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE'
  890. AND deleted = 0
  891. AND declare_result = '审核通过') cd ON (
  892. cd.business_id = a.id
  893. AND (cd.production_id IS NULL OR cd.production_id = ap.id))
  894. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  895. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  896. LEFT JOIN (SELECT business_id, report_no, member_id, performance_distribution
  897. FROM business_performance_distribution
  898. WHERE deleted = 0
  899. AND user_type = '评估人员') bpd
  900. ON (bpd.business_id = a.id AND bpd.report_no = ap.production_no)
  901. LEFT JOIN user u ON u.id = bpd.member_id
  902. GROUP BY bpd.member_id
  903. </select>
  904. <!--资产评估人员提成信息导出-->
  905. <select id="assetsEvaluatorUserDetailExport" resultType="com.dayou.vo.UserCommissionProdAssetsVO">
  906. SELECT
  907. ap.id,
  908. ROUND(fc.claim_amount,2) as realAmount,
  909. ap.production_no AS reportNo,
  910. IF
  911. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  912. ap.assets_name AS name,
  913. ap.created,
  914. dd.NAME AS businessCate,
  915. IFNULL(cd.ratio,bcr.min_ratio) AS ratio,
  916. cd.defined_low_limit_amount AS lowLimitAmount,
  917. ROUND(bcr.min_ratio,2) AS ratio,
  918. bpd.member_id AS userId,
  919. ROUND(bpd.performance_distribution,2) AS allotRatio,
  920. ROUND(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  921. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  922. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  923. ),2) AS commissionAmount,
  924. ROUND(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  925. fc.claim_amount * (cd.ratio / 100),
  926. cd.defined_low_limit_amount * (cd.ratio / 100)
  927. ),2) AS totalAmount,
  928. u.name as userName
  929. FROM
  930. (
  931. SELECT
  932. claim_amount,
  933. order_fund_id,
  934. production_fund_id,
  935. claim_datetime
  936. FROM
  937. finance_claim
  938. WHERE
  939. deleted = 0
  940. AND production_fund_id IS NOT NULL
  941. AND claim_datetime &gt;= #{vo.startDate}
  942. AND claim_datetime &lt;= #{vo.endDate}
  943. UNION ALL
  944. SELECT
  945. allot_amount AS claim_amount,
  946. order_fund_id,
  947. production_fund_id,
  948. created AS claim_datetime
  949. FROM
  950. order_fund_allot
  951. WHERE
  952. deleted = 0
  953. AND created &gt;= #{vo.startDate}
  954. AND created &lt;= #{vo.endDate}
  955. ) fc
  956. 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 )
  957. 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
  958. LEFT JOIN assets a ON a.id = ap.business_id
  959. 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 (
  960. cd.business_id = a.id
  961. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  962. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  963. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  964. 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)
  965. LEFT JOIN user u on u.id = bpd.member_id
  966. <where>
  967. <if test="vo!=null and vo.userId!=null">
  968. and bpd.member_id = #{vo.userId}
  969. </if>
  970. </where>
  971. order by bpd.member_id
  972. </select>
  973. <!--资产市场人员提成计算-->
  974. <select id="assetsMarketCommission" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  975. SELECT bpd.member_id as id,
  976. u.name as userName,
  977. SUM(( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100))) AS commissionTotalAmount
  978. FROM
  979. (
  980. SELECT
  981. claim_amount,
  982. order_fund_id,
  983. production_fund_id,
  984. claim_datetime
  985. FROM
  986. finance_claim
  987. WHERE
  988. deleted = 0
  989. AND production_fund_id IS NOT NULL
  990. AND claim_datetime &gt;= #{vo.startDate}
  991. AND claim_datetime &lt;= #{vo.endDate}
  992. 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
  993. AND created &gt;= #{vo.startDate}
  994. AND created &lt;= #{vo.endDate}
  995. ) fc
  996. 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 )
  997. 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
  998. LEFT JOIN assets a ON a.id = ap.business_id
  999. 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 (
  1000. cd.business_id = a.id
  1001. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1002. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1003. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1004. LEFT JOIN ( SELECT business_id, report_no,declare_id, member_id, performance_distribution FROM business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员'
  1005. ) 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 ))
  1006. LEFT JOIN user u ON u.id = bpd.member_id
  1007. GROUP BY
  1008. bpd.member_id
  1009. having 1=1
  1010. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  1011. and u.name like concat ('%',#{vo.userName},'%')
  1012. </if>
  1013. order by commissionTotalAmount DESC
  1014. </select>
  1015. <!--资产市场人员提成计算详情-->
  1016. <select id="assetsMarketCommissionDetail" resultType="com.dayou.vo.UserCommissionProdVO">
  1017. SELECT
  1018. ap.id,
  1019. fc.claim_amount as realAmount,
  1020. ap.production_no AS reportNo,
  1021. IF
  1022. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1023. ap.assets_name AS name,
  1024. ap.created,
  1025. dd.NAME AS businessCate,
  1026. bcr.min_ratio AS ratio,
  1027. bpd.member_id AS userId,
  1028. bpd.performance_distribution AS allotRatio,
  1029. ( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100) ) AS commissionAmount,
  1030. ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
  1031. u.name as userName
  1032. FROM
  1033. (
  1034. SELECT
  1035. claim_amount,
  1036. order_fund_id,
  1037. production_fund_id,
  1038. claim_datetime
  1039. FROM
  1040. finance_claim
  1041. WHERE
  1042. deleted = 0
  1043. AND production_fund_id IS NOT NULL
  1044. AND claim_datetime &gt;= #{vo.startDate}
  1045. AND claim_datetime &lt;= #{vo.endDate}
  1046. UNION ALL
  1047. SELECT
  1048. allot_amount AS claim_amount,
  1049. order_fund_id,
  1050. production_fund_id,
  1051. created AS claim_datetime
  1052. FROM
  1053. order_fund_allot
  1054. WHERE
  1055. deleted = 0
  1056. AND created &gt;= #{vo.startDate}
  1057. AND created &lt;= #{vo.endDate}
  1058. ) fc
  1059. 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 )
  1060. 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
  1061. LEFT JOIN assets a ON a.id = ap.business_id
  1062. 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 (
  1063. cd.business_id = a.id
  1064. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1065. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1066. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1067. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution,declare_id FROM business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员' ) bpd
  1068. 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 ))
  1069. LEFT JOIN user u on u.id = bpd.member_id
  1070. WHERE
  1071. bpd.member_id = #{vo.userId}
  1072. order by settleDate DESC
  1073. </select>
  1074. <!--资产市场人员提成合计导出-->
  1075. <select id="assetsMarketTotalAmountExport" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  1076. SELECT bpd.member_id as id,
  1077. u.name as userName,
  1078. ROUND(SUM((fc.claim_amount * (bcr.min_ratio / 100) * (bpd.performance_distribution / 100))),
  1079. 2) AS commissionTotalAmount,
  1080. '市场人员' as userType,
  1081. '资产业务' as businessType,
  1082. #{vo.startDate} as startDate,
  1083. #{vo.endDate} as endDate
  1084. FROM (SELECT claim_amount,
  1085. order_fund_id,
  1086. production_fund_id,
  1087. claim_datetime
  1088. FROM finance_claim
  1089. WHERE deleted = 0
  1090. AND production_fund_id IS NOT NULL
  1091. AND claim_datetime &gt;= #{vo.startDate}
  1092. AND claim_datetime &lt;= #{vo.endDate}
  1093. UNION ALL
  1094. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime
  1095. FROM order_fund_allot
  1096. WHERE deleted = 0
  1097. AND created &gt;= #{vo.startDate}
  1098. AND created &lt;= #{vo.endDate}) fc
  1099. INNER JOIN (SELECT id, order_fund_id, business_id, production_no
  1100. FROM production_fund
  1101. WHERE business_type = 'ASSET_BUSINESS'
  1102. AND deleted = 0) pf
  1103. ON (pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id)
  1104. INNER JOIN (SELECT id,
  1105. business_id,
  1106. assets_name,
  1107. production_no,
  1108. production_type,
  1109. save_file_date,
  1110. created
  1111. FROM assets_production
  1112. WHERE deleted = 0
  1113. AND delivery = true) ap ON ap.production_no = pf.production_no
  1114. LEFT JOIN assets a ON a.id = ap.business_id
  1115. INNER JOIN (SELECT id, business_id, production_id, commission_rate_id
  1116. FROM commission_declare
  1117. WHERE business_type = 'COMMISSION_DECLARE_ASSET_MARKET'
  1118. AND deleted = 0
  1119. AND declare_result = '审核通过') cd ON (
  1120. cd.business_id = a.id
  1121. AND (cd.production_id IS NULL OR cd.production_id = ap.id))
  1122. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1123. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1124. LEFT JOIN (SELECT business_id, report_no, declare_id, member_id, performance_distribution
  1125. FROM business_performance_distribution
  1126. WHERE deleted = 0
  1127. AND user_type = '市场人员') bpd ON (bpd.business_id = a.id AND cd.id = bpd.declare_id AND
  1128. (bpd.report_no is null or bpd.report_no = ap.production_no))
  1129. LEFT JOIN user u ON u.id = bpd.member_id
  1130. GROUP BY bpd.member_id
  1131. ORDER BY commissionTotalAmount DESC
  1132. </select>
  1133. <!--资产市场人员提成信息导出-->
  1134. <select id="assetsMarketUserDetailExport" resultType="com.dayou.vo.UserCommissionProdVO">
  1135. SELECT
  1136. ap.id,
  1137. ROUND(fc.claim_amount,2) as realAmount,
  1138. ap.production_no AS reportNo,
  1139. IF
  1140. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1141. ap.assets_name AS name,
  1142. ap.created,
  1143. dd.`name` AS businessCate,
  1144. ROUND(bcr.min_ratio,2) AS ratio,
  1145. bpd.member_id AS userId,
  1146. ROUND(bpd.performance_distribution,2) AS allotRatio,
  1147. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100) ),2) AS
  1148. commissionAmount,
  1149. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) ),2) AS totalAmount,
  1150. u.name as userName
  1151. FROM
  1152. (
  1153. SELECT
  1154. claim_amount,
  1155. order_fund_id,
  1156. production_fund_id,
  1157. claim_datetime
  1158. FROM
  1159. finance_claim
  1160. WHERE
  1161. deleted = 0
  1162. AND production_fund_id IS NOT NULL
  1163. AND claim_datetime &gt;= #{vo.startDate}
  1164. AND claim_datetime &lt;= #{vo.endDate}
  1165. UNION ALL
  1166. SELECT
  1167. allot_amount AS claim_amount,
  1168. order_fund_id,
  1169. production_fund_id,
  1170. created AS claim_datetime
  1171. FROM
  1172. order_fund_allot
  1173. WHERE
  1174. deleted = 0
  1175. AND created &gt;= #{vo.startDate}
  1176. AND created &lt;= #{vo.endDate}
  1177. ) fc
  1178. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type =
  1179. 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id
  1180. )
  1181. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, save_file_date, created FROM
  1182. assets_production WHERE deleted = 0 AND delivery = true ) ap ON ap.production_no = pf.production_no
  1183. LEFT JOIN assets a ON a.id = ap.business_id
  1184. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE
  1185. business_type = 'COMMISSION_DECLARE_ASSET_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1186. cd.business_id = a.id
  1187. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1188. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1189. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1190. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution, declare_id FROM
  1191. business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员' ) bpd
  1192. ON ( bpd.business_id = a.id AND cd.id = bpd.declare_id AND (bpd.report_no is null or bpd.report_no =
  1193. ap.production_no ))
  1194. LEFT JOIN user u on u.id = bpd.member_id
  1195. <where>
  1196. <if test="vo!=null and vo.userId!=null">
  1197. and bpd.member_id = #{vo.userId}
  1198. </if>
  1199. </where>
  1200. order by bpd.member_id
  1201. </select>
  1202. <!--资产收款逾期查询Sql-->
  1203. <sql id="assetsOverdueSql">
  1204. SELECT
  1205. DATEDIFF(CURDATE(), DATE( ap.repertory_out_time )) AS overdueDay,
  1206. a.allot_type,
  1207. a.order_id,
  1208. a.assets_business_gener,
  1209. u.name AS clientManager,
  1210. u1.name AS principal,
  1211. cc1.name AS clientName,
  1212. cc2.name AS clientSubName,
  1213. pf.production_should_amount,
  1214. `of`.should_amount,
  1215. pf.standard_amount,
  1216. ap.*
  1217. FROM
  1218. (
  1219. SELECT
  1220. id,
  1221. business_id,
  1222. production_no,
  1223. ( CASE production_type WHEN 'STATEMENT' THEN '意见书' WHEN 'REPORT' THEN '评估报告' WHEN 'LETTER' THEN '意见函' WHEN 'CONSULT' THEN '咨询报告' ELSE '' END ) productionType,
  1224. assets_name,
  1225. evaluate_amount,
  1226. repertory_out_time
  1227. FROM
  1228. assets_production ap
  1229. WHERE
  1230. deleted = 0
  1231. AND repertory_out_time IS NOT NULL
  1232. AND production_type != 'STATEMENT'
  1233. ) ap
  1234. 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
  1235. ON ( ap.business_id = pf.business_id AND ap.production_no = pf.production_no )
  1236. 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
  1237. LEFT JOIN assets a ON a.id = ap.business_id
  1238. LEFT JOIN user u ON u.id = a.client_manager_id
  1239. LEFT JOIN user u1 ON u1.id = a.principal_id
  1240. LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_id
  1241. LEFT JOIN customer_company cc2 ON cc2.id = a.clientele_sub_id
  1242. WHERE
  1243. ap.productionType != 'STATEMENT'
  1244. AND ( pf.production_no IS NULL OR pf.real_amount IS NULL )
  1245. AND DATEDIFF(CURDATE(),DATE( ap.repertory_out_time )) &gt;= #{overdueVO.overdueMin}
  1246. <if test="overdueVO!=null and overdueVO.overdueMax!=null">
  1247. AND DATEDIFF(CURDATE(),DATE( ap.repertory_out_time )) &lt;= #{overdueVO.overdueMax}
  1248. </if>
  1249. <if test="overdueVO!=null and overdueVO.orderId!=null and overdueVO.orderId!=''">
  1250. and a.order_id = #{overdueVO.orderId}
  1251. </if>
  1252. <if test="overdueVO!=null and overdueVO.productionNo!=null and overdueVO.productionNo!=''">
  1253. and ap.production_no like concat ('%',#{overdueVO.productionNo},'%')
  1254. </if>
  1255. <if test="overdueVO!=null and overdueVO.principal!=null and overdueVO.principal!=''">
  1256. and u1.name like concat ('%',#{overdueVO.principal},'%')
  1257. </if>
  1258. order by overdueDay desc
  1259. </sql>
  1260. <!--资产收款逾期列表-->
  1261. <select id="overdueAssets" resultType="com.dayou.vo.AssetsProdOverdueVO">
  1262. <include refid="assetsOverdueSql" />
  1263. </select>
  1264. <!--资产收款逾期列表导出-->
  1265. <select id="overdueAssetsExport" resultType="com.dayou.vo.AssetsProdOverdueVO">
  1266. <include refid="assetsOverdueSql" />
  1267. </select>
  1268. <!--资产市场人员结算项目Sql-->
  1269. <sql id="assetsMarketerSettleSql">
  1270. SELECT
  1271. ap.id,
  1272. fc.claim_amount,
  1273. a.order_id,
  1274. ap.production_no,
  1275. fc.claim_datetime as claimDate,
  1276. ap.delivery_date,
  1277. ap.save_file_date,
  1278. IF
  1279. ( fc.claim_datetime > ap.delivery_date, fc.claim_datetime, ap.delivery_date ) AS settleDate,
  1280. ap.assets_name,
  1281. a.bailor,
  1282. ap.evaluate_amount,
  1283. u.name AS principal,
  1284. u1.name AS clientManager,
  1285. cc.name AS clientName,
  1286. cc1.name AS clientSubName,
  1287. d.name AS evaluateDepartmentName,
  1288. (
  1289. SELECT
  1290. GROUP_CONCAT( department.name )
  1291. FROM
  1292. department
  1293. WHERE
  1294. id IN (
  1295. SELECT
  1296. department_id
  1297. FROM
  1298. post
  1299. WHERE
  1300. id IN ( SELECT post_id FROM user_post WHERE user_id = a.client_manager_id ))) AS marketDepartmentName
  1301. FROM
  1302. (
  1303. SELECT
  1304. claim_amount,
  1305. order_fund_id,
  1306. production_fund_id,
  1307. claim_datetime
  1308. FROM
  1309. finance_claim
  1310. WHERE
  1311. deleted = 0
  1312. AND production_fund_id IS NOT NULL
  1313. AND claim_datetime &gt;= #{settleVO.startDate}
  1314. AND claim_datetime &lt;= #{settleVO.endDate} UNION ALL
  1315. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime FROM
  1316. order_fund_allot WHERE deleted = 0
  1317. AND created &gt;= #{settleVO.startDate}
  1318. AND created &lt;= #{settleVO.endDate}
  1319. ) fc
  1320. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type =
  1321. 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id
  1322. )
  1323. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, evaluate_amount,
  1324. delivery_date, save_file_date FROM assets_production WHERE deleted = 0 AND delivery = true ) ap ON ap.production_no =
  1325. pf.production_no
  1326. LEFT JOIN assets a ON a.id = ap.business_id
  1327. LEFT JOIN user u ON u.id = a.principal_id
  1328. LEFT JOIN user u1 ON u1.id = a.client_manager_id
  1329. LEFT JOIN customer_company cc ON cc.id = a.clientele_id
  1330. LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_sub_id
  1331. LEFT JOIN department d ON d.id = a.department_id
  1332. <where>
  1333. <if test="settleVO!=null and settleVO.orderId!=null and settleVO.orderId!='' ">
  1334. and a.order_id = #{settleVO.orderId}
  1335. </if>
  1336. <if test="settleVO!=null and settleVO.productionNo!=null and settleVO.productionNo!='' ">
  1337. and ap.report_no like concat ('%',#{settleVO.productionNo},'%')
  1338. </if>
  1339. <if test="settleVO!=null and settleVO.principal!=null and settleVO.principal!='' ">
  1340. and u.name like concat ('%',#{settleVO.principal},'%')
  1341. </if>
  1342. <if test="settleVO!=null and settleVO.clientManager!=null and settleVO.clientManager!='' ">
  1343. and u1.name like concat ('%',#{settleVO.clientManager},'%')
  1344. </if>
  1345. </where>
  1346. order by settleDate DESC
  1347. </sql>
  1348. <!--资产结算项目查询-->
  1349. <select id="assetsMarketSettleProd" resultType="com.dayou.vo.SettleAssetsProductionVO">
  1350. <include refid="assetsMarketerSettleSql" />
  1351. </select>
  1352. <!--资产结算项目导出-->
  1353. <select id="assetsMarketSettleExport" resultType="com.dayou.vo.SettleAssetsProductionVO">
  1354. <include refid="assetsMarketerSettleSql" />
  1355. </select>
  1356. <!--资产评估人员结算项目Sql-->
  1357. <sql id="assetsEvaluatorSettleSql">
  1358. SELECT
  1359. ap.id,
  1360. fc.claim_amount,
  1361. a.order_id,
  1362. ap.production_no,
  1363. fc.claim_datetime as claimDate,
  1364. ap.save_file_date,
  1365. IF( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1366. ap.assets_name AS projectName,
  1367. a.bailor,
  1368. ap.evaluate_amount,
  1369. u.name AS principal,
  1370. u1.name AS clientManager,
  1371. cc.name AS clientName,
  1372. cc1.name AS clientSubName,
  1373. d.name AS evaluateDepartmentName,
  1374. (
  1375. SELECT
  1376. GROUP_CONCAT( NAME )
  1377. FROM
  1378. department
  1379. WHERE
  1380. id IN (
  1381. SELECT
  1382. department_id
  1383. FROM
  1384. post
  1385. WHERE
  1386. id IN ( SELECT post_id FROM user_post WHERE user_id = a.client_manager_id ))) AS marketDepartmentName
  1387. FROM
  1388. (
  1389. SELECT
  1390. claim_amount,
  1391. order_fund_id,
  1392. production_fund_id,
  1393. claim_datetime
  1394. FROM
  1395. finance_claim
  1396. WHERE
  1397. deleted = 0
  1398. AND production_fund_id IS NOT NULL
  1399. AND claim_datetime &gt;= #{settleVO.startDate}
  1400. AND claim_datetime &lt;= #{settleVO.endDate} UNION ALL
  1401. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime FROM order_fund_allot WHERE deleted = 0
  1402. AND created &gt;= #{settleVO.startDate}
  1403. AND created &lt;= #{settleVO.endDate}
  1404. ) fc
  1405. 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 )
  1406. 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
  1407. LEFT JOIN assets a ON a.id = ap.business_id
  1408. LEFT JOIN user u ON u.id = a.principal_id
  1409. LEFT JOIN user u1 ON u1.id = a.client_manager_id
  1410. LEFT JOIN customer_company cc ON cc.id = a.clientele_id
  1411. LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_sub_id
  1412. LEFT JOIN department d ON d.id = a.department_id
  1413. <where>
  1414. <if test="settleVO!=null and settleVO.orderId!=null and settleVO.orderId!='' ">
  1415. and a.order_id = #{settleVO.orderId}
  1416. </if>
  1417. <if test="settleVO!=null and settleVO.productionNo!=null and settleVO.productionNo!='' ">
  1418. and ap.production_no like concat ('%',#{settleVO.productionNo},'%')
  1419. </if>
  1420. <if test="settleVO!=null and settleVO.principal!=null and settleVO.principal!='' ">
  1421. and u.name like concat ('%',#{settleVO.principal},'%')
  1422. </if>
  1423. <if test="settleVO!=null and settleVO.clientManager!=null and settleVO.clientManager!='' ">
  1424. and u1.name like concat ('%',#{settleVO.clientManager},'%')
  1425. </if>
  1426. </where>
  1427. order by settleDate DESC
  1428. </sql>
  1429. <!--资产评估人员结算项目查询-->
  1430. <select id="assetsEvaluatorSettleProd" resultType="com.dayou.vo.SettleAssetsProductionVO">
  1431. <include refid="assetsEvaluatorSettleSql" />
  1432. </select>
  1433. <!--资产评估人员结算项目导出-->
  1434. <select id="assetsEvaluatorSettleExport" resultType="com.dayou.vo.SettleAssetsProductionVO">
  1435. <include refid="assetsEvaluatorSettleSql" />
  1436. </select>
  1437. </mapper>