FinanceClaimMapper.xml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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. p.production_type
  112. FROM
  113. production_fund p
  114. WHERE
  115. p.business_type = 'MAJOR_BUSINESS'
  116. AND p.deleted = 0
  117. ) f ON ( fc.order_fund_id = f.oId AND fc.production_fund_id = f.pId )
  118. LEFT JOIN major m ON f.business_id = m.id
  119. LEFT JOIN finance_real_fund frf ON frf.id = fc.real_fund_id
  120. LEFT JOIN (
  121. SELECT
  122. mpp.major_id,
  123. mpp.report_no,
  124. mpp.production,
  125. mpp.evaluate_amount,
  126. mpp.if_save_file,
  127. mpp.NAME
  128. FROM
  129. major_production mpp
  130. 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 )
  131. WHERE
  132. ppf.real_amount IS NOT NULL
  133. ) mp ON ( mp.major_id = m.id AND mp.report_no = f.production_no and mp.production = f.production_type )
  134. LEFT JOIN user u2 ON u2.id = fc.claim_user_id
  135. LEFT JOIN user u ON u.id = m.client_manager_id
  136. LEFT JOIN user u1 ON u1.id = m.principal_id
  137. LEFT JOIN department d ON d.id = m.department_id
  138. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_id
  139. LEFT JOIN customer_company cc2 ON cc2.id = m.clientele_sub_id
  140. LEFT JOIN customer_linkman cl1 ON cl1.id = m.clientele_contact_id
  141. <where>
  142. m.financial is not null
  143. <if test="keyword!=null and keyword!='' ">
  144. and (
  145. m.order_id like concat ('%',#{keyword},'%')
  146. or f.production_no like concat ('%',#{keyword},'%')
  147. or u1.name like concat ('%',#{keyword},'%')
  148. or fc.claim_amount = #{keyword}
  149. or u2.NAME like concat ('%',#{keyword},'%')
  150. )
  151. </if>
  152. <if test="majorStat!=null and majorStat.payStartDate!=null and majorStat.payStartDate!='' ">
  153. and frf.pay_datetime &gt;= #{majorStat.payStartDate}
  154. </if>
  155. <if test="majorStat!=null and majorStat.payEndDate!=null and majorStat.payEndDate!='' ">
  156. and frf.pay_datetime &lt;= #{majorStat.payEndDate}
  157. </if>
  158. <if test="majorStat!=null and majorStat.ifSaveFile!=null ">
  159. and mp.if_save_file = #{majorStat.ifSaveFile}
  160. </if>
  161. <if test="majorStat!=null and majorStat.financial!=null ">
  162. and m.financial = #{majorStat.financial}
  163. </if>
  164. <if test="majorStat!=null and majorStat.evaluateDepartmentName!=null and majorStat.evaluateDepartmentName!='' ">
  165. and d.name = #{majorStat.evaluateDepartmentName}
  166. </if>
  167. </where>
  168. </sql>
  169. <select id="majorStat" parameterType="com.dayou.vo.RealFundMajorStatVO" resultType="com.dayou.vo.RealFundMajorStatVO">
  170. <include refid="majorStatQuery" />
  171. ORDER BY
  172. fc.claim_datetime DESC
  173. </select>
  174. <select id="majorStatExport" parameterType="com.dayou.vo.RealFundMajorStatVO" resultType="com.dayou.vo.RealFundMajorStatVO">
  175. <include refid="majorStatQuery" />
  176. ORDER BY
  177. fc.claim_datetime ASC
  178. </select>
  179. <!--资产实收款统计-->
  180. <sql id="assetsStatQuery">
  181. SELECT
  182. claim.real_fund_id,
  183. claim.order_fund_id,
  184. claim.production_fund_id,
  185. claim.id,
  186. prod.production_no AS reportNo,
  187. assets.order_id AS orderId,
  188. assets.`name` AS orderName,
  189. (
  190. SELECT
  191. GROUP_CONCAT(DISTINCT department.name SEPARATOR '、' )
  192. FROM
  193. department,
  194. post,
  195. user_post,
  196. `user`
  197. WHERE
  198. `user`.id = user_post.user_id
  199. AND user_post.post_id = post.id
  200. AND post.department_id = department.id
  201. AND `user`.id = assets.client_manager_id
  202. AND user_post.deleted = 0
  203. ) AS marketDepartment,
  204. ( SELECT department.name FROM department WHERE department.id = assets.department_id ) AS evaluateDepartment,
  205. managerUser.name AS clientManagerName,
  206. principalUser.name AS principalName,
  207. realFund.payer AS payer,
  208. realFund.pay_datetime AS payDateTime,
  209. order_fund.should_amount AS orderShouldAmount,
  210. prodFund.production_should_amount AS prodShouldAmount,
  211. claim.claim_amount AS claimAmount,
  212. claimUser.name AS claimUser,
  213. claim.claim_datetime AS claimDatetime,
  214. assets.assets_business_gener AS assetsBusinessGener,
  215. ( SELECT customer_company.name FROM customer_company WHERE customer_company.id = assets.clientele_id ) AS clientName,
  216. ( SELECT customer_company.name FROM customer_company WHERE customer_company.id = assets.clientele_sub_id ) AS clientSubName,
  217. assets.bailor AS bailor,
  218. prod.evaluate_amount,
  219. (
  220. CASE
  221. WHEN prod.production_type = 'REPORT' THEN '评估报告'
  222. WHEN prod.production_type = 'CONSULT' THEN '咨询报告'
  223. WHEN prod.production_type = 'LETTER' THEN '意见函'
  224. ELSE '其他'
  225. END
  226. ) AS productionType,
  227. prod.if_save_file AS ifSaveFile,
  228. assets.members
  229. FROM
  230. finance_claim AS claim
  231. LEFT JOIN finance_real_fund AS realFund ON realFund.id = claim.real_fund_id
  232. LEFT JOIN order_fund ON order_fund.id = claim.order_fund_id
  233. LEFT JOIN production_fund AS prodFund ON prodFund.id = claim.production_fund_id
  234. LEFT JOIN assets ON assets.id = order_fund.business_id
  235. AND assets.order_id = order_fund.order_id
  236. LEFT JOIN `user` AS managerUser ON managerUser.id = assets.client_manager_id
  237. LEFT JOIN `user` AS principalUser ON principalUser.id = assets.principal_id
  238. LEFT JOIN `user` AS claimUser ON claimUser.id = claim.claim_user_id
  239. LEFT JOIN assets_production AS prod ON assets.id = prod.business_id AND prodFund.production_no = prod.production_no
  240. WHERE order_fund.business_type = 'ASSET_BUSINESS' and claim.deleted = 0
  241. <if test="keyword!=null and keyword!='' ">
  242. and (
  243. assets.order_id like concat ('%',#{keyword},'%')
  244. or prod.production_no like concat ('%',#{keyword},'%')
  245. )
  246. </if>
  247. <if test="dto != null and dto.principalId != null and dto.principalId != ''">
  248. AND assets.principal_id = #{dto.principalId}
  249. </if>
  250. <if test="dto != null and dto.claimUserId != null and dto.claimUserId != ''">
  251. AND claim.claim_user_id = #{dto.claimUserId}
  252. </if>
  253. <if test="dto != null and dto.claimAmount != null and dto.claimAmount != ''">
  254. AND claim.claim_amount = #{dto.claimAmount}
  255. </if>
  256. <if test="dto != null and dto.assetsBusinessGener != null and dto.assetsBusinessGener != ''">
  257. AND assets.assets_business_gener = #{dto.assetsBusinessGener}
  258. </if>
  259. <if test="dto != null and dto.ifSaveFile != null and dto.ifSaveFile != ''">
  260. AND prod.if_save_file = #{dto.ifSaveFile}
  261. </if>
  262. <if test="dto != null and dto.startTime != null and dto.endTime!= null">
  263. AND (claim.claim_datetime BETWEEN #{dto.startTime} AND #{dto.endTime})
  264. </if>
  265. <if test="dto != null and dto.payStartTime != null and dto.payEndTime!= null">
  266. AND (realFund.pay_datetime BETWEEN #{dto.payStartTime} AND #{dto.payEndTime})
  267. </if>
  268. </sql>
  269. <!--查询资产实收款统计-->
  270. <select id="assetsSate" parameterType="com.dayou.dto.RealFundAssetsStatDTO" resultType="com.dayou.vo.RealFundAssetsStatVO">
  271. <include refid="assetsStatQuery" />
  272. ORDER BY claim.claim_datetime DESC
  273. </select>
  274. <!--资产实收款统计导出-->
  275. <select id="assetsSateExport" resultType="com.dayou.vo.RealFundAssetsStatVO">
  276. <include refid="assetsStatQuery" />
  277. ORDER BY claim.claim_datetime ASC
  278. </select>
  279. <sql id="personalStatSql">
  280. SELECT
  281. fc.*,
  282. f.should_amount,
  283. p.order_id,
  284. p.location,
  285. u.NAME AS clientManager,
  286. cc1.NAME AS clientName,
  287. cc2.NAME AS clientSubName,
  288. frf.pay_datetime,
  289. u2.NAME AS claimUser,
  290. p.bailorA,
  291. ( pt.amount / 10000 ) AS amount,
  292. p.if_save_file,
  293. (
  294. SELECT
  295. GROUP_CONCAT( NAME SEPARATOR '、' )
  296. FROM
  297. department
  298. WHERE
  299. id IN (
  300. SELECT
  301. department_id
  302. FROM
  303. post
  304. WHERE
  305. id IN ( SELECT post_id FROM user_post WHERE user_id = u.id ))) AS marketDepartment
  306. FROM
  307. (
  308. SELECT
  309. orderFund.id AS oId,
  310. orderFund.business_id,
  311. orderFund.order_id,
  312. orderFund.should_amount
  313. FROM
  314. order_fund orderFund
  315. WHERE
  316. orderFund.business_type = 'PERSONAL_BUSINESS'
  317. AND orderFund.deleted = 0
  318. ) f
  319. INNER JOIN
  320. (select * from finance_claim where deleted = 0
  321. AND claim_datetime &gt;= #{dto.startTime}
  322. AND claim_datetime &lt;= #{dto.endTime}
  323. )
  324. fc ON fc.order_fund_id = f.oId
  325. LEFT JOIN personal p ON f.business_id = p.id
  326. LEFT JOIN user u ON u.id = p.client_manager_id
  327. LEFT JOIN customer_company cc1 ON cc1.id = p.clientele_id
  328. LEFT JOIN customer_company cc2 ON cc2.id = p.clientele_sub_id
  329. LEFT JOIN finance_real_fund frf ON frf.id = fc.real_fund_id
  330. LEFT JOIN user u2 ON u2.id = fc.claim_user_id
  331. LEFT JOIN personal_target pt ON pt.personal_id = p.id
  332. WHERE
  333. p.deleted = 0 and fc.deleted = 0
  334. <if test="dto != null and dto.orderId != null and dto.orderId != ''">
  335. AND p.order_id = #{dto.orderId}
  336. </if>
  337. <if test="dto != null and dto.claimUser != null and dto.claimUser != ''">
  338. AND u2.NAME like concat ('%',#{dto.claimUser},'%')
  339. </if>
  340. <if test="dto != null and dto.claimAmount != null and dto.claimAmount != ''">
  341. AND fc.claim_amount = #{dto.claimAmount}
  342. </if>
  343. <if test="dto != null and dto.ifSaveFile != null">
  344. AND p.if_save_file = #{dto.ifSaveFile}
  345. </if>
  346. <if test="dto != null and dto.payStartTime != null and dto.payEndTime!= null">
  347. AND (frf.pay_datetime BETWEEN #{dto.payStartTime} AND #{dto.payEndTime})
  348. </if>
  349. ORDER BY
  350. fc.claim_datetime DESC
  351. </sql>
  352. <select id="personalStat" parameterType="com.dayou.vo.RealFundPersonalVO" resultType="com.dayou.vo.RealFundPersonalVO">
  353. <include refid="personalStatSql" />
  354. </select>
  355. <select id="personalStatExport" parameterType="com.dayou.vo.RealFundPersonalVO" resultType="com.dayou.vo.RealFundPersonalVO">
  356. <include refid="personalStatSql" />
  357. </select>
  358. <select id="queryOrderTotalAmount" resultType="com.dayou.entity.OrderFund">
  359. SELECT
  360. fc.order_fund_id as id,
  361. realAmount,
  362. oof.business_type
  363. FROM
  364. ( SELECT order_fund_id, sum( claim_amount ) realAmount FROM finance_claim WHERE deleted = 0 GROUP BY order_fund_id ) fc
  365. LEFT JOIN order_fund oof ON oof.id = fc.order_fund_id
  366. </select>
  367. <sql id="claimList">
  368. SELECT
  369. fc.id,
  370. frf.payer,
  371. frf.amount,
  372. frf.pay_datetime,
  373. fc.claim_amount,
  374. u.NAME AS creator,
  375. frf.created,
  376. frf.remark,
  377. u1.name as claimUser,
  378. fc.claim_datetime ,
  379. ( CASE off.business_type WHEN 'MAJOR_BUSINESS' THEN '大中型业务' WHEN 'PERSONAL_BUSINESS' THEN '个贷业务' WHEN 'ASSET_BUSINESS' THEN '资产业务' WHEN 'ITEM_BUSINESS' THEN '土规业务' ELSE '-' END ) AS businessType,
  380. off.order_id,
  381. u2.name AS clientManager
  382. FROM
  383. finance_claim fc
  384. LEFT JOIN finance_real_fund frf ON frf.id = fc.real_fund_id
  385. left join user u on u.id = frf.creator_id
  386. left join user u1 on u1.id = fc.claim_user_id
  387. left join order_fund off on off.id = fc.order_fund_id
  388. LEFT JOIN user u2 ON u2.id = off.client_manager_id
  389. where frf.deleted = 0 and fc.deleted = 0
  390. <if test="keyword!=null and keyword!='' ">
  391. and (
  392. frf.payer like concat ('%',#{keyword},'%')
  393. or frf.payer_bank like concat('%',#{keyword},'%')
  394. or u.name like concat('%',#{keyword},'%')
  395. or frf.payer_account like concat('%',#{keyword},'%')
  396. or frf.amount like concat('%',#{keyword},'%')
  397. or frf.remark like concat('%',#{keyword},'%')
  398. or off.order_id = #{keyword}
  399. )
  400. </if>
  401. <if test="vo!=null and vo.startDate!=null and vo.startDate!=''">
  402. and frf.pay_datetime &gt;= #{vo.startDate}
  403. </if>
  404. <if test="vo!=null and vo.endDate!=null and vo.endDate!=''">
  405. and frf.pay_datetime &lt;= #{vo.endDate}
  406. </if>
  407. <if test="vo!=null and vo.xStartDate!=null and vo.xStartDate!=''">
  408. and fc.claim_datetime &gt;= #{vo.xStartDate}
  409. </if>
  410. <if test="vo!=null and vo.xEndDate!=null and vo.xEndDate!=''">
  411. and fc.claim_datetime &lt;= #{vo.xEndDate}
  412. </if>
  413. <if test="vo!=null and vo.businessType!=null and vo.businessType!=''">
  414. and off.business_type = #{vo.businessType}
  415. </if>
  416. <if test="vo!=null and vo.claimUserId!=null and vo.claimUserId!=''">
  417. and fc.claim_user_id = #{vo.claimUserId}
  418. </if>
  419. <if test="vo!=null and vo.userIds!=null and vo.userIds.size!=0">
  420. and off.client_manager_id in
  421. <foreach collection="vo.userIds" open="(" close=")" separator="," item="userId">
  422. #{userId}
  423. </foreach>
  424. </if>
  425. order by fc.claim_datetime DESC
  426. </sql>
  427. <select id="financeClaimsList" parameterType="com.dayou.vo.FinanceClaimsVO" resultType="com.dayou.vo.FinanceClaimsVO">
  428. <include refid="claimList" />
  429. </select>
  430. <select id="exportList" parameterType="com.dayou.vo.FinanceClaimsVO" resultType="com.dayou.vo.FinanceClaimsVO">
  431. <include refid="claimList" />
  432. </select>
  433. <select id="updateClaimProductionId" resultType="com.dayou.dto.history.HisClaimProd">
  434. SELECT
  435. t.id,
  436. p.id AS pid,
  437. fc.id AS fcid,
  438. fc.production_fund_id
  439. FROM
  440. ( SELECT id, created FROM order_fund WHERE business_type = #{businessType} AND deleted = 0 ) t
  441. 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
  442. LEFT JOIN ( SELECT id, production_fund_id, order_fund_id FROM finance_claim WHERE deleted = 0 ) fc ON fc.order_fund_id = t.id
  443. WHERE
  444. fc.id IS NOT NULL and p.id is not null and fc.production_fund_id is null
  445. ORDER BY
  446. t.created DESC
  447. </select>
  448. <select id="getProductionIdByMajorId" parameterType="java.lang.Long" resultType="com.dayou.entity.MajorProduction">
  449. select production_type as production,production_no as reportNo from production_fund where id = ( SELECT
  450. production_fund_id
  451. FROM
  452. finance_claim
  453. WHERE
  454. order_fund_id = (select id
  455. FROM
  456. order_fund
  457. WHERE
  458. business_id = #{businessId}
  459. AND business_type = 'MAJOR_BUSINESS'
  460. AND real_amount IS NOT NULL) and production_fund_id is not null limit 1) and deleted = 0
  461. </select>
  462. </mapper>