FinanceClaimMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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.FinanceClaimMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.dayou.entity.FinanceClaim">
  6. <result column="id" property="id" />
  7. <result column="created" property="created" />
  8. <result column="deleted" property="deleted" />
  9. <result column="modified" property="modified" />
  10. <result column="real_fund_id" property="realFundId" />
  11. <result column="production_fund_id" property="productionFundId" />
  12. <result column="claim_user_id" property="claimUserId" />
  13. <result column="claim_datetime" property="claimDatetime" />
  14. <result column="claim_amount" property="claimAmount" />
  15. </resultMap>
  16. <!-- 通用查询结果列 -->
  17. <sql id="Base_Column_List">
  18. id,
  19. created,
  20. deleted,
  21. modified,
  22. real_fund_id, production_fund_id, claim_user_id, claim_datetime, claim_amount
  23. </sql>
  24. <select id="getList" parameterType="com.dayou.entity.FinanceClaim" resultType="com.dayou.vo.FinanceClaimVO">
  25. SELECT
  26. fc.id,
  27. fc.real_fund_id,
  28. ( CASE orf.business_type WHEN 'MAJOR_BUSINESS' THEN '大中型业务' WHEN 'PERSONAL_BUSINESS' THEN '个贷业务' WHEN 'ASSET_BUSINESS' THEN '资产业务' WHEN 'ITEM_BUSINESS' THEN '土规业务' ELSE '-' END ) AS businessType,
  29. orf.should_amount,
  30. fc.claim_amount,
  31. u.NAME AS claimName,
  32. fc.created,
  33. orf.order_id,
  34. orf.order_name,
  35. orf.remark,
  36. off.production_should_amount,
  37. off.production_no
  38. FROM
  39. finance_claim fc
  40. LEFT JOIN order_fund orf ON fc.order_fund_id = orf.id
  41. LEFT JOIN ( SELECT id,order_fund_id,production_no,production_should_amount FROM production_fund WHERE deleted = 0) off ON (off.order_fund_id = fc.order_fund_id and fc.production_fund_id = off.id)
  42. LEFT JOIN user u ON u.id = fc.claim_user_id
  43. WHERE
  44. fc.real_fund_id = #{realFundId}
  45. AND fc.deleted = 0
  46. ORDER BY
  47. fc.created DESC
  48. </select>
  49. <select id="getTotalClaimAmountByProductionFundId" parameterType="java.lang.Long" resultType="java.math.BigDecimal">
  50. select ifnull(sum(claim_amount),0) from finance_claim where production_fund_id = #{productionFundId} and deleted = 0
  51. </select>
  52. <select id="getTotalClaimAmountByOrderFundId" parameterType="java.lang.Long" resultType="java.math.BigDecimal">
  53. select ifnull(sum(claim_amount),0) from finance_claim where order_fund_id = #{orderFundId} and deleted = 0
  54. </select>
  55. <select id="residueAmount" parameterType="java.lang.Long" resultType="java.math.BigDecimal">
  56. SELECT amount -( SELECT IFNULL( sum( claim_amount ), 0 ) FROM `finance_claim` WHERE deleted = 0 AND real_fund_id = #{financeFundId} ) AS residueAmount
  57. FROM
  58. finance_real_fund
  59. WHERE
  60. id = #{financeFundId} and deleted = 0
  61. </select>
  62. <sql id="majorStatQuery">
  63. SELECT
  64. fc.*,
  65. f.oId,
  66. f.pId,
  67. f.production_no as reportNo,
  68. m.order_id,
  69. f.shouldAmount as orderShouldAmount,
  70. m.financial,
  71. m.members,
  72. m.bailor,
  73. m.NAME AS orderName,
  74. mp.NAME,
  75. mp.if_save_file,
  76. mp.evaluate_amount,
  77. mp.production AS productionType,
  78. u.NAME AS clientManager,
  79. u1.NAME AS principal,
  80. cc1.NAME AS clientName,
  81. cc2.NAME AS clientSubName,
  82. frf.pay_datetime,
  83. frf.payer,
  84. u2.NAME AS claimUser,
  85. d.NAME AS evaluateDepartment,
  86. (
  87. SELECT
  88. GROUP_CONCAT( NAME SEPARATOR '、' )
  89. FROM
  90. department
  91. WHERE
  92. id IN (
  93. SELECT
  94. department_id
  95. FROM
  96. post
  97. WHERE
  98. id IN ( SELECT post_id FROM user_post WHERE user_id = u.id and deleted = 0 ))) AS marketDepartment
  99. FROM
  100. (select * from finance_claim where deleted = 0 and production_fund_id is not null
  101. AND claim_datetime &gt;= #{majorStat.startDate}
  102. AND claim_datetime &lt;= #{majorStat.endDate}
  103. ) fc
  104. INNER JOIN (
  105. SELECT
  106. p.order_fund_id oId,
  107. p.id AS pId,
  108. p.business_id,
  109. p.production_no,
  110. p.production_should_amount AS shouldAmount
  111. FROM
  112. production_fund p
  113. WHERE
  114. p.business_type = 'MAJOR_BUSINESS'
  115. AND p.deleted = 0
  116. ) f ON ( fc.order_fund_id = f.oId AND fc.production_fund_id = f.pId )
  117. LEFT JOIN major m ON f.business_id = m.id
  118. LEFT JOIN finance_real_fund frf ON frf.id = fc.real_fund_id
  119. LEFT JOIN (
  120. SELECT
  121. mpp.major_id,
  122. mpp.report_no,
  123. mpp.production,
  124. mpp.evaluate_amount,
  125. mpp.if_save_file,
  126. mpp.NAME
  127. FROM
  128. major_production mpp
  129. LEFT JOIN ( SELECT production_no, production_type, real_amount FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) ppf ON ( mpp.report_no = ppf.production_no AND mpp.production = ppf.production_type )
  130. WHERE
  131. ppf.real_amount IS NOT NULL
  132. ) mp ON ( mp.major_id = m.id AND mp.report_no = f.production_no )
  133. LEFT JOIN user u2 ON u2.id = fc.claim_user_id
  134. LEFT JOIN user u ON u.id = m.client_manager_id
  135. LEFT JOIN user u1 ON u1.id = m.principal_id
  136. LEFT JOIN department d ON d.id = m.department_id
  137. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_id
  138. LEFT JOIN customer_company cc2 ON cc2.id = m.clientele_sub_id
  139. LEFT JOIN customer_linkman cl1 ON cl1.id = m.clientele_contact_id
  140. <where>
  141. m.financial is not null
  142. <if test="keyword!=null and keyword!='' ">
  143. and (
  144. m.order_id like concat ('%',#{keyword},'%')
  145. or f.production_no like concat ('%',#{keyword},'%')
  146. or u1.name like concat ('%',#{keyword},'%')
  147. or fc.claim_amount = #{keyword}
  148. or u2.NAME like concat ('%',#{keyword},'%')
  149. )
  150. </if>
  151. <if test="majorStat!=null and majorStat.payStartDate!=null and majorStat.payStartDate!='' ">
  152. and frf.pay_datetime &gt;= #{majorStat.payStartDate}
  153. </if>
  154. <if test="majorStat!=null and majorStat.payEndDate!=null and majorStat.payEndDate!='' ">
  155. and frf.pay_datetime &lt;= #{majorStat.payEndDate}
  156. </if>
  157. <if test="majorStat!=null and majorStat.ifSaveFile!=null ">
  158. and mp.if_save_file = #{majorStat.ifSaveFile}
  159. </if>
  160. <if test="majorStat!=null and majorStat.financial!=null ">
  161. and m.financial = #{majorStat.financial}
  162. </if>
  163. </where>
  164. </sql>
  165. <select id="majorStat" parameterType="com.dayou.vo.RealFundMajorStatVO" resultType="com.dayou.vo.RealFundMajorStatVO">
  166. <include refid="majorStatQuery" />
  167. ORDER BY
  168. fc.claim_datetime DESC
  169. </select>
  170. <select id="majorStatExport" parameterType="com.dayou.vo.RealFundMajorStatVO" resultType="com.dayou.vo.RealFundMajorStatVO">
  171. <include refid="majorStatQuery" />
  172. ORDER BY
  173. fc.claim_datetime ASC
  174. </select>
  175. <!--资产实收款统计-->
  176. <sql id="assetsStatQuery">
  177. SELECT
  178. claim.real_fund_id,
  179. claim.order_fund_id,
  180. claim.production_fund_id,
  181. claim.id,
  182. prod.production_no AS reportNo,
  183. assets.order_id AS orderId,
  184. assets.`name` AS orderName,
  185. (
  186. SELECT
  187. GROUP_CONCAT(DISTINCT department.name SEPARATOR '、' )
  188. FROM
  189. department,
  190. post,
  191. user_post,
  192. `user`
  193. WHERE
  194. `user`.id = user_post.user_id
  195. AND user_post.post_id = post.id
  196. AND post.department_id = department.id
  197. AND `user`.id = assets.client_manager_id
  198. AND user_post.deleted = 0
  199. ) AS marketDepartment,
  200. ( SELECT department.name FROM department WHERE department.id = assets.department_id ) AS evaluateDepartment,
  201. managerUser.name AS clientManagerName,
  202. principalUser.name AS principalName,
  203. realFund.payer AS payer,
  204. realFund.pay_datetime AS payDateTime,
  205. order_fund.should_amount AS orderShouldAmount,
  206. prodFund.production_should_amount AS prodShouldAmount,
  207. claim.claim_amount AS claimAmount,
  208. claimUser.name AS claimUser,
  209. claim.claim_datetime AS claimDatetime,
  210. assets.assets_business_gener AS assetsBusinessGener,
  211. ( SELECT customer_company.name FROM customer_company WHERE customer_company.id = assets.clientele_id ) AS clientName,
  212. ( SELECT customer_company.name FROM customer_company WHERE customer_company.id = assets.clientele_sub_id ) AS clientSubName,
  213. assets.bailor AS bailor,
  214. prod.evaluate_amount,
  215. (
  216. CASE
  217. WHEN prod.production_type = 'REPORT' THEN '评估报告'
  218. WHEN prod.production_type = 'CONSULT' THEN '咨询报告'
  219. WHEN prod.production_type = 'LETTER' THEN '意见函'
  220. ELSE '其他'
  221. END
  222. ) AS productionType,
  223. prod.if_save_file AS ifSaveFile,
  224. assets.members
  225. FROM
  226. finance_claim AS claim
  227. LEFT JOIN finance_real_fund AS realFund ON realFund.id = claim.real_fund_id
  228. LEFT JOIN order_fund ON order_fund.id = claim.order_fund_id
  229. LEFT JOIN production_fund AS prodFund ON prodFund.id = claim.production_fund_id
  230. LEFT JOIN assets ON assets.id = order_fund.business_id
  231. AND assets.order_id = order_fund.order_id
  232. LEFT JOIN `user` AS managerUser ON managerUser.id = assets.client_manager_id
  233. LEFT JOIN `user` AS principalUser ON principalUser.id = assets.principal_id
  234. LEFT JOIN `user` AS claimUser ON claimUser.id = claim.claim_user_id
  235. LEFT JOIN assets_production AS prod ON assets.id = prod.business_id AND prodFund.production_no = prod.production_no
  236. WHERE order_fund.business_type = 'ASSET_BUSINESS' and claim.deleted = 0
  237. <if test="keyword!=null and keyword!='' ">
  238. and (
  239. assets.order_id like concat ('%',#{keyword},'%')
  240. or prod.production_no like concat ('%',#{keyword},'%')
  241. )
  242. </if>
  243. <if test="dto != null and dto.principalId != null and dto.principalId != ''">
  244. AND assets.principal_id = #{dto.principalId}
  245. </if>
  246. <if test="dto != null and dto.claimUserId != null and dto.claimUserId != ''">
  247. AND claim.claim_user_id = #{dto.claimUserId}
  248. </if>
  249. <if test="dto != null and dto.claimAmount != null and dto.claimAmount != ''">
  250. AND claim.claim_amount = #{dto.claimAmount}
  251. </if>
  252. <if test="dto != null and dto.assetsBusinessGener != null and dto.assetsBusinessGener != ''">
  253. AND assets.assets_business_gener = #{dto.assetsBusinessGener}
  254. </if>
  255. <if test="dto != null and dto.ifSaveFile != null and dto.ifSaveFile != ''">
  256. AND prod.if_save_file = #{dto.ifSaveFile}
  257. </if>
  258. <if test="dto != null and dto.startTime != null and dto.endTime!= null">
  259. AND (claim.claim_datetime BETWEEN #{dto.startTime} AND #{dto.endTime})
  260. </if>
  261. <if test="dto != null and dto.payStartTime != null and dto.payEndTime!= null">
  262. AND (realFund.pay_datetime BETWEEN #{dto.payStartTime} AND #{dto.payEndTime})
  263. </if>
  264. </sql>
  265. <!--查询资产实收款统计-->
  266. <select id="assetsSate" parameterType="com.dayou.dto.RealFundAssetsStatDTO" resultType="com.dayou.vo.RealFundAssetsStatVO">
  267. <include refid="assetsStatQuery" />
  268. ORDER BY claim.claim_datetime DESC
  269. </select>
  270. <!--资产实收款统计导出-->
  271. <select id="assetsSateExport" resultType="com.dayou.vo.RealFundAssetsStatVO">
  272. <include refid="assetsStatQuery" />
  273. ORDER BY claim.claim_datetime ASC
  274. </select>
  275. <sql id="personalStatSql">
  276. SELECT
  277. fc.*,
  278. f.should_amount,
  279. p.order_id,
  280. p.location,
  281. u.NAME AS clientManager,
  282. cc1.NAME AS clientName,
  283. cc2.NAME AS clientSubName,
  284. frf.pay_datetime,
  285. u2.NAME AS claimUser,
  286. p.bailorA,
  287. ( pt.amount / 10000 ) AS amount,
  288. p.if_save_file,
  289. (
  290. SELECT
  291. GROUP_CONCAT( NAME SEPARATOR '、' )
  292. FROM
  293. department
  294. WHERE
  295. id IN (
  296. SELECT
  297. department_id
  298. FROM
  299. post
  300. WHERE
  301. id IN ( SELECT post_id FROM user_post WHERE user_id = u.id ))) AS marketDepartment
  302. FROM
  303. (
  304. SELECT
  305. orderFund.id AS oId,
  306. orderFund.business_id,
  307. orderFund.order_id,
  308. orderFund.should_amount
  309. FROM
  310. order_fund orderFund
  311. WHERE
  312. orderFund.business_type = 'PERSONAL_BUSINESS'
  313. AND orderFund.deleted = 0
  314. ) f
  315. INNER JOIN
  316. (select * from finance_claim where deleted = 0
  317. AND claim_datetime &gt;= #{dto.startTime}
  318. AND claim_datetime &lt;= #{dto.endTime}
  319. )
  320. fc ON fc.order_fund_id = f.oId
  321. LEFT JOIN personal p ON f.business_id = p.id
  322. LEFT JOIN user u ON u.id = p.client_manager_id
  323. LEFT JOIN customer_company cc1 ON cc1.id = p.clientele_id
  324. LEFT JOIN customer_company cc2 ON cc2.id = p.clientele_sub_id
  325. LEFT JOIN finance_real_fund frf ON frf.id = fc.real_fund_id
  326. LEFT JOIN user u2 ON u2.id = fc.claim_user_id
  327. LEFT JOIN personal_target pt ON pt.personal_id = p.id
  328. WHERE
  329. p.deleted = 0 and fc.deleted = 0
  330. <if test="dto != null and dto.orderId != null and dto.orderId != ''">
  331. AND p.order_id = #{dto.orderId}
  332. </if>
  333. <if test="dto != null and dto.claimUser != null and dto.claimUser != ''">
  334. AND u2.NAME like concat ('%',#{dto.claimUser},'%')
  335. </if>
  336. <if test="dto != null and dto.claimAmount != null and dto.claimAmount != ''">
  337. AND fc.claim_amount = #{dto.claimAmount}
  338. </if>
  339. <if test="dto != null and dto.ifSaveFile != null">
  340. AND p.if_save_file = #{dto.ifSaveFile}
  341. </if>
  342. <if test="dto != null and dto.payStartTime != null and dto.payEndTime!= null">
  343. AND (frf.pay_datetime BETWEEN #{dto.payStartTime} AND #{dto.payEndTime})
  344. </if>
  345. ORDER BY
  346. fc.claim_datetime DESC
  347. </sql>
  348. <select id="personalStat" parameterType="com.dayou.vo.RealFundPersonalVO" resultType="com.dayou.vo.RealFundPersonalVO">
  349. <include refid="personalStatSql" />
  350. </select>
  351. <select id="personalStatExport" parameterType="com.dayou.vo.RealFundPersonalVO" resultType="com.dayou.vo.RealFundPersonalVO">
  352. <include refid="personalStatSql" />
  353. </select>
  354. <select id="queryOrderTotalAmount" resultType="com.dayou.entity.OrderFund">
  355. SELECT
  356. fc.order_fund_id as id,
  357. realAmount,
  358. oof.business_type
  359. FROM
  360. ( SELECT order_fund_id, sum( claim_amount ) realAmount FROM finance_claim WHERE deleted = 0 GROUP BY order_fund_id ) fc
  361. LEFT JOIN order_fund oof ON oof.id = fc.order_fund_id
  362. </select>
  363. <sql id="claimList">
  364. SELECT
  365. fc.id,
  366. frf.payer,
  367. frf.amount,
  368. frf.pay_datetime,
  369. fc.claim_amount,
  370. u.NAME AS creator,
  371. frf.created,
  372. frf.remark,
  373. u1.name as claimUser,
  374. fc.claim_datetime ,
  375. ( CASE off.business_type WHEN 'MAJOR_BUSINESS' THEN '大中型业务' WHEN 'PERSONAL_BUSINESS' THEN '个贷业务' WHEN 'ASSET_BUSINESS' THEN '资产业务' WHEN 'ITEM_BUSINESS' THEN '土规业务' ELSE '-' END ) AS businessType,
  376. off.order_id,
  377. u2.name AS clientManager
  378. FROM
  379. finance_claim fc
  380. LEFT JOIN finance_real_fund frf ON frf.id = fc.real_fund_id
  381. left join user u on u.id = frf.creator_id
  382. left join user u1 on u1.id = fc.claim_user_id
  383. left join order_fund off on off.id = fc.order_fund_id
  384. LEFT JOIN user u2 ON u2.id = off.client_manager_id
  385. where frf.deleted = 0 and fc.deleted = 0
  386. <if test="keyword!=null and keyword!='' ">
  387. and (
  388. frf.payer like concat ('%',#{keyword},'%')
  389. or frf.payer_bank like concat('%',#{keyword},'%')
  390. or u.name like concat('%',#{keyword},'%')
  391. or frf.payer_account like concat('%',#{keyword},'%')
  392. or frf.amount like concat('%',#{keyword},'%')
  393. or frf.remark like concat('%',#{keyword},'%')
  394. or off.order_id = #{keyword}
  395. )
  396. </if>
  397. <if test="vo!=null and vo.startDate!=null and vo.startDate!=''">
  398. and frf.pay_datetime &gt;= #{vo.startDate}
  399. </if>
  400. <if test="vo!=null and vo.endDate!=null and vo.endDate!=''">
  401. and frf.pay_datetime &lt;= #{vo.endDate}
  402. </if>
  403. <if test="vo!=null and vo.xStartDate!=null and vo.xStartDate!=''">
  404. and fc.claim_datetime &gt;= #{vo.xStartDate}
  405. </if>
  406. <if test="vo!=null and vo.xEndDate!=null and vo.xEndDate!=''">
  407. and fc.claim_datetime &lt;= #{vo.xEndDate}
  408. </if>
  409. <if test="vo!=null and vo.businessType!=null and vo.businessType!=''">
  410. and off.business_type = #{vo.businessType}
  411. </if>
  412. <if test="vo!=null and vo.claimUserId!=null and vo.claimUserId!=''">
  413. and fc.claim_user_id = #{vo.claimUserId}
  414. </if>
  415. <if test="vo!=null and vo.userIds!=null and vo.userIds.size!=0">
  416. and off.client_manager_id in
  417. <foreach collection="vo.userIds" open="(" close=")" separator="," item="userId">
  418. #{userId}
  419. </foreach>
  420. </if>
  421. order by fc.claim_datetime DESC
  422. </sql>
  423. <select id="financeClaimsList" parameterType="com.dayou.vo.FinanceClaimsVO" resultType="com.dayou.vo.FinanceClaimsVO">
  424. <include refid="claimList" />
  425. </select>
  426. <select id="exportList" parameterType="com.dayou.vo.FinanceClaimsVO" resultType="com.dayou.vo.FinanceClaimsVO">
  427. <include refid="claimList" />
  428. </select>
  429. <select id="updateClaimProductionId" resultType="com.dayou.dto.history.HisClaimProd">
  430. SELECT
  431. t.id,
  432. p.id AS pid,
  433. fc.id AS fcid,
  434. fc.production_fund_id
  435. FROM
  436. ( SELECT id, created FROM order_fund WHERE business_type = #{businessType} AND deleted = 0 ) t
  437. LEFT JOIN ( SELECT id, order_fund_id FROM production_fund WHERE business_type = #{businessType} AND deleted = 0 ) p ON t.id = p.order_fund_id
  438. LEFT JOIN ( SELECT id, production_fund_id, order_fund_id FROM finance_claim WHERE deleted = 0 ) fc ON fc.order_fund_id = t.id
  439. WHERE
  440. fc.id IS NOT NULL and p.id is not null and fc.production_fund_id is null
  441. ORDER BY
  442. t.created DESC
  443. </select>
  444. </mapper>