LiveGoodsMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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.fs.live.mapper.LiveGoodsMapper">
  6. <resultMap type="LiveGoods" id="LiveGoodsResult">
  7. <result property="goodsId" column="goods_id" />
  8. <result property="liveId" column="live_id" />
  9. <result property="companyId" column="company_id" />
  10. <result property="companyUserId" column="company_user_id" />
  11. <result property="storeId" column="store_id" />
  12. <result property="productId" column="product_id" />
  13. <result property="createTime" column="create_time" />
  14. <result property="createBy" column="create_by" />
  15. <result property="updateBy" column="update_by" />
  16. <result property="updateTime" column="update_time" />
  17. <result property="remark" column="remark" />
  18. <result property="status" column="status" />
  19. <result property="stock" column="stock" />
  20. <result property="sort" column="sort" />
  21. <result property="isShow" column="is_show" />
  22. <result property="sales" column="sales" />
  23. </resultMap>
  24. <sql id="selectLiveGoodsVo">
  25. select goods_id, live_id, company_id, company_user_id,sales, store_id, product_id, create_time, create_by, update_by, update_time, remark, status, stock, sort,case when is_show = 1 then true else false end as is_show from live_goods
  26. </sql>
  27. <select id="selectLiveGoodsList" parameterType="LiveGoods" resultMap="LiveGoodsResult">
  28. <include refid="selectLiveGoodsVo"/>
  29. <where>
  30. <if test="liveId != null "> and live_id = #{liveId}</if>
  31. <if test="companyId != null "> and company_id = #{companyId}</if>
  32. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  33. <if test="storeId != null "> and store_id = #{storeId}</if>
  34. <if test="productId != null "> and product_id = #{productId}</if>
  35. <if test="status != null "> and status = #{status}</if>
  36. <if test="stock != null "> and stock = #{stock}</if>
  37. <if test="sort != null "> and sort = #{sort}</if>
  38. <if test="isShow != null "> and is_show = #{isShow}</if>
  39. <if test="sales != null "> and sales = #{sales}</if>
  40. </where>
  41. </select>
  42. <select id="selectLiveGoodsByGoodsId" parameterType="Long" resultMap="LiveGoodsResult">
  43. <include refid="selectLiveGoodsVo"/>
  44. where goods_id = #{goodsId}
  45. </select>
  46. <insert id="insertLiveGoods" parameterType="LiveGoods" useGeneratedKeys="true" keyProperty="goodsId">
  47. insert into live_goods
  48. <trim prefix="(" suffix=")" suffixOverrides=",">
  49. <if test="liveId != null">live_id,</if>
  50. <if test="companyId != null">company_id,</if>
  51. <if test="companyUserId != null">company_user_id,</if>
  52. <if test="storeId != null">store_id,</if>
  53. <if test="productId != null">product_id,</if>
  54. <if test="createTime != null">create_time,</if>
  55. <if test="createBy != null">create_by,</if>
  56. <if test="updateBy != null">update_by,</if>
  57. <if test="updateTime != null">update_time,</if>
  58. <if test="remark != null">remark,</if>
  59. <if test="status != null">status,</if>
  60. <if test="stock != null">stock,</if>
  61. <if test="sort != null">sort,</if>
  62. <if test="isShow != null">is_show,</if>
  63. <if test="sales != null">sales,</if>
  64. </trim>
  65. <trim prefix="values (" suffix=")" suffixOverrides=",">
  66. <if test="liveId != null">#{liveId},</if>
  67. <if test="companyId != null">#{companyId},</if>
  68. <if test="companyUserId != null">#{companyUserId},</if>
  69. <if test="storeId != null">#{storeId},</if>
  70. <if test="productId != null">#{productId},</if>
  71. <if test="createTime != null">#{createTime},</if>
  72. <if test="createBy != null">#{createBy},</if>
  73. <if test="updateBy != null">#{updateBy},</if>
  74. <if test="updateTime != null">#{updateTime},</if>
  75. <if test="remark != null">#{remark},</if>
  76. <if test="status != null">#{status},</if>
  77. <if test="stock != null">#{stock},</if>
  78. <if test="sort != null">#{sort},</if>
  79. <if test="isShow != null">#{isShow},</if>
  80. <if test="sales != null">#{sales},</if>
  81. </trim>
  82. </insert>
  83. <update id="updateLiveGoods" parameterType="LiveGoods">
  84. update live_goods
  85. <trim prefix="SET" suffixOverrides=",">
  86. <if test="liveId != null">live_id = #{liveId},</if>
  87. <if test="companyId != null">company_id = #{companyId},</if>
  88. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  89. <if test="storeId != null">store_id = #{storeId},</if>
  90. <if test="productId != null">product_id = #{productId},</if>
  91. <if test="createTime != null">create_time = #{createTime},</if>
  92. <if test="createBy != null">create_by = #{createBy},</if>
  93. <if test="updateBy != null">update_by = #{updateBy},</if>
  94. <if test="updateTime != null">update_time = #{updateTime},</if>
  95. <if test="remark != null">remark = #{remark},</if>
  96. <if test="status != null">status = #{status},</if>
  97. <if test="stock != null">stock = #{stock},</if>
  98. <if test="sort != null">sort = #{sort},</if>
  99. <if test="isShow != null">is_show = #{isShow},</if>
  100. <if test="sales != null">sales = #{sales},</if>
  101. </trim>
  102. where goods_id = #{goodsId}
  103. </update>
  104. <delete id="deleteLiveGoodsByGoodsId" parameterType="Long">
  105. delete from live_goods where goods_id = #{goodsId}
  106. </delete>
  107. <delete id="deleteLiveGoodsByGoodsIds" parameterType="String">
  108. delete from live_goods where goods_id in
  109. <foreach item="goodsId" collection="array" open="(" separator="," close=")">
  110. #{goodsId}
  111. </foreach>
  112. </delete>
  113. <select id="selectStoreIdByLiveId" parameterType="Long" resultType="Long">
  114. select distinct store_id from live_goods where live_id = #{liveId}
  115. </select>
  116. <insert id="insertLiveGoodsList">
  117. INSERT INTO live_goods (
  118. live_id, company_id, company_user_id,
  119. product_id, create_time, create_by, update_by,
  120. update_time, remark, status, stock, sort, is_show,sales
  121. ) VALUES
  122. <foreach collection="liveGoodsList" item="item" separator=",">
  123. (
  124. #{item.liveId},
  125. <choose>
  126. <when test="item.companyId != null">
  127. #{item.companyId},
  128. </when>
  129. <otherwise>
  130. null,
  131. </otherwise>
  132. </choose>
  133. <choose>
  134. <when test="item.companyUserId != null">
  135. #{item.companyUserId},
  136. </when>
  137. <otherwise>
  138. null,
  139. </otherwise>
  140. </choose>
  141. #{item.productId},
  142. #{item.createTime},
  143. #{item.createBy},
  144. #{item.updateBy},
  145. #{item.updateTime},
  146. #{item.remark},
  147. #{item.status},
  148. #{item.stock},
  149. #{item.sort},
  150. #{item.isShow},
  151. #{item.sales}
  152. )
  153. </foreach>
  154. </insert>
  155. <select id="selectProductIdsByLiveId" resultType="string">
  156. SELECT product_id
  157. FROM live_goods
  158. WHERE live_id = #{liveId}
  159. </select>
  160. <select id="selectProductListByLiveId" parameterType="LiveGoods" resultType="com.fs.live.vo.LiveGoodsVo">
  161. select lg.goods_id,sp.image as img_url,sp.product_name,sp.price,sp.stock,lg.sales,lg.status,sp.product_id,sp.ot_price,case when lg.is_show = 1 then true else false end as is_show
  162. <if test="companyUserId != null "> ,if(uf.favorite_id is not null, true, false) is_favorite </if>
  163. from live_goods lg
  164. left join fs_store_product sp
  165. ON lg.product_id = sp.product_id
  166. <if test="companyUserId != null "> left join live_user_favorite uf on uf.product_id = lg.goods_id and uf.user_id = #{companyUserId} </if>
  167. <where>
  168. lg.live_id = #{liveId} and lg.status=1 and sp.is_show = 1
  169. <if test="companyId != null "> and company_id = #{companyId}</if>
  170. <if test="productId != null "> and product_id = #{productId}</if>
  171. <if test="status != null "> and status = #{status}</if>
  172. <if test="stock != null "> and stock = #{stock}</if>
  173. <if test="sort != null "> and sort = #{sort}</if>
  174. <if test="isShow != null "> and is_show = #{isShow}</if>
  175. <if test="sales != null "> and sales = #{sales}</if>
  176. <if test="keywords != null and keywords != ''">
  177. and sp.product_name like concat('%',#{keywords},'%')
  178. </if>
  179. </where>
  180. </select>
  181. <select id="selectProductListByLiveIdAll" parameterType="LiveGoods" resultType="com.fs.live.vo.LiveGoodsVo">
  182. select lg.goods_id,sp.image as img_url,sp.product_name,sp.price,lg.stock,lg.sales,lg.status,sp.product_id,sp.ot_price,case when lg.is_show = 1 then true else false end as is_show,sp.is_show as fs_status
  183. from live_goods lg
  184. left join fs_store_product sp
  185. ON lg.product_id = sp.product_id
  186. <where>
  187. live_id = #{liveId}
  188. <if test="productId != null "> and product_id = #{productId}</if>
  189. <if test="status != null "> and status = #{status}</if>
  190. <if test="stock != null "> and stock = #{stock}</if>
  191. <if test="sort != null "> and sort = #{sort}</if>
  192. <if test="isShow != null "> and is_show = #{isShow}</if>
  193. <if test="keywords != null and keywords != ''">
  194. and sp.product_name like concat('%',#{keywords},'%')
  195. </if>
  196. </where>
  197. </select>
  198. <select id="selectLiveGoodsVoByGoodsId" resultType="com.fs.live.vo.LiveGoodsVo">
  199. select lg.goods_id,sp.image as img_url,sp.product_name,sp.price,lg.stock,lg.sales,lg.status,sp.product_id,sp.ot_price, case when lg.is_show = 1 then true else false end as is_show,sp.is_show as fs_status
  200. from live_goods lg
  201. left join fs_store_product sp
  202. ON lg.product_id = sp.product_id
  203. <where>
  204. goods_id = #{goodsId}
  205. </where>
  206. </select>
  207. <select id="showGoods" resultType="com.fs.live.vo.LiveGoodsVo">
  208. select lg.goods_id,sp.image as img_url,sp.product_name,sp.price,lg.stock,lg.sales,lg.status,sp.product_id,sp.ot_price, case when lg.is_show = 1 then true else false end as is_show,sp.is_show as fs_status
  209. from live_goods lg
  210. left join fs_store_product sp
  211. ON lg.product_id = sp.product_id
  212. <where>
  213. lg.live_id = #{liveId} and lg.is_show = 1
  214. </where>
  215. limit 1
  216. </select>
  217. <update id="updateBatchList" parameterType="com.fs.live.vo.LiveGoodsListVo">
  218. update live_goods set status = #{listVo.status} where goods_id in
  219. <foreach item="goodsId" collection="listVo.goodsIds" open="(" separator="," close=")">
  220. #{goodsId}
  221. </foreach>
  222. </update>
  223. <delete id="deleteBatchList" parameterType="com.fs.live.vo.LiveGoodsListVo">
  224. delete from live_goods
  225. WHERE goods_id IN
  226. <foreach item="goodsId" collection="listVo.goodsIds" open="(" separator="," close=")">
  227. #{goodsId}
  228. </foreach>
  229. </delete>
  230. <select id="selectProductListByOrder" parameterType="com.fs.live.domain.LiveOrder" resultType="com.fs.live.vo.LiveGoodsVo">
  231. select sp.image as img_url,sp.product_name,sp.price,sp.stock,sp.sales,sp.product_id,sp.ot_price, sp.is_show as fs_status,pav.bar_code
  232. from fs_store_product sp
  233. left join fs_store_product_attr_value pav
  234. ON sp.product_id = pav.product_id
  235. <where>
  236. sp.product_id = #{productId}
  237. </where>
  238. </select>
  239. <select id="selectLiveGoodsListByStoreId" resultType="com.fs.live.vo.LiveGoodsVo">
  240. select
  241. g.*,
  242. if(uf.favorite_id is not null, true, false) isFavorite,
  243. p.image as img_url, p.product_name, p.price, g.sales, p.ot_price,p.is_show as fs_status
  244. from live_goods g
  245. left join fs_store_product p on p.product_id = g.product_id and p.is_show = 1
  246. left join live_user_favorite uf on uf.product_id = g.goods_id and uf.user_id = #{params.userId}
  247. where g.status = 1
  248. <if test="params.productName != null "> and p.product_name like concat('%',#{params.productName},'%')</if>
  249. <if test="params.liveId != null "> and g.live_id = #{params.liveId}</if>
  250. </select>
  251. <update id="handleShelfOrUnAdmin" parameterType="com.fs.live.vo.LiveGoodsListVo">
  252. update live_goods set status = #{listVo.status} where goods_id in
  253. <foreach item="goodsId" collection="listVo.goodsIds" open="(" separator="," close=")">
  254. #{goodsId}
  255. </foreach>
  256. </update>
  257. <update id="handleIsShowChange" parameterType="com.fs.live.vo.LiveGoodsListVo">
  258. update live_goods set is_show = #{listVo.isShow} and status = 1 where goods_id in
  259. <foreach item="goodsId" collection="listVo.goodsIds" open="(" separator="," close=")">
  260. #{goodsId}
  261. </foreach>
  262. </update>
  263. <delete id="handleDeleteSelectedAdmin" parameterType="com.fs.live.vo.LiveGoodsListVo">
  264. delete from live_goods
  265. WHERE goods_id IN
  266. <foreach item="goodsId" collection="listVo.goodsIds" open="(" separator="," close=")">
  267. #{goodsId}
  268. </foreach>
  269. </delete>
  270. </mapper>