BizCollectionDetailMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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.BizCollectionDetailMapper">
  4. <!-- 基础的返回map 多表复杂的 自行组合 -->
  5. <resultMap id="BaseResultMap" type="cn.ezhizao.project.business.collection.domain.BizCollectionDetail">
  6. </resultMap>
  7. <resultMap id="DetailResultMap" type="cn.ezhizao.project.business.collection.domain.BizCollectionDetail">
  8. <id column="id" property="id"/>
  9. <result column="collection_id" property="collectionId"/>
  10. <result column="contract_id" property="contractId"/>
  11. <association property="bizCollection" column="collection_id" select="getCollection" javaType="cn.ezhizao.project.business.collection.domain.BizCollection" />
  12. <association property="bizArchiveInput" column="contract_id" select="getArchiveInput" javaType="cn.ezhizao.project.business.collection.domain.vo.ArchiveVo" />
  13. </resultMap>
  14. <select id="getCollection" resultType="cn.ezhizao.project.business.collection.domain.BizCollection">
  15. select *,user1.nick_name as applierName,user2.nick_name as verifyName from biz_collection
  16. left join sys_user user1 on user1.user_id = biz_collection.applier_id
  17. left join sys_user user2 on user2.user_id = biz_collection.verify_id
  18. where id = #{collection_id}
  19. </select>
  20. <select id="getArchiveInput" resultType="cn.ezhizao.project.business.collection.domain.vo.ArchiveVo">
  21. select * from biz_archive_input where id = #{contract_id}
  22. </select>
  23. <!--带条件的List查询-->
  24. <select id="getList" resultMap="BaseResultMap">
  25. <include refid="getListSql"/>
  26. </select>
  27. <!--带条件的List查询 数据总条数-->
  28. <select id="getTotal" resultType="java.lang.Integer">
  29. SELECT COUNT(1) FROM (<include refid="getListSql"/>) AS C
  30. </select>
  31. <sql id="getListSql">
  32. SELECT
  33. t1.id,
  34. t1.contract_detail_id,
  35. t1.collection_id,
  36. t1.collection_contract_id,
  37. t1.task_type_id,
  38. t1.company_id,
  39. t4.address_style,
  40. t4.fiction_address_id,
  41. t4.province,
  42. t4.city,
  43. t4.district,
  44. t4.belong_region,
  45. t4.remark as inputRemark,
  46. t1.remark,
  47. t1.contract_id,
  48. t1.arrive_amount,
  49. t4.amount as amount,
  50. t3.name AS company_name,
  51. t2.name AS task_type_name,
  52. (select sum(cd.arrive_amount) from biz_collection_detail cd left join biz_collection c on c.id = cd.collection_id
  53. where cd.contract_detail_id = t1.contract_detail_id
  54. and cd.deleted = 0 and t1.contract_id = cd.contract_id and c.status = 1) arrived
  55. FROM
  56. biz_collection_detail t1
  57. left join biz_collection c on c.id = t1.collection_id
  58. left join biz_task_type t2 on t2.id = t1.task_type_id
  59. LEFT JOIN
  60. biz_company t3 on t1.company_id = t3.id
  61. left join biz_archive_input_detail t4 on t4.id = t1.contract_detail_id
  62. <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
  63. t1.deleted = 0 AND
  64. <if test="id != null ">
  65. t1.id = #{id} AND
  66. </if>
  67. <if test="collectionId != null ">
  68. t1.collection_id = #{collectionId} AND
  69. </if>
  70. <if test="tenantId != null">
  71. t1.tenant_id = #{tenantId} AND
  72. </if>
  73. <if test="collectionIds != null and collectionIds.size > 0 ">
  74. collection_id in
  75. <foreach collection="collectionIds" index="index" item="item" separator="," open="(" close=")">
  76. #{item,jdbcType=BIGINT}
  77. </foreach>
  78. AND
  79. </if>
  80. <if test="contractDetailId != null">
  81. t1.contract_detail_id = #{contractDetailId} AND
  82. </if>
  83. <if test="verifyStatus != null">
  84. c.status = #{verifyStatus} AND
  85. </if>
  86. <if test="contractId != null ">
  87. t1.contract_id = #{contractId} AND
  88. </if>
  89. <if test="companyId != null ">
  90. t1.company_id = #{companyId} AND
  91. </if>
  92. <if test="taskTypeId != null ">
  93. t1.task_type_id = #{taskTypeId} AND
  94. </if>
  95. <if test="remark != null and remark != '' ">
  96. t1.remark = #{remark} AND
  97. </if>
  98. <if test="ids != null ">
  99. t1.contract_id IN
  100. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  101. #{item,jdbcType=BIGINT}
  102. </foreach>
  103. AND
  104. </if>
  105. </trim>
  106. </sql>
  107. <!--根据主表id,删除 为的是表单保存时,明细统一物理删除后,再统一插入-->
  108. <update id="remove">
  109. UPDATE biz_collection_detail
  110. SET deleted=1
  111. WHERE collection_id in
  112. <foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
  113. #{id}
  114. </foreach>
  115. </update>
  116. <!--根据主表id,删除 为的是表单保存时,明细统一物理删除后,再统一插入-->
  117. <delete id="physicallyDelete">
  118. DELETE FROM
  119. biz_collection_detail
  120. WHERE id > 0
  121. <if test="id != null">
  122. AND id = #{id}
  123. </if>
  124. <if test="collectionId != null">
  125. AND collection_id = #{collectionId}
  126. </if>
  127. </delete>
  128. <select id="getDetailList" resultMap="DetailResultMap">
  129. select detail.*,(select sum(cd.arrive_amount) from biz_collection_detail cd left join biz_collection c on c.id =
  130. cd.collection_id
  131. where cd.contract_detail_id = detail.contract_detail_id
  132. and cd.deleted = 0 and detail.contract_id = cd.contract_id and c.status = 1) arrived from biz_collection_detail
  133. detail
  134. LEFT JOIN biz_collection collection on collection.id = detail.collection_id
  135. LEFT JOIN biz_task_type t2 on t2.id = detail.task_type_id
  136. LEFT JOIN biz_archive_input_detail inputDetail on inputDetail.id = detail.contract_detail_id
  137. LEFT JOIN biz_archive_input input on input.id = inputDetail.contract_id
  138. LEFT JOIN biz_company company on detail.company_id = company.id
  139. left join sys_user user1 on user1.user_id = collection.verify_id
  140. left join sys_user user2 on user2.user_id = collection.applier_id
  141. <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
  142. detail.deleted = 0 AND collection.status = 1
  143. <if test="id != null ">
  144. AND detail.id = #{id}
  145. </if>
  146. <if test="collectionId != null ">
  147. AND detail.collection_id = #{collectionId}
  148. </if>
  149. <if test="tenantId != null">
  150. AND detail.tenant_id = #{tenantId}
  151. </if>
  152. <if test="collectionIds != null and collectionIds.size > 0 ">
  153. AND collection_id in
  154. <foreach collection="collectionIds" index="index" item="item" separator="," open="(" close=")">
  155. #{item,jdbcType=BIGINT}
  156. </foreach>
  157. </if>
  158. <if test="contractDetailId != null">
  159. AND detail.contract_detail_id = #{contractDetailId}
  160. </if>
  161. <if test="bizArchiveInput != null and bizArchiveInput.contractNo != null and bizArchiveInput.contractNo != ''">
  162. AND input.contract_no LIKE CONCAT('%', #{bizArchiveInput.contractNo},'%')
  163. </if>
  164. <if test="bizArchiveInput != null and bizArchiveInput.boss != null and bizArchiveInput.boss != ''">
  165. AND input.boss LIKE CONCAT('%', #{bizArchiveInput.boss},'%')
  166. </if>
  167. <if test="bizArchiveInput != null and bizArchiveInput.party != null and bizArchiveInput.party != ''">
  168. AND input.party LIKE CONCAT('%', #{bizArchiveInput.party},'%')
  169. </if>
  170. <if test="bizArchiveInput != null and bizArchiveInput.contractType != null">
  171. AND input.contract_type = #{bizArchiveInput.contractType}
  172. </if>
  173. <if test="bizCollection != null and bizCollection.verifyName != null and bizCollection.verifyName != ''">
  174. AND user1.nick_name LIKE CONCAT('%', #{bizCollection.verifyName},'%')
  175. </if>
  176. <if test="bizCollection != null and bizCollection.applierName != null and bizCollection.applierName != ''">
  177. AND user2.nick_name LIKE CONCAT('%', #{bizCollection.applierName},'%')
  178. </if>
  179. <if test="bizCollection != null and bizCollection.isProject != null">
  180. AND collection.is_project = #{bizCollection.isProject}
  181. </if>
  182. <if test="bizCollection != null and bizCollection.projectMainName != null and bizCollection.projectMainName != ''">
  183. AND collection.project_main_name LIKE CONCAT('%', #{bizCollection.projectMainName},'%')
  184. </if>
  185. <if test="bizCollection != null and bizCollection.projectName != null and bizCollection.projectName != ''">
  186. AND collection.project_name LIKE CONCAT('%', #{bizCollection.projectName},'%')
  187. </if>
  188. <if test="verifyStatus != null">
  189. AND collection.status = #{verifyStatus}
  190. </if>
  191. <if test="contractId != null ">
  192. AND detail.contract_id = #{contractId}
  193. </if>
  194. <if test="bizCollection != null and bizCollection.companyName != null and bizCollection.companyName != '' ">
  195. AND company.name LIKE CONCAT('%', #{bizCollection.companyName},'%')
  196. </if>
  197. <if test=" bizArchiveInput != null and bizArchiveInput.map != null and bizArchiveInput.map.receiptDateFilter != null">
  198. AND (
  199. DATE_FORMAT(collection.arrive_date,'%Y-%m-%d') &gt;= #{bizArchiveInput.map.receiptDateFilter[0]}
  200. AND
  201. DATE_FORMAT(collection.arrive_date,'%Y-%m-%d') &lt;= #{bizArchiveInput.map.receiptDateFilter[1]}
  202. )
  203. </if>
  204. <if test=" bizArchiveInput != null and bizArchiveInput.map != null and bizArchiveInput.map.actuallyDateFilter != null">
  205. AND(
  206. DATE_FORMAT(collection.actually_date,'%Y-%m-%d') &gt;= #{bizArchiveInput.map.actuallyDateFilter[0]}
  207. AND
  208. DATE_FORMAT(collection.actually_date,'%Y-%m-%d') &lt;= #{bizArchiveInput.map.actuallyDateFilter[1]}
  209. )
  210. </if>
  211. <if test="taskTypeId != null ">
  212. and detail.task_type_id = #{taskTypeId} AND
  213. </if>
  214. <if test="remark != null and remark != '' ">
  215. detail.remark = #{remark} AND
  216. </if>
  217. <if test="ids != null ">
  218. detail.contract_id IN
  219. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  220. #{item,jdbcType=BIGINT}
  221. </foreach>
  222. AND
  223. </if>
  224. </trim>
  225. order by detail.create_time desc
  226. </select>
  227. </mapper>