tb_product
删除 库存警戒线 库存开关 库存数量 新增 是否自动售罄 标识 tb_shop_prod_category 新增 refund_mode 退菜是否退库存 tb_shop_config 新增 refund_mode 退菜退库存模式 删除 扣除库存模式
This commit is contained in:
@@ -12,7 +12,6 @@ import com.mybatisflex.core.query.QueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -38,8 +37,6 @@ public interface ProductMapper extends BaseMapper<Product> {
|
||||
|
||||
List<RecommendProVO> selectCouponProBySaleNum();
|
||||
|
||||
void updateProductStockNum(@Param("id") Long id, @Param("shopId") Long shopId, @Param("type") String type, @Param("num") BigDecimal num);
|
||||
|
||||
List<RecommendProVO> selectRecommendProductList(@Param("lng") String lng, @Param("lat") String lat, @Param("address") String address,
|
||||
@Param("classify") Integer classify, @Param("orderType") Integer orderType,
|
||||
@Param("distanceType") Integer distanceType, @Param("name") String name);
|
||||
|
||||
@@ -5,12 +5,14 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.config.RabbitPublisher;
|
||||
import com.czg.constants.SystemConstants;
|
||||
import com.czg.product.dto.ProductStockSubtractDTO;
|
||||
import com.czg.product.entity.*;
|
||||
import com.czg.product.entity.ConsInfo;
|
||||
import com.czg.product.entity.ConsStockFlow;
|
||||
import com.czg.product.entity.ProdConsRelation;
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.enums.InOutItemEnum;
|
||||
import com.czg.product.enums.InOutTypeEnum;
|
||||
import com.czg.product.service.ConsStockFlowService;
|
||||
@@ -71,37 +73,13 @@ public class ProductRpcServiceImpl implements ProductRpcService {
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
//TODO 优化耗材库存更新逻辑 耗材预警
|
||||
boolean isLowWarnLine = false;
|
||||
for (ProductStockSubtractDTO dto : list) {
|
||||
Product product = productMapper.selectOneById(dto.getProductId());
|
||||
if (product == null) {
|
||||
continue;
|
||||
}
|
||||
// 商品开启库存
|
||||
if (product.getIsStock() == SystemConstants.OneZero.ONE) {
|
||||
productMapper.updateProductStockNum(dto.getProductId(), dto.getShopId(), "sub", dto.getNum());
|
||||
// 记录商品库存流水
|
||||
ProductStockFlow flow = new ProductStockFlow();
|
||||
flow.setCreateUserId(1L);
|
||||
flow.setCreateUserName("银收客");
|
||||
flow.setShopId(shopId);
|
||||
flow.setProductId(product.getId());
|
||||
flow.setProductName(product.getName());
|
||||
flow.setBeforeNumber(NumberUtil.toBigDecimal(product.getStockNumber()));
|
||||
flow.setInOutNumber(NumberUtil.sub(BigDecimal.ZERO, NumberUtil.toBigDecimal(dto.getNum())));
|
||||
flow.setAfterNumber(NumberUtil.sub(NumberUtil.toBigDecimal(product.getStockNumber()), NumberUtil.toBigDecimal(dto.getNum())));
|
||||
flow.setInOutType(InOutTypeEnum.OUT.value());
|
||||
flow.setInOutItem(InOutItemEnum.ORDER_OUT.value());
|
||||
flow.setOrderId(orderId);
|
||||
productStockFlowService.saveFlow(flow);
|
||||
cleanCategoryProduct(shopId, product.getCategoryId());
|
||||
refreshRedisProdStock(shopId, product.getId(), flow.getAfterNumber());
|
||||
Integer warnLine = ObjUtil.defaultIfNull(product.getWarnLine(), 10);
|
||||
if (!isLowWarnLine && NumberUtil.isLess(flow.getAfterNumber(), Convert.toBigDecimal(warnLine))) {
|
||||
isLowWarnLine = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 查询商品绑定耗材信息
|
||||
List<ProdConsRelation> relationList = prodConsRelationMapper.selectListByQuery(QueryWrapper.create().eq(ProdConsRelation::getProductId, dto.getProductId()));
|
||||
if (CollUtil.isEmpty(relationList)) {
|
||||
@@ -161,28 +139,6 @@ public class ProductRpcServiceImpl implements ProductRpcService {
|
||||
}
|
||||
boolean isLowWarnLine = false;
|
||||
for (ProductStockSubtractDTO dto : list) {
|
||||
Product product = productMapper.selectOneById(dto.getProductId());
|
||||
productMapper.updateProductStockNum(dto.getProductId(), dto.getShopId(), "add", dto.getNum());
|
||||
// 记录商品库存流水
|
||||
ProductStockFlow flow = new ProductStockFlow();
|
||||
flow.setCreateUserId(1L);
|
||||
flow.setCreateUserName("银收客");
|
||||
flow.setShopId(shopId);
|
||||
flow.setProductId(product.getId());
|
||||
flow.setProductName(product.getName());
|
||||
flow.setBeforeNumber(NumberUtil.toBigDecimal(product.getStockNumber()));
|
||||
flow.setInOutNumber(NumberUtil.toBigDecimal(dto.getNum()));
|
||||
flow.setAfterNumber(NumberUtil.add(NumberUtil.toBigDecimal(product.getStockNumber()), NumberUtil.toBigDecimal(dto.getNum())));
|
||||
flow.setInOutType(InOutTypeEnum.OUT.value());
|
||||
flow.setInOutItem(InOutItemEnum.ORDER_OUT.value());
|
||||
flow.setRemark("红冲订单取消/退菜/退单消耗的库存");
|
||||
flow.setOrderId(orderId);
|
||||
productStockFlowService.saveFlow(flow);
|
||||
refreshRedisProdStock(shopId, product.getId(), flow.getAfterNumber());
|
||||
Integer warnLine = ObjUtil.defaultIfNull(product.getWarnLine(), 10);
|
||||
if (!isLowWarnLine && (NumberUtil.isLessOrEqual(flow.getBeforeNumber(), BigDecimal.ZERO) || NumberUtil.isLess(flow.getAfterNumber(), Convert.toBigDecimal(warnLine)))) {
|
||||
isLowWarnLine = true;
|
||||
}
|
||||
// 查询商品绑定耗材信息
|
||||
List<ProdConsRelation> relationList = prodConsRelationMapper.selectListByQuery(QueryWrapper.create().eq(ProdConsRelation::getProductId, dto.getProductId()));
|
||||
if (CollUtil.isEmpty(relationList)) {
|
||||
@@ -220,7 +176,6 @@ public class ProductRpcServiceImpl implements ProductRpcService {
|
||||
consStockFlow.setAfterNumber(consInfo.getStockNumber());
|
||||
consStockFlow.setSubTotal(NumberUtil.mul(surplusStock, consInfo.getPrice()));
|
||||
consStockFlow.setProductId(dto.getProductId());
|
||||
//consStockFlow.setSkuId(0L);
|
||||
consStockFlow.setRemark("红冲订单取消/退菜/退单消耗的库存");
|
||||
consStockFlow.setOrderId(orderId);
|
||||
consStockFlowService.saveFlow(consStockFlow);
|
||||
@@ -241,32 +196,6 @@ public class ProductRpcServiceImpl implements ProductRpcService {
|
||||
}
|
||||
boolean isLowWarnLine = false;
|
||||
for (ProductStockSubtractDTO dto : list) {
|
||||
Product product = productMapper.selectOneById(dto.getProductId());
|
||||
// 商品是否允许退款退货时归还库存
|
||||
if (SystemConstants.OneZero.ONE == product.getIsRefundStock() && SystemConstants.OneZero.ONE == product.getIsStock()) {
|
||||
productMapper.updateProductStockNum(dto.getProductId(), dto.getShopId(), "add", dto.getNum());
|
||||
// 记录商品库存流水
|
||||
ProductStockFlow flow = new ProductStockFlow();
|
||||
flow.setCreateUserId(1L);
|
||||
flow.setCreateUserName("银收客");
|
||||
flow.setShopId(shopId);
|
||||
flow.setProductId(product.getId());
|
||||
flow.setProductName(product.getName());
|
||||
flow.setBeforeNumber(NumberUtil.toBigDecimal(product.getStockNumber()));
|
||||
flow.setInOutNumber(NumberUtil.toBigDecimal(dto.getNum()));
|
||||
flow.setAfterNumber(NumberUtil.add(NumberUtil.toBigDecimal(product.getStockNumber()), NumberUtil.toBigDecimal(dto.getNum())));
|
||||
flow.setInOutType(InOutTypeEnum.OUT.value());
|
||||
flow.setInOutItem(InOutItemEnum.ORDER_OUT.value());
|
||||
flow.setRemark("红冲订单取消/退菜/退单消耗的库存");
|
||||
flow.setOrderId(orderId);
|
||||
productStockFlowService.saveFlow(flow);
|
||||
// String key = StrUtil.format(SHOP_PRODUCT_STOCK, shopId, product.getId());
|
||||
refreshRedisProdStock(shopId, product.getId(), flow.getAfterNumber());
|
||||
Integer warnLine = ObjUtil.defaultIfNull(product.getWarnLine(), 10);
|
||||
if (!isLowWarnLine && (NumberUtil.isLessOrEqual(flow.getBeforeNumber(), BigDecimal.ZERO) || NumberUtil.isLess(flow.getAfterNumber(), Convert.toBigDecimal(warnLine)))) {
|
||||
isLowWarnLine = true;
|
||||
}
|
||||
}
|
||||
// 查询商品绑定耗材信息
|
||||
List<ProdConsRelation> relationList = prodConsRelationMapper.selectListByQuery(QueryWrapper.create().eq(ProdConsRelation::getProductId, dto.getProductId()));
|
||||
if (CollUtil.isEmpty(relationList)) {
|
||||
@@ -304,7 +233,6 @@ public class ProductRpcServiceImpl implements ProductRpcService {
|
||||
consStockFlow.setAfterNumber(consInfo.getStockNumber());
|
||||
consStockFlow.setSubTotal(NumberUtil.mul(surplusStock, consInfo.getPrice()));
|
||||
consStockFlow.setProductId(dto.getProductId());
|
||||
// consStockFlow.setSkuId(0L);
|
||||
consStockFlow.setOrderId(orderId);
|
||||
consStockFlow.setRemark("红冲订单取消/退菜/退单消耗的库存");
|
||||
consStockFlowService.saveFlow(consStockFlow);
|
||||
|
||||
@@ -25,8 +25,6 @@ import com.czg.sa.StpKit;
|
||||
import com.czg.service.RedisService;
|
||||
import com.czg.service.product.mapper.*;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.row.DbChain;
|
||||
@@ -271,7 +269,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
.setMemberPrice(getMainSkuMemberPrice(exportDTO))
|
||||
.setType(exportDTO.getType())
|
||||
.setGroupType(exportDTO.getGroupType())
|
||||
.setStockNumber(exportDTO.getStockNumber())
|
||||
.setIsSale(getMainSkuIsSale(exportDTO))
|
||||
.setGroupTitleName(proGroupDTO.getTitle())
|
||||
.setGroupProductNumber(Optional.ofNullable(proGroupDTO.getNumber()).map(String::valueOf).orElse(""))
|
||||
@@ -510,24 +507,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
}
|
||||
prodSkuMapper.insertBatch(prodSkuList);
|
||||
}
|
||||
if (entity.getIsStock() == SystemConstants.OneZero.ZERO) {
|
||||
return;
|
||||
}
|
||||
// 记录商品库存流水
|
||||
ProductStockFlow flow = new ProductStockFlow();
|
||||
Long createUserId = StpKit.USER.getLoginIdAsLong();
|
||||
String createUserName = StpKit.USER.getAccount();
|
||||
flow.setCreateUserId(createUserId);
|
||||
flow.setCreateUserName(createUserName);
|
||||
flow.setShopId(shopId);
|
||||
flow.setProductId(entity.getId());
|
||||
flow.setProductName(entity.getName());
|
||||
flow.setBeforeNumber(BigDecimal.ZERO);
|
||||
flow.setInOutNumber(NumberUtil.toBigDecimal(entity.getStockNumber()));
|
||||
flow.setAfterNumber(NumberUtil.toBigDecimal(entity.getStockNumber()));
|
||||
flow.setInOutType(InOutTypeEnum.IN.value());
|
||||
flow.setInOutItem(InOutItemEnum.WIN_IN.value());
|
||||
productStockFlowService.saveFlow(flow);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -561,19 +540,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
}
|
||||
entity.setRelatedRecommend(dto.getRelatedRecommendStr());
|
||||
super.updateById(entity);
|
||||
// 清除商品分类列表缓存
|
||||
clearProductCache(old.getCategoryId());
|
||||
if (!old.getCategoryId().equals(dto.getCategoryId())) {
|
||||
clearProductCache(entity.getCategoryId());
|
||||
}
|
||||
if (ObjUtil.defaultIfNull(dto.getIsStock(), old.getIsStock()) == SystemConstants.OneZero.ZERO) {
|
||||
redisService.del(StrUtil.format(CacheConstant.SHOP_PRODUCT_STOCK, shopId, dto.getId()));
|
||||
Boolean b = redisService.hasKey(StrUtil.format(CacheConstant.SHOP_PRODUCT_STOCK, shopId, dto.getId()));
|
||||
log.info("删除商品库存缓存:{}-{}", dto.getId(), b);
|
||||
} else {
|
||||
redisService.set(StrUtil.format(CacheConstant.SHOP_PRODUCT_STOCK, shopId, dto.getId()), dto.getStockNumber());
|
||||
log.info("设置商品库存缓存:{}-{}", dto.getId(), dto.getStockNumber());
|
||||
}
|
||||
|
||||
List<ProdSkuDTO> skuList = dto.getSkuList();
|
||||
// 商品SKU-ID列表
|
||||
List<Long> skuIdList = prodSkuMapper.selectListByQueryAs(query().select(ProdSku::getId).eq(ProdSku::getProductId, dto.getId()), Long.class);
|
||||
@@ -605,85 +572,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
.eq(ProdSku::getShopId, shopId)
|
||||
.update();
|
||||
}
|
||||
if (entity.getIsStock() == SystemConstants.OneZero.ZERO) {
|
||||
return;
|
||||
}
|
||||
// 记录商品库存流水
|
||||
ProductStockFlow flow = new ProductStockFlow();
|
||||
Long createUserId = StpKit.USER.getLoginIdAsLong();
|
||||
String createUserName = StpKit.USER.getAccount();
|
||||
flow.setCreateUserId(createUserId);
|
||||
flow.setCreateUserName(createUserName);
|
||||
flow.setShopId(shopId);
|
||||
flow.setProductId(old.getId());
|
||||
flow.setProductName(old.getName());
|
||||
flow.setBeforeNumber(NumberUtil.toBigDecimal(old.getStockNumber()));
|
||||
BigDecimal inOutNumber = NumberUtil.sub(NumberUtil.toBigDecimal(entity.getStockNumber()), flow.getBeforeNumber());
|
||||
// 盘亏
|
||||
if (NumberUtil.isLess(inOutNumber, BigDecimal.ZERO)) {
|
||||
flow.setInOutNumber(inOutNumber);
|
||||
flow.setInOutType(InOutTypeEnum.OUT.value());
|
||||
flow.setInOutItem(InOutItemEnum.LOSS_OUT.value());
|
||||
}
|
||||
// 盘盈
|
||||
if (NumberUtil.isGreater(inOutNumber, BigDecimal.ZERO)) {
|
||||
flow.setInOutNumber(inOutNumber);
|
||||
flow.setInOutType(InOutTypeEnum.IN.value());
|
||||
flow.setInOutItem(InOutItemEnum.WIN_IN.value());
|
||||
}
|
||||
// 盘平
|
||||
if (NumberUtil.equals(inOutNumber, BigDecimal.ZERO)) {
|
||||
return;
|
||||
}
|
||||
flow.setAfterNumber(NumberUtil.toBigDecimal(entity.getStockNumber()));
|
||||
productStockFlowService.saveFlow(flow);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateProductStock(ProductModifyStockParam param) {
|
||||
Product entity = super.getById(param.getId());
|
||||
if (entity.getIsStock() == SystemConstants.OneZero.ZERO) {
|
||||
throw new CzgException("该商品未开启库存管理,暂不支持修改库存");
|
||||
}
|
||||
if (!entity.getShopId().equals(param.getShopId())) {
|
||||
return;
|
||||
}
|
||||
UpdateChain.of(Product.class)
|
||||
.set(Product::getStockNumber, param.getStockNumber())
|
||||
.set(Product::getShopId, param.getShopId())
|
||||
.eq(Product::getId, param.getId())
|
||||
.update();
|
||||
// 记录商品库存流水
|
||||
ProductStockFlow flow = new ProductStockFlow();
|
||||
Long createUserId = StpKit.USER.getLoginIdAsLong();
|
||||
String createUserName = StpKit.USER.getAccount();
|
||||
flow.setCreateUserId(createUserId);
|
||||
flow.setCreateUserName(createUserName);
|
||||
flow.setShopId(param.getShopId());
|
||||
flow.setProductId(entity.getId());
|
||||
flow.setProductName(entity.getName());
|
||||
flow.setBeforeNumber(NumberUtil.toBigDecimal(entity.getStockNumber()));
|
||||
BigDecimal inOutNumber = NumberUtil.sub(NumberUtil.toBigDecimal(param.getStockNumber()), flow.getBeforeNumber());
|
||||
// 盘亏
|
||||
if (NumberUtil.isLess(inOutNumber, BigDecimal.ZERO)) {
|
||||
flow.setInOutNumber(inOutNumber);
|
||||
flow.setInOutType(InOutTypeEnum.OUT.value());
|
||||
flow.setInOutItem(InOutItemEnum.LOSS_OUT.value());
|
||||
}
|
||||
// 盘盈
|
||||
if (NumberUtil.isGreater(inOutNumber, BigDecimal.ZERO)) {
|
||||
flow.setInOutNumber(inOutNumber);
|
||||
flow.setInOutType(InOutTypeEnum.IN.value());
|
||||
flow.setInOutItem(InOutItemEnum.WIN_IN.value());
|
||||
}
|
||||
// 盘平
|
||||
if (NumberUtil.equals(inOutNumber, BigDecimal.ZERO)) {
|
||||
return;
|
||||
}
|
||||
flow.setAfterNumber(NumberUtil.toBigDecimal(entity.getStockNumber()));
|
||||
flow.setRemark(param.getRemark());
|
||||
productStockFlowService.saveFlow(flow);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -757,12 +645,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
.eq(ProdSku::getProductId, id)
|
||||
.eq(ProdSku::getShopId, shopId)
|
||||
.update();
|
||||
}else if("stock".equals(param.getOptType())){
|
||||
UpdateChain.of(Product.class)
|
||||
.set(Product::getIsStock, isSale)
|
||||
.eq(Product::getId, id)
|
||||
.eq(Product::getShopId, shopId)
|
||||
.update();
|
||||
}
|
||||
Product product = mapper.selectOneById(id);
|
||||
prodId = product.getId();
|
||||
@@ -834,14 +716,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
super.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stockWarning(Integer warnLine) {
|
||||
Long shopId = StpKit.USER.getShopId();
|
||||
UpdateChain.of(Product.class)
|
||||
.set(Product::getWarnLine, warnLine)
|
||||
.eq(Product::getShopId, shopId)
|
||||
.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -849,34 +723,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
Long shopId = StpKit.USER.getShopId();
|
||||
Long createUserId = StpKit.USER.getLoginIdAsLong();
|
||||
String createUserName = StpKit.USER.getAccount();
|
||||
Product product = mapper.selectOneById(param.getProductId());
|
||||
if (product == null) {
|
||||
throw new CzgException("商品不存在");
|
||||
}
|
||||
if (product.getIsStock() == SystemConstants.OneZero.ZERO) {
|
||||
throw new CzgException("商品未开启库存不支持报损操作");
|
||||
}
|
||||
// 商品现有库存数量
|
||||
Integer stockNumber = product.getStockNumber();
|
||||
product.setStockNumber(stockNumber - param.getNumber());
|
||||
if (product.getStockNumber() < 0) {
|
||||
throw new CzgException("商品库存不足,无法报损");
|
||||
}
|
||||
super.updateById(product);
|
||||
// 记录商品库存流水
|
||||
ProductStockFlow flow = new ProductStockFlow();
|
||||
flow.setCreateUserId(createUserId);
|
||||
flow.setCreateUserName(createUserName);
|
||||
flow.setShopId(shopId);
|
||||
flow.setProductId(product.getId());
|
||||
flow.setProductName(product.getName());
|
||||
flow.setBeforeNumber(NumberUtil.toBigDecimal(stockNumber));
|
||||
flow.setInOutNumber(NumberUtil.sub(BigDecimal.ZERO, NumberUtil.toBigDecimal(param.getNumber())));
|
||||
flow.setAfterNumber(NumberUtil.toBigDecimal(product.getStockNumber()));
|
||||
flow.setInOutType(InOutTypeEnum.OUT.value());
|
||||
flow.setInOutItem(InOutItemEnum.DAMAGE_OUT.value());
|
||||
flow.setImgUrls(JSON.toJSONString(param.getImgUrls()));
|
||||
productStockFlowService.saveFlow(flow);
|
||||
// 如果绑定了耗材,则同步更新耗材库存
|
||||
List<ProdConsRelationDTO> consList = prodConsRelationMapper.selectListByProdId(param.getProductId());
|
||||
if (CollUtil.isEmpty(consList)) {
|
||||
@@ -921,43 +767,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ProductStockFlow> findProductStockFlowPage(ProductStockFlowParam param) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
param.setShopId(shopId);
|
||||
PageHelper.startPage(PageUtil.buildPageHelp());
|
||||
if (InOutItemEnum.ORDER_IN.value().equals(param.getInOutItem())) {
|
||||
param.setInOutType(InOutTypeEnum.OUT.value());
|
||||
param.setInOutItem(InOutItemEnum.ORDER_OUT.value());
|
||||
param.setIsGreaterZero(SystemConstants.OneZero.ONE);
|
||||
}
|
||||
return PageUtil.convert(new PageInfo<>(productStockFlowMapper.getProductStockFlowList(param)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshProductStock(ProductDTO param, List<ProductDTO> records) {
|
||||
QueryWrapper queryWrapper = buildQueryWrapper(param);
|
||||
queryWrapper.select(PRODUCT.ID, PRODUCT.STOCK_NUMBER);
|
||||
List<Product> list = super.list(queryWrapper);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
Map<Long, Integer> stock = list.stream().collect(Collectors.toMap(Product::getId, Product::getStockNumber));
|
||||
records.parallelStream().forEach(record -> {
|
||||
record.setStockNumber(stock.getOrDefault(record.getId(), 0));
|
||||
if (record.getIsStock() == SystemConstants.OneZero.ONE) {
|
||||
refreshRedisStock(record.getShopId(), record.getId(), record.getStockNumber());
|
||||
} else {
|
||||
redisService.del(StrUtil.format(CacheConstant.SHOP_PRODUCT_STOCK, record.getShopId(), record.getId()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void refreshRedisStock(Long shopId, Long productId, Integer stockNumber) {
|
||||
String key = StrUtil.format(CacheConstant.SHOP_PRODUCT_STOCK, shopId, productId);
|
||||
redisService.set(key, stockNumber);
|
||||
}
|
||||
|
||||
private List<RelatedProductDTO> getRelateProductList(String relatedProduct) {
|
||||
if (StrUtil.isNotBlank(relatedProduct) && !"[]".equals(relatedProduct)) {
|
||||
List<Long> idList = JSONArray.parseArray(relatedProduct, Long.class);
|
||||
|
||||
@@ -1,25 +1,12 @@
|
||||
package com.czg.service.product.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.entity.ProductStockFlow;
|
||||
import com.czg.product.service.ProductStockFlowService;
|
||||
import com.czg.service.product.mapper.ConsInfoMapper;
|
||||
import com.czg.service.product.mapper.ProductMapper;
|
||||
import com.czg.service.product.mapper.ProductStockFlowMapper;
|
||||
import com.czg.service.product.util.WxAccountUtil;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品库存流水服务实现类
|
||||
*
|
||||
@@ -30,31 +17,4 @@ import java.util.List;
|
||||
@Slf4j
|
||||
public class ProductStockFlowServiceImpl extends ServiceImpl<ProductStockFlowMapper, ProductStockFlow> implements ProductStockFlowService {
|
||||
|
||||
@Resource
|
||||
private ProductMapper productMapper;
|
||||
@Resource
|
||||
private ConsInfoMapper consInfoMapper;
|
||||
@Resource
|
||||
private WxAccountUtil wxAccountUtil;
|
||||
|
||||
@Override
|
||||
public void saveFlow(ProductStockFlow entity) {
|
||||
mapper.insert(entity);
|
||||
Long shopId = entity.getShopId();
|
||||
BigDecimal afterNumber = entity.getAfterNumber();
|
||||
Product product = productMapper.selectOneById(entity.getProductId());
|
||||
String shopName = productMapper.getShopName(shopId);
|
||||
BigDecimal warnLine = Convert.toBigDecimal(product.getWarnLine());
|
||||
// 库存小于警告值,发送消息提醒
|
||||
if (NumberUtil.isLess(afterNumber, warnLine)) {
|
||||
List<String> openIdList = consInfoMapper.findOpenIdList(shopId, "pro");
|
||||
if (CollUtil.isEmpty(openIdList)) {
|
||||
return;
|
||||
}
|
||||
String productName = StrUtil.sub(product.getName(), 0, 10).concat("...");
|
||||
String conName = StrUtil.format("{}数量<预警值{}", productName, warnLine);
|
||||
ThreadUtil.execAsync(() -> openIdList.parallelStream().forEach(openId ->
|
||||
wxAccountUtil.sendStockMsg("商品库存预警", shopName, conName, afterNumber, openId)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,12 +15,11 @@ import com.czg.service.product.mapper.ShopProdCategoryMapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.update.UpdateChain;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -30,7 +29,7 @@ import java.util.List;
|
||||
* @author Tankaikai tankaikai@aliyun.com
|
||||
* @since 1.0 2025-02-10
|
||||
*/
|
||||
@Service
|
||||
@DubboService
|
||||
public class ShopProdCategoryServiceImpl extends ServiceImpl<ShopProdCategoryMapper, ShopProdCategory> implements ShopProdCategoryService {
|
||||
|
||||
@Resource
|
||||
@@ -121,22 +120,18 @@ public class ShopProdCategoryServiceImpl extends ServiceImpl<ShopProdCategoryMap
|
||||
@Override
|
||||
public void disableShopProdCategory(Long id) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
UpdateChain.of(ShopProdCategory.class)
|
||||
.set(ShopProdCategory::getStatus, SystemConstants.OneZero.ZERO)
|
||||
.eq(ShopProdCategory::getId, id)
|
||||
.eq(ShopProdCategory::getShopId, shopId)
|
||||
.update();
|
||||
ShopProdCategory prodCategory = new ShopProdCategory();
|
||||
prodCategory.setStatus(SystemConstants.OneZero.ZERO);
|
||||
update(prodCategory, query().eq(ShopProdCategory::getId, id).eq(ShopProdCategory::getShopId, shopId));
|
||||
productService.clearProductCache(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableShopProdCategory(Long id) {
|
||||
Long shopId = StpKit.USER.getShopId(0L);
|
||||
UpdateChain.of(ShopProdCategory.class)
|
||||
.set(ShopProdCategory::getStatus,SystemConstants.OneZero.ONE)
|
||||
.eq(ShopProdCategory::getId, id)
|
||||
.eq(ShopProdCategory::getShopId, shopId)
|
||||
.update();
|
||||
ShopProdCategory prodCategory = new ShopProdCategory();
|
||||
prodCategory.setStatus(SystemConstants.OneZero.ONE);
|
||||
update(prodCategory, query().eq(ShopProdCategory::getId, id).eq(ShopProdCategory::getShopId, shopId));
|
||||
productService.clearProductCache(id);
|
||||
}
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
||||
unitMap.put(unit.getSyncId(), unit.getId());
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
buildNotice(mainMapList, "单位同步", pointShopUnits.size(), null, null);
|
||||
buildNotice(mainMapList, "单位新增", unitMap.size() - pointShopUnits.size(), null, null);
|
||||
log.info("单位同步,源{}个,已有{}个,同步{}个", list.size(), pointShopUnits.size(), unitMap.size() - pointShopUnits.size());
|
||||
@@ -546,7 +546,6 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
||||
tbProductNew.setCategoryId(tbProduct.getCategoryId() != null ? cateGoryMap.get(tbProduct.getCategoryId()) : null);
|
||||
tbProductNew.setSpecId(tbProduct.getSpecId() != null ? specMap.get(tbProduct.getSpecId()) : null);
|
||||
tbProductNew.setUnitId(tbProduct.getUnitId() != null ? unitMap.get(tbProduct.getUnitId()) : null);
|
||||
tbProductNew.setStockNumber(0);
|
||||
if (CollUtil.isNotEmpty(pointProducts)) {
|
||||
tbProductNew.setIsSale(0);
|
||||
}
|
||||
@@ -565,9 +564,9 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
||||
tbProductNew.setType(tbProduct.getType());
|
||||
tbProductNew.setGroupType(tbProduct.getGroupType());
|
||||
tbProductNew.setPackFee(tbProduct.getPackFee());
|
||||
tbProductNew.setIsAutoSoldStock(tbProduct.getIsAutoSoldStock());
|
||||
tbProductNew.setCoverImg(tbProduct.getCoverImg());
|
||||
tbProductNew.setImages(tbProduct.getImages());
|
||||
tbProductNew.setWarnLine(tbProduct.getWarnLine());
|
||||
tbProductNew.setWeight(tbProduct.getWeight());
|
||||
tbProductNew.setSelectSpecInfo(tbProduct.getSelectSpecInfo());
|
||||
tbProductNew.setSort(tbProduct.getSort());
|
||||
@@ -655,16 +654,13 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
||||
newEntity.setEndTime(null);
|
||||
newEntity.setDays(null);
|
||||
newEntity.setIsHot(null);
|
||||
newEntity.setIsStock(null);
|
||||
newEntity.setIsSoldStock(null);
|
||||
newEntity.setStockNumber(null);
|
||||
newEntity.setIsSale(null);
|
||||
newEntity.setIsRefundStock(null);
|
||||
productService.updateById(newEntity);
|
||||
} else {
|
||||
newEntity.setId(null);
|
||||
newEntity.setIsSale(0);
|
||||
newEntity.setStockNumber(0);
|
||||
productService.save(newEntity);
|
||||
}
|
||||
if (newEntity.getCategoryId() != null) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.czg.service.product.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -166,55 +165,11 @@ public class UProductServiceImpl extends ServiceImpl<ProductMapper, Product> imp
|
||||
, ShopProductSkuInfoVo.class);
|
||||
// throw new CzgException("商品SKU不可售或不存在");
|
||||
if (data != null) {
|
||||
data.setStockNumber(ObjUtil.defaultIfNull(product.getStockNumber(), 0));
|
||||
data.setIsSoldStock(data.getIsPauseSale());
|
||||
data.setIsSale(data.getIsGrounding());
|
||||
data.setIsStock(product.getIsStock());
|
||||
return data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, Integer> findShopProductStock(Long shopId) {
|
||||
List<Product> list = productMapper.selectListByQuery(query().select(Product::getId, Product::getStockNumber).eq(Product::getShopId, shopId));
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return null;
|
||||
}
|
||||
return list.stream().collect(Collectors.toMap(Product::getId, Product::getStockNumber));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshProductStock(Long shopId, List<ShopProductVo> productList) {
|
||||
Map<Long, Integer> stock = findShopProductStock(shopId);
|
||||
if (MapUtil.isEmpty(stock)) {
|
||||
return;
|
||||
}
|
||||
productList.parallelStream().forEach(record -> {
|
||||
record.setStockNumber(stock.getOrDefault(record.getId(), 0));
|
||||
refreshRedisStock(record.getShopId(), record.getId(), record.getStockNumber());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshProductStock(Map<Long, Integer> productStock, List<ShopProductVo> productList) {
|
||||
if (MapUtil.isEmpty(productStock)) {
|
||||
return;
|
||||
}
|
||||
productList.parallelStream().forEach(record -> {
|
||||
record.setStockNumber(productStock.getOrDefault(record.getId(), 0));
|
||||
if (record.getIsStock() == SystemConstants.OneZero.ONE) {
|
||||
refreshRedisStock(record.getShopId(), record.getId(), record.getStockNumber());
|
||||
} else {
|
||||
redisService.del(StrUtil.format(CacheConstant.SHOP_PRODUCT_STOCK, record.getShopId(), record.getId()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void refreshRedisStock(Long shopId, Long productId, Integer stockNumber) {
|
||||
String key = StrUtil.format(CacheConstant.SHOP_PRODUCT_STOCK, shopId, productId);
|
||||
redisService.set(key, stockNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算是否在可售时间内
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
t1.unit_id,
|
||||
t1.weight,
|
||||
t1.end_time,
|
||||
t1.is_stock,
|
||||
t1.pack_fee,
|
||||
t1.cover_img,
|
||||
t1.warn_line,
|
||||
@@ -29,7 +28,6 @@
|
||||
t1.short_title,
|
||||
t1.update_time,
|
||||
t1.is_sold_stock,
|
||||
t1.stock_number,
|
||||
t1.is_refund_stock,
|
||||
t1.select_spec_info,
|
||||
t1.group_category_id,
|
||||
@@ -82,7 +80,6 @@
|
||||
t3.name as unit_name,
|
||||
t1.is_sold_stock,
|
||||
t1.sync_id as syncId,
|
||||
t1.stock_number,
|
||||
t1.type,
|
||||
t1.group_type,
|
||||
t1.days,
|
||||
@@ -95,7 +92,6 @@
|
||||
t1.pack_fee,
|
||||
ifnull(t4.sales_volume, 0) as sales_volume,
|
||||
t1.shop_id,
|
||||
t1.is_stock,
|
||||
t1.related_recommend
|
||||
from tb_product t1
|
||||
left join (select x.product_id,
|
||||
@@ -271,16 +267,4 @@
|
||||
</if>
|
||||
GROUP BY a.id
|
||||
</select>
|
||||
<update id="updateProductStockNum">
|
||||
update tb_product
|
||||
<if test="type == 'add'">
|
||||
set stock_number = stock_number + #{num}
|
||||
</if>
|
||||
<if test="type == 'sub'">
|
||||
set stock_number = stock_number - #{num}
|
||||
</if>
|
||||
where id = #{id}
|
||||
and is_stock = 1
|
||||
and shop_id = #{shopId}
|
||||
</update>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user