FinanceClaimMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. f.order_id,
  69. f.should_amount 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 ))) AS marketDepartment
  99. FROM
  100. (
  101. SELECT
  102. p.order_fund_id oId,
  103. p.id AS pId,
  104. p.business_id,
  105. o.order_id,
  106. p.production_no,
  107. o.should_amount
  108. FROM
  109. production_fund p left join (select id,order_id,should_amount from order_fund where business_type='MAJOR_BUSINESS' and deleted = 0) o on o.id = p.order_fund_id
  110. WHERE
  111. p.business_type = 'MAJOR_BUSINESS'
  112. AND p.deleted = 0
  113. ) f
  114. INNER JOIN finance_claim fc ON
  115. ( fc.order_fund_id = f.oId and fc.production_fund_id = f.pId)
  116. LEFT JOIN major m ON f.business_id = m.id
  117. LEFT JOIN user u ON u.id = m.client_manager_id
  118. LEFT JOIN user u1 ON u1.id = m.principal_id
  119. LEFT JOIN department d ON d.id = m.department_id
  120. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_id
  121. LEFT JOIN customer_company cc2 ON cc2.id = m.clientele_sub_id
  122. LEFT JOIN customer_linkman cl1 ON cl1.id = m.clientele_contact_id
  123. LEFT JOIN finance_real_fund frf ON frf.id = fc.real_fund_id
  124. LEFT JOIN ( SELECT major_id, report_no,production, evaluate_amount, if_save_file, NAME FROM major_production WHERE deleted = 0 ) mp ON ( mp.major_id = m.id AND mp.report_no = f.production_no )
  125. LEFT JOIN user u2 ON u2.id = fc.claim_user_id
  126. where m.deleted = 0
  127. <if test="keyword!=null and keyword!='' ">
  128. and (
  129. f.order_id like concat ('%',#{keyword},'%')
  130. or f.production_no like concat ('%',#{keyword},'%')
  131. or u1.name like concat ('%',#{keyword},'%')
  132. or fc.claim_amount = #{keyword}
  133. or u2.NAME like concat ('%',#{keyword},'%')
  134. )
  135. </if>
  136. <if test="majorStat!=null and majorStat.startDate!=null and majorStat.startDate!='' ">
  137. and fc.claim_datetime &gt;= #{majorStat.startDate}
  138. </if>
  139. <if test="majorStat!=null and majorStat.endDate!=null and majorStat.endDate!='' ">
  140. and fc.claim_datetime &lt;= #{majorStat.endDate}
  141. </if>
  142. <if test="majorStat!=null and majorStat.payStartDate!=null and majorStat.payStartDate!='' ">
  143. and frf.pay_datetime &gt;= #{majorStat.payStartDate}
  144. </if>
  145. <if test="majorStat!=null and majorStat.payEndDate!=null and majorStat.payEndDate!='' ">
  146. and frf.pay_datetime &lt;= #{majorStat.payEndDate}
  147. </if>
  148. <if test="majorStat!=null and majorStat.ifSaveFile!=null ">
  149. and mp.if_save_file = #{majorStat.ifSaveFile}
  150. </if>
  151. <if test="majorStat!=null and majorStat.financial!=null ">
  152. and m.financial = #{majorStat.financial}
  153. </if>
  154. </sql>
  155. <select id="majorStat" parameterType="com.dayou.vo.RealFundMajorStatVO" resultType="com.dayou.vo.RealFundMajorStatVO">
  156. <include refid="majorStatQuery" />
  157. ORDER BY
  158. fc.claim_datetime DESC
  159. </select>
  160. <select id="majorStatExport" parameterType="com.dayou.vo.RealFundMajorStatVO" resultType="com.dayou.vo.RealFundMajorStatVO">
  161. <include refid="majorStatQuery" />
  162. ORDER BY
  163. fc.claim_datetime ASC
  164. </select>
  165. <!--资产实收款统计-->
  166. <sql id="assetsStatQuery">
  167. SELECT
  168. claim.real_fund_id,
  169. claim.order_fund_id,
  170. claim.production_fund_id,
  171. claim.id,
  172. prod.production_no AS reportNo,
  173. assets.order_id AS orderId,
  174. assets.`name` AS orderName,
  175. (
  176. SELECT
  177. GROUP_CONCAT( department.name SEPARATOR '、' )
  178. FROM
  179. department,
  180. post,
  181. user_post,
  182. `user`
  183. WHERE
  184. `user`.id = user_post.user_id
  185. AND user_post.post_id = post.id
  186. AND post.department_id = department.id
  187. AND `user`.id = assets.client_manager_id
  188. AND user_post.deleted = 0
  189. ) AS marketDepartment,
  190. ( SELECT department.name FROM department WHERE department.id = assets.department_id ) AS evaluateDepartment,
  191. managerUser.name AS clientManagerName,
  192. principalUser.name AS principalName,
  193. realFund.payer AS payer,
  194. realFund.pay_datetime AS payDateTime,
  195. order_fund.should_amount AS orderShouldAmount,
  196. prodFund.production_should_amount AS prodShouldAmount,
  197. claim.claim_amount AS claimAmount,
  198. claimUser.name AS claimUser,
  199. claim.claim_datetime AS claimDatetime,
  200. assets.assets_business_gener AS assetsBusinessGener,
  201. ( SELECT customer_company.name FROM customer_company WHERE customer_company.id = assets.clientele_id ) AS clientName,
  202. ( SELECT customer_company.name FROM customer_company WHERE customer_company.id = assets.clientele_sub_id ) AS clientSubName,
  203. assets.bailor AS bailor,
  204. prod.evaluate_amount,
  205. (
  206. CASE
  207. WHEN prod.production_type = 'REPORT' THEN '评估报告'
  208. WHEN prod.production_type = 'CONSULT' THEN '咨询报告'
  209. WHEN prod.production_type = 'LETTER' THEN '意见函'
  210. ELSE '其他'
  211. END
  212. ) AS productionType,
  213. prod.if_save_file AS ifSaveFile
  214. FROM
  215. finance_claim AS claim
  216. LEFT JOIN finance_real_fund AS realFund ON realFund.id = claim.real_fund_id
  217. LEFT JOIN order_fund ON order_fund.id = claim.order_fund_id
  218. LEFT JOIN production_fund AS prodFund ON prodFund.id = claim.production_fund_id
  219. LEFT JOIN assets ON assets.id = order_fund.business_id
  220. AND assets.order_id = order_fund.order_id
  221. LEFT JOIN `user` AS managerUser ON managerUser.id = assets.client_manager_id
  222. LEFT JOIN `user` AS principalUser ON principalUser.id = assets.principal_id
  223. LEFT JOIN `user` AS claimUser ON claimUser.id = claim.claim_user_id
  224. LEFT JOIN assets_production AS prod ON assets.id = prod.business_id AND prodFund.production_no = prod.production_no
  225. WHERE order_fund.business_type = 'ASSET_BUSINESS'
  226. <if test="keyword!=null and keyword!='' ">
  227. and (
  228. assets.order_id like concat ('%',#{keyword},'%')
  229. or prod.production_no like concat ('%',#{keyword},'%')
  230. )
  231. </if>
  232. <if test="dto != null and dto.principalId != null and dto.principalId != ''">
  233. AND assets.principal_id = #{dto.principalId}
  234. </if>
  235. <if test="dto != null and dto.claimUserId != null and dto.claimUserId != ''">
  236. AND claim.claim_user_id = #{dto.claimUserId}
  237. </if>
  238. <if test="dto != null and dto.claimAmount != null and dto.claimAmount != ''">
  239. AND claim.claim_amount = #{dto.claimAmount}
  240. </if>
  241. <if test="dto != null and dto.assetsBusinessGener != null and dto.assetsBusinessGener != ''">
  242. AND assets.assets_business_gener = #{dto.assetsBusinessGener}
  243. </if>
  244. <if test="dto != null and dto.ifSaveFile != null and dto.ifSaveFile != ''">
  245. AND prod.if_save_file = #{dto.ifSaveFile}
  246. </if>
  247. <if test="dto != null and dto.startTime != null and dto.endTime!= null">
  248. AND (claim.claim_datetime BETWEEN #{dto.startTime} AND #{dto.endTime})
  249. </if>
  250. <if test="dto != null and dto.payStartTime != null and dto.payEndTime!= null">
  251. AND (realFund.pay_datetime BETWEEN #{dto.payStartTime} AND #{dto.payEndTime})
  252. </if>
  253. ORDER BY claim.claim_datetime DESC
  254. </sql>
  255. <!--查询资产实收款统计-->
  256. <select id="assetsSate" parameterType="com.dayou.dto.RealFundAssetsStatDTO" resultType="com.dayou.vo.RealFundAssetsStatVO">
  257. <include refid="assetsStatQuery" />
  258. </select>
  259. <!--资产实收款统计导出-->
  260. <select id="assetsSateExport" resultType="com.dayou.vo.RealFundAssetsStatVO">
  261. <include refid="assetsStatQuery" />
  262. </select>
  263. <sql id="personalStatSql">
  264. SELECT
  265. fc.*,
  266. f.should_amount,
  267. p.order_id,
  268. p.location,
  269. u.NAME AS clientManager,
  270. cc1.NAME AS clientName,
  271. cc2.NAME AS clientSubName,
  272. frf.pay_datetime,
  273. u2.NAME AS claimUser,
  274. p.bailorA,
  275. ( pt.amount / 10000 ) AS amount,
  276. p.if_save_file,
  277. (
  278. SELECT
  279. GROUP_CONCAT( NAME SEPARATOR '、' )
  280. FROM
  281. department
  282. WHERE
  283. id IN (
  284. SELECT
  285. department_id
  286. FROM
  287. post
  288. WHERE
  289. id IN ( SELECT post_id FROM user_post WHERE user_id = u.id ))) AS marketDepartment
  290. FROM
  291. (
  292. SELECT
  293. orderFund.id AS oId,
  294. orderFund.business_id,
  295. orderFund.order_id,
  296. orderFund.should_amount
  297. FROM
  298. order_fund orderFund
  299. WHERE
  300. orderFund.business_type = 'PERSONAL_BUSINESS'
  301. AND orderFund.deleted = 0
  302. ) f
  303. INNER JOIN finance_claim fc ON fc.order_fund_id = f.oId
  304. LEFT JOIN personal p ON f.business_id = p.id
  305. LEFT JOIN user u ON u.id = p.client_manager_id
  306. LEFT JOIN customer_company cc1 ON cc1.id = p.clientele_id
  307. LEFT JOIN customer_company cc2 ON cc2.id = p.clientele_sub_id
  308. LEFT JOIN finance_real_fund frf ON frf.id = fc.real_fund_id
  309. LEFT JOIN user u2 ON u2.id = fc.claim_user_id
  310. LEFT JOIN personal_target pt ON pt.personal_id = p.id
  311. WHERE
  312. p.deleted = 0
  313. <if test="dto != null and dto.orderId != null and dto.orderId != ''">
  314. AND p.order_id = #{dto.orderId}
  315. </if>
  316. <if test="dto != null and dto.claimUser != null and dto.claimUser != ''">
  317. AND u2.NAME like concat ('%',#{dto.claimUser},'%')
  318. </if>
  319. <if test="dto != null and dto.claimAmount != null and dto.claimAmount != ''">
  320. AND fc.claim_amount = #{dto.claimAmount}
  321. </if>
  322. <if test="dto != null and dto.ifSaveFile != null">
  323. AND p.if_save_file = #{dto.ifSaveFile}
  324. </if>
  325. <if test="dto != null and dto.startTime != null and dto.endTime!= null">
  326. AND (fc.claim_datetime BETWEEN #{dto.startTime} AND #{dto.endTime})
  327. </if>
  328. <if test="dto != null and dto.payStartTime != null and dto.payEndTime!= null">
  329. AND (frf.pay_datetime BETWEEN #{dto.payStartTime} AND #{dto.payEndTime})
  330. </if>
  331. ORDER BY
  332. fc.claim_datetime DESC
  333. </sql>
  334. <select id="personalStat" parameterType="com.dayou.vo.RealFundPersonalVO" resultType="com.dayou.vo.RealFundPersonalVO">
  335. <include refid="personalStatSql" />
  336. </select>
  337. <select id="personalStatExport" parameterType="com.dayou.vo.RealFundPersonalVO" resultType="com.dayou.vo.RealFundPersonalVO">
  338. <include refid="personalStatSql" />
  339. </select>
  340. <select id="queryOrderTotalAmount" resultType="com.dayou.entity.OrderFund">
  341. SELECT
  342. fc.order_fund_id as id,
  343. realAmount,
  344. oof.business_type
  345. FROM
  346. ( SELECT order_fund_id, sum( claim_amount ) realAmount FROM finance_claim WHERE deleted = 0 GROUP BY order_fund_id ) fc
  347. LEFT JOIN order_fund oof ON oof.id = fc.order_fund_id
  348. </select>
  349. </mapper>