KwcContractTradeMapper.xml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. a.unload_way unloadWay,
  30. a.signing_way signingWay
  31. from kwc_contract_trade a
  32. left join kwc_contract_trade_unit b
  33. on a.id = b.contract_id
  34. and b.unit_type = #{entType}
  35. and case when a.status != 3 then b.ent_id in
  36. <foreach collection="allEnt" separator="," open="(" close=")" item="item">
  37. #{item}
  38. </foreach>
  39. else 1=1
  40. end
  41. and b.del_flag = 0
  42. left join kwc_contract_trade_track c on a.id = c.contract_id and c.del_flag = 0 and c.type = 1
  43. left join kwc_contract_trade_track d on a.id = d.contract_id and d.del_flag = 0 and d.type = 0
  44. left join kwc_contract_trade_unit e on a.id = e.contract_id and e.unit_type != #{entType} and e.del_flag = 0
  45. left join kwc_contract_trade f on f.id = a.contract_pid
  46. where a.del_flag = 0
  47. <!-- and case when a.status = 3 then a.ent_id = #{entId} and #{entType} = 1-->
  48. <!-- else (b.ent_id in-->
  49. <!-- <foreach collection="allEnt" separator="," open="(" close=")" item="item">-->
  50. <!-- #{item}-->
  51. <!-- </foreach>-->
  52. <!-- and b.id is not null)-->
  53. <!-- end-->
  54. <if test="startTime != null">
  55. and a.create_time >= #{startTime}
  56. </if>
  57. <if test="endTime != null">
  58. and a.create_time &lt;= #{endTime}
  59. </if>
  60. <if test="status != null">
  61. and a.status = #{status}
  62. </if>
  63. <if test="keywords != null and keywords != ''">
  64. and (b.firm_name like concat('%', #{keywords}, '%') or
  65. e.firm_name like concat('%', #{keywords}, '%') or
  66. b.phone like concat('%', #{keywords}, '%') or
  67. b.sign_phone like concat('%', #{keywords}, '%') or
  68. a.contract_no like concat('%', #{keywords}, '%') or
  69. a.name like concat('%', #{keywords}, '%')
  70. <if test="initiateList != null and initiateList.size() > 0">
  71. or a.create_by in
  72. <foreach collection="initiateList" item="item" open="(" close=")" separator=",">
  73. #{item}
  74. </foreach>
  75. </if> )
  76. </if>
  77. <if test="idList != null and idList.size() > 0">
  78. and a.id in
  79. <foreach collection="idList" open="(" close=")" separator="," item="item">
  80. #{item}
  81. </foreach>
  82. </if>
  83. <if test="trading != null">
  84. and a.trading = #{trading}
  85. </if>
  86. <if test="signingWay != null">
  87. and a.signing_way = #{signingWay}
  88. </if>
  89. <if test="targetEntId != null">
  90. and e.ent_id = #{targetEntId}
  91. </if>
  92. <if test="contractCode != null and '' != contractCode">
  93. and f.contract_no like concat('%',#{contractCode},'%')
  94. </if>
  95. <if test="contractName != null and '' != contractName">
  96. and f.name like concat('%',#{contractName},'%')
  97. </if>
  98. <if test="supplementCode != null and '' != supplementCode">
  99. and f.contract_pid != null
  100. and f.contract_no like concat('%',#{supplementCode},'%')
  101. </if>
  102. <if test="purchaseEntId != null and '' != purchaseEntId">
  103. and e.unit_type = 2
  104. and e.id = #{purchaseEntId}
  105. </if>
  106. <if test="supplyEntId != null and '' != supplyEntId">
  107. and e.unit_type = 1
  108. and e.id = #{supplyEntId}
  109. </if>
  110. order by a.create_time desc
  111. </select>
  112. <select id="queryContractValidCount" resultType="com.sckw.contract.model.dto.res.QueryContractValidCountResDto">
  113. SELECT b.unit_type,
  114. count(1) cnt
  115. FROM kwc_contract_trade a
  116. left join kwc_contract_trade_unit b on a.id = b.contract_id
  117. where a.`status` != 3
  118. <if test="list != null and list.size() > 0">
  119. and b.ent_id in
  120. <foreach collection="list" separator="," open="(" close=")" item="item">
  121. #{item}
  122. </foreach>
  123. </if>
  124. GROUP BY b.unit_type
  125. union all
  126. SELECT b.unit_type,
  127. count(1)
  128. FROM kwc_contract_logistics a
  129. left join kwc_contract_logistics_unit b on a.id = b.contract_id
  130. where a.`status` != 3
  131. <if test="list != null and list.size() > 0">
  132. and b.ent_id in
  133. <foreach collection="list" separator="," open="(" close=")" item="item">
  134. #{item}
  135. </foreach>
  136. </if>
  137. GROUP BY b.unit_type
  138. </select>
  139. <select id="queryTradeList" resultType="com.sckw.contract.model.dto.res.QueryListResDto">
  140. select a.amount,
  141. a.trading,
  142. a.name contractName,
  143. a.contract_no,
  144. c.create_by initiateBy,
  145. c.create_time initiateTime,
  146. a.create_time,
  147. a.start_time,
  148. a.end_time,
  149. a.id,
  150. a.remark,
  151. a.signing_way,
  152. d.create_time signTime,
  153. a.status,
  154. b.ent_id provideEntId,
  155. b.firm_name provideEntName,
  156. e.ent_id purchaseEntId,
  157. e.firm_name purchaseEntName,
  158. a.contract_pid contractPid,
  159. a.performed_amount performedAmount,
  160. f.name contractPname
  161. from kwc_contract_trade a
  162. left join kwc_contract_trade_unit b on a.id = b.contract_id and b.del_flag = 0 and b.unit_type = 1
  163. left join kwc_contract_trade_unit e on a.id = e.contract_id and e.del_flag = 0 and e.unit_type = 2
  164. left join kwc_contract_trade_track c on a.id = c.contract_id and c.del_flag = 0 and c.type = 1
  165. left join kwc_contract_trade_track d on a.id = d.contract_id and d.del_flag = 0 and d.type = 0
  166. left join kwc_contract_trade f on a.contract_pid = f.id
  167. where a.del_flag = 0
  168. and a.status != 3
  169. <if test="authEntIdList != null and authEntIdList.size() != 0">
  170. and a.ent_id in
  171. <foreach collection="authEntIdList" item="item" open="(" close=")" separator=",">
  172. #{item}
  173. </foreach>
  174. </if>
  175. <if test="reqVo.startTime != null">
  176. and a.create_time >= #{reqVo.startTime}
  177. </if>
  178. <if test="reqVo.endTime != null">
  179. and a.create_time &lt;= #{reqVo.endTime}
  180. </if>
  181. <if test="reqVo.status != null">
  182. and a.status = #{reqVo.status}
  183. </if>
  184. <if test="reqVo.keywords != null and reqVo.keywords != ''">
  185. and (b.firm_name like concat('%', #{reqVo.keywords}, '%') or
  186. e.firm_name like concat('%', #{reqVo.keywords}, '%') or
  187. b.contacts like concat('%', #{reqVo.keywords}, '%') or
  188. e.contacts like concat('%', #{reqVo.keywords}, '%') or
  189. a.contract_no like concat('%', #{reqVo.keywords}, '%') or
  190. a.name like concat('%', #{reqVo.keywords}, '%'))
  191. </if>
  192. <if test="reqVo.idList != null and reqVo.idList.size() > 0">
  193. and a.id in
  194. <foreach collection="reqVo.idList" open="(" close=")" separator="," item="item">
  195. #{item}
  196. </foreach>
  197. </if>
  198. <if test="reqVo.trading != null">
  199. and a.trading = #{reqVo.trading}
  200. </if>
  201. <if test="reqVo.signingWay != null">
  202. and a.signing_way = #{reqVo.signingWay}
  203. </if>
  204. order by a.create_time desc
  205. </select>
  206. </mapper>