出入库商品添加库存警告线

This commit is contained in:
SongZhang 2024-06-27 14:09:47 +08:00
parent 4787e17836
commit 2072621990
7 changed files with 124 additions and 3 deletions

View File

@ -1,21 +1,32 @@
package cn.ysk.cashier.controller.product;
import cn.hutool.core.util.StrUtil;
import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.dto.product.StockQueryDto;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.service.product.StockService;
import cn.ysk.cashier.utils.BeanUtil;
import cn.ysk.cashier.utils.SecurityUtils;
import cn.ysk.cashier.vo.StockPageImpl;
import cn.ysk.cashier.vo.StockUpdateValueVO;
import cn.ysk.cashier.vo.StockUpdateWarnLineVO;
import cn.ysk.cashier.vo.StockV2Vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Map;
@RestController
@RequiredArgsConstructor
@ -89,7 +100,14 @@ public class StockController {
public ResponseEntity<Object> queryTbProductV2(StockQueryDto criteria,
@RequestParam(required = false, defaultValue = "0") Integer page,
@RequestParam(required = false, defaultValue = "10") Integer size){
return new ResponseEntity<>(stockService.queryAllV2(criteria,page,size), HttpStatus.OK);
Page<StockV2Vo> stockV2Vos = stockService.queryAllV2(criteria, page, size);
Map<String, Object> dataMap = BeanUtil.transBean2Map(stockV2Vos);
if (stockV2Vos.getContent().isEmpty()) {
dataMap.put("warnLine", 0);
}else {
dataMap.put("warnLine", stockV2Vos.getContent().get(0).getWarnLine());
}
return new ResponseEntity<>(dataMap, HttpStatus.OK);
}
@GetMapping("/sku")
@ -113,4 +131,14 @@ public class StockController {
return new ResponseEntity<>("修改成功", HttpStatus.OK);
}
@PutMapping("warnLine")
@ApiOperation("修改商品警告线")
public ResponseEntity<Object> updateProductWarnLine(@RequestBody StockUpdateWarnLineVO stockUpdateWarnLineVO) {
if (StrUtil.isBlank(stockUpdateWarnLineVO.getShopId()) || stockUpdateWarnLineVO.getWarnLine() == null || stockUpdateWarnLineVO.getWarnLine() <= 0) {
throw new BadRequestException("参数有误");
}
stockService.updateProductWarnLine(stockUpdateWarnLineVO);
return new ResponseEntity<>("修改成功", HttpStatus.OK);
}
}

View File

@ -59,7 +59,7 @@ public interface TbProductSkuRepository extends JpaRepository<TbProductSku, Inte
" WHEN pro.isDistribute = 1 THEN IFNULL(pro.stockNumber, 0) " +
" ELSE SUM(sku.stockNumber) " +
" END " +
", pro.isDistribute, pro.isPauseSale, true) " +
", pro.isDistribute, pro.isPauseSale, true, sku.warnLine) " +
"from " +
"TbProduct pro " +
"LEFT JOIN TbProductSku sku on pro.id = sku.productId " +
@ -150,4 +150,9 @@ public interface TbProductSkuRepository extends JpaRepository<TbProductSku, Inte
@Modifying
@Query("update FROM TbProductSku sku set sku.costPrice=:cost WHERE sku.productId=:productId")
Integer updateCostByProductId(String productId, BigDecimal cost);
@Transactional
@Modifying
@Query("UPDATE TbProductSku p SET p.warnLine = :warnLine WHERE p.shopId = :shopId")
Integer updateWarnLineByShopId(@Param("warnLine")Integer warnLine, @Param("shopId")String shopId);
}

View File

@ -4,8 +4,11 @@ import cn.ysk.cashier.dto.product.OutAndOnDto;
import cn.ysk.cashier.dto.product.StockQueryDto;
import cn.ysk.cashier.dto.product.TbProductDto;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.mapper.shop.TbShopInfoMapper;
import cn.ysk.cashier.pojo.product.TbProductSku;
import cn.ysk.cashier.pojo.shop.TbShopInfo;
import cn.ysk.cashier.repository.product.TbProductSkuRepository;
import cn.ysk.cashier.repository.shop.TbShopInfoRepository;
import cn.ysk.cashier.service.TbProductStockOperateService;
import cn.ysk.cashier.service.product.StockService;
import cn.ysk.cashier.service.product.TbProductService;
@ -13,6 +16,7 @@ import cn.ysk.cashier.utils.FileUtil;
import cn.ysk.cashier.utils.RedisUtils;
import cn.ysk.cashier.utils.StringUtils;
import cn.ysk.cashier.vo.StockUpdateValueVO;
import cn.ysk.cashier.vo.StockUpdateWarnLineVO;
import cn.ysk.cashier.vo.StockV2Vo;
import cn.ysk.cashier.vo.StockVo;
import lombok.RequiredArgsConstructor;
@ -24,6 +28,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
@ -31,6 +36,10 @@ import org.springframework.web.multipart.MultipartFile;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;
import java.io.IOException;
@ -49,6 +58,7 @@ public class StockServiceImpl implements StockService {
private final TbProductStockOperateService stockOperateService;
private final TbProductSkuRepository skuRepository;
private final TbShopInfoRepository tbShopInfoRepository;
@PersistenceContext
private EntityManager em;
@ -313,4 +323,13 @@ public class StockServiceImpl implements StockService {
Query nativeQuery = em.createNativeQuery(String.valueOf(sqlQuery));
nativeQuery.executeUpdate();
}
@Override
public void updateProductWarnLine(StockUpdateWarnLineVO stockUpdateWarnLineVO) {
TbShopInfo shopInfo = tbShopInfoRepository.findById(Integer.valueOf(stockUpdateWarnLineVO.getShopId())).orElse(null);
if (shopInfo == null) {
throw new BadRequestException("店铺不存在");
}
tbProductSkuRepository.updateWarnLineByShopId(stockUpdateWarnLineVO.getWarnLine(), stockUpdateWarnLineVO.getShopId());
}
}

View File

@ -2,6 +2,7 @@ package cn.ysk.cashier.service.product;
import cn.ysk.cashier.dto.product.StockQueryDto;
import cn.ysk.cashier.vo.StockUpdateValueVO;
import cn.ysk.cashier.vo.StockUpdateWarnLineVO;
import cn.ysk.cashier.vo.StockV2Vo;
import cn.ysk.cashier.vo.StockVo;
import org.springframework.data.domain.Page;
@ -20,7 +21,7 @@ public interface StockService {
*/
Page queryAll(StockQueryDto criteria, Integer page, Integer size);
Page queryAllV2(StockQueryDto criteria, Integer page, Integer size);
Page<StockV2Vo> queryAllV2(StockQueryDto criteria, Integer page, Integer size);
List<StockV2Vo> queryProductSku(String productId);
@ -37,4 +38,10 @@ public interface StockService {
void updateIsStock(Integer proId, String shopId,Integer isStock);
void updateProductStatus(StockUpdateValueVO updateValueVO);
/**
* 商品库存警戒线设置
* @param stockUpdateWarnLineVO 警戒线
*/
void updateProductWarnLine(StockUpdateWarnLineVO stockUpdateWarnLineVO);
}

View File

@ -0,0 +1,26 @@
package cn.ysk.cashier.vo;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import java.util.List;
public class StockPageImpl<T> extends PageImpl<T> {
private Integer warnLine;
public StockPageImpl(List<T> content, Pageable pageable, long total) {
super(content, pageable, total);
}
public StockPageImpl(List<T> content) {
super(content);
}
public Integer getWarnLine() {
return warnLine;
}
public void setWarnLine(Integer warnLine) {
this.warnLine = warnLine;
}
}

View File

@ -0,0 +1,13 @@
package cn.ysk.cashier.vo;
import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Data
public class StockUpdateWarnLineVO {
private String shopId;
private Integer warnLine;
}

View File

@ -22,6 +22,7 @@ public class StockV2Vo {
private Integer isDistribute;
private Integer isPauseSale;
private Object number;
private Integer warnLine;
public StockV2Vo(Integer proId, Integer skuId, String name, String unitName,String specSnap, Object number,Object stockNumber, Integer isDistribute) {
this.proId = proId;
@ -55,6 +56,28 @@ public class StockV2Vo {
this.isPauseSale = isPauseSale;
}
public StockV2Vo(Integer id, Integer proId,String img,String name,String unitName, String type, String specSnap,
Object isStock, Object number, Integer isDistribute, Integer isPauseSale, boolean isPro, Integer warnLine) {
this.id = id.toString() + "-" + proId.toString();
if (isPro) {
this.id += proId;
} else {
this.id += id;
}
this.skuId = id;
this.proId = proId;
this.img = img;
this.name = name;
this.unitName = unitName;
setType(type);
this.specSnap = specSnap;
this.isStock = isStock;
this.stockNumber = number;
this.isDistribute = isDistribute;
this.isPauseSale = isPauseSale;
this.warnLine = warnLine;
}
public void setType(String type) {
switch (type) {
case "normal":