库存预警功能
This commit is contained in:
@@ -164,6 +164,9 @@ public class GoodsSku extends BaseEntity {
|
||||
@ApiModelProperty(value = "商品类型", required = true)
|
||||
private String goodsType;
|
||||
|
||||
@ApiModelProperty(value = "预警数量")
|
||||
private Integer alertQuantity;
|
||||
|
||||
public Double getWeight() {
|
||||
if (weight == null) {
|
||||
return 0d;
|
||||
@@ -171,6 +174,13 @@ public class GoodsSku extends BaseEntity {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public Integer getalertQuantity() {
|
||||
if(alertQuantity == null){
|
||||
return 0;
|
||||
}
|
||||
return alertQuantity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getCreateTime() {
|
||||
if (super.getCreateTime() == null) {
|
||||
@@ -200,6 +210,7 @@ public class GoodsSku extends BaseEntity {
|
||||
this.mobileIntro = goods.getMobileIntro();
|
||||
this.goodsUnit = goods.getGoodsUnit();
|
||||
this.grade = 100D;
|
||||
this.alertQuantity = 0;
|
||||
//商品状态
|
||||
this.authFlag = goods.getAuthFlag();
|
||||
this.salesModel = goods.getSalesModel();
|
||||
|
||||
@@ -90,6 +90,9 @@ public class GoodsSearchParams extends PageVO {
|
||||
@ApiModelProperty(value = "销售模式", required = true)
|
||||
private String salesModel;
|
||||
|
||||
@ApiModelProperty(value = "预警库存")
|
||||
private Boolean alertQuantity;
|
||||
|
||||
public <T> QueryWrapper<T> queryWrapper() {
|
||||
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
|
||||
if (CharSequenceUtil.isNotEmpty(goodsId)) {
|
||||
@@ -140,7 +143,9 @@ public class GoodsSearchParams extends PageVO {
|
||||
if (CharSequenceUtil.isNotEmpty(salesModel)) {
|
||||
queryWrapper.eq("sales_model", salesModel);
|
||||
}
|
||||
|
||||
if(alertQuantity != null && alertQuantity){
|
||||
queryWrapper.apply("quantity <= alert_quantity");
|
||||
}
|
||||
queryWrapper.in(CollUtil.isNotEmpty(ids), "id", ids);
|
||||
|
||||
queryWrapper.eq("delete_flag", false);
|
||||
|
||||
@@ -21,5 +21,6 @@ public class GoodsSkuStockDTO {
|
||||
@ApiModelProperty(value = "库存")
|
||||
private Integer quantity;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "预警库存")
|
||||
private Integer alertQuantity;
|
||||
}
|
||||
|
||||
@@ -188,6 +188,18 @@ public interface GoodsSkuService extends IService<GoodsSku> {
|
||||
*/
|
||||
void updateStocks(List<GoodsSkuStockDTO> goodsSkuStockDTOS);
|
||||
|
||||
/**
|
||||
* 更新SKU预警库存
|
||||
* @param goodsSkuStockDTOS sku库存修改实体
|
||||
*/
|
||||
void batchUpdateAlertQuantity(List<GoodsSkuStockDTO> goodsSkuStockDTOS);
|
||||
|
||||
/**
|
||||
* 更新SKU预警库存
|
||||
* @param goodsSkuStockDTO sku库存修改实体
|
||||
*/
|
||||
void updateAlertQuantity(GoodsSkuStockDTO goodsSkuStockDTO);
|
||||
|
||||
/**
|
||||
* 更新SKU库存
|
||||
*
|
||||
|
||||
@@ -536,6 +536,36 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAlertQuantity(GoodsSkuStockDTO goodsSkuStockDTO) {
|
||||
GoodsSku goodsSku = this.getById(goodsSkuStockDTO.getSkuId());
|
||||
goodsSku.setAlertQuantity(goodsSkuStockDTO.getAlertQuantity());
|
||||
//清除缓存,防止修改预警后直接修改商品导致预警数值错误
|
||||
cache.remove(CachePrefix.GOODS.getPrefix() + goodsSku.getGoodsId());
|
||||
this.update(goodsSku);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchUpdateAlertQuantity(List<GoodsSkuStockDTO> goodsSkuStockDTOS) {
|
||||
List<GoodsSku> goodsSkuList = new ArrayList<>();
|
||||
List<String> skuIds = goodsSkuStockDTOS.stream().map(GoodsSkuStockDTO::getSkuId).collect(Collectors.toList());
|
||||
List<GoodsSkuStockDTO> goodsSkuStockList = this.baseMapper.queryStocks(GoodsSearchParams.builder().ids(skuIds).build().queryWrapper());
|
||||
List<String> goodsIdList = goodsSkuStockList.stream().map(GoodsSkuStockDTO::getGoodsId).collect(Collectors.toList());
|
||||
HashSet<String> uniqueSet = new HashSet<>(goodsIdList);
|
||||
// 将去重后的元素转回列表
|
||||
List<String> uniqueGoodsIdList = new ArrayList<>(uniqueSet);
|
||||
for (String goodsId : uniqueGoodsIdList) {
|
||||
cache.remove(CachePrefix.GOODS.getPrefix() + goodsId);
|
||||
}
|
||||
//修改预警库存
|
||||
for (GoodsSkuStockDTO goodsSkuStockDTO : goodsSkuStockDTOS) {
|
||||
GoodsSku goodsSku = this.getById(goodsSkuStockDTO.getSkuId());
|
||||
goodsSku.setAlertQuantity(goodsSkuStockDTO.getAlertQuantity());
|
||||
goodsSkuList.add(goodsSku);
|
||||
}
|
||||
this.updateBatchById(goodsSkuList);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
|
||||
@@ -64,7 +64,7 @@ public class GoodsSkuBuilder {
|
||||
Map<String, Object> specMap = new LinkedHashMap<>();
|
||||
|
||||
// 原始规格项
|
||||
String[] ignoreOriginKeys = {"id", "sn", "cost", "price", "quantity", "weight"};
|
||||
String[] ignoreOriginKeys = {"id", "sn", "cost", "price", "quantity", "weight", "alertQuantity"};
|
||||
//获取规格信息
|
||||
for (Map.Entry<String, Object> spec : skuInfo.entrySet()) {
|
||||
//保存新增规格信息
|
||||
@@ -91,6 +91,7 @@ public class GoodsSkuBuilder {
|
||||
goodsSku.setQuantity(Convert.toInt(skuInfo.get("quantity"), 0));
|
||||
goodsSku.setSpecs(JSONUtil.toJsonStr(specMap));
|
||||
goodsSku.setSimpleSpecs(simpleSpecs.toString());
|
||||
goodsSku.setAlertQuantity(Convert.toInt(skuInfo.get("alertQuantity"), 0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,4 +27,7 @@ public interface GoodsStatisticsService extends IService<Goods> {
|
||||
* @return 今天的已上架的商品数量
|
||||
*/
|
||||
long todayUpperNum();
|
||||
|
||||
long alertQuantityNum();
|
||||
|
||||
}
|
||||
@@ -59,4 +59,15 @@ public class GoodsStatisticsServiceImpl extends ServiceImpl<GoodsStatisticsMappe
|
||||
queryWrapper.ge(Goods::getCreateTime, DateUtil.beginOfDay(new DateTime()));
|
||||
return this.count(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long alertQuantityNum() {
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
|
||||
queryWrapper.eq(CharSequenceUtil.equals(currentUser.getRole().name(), UserEnums.STORE.name()),
|
||||
"store_id", currentUser.getStoreId());
|
||||
queryWrapper.eq("market_enable",GoodsStatusEnum.UPPER.name());
|
||||
queryWrapper.apply("quantity < alert_quantity");
|
||||
return goodsSkuService.count(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ public class IndexStatisticsServiceImpl implements IndexStatisticsService {
|
||||
Map<String, Object> map = storeFlowStatisticsService.getOrderStatisticsPrice();
|
||||
storeIndexStatisticsVO.setOrderNum(Convert.toInt(map.get("num").toString()));
|
||||
storeIndexStatisticsVO.setOrderPrice(map.get("price") != null ? Double.parseDouble(map.get("price").toString()) : 0.0);
|
||||
|
||||
storeIndexStatisticsVO.setAlertQuantityNum(goodsStatisticsService.alertQuantityNum());
|
||||
//访问量
|
||||
StatisticsQueryParam queryParam = new StatisticsQueryParam();
|
||||
queryParam.setSearchType(SearchTypeEnum.TODAY.name());
|
||||
|
||||
Reference in New Issue
Block a user