From a962939db8e55a8d485f74a26bdada794bb44b89 Mon Sep 17 00:00:00 2001 From: chc <1501738723@qq.com> Date: Thu, 18 Jan 2024 11:44:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=93=E5=AD=98=E9=A2=84=E8=AD=A6=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DB/version4.3toMASTER.sql | 13 ++++- .../modules/goods/entity/dos/GoodsSku.java | 11 +++++ .../goods/entity/dto/GoodsSearchParams.java | 7 ++- .../goods/entity/dto/GoodsSkuStockDTO.java | 3 +- .../goods/service/GoodsSkuService.java | 12 +++++ .../serviceimpl/GoodsSkuServiceImpl.java | 30 ++++++++++++ .../modules/goods/sku/GoodsSkuBuilder.java | 3 +- .../service/GoodsStatisticsService.java | 3 ++ .../GoodsStatisticsServiceImpl.java | 11 +++++ .../IndexStatisticsServiceImpl.java | 2 +- .../goods/GoodsStoreController.java | 49 ++++++++++++++----- 11 files changed, 127 insertions(+), 17 deletions(-) diff --git a/DB/version4.3toMASTER.sql b/DB/version4.3toMASTER.sql index 60b4305b..8f25792e 100644 --- a/DB/version4.3toMASTER.sql +++ b/DB/version4.3toMASTER.sql @@ -63,7 +63,16 @@ CREATE TABLE `li_order_package_item` ( PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin ROW_FORMAT=DYNAMIC; - +/* + 订单货物增加发货数量 +*/ ALTER TABLE li_order_item ADD `deliver_number` int DEFAULT NULL COMMENT '发货数量'; -ALTER TABLE li_goods_sku ADD `alert_quantity` int DEFAULT NULL COMMENT '预警库存'; \ No newline at end of file +/* + sku增加预警库存 +*/ +ALTER TABLE li_goods_sku ADD `alert_quantity` int DEFAULT NULL COMMENT '预警库存'; +/* + 增加库存预警菜单 +*/ +INSERT INTO `lilishop`.`li_store_menu`(`id`, `create_by`, `create_time`, `delete_flag`, `update_by`, `update_time`, `description`, `front_route`, `icon`, `level`, `name`, `parent_id`, `path`, `sort_order`, `title`, `permission`) VALUES (1349237928434098177, NULL, '2022-01-11 22:35:45.000000', b'0', NULL, '2022-01-11 22:37:05', NULL, 'goods/goods-seller/alertQuantity', 'ios-american-football', 2, 'alert-goods-quantity', '1348810864748945408', 'alert-goods-quantity', '1.14', '库存预警', NULL); \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/goods/entity/dos/GoodsSku.java b/framework/src/main/java/cn/lili/modules/goods/entity/dos/GoodsSku.java index eef998a6..464e6d66 100644 --- a/framework/src/main/java/cn/lili/modules/goods/entity/dos/GoodsSku.java +++ b/framework/src/main/java/cn/lili/modules/goods/entity/dos/GoodsSku.java @@ -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(); diff --git a/framework/src/main/java/cn/lili/modules/goods/entity/dto/GoodsSearchParams.java b/framework/src/main/java/cn/lili/modules/goods/entity/dto/GoodsSearchParams.java index 2187c484..9e30d21d 100644 --- a/framework/src/main/java/cn/lili/modules/goods/entity/dto/GoodsSearchParams.java +++ b/framework/src/main/java/cn/lili/modules/goods/entity/dto/GoodsSearchParams.java @@ -90,6 +90,9 @@ public class GoodsSearchParams extends PageVO { @ApiModelProperty(value = "销售模式", required = true) private String salesModel; + @ApiModelProperty(value = "预警库存") + private Boolean alertQuantity; + public QueryWrapper queryWrapper() { QueryWrapper 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); diff --git a/framework/src/main/java/cn/lili/modules/goods/entity/dto/GoodsSkuStockDTO.java b/framework/src/main/java/cn/lili/modules/goods/entity/dto/GoodsSkuStockDTO.java index 97181f83..fd9b6b1c 100644 --- a/framework/src/main/java/cn/lili/modules/goods/entity/dto/GoodsSkuStockDTO.java +++ b/framework/src/main/java/cn/lili/modules/goods/entity/dto/GoodsSkuStockDTO.java @@ -21,5 +21,6 @@ public class GoodsSkuStockDTO { @ApiModelProperty(value = "库存") private Integer quantity; - + @ApiModelProperty(value = "预警库存") + private Integer alertQuantity; } diff --git a/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java b/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java index f31091ce..ed84429a 100644 --- a/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java +++ b/framework/src/main/java/cn/lili/modules/goods/service/GoodsSkuService.java @@ -188,6 +188,18 @@ public interface GoodsSkuService extends IService { */ void updateStocks(List goodsSkuStockDTOS); + /** + * 更新SKU预警库存 + * @param goodsSkuStockDTOS sku库存修改实体 + */ + void batchUpdateAlertQuantity(List goodsSkuStockDTOS); + + /** + * 更新SKU预警库存 + * @param goodsSkuStockDTO sku库存修改实体 + */ + void updateAlertQuantity(GoodsSkuStockDTO goodsSkuStockDTO); + /** * 更新SKU库存 * diff --git a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java index ee49c388..172f621f 100644 --- a/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/goods/serviceimpl/GoodsSkuServiceImpl.java @@ -536,6 +536,36 @@ public class GoodsSkuServiceImpl extends ServiceImpl 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 goodsSkuStockDTOS) { + List goodsSkuList = new ArrayList<>(); + List skuIds = goodsSkuStockDTOS.stream().map(GoodsSkuStockDTO::getSkuId).collect(Collectors.toList()); + List goodsSkuStockList = this.baseMapper.queryStocks(GoodsSearchParams.builder().ids(skuIds).build().queryWrapper()); + List goodsIdList = goodsSkuStockList.stream().map(GoodsSkuStockDTO::getGoodsId).collect(Collectors.toList()); + HashSet uniqueSet = new HashSet<>(goodsIdList); + // 将去重后的元素转回列表 + List 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) diff --git a/framework/src/main/java/cn/lili/modules/goods/sku/GoodsSkuBuilder.java b/framework/src/main/java/cn/lili/modules/goods/sku/GoodsSkuBuilder.java index f7fb9771..0df1a26a 100644 --- a/framework/src/main/java/cn/lili/modules/goods/sku/GoodsSkuBuilder.java +++ b/framework/src/main/java/cn/lili/modules/goods/sku/GoodsSkuBuilder.java @@ -64,7 +64,7 @@ public class GoodsSkuBuilder { Map specMap = new LinkedHashMap<>(); // 原始规格项 - String[] ignoreOriginKeys = {"id", "sn", "cost", "price", "quantity", "weight"}; + String[] ignoreOriginKeys = {"id", "sn", "cost", "price", "quantity", "weight", "alertQuantity"}; //获取规格信息 for (Map.Entry 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)); } diff --git a/framework/src/main/java/cn/lili/modules/statistics/service/GoodsStatisticsService.java b/framework/src/main/java/cn/lili/modules/statistics/service/GoodsStatisticsService.java index 7e2639f7..19f3b00f 100644 --- a/framework/src/main/java/cn/lili/modules/statistics/service/GoodsStatisticsService.java +++ b/framework/src/main/java/cn/lili/modules/statistics/service/GoodsStatisticsService.java @@ -27,4 +27,7 @@ public interface GoodsStatisticsService extends IService { * @return 今天的已上架的商品数量 */ long todayUpperNum(); + + long alertQuantityNum(); + } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/statistics/serviceimpl/GoodsStatisticsServiceImpl.java b/framework/src/main/java/cn/lili/modules/statistics/serviceimpl/GoodsStatisticsServiceImpl.java index 91242c63..b6afc59b 100644 --- a/framework/src/main/java/cn/lili/modules/statistics/serviceimpl/GoodsStatisticsServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/statistics/serviceimpl/GoodsStatisticsServiceImpl.java @@ -59,4 +59,15 @@ public class GoodsStatisticsServiceImpl extends ServiceImpl 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()); diff --git a/seller-api/src/main/java/cn/lili/controller/goods/GoodsStoreController.java b/seller-api/src/main/java/cn/lili/controller/goods/GoodsStoreController.java index 11d5b99a..4ed41f41 100644 --- a/seller-api/src/main/java/cn/lili/controller/goods/GoodsStoreController.java +++ b/seller-api/src/main/java/cn/lili/controller/goods/GoodsStoreController.java @@ -3,6 +3,7 @@ package cn.lili.controller.goods; import cn.lili.common.aop.annotation.DemoSite; import cn.lili.common.enums.ResultCode; import cn.lili.common.enums.ResultUtil; +import cn.lili.common.exception.RetryException; import cn.lili.common.exception.ServiceException; import cn.lili.common.security.OperationalJudgment; import cn.lili.common.security.context.UserContext; @@ -18,22 +19,26 @@ import cn.lili.modules.goods.entity.vos.GoodsVO; import cn.lili.modules.goods.entity.vos.StockWarningVO; import cn.lili.modules.goods.service.GoodsService; import cn.lili.modules.goods.service.GoodsSkuService; +import cn.lili.modules.search.service.EsGoodsIndexService; import cn.lili.modules.statistics.aop.PageViewPoint; import cn.lili.modules.statistics.aop.enums.PageViewEnum; import cn.lili.modules.store.entity.dos.StoreDetail; import cn.lili.modules.store.service.StoreDetailService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; -import io.swagger.annotations.ApiOperation; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import io.swagger.annotations.*; import lombok.extern.slf4j.Slf4j; +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.index.reindex.BulkByScrollResponse; +import org.elasticsearch.index.reindex.DeleteByQueryRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import javax.validation.constraints.NotNull; +import java.io.IOException; import java.util.List; import java.util.Map; import java.util.Objects; @@ -67,6 +72,9 @@ public class GoodsStoreController { @Autowired private StoreDetailService storeDetailService; + @Autowired + private EsGoodsIndexService esGoodsIndexService; + @ApiOperation(value = "分页获取商品列表") @GetMapping(value = "/list") public ResultMessage> getByPage(GoodsSearchParams goodsSearchParams) { @@ -87,17 +95,36 @@ public class GoodsStoreController { @ApiOperation(value = "分页获取库存告警商品列表") @GetMapping(value = "/list/stock") - public ResultMessage getWarningStockByPage(GoodsSearchParams goodsSearchParams) { + public ResultMessage> getWarningStockByPage(GoodsSearchParams goodsSearchParams) { //获取当前登录商家账号 String storeId = Objects.requireNonNull(UserContext.getCurrentUser()).getStoreId(); - StoreDetail storeDetail = OperationalJudgment.judgment(storeDetailService.getStoreDetail(storeId)); - Integer stockWarnNum = storeDetail.getStockWarning(); goodsSearchParams.setStoreId(storeId); - goodsSearchParams.setLeQuantity(stockWarnNum); + goodsSearchParams.setAlertQuantity(true); goodsSearchParams.setMarketEnable(GoodsStatusEnum.UPPER.name()); - IPage goodsSku = goodsSkuService.getGoodsSkuByPage(goodsSearchParams); - StockWarningVO stockWarning = new StockWarningVO(stockWarnNum, goodsSku); - return ResultUtil.data(stockWarning); + IPage goodsSkuPage = goodsSkuService.getGoodsSkuByPage(goodsSearchParams); + return ResultUtil.data(goodsSkuPage); + } + + @ApiOperation(value = "批量修改商品预警库存") + @PutMapping(value = "/batch/update/alert/stocks", consumes = "application/json") + public ResultMessage batchUpdateAlertQuantity(@RequestBody List updateStockList) { + String storeId = Objects.requireNonNull(UserContext.getCurrentUser()).getStoreId(); + // 获取商品skuId集合 + List goodsSkuIds = updateStockList.stream().map(GoodsSkuStockDTO::getSkuId).collect(Collectors.toList()); + // 根据skuId集合查询商品信息 + List goodsSkuList = goodsSkuService.list(new LambdaQueryWrapper().in(GoodsSku::getId, goodsSkuIds).eq(GoodsSku::getStoreId, storeId)); + // 过滤不符合当前店铺的商品 + List filterGoodsSkuIds = goodsSkuList.stream().map(GoodsSku::getId).collect(Collectors.toList()); + List collect = updateStockList.stream().filter(i -> filterGoodsSkuIds.contains(i.getSkuId())).collect(Collectors.toList()); + goodsSkuService.batchUpdateAlertQuantity(collect); + return ResultUtil.success(); + } + + @ApiOperation(value = "修改商品预警库存") + @PutMapping(value = "/update/alert/stocks", consumes = "application/json") + public ResultMessage updateAlertQuantity(@RequestBody GoodsSkuStockDTO goodsSkuStockDTO) { + goodsSkuService.updateAlertQuantity(goodsSkuStockDTO); + return ResultUtil.success(); }