BizCollectionMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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="cn.ezhizao.project.business.collection.mapper.BizCollectionMapper">
  4. <!-- 基础的返回map 多表复杂的 自行组合 -->
  5. <resultMap id="BaseResultMap" type="cn.ezhizao.project.business.collection.domain.BizCollection">
  6. </resultMap>
  7. <!--带条件的List查询-->
  8. <select id="getList" resultMap="BaseResultMap">
  9. <include refid="getListSql"/>
  10. order by create_time desc
  11. </select>
  12. <!--带条件的List查询 数据总条数-->
  13. <select id="getTotal" resultType="java.lang.Integer">
  14. SELECT COUNT(1) FROM (<include refid="getListSql"/>) AS C
  15. </select>
  16. <select id="statistics" resultType="resStatisticsVo">
  17. SELECT
  18. tt1.company_id as companyId,
  19. tt1.name as companyName,
  20. tt1.task_type_id as taskTypeId,
  21. tt1.typeName,
  22. tt1.contract_id as contractId,
  23. tt1.contract_no as contractNo,
  24. date_format(tt1.daozhangriqi, '%Y-%m-%d') as receiptDate,
  25. tt1.tishoukuanjine as withdrawalAmount,
  26. tt1.hetongleixing as contractType,
  27. tt1.shenqingren as applierName,
  28. tt1.shifouweixiangmu as isProject,
  29. tt1.fuwujine as detailAllAmount,
  30. tt1.shishoujine as reallyDetailAmount,
  31. tt1.daishoukuanjine as waitDetailAmount,
  32. tt1.shenheshijian as examineTime,
  33. tt2.zhichu as outAmount
  34. FROM
  35. (
  36. SELECT
  37. c.company_id,
  38. com.NAME,
  39. detail.task_type_id,
  40. type.`name` as typeName,
  41. c.contract_id,
  42. input.contract_no,
  43. GROUP_CONCAT( DISTINCT arrive_date ) AS daozhangriqi,
  44. SUM( detail.arrive_amount ) AS tishoukuanjine,
  45. GROUP_CONCAT( DISTINCT u.nick_name ) AS shenqingren,
  46. CASE
  47. WHEN input.contract_type = 1 THEN
  48. "续签" ELSE "新签"
  49. END AS hetongleixing,
  50. CASE
  51. WHEN c.is_project = 0 THEN '项目'
  52. WHEN c.is_project = 1 THEN '非项目'
  53. ELSE ''
  54. END AS shifouweixiangmu,
  55. detail.amount AS fuwujine,
  56. SUM( CASE WHEN c.STATUS = 1 THEN detail.arrive_amount ELSE 0 END ) AS shishoujine,
  57. (
  58. detail.amount - SUM( CASE WHEN c.STATUS = 1 THEN detail.arrive_amount ELSE 0 END )) AS
  59. daishoukuanjine,
  60. GROUP_CONCAT(
  61. IF
  62. ( c.STATUS = 1, c.verify_date, NULL )) AS shenheshijian
  63. FROM
  64. biz_collection c
  65. LEFT JOIN biz_collection_detail detail ON c.id = detail.collection_id
  66. LEFT JOIN biz_company com ON com.id = c.company_id
  67. LEFT JOIN biz_archive_input input ON input.id = c.contract_id
  68. LEFT JOIN sys_user u ON u.user_id = c.applier_id
  69. LEFT JOIN biz_task_type type on type.id = detail.task_type_id
  70. WHERE
  71. c.deleted = 0
  72. AND c.STATUS != 2
  73. AND com.tenant_id = #{conditions.tenantId}
  74. <if test="conditions.companyName != null and conditions.companyName != ''">
  75. AND com.NAME LIKE CONCAT('%',#{conditions.companyName},'%')
  76. </if>
  77. <if test="conditions.contractNo != null and conditions.contractNo != ''">
  78. AND input.contract_no LIKE CONCAT('%',#{conditions.contractNo},'%')
  79. </if>
  80. <if test="conditions.taskTypeIds != null and conditions.taskTypeIds.size() &gt; 0">
  81. AND detail.task_type_id IN
  82. <foreach collection="conditions.taskTypeIds" index="index" item="item" open="(" separator="," close=")">
  83. #{item}
  84. </foreach>
  85. </if>
  86. <if test="conditions.receiptDateFilter != null and conditions.receiptDateFilter.size() ">
  87. AND (
  88. DATE_FORMAT(c.arrive_date,'%Y-%m-%d') &gt;= #{conditions.receiptDateFilter[0]}
  89. AND
  90. DATE_FORMAT(c.arrive_date,'%Y-%m-%d') &lt;= #{conditions.receiptDateFilter[1]}
  91. )
  92. </if>
  93. <if test="conditions.examineTimeFilter != null and conditions.examineTimeFilter.size() ">
  94. AND(
  95. DATE_FORMAT(c.verify_date,'%Y-%m-%d') &gt;= #{conditions.examineTimeFilter[0]}
  96. AND
  97. DATE_FORMAT(c.verify_date,'%Y-%m-%d') &lt;= #{conditions.examineTimeFilter[1]}
  98. )
  99. </if>
  100. <if test="conditions.isProject != null">
  101. AND c.is_project = #{conditions.isProject}
  102. </if>
  103. <if test="conditions.isNew != null">
  104. AND c.is_new = #{conditions.isNew}
  105. </if>
  106. GROUP BY
  107. c.company_id,
  108. detail.task_type_id,
  109. c.contract_id
  110. order by
  111. c.create_time desc
  112. ) tt1
  113. LEFT JOIN (
  114. SELECT
  115. t1.company_id,
  116. t3.task_type_id,
  117. t1.contract_id,
  118. SUM( CASE WHEN t1.payment_status = 1 THEN t3.payment_amount ELSE 0 END ) zhichu
  119. FROM
  120. biz_payment t1
  121. LEFT JOIN biz_archive_input t2 ON t1.contract_id = t2.id
  122. LEFT JOIN biz_payment_detail t3 ON t1.id = t3.payment_id
  123. left join biz_company com on com.id = t1.company_id
  124. left join biz_archive_input input on input.id = t1.contract_id
  125. WHERE
  126. t1.deleted = 0
  127. AND t1.payment_status = 1
  128. AND t1.verify_status = 3
  129. AND com.tenant_id = #{conditions.tenantId}
  130. <if test="conditions.companyName != null and conditions.companyName != ''">
  131. AND com.NAME LIKE CONCAT('%',#{conditions.companyName},'%')
  132. </if>
  133. <if test="conditions.contractNo != null and conditions.contractNo != ''">
  134. AND input.contract_no LIKE CONCAT('%',#{conditions.contractNo},'%')
  135. </if>
  136. <if test="conditions.taskTypeIds != null and conditions.taskTypeIds.size() &gt; 0">
  137. AND t3.task_type_id IN
  138. <foreach collection="conditions.taskTypeIds" index="index" item="item" open="(" separator="," close=")">
  139. #{item}
  140. </foreach>
  141. </if>
  142. <if test="conditions.examineTimeFilter != null and conditions.examineTimeFilter.size() &gt; 0 ">
  143. AND (
  144. DATE_FORMAT(t1.verify_date,'%Y-%m-%d') &gt;= #{conditions.examineTimeFilter[0]}
  145. AND
  146. DATE_FORMAT(t1.verify_date,'%Y-%m-%d') &lt;= #{conditions.examineTimeFilter[1]}
  147. )
  148. </if>
  149. GROUP BY
  150. t1.company_id,
  151. t3.task_type_id,
  152. t1.contract_id
  153. ) tt2 ON tt1.company_id = tt2.company_id
  154. AND tt1.task_type_id = tt2.task_type_id
  155. AND tt1.contract_id = tt2.contract_id
  156. </select>
  157. <select id="getByContractIn" resultType="cn.ezhizao.project.business.collection.domain.vo.ResStatisticsVo">
  158. SELECT
  159. t3.NAME AS companyName,
  160. t4.`name` AS taskTypeName,
  161. t5.contract_no AS contractNo,
  162. t1.arrive_date,
  163. t6.nick_name,
  164. CASE
  165. WHEN t5.contract_type = 1 THEN "续签" ELSE "新签"
  166. END AS contractType,
  167. CASE
  168. WHEN t1.is_project = 0 THEN '项目'
  169. WHEN t1.is_project = 1 THEN '非项目'
  170. ELSE ''
  171. END AS isProject,
  172. t2.amount AS detailAllAmount,
  173. CASE WHEN t1.STATUS = 1 THEN t2.arrive_amount ELSE 0 END AS reallyDetailAmount,
  174. t1.verify_date as examineTime,
  175. t1.applier_id,
  176. t6.nick_name AS applierName,
  177. t2.task_type_id,
  178. t7.name as typeName,
  179. date_format( t1.arrive_date, '%Y-%m-%d') as receiptDate
  180. FROM
  181. biz_collection t1 right join biz_collection_detail t2 ON t1.id = t2.collection_id
  182. LEFT JOIN biz_company t3 ON t3.id = t1.company_id
  183. LEFT JOIN biz_task_type t4 ON t4.id = t2.task_type_id
  184. LEFT JOIN biz_archive_input t5 ON t5.id = t1.contract_id
  185. LEFT JOIN sys_user t6 ON t6.user_id = t1.applier_id
  186. LEFT JOIN biz_task_type t7 on t7.id = t2.task_type_id
  187. WHERE
  188. t1.contract_id = #{conditions.contractId}
  189. AND
  190. t2.task_type_id = #{conditions.taskTypeIds[0]}
  191. <if test="conditions.receiptDateFilter != null and conditions.receiptDateFilter.size() &gt; 0 ">
  192. AND (
  193. DATE_FORMAT(c.arrive_date,'%Y-%m-%d') &gt;= #{conditions.receiptDateFilter[0]}
  194. AND
  195. DATE_FORMAT(c.arrive_date,'%Y-%m-%d') &lt;= #{conditions.receiptDateFilter[1]}
  196. )
  197. </if>
  198. <if test="conditions.examineTimeFilter != null and conditions.examineTimeFilter.size() &gt; 0 ">
  199. AND(
  200. DATE_FORMAT(c.verify_date,'%Y-%m-%d') &gt;= #{conditions.examineTimeFilter[0]}
  201. AND
  202. DATE_FORMAT(c.verify_date,'%Y-%m-%d') &lt;= #{conditions.examineTimeFilter[1]}
  203. )
  204. </if>
  205. </select>
  206. <select id="getByContractOut"
  207. resultType="cn.ezhizao.project.business.collection.domain.vo.ResStatisticsVo">
  208. select tt1.*, tt2.zongjine as withdrawalAmount
  209. from (SELECT t3.NAME AS companyName,
  210. t4.`name` AS taskTypeName,
  211. t5.contract_no AS contractNo,
  212. t6.nick_name,
  213. t2.amount AS detailAllAmount,
  214. t2.payment_amount AS reallyDetailAmount,
  215. t1.verify_date AS examineTime,
  216. t2.task_type_id,
  217. t1.company_id,
  218. t1.contract_id,
  219. t1.applier_id,
  220. t7.name as typeName,
  221. t6.nick_name AS applierName
  222. FROM biz_payment t1
  223. RIGHT JOIN biz_payment_detail t2 ON t1.id = t2.payment_id
  224. LEFT JOIN biz_company t3 ON t3.id = t1.company_id
  225. LEFT JOIN biz_task_type t4 ON t4.id = t2.task_type_id
  226. LEFT JOIN biz_archive_input t5 ON t5.id = t1.contract_id
  227. LEFT JOIN sys_user t6 ON t6.user_id = t1.applier_id
  228. LEFT JOIN biz_task_type t7 on t7.id = t2.task_type_id
  229. WHERE t1.contract_id = #{conditions.contractId}
  230. AND t2.task_type_id = #{conditions.taskTypeIds[0]}
  231. <if test="conditions.examineTimeFilter != null and conditions.examineTimeFilter.size() &gt; 0 ">
  232. AND (
  233. DATE_FORMAT(t1.verify_date,'%Y-%m-%d') &gt;= #{conditions.examineTimeFilter[0]}
  234. AND
  235. DATE_FORMAT(t1.verify_date,'%Y-%m-%d') &lt;= #{conditions.examineTimeFilter[1]}
  236. )
  237. </if>
  238. ORDER BY t1.verify_date DESC
  239. ) tt1
  240. LEFT JOIN
  241. (SELECT p.company_id,
  242. de.task_type_id,
  243. p.contract_id,
  244. sum(de.payment_amount) as zongjine
  245. FROM biz_payment p
  246. right join biz_payment_detail de ON p.id = de.payment_id
  247. WHERE p.verify_status != 4
  248. <if test="conditions.examineTimeFilter != null and conditions.examineTimeFilter.size() &gt; 0 ">
  249. AND (
  250. DATE_FORMAT(t1.verify_date,'%Y-%m-%d') &gt;= #{conditions.examineTimeFilter[0]}
  251. AND
  252. DATE_FORMAT(t1.verify_date,'%Y-%m-%d') &lt;= #{conditions.examineTimeFilter[1]}
  253. )
  254. </if>
  255. GROUP BY
  256. p.company_id,
  257. de.task_type_id,
  258. p.contract_id) tt2 on tt1.task_type_id = tt2.task_type_id and tt1.company_id = tt2.company_id and
  259. tt1.contract_id = tt2.contract_id
  260. </select>
  261. <sql id="getListSql">
  262. SELECT a.id, a.flow_no, a.subsidiary_id, a.subsidiary, a.subsidiary_name, a.subsidiary_bank_account, a.form_date
  263. , a.subsidiary_bank_name, a.company_id, b.name as company_name
  264. , a.is_new, a.is_project, a.project_name, a.project_no, a.project_main_name
  265. , a.amount
  266. , a.verify_status
  267. , a.arrive_amount
  268. , a.arrive_date
  269. , a.arrive_time, a.status, a.applier_id, a.verify_date, a.verify_comment
  270. , a.arrive_status, a.apply_name
  271. , a.appy_account, a.create_time, a.creator_id, a.update_time, a.updater_id
  272. , a.deleted, a.version, a.remark
  273. , a.actually_date
  274. , b.name as company_name, t5.nick_name as applier_name
  275. , ai.contract_no
  276. , (select ifnull(sum(amount), 0) from biz_collection col where col.contract_id = a.contract_id and col.status =
  277. 1) payment_amount
  278. FROM biz_collection a left join biz_company b on b.id = a.company_id
  279. left join biz_archive_input ai on ai.id = a.contract_id
  280. left join sys_user t5 on t5.user_id = a.applier_id
  281. <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
  282. a.deleted = 0 AND
  283. <if test="id != null ">
  284. a.id = #{id} AND
  285. </if>
  286. <if test="tenantId != null">
  287. a.tenant_id = #{tenantId} AND
  288. </if>
  289. <if test="contractId != null">
  290. a.contract_id = #{contractId} AND
  291. </if>
  292. <if test="flowNo != null and formNo != '' ">
  293. a.flow_no LIKE CONCAT('%',#{flowNo},'%') AND
  294. </if>
  295. <if test="subsidiaryId != null">
  296. a.subsidiary_id = #{subsidiaryId} AND
  297. </if>
  298. <if test="subsidiary != null and subsidiary != '' ">
  299. a.subsidiary = #{subsidiary} AND
  300. </if>
  301. <if test="subsidiaryName != null and subsidiaryName != '' ">
  302. a.subsidiary_name = #{subsidiaryName} AND
  303. </if>
  304. <if test="subsidiaryBankAccount != null and subsidiaryBankAccount != ''">
  305. a.subsidiary_bank_account = #{subsidiaryBankAccount} AND
  306. </if>
  307. <if test="subsidiaryBankName != null and subsidiaryBankName != ''">
  308. a.subsidiary_bank_name = #{subsidiaryBankName} AND
  309. </if>
  310. <if test="companyId != null">
  311. a.company_id = #{companyId} AND
  312. </if>
  313. <if test="companyName != null and companyName != '' ">
  314. (LOCATE(#{companyName}, a.company_name) or LOCATE(#{companyName}, b.name)) AND
  315. </if>
  316. <if test="applierName != null and applierName != '' ">
  317. LOCATE(#{applierName}, t5.nick_name) AND
  318. </if>
  319. <if test="amount != null ">
  320. a.amount = #{amount} AND
  321. </if>
  322. <if test="arriveDate != null ">
  323. a.arrive_date = #{arriveDate} AND
  324. </if>
  325. <if test="actuallyDate != null">
  326. DATE_FORMAT(a.actually_date, '%Y-%m-%d') = #{actuallyDate} AND
  327. </if>
  328. <if test="startDate != null and endDate != null">
  329. (
  330. DATE_FORMAT(a.arrive_date,'%Y-%m-%d') &gt;= #{startDate}
  331. AND
  332. DATE_FORMAT(a.arrive_date,'%Y-%m-%d') &lt;= #{endDate}
  333. ) AND
  334. </if>
  335. <if test="dateFilter != null">
  336. (
  337. DATE_FORMAT(a.verify_date,'%Y-%m-%d') &gt;= #{dateFilter[0]}
  338. AND
  339. DATE_FORMAT(a.verify_date,'%Y-%m-%d') &lt;= #{dateFilter[1]}
  340. ) AND
  341. </if>
  342. <if test="arriveTime != null and arriveTime != '' ">
  343. a.arrive_time = #{arriveTime} AND
  344. </if>
  345. <if test="status != null">
  346. a.status = #{status} AND
  347. </if>
  348. <if test="arriveStatus != null">
  349. a.arrive_status = #{arriveStatus} AND
  350. </if>
  351. <if test="applyName != null and applyName != '' ">
  352. a.apply_name = #{applyName} AND
  353. </if>
  354. <if test="appyAccount != null and appyAccount != '' ">
  355. a.appy_account = #{appyAccount} AND
  356. </if>
  357. <if test="verifyDate != null">
  358. a.verify_date = #{verifyDate}
  359. </if>
  360. <if test="remark != null and remark != '' ">
  361. a.remark = #{remark} AND
  362. </if>
  363. </trim>
  364. </sql>
  365. </mapper>