xw преди 3 дни
родител
ревизия
634da1a93d

+ 55 - 0
fs-admin/src/main/java/com/fs/live/controller/LiveGoodsController.java

@@ -16,6 +16,8 @@ import com.fs.live.domain.LiveGoods;
 import com.fs.live.service.ILiveGoodsService;
 import com.fs.live.vo.LiveGoodsListVo;
 import com.fs.live.vo.LiveGoodsVo;
+import com.fs.system.domain.SysConfig;
+import com.fs.system.service.ISysConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
@@ -39,6 +41,9 @@ public class LiveGoodsController extends BaseController
     @Autowired
     private IFsStoreProductScrmService fsStoreProductService;
 
+    @Autowired
+    private ISysConfigService configService;
+
 
     /**
      * 查询直播商品列表
@@ -178,4 +183,54 @@ public class LiveGoodsController extends BaseController
     public R handleIsShowChange(@RequestBody LiveGoodsListVo listVo) {
         return liveGoodsService.handleIsShowChange(listVo);
     }
+
+    /**
+     * 查询直播低库存阈值
+     */
+    @GetMapping("/stockHintThreshold")
+    public AjaxResult getStockHintThreshold() {
+        final String configKey = "live.lowStockThreshold";
+        final int defaultThreshold = 10;
+        String configValue = configService.selectConfigByKey(configKey);
+        int threshold = defaultThreshold;
+        try {
+            if (configValue != null && !configValue.trim().isEmpty()) {
+                threshold = Integer.parseInt(configValue.trim());
+            }
+        } catch (NumberFormatException ignore) {
+            threshold = defaultThreshold;
+        }
+        AjaxResult result = AjaxResult.success();
+        result.put("configKey", configKey);
+        result.put("threshold", threshold);
+        return result;
+    }
+
+    /**
+     * 更新直播低库存阈值
+     */
+    @Log(title = "直播低库存阈值", businessType = BusinessType.UPDATE)
+    @PostMapping("/stockHintThreshold")
+    public AjaxResult updateStockHintThreshold(@RequestParam Integer threshold) {
+        final String configKey = "live.lowStockThreshold";
+        if (threshold == null || threshold < 1 || threshold > 9999) {
+            return AjaxResult.error("阈值范围需在1~9999");
+        }
+        SysConfig config = configService.selectConfigByConfigKey(configKey);
+        if (config == null) {
+            config = new SysConfig();
+            config.setConfigName("直播低库存阈值");
+            config.setConfigKey(configKey);
+            config.setConfigType("N");
+            config.setRemark("直播商品库存提示阈值,stock<=threshold时显示仅剩X件");
+            config.setCreateBy(SecurityUtils.getUsername());
+            config.setConfigValue(String.valueOf(threshold));
+            configService.insertConfig(config);
+        } else {
+            config.setConfigValue(String.valueOf(threshold));
+            config.setUpdateBy(SecurityUtils.getUsername());
+            configService.updateConfig(config);
+        }
+        return AjaxResult.success();
+    }
 }

+ 44 - 4
fs-service/src/main/java/com/fs/live/service/impl/LiveGoodsServiceImpl.java

@@ -19,11 +19,13 @@ import com.fs.live.service.ILiveAutoTaskService;
 import com.fs.live.service.ILiveGoodsService;
 import com.fs.live.vo.LiveGoodsListVo;
 import com.fs.live.vo.LiveGoodsVo;
+import com.fs.system.service.ISysConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -46,6 +48,8 @@ public class LiveGoodsServiceImpl extends ServiceImpl<LiveGoodsMapper, LiveGoods
     private LiveGoodsMapper baseMapper;
     @Autowired
     private ILiveAutoTaskService liveAutoTaskService;
+    @Autowired
+    private ISysConfigService configService;
 
     /**
      * 查询直播商品
@@ -155,6 +159,7 @@ public class LiveGoodsServiceImpl extends ServiceImpl<LiveGoodsMapper, LiveGoods
         liveGoods.setLiveId(liveId);
         liveGoods.setKeywords(key);
         List<LiveGoodsVo> liveGoodsVos = baseMapper.selectProductListByLiveId(liveGoods);
+        applyStockThreshold(liveGoodsVos);
         if (liveGoodsVos.isEmpty()) {
             return R.ok();
         }
@@ -165,17 +170,23 @@ public class LiveGoodsServiceImpl extends ServiceImpl<LiveGoodsMapper, LiveGoods
 
     @Override
     public List<LiveGoodsVo> selectProductListByLiveId(LiveGoods liveGoods) {
-        return baseMapper.selectProductListByLiveIdAll(liveGoods);
+        List<LiveGoodsVo> list = baseMapper.selectProductListByLiveIdAll(liveGoods);
+        applyStockThreshold(list);
+        return list;
     }
 
     @Override
     public LiveGoodsVo selectLiveGoodsVoByGoodsId(Long goodsId) {
-        return baseMapper.selectLiveGoodsVoByGoodsId(goodsId);
+        LiveGoodsVo liveGoodsVo = baseMapper.selectLiveGoodsVoByGoodsId(goodsId);
+        applyStockThreshold(Collections.singletonList(liveGoodsVo));
+        return liveGoodsVo;
     }
 
     @Override
     public LiveGoodsVo showGoods(Long liveId) {
-        return baseMapper.showGoods(liveId);
+        LiveGoodsVo liveGoodsVo = baseMapper.showGoods(liveId);
+        applyStockThreshold(Collections.singletonList(liveGoodsVo));
+        return liveGoodsVo;
     }
 
     @Override
@@ -200,6 +211,7 @@ public class LiveGoodsServiceImpl extends ServiceImpl<LiveGoodsMapper, LiveGoods
         liveGoods.setKeywords(key);
         liveGoods.setCompanyUserId(Long.parseLong(userId));
         List<LiveGoodsVo> liveGoodsVos = baseMapper.selectProductListByLiveId(liveGoods);
+        applyStockThreshold(liveGoodsVos);
         if (liveGoodsVos.isEmpty()) {
             return R.ok();
         }
@@ -424,7 +436,9 @@ public class LiveGoodsServiceImpl extends ServiceImpl<LiveGoodsMapper, LiveGoods
      */
     @Override
     public List<LiveGoodsVo> selectLiveGoodsListByMap(Map<String, Object> params) {
-        return baseMapper.selectLiveGoodsListByStoreId(params);
+        List<LiveGoodsVo> list = baseMapper.selectLiveGoodsListByStoreId(params);
+        applyStockThreshold(list);
+        return list;
     }
 
     @Override
@@ -472,4 +486,30 @@ public class LiveGoodsServiceImpl extends ServiceImpl<LiveGoodsMapper, LiveGoods
         baseMapper.handleIsShowChange(listVo);
         return R.ok().put("isShow", listVo.getIsShow());
     }
+
+    private void applyStockThreshold(List<LiveGoodsVo> liveGoodsVos) {
+        if (liveGoodsVos == null || liveGoodsVos.isEmpty()) {
+            return;
+        }
+        int lowStockThreshold = getLowStockThreshold();
+        for (LiveGoodsVo liveGoodsVo : liveGoodsVos) {
+            if (liveGoodsVo == null) {
+                continue;
+            }
+            liveGoodsVo.setShowStockHint(lowStockThreshold);
+        }
+    }
+
+    private int getLowStockThreshold() {
+        String threshold = configService.selectConfigByKey("live.lowStockThreshold");
+        if (threshold == null || threshold.trim().isEmpty()) {
+            return 0;
+        }
+        try {
+            int value = Integer.parseInt(threshold.trim());
+            return Math.max(1, value);
+        } catch (NumberFormatException ignore) {
+            return 0;
+        }
+    }
 }

+ 5 - 0
fs-service/src/main/java/com/fs/live/vo/LiveGoodsVo.java

@@ -28,4 +28,9 @@ public class LiveGoodsVo {
      * 仓库代码
      */
     private String warehouseCode;
+
+    /**
+     * 低库存提示阈值
+     */
+    private Integer showStockHint;
 }

+ 1 - 1
fs-service/src/main/resources/mapper/live/LiveGoodsMapper.xml

@@ -170,7 +170,7 @@
 
     <select id="selectProductListByLiveId" parameterType="LiveGoods" resultType="com.fs.live.vo.LiveGoodsVo">
 
-        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
+        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
         <if test="companyUserId != null "> ,if(uf.favorite_id is not null, true, false) is_favorite </if>
 
         from live_goods lg