|
|
@@ -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;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|