KwcContractTradeMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. a.create_by initiateBy,
  12. a.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. a.create_time signTime,
  20. a.status,
  21. b.unit_type,
  22. b.ent_id,
  23. b.firm_name entName,
  24. b.ent_id targetEntId,
  25. b.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 -->
  43. <!-- left join kwc_contract_trade_track d on a.id = d.contract_id and d.del_flag = 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 b.ent_id = #{targetEntId}
  91. </if>
  92. <if test="contractCode != null and '' != contractCode">
  93. and a.contract_no like concat('%',#{contractCode},'%')
  94. </if>
  95. <if test="contractName != null and '' != contractName">
  96. and a.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 b.unit_type = 2
  104. and b.id = #{purchaseEntId}
  105. </if>
  106. <if test="supplyEntId != null and '' != supplyEntId">
  107. and b.unit_type = 1
  108. and b.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. <select id="queryList1" resultType="com.sckw.contract.model.dto.res.QueryListResDto">
  207. select a.amount,
  208. a.trading,
  209. a.name contractName,
  210. a.contract_no,
  211. a.create_by initiateBy,
  212. a.create_time initiateTime,
  213. a.create_time,
  214. a.start_time,
  215. a.end_time,
  216. a.id,
  217. a.remark,
  218. a.signing_way,
  219. a.sign_time signTime,
  220. a.status,
  221. b.unit_type,
  222. b.ent_id,
  223. b.firm_name entName,
  224. b.ent_id targetEntId,
  225. b.firm_name targetEntName,
  226. a.contract_pid contractPid,
  227. a.performed_amount performedAmount,
  228. f.name contractPname,
  229. f.contract_no contractPidNo,
  230. a.unload_way unloadWay,
  231. a.signing_way signingWay
  232. from kwc_contract_trade a
  233. left join kwc_contract_trade_unit b
  234. on a.id = b.contract_id
  235. and b.del_flag = 0
  236. left join kwc_contract_trade f on f.id = a.contract_pid
  237. where a.del_flag = 0
  238. <if test="startTime != null">
  239. and a.create_time >= #{startTime}
  240. </if>
  241. <if test="endTime != null">
  242. and a.create_time &lt;= #{endTime}
  243. </if>
  244. <if test="status != null">
  245. and a.status = #{status}
  246. </if>
  247. <if test="trading != null">
  248. and a.trading = #{trading}
  249. </if>
  250. <if test="signingWay != null">
  251. and a.signing_way = #{signingWay}
  252. </if>
  253. <if test="targetEntId != null">
  254. and b.ent_id = #{targetEntId}
  255. </if>
  256. <if test="contractCode != null and '' != contractCode">
  257. and a.contract_no like concat('%',#{contractCode},'%')
  258. </if>
  259. <if test="contractName != null and '' != contractName">
  260. and a.name like concat('%',#{contractName},'%')
  261. </if>
  262. <if test="supplementCode != null and '' != supplementCode">
  263. and f.contract_no like concat('%',#{supplementCode},'%')
  264. </if>
  265. <if test="purchaseEntId != null and '' != purchaseEntId">
  266. and b.unit_type = 2
  267. and b.id = #{purchaseEntId}
  268. </if>
  269. <if test="supplyEntId != null and '' != supplyEntId">
  270. and b.unit_type = 1
  271. and b.id = #{supplyEntId}
  272. </if>
  273. <if test="allEnt != null and allEnt.size() > 0">
  274. and a.ent_id in
  275. <foreach collection="allEnt" separator="," open="(" close=")" item="item">
  276. #{item}
  277. </foreach>
  278. </if>
  279. order by a.create_time desc
  280. </select>
  281. <select id="queryNewSignPrice" resultType="com.sckw.contract.api.model.vo.TradeContractGoodsDto">
  282. select a.id, b.price
  283. from kwc_contract_trade a
  284. left join kwc_contract_trade_goods b on a.id = b.contract_id and b.del_flag = 0
  285. left join kwc_contract_trade_unit c on a.id = c.contract_id and c.del_flag = 0
  286. <where>
  287. a.del_flag = 0
  288. and a.status = 0
  289. and c.unit_type = 2
  290. and a.start_time &lt; #{time}
  291. and (a.end_time &gt; #{time} OR a.end_time IS NULL)
  292. and c.ent_id = #{entId}
  293. and b.goods_id = #{goodsId}
  294. order by a.create_time desc
  295. limit 1
  296. </where>
  297. </select>
  298. <select id="queryNewSignGoods" resultType="java.lang.Long">
  299. select distinct b.goods_id
  300. from kwc_contract_trade a
  301. left join kwc_contract_trade_goods b on a.id = b.contract_id and b.del_flag = 0
  302. left join kwc_contract_trade_unit c on a.id = c.contract_id and c.del_flag = 0
  303. <where>
  304. a.del_flag = 0
  305. and a.status = 0
  306. and c.unit_type = 2
  307. and a.start_time &lt; #{time}
  308. and (a.end_time &gt; #{time} OR a.end_time IS NULL)
  309. and c.ent_id = #{entId}
  310. </where>
  311. </select>
  312. <select id="querySignTradeContract" resultType="java.lang.Long">
  313. select distinct b.goods_id
  314. from kwc_contract_trade a
  315. left join kwc_contract_trade_goods b on a.id = b.contract_id and b.del_flag = 0
  316. left join kwc_contract_trade_unit c on a.id = c.contract_id and c.del_flag = 0
  317. <where>
  318. a.del_flag = 0
  319. and a.status = 0
  320. and c.unit_type = 2
  321. and a.start_time &lt; #{time}
  322. and (a.end_time &gt; #{time} OR a.end_time IS NULL)
  323. and c.ent_id = #{entId}
  324. order by a.create_time desc
  325. </where>
  326. </select>
  327. <select id="selectByContract" resultType="java.lang.Long">
  328. select distinct b.goods_id
  329. from kwc_contract_trade a
  330. left join kwc_contract_trade_goods b on a.id = b.contract_id and b.del_flag = 0
  331. <where>
  332. a.del_flag = 0
  333. and a.status = 0
  334. and a.id = #{contractId}
  335. </where>
  336. </select>
  337. </mapper>