FinanceRealFundMapper.xml 93 KB

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