库存警戒值

This commit is contained in:
2024-10-08 13:34:05 +08:00
parent 869d14f158
commit ca3b16c677
4 changed files with 8 additions and 50 deletions

View File

@@ -415,13 +415,6 @@ public class TbProductServiceImpl implements TbProductService {
if (resources.getCategoryId() == null) { if (resources.getCategoryId() == null) {
throw new BadRequestException("必填内容未填写"); throw new BadRequestException("必填内容未填写");
} }
// if (resources.getIsShowMall() == 1) {
// for (TbProductSku sku : resources.getSkuList()) {
// if (sku.getStockNumber() <= 0) {
// throw new BadRequestException("上架区域包括小程序时,库存数量必须大于0。");
// }
// }
// }
product.setCategoryId(String.valueOf(resources.getCategoryId())); product.setCategoryId(String.valueOf(resources.getCategoryId()));
} }
if (product.getUnitId() == null) { if (product.getUnitId() == null) {
@@ -465,16 +458,6 @@ public class TbProductServiceImpl implements TbProductService {
tbProductRepository.save(save); tbProductRepository.save(save);
//sku //sku
if (resources.getSkuList() != null) { if (resources.getSkuList() != null) {
Integer warnLine = 0;
List<TbProduct> productList = tbProductRepository.selectByShopId(resources.getShopId());
if (!productList.isEmpty()) {
TbProduct p = productList.get(0);
List<TbProductSku> productSkus = tbProductSkuRepository.searchSku(p.getId().toString());
if (!productSkus.isEmpty()) {
warnLine = productSkus.get(0).getWarnLine();
}
}
List<TbProductSku> skuList = new ArrayList<>(); List<TbProductSku> skuList = new ArrayList<>();
for (TbProductSku sku : resources.getSkuList()) { for (TbProductSku sku : resources.getSkuList()) {
sku.setProductId(String.valueOf(save.getId())); sku.setProductId(String.valueOf(save.getId()));
@@ -482,13 +465,8 @@ public class TbProductServiceImpl implements TbProductService {
sku.setCreatedAt(Instant.now().toEpochMilli()); sku.setCreatedAt(Instant.now().toEpochMilli());
sku.setUpdatedAt(Instant.now().toEpochMilli()); sku.setUpdatedAt(Instant.now().toEpochMilli());
sku.setIsGrounding(1); sku.setIsGrounding(1);
sku.setWarnLine(warnLine);
skuList.add(sku); skuList.add(sku);
} }
List<TbProductSku> tbProductSkus = tbProductSkuRepository.saveAll(skuList);
Map<Integer, Double> idStockMap = tbProductSkus.stream()
.collect(Collectors.toMap(TbProductSku::getId, TbProductSku::getStockNumber));
redisUtils.redisUp(1, save.getShopId(), idStockMap);
} }
//保存到sku_result //保存到sku_result
if ("sku".equals(resources.getTypeEnum())) { if ("sku".equals(resources.getTypeEnum())) {

View File

@@ -19,9 +19,9 @@ import cn.ysk.cashier.system.domain.Dept;
import cn.ysk.cashier.system.domain.Job; import cn.ysk.cashier.system.domain.Job;
import cn.ysk.cashier.system.domain.Role; import cn.ysk.cashier.system.domain.Role;
import cn.ysk.cashier.system.domain.User; import cn.ysk.cashier.system.domain.User;
import cn.ysk.cashier.system.enums.ParamsEnum; //import cn.ysk.cashier.system.enums.ParamsEnum;
import cn.ysk.cashier.system.repository.UserRepository; import cn.ysk.cashier.system.repository.UserRepository;
import cn.ysk.cashier.system.service.ParamsService; //import cn.ysk.cashier.system.service.ParamsService;
import cn.ysk.cashier.system.service.UserService; import cn.ysk.cashier.system.service.UserService;
import cn.ysk.cashier.utils.*; import cn.ysk.cashier.utils.*;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@@ -62,7 +62,7 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
private final UserCacheManager userCacheManager; private final UserCacheManager userCacheManager;
private final TokenProvider tokenProvider; private final TokenProvider tokenProvider;
private final ParamsService paramsService; // private final ParamsService paramsService;
private final TbMerchantRegisterRepository merchantRegisterRepository; private final TbMerchantRegisterRepository merchantRegisterRepository;
@@ -97,8 +97,8 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
tbShopInfo.setSmallQrcode(smallQrcode); tbShopInfo.setSmallQrcode(smallQrcode);
tbShopInfoRepository.save(tbShopInfo); tbShopInfoRepository.save(tbShopInfo);
} }
String baseUrl = paramsService.getValue(ParamsEnum.SHOP_ORDER_PAY_BASE_URL.name()); // String baseUrl = paramsService.getValue(ParamsEnum.SHOP_ORDER_PAY_BASE_URL.name());
tbShopInfo.setPaymentQrcode(baseUrl+"?shopId="+id); // tbShopInfo.setPaymentQrcode(baseUrl+"?shopId="+id);
ValidationUtil.isNull(tbShopInfo.getId(),"TbShopInfo","id",id); ValidationUtil.isNull(tbShopInfo.getId(),"TbShopInfo","id",id);
return tbShopInfoMapper.toDto(tbShopInfo); return tbShopInfoMapper.toDto(tbShopInfo);
} }

View File

@@ -747,7 +747,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
*/ */
private void checkWarnLineAndSendMsg(TbProductSku productSku, TbProduct product, Integer shopId, Integer num) { private void checkWarnLineAndSendMsg(TbProductSku productSku, TbProduct product, Integer shopId, Integer num) {
TbShopInfo shopInfo = shopInfoRepository.getById(shopId); TbShopInfo shopInfo = shopInfoRepository.getById(shopId);
if (productSku.getWarnLine() == null) { if (product.getWarnLine() == null) {
return; return;
} }
@@ -755,28 +755,12 @@ public class TbShopTableServiceImpl implements TbShopTableService {
return; return;
} }
if (productSku.getStockNumber() == null) {
productSku.setStockNumber((double) 0);
}
if (product.getStockNumber() == null) { if (product.getStockNumber() == null) {
product.setStockNumber(0); product.setStockNumber(0);
} }
if ( if (product.getStockNumber() - num <= product.getWarnLine()) {
(product.getIsDistribute() == 1 && product.getStockNumber() - num <= productSku.getWarnLine())
|| (product.getIsDistribute() != 1) && productSku.getStockNumber() - num <= productSku.getWarnLine()
) {
List<TbShopOpenId> openIdList = shopOpenIdMapper.selectList(new LambdaQueryWrapper<TbShopOpenId>()
.eq(TbShopOpenId::getShopId, shopId)
.eq(TbShopOpenId::getStatus, 1)
.and((queryWrapper) -> queryWrapper.eq(TbShopOpenId::getType, ShopWxMsgTypeEnum.ALL_MSG.getType())
.or().eq(TbShopOpenId::getType, ShopWxMsgTypeEnum.STOCK_MSG.getType()))
.groupBy(TbShopOpenId::getOpenId)
);
wxMsgUtils.aboardStockMsg(shopInfo.getShopName(), shopId, product.getName(), wxMsgUtils.aboardStockMsg(shopInfo.getShopName(), shopId, product.getName(),
product.getIsDistribute() == 1 ? product.getStockNumber() - num : (int) (productSku.getStockNumber() - num)); product.getStockNumber() - num);
} }
} }

View File

@@ -90,10 +90,6 @@ public interface TbProductService {
*/ */
void download(List<TbProductDto> all, HttpServletResponse response) throws IOException; void download(List<TbProductDto> all, HttpServletResponse response) throws IOException;
void updateIsHot(Integer id,Integer isStock);
void updateIsStock(Integer proId, String shopId, Integer isStock);
/** /**
* 增加库存 * 增加库存
* *