xw 3 дней назад
Родитель
Сommit
d8e2f53d2f

+ 2 - 1
fs-admin/src/main/java/com/fs/hisStore/controller/FsStoreProductScrmController.java

@@ -153,7 +153,8 @@ public class FsStoreProductScrmController extends BaseController
     {
         FsStoreProductScrm product=fsStoreProductService.selectFsStoreProductById(productId);
         List<FsStoreProductAttrScrm> attrs=attrService.selectFsStoreProductAttrByProductId(productId);
-        return R.ok().put("data",product).put("attrs", attrs);
+        List<Long> tagIds = fsStoreProductService.selectTagIdsByProductId(productId);
+        return R.ok().put("data",product).put("attrs", attrs).put("tagIds", tagIds);
     }
 
     @PreAuthorize("@ss.hasPermi('store:storeProduct:add')")

+ 70 - 0
fs-admin/src/main/java/com/fs/hisStore/controller/FsStoreProductTagScrmController.java

@@ -0,0 +1,70 @@
+package com.fs.hisStore.controller;
+
+import com.fs.common.annotation.Log;
+import com.fs.common.core.controller.BaseController;
+import com.fs.common.core.domain.AjaxResult;
+import com.fs.common.core.page.TableDataInfo;
+import com.fs.common.enums.BusinessType;
+import com.fs.hisStore.domain.FsStoreProductTagScrm;
+import com.fs.hisStore.service.IFsStoreProductTagScrmService;
+import com.fs.hisStore.vo.FsStoreProductTagListVO;
+import com.fs.hisStore.vo.FsStoreTagProductVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * 商品标签管理
+ */
+@RestController
+@RequestMapping("/store/store/storeProductTag")
+public class FsStoreProductTagScrmController extends BaseController {
+
+    @Autowired
+    private IFsStoreProductTagScrmService productTagService;
+
+    @PreAuthorize("@ss.hasPermi('store:storeProductTag:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(FsStoreProductTagScrm query) {
+        startPage();
+        List<FsStoreProductTagListVO> list = productTagService.selectListVOPage(query);
+        return getDataTable(list);
+    }
+
+    @PreAuthorize("@ss.hasPermi('store:storeProductTag:query')")
+    @GetMapping("/products/{tagId}")
+    public TableDataInfo listProductsByTagId(@PathVariable Long tagId) {
+        startPage();
+        List<FsStoreTagProductVO> list = productTagService.selectProductsByTagId(tagId);
+        return getDataTable(list);
+    }
+
+    @PreAuthorize("@ss.hasPermi('store:storeProductTag:query')")
+    @GetMapping("/{id}")
+    public AjaxResult getInfo(@PathVariable Long id) {
+        return AjaxResult.success(productTagService.selectById(id));
+    }
+
+    @PreAuthorize("@ss.hasPermi('store:storeProductTag:add')")
+    @Log(title = "商品标签", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody FsStoreProductTagScrm entity) {
+        return toAjax(productTagService.insert(entity));
+    }
+
+    @PreAuthorize("@ss.hasPermi('store:storeProductTag:edit')")
+    @Log(title = "商品标签", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody FsStoreProductTagScrm entity) {
+        return toAjax(productTagService.update(entity));
+    }
+
+    @PreAuthorize("@ss.hasPermi('store:storeProductTag:remove')")
+    @Log(title = "商品标签", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable Long[] ids) {
+        return toAjax(productTagService.deleteByIds(ids));
+    }
+}

+ 30 - 0
fs-service/src/main/java/com/fs/hisStore/domain/FsStoreProductTagScrm.java

@@ -0,0 +1,30 @@
+package com.fs.hisStore.domain;
+
+import com.fs.common.annotation.Excel;
+import com.fs.common.core.domain.BaseEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 商品标签对象 fs_store_product_tag_scrm
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class FsStoreProductTagScrm extends BaseEntity {
+
+    private static final long serialVersionUID = 1L;
+
+    private Long id;
+
+    @Excel(name = "店铺ID")
+    private Long storeId;
+
+    @Excel(name = "标签名称")
+    private String tagName;
+
+    @Excel(name = "状态", readConverterExp = "1=显示,0=隐藏")
+    private Integer status;
+
+    @Excel(name = "排序")
+    private Long sort;
+}

+ 28 - 0
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreProductTagScrmMapper.java

@@ -0,0 +1,28 @@
+package com.fs.hisStore.mapper;
+
+import com.fs.hisStore.domain.FsStoreProductTagScrm;
+import com.fs.hisStore.vo.FsStoreProductTagListVO;
+import com.fs.hisStore.vo.FsStoreTagProductVO;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * ÉÌÆ·±êÇ© Mapper
+ */
+public interface FsStoreProductTagScrmMapper {
+
+    FsStoreProductTagScrm selectById(Long id);
+
+    List<FsStoreProductTagListVO> selectListVO(FsStoreProductTagScrm query);
+
+    int insert(FsStoreProductTagScrm entity);
+
+    int update(FsStoreProductTagScrm entity);
+
+    int deleteById(Long id);
+
+    int deleteByIds(Long[] ids);
+
+    List<FsStoreTagProductVO> selectProductsByTagId(@Param("tagId") Long tagId);
+}

+ 3 - 0
fs-service/src/main/java/com/fs/hisStore/param/FsStoreProductAddEditParam.java

@@ -302,4 +302,7 @@ public class FsStoreProductAddEditParam implements Serializable
     /** 所属小程序app_id,多个用逗号隔开 */
     private String appIds;
 
+    /** 商品标签ID列表(最多3个) */
+    private List<Long> tagIds;
+
 }

+ 2 - 0
fs-service/src/main/java/com/fs/hisStore/service/IFsStoreProductScrmService.java

@@ -153,4 +153,6 @@ public interface IFsStoreProductScrmService
     R copyStoreProduct(Long productId);
 
     R updateCache(Long productId);
+
+    List<Long> selectTagIdsByProductId(Long productId);
 }

+ 29 - 0
fs-service/src/main/java/com/fs/hisStore/service/IFsStoreProductTagScrmService.java

@@ -0,0 +1,29 @@
+package com.fs.hisStore.service;
+
+import com.fs.hisStore.domain.FsStoreProductTagScrm;
+import com.fs.hisStore.vo.FsStoreProductTagListVO;
+import com.fs.hisStore.vo.FsStoreTagProductVO;
+
+import java.util.List;
+
+/**
+ * ÉÌÆ·±êÇ© Service ½Ó¿Ú
+ */
+public interface IFsStoreProductTagScrmService {
+
+    FsStoreProductTagScrm selectById(Long id);
+
+    List<FsStoreProductTagListVO> selectListVO(FsStoreProductTagScrm query);
+
+    List<FsStoreProductTagListVO> selectListVOPage(FsStoreProductTagScrm query);
+
+    List<FsStoreTagProductVO> selectProductsByTagId(Long tagId);
+
+    int insert(FsStoreProductTagScrm entity);
+
+    int update(FsStoreProductTagScrm entity);
+
+    int deleteById(Long id);
+
+    int deleteByIds(Long[] ids);
+}

+ 28 - 0
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreProductScrmServiceImpl.java

@@ -166,6 +166,9 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
     @Autowired
     private RedisCacheT<FsStoreProductScrm> redisCacheT;
 
+    @Autowired
+    private FsStoreProductTagRelationScrmMapper fsStoreProductTagRelationScrmMapper;
+
     /**
      * 清除商品详情缓存
      * @param productId 商品ID
@@ -267,6 +270,13 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
     {
         storeAuditLogUtil.addBatchAuditArray(productIds, "", "");
         log.info("批量删除商品:{}", productIds);
+        if (productIds != null) {
+            for (Long pid : productIds) {
+                if (pid != null) {
+                    fsStoreProductTagRelationScrmMapper.deleteByProductId(pid);
+                }
+            }
+        }
         int result = fsStoreProductMapper.deleteFsStoreProductByIds(productIds);
 
         // 清除缓存
@@ -527,6 +537,9 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
     @Override
     public int deleteFsStoreProductById(Long productId)
     {
+        if (productId != null) {
+            fsStoreProductTagRelationScrmMapper.deleteByProductId(productId);
+        }
         int result = fsStoreProductMapper.deleteFsStoreProductById(productId);
         // 清除缓存
         clearProductDetailCache(productId);
@@ -784,6 +797,13 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
         } else {
             addProductAttr(product.getProductId(),param.getItems(),param.getValues());
         }
+        fsStoreProductTagRelationScrmMapper.deleteByProductId(product.getProductId());
+        if (param.getTagIds() != null && !param.getTagIds().isEmpty()) {
+            if (param.getTagIds().size() > 3) {
+                throw new ServiceException("商品标签最多选择3个");
+            }
+            fsStoreProductTagRelationScrmMapper.insertBatch(product.getProductId(), param.getTagIds());
+        }
         // 数据修改缓存
         if (product.getProductId() != null) {
             FsStoreProductScrm cacheProduct = fsStoreProductMapper.selectFsStoreProductById(product.getProductId());
@@ -1720,4 +1740,12 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
         }
         return R.ok();
     }
+
+    @Override
+    public List<Long> selectTagIdsByProductId(Long productId) {
+        if (productId == null) {
+            return Collections.emptyList();
+        }
+        return fsStoreProductTagRelationScrmMapper.selectTagIdsByProductId(productId);
+    }
 }

+ 81 - 0
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreProductTagScrmServiceImpl.java

@@ -0,0 +1,81 @@
+package com.fs.hisStore.service.impl;
+
+import com.fs.common.exception.ServiceException;
+import com.fs.common.utils.DateUtils;
+import com.fs.hisStore.domain.FsStoreProductTagScrm;
+import com.fs.hisStore.mapper.FsStoreProductTagRelationScrmMapper;
+import com.fs.hisStore.mapper.FsStoreProductTagScrmMapper;
+import com.fs.hisStore.service.IFsStoreProductTagScrmService;
+import com.fs.hisStore.vo.FsStoreProductTagListVO;
+import com.fs.hisStore.vo.FsStoreTagProductVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 商品标签 Service 实现
+ */
+@Service
+public class FsStoreProductTagScrmServiceImpl implements IFsStoreProductTagScrmService {
+
+    @Autowired
+    private FsStoreProductTagScrmMapper mapper;
+
+    @Autowired
+    private FsStoreProductTagRelationScrmMapper productTagRelationMapper;
+
+    @Override
+    public FsStoreProductTagScrm selectById(Long id) {
+        return mapper.selectById(id);
+    }
+
+    @Override
+    public List<FsStoreProductTagListVO> selectListVO(FsStoreProductTagScrm query) {
+        return mapper.selectListVO(query);
+    }
+
+    @Override
+    public List<FsStoreProductTagListVO> selectListVOPage(FsStoreProductTagScrm query) {
+        return mapper.selectListVO(query);
+    }
+
+    @Override
+    public List<FsStoreTagProductVO> selectProductsByTagId(Long tagId) {
+        return mapper.selectProductsByTagId(tagId);
+    }
+
+    @Override
+    public int insert(FsStoreProductTagScrm entity) {
+        if (entity.getTagName() != null && entity.getTagName().length() > 4) {
+            throw new ServiceException("标签名称最多4个字");
+        }
+        entity.setCreateTime(DateUtils.getNowDate());
+        entity.setUpdateTime(DateUtils.getNowDate());
+        return mapper.insert(entity);
+    }
+
+    @Override
+    public int update(FsStoreProductTagScrm entity) {
+        if (entity.getTagName() != null && entity.getTagName().length() > 4) {
+            throw new ServiceException("标签名称最多4个字");
+        }
+        entity.setUpdateTime(DateUtils.getNowDate());
+        return mapper.update(entity);
+    }
+
+    @Override
+    public int deleteById(Long id) {
+        productTagRelationMapper.deleteByTagIds(new Long[]{id});
+        return mapper.deleteById(id);
+    }
+
+    @Override
+    public int deleteByIds(Long[] ids) {
+        if (ids == null || ids.length == 0) {
+            return 0;
+        }
+        productTagRelationMapper.deleteByTagIds(ids);
+        return mapper.deleteByIds(ids);
+    }
+}

+ 23 - 0
fs-service/src/main/java/com/fs/hisStore/vo/FsStoreProductTagListVO.java

@@ -0,0 +1,23 @@
+package com.fs.hisStore.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 商品标签列表VO(含关联商品数量)
+ */
+@Data
+public class FsStoreProductTagListVO implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private Long id;
+    private Long storeId;
+    private String tagName;
+    private Integer status;
+    private Long sort;
+    private Date createTime;
+    private Integer productCount;
+}

+ 21 - 0
fs-service/src/main/java/com/fs/hisStore/vo/FsStoreTagProductVO.java

@@ -0,0 +1,21 @@
+package com.fs.hisStore.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * ±êÇ©¹ØÁªÉÌÆ·Ïî
+ */
+@Data
+public class FsStoreTagProductVO implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private Long productId;
+    private String productName;
+    private String image;
+    private BigDecimal price;
+    private Integer isShow;
+}

+ 65 - 0
fs-service/src/main/resources/mapper/hisStore/FsStoreProductTagScrmMapper.xml

@@ -0,0 +1,65 @@
+<?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.FsStoreProductTagScrmMapper">
+
+    <resultMap id="BaseResultMap" type="com.fs.hisStore.domain.FsStoreProductTagScrm">
+        <id property="id" column="id"/>
+        <result property="storeId" column="store_id"/>
+        <result property="tagName" column="tag_name"/>
+        <result property="status" column="status"/>
+        <result property="sort" column="sort"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateTime" column="update_time"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">id, store_id, tag_name, status, sort, create_time, update_time</sql>
+
+    <select id="selectById" resultMap="BaseResultMap">
+        select <include refid="Base_Column_List"/> from fs_store_product_tag_scrm where id = #{id}
+    </select>
+
+    <select id="selectListVO" resultType="com.fs.hisStore.vo.FsStoreProductTagListVO">
+        select t.id, t.store_id, t.tag_name, t.status, t.sort, t.create_time,
+               (select count(*) from fs_store_product_tag_relation_scrm r where r.tag_id = t.id) as product_count
+        from fs_store_product_tag_scrm t
+        <where>
+            <if test="storeId != null">and t.store_id = #{storeId}</if>
+            <if test="tagName != null and tagName != ''">and t.tag_name like concat('%', #{tagName}, '%')</if>
+            <if test="status != null">and t.status = #{status}</if>
+        </where>
+        order by t.sort asc, t.create_time desc
+    </select>
+
+    <insert id="insert" parameterType="com.fs.hisStore.domain.FsStoreProductTagScrm" useGeneratedKeys="true" keyProperty="id">
+        insert into fs_store_product_tag_scrm (store_id, tag_name, status, sort, create_time, update_time)
+        values (#{storeId}, #{tagName}, #{status}, #{sort}, #{createTime}, #{updateTime})
+    </insert>
+
+    <update id="update" parameterType="com.fs.hisStore.domain.FsStoreProductTagScrm">
+        update fs_store_product_tag_scrm
+        <set>
+            <if test="tagName != null">tag_name = #{tagName},</if>
+            <if test="status != null">status = #{status},</if>
+            <if test="sort != null">sort = #{sort},</if>
+            <if test="updateTime != null">update_time = #{updateTime},</if>
+        </set>
+        where id = #{id}
+    </update>
+
+    <delete id="deleteById">
+        delete from fs_store_product_tag_scrm where id = #{id}
+    </delete>
+
+    <delete id="deleteByIds">
+        delete from fs_store_product_tag_scrm where id in
+        <foreach collection="array" item="id" open="(" separator="," close=")">#{id}</foreach>
+    </delete>
+
+    <select id="selectProductsByTagId" resultType="com.fs.hisStore.vo.FsStoreTagProductVO">
+        select p.product_id as productId, p.product_name as productName, p.image as image, p.price as price, p.is_show as isShow
+        from fs_store_product_scrm p
+        inner join fs_store_product_tag_relation_scrm r on p.product_id = r.product_id
+        where r.tag_id = #{tagId} and (p.is_del is null or p.is_del = 0)
+        order by p.create_time desc
+    </select>
+</mapper>