|
@@ -1,6 +1,7 @@
|
|
package com.hys.app.service.erp.impl;
|
|
package com.hys.app.service.erp.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -14,12 +15,11 @@ import com.hys.app.framework.util.DateUtil;
|
|
import com.hys.app.framework.util.PageConvert;
|
|
import com.hys.app.framework.util.PageConvert;
|
|
import com.hys.app.framework.util.StringUtil;
|
|
import com.hys.app.framework.util.StringUtil;
|
|
import com.hys.app.mapper.erp.StockInventoryMapper;
|
|
import com.hys.app.mapper.erp.StockInventoryMapper;
|
|
-import com.hys.app.model.erp.dos.ProductStockDO;
|
|
|
|
-import com.hys.app.model.erp.dos.StockInventory;
|
|
|
|
-import com.hys.app.model.erp.dos.StockInventoryProduct;
|
|
|
|
|
|
+import com.hys.app.model.erp.dos.*;
|
|
import com.hys.app.model.erp.dto.*;
|
|
import com.hys.app.model.erp.dto.*;
|
|
import com.hys.app.model.erp.enums.DamageinventoryEnum;
|
|
import com.hys.app.model.erp.enums.DamageinventoryEnum;
|
|
import com.hys.app.model.erp.enums.NoBusinessTypeEnum;
|
|
import com.hys.app.model.erp.enums.NoBusinessTypeEnum;
|
|
|
|
+import com.hys.app.model.erp.enums.SnCodeStatusEnum;
|
|
import com.hys.app.model.erp.enums.StockInventoryStatusEnum;
|
|
import com.hys.app.model.erp.enums.StockInventoryStatusEnum;
|
|
import com.hys.app.model.erp.vo.GoodsVO;
|
|
import com.hys.app.model.erp.vo.GoodsVO;
|
|
import com.hys.app.model.erp.vo.ProductVO;
|
|
import com.hys.app.model.erp.vo.ProductVO;
|
|
@@ -54,6 +54,8 @@ public class StockInventoryManagerImpl extends ServiceImpl<StockInventoryMapper,
|
|
private ProductStockManager productStockManager;
|
|
private ProductStockManager productStockManager;
|
|
private GoodsManager goodsManager;
|
|
private GoodsManager goodsManager;
|
|
private ProductManager productManager;
|
|
private ProductManager productManager;
|
|
|
|
+ private ItemSnCodeManager itemSnCodeManager;
|
|
|
|
+ private GoodsSnManager goodsSnManager;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -86,9 +88,51 @@ public class StockInventoryManagerImpl extends ServiceImpl<StockInventoryMapper,
|
|
save(copied);
|
|
save(copied);
|
|
List<StockInventoryProduct> list = BeanUtils.toBean(stockInventoryDTO.getProductList(), StockInventoryProduct.class);
|
|
List<StockInventoryProduct> list = BeanUtils.toBean(stockInventoryDTO.getProductList(), StockInventoryProduct.class);
|
|
list.forEach(item -> item.setInventoryId(copied.getId()));
|
|
list.forEach(item -> item.setInventoryId(copied.getId()));
|
|
- this.stockInventoryProductManager.saveProduct(copied.getId(), stockInventoryDTO.getProductList());
|
|
|
|
|
|
+ this.stockInventoryProductManager.saveBatch(list);
|
|
|
|
+ //如果这个商品有序列号补习不全序列号关系
|
|
|
|
+ for (StockInventoryProductDTO dto : stockInventoryDTO.getProductList()) {
|
|
|
|
+ StockInventoryProduct product = list.stream().filter(item -> item.getProductId().equals(dto.getProductId())).findFirst().get();
|
|
|
|
+ dto.setId(product.getId());
|
|
|
|
+ }
|
|
|
|
+ saveSnCode(copied.getId(), stockInventoryDTO.getProductList());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void saveSnCode(Long stockInventoryId, List<StockInventoryProductDTO> productList) {
|
|
|
|
+ List<ItemSnCodeDO> itemSnCodeDOS = new ArrayList<>();
|
|
|
|
+ //如果有序列号,保存序列号和入库单的关系,更爱序列号的状态
|
|
|
|
+ List<String> arrayList = new ArrayList<>();
|
|
|
|
+ for (StockInventoryProductDTO aDo : productList) {
|
|
|
|
+ ProductDO byId = productManager.getById(aDo.getProductId());
|
|
|
|
+ if (byId.getHaveSn() && CollUtil.isEmpty(aDo.getSnCodeList())){
|
|
|
|
+ throw new ServiceException("有序列号的商品序列号不能为空");
|
|
|
|
+ }
|
|
|
|
+ if (CollUtil.isNotEmpty(aDo.getSnCodeList())) {
|
|
|
|
+ if (aDo.getInventoryNum() != aDo.getSnCodeList().size()) {
|
|
|
|
+ throw new ServiceException("序列号个数和盘点个数不等");
|
|
|
|
+ }
|
|
|
|
+ arrayList.addAll(aDo.getSnCodeList().stream().map(GoodsSnDO::getSnCode).collect(Collectors.toList()));
|
|
|
|
+ aDo.getSnCodeList().forEach(item -> {
|
|
|
|
+ ItemSnCodeDO itemSnCodeDO = new ItemSnCodeDO();
|
|
|
|
+ itemSnCodeDO.setItemId(aDo.getId());
|
|
|
|
+ itemSnCodeDO.setEntryOutHouseId(stockInventoryId);
|
|
|
|
+ itemSnCodeDO.setType("inventory");
|
|
|
|
+ itemSnCodeDO.setSnCodeId(item.getId());
|
|
|
|
+ itemSnCodeDOS.add(itemSnCodeDO);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(CollUtil.isNotEmpty(arrayList)){
|
|
|
|
+ long count = goodsSnManager.count(new LambdaQueryWrapper<GoodsSnDO>().in(GoodsSnDO::getSnCode, arrayList));
|
|
|
|
+ if (count != arrayList.size()) {
|
|
|
|
+ throw new ServiceException("部分序列号不存在");
|
|
|
|
+ }
|
|
|
|
+ //保存序列号和子表的关系
|
|
|
|
+ itemSnCodeManager.saveBatch(itemSnCodeDOS);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
public void syncStock(Long id) {
|
|
public void syncStock(Long id) {
|
|
@@ -108,8 +152,31 @@ public class StockInventoryManagerImpl extends ServiceImpl<StockInventoryMapper,
|
|
dto.setNum(product.getInventoryNum());
|
|
dto.setNum(product.getInventoryNum());
|
|
listStock.add(dto);
|
|
listStock.add(dto);
|
|
}
|
|
}
|
|
- productStockManager.updateActualStock(listStock,"inventory");
|
|
|
|
-
|
|
|
|
|
|
+ productStockManager.updateActualStock(listStock, "inventory");
|
|
|
|
+ //更新序列号的关系
|
|
|
|
+ GoodsSnDO snDO = new GoodsSnDO();
|
|
|
|
+ snDO.setEntryHouseId(null);
|
|
|
|
+ snDO.setInventoryId(null);
|
|
|
|
+ snDO.setOutHouseId(null);
|
|
|
|
+ snDO.setWarehouseId(null);
|
|
|
|
+ snDO.setStatus(SnCodeStatusEnum.NOT_USED);
|
|
|
|
+ goodsSnManager.update(snDO, new LambdaQueryWrapper<GoodsSnDO>()
|
|
|
|
+ .eq(GoodsSnDO::getWarehouseId, stockInventory.getWarehouseId())
|
|
|
|
+ .in(GoodsSnDO::getProductId, goodsList.stream().map(StockInventoryProduct::getProductId).collect(Collectors.toList())));
|
|
|
|
+ //找到这个订单关联的所有序列号
|
|
|
|
+ List<ItemSnCodeDO> listed = itemSnCodeManager.list(new LambdaQueryWrapper<ItemSnCodeDO>()
|
|
|
|
+ .eq(ItemSnCodeDO::getType, "inventory").eq(ItemSnCodeDO::getEntryOutHouseId, id));
|
|
|
|
+ if (CollUtil.isNotEmpty(listed)){
|
|
|
|
+ List<GoodsSnDO> goodsSnDOS = goodsSnManager.list(new LambdaQueryWrapper<GoodsSnDO>().in(GoodsSnDO::getId, listed.stream().map(ItemSnCodeDO::getSnCodeId).collect(Collectors.toList())));
|
|
|
|
+ //更爱序列号状态
|
|
|
|
+ for (GoodsSnDO aDo : goodsSnDOS) {
|
|
|
|
+ aDo.setStatus(SnCodeStatusEnum.IN_WAREHOUSE);
|
|
|
|
+ aDo.setInventoryId(id);
|
|
|
|
+ aDo.setWarehouseId(stockInventory.getWarehouseId());
|
|
|
|
+ aDo.setInventoryId(id);
|
|
|
|
+ }
|
|
|
|
+ goodsSnManager.updateBatchById(goodsSnDOS);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -136,6 +203,11 @@ public class StockInventoryManagerImpl extends ServiceImpl<StockInventoryMapper,
|
|
dto.setProductVO(productVO);
|
|
dto.setProductVO(productVO);
|
|
GoodsVO goodsVO = BeanUtil.copyProperties(goodsManager.getById(productVO.getGoodsId()), GoodsVO.class);
|
|
GoodsVO goodsVO = BeanUtil.copyProperties(goodsManager.getById(productVO.getGoodsId()), GoodsVO.class);
|
|
dto.setUsableStock(aDo.getUsableStock());
|
|
dto.setUsableStock(aDo.getUsableStock());
|
|
|
|
+ List<ItemSnCodeDO> list2 = itemSnCodeManager.list(new LambdaQueryWrapper<ItemSnCodeDO>().eq(ItemSnCodeDO::getItemId, dto.getId()));
|
|
|
|
+ if (CollUtil.isNotEmpty(list2)) {
|
|
|
|
+ List<Long> collected = list2.stream().map(ItemSnCodeDO::getSnCodeId).collect(Collectors.toList());
|
|
|
|
+ dto.setSnCodeList(goodsSnManager.list(new LambdaQueryWrapper<GoodsSnDO>().in(GoodsSnDO::getId, collected)));
|
|
|
|
+ }
|
|
dto.setGoodsVO(goodsVO);
|
|
dto.setGoodsVO(goodsVO);
|
|
}
|
|
}
|
|
stockInventoryVO.setProductList(beanList);
|
|
stockInventoryVO.setProductList(beanList);
|