库存管理 库存记录
This commit is contained in:
@@ -4,6 +4,8 @@ import cn.ysk.cashier.annotation.Log;
|
|||||||
import cn.ysk.cashier.dto.product.OutAndOnDto;
|
import cn.ysk.cashier.dto.product.OutAndOnDto;
|
||||||
import cn.ysk.cashier.dto.product.StockQueryDto;
|
import cn.ysk.cashier.dto.product.StockQueryDto;
|
||||||
import cn.ysk.cashier.exception.BadRequestException;
|
import cn.ysk.cashier.exception.BadRequestException;
|
||||||
|
import cn.ysk.cashier.pojo.product.TbProductSku;
|
||||||
|
import cn.ysk.cashier.repository.product.TbProductSkuRepository;
|
||||||
import cn.ysk.cashier.service.TbProductStockOperateService;
|
import cn.ysk.cashier.service.TbProductStockOperateService;
|
||||||
import cn.ysk.cashier.service.product.StockService;
|
import cn.ysk.cashier.service.product.StockService;
|
||||||
import cn.ysk.cashier.vo.StockVo;
|
import cn.ysk.cashier.vo.StockVo;
|
||||||
@@ -23,6 +25,7 @@ import java.io.IOException;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -33,6 +36,7 @@ public class StockController {
|
|||||||
|
|
||||||
private final StockService stockService;
|
private final StockService stockService;
|
||||||
private final TbProductStockOperateService stockOperateService;
|
private final TbProductStockOperateService stockOperateService;
|
||||||
|
private final TbProductSkuRepository skuRepository;
|
||||||
|
|
||||||
@ApiOperation("库存导出")
|
@ApiOperation("库存导出")
|
||||||
@PostMapping(value = "download")
|
@PostMapping(value = "download")
|
||||||
@@ -62,12 +66,17 @@ public class StockController {
|
|||||||
row = sheet.getRow(i);
|
row = sheet.getRow(i);
|
||||||
if(row!=null){
|
if(row!=null){
|
||||||
if(row.getCell(0)!=null){
|
if(row.getCell(0)!=null){
|
||||||
list.add(new StockVo(
|
Optional<TbProductSku> byId = skuRepository.findById(Integer.valueOf(row.getCell(0).getRawValue()));
|
||||||
Integer.valueOf(row.getCell(0).getRawValue()),
|
if(byId.isPresent()){
|
||||||
row.getCell(1).toString(),
|
TbProductSku sku = byId.get();
|
||||||
row.getCell(4).toString(),
|
list.add(new StockVo(
|
||||||
row.getCell(3).toString(),
|
sku.getId(),
|
||||||
row.getCell(5).toString()));
|
row.getCell(1).toString(),
|
||||||
|
row.getCell(4).toString(),
|
||||||
|
row.getCell(3).toString(),
|
||||||
|
row.getCell(5).toString(),
|
||||||
|
sku.getStockNumber()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,7 +85,7 @@ public class StockController {
|
|||||||
outAndOnDto.setShopId(shopId);
|
outAndOnDto.setShopId(shopId);
|
||||||
outAndOnDto.setList(new ArrayList<>(list));
|
outAndOnDto.setList(new ArrayList<>(list));
|
||||||
outAndOnDto.setType("purchase");
|
outAndOnDto.setType("purchase");
|
||||||
outAndOnDto.setRemark("一次性导入库存");
|
outAndOnDto.setRemark("一次性导入 库存数会覆盖");
|
||||||
outAndOnDto.setIsImport("true");
|
outAndOnDto.setIsImport("true");
|
||||||
outAndOnDto.setTime(System.currentTimeMillis());
|
outAndOnDto.setTime(System.currentTimeMillis());
|
||||||
outAndOnDto.setTotalAmount(BigDecimal.ZERO);
|
outAndOnDto.setTotalAmount(BigDecimal.ZERO);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public class StockQueryDto {
|
|||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String shopId;
|
private String shopId;
|
||||||
|
private Double num;
|
||||||
private Integer isStock;
|
private Integer isStock;
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
@@ -27,4 +28,10 @@ public class StockQueryDto {
|
|||||||
this.isStock = isStock;
|
this.isStock = isStock;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNum(Double num) {
|
||||||
|
if (num!=null) {
|
||||||
|
this.num = num;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,4 +101,21 @@ stockpile存酒入库
|
|||||||
private Long createdAt;
|
private Long createdAt;
|
||||||
|
|
||||||
private Long updatedAt;
|
private Long updatedAt;
|
||||||
|
|
||||||
|
public void setTypes() {
|
||||||
|
switch (this.type) {
|
||||||
|
case "purchase":
|
||||||
|
this.type = "其他入库";
|
||||||
|
break;
|
||||||
|
case "other-out":
|
||||||
|
this.type = "其他出库";
|
||||||
|
break;
|
||||||
|
case "reject":
|
||||||
|
this.type = "供应商退货";
|
||||||
|
break;
|
||||||
|
case "purveyor":
|
||||||
|
this.type = "供应商入库";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,7 @@ package cn.ysk.cashier.dto.product;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import cn.ysk.cashier.annotation.Query;
|
import cn.ysk.cashier.annotation.Query;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @website https://eladmin.vip
|
* @website https://eladmin.vip
|
||||||
@@ -38,6 +39,9 @@ public class TbProductStockDetailQueryCriteria{
|
|||||||
/** 精确 */
|
/** 精确 */
|
||||||
@Query
|
@Query
|
||||||
private String productName;
|
private String productName;
|
||||||
|
|
||||||
|
@Query
|
||||||
|
private String type;
|
||||||
/** BETWEEN */
|
/** BETWEEN */
|
||||||
@Query(type = Query.Type.BETWEEN)
|
@Query(type = Query.Type.BETWEEN)
|
||||||
private List<Long> createdAt;
|
private List<Long> createdAt;
|
||||||
@@ -51,4 +55,10 @@ public class TbProductStockDetailQueryCriteria{
|
|||||||
private Integer size;
|
private Integer size;
|
||||||
|
|
||||||
private String sort = "id,desc";
|
private String sort = "id,desc";
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
if(StringUtils.isNotBlank(type)){
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -46,10 +46,11 @@ public interface TbProductSkuRepository extends JpaRepository<TbProductSku, Inte
|
|||||||
"pro.shopId = :shopId " +
|
"pro.shopId = :shopId " +
|
||||||
"AND pro.status = 1 " +
|
"AND pro.status = 1 " +
|
||||||
"AND (:proName IS NULL OR pro.name LIKE %:proName%) " +
|
"AND (:proName IS NULL OR pro.name LIKE %:proName%) " +
|
||||||
|
"AND (:num IS NULL OR sku.stockNumber < :num) " +
|
||||||
"AND (:isStock IS NULL OR pro.isStock = :isStock) " +
|
"AND (:isStock IS NULL OR pro.isStock = :isStock) " +
|
||||||
"ORDER BY " +
|
"ORDER BY " +
|
||||||
"pro.name DESC,sku.stockNumber DESC")
|
"pro.name DESC,sku.stockNumber DESC")
|
||||||
Page<StockVo> searchProStock(@Param("shopId") String shopId, @Param("proName") String proName, @Param("isStock")Integer isStock, Pageable pageable);
|
Page<StockVo> searchProStock(@Param("shopId") String shopId, @Param("proName") String proName, @Param("isStock")Integer isStock,@Param("num")Double num, Pageable pageable);
|
||||||
@Query("SELECT new cn.ysk.cashier.vo.StockVo(" +
|
@Query("SELECT new cn.ysk.cashier.vo.StockVo(" +
|
||||||
"sku.id,pro.id,pro.coverImg,pro.name,unit.name,pro.typeEnum,sku.specSnap,pro.isStock,sku.stockNumber" +
|
"sku.id,pro.id,pro.coverImg,pro.name,unit.name,pro.typeEnum,sku.specSnap,pro.isStock,sku.stockNumber" +
|
||||||
") " +
|
") " +
|
||||||
@@ -59,11 +60,13 @@ public interface TbProductSkuRepository extends JpaRepository<TbProductSku, Inte
|
|||||||
"LEFT JOIN TbShopUnit unit ON pro.unitId = unit.id " +
|
"LEFT JOIN TbShopUnit unit ON pro.unitId = unit.id " +
|
||||||
"WHERE " +
|
"WHERE " +
|
||||||
"pro.shopId = :shopId " +
|
"pro.shopId = :shopId " +
|
||||||
|
"AND pro.status = 1 " +
|
||||||
"AND (:proName IS NULL OR pro.name LIKE %:proName%) " +
|
"AND (:proName IS NULL OR pro.name LIKE %:proName%) " +
|
||||||
"AND (:isStock IS NULL OR pro.isStock = :isStock) " +
|
"AND (:isStock IS NULL OR pro.isStock = :isStock) " +
|
||||||
|
"AND (:num IS NULL OR sku.stockNumber < :num) " +
|
||||||
"ORDER BY " +
|
"ORDER BY " +
|
||||||
"pro.name DESC,sku.stockNumber DESC")
|
"pro.name DESC,sku.stockNumber DESC")
|
||||||
List<StockVo> searchProStock(@Param("shopId") String shopId, @Param("proName") String proName, @Param("isStock")Integer isStock);
|
List<StockVo> searchProStock(@Param("shopId") String shopId, @Param("proName") String proName, @Param("isStock")Integer isStock,@Param("num")Double num);
|
||||||
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|||||||
@@ -32,13 +32,13 @@ public class StockServiceImpl implements StockService {
|
|||||||
@Override
|
@Override
|
||||||
public Page queryAll(StockQueryDto criteria, Integer page, Integer size) {
|
public Page queryAll(StockQueryDto criteria, Integer page, Integer size) {
|
||||||
Pageable pageable = PageRequest.of(page, size);
|
Pageable pageable = PageRequest.of(page, size);
|
||||||
return tbProductSkuRepository.searchProStock(criteria.getShopId(), criteria.getName(), criteria.getIsStock(), pageable);
|
return tbProductSkuRepository.searchProStock(criteria.getShopId(), criteria.getName(), criteria.getIsStock(),criteria.getNum(), pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void download(StockQueryDto criteria, HttpServletResponse response) throws IOException {
|
public void download(StockQueryDto criteria, HttpServletResponse response) throws IOException {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
List<StockVo> stockVos = tbProductSkuRepository.searchProStock(criteria.getShopId(), criteria.getName(), criteria.getIsStock());
|
List<StockVo> stockVos = tbProductSkuRepository.searchProStock(criteria.getShopId(), criteria.getName(), criteria.getIsStock(),criteria.getNum());
|
||||||
for (StockVo all : stockVos) {
|
for (StockVo all : stockVos) {
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
map.put("id(如需导入,该值不可变)", all.getId());
|
map.put("id(如需导入,该值不可变)", all.getId());
|
||||||
|
|||||||
@@ -65,8 +65,11 @@ public class TbProductStockDetailServiceImpl implements TbProductStockDetailServ
|
|||||||
|
|
||||||
Page<TbProductStockDetail> page = tbProductStockDetailRepository.findAll((root, criteriaQuery, criteriaBuilder)
|
Page<TbProductStockDetail> page = tbProductStockDetailRepository.findAll((root, criteriaQuery, criteriaBuilder)
|
||||||
-> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
-> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||||
|
Page<TbProductStockDetailDto> map = page.map(tbProductStockDetailMapper::toDto);
|
||||||
return PageUtil.toPage(page.map(tbProductStockDetailMapper::toDto));
|
for (TbProductStockDetailDto tbProductStockDetailDto : map.getContent()) {
|
||||||
|
tbProductStockDetailDto.setTypes();
|
||||||
|
}
|
||||||
|
return PageUtil.toPage(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -163,7 +163,6 @@ public class TbProductStockOperateServiceImpl implements TbProductStockOperateSe
|
|||||||
stockOperate.setStatus("normal");
|
stockOperate.setStatus("normal");
|
||||||
stockOperate.setPurveyorId(resources.getPurveyorId());
|
stockOperate.setPurveyorId(resources.getPurveyorId());
|
||||||
stockOperate.setPurveyorName(resources.getPurveyorName());
|
stockOperate.setPurveyorName(resources.getPurveyorName());
|
||||||
TbProductStockOperate saveStockOperate = tbProductStockOperateRepository.save(stockOperate);
|
|
||||||
if (!resources.getIsImport().equals("true")) {
|
if (!resources.getIsImport().equals("true")) {
|
||||||
//供应商退货 reject
|
//供应商退货 reject
|
||||||
//供应商入库 purveyor
|
//供应商入库 purveyor
|
||||||
@@ -197,10 +196,14 @@ public class TbProductStockOperateServiceImpl implements TbProductStockOperateSe
|
|||||||
purveyorRepository.upLastTransactAt(resources.getPurveyorId());
|
purveyorRepository.upLastTransactAt(resources.getPurveyorId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TbProductStockOperate saveStockOperate = tbProductStockOperateRepository.save(stockOperate);
|
||||||
Map<Integer, Double> idStockMap = new HashMap<>();
|
Map<Integer, Double> idStockMap = new HashMap<>();
|
||||||
for (Object date : resources.getList()) {
|
for (Object date : resources.getList()) {
|
||||||
//商品详情
|
//商品详情
|
||||||
ProductListDto productListDto = JSONObject.parseObject(JSONObject.toJSONString(date), ProductListDto.class);
|
ProductListDto productListDto = JSONObject.parseObject(JSONObject.toJSONString(date), ProductListDto.class);
|
||||||
|
if (productListDto.getNumber().equals(0)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
TbProductSku tbProductSku = tbProductSkuRepository.findById(productListDto.getId()).orElseGet(TbProductSku::new);
|
TbProductSku tbProductSku = tbProductSkuRepository.findById(productListDto.getId()).orElseGet(TbProductSku::new);
|
||||||
TbProductStockDetail productStockDetail = new TbProductStockDetail();
|
TbProductStockDetail productStockDetail = new TbProductStockDetail();
|
||||||
productStockDetail.setBatchNumber(resources.getBatchNumber());
|
productStockDetail.setBatchNumber(resources.getBatchNumber());
|
||||||
@@ -215,6 +218,7 @@ public class TbProductStockOperateServiceImpl implements TbProductStockOperateSe
|
|||||||
productStockDetail.setShopId(resources.getShopId());
|
productStockDetail.setShopId(resources.getShopId());
|
||||||
productStockDetail.setSkuId(productListDto.getId().toString());
|
productStockDetail.setSkuId(productListDto.getId().toString());
|
||||||
productStockDetail.setSourcePath("NORMAL");
|
productStockDetail.setSourcePath("NORMAL");
|
||||||
|
productStockDetail.setStockSnap(productListDto.getSpecSnap());
|
||||||
productListDto.setNumber(productListDto.getNumber() != null ? productListDto.getNumber() : 0);
|
productListDto.setNumber(productListDto.getNumber() != null ? productListDto.getNumber() : 0);
|
||||||
switch (resources.getType()) {
|
switch (resources.getType()) {
|
||||||
case "sale":
|
case "sale":
|
||||||
@@ -253,6 +257,8 @@ public class TbProductStockOperateServiceImpl implements TbProductStockOperateSe
|
|||||||
idStockMap.put(productListDto.getId(), productStockDetail.getStockNumber());
|
idStockMap.put(productListDto.getId(), productStockDetail.getStockNumber());
|
||||||
}
|
}
|
||||||
redisUtils.redisUp(2, resources.getShopId(), idStockMap);
|
redisUtils.redisUp(2, resources.getShopId(), idStockMap);
|
||||||
|
}else {
|
||||||
|
tbProductStockOperateRepository.save(stockOperate);
|
||||||
}
|
}
|
||||||
return resources;
|
return resources;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,13 +13,15 @@ public class StockVo {
|
|||||||
private String specSnap;
|
private String specSnap;
|
||||||
private Object isStock;
|
private Object isStock;
|
||||||
private Object number;
|
private Object number;
|
||||||
|
private Object stockNumber;
|
||||||
|
|
||||||
public StockVo(Integer id,String name,String unitName,String specSnap, Object number) {
|
public StockVo(Integer id,String name,String unitName,String specSnap, Object number,Object stockNumber) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.unitName = unitName;
|
this.unitName = unitName;
|
||||||
this.specSnap = specSnap;
|
this.specSnap = specSnap;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.number = number;
|
this.number = number;
|
||||||
|
this.stockNumber = stockNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StockVo(Integer id, Integer proId,String img,String name,String unitName, String type, String specSnap, Object isStock, Object number) {
|
public StockVo(Integer id, Integer proId,String img,String name,String unitName, String type, String specSnap, Object isStock, Object number) {
|
||||||
@@ -63,7 +65,8 @@ public class StockVo {
|
|||||||
"\"name\":\"" + name + "\","+
|
"\"name\":\"" + name + "\","+
|
||||||
"\"unitName\":\"" + unitName +"\","+
|
"\"unitName\":\"" + unitName +"\","+
|
||||||
"\"specSnap\":\"" + specSnap + "\"," +
|
"\"specSnap\":\"" + specSnap + "\"," +
|
||||||
"\"number\":\"" + number + "\"" +
|
"\"number\":\"" + number + "\"," +
|
||||||
|
"\"stockNumber\":\"" + stockNumber + "\"" +
|
||||||
"}";
|
"}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user