库存预警功能
This commit is contained in:
@@ -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<IPage<Goods>> getByPage(GoodsSearchParams goodsSearchParams) {
|
||||
@@ -87,17 +95,36 @@ public class GoodsStoreController {
|
||||
|
||||
@ApiOperation(value = "分页获取库存告警商品列表")
|
||||
@GetMapping(value = "/list/stock")
|
||||
public ResultMessage<StockWarningVO> getWarningStockByPage(GoodsSearchParams goodsSearchParams) {
|
||||
public ResultMessage<IPage<GoodsSku>> 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> goodsSku = goodsSkuService.getGoodsSkuByPage(goodsSearchParams);
|
||||
StockWarningVO stockWarning = new StockWarningVO(stockWarnNum, goodsSku);
|
||||
return ResultUtil.data(stockWarning);
|
||||
IPage<GoodsSku> goodsSkuPage = goodsSkuService.getGoodsSkuByPage(goodsSearchParams);
|
||||
return ResultUtil.data(goodsSkuPage);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "批量修改商品预警库存")
|
||||
@PutMapping(value = "/batch/update/alert/stocks", consumes = "application/json")
|
||||
public ResultMessage<Object> batchUpdateAlertQuantity(@RequestBody List<GoodsSkuStockDTO> updateStockList) {
|
||||
String storeId = Objects.requireNonNull(UserContext.getCurrentUser()).getStoreId();
|
||||
// 获取商品skuId集合
|
||||
List<String> goodsSkuIds = updateStockList.stream().map(GoodsSkuStockDTO::getSkuId).collect(Collectors.toList());
|
||||
// 根据skuId集合查询商品信息
|
||||
List<GoodsSku> goodsSkuList = goodsSkuService.list(new LambdaQueryWrapper<GoodsSku>().in(GoodsSku::getId, goodsSkuIds).eq(GoodsSku::getStoreId, storeId));
|
||||
// 过滤不符合当前店铺的商品
|
||||
List<String> filterGoodsSkuIds = goodsSkuList.stream().map(GoodsSku::getId).collect(Collectors.toList());
|
||||
List<GoodsSkuStockDTO> 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<Object> updateAlertQuantity(@RequestBody GoodsSkuStockDTO goodsSkuStockDTO) {
|
||||
goodsSkuService.updateAlertQuantity(goodsSkuStockDTO);
|
||||
return ResultUtil.success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user