|
@@ -71,6 +71,7 @@ public class PurchaseReturnServiceImpl extends ServiceImpl<PurchaseReturnMapper,
|
|
|
public Page<PurchaseReturnVo> getPage(PurchaseReturnSelectDto dto) {
|
|
|
IWrapper<PurchaseReturn> wrapper = getWrapper();
|
|
|
wrapper.orderByDesc("pr", PurchaseReturn::getId);
|
|
|
+ wrapper.eq("pr", PurchaseReturn::getFlowStatus, dto.getFlowStatus());
|
|
|
|
|
|
// 查询采购退货数据
|
|
|
Page<PurchaseReturnVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
@@ -116,11 +117,11 @@ public class PurchaseReturnServiceImpl extends ServiceImpl<PurchaseReturnMapper,
|
|
|
Map<Long, BomSpec> bomSpecMap = bomSpecService.mapKEntity(BaseIdPo::getId, q -> q.in(BaseIdPo::getId, bomSpecIds));
|
|
|
purchaseReturnBomList.forEach(item -> {
|
|
|
item.setPurchaseReturnId(purchaseReturnDto.getId());
|
|
|
- BomSpec bomSpec = bomSpecMap.get(item.getPurchaseBomId());
|
|
|
+ BomSpec bomSpec = bomSpecMap.get(item.getBomSpecId());
|
|
|
if (bomSpec == null) {
|
|
|
throw new ServiceException("未知bom规格id!");
|
|
|
}
|
|
|
- Inventory inventory = inventoryMap.get(item.getPurchaseBomId());
|
|
|
+ Inventory inventory = inventoryMap.get(item.getBomSpecId());
|
|
|
if (inventory == null || inventory.getQuantity().compareTo(item.getReturnQuantity()) < 0) {
|
|
|
throw new ServiceException("退货失败,品名为:" + bomSpec.getName() + " 的bom库存不足,库存为:" +
|
|
|
(inventory == null ? BigDecimal.ZERO : inventory.getQuantity()));
|
|
@@ -133,13 +134,14 @@ public class PurchaseReturnServiceImpl extends ServiceImpl<PurchaseReturnMapper,
|
|
|
BigDecimal::add
|
|
|
));
|
|
|
|
|
|
- boolean result = inventoryService.lockPurchaseDefectiveStorage(map);
|
|
|
+ boolean result = inventoryService.lockStorage(map, WarehouseConstant.PURCHASE_DEFECTIVE);
|
|
|
if (!result) {
|
|
|
throw new ServiceException("库存不足,退货失败");
|
|
|
}
|
|
|
purchaseReturnBomService.saveBatch(purchaseReturnBomList);
|
|
|
}
|
|
|
|
|
|
+ @DSTransactional
|
|
|
@Override
|
|
|
public void edit(PurchaseReturnDto purchaseReturnDto) {
|
|
|
// 状态为未发起时, 流程重新发起
|
|
@@ -197,13 +199,13 @@ public class PurchaseReturnServiceImpl extends ServiceImpl<PurchaseReturnMapper,
|
|
|
// 对原数据有修改时,更新数据
|
|
|
if (!lockBomMap.isEmpty() || !unlockBomMap.isEmpty()) {
|
|
|
if (!lockBomMap.isEmpty()) {
|
|
|
- boolean result = inventoryService.lockPurchaseDefectiveStorage(lockBomMap);
|
|
|
+ boolean result = inventoryService.lockStorage(lockBomMap, WarehouseConstant.PURCHASE_DEFECTIVE);
|
|
|
if (!result) {
|
|
|
throw new ServiceException("库存不足,新增退货失败");
|
|
|
}
|
|
|
}
|
|
|
if (!unlockBomMap.isEmpty()) {
|
|
|
- inventoryService.unlockPurchaseDefectiveStorage(unlockBomMap);
|
|
|
+ inventoryService.unlockStorage(unlockBomMap, WarehouseConstant.PURCHASE_DEFECTIVE);
|
|
|
}
|
|
|
purchaseReturnBomService.editLinked(newPurchaseReturnBomList, PurchaseReturnBom::getPurchaseReturnId, purchaseReturnDto.getId());
|
|
|
}
|
|
@@ -215,7 +217,7 @@ public class PurchaseReturnServiceImpl extends ServiceImpl<PurchaseReturnMapper,
|
|
|
PurchaseReturnDetailVo result = BeanUtil.toBean(purchaseReturn, PurchaseReturnDetailVo.class);
|
|
|
// 查询bom列表
|
|
|
List<PurchaseReturnBomVo> purchaseReturnBomList = purchaseReturnBomService.selectListByPurchaseReturnId(purchaseReturn.getId());
|
|
|
- result.setReturnBomList(purchaseReturnBomList);
|
|
|
+ result.setPurchaseReturnBomList(purchaseReturnBomList);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -242,7 +244,7 @@ public class PurchaseReturnServiceImpl extends ServiceImpl<PurchaseReturnMapper,
|
|
|
vo.setBomSpecName(bomSpec.getName());
|
|
|
vo.setUnitPrice(item.getUnitPrice());
|
|
|
vo.setPurchaseQuantity(item.getPurchaseQuantity());
|
|
|
- vo.setArrivalQuantity(item.getArrivalQuantity());
|
|
|
+ vo.setCanReturnQuantity(item.getArrivalQuantity().subtract(item.getReturnQuantity()));
|
|
|
vo.setFinishReturnQuantity(item.getReturnQuantity());
|
|
|
return vo;
|
|
|
}).collect(Collectors.toList());
|
|
@@ -273,5 +275,15 @@ public class PurchaseReturnServiceImpl extends ServiceImpl<PurchaseReturnMapper,
|
|
|
lockPurchaseDefective.setLockStorage(StatusConstant.YES);
|
|
|
lockPurchaseDefective.setInOutStorageBomList(inOutStorageBomList);
|
|
|
inOutStorageService.add(lockPurchaseDefective);
|
|
|
+ // 更新退货数量
|
|
|
+ Map<Long, BigDecimal> returnQuantityMap = purchaseReturnBomList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ PurchaseReturnBom::getPurchaseBomId,
|
|
|
+ PurchaseReturnBom::getReturnQuantity,
|
|
|
+ (v1, v2) -> v2)
|
|
|
+ );
|
|
|
+ List<PurchaseBom> list = purchaseBomService.list(q -> q.in(BaseIdPo::getId, returnQuantityMap.keySet()));
|
|
|
+ list.forEach(item -> item.setReturnQuantity(item.getReturnQuantity().add(returnQuantityMap.get(item.getId()))));
|
|
|
+ purchaseBomService.updateBatchById(list);
|
|
|
}
|
|
|
}
|