KwcContractTradeMapper.xml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.sckw.contract.dao.KwcContractTradeMapper">
  6. <select id="queryList" resultType="com.sckw.contract.model.dto.res.QueryListResDto">
  7. select a.amount,
  8. a.trading,
  9. a.name contractName,
  10. a.contract_no,
  11. c.create_by initiateBy,
  12. c.create_time initiateTime,
  13. a.create_time,
  14. a.start_time,
  15. a.end_time,
  16. a.id,
  17. a.remark,
  18. a.signing_way,
  19. d.create_time signTime,
  20. a.status,
  21. b.unit_type,
  22. b.ent_id,
  23. b.firm_name entName,
  24. e.ent_id targetEntId,
  25. e.firm_name targetEntName,
  26. a.contract_pid contractPid,
  27. a.performed_amount performedAmount,
  28. f.name contractPname
  29. from kwc_contract_trade a
  30. left join kwc_contract_trade_unit b
  31. on a.id = b.contract_id
  32. and b.unit_type = #{entType}
  33. and case when a.status != 3 then b.ent_id in
  34. <foreach collection="allEnt" separator="," open="(" close=")" item="item">
  35. #{item}
  36. </foreach>
  37. else 1=1
  38. end
  39. and b.del_flag = 0
  40. left join kwc_contract_trade_track c on a.id = c.contract_id and c.del_flag = 0 and c.type = 1
  41. left join kwc_contract_trade_track d on a.id = d.contract_id and d.del_flag = 0 and d.type = 0
  42. left join kwc_contract_trade_unit e on a.id = e.contract_id and e.unit_type != #{entType} and e.del_flag = 0
  43. left join kwc_contract_trade f on f.id = a.contract_pid
  44. where a.del_flag = 0
  45. and case when a.status = 3 then a.ent_id = #{entId} and #{entType} = 1
  46. else (b.ent_id in
  47. <foreach collection="allEnt" separator="," open="(" close=")" item="item">
  48. #{item}
  49. </foreach>
  50. and b.id is not null)
  51. end
  52. <if test="startTime != null">
  53. and a.create_time >= #{startTime}
  54. </if>
  55. <if test="endTime != null">
  56. and a.create_time &lt;= #{endTime}
  57. </if>
  58. <if test="status != null">
  59. and a.status = #{status}
  60. </if>
  61. <if test="keywords != null and keywords != ''">
  62. and (b.firm_name like concat('%', #{keywords}, '%') or
  63. e.firm_name like concat('%', #{keywords}, '%') or
  64. b.contacts like concat('%', #{keywords}, '%') or
  65. b.phone like concat('%', #{keywords}, '%') or
  66. b.sign_phone like concat('%', #{keywords}, '%') or
  67. a.contract_no like concat('%', #{keywords}, '%') or
  68. a.name like concat('%', #{keywords}, '%'))
  69. </if>
  70. <if test="idList != null and idList.size() > 0">
  71. and a.id in
  72. <foreach collection="idList" open="(" close=")" separator="," item="item">
  73. #{item}
  74. </foreach>
  75. </if>
  76. <if test="trading != null">
  77. and a.trading = #{trading}
  78. </if>
  79. <if test="signingWay != null">
  80. and a.signing_way = #{signingWay}
  81. </if>
  82. <if test="targetEntId != null">
  83. and e.ent_id = #{targetEntId}
  84. </if>
  85. order by a.create_time desc
  86. </select>
  87. <select id="queryContractValidCount" resultType="com.sckw.contract.model.dto.res.QueryContractValidCountResDto">
  88. SELECT b.unit_type,
  89. count(1) cnt
  90. FROM kwc_contract_trade a
  91. left join kwc_contract_trade_unit b on a.id = b.contract_id
  92. where a.`status` != 3
  93. <if test="list != null and list.size() > 0">
  94. and b.ent_id in
  95. <foreach collection="list" separator="," open="(" close=")" item="item">
  96. #{item}
  97. </foreach>
  98. </if>
  99. GROUP BY b.unit_type
  100. union all
  101. SELECT b.unit_type,
  102. count(1)
  103. FROM kwc_contract_logistics a
  104. left join kwc_contract_logistics_unit b on a.id = b.contract_id
  105. where a.`status` != 3
  106. <if test="list != null and list.size() > 0">
  107. and b.ent_id in
  108. <foreach collection="list" separator="," open="(" close=")" item="item">
  109. #{item}
  110. </foreach>
  111. </if>
  112. GROUP BY b.unit_type
  113. </select>
  114. <select id="queryTradeList" resultType="com.sckw.contract.model.dto.res.QueryListResDto">
  115. select a.amount,
  116. a.trading,
  117. a.name contractName,
  118. a.contract_no,
  119. c.create_by initiateBy,
  120. c.create_time initiateTime,
  121. a.create_time,
  122. a.start_time,
  123. a.end_time,
  124. a.id,
  125. a.remark,
  126. a.signing_way,
  127. d.create_time signTime,
  128. a.status,
  129. b.ent_id provideEntId,
  130. b.firm_name provideEntName,
  131. e.ent_id purchaseEntId,
  132. e.firm_name purchaseEntName,
  133. a.contract_pid contractPid,
  134. a.performed_amount performedAmount,
  135. f.name contractPname
  136. from kwc_contract_trade a
  137. left join kwc_contract_trade_unit b on a.id = b.contract_id and b.del_flag = 0 and b.unit_type = 1
  138. left join kwc_contract_trade_unit e on a.id = e.contract_id and e.del_flag = 0 and e.unit_type = 2
  139. left join kwc_contract_trade_track c on a.id = c.contract_id and c.del_flag = 0 and c.type = 1
  140. left join kwc_contract_trade_track d on a.id = d.contract_id and d.del_flag = 0 and d.type = 0
  141. left join kwc_contract_trade f on a.contract_pid = f.id
  142. where a.del_flag = 0
  143. and a.status != 3
  144. <if test="startTime != null">
  145. and a.create_time >= #{startTime}
  146. </if>
  147. <if test="endTime != null">
  148. and a.create_time &lt;= #{endTime}
  149. </if>
  150. <if test="status != null">
  151. and a.status = #{status}
  152. </if>
  153. <if test="keywords != null and keywords != ''">
  154. and (b.firm_name like concat('%', #{keywords}, '%') or
  155. e.firm_name like concat('%', #{keywords}, '%') or
  156. b.contacts like concat('%', #{keywords}, '%') or
  157. e.contacts like concat('%', #{keywords}, '%') or
  158. a.contract_no like concat('%', #{keywords}, '%') or
  159. a.name like concat('%', #{keywords}, '%'))
  160. </if>
  161. <if test="idList != null and idList.size() > 0">
  162. and a.id in
  163. <foreach collection="idList" open="(" close=")" separator="," item="item">
  164. #{item}
  165. </foreach>
  166. </if>
  167. <if test="trading != null">
  168. and a.trading = #{trading}
  169. </if>
  170. <if test="signingWay != null">
  171. and a.signing_way = #{signingWay}
  172. </if>
  173. order by a.create_time desc
  174. </select>
  175. </mapper>