|
@@ -4,9 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.jsh.erp.datasource.entities.*;
|
|
|
import com.jsh.erp.datasource.mappers.MaterialBatchMapper;
|
|
|
+import com.jsh.erp.datasource.mappers.MaterialInitialStockMapper;
|
|
|
import com.jsh.erp.datasource.vo.TaskStocktakingItemVO;
|
|
|
import com.jsh.erp.exception.JshException;
|
|
|
import com.jsh.erp.query.LambdaQueryWrapperX;
|
|
|
+import com.jsh.erp.query.QueryWrapperX;
|
|
|
import com.jsh.erp.service.*;
|
|
|
import com.jsh.erp.utils.DateUtils;
|
|
|
import com.jsh.erp.utils.RandomHelper;
|
|
@@ -40,6 +42,9 @@ public class MaterialBatchServiceImpl extends ServiceImpl<MaterialBatchMapper,Ma
|
|
|
@Resource
|
|
|
private InventoryLogService inventoryLogService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private MaterialInitialStockMapper materialInitialStockMapper;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 根据单据子表id生成商品批次数据
|
|
@@ -82,28 +87,45 @@ public class MaterialBatchServiceImpl extends ServiceImpl<MaterialBatchMapper,Ma
|
|
|
materialBatch.setPosition(depotItem.getPosition());
|
|
|
//条码
|
|
|
materialBatch.setBarCode(materialExtend.getBarCode());
|
|
|
+ materialBatch.setMaterialExtendId(materialExtend.getId());
|
|
|
materialBatchMapper.insert(materialBatch);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void handleMaterialBatchByDepotItemId(Long diId) throws Exception {
|
|
|
DepotItem depotItem = depotItemService.getDepotItem(diId);
|
|
|
+ //获取商品期初库存
|
|
|
+ MaterialInitialStock mis = materialInitialStockMapper.selectOne(new LambdaQueryWrapperX<MaterialInitialStock>()
|
|
|
+ .eq(MaterialInitialStock::getMaterialId,depotItem.getMaterialId())
|
|
|
+ .eq(MaterialInitialStock::getDepotId,depotItem.getDepotId())
|
|
|
+ .eq(MaterialInitialStock::getDeleteFlag,"0"));
|
|
|
//根据单据商品id查询商品批次数据
|
|
|
List<MaterialBatch> list = materialBatchMapper.getMaterialBatchByMaterialId(depotItem.getMaterialId(),depotItem.getDepotId());
|
|
|
//根据单据子表基础单位数量减去批次库存
|
|
|
BigDecimal basicNumber = depotItem.getBasicNumber();
|
|
|
- for (MaterialBatch materialBatch : list) {
|
|
|
- if (materialBatch.getInventory().compareTo(basicNumber) >= 0){
|
|
|
- //批次库存足够,扣除库存,结束循环
|
|
|
- BigDecimal inventory = materialBatch.getInventory().subtract(basicNumber);
|
|
|
- materialBatch.setInventory(inventory);
|
|
|
- updateInventory("出库",diId,materialBatch);
|
|
|
- break;
|
|
|
- }else {
|
|
|
- //库存不足,扣除当前批次库存,继续循环
|
|
|
- basicNumber = basicNumber.subtract(materialBatch.getInventory());
|
|
|
- materialBatch.setInventory(BigDecimal.ZERO);
|
|
|
- updateInventory("出库",diId,materialBatch);
|
|
|
+ if (mis.getNumber() != null && mis.getNumber().compareTo(basicNumber) >= 0){
|
|
|
+ //初期库存足够,扣除期初库存
|
|
|
+ BigDecimal inventory = mis.getNumber().subtract(basicNumber);
|
|
|
+ mis.setNumber(inventory);
|
|
|
+ materialInitialStockMapper.updateByPrimaryKeySelective(mis);
|
|
|
+ }else {
|
|
|
+ //初期库存不足,先扣除期初,再从批次扣除
|
|
|
+ basicNumber = basicNumber.subtract(mis.getNumber());
|
|
|
+ mis.setNumber(BigDecimal.ZERO);
|
|
|
+ materialInitialStockMapper.updateByPrimaryKeySelective(mis);
|
|
|
+ for (MaterialBatch materialBatch : list) {
|
|
|
+ if (materialBatch.getInventory().compareTo(basicNumber) >= 0){
|
|
|
+ //批次库存足够,扣除库存,结束循环
|
|
|
+ BigDecimal inventory = materialBatch.getInventory().subtract(basicNumber);
|
|
|
+ materialBatch.setInventory(inventory);
|
|
|
+ updateInventory("出库",diId,materialBatch);
|
|
|
+ break;
|
|
|
+ }else {
|
|
|
+ //库存不足,扣除当前批次库存,继续循环
|
|
|
+ basicNumber = basicNumber.subtract(materialBatch.getInventory());
|
|
|
+ materialBatch.setInventory(BigDecimal.ZERO);
|
|
|
+ updateInventory("出库",diId,materialBatch);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -113,19 +135,19 @@ public class MaterialBatchServiceImpl extends ServiceImpl<MaterialBatchMapper,Ma
|
|
|
if (materialBatch.getInventory() != null){
|
|
|
//获取修改前库存
|
|
|
int originalStock = materialBatchMapper.selectOne("id",materialBatch.getId()).getInventory().intValue();
|
|
|
- User user = userService.getCurrentUser();
|
|
|
- InventoryLog log = new InventoryLog();
|
|
|
- log.setUpdateUser(user.getId());
|
|
|
- log.setUpdateTime(new Date());
|
|
|
- log.setMaterialId(materialBatch.getMaterialId());
|
|
|
- log.setMaterialExtendId(materialBatch.getId());
|
|
|
- log.setOriginalStock(originalStock);
|
|
|
- log.setCurrentStock(materialBatch.getInventory().intValue());
|
|
|
- log.setItemId(id);
|
|
|
- log.setType(type);
|
|
|
- inventoryLogService.save(log);
|
|
|
- update(new UpdateWrapper<MaterialBatch>().set("inventory",materialBatch.getInventory()).eq("id",materialBatch.getId()));
|
|
|
- depotItemService.updateCurrentStockFun(materialBatch.getMaterialId(),materialBatch.getDepotId());
|
|
|
+ User user = userService.getCurrentUser();
|
|
|
+ InventoryLog log = new InventoryLog();
|
|
|
+ log.setUpdateUser(user.getId());
|
|
|
+ log.setUpdateTime(new Date());
|
|
|
+ log.setMaterialId(materialBatch.getMaterialId());
|
|
|
+ log.setMaterialExtendId(materialBatch.getId());
|
|
|
+ log.setOriginalStock(originalStock);
|
|
|
+ log.setCurrentStock(materialBatch.getInventory().intValue());
|
|
|
+ log.setItemId(id);
|
|
|
+ log.setType(type);
|
|
|
+ inventoryLogService.save(log);
|
|
|
+ update(new UpdateWrapper<MaterialBatch>().set("inventory",materialBatch.getInventory()).eq("id",materialBatch.getId()));
|
|
|
+ depotItemService.updateCurrentStockFun(materialBatch.getMaterialId(),materialBatch.getDepotId());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -146,7 +168,6 @@ public class MaterialBatchServiceImpl extends ServiceImpl<MaterialBatchMapper,Ma
|
|
|
public List<MaterialVo4Unit> findBySelectWithBarCode(Long categoryId, String q, String standardOrModel, String color, String brand, String mfrs, String enableSerialNumber, String enableBatchNumber, Integer offset, Integer rows, Long depotId) throws Exception {
|
|
|
List<MaterialVo4Unit> list =null;
|
|
|
try{
|
|
|
-
|
|
|
if(StringUtil.isNotEmpty(q)) {
|
|
|
q = q.replace("'", "");
|
|
|
q = q.trim();
|
|
@@ -169,8 +190,8 @@ public class MaterialBatchServiceImpl extends ServiceImpl<MaterialBatchMapper,Ma
|
|
|
if (barCodes != null && !barCodes.isEmpty()){
|
|
|
barCodeList = Arrays.asList(barCodes.split(","));
|
|
|
}
|
|
|
- List<Long> ids = materialExtendService.selectIdsByBarCode(barCodeList);
|
|
|
- List<MaterialBatch> list = materialBatchMapper.selectList(new LambdaQueryWrapperX<MaterialBatch>().eq(MaterialBatch::getDepotId,depotId).inIfPresent(MaterialBatch::getMaterialId,ids).gt(MaterialBatch::getInventory,BigDecimal.ZERO));
|
|
|
+ //List<Long> ids = materialExtendService.selectIdsByBarCode(barCodeList);
|
|
|
+ List<MaterialBatch> list = materialBatchMapper.selectList(new LambdaQueryWrapperX<MaterialBatch>().eq(MaterialBatch::getDepotId,depotId).inIfPresent(MaterialBatch::getBarCode,barCodeList).gt(MaterialBatch::getInventory,BigDecimal.ZERO));
|
|
|
return list;
|
|
|
}
|
|
|
|