BizCollectionMapper.xml 16 KB

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