KwoWantBuyMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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="com.sckw.order.dao.KwpWantBuyMapper">
  4. <sql id="Base_Column_List">
  5. kb.id
  6. ,kb.`name`
  7. ,kb.ent_id
  8. , kb.goods_type goodsType
  9. , kb.spec
  10. , kb.price
  11. , kb.amount
  12. , kb.contacts
  13. , kb.phone
  14. , kb.status
  15. , kb.remark
  16. , kb.create_time createTime
  17. , kb.update_time updateTime
  18. , kt.want_buy_id wantBuyId
  19. , kt.trading trading
  20. , kba.name addressName
  21. , kba.city_name cityName
  22. , kba.detail_address detailAddress
  23. </sql>
  24. <resultMap id="wangBuyResultMap" type="com.sckw.order.model.vo.res.WantBuySelectRes">
  25. <id column="id" property="id"/>
  26. <result column="name" property="name"/>
  27. <result column="goodsType" property="goodsType"/>
  28. <result column="spec" property="spec"/>
  29. <result column="price" property="price"/>
  30. <result column="amount" property="amount"/>
  31. <result column="contacts" property="contacts"/>
  32. <result column="phone" property="phone"/>
  33. <result column="status" property="status"/>
  34. <result column="remark" property="remark"/>
  35. <result column="createTime" property="createTime"/>
  36. <result column="updateTime" property="updateTime"/>
  37. <collection property="wantBuyTradings" column="id" ofType="com.sckw.order.model.vo.res.WantBuyTradingRes" javaType="java.util.List" select="tradingSql">
  38. <id column="wantBuyId" property="wantBuyId"/>
  39. <result column="trading" property="trading"/>
  40. </collection>
  41. </resultMap>
  42. <sql id="managerWhere">
  43. kb.del_flag = 0
  44. <if test="authEntIdList != null and authEntIdList.size() != 0">
  45. and kb.ent_id in
  46. <foreach collection="authEntIdList" item="item" open="(" close=")" separator=",">
  47. #{item}
  48. </foreach>
  49. </if>
  50. <if test="wantBuyReq.startCreateTime != null">
  51. and kb.create_time &gt;= #{wantBuyReq.startCreateTime,jdbcType=TIMESTAMP}
  52. </if>
  53. <if test="wantBuyReq.endCreateTime != null">
  54. and kb.create_time &lt;= #{wantBuyReq.endCreateTime,jdbcType=TIMESTAMP}
  55. </if>
  56. <if test="wantBuyReq.tradings != null and wantBuyReq.tradings.size() > 0">
  57. <!--私用and条件-->
  58. <!-- and kt.trading in-->
  59. <!-- <foreach collection="wantBuyReq.tradings" item="item" open="(" close=")" separator=",">-->
  60. <!-- #{item,jdbcType=VARCHAR}-->
  61. <!-- </foreach>-->
  62. <!-- 使用 AND 条件 -->
  63. <!-- and (-->
  64. <!-- <foreach collection="wantBuyReq.tradings" item="item" separator=" and ">-->
  65. <!-- kt.trading = #{item,jdbcType=VARCHAR}-->
  66. <!-- </foreach>-->
  67. <!-- )-->
  68. <foreach collection="wantBuyReq.tradings" item="value" separator="">
  69. AND EXISTS (
  70. SELECT 1
  71. FROM kwo_want_buy_trading kt2
  72. WHERE kt2.want_buy_id = kb.id
  73. AND kt2.trading = #{value}
  74. )
  75. </foreach>
  76. </if>
  77. <if test="wantBuyReq.wantBuyIds != null and wantBuyReq.wantBuyIds.size() > 0">
  78. and kb.id in
  79. <foreach collection="wantBuyReq.wantBuyIds" item="item" open="(" close=")" separator=",">
  80. #{item,jdbcType=BIGINT}
  81. </foreach>
  82. </if>
  83. <if test="wantBuyReq.status != null">
  84. and kb.status = #{wantBuyReq.status}
  85. </if>
  86. <if test="wantBuyReq.entId != null ">
  87. and kb.ent_id = #{wantBuyReq.entId}
  88. </if>
  89. <if test="wantBuyReq.keywords != null and wantBuyReq.keywords != ''">
  90. <if test="wantBuyReq.entIds != null and wantBuyReq.entIds.size() > 0">
  91. and (kb.ent_id in
  92. <foreach collection="wantBuyReq.entIds" item="item" open="(" close=")" separator=",">
  93. #{item,jdbcType=BIGINT}
  94. </foreach>
  95. or kb.`name` like concat('%', #{wantBuyReq.keywords,jdbcType=VARCHAR}, '%')
  96. )
  97. </if>
  98. <if test="wantBuyReq.entIds == null or wantBuyReq.entIds.size() == 0">
  99. and (kb.`name` like concat('%', #{wantBuyReq.keywords,jdbcType=VARCHAR}, '%'))
  100. </if>
  101. </if>
  102. <if test="wantBuyReq.goodsTypeValueSearch != null and wantBuyReq.goodsTypeValueSearch.size() > 0">
  103. and kb.goods_type in
  104. <foreach collection="wantBuyReq.goodsTypeValueSearch" item="item" open="(" close=")" separator=",">
  105. #{item}
  106. </foreach>
  107. </if>
  108. <if test="wantBuyReq.cityCode != null and wantBuyReq.cityCode != ''">
  109. and (kba.`city_code` like concat(#{wantBuyReq.cityCode,jdbcType=VARCHAR}, '%'))
  110. </if>
  111. <if test="wantBuyReq.systemType != null and wantBuyReq.systemType == 1">
  112. and kb.status in (1,2)
  113. </if>
  114. </sql>
  115. <sql id="where">
  116. kb.del_flag = 0
  117. <if test="wantBuyReq.startCreateTime != null">
  118. and kb.create_time &gt;= #{wantBuyReq.startCreateTime,jdbcType=TIMESTAMP}
  119. </if>
  120. <if test="wantBuyReq.endCreateTime != null">
  121. and kb.create_time &lt;= #{wantBuyReq.endCreateTime,jdbcType=TIMESTAMP}
  122. </if>
  123. <if test="wantBuyReq.tradings != null and wantBuyReq.tradings.size() > 0">
  124. <!--私用and条件-->
  125. <!-- and kt.trading in-->
  126. <!-- <foreach collection="wantBuyReq.tradings" item="item" open="(" close=")" separator=",">-->
  127. <!-- #{item,jdbcType=VARCHAR}-->
  128. <!-- </foreach>-->
  129. <!-- 使用 AND 条件 -->
  130. <!-- and (-->
  131. <!-- <foreach collection="wantBuyReq.tradings" item="item" separator=" and ">-->
  132. <!-- kt.trading = #{item,jdbcType=VARCHAR}-->
  133. <!-- </foreach>-->
  134. <!-- )-->
  135. <foreach collection="wantBuyReq.tradings" item="value" separator="">
  136. AND EXISTS (
  137. SELECT 1
  138. FROM kwo_want_buy_trading kt2
  139. WHERE kt2.want_buy_id = kb.id
  140. AND kt2.trading = #{value}
  141. )
  142. </foreach>
  143. </if>
  144. <if test="wantBuyReq.wantBuyIds != null and wantBuyReq.wantBuyIds.size() > 0">
  145. and kb.id in
  146. <foreach collection="wantBuyReq.wantBuyIds" item="item" open="(" close=")" separator=",">
  147. #{item,jdbcType=BIGINT}
  148. </foreach>
  149. </if>
  150. <if test="wantBuyReq.status != null">
  151. and kb.status = #{wantBuyReq.status}
  152. </if>
  153. <if test="wantBuyReq.entId != null ">
  154. and kb.ent_id = #{wantBuyReq.entId}
  155. </if>
  156. <if test="wantBuyReq.keywords != null and wantBuyReq.keywords != ''">
  157. <if test="wantBuyReq.entIds != null and wantBuyReq.entIds.size() > 0">
  158. and (kb.ent_id in
  159. <foreach collection="wantBuyReq.entIds" item="item" open="(" close=")" separator=",">
  160. #{item,jdbcType=BIGINT}
  161. </foreach>
  162. or kb.`name` like concat('%', #{wantBuyReq.keywords,jdbcType=VARCHAR}, '%')
  163. )
  164. </if>
  165. <if test="wantBuyReq.entIds == null or wantBuyReq.entIds.size() == 0">
  166. and (kb.`name` like concat('%', #{wantBuyReq.keywords,jdbcType=VARCHAR}, '%'))
  167. </if>
  168. </if>
  169. <if test="wantBuyReq.goodsTypeValueSearch != null and wantBuyReq.goodsTypeValueSearch.size() > 0">
  170. and kb.goods_type in
  171. <foreach collection="wantBuyReq.goodsTypeValueSearch" item="item" open="(" close=")" separator=",">
  172. #{item}
  173. </foreach>
  174. </if>
  175. <if test="wantBuyReq.cityCode != null and wantBuyReq.cityCode != ''">
  176. and (kba.`city_code` like concat(#{wantBuyReq.cityCode,jdbcType=VARCHAR}, '%'))
  177. </if>
  178. <if test="wantBuyReq.systemType != null and wantBuyReq.systemType == 1">
  179. and kb.status in (1,2)
  180. </if>
  181. <if test="wantBuyReq.specialEntIds != null and wantBuyReq.specialEntIds.size() > 0">
  182. and kb.ent_id in
  183. <foreach collection="wantBuyReq.specialEntIds" item="item" open="(" close=")" separator=",">
  184. #{item,jdbcType=BIGINT}
  185. </foreach>
  186. </if>
  187. </sql>
  188. <select id="pageSelect" resultMap="wangBuyResultMap" resultType="com.sckw.order.model.vo.res.WantBuySelectRes">
  189. select
  190. <include refid="Base_Column_List" />
  191. from kwo_want_buy kb left join kwo_want_buy_address kba on kb.id = kba.want_buy_id and kba.del_flag = 0
  192. left join kwo_want_buy_trading kt on kb.id = kt.want_buy_id and kt.del_flag = 0
  193. <where>
  194. <include refid="where" />
  195. </where>
  196. group by kb.id
  197. order by kb.create_time desc
  198. </select><select id="pageSelectAllByManager" resultMap="wangBuyResultMap" resultType="com.sckw.order.model.vo.res.WantBuySelectRes">
  199. select
  200. <include refid="Base_Column_List" />
  201. from kwo_want_buy kb left join kwo_want_buy_address kba on kb.id = kba.want_buy_id and kba.del_flag = 0
  202. left join kwo_want_buy_trading kt on kb.id = kt.want_buy_id and kt.del_flag = 0
  203. <where>
  204. <include refid="managerWhere" />
  205. </where>
  206. group by kb.id
  207. order by kb.create_time desc
  208. </select>
  209. <!-- <resultMap id="tradIngMap" type="com.sckw.order.model.KwoWantBuyTrading">-->
  210. <resultMap id="tradIngMap" type="com.sckw.order.model.vo.res.WantBuyTradingRes">
  211. <id column="wantBuyId" property="wantBuyId"/>
  212. <result column="trading" property="trading"/>
  213. </resultMap>
  214. <select id="tradingSql" resultMap="tradIngMap">
  215. select want_buy_id wantBuyId, trading
  216. from kwo_want_buy_trading
  217. where want_buy_id = #{wantBuyId} and del_flag = 0
  218. </select>
  219. <select id="statisticsCount" resultType="com.sckw.order.model.vo.res.TableTopRes" parameterType="java.util.Map">
  220. select kb.`status` value
  221. from kwo_want_buy kb left join kwo_want_buy_trading kt on kb.id = kt.want_buy_id
  222. <where>
  223. <include refid="where" />
  224. </where>
  225. group by kb.id
  226. order by kb.create_time desc
  227. </select>
  228. <select id="queryBuyHallList" resultMap="wangBuyResultMap" resultType="com.sckw.order.model.vo.res.WantBuySelectRes">
  229. select
  230. <include refid="Base_Column_List" />
  231. from kwo_want_buy kb left join kwo_want_buy_address kba on kb.id = kba.want_buy_id and kba.del_flag = 0
  232. left join kwo_want_buy_trading kt on kb.id = kt.want_buy_id and kt.del_flag = 0
  233. <where>
  234. <include refid="where" />
  235. </where>
  236. group by kb.id
  237. order by RAND()
  238. </select>
  239. </mapper>