|
|
@@ -1,55 +1,118 @@
|
|
|
-<?xml version="1.0" encoding="UTF-8" ?>
|
|
|
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
-<mapper namespace="com.fs.hisStore.mapper.FsStoreProductUserEndCategoryMapper">
|
|
|
-
|
|
|
- <insert id="insertBatch">
|
|
|
- insert into fs_store_product_user_end_category (product_id, user_end_category_id) values
|
|
|
- <foreach collection="categoryIds" item="cid" separator=",">(#{productId}, #{cid})</foreach>
|
|
|
- </insert>
|
|
|
-
|
|
|
- <delete id="deleteByProductId">
|
|
|
- delete from fs_store_product_user_end_category where product_id = #{productId}
|
|
|
- </delete>
|
|
|
-
|
|
|
- <select id="selectCategoryIdsByProductId" resultType="java.lang.Long">
|
|
|
- select user_end_category_id from fs_store_product_user_end_category where product_id = #{productId}
|
|
|
- </select>
|
|
|
-
|
|
|
- <delete id="deleteByCategoryIds">
|
|
|
- delete from fs_store_product_user_end_category where user_end_category_id in
|
|
|
- <foreach collection="categoryIds" item="id" open="(" separator="," close=")">#{id}</foreach>
|
|
|
- </delete>
|
|
|
-
|
|
|
- <select id="selectDistinctProductIdsByCategoryId" resultType="java.lang.Long">
|
|
|
- select distinct a.product_id from fs_store_product_user_end_category a left join fs_store_product_scrm c on a.product_id = c.product_id
|
|
|
- where a.user_end_category_id = #{categoryId} and c.is_del = 0 and c.is_show = 1 and c.is_display = 1 and c.is_audit = 1
|
|
|
- <if test="keyword != null and keyword != ''">
|
|
|
- and c.product_name like CONCAT('%', #{keyword}, '%')
|
|
|
- </if>
|
|
|
- order by c.sort asc, c.create_time desc, a.product_id
|
|
|
- </select>
|
|
|
-
|
|
|
- <select id="selectDistinctProductIds" resultType="java.lang.Long">
|
|
|
- select distinct a.product_id from fs_store_product_user_end_category a left join fs_store_product_scrm c on a.product_id = c.product_id
|
|
|
- where c.is_del = 0 and c.is_show = 1 and c.is_display = 1 and c.is_audit = 1
|
|
|
- <if test="keyword != null and keyword != ''">
|
|
|
- and c.product_name like CONCAT('%', #{keyword}, '%')
|
|
|
- </if>
|
|
|
- order by c.sort asc, c.create_time desc, a.product_id
|
|
|
- </select>
|
|
|
-
|
|
|
- <!-- 按区域位置(1金刚区 2瀑布区)查询商品ID,支持 keyword、storeId -->
|
|
|
- <select id="selectDistinctProductIdsByPosition" resultType="java.lang.Long">
|
|
|
- select distinct a.product_id from fs_store_product_user_end_category a
|
|
|
- left join fs_store_product_scrm c on a.product_id = c.product_id
|
|
|
- left join fs_store_user_end_category_scrm uec on a.user_end_category_id = uec.id
|
|
|
- where uec.status = 1 and uec.position = #{position}
|
|
|
- and c.is_del = 0 and c.is_show = 1 and c.is_display = 1 and c.is_audit = 1
|
|
|
- <if test="id != null and id != 0">and a.user_end_category_id = #{id}</if>
|
|
|
- <if test="storeId != null">and uec.store_id = #{storeId}</if>
|
|
|
- <if test="keyword != null and keyword != ''">
|
|
|
- and c.product_name like CONCAT('%', #{keyword}, '%')
|
|
|
- </if>
|
|
|
- order by c.sort asc, c.create_time desc, a.product_id
|
|
|
- </select>
|
|
|
-</mapper>
|
|
|
+<?xml version="1.0" encoding="UTF-8" ?>
|
|
|
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
+<mapper namespace="com.fs.hisStore.mapper.FsStoreProductUserEndCategoryMapper">
|
|
|
+
|
|
|
+ <insert id="insertBatch">
|
|
|
+ insert into fs_store_product_user_end_category (product_id, user_end_category_id, sort) values
|
|
|
+ <foreach collection="categoryIds" item="cid" separator=",">(#{productId}, #{cid}, 0)</foreach>
|
|
|
+ </insert>
|
|
|
+
|
|
|
+ <delete id="deleteByProductId">
|
|
|
+ delete from fs_store_product_user_end_category where product_id = #{productId}
|
|
|
+ </delete>
|
|
|
+
|
|
|
+ <select id="selectCategoryIdsByProductId" resultType="java.lang.Long">
|
|
|
+ select user_end_category_id from fs_store_product_user_end_category where product_id = #{productId}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <delete id="deleteByCategoryIds">
|
|
|
+ delete from fs_store_product_user_end_category where user_end_category_id in
|
|
|
+ <foreach collection="categoryIds" item="id" open="(" separator="," close=")">#{id}</foreach>
|
|
|
+ </delete>
|
|
|
+
|
|
|
+ <!-- 排序使用关联表 a.sort;GROUP BY 避免同一商品多分类时 DISTINCT+ORDER BY 不稳定 -->
|
|
|
+ <select id="selectDistinctProductIdsByCategoryId" resultType="java.lang.Long">
|
|
|
+ select t.product_id from (
|
|
|
+ select a.product_id,
|
|
|
+ min(case when a.sort is null or a.sort = 0 then 1 else 0 end) as o1,
|
|
|
+ max(case when a.sort is null or a.sort = 0 then 0 else a.sort end) as o2,
|
|
|
+ max(c.create_time) as ct
|
|
|
+ from fs_store_product_user_end_category a
|
|
|
+ left join fs_store_product_scrm c on a.product_id = c.product_id
|
|
|
+ where a.user_end_category_id = #{categoryId} and c.is_del = 0 and c.is_show = 1 and c.is_display = 1 and c.is_audit = 1
|
|
|
+ <if test="keyword != null and keyword != ''">
|
|
|
+ and c.product_name like CONCAT('%', #{keyword}, '%')
|
|
|
+ </if>
|
|
|
+ group by a.product_id
|
|
|
+ ) t
|
|
|
+ order by t.o1 asc, t.o2 desc, t.ct desc, t.product_id desc
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="selectDistinctProductIds" resultType="java.lang.Long">
|
|
|
+ select t.product_id from (
|
|
|
+ select a.product_id,
|
|
|
+ min(case when a.sort is null or a.sort = 0 then 1 else 0 end) as o1,
|
|
|
+ max(case when a.sort is null or a.sort = 0 then 0 else a.sort end) as o2,
|
|
|
+ max(c.create_time) as ct
|
|
|
+ from fs_store_product_user_end_category a
|
|
|
+ left join fs_store_product_scrm c on a.product_id = c.product_id
|
|
|
+ where c.is_del = 0 and c.is_show = 1 and c.is_display = 1 and c.is_audit = 1
|
|
|
+ <if test="keyword != null and keyword != ''">
|
|
|
+ and c.product_name like CONCAT('%', #{keyword}, '%')
|
|
|
+ </if>
|
|
|
+ group by a.product_id
|
|
|
+ ) t
|
|
|
+ order by t.o1 asc, t.o2 desc, t.ct desc, t.product_id desc
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 按区域位置(1金刚区 2瀑布区)查询商品ID,支持 keyword、storeId;排序为关联表 a.sort -->
|
|
|
+ <select id="selectDistinctProductIdsByPosition" resultType="java.lang.Long">
|
|
|
+ select t.product_id from (
|
|
|
+ select a.product_id,
|
|
|
+ min(case when a.sort is null or a.sort = 0 then 1 else 0 end) as o1,
|
|
|
+ max(case when a.sort is null or a.sort = 0 then 0 else a.sort end) as o2,
|
|
|
+ max(c.create_time) as ct
|
|
|
+ from fs_store_product_user_end_category a
|
|
|
+ left join fs_store_product_scrm c on a.product_id = c.product_id
|
|
|
+ left join fs_store_user_end_category_scrm uec on a.user_end_category_id = uec.id
|
|
|
+ where uec.status = 1 and uec.position = #{position}
|
|
|
+ and c.is_del = 0 and c.is_show = 1 and c.is_display = 1 and c.is_audit = 1
|
|
|
+ <if test="id != null and id != 0">and a.user_end_category_id = #{id}</if>
|
|
|
+ <if test="storeId != null">and uec.store_id = #{storeId}</if>
|
|
|
+ <if test="keyword != null and keyword != ''">
|
|
|
+ and c.product_name like CONCAT('%', #{keyword}, '%')
|
|
|
+ </if>
|
|
|
+ group by a.product_id
|
|
|
+ ) t
|
|
|
+ order by t.o1 asc, t.o2 desc, t.ct desc, t.product_id desc
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <update id="updateRelSortByCategoryAndProduct">
|
|
|
+ update fs_store_product_user_end_category
|
|
|
+ set sort = #{sort}
|
|
|
+ where user_end_category_id = #{userEndCategoryId} and product_id = #{productId}
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <select id="selectSortByCategoryAndProductIds" resultType="com.fs.hisStore.domain.FsStoreProductUserEndCategory">
|
|
|
+ select product_id, user_end_category_id, sort
|
|
|
+ from fs_store_product_user_end_category
|
|
|
+ where user_end_category_id = #{userEndCategoryId}
|
|
|
+ and product_id in
|
|
|
+ <foreach collection="productIds" item="pid" open="(" separator="," close=")">#{pid}</foreach>
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="selectAggSortByPositionAndProductIds" resultType="com.fs.hisStore.domain.FsStoreProductUserEndCategory">
|
|
|
+ select a.product_id,
|
|
|
+ max(case when a.sort is null or a.sort = 0 then 0 else a.sort end) as sort
|
|
|
+ from fs_store_product_user_end_category a
|
|
|
+ left join fs_store_product_scrm c on a.product_id = c.product_id
|
|
|
+ left join fs_store_user_end_category_scrm uec on a.user_end_category_id = uec.id
|
|
|
+ where uec.status = 1 and uec.position = #{position}
|
|
|
+ and c.is_del = 0 and c.is_show = 1 and c.is_display = 1 and c.is_audit = 1
|
|
|
+ <if test="storeId != null">and uec.store_id = #{storeId}</if>
|
|
|
+ and a.product_id in
|
|
|
+ <foreach collection="productIds" item="pid" open="(" separator="," close=")">#{pid}</foreach>
|
|
|
+ group by a.product_id
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="selectAggSortGlobalAndProductIds" resultType="com.fs.hisStore.domain.FsStoreProductUserEndCategory">
|
|
|
+ select a.product_id,
|
|
|
+ max(case when a.sort is null or a.sort = 0 then 0 else a.sort end) as sort
|
|
|
+ from fs_store_product_user_end_category a
|
|
|
+ left join fs_store_product_scrm c on a.product_id = c.product_id
|
|
|
+ where c.is_del = 0 and c.is_show = 1 and c.is_display = 1 and c.is_audit = 1
|
|
|
+ and a.product_id in
|
|
|
+ <foreach collection="productIds" item="pid" open="(" separator="," close=")">#{pid}</foreach>
|
|
|
+ group by a.product_id
|
|
|
+ </select>
|
|
|
+</mapper>
|