BizCollectionDetailMapper.xml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. <!--带条件的List查询-->
  8. <select id="getList" resultMap="BaseResultMap">
  9. <include refid="getListSql"/>
  10. </select>
  11. <!--带条件的List查询 数据总条数-->
  12. <select id="getTotal" resultType="java.lang.Integer">
  13. SELECT COUNT(1) FROM (<include refid="getListSql"/>) AS C
  14. </select>
  15. <sql id="getListSql">
  16. SELECT
  17. t1.id,
  18. t1.contract_detail_id,
  19. t1.collection_id,
  20. t1.collection_contract_id,
  21. t1.task_type_id,
  22. t1.company_id,
  23. t1.contract_id,
  24. t1.arrive_amount,
  25. t4.amount as amount,
  26. t3.name AS company_name,
  27. t2.name AS task_type_name,
  28. (select sum(cd.arrive_amount) from biz_collection_detail cd left join biz_collection c on c.id = cd.collection_id
  29. where cd.contract_detail_id = t1.contract_detail_id
  30. and cd.deleted = 0 and t1.contract_id = cd.contract_id and c.status = 1) arrived
  31. FROM
  32. biz_collection_detail t1
  33. left join biz_collection c on c.id = t1.collection_id
  34. left join biz_task_type t2 on t2.id = t1.task_type_id
  35. LEFT JOIN
  36. biz_company t3 on t1.company_id = t3.id
  37. left join biz_archive_input_detail t4 on t4.id = t1.contract_detail_id
  38. <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
  39. t1.deleted = 0 AND
  40. <if test="id != null ">
  41. t1.id = #{id} AND
  42. </if>
  43. <if test="collectionId != null ">
  44. t1.collection_id = #{collectionId} AND
  45. </if>
  46. <if test="tenantId != null">
  47. t1.tenant_id = #{tenantId} AND
  48. </if>
  49. <if test="collectionIds != null and collectionIds.size > 0 ">
  50. collection_id in
  51. <foreach collection="collectionIds" index="index" item="item" separator="," open="(" close=")">
  52. #{item,jdbcType=BIGINT}
  53. </foreach>
  54. AND
  55. </if>
  56. <if test="contractDetailId != null">
  57. t1.contract_detail_id = #{contractDetailId} AND
  58. </if>
  59. <if test="verifyStatus != null">
  60. c.status = #{verifyStatus} AND
  61. </if>
  62. <if test="contractId != null ">
  63. t1.contract_id = #{contractId} AND
  64. </if>
  65. <if test="companyId != null ">
  66. t1.company_id = #{companyId} AND
  67. </if>
  68. <if test="taskTypeId != null ">
  69. t1.task_type_id = #{taskTypeId} AND
  70. </if>
  71. <if test="remark != null and remark != '' ">
  72. t1.remark = #{remark} AND
  73. </if>
  74. <if test="ids != null ">
  75. t1.contract_id IN
  76. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  77. #{item,jdbcType=BIGINT}
  78. </foreach>
  79. AND
  80. </if>
  81. </trim>
  82. </sql>
  83. <!--根据主表id,删除 为的是表单保存时,明细统一物理删除后,再统一插入-->
  84. <update id="remove">
  85. UPDATE biz_collection_detail
  86. SET deleted=1
  87. WHERE collection_id in
  88. <foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
  89. #{id}
  90. </foreach>
  91. </update>
  92. <!--根据主表id,删除 为的是表单保存时,明细统一物理删除后,再统一插入-->
  93. <delete id="physicallyDelete">
  94. DELETE FROM
  95. biz_collection_detail
  96. WHERE id > 0
  97. <if test="id != null">
  98. AND id = #{id}
  99. </if>
  100. <if test="collectionId != null">
  101. AND collection_id = #{collectionId}
  102. </if>
  103. <if test="tenantId != null">
  104. AND tenant_id = #{tenantId}
  105. </if>
  106. </delete>
  107. </mapper>