|
|
@ -31,10 +31,7 @@ import com.ruoyi.process.general.service.IProcessService; |
|
|
|
import com.ruoyi.process.todoitem.mapper.BizTodoItemMapper; |
|
|
|
import com.ruoyi.purchase.domain.*; |
|
|
|
import com.ruoyi.purchase.domain.Vo.*; |
|
|
|
import com.ruoyi.purchase.mapper.PurchaseOrderChildMapper; |
|
|
|
import com.ruoyi.purchase.mapper.PurchaseOrderMapper; |
|
|
|
import com.ruoyi.purchase.mapper.PurchasePlanChildMapper; |
|
|
|
import com.ruoyi.purchase.mapper.PurchasePlanMapper; |
|
|
|
import com.ruoyi.purchase.mapper.*; |
|
|
|
import com.ruoyi.purchase.service.IPurchaseOrderService; |
|
|
|
import com.ruoyi.system.domain.SysAttachFile; |
|
|
|
import com.ruoyi.system.domain.SysCompanyInformation; |
|
|
@ -97,12 +94,23 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService |
|
|
|
@Autowired |
|
|
|
private PurchasePlanMapper purchasePlanMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private PurchaseStorageMapper purchaseStorageMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private PurchaseStorageChildMapper purchaseStorageChildMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RedisCache redisCache; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WarehouseStorageOrderMapper warehouseStorageOrderMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WarehouseStorageOrderDetailMapper warehouseStorageOrderDetailMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WarehouseStorageOrderDetailMapper storageOrderDetailMapper; |
|
|
|
|
|
|
@ -1156,6 +1164,243 @@ public class PurchaseOrderServiceImpl implements IPurchaseOrderService |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 创建采购入库单 |
|
|
|
* */ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public int addPurchaseStorageSave(PurchaseOrder purchaseOrder) { |
|
|
|
Long purchaseOrderId = purchaseOrder.getPurchaseOrderId(); |
|
|
|
|
|
|
|
List<PurchaseOrderChild> purchaseOrderChildList = purchaseOrder.getPurchaseOrderChildList(); |
|
|
|
|
|
|
|
|
|
|
|
//过滤掉通知已到货数为空的数据
|
|
|
|
purchaseOrderChildList = purchaseOrderChildList.stream().filter(item -> item.getNotifyArriveNum() != null).collect(Collectors.toList()); |
|
|
|
|
|
|
|
boolean allNotifyArriveNum = purchaseOrderChildList.stream().allMatch(item -> item.getNotifyArriveNum() == 0); |
|
|
|
if (allNotifyArriveNum){ |
|
|
|
throw new BusinessException("通知到货数不能都为0"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//过滤掉通知到货数为0的数据
|
|
|
|
List<PurchaseOrderChild> filterPurchaseOrderChildList = purchaseOrderChildList.stream().filter(item -> item.getNotifyArriveNum() != 0).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
purchaseOrder = purchaseOrderMapper.selectPurchaseOrderById(purchaseOrderId); |
|
|
|
|
|
|
|
|
|
|
|
String warehouseStorageCode = redisCache.generateBillNo("RK"); |
|
|
|
|
|
|
|
|
|
|
|
//生成采购入库单子表
|
|
|
|
buildPurchaseStorageChild(purchaseOrder, warehouseStorageCode,filterPurchaseOrderChildList); |
|
|
|
|
|
|
|
//生成采购入库单主表
|
|
|
|
buildPurchaseStorage(purchaseOrder, filterPurchaseOrderChildList, warehouseStorageCode); |
|
|
|
|
|
|
|
//生成仓库入库单
|
|
|
|
buildWarehouseStorage(purchaseOrder, warehouseStorageCode,filterPurchaseOrderChildList); |
|
|
|
|
|
|
|
//生成仓库入库单子表
|
|
|
|
buildWarehouseChild(purchaseOrder, warehouseStorageCode,filterPurchaseOrderChildList); |
|
|
|
|
|
|
|
//更新采购订单子表
|
|
|
|
updatePurchaseOrderChildData(purchaseOrder, filterPurchaseOrderChildList); |
|
|
|
|
|
|
|
int allNotifyArrivedNum = filterPurchaseOrderChildList.stream().mapToInt(PurchaseOrderChild::getNotifyArriveNum).sum(); |
|
|
|
int allNotifyHasArrivedNum = filterPurchaseOrderChildList.stream().mapToInt(PurchaseOrderChild::getNotifyHasArrivedNum).sum(); |
|
|
|
|
|
|
|
if (allNotifyHasArrivedNum == 0){ |
|
|
|
purchaseOrder.setNotifyHasArrivedSum(allNotifyArrivedNum); |
|
|
|
}else { |
|
|
|
purchaseOrder.setNotifyHasArrivedSum(allNotifyHasArrivedNum + allNotifyArrivedNum); |
|
|
|
} |
|
|
|
|
|
|
|
if (purchaseOrder.getNotifyHasArrivedSum().equals(purchaseOrder.getActualPurchaseSum())){ |
|
|
|
purchaseOrder.setWarehouseStorageStatus("4"); |
|
|
|
}if (purchaseOrder.getNotifyHasArrivedSum() < purchaseOrder.getActualPurchaseSum()){ |
|
|
|
purchaseOrder.setWarehouseStorageStatus("3"); |
|
|
|
} |
|
|
|
|
|
|
|
return purchaseOrderMapper.updatePurchaseOrder(purchaseOrder); |
|
|
|
} |
|
|
|
|
|
|
|
//采购入库更新采购订单子表的数据
|
|
|
|
private void updatePurchaseOrderChildData(PurchaseOrder purchaseOrder, List<PurchaseOrderChild> filterPurchaseOrderChildList) { |
|
|
|
|
|
|
|
for (PurchaseOrderChild purchaseOrderChild : filterPurchaseOrderChildList) { |
|
|
|
if (purchaseOrderChild.getNotifyHasArrivedNum() == 0 || purchaseOrderChild.getNotifyHasArrivedNum() == null){ |
|
|
|
purchaseOrderChild.setNotifyHasArrivedNum(purchaseOrderChild.getNotifyArriveNum()); |
|
|
|
}else { |
|
|
|
purchaseOrderChild.setNotifyHasArrivedNum(purchaseOrderChild.getNotifyHasArrivedNum() + purchaseOrderChild.getNotifyArriveNum()); |
|
|
|
} |
|
|
|
int updatePurchaseOrderChild = purchaseOrderChildMapper.updatePurchaseOrderChild(purchaseOrderChild); |
|
|
|
if (updatePurchaseOrderChild <= 0){ |
|
|
|
throw new BusinessException("更新采购订单子表数据失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//采购入库生成采购入库单主表
|
|
|
|
private void buildPurchaseStorage(PurchaseOrder purchaseOrder, List<PurchaseOrderChild> filterPurchaseOrderChildList, String warehouseStorageCode) { |
|
|
|
PurchaseStorage purchaseStorage = new PurchaseStorage(); |
|
|
|
|
|
|
|
PurchaseOrderChild purchaseOrderChild = filterPurchaseOrderChildList.get(0); |
|
|
|
purchaseStorage.setWarehouseStorageStatus("0"); |
|
|
|
purchaseStorage.setWarehouseStorageType("5"); |
|
|
|
purchaseStorage.setWarehouseDeptType(purchaseOrderChild.getWarehouseDept()); |
|
|
|
purchaseStorage.setWarehouseQualityStatus("0"); |
|
|
|
purchaseStorage.setWarehouseOrderType("0"); |
|
|
|
|
|
|
|
|
|
|
|
purchaseStorage.setArrivedTime(purchaseOrder.getArrivedTime()); |
|
|
|
purchaseStorage.setRelatedOrderCode(purchaseOrder.getPurchaseOrderCode()); |
|
|
|
purchaseStorage.setSupplierCode(purchaseOrder.getSupplierCode()); |
|
|
|
purchaseStorage.setSupplierName(purchaseOrder.getSupplierName()); |
|
|
|
purchaseStorage.setWarehouseStorageCode(warehouseStorageCode); |
|
|
|
|
|
|
|
int allNotifyArrivedNum = filterPurchaseOrderChildList.stream().mapToInt(PurchaseOrderChild::getNotifyArriveNum).sum(); |
|
|
|
int allNotifyHasArrivedNum = filterPurchaseOrderChildList.stream().mapToInt(PurchaseOrderChild::getNotifyHasArrivedNum).sum(); |
|
|
|
|
|
|
|
if (allNotifyHasArrivedNum == 0){ |
|
|
|
purchaseStorage.setNotifyArrivedSum(allNotifyArrivedNum); |
|
|
|
}else { |
|
|
|
purchaseStorage.setNotifyArrivedSum(allNotifyHasArrivedNum + allNotifyArrivedNum); |
|
|
|
} |
|
|
|
purchaseStorage.setActualArrivedSum(allNotifyArrivedNum); |
|
|
|
int insertResult = purchaseStorageMapper.insertPurchaseStorage(purchaseStorage); |
|
|
|
if (insertResult <= 0){ |
|
|
|
throw new BusinessException("生成采购入库单数据失败"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//采购入库生成仓库入库主表数据
|
|
|
|
private void buildWarehouseStorage(PurchaseOrder purchaseOrder, String warehouseStorageCode, List<PurchaseOrderChild> filterPurchaseOrderChildList) { |
|
|
|
|
|
|
|
PurchaseOrderChild purchaseOrderChild = filterPurchaseOrderChildList.get(0); |
|
|
|
WarehouseStorageOrder warehouseStorageOrder = new WarehouseStorageOrder(); |
|
|
|
warehouseStorageOrder.setWarehouseStorageCode(warehouseStorageCode); |
|
|
|
warehouseStorageOrder.setWarehouseStorageStatus("0"); |
|
|
|
warehouseStorageOrder.setWarehouseStorageType("5"); |
|
|
|
warehouseStorageOrder.setWarehouseDeptType(purchaseOrderChild.getWarehouseDept()); |
|
|
|
warehouseStorageOrder.setWarehouseQualityStatus("0"); |
|
|
|
warehouseStorageOrder.setWarehouseOrderType("0"); |
|
|
|
int allNotifyArrivedNum = filterPurchaseOrderChildList.stream().mapToInt(PurchaseOrderChild::getNotifyArriveNum).sum(); |
|
|
|
int allNotifyHasArrivedNum = filterPurchaseOrderChildList.stream().mapToInt(PurchaseOrderChild::getNotifyHasArrivedNum).sum(); |
|
|
|
if (allNotifyHasArrivedNum == 0){ |
|
|
|
warehouseStorageOrder.setNotifyArrivedNum(allNotifyArrivedNum); |
|
|
|
}else { |
|
|
|
warehouseStorageOrder.setNotifyArrivedNum(allNotifyHasArrivedNum + allNotifyArrivedNum); |
|
|
|
} |
|
|
|
warehouseStorageOrder.setActualArrivedNum(allNotifyArrivedNum); |
|
|
|
warehouseStorageOrder.setArrivedTime(purchaseOrder.getArrivedTime()); |
|
|
|
warehouseStorageOrder.setRelatedOrderCode(purchaseOrder.getPurchaseOrderCode()); |
|
|
|
warehouseStorageOrder.setCreateTime(new Date()); |
|
|
|
warehouseStorageOrder.setCreateBy(ShiroUtils.getLoginName()); |
|
|
|
|
|
|
|
int insertResult = warehouseStorageOrderMapper.insertWarehouseStorageOrder(warehouseStorageOrder); |
|
|
|
if (insertResult <= 0){ |
|
|
|
throw new BusinessException("生成仓库入库单数据失败"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//采购入库生成仓库入库子表数据
|
|
|
|
private void buildWarehouseChild(PurchaseOrder purchaseOrder, String warehouseStorageCode, List<PurchaseOrderChild> filterPurchaseOrderChildList) { |
|
|
|
|
|
|
|
String purchaseOrderCode = purchaseOrder.getPurchaseOrderCode(); |
|
|
|
List<WarehouseStorageOrderDetail> warehouseStorageOrderDetailChildren = new ArrayList<>(); |
|
|
|
for (PurchaseOrderChild purchaseOrderChild : filterPurchaseOrderChildList) { |
|
|
|
WarehouseStorageOrderDetail warehouseStorageOrderDetail = new WarehouseStorageOrderDetail(); |
|
|
|
warehouseStorageOrderDetail.setWarehouseStorageCode(warehouseStorageCode); |
|
|
|
warehouseStorageOrderDetail.setRelatedOrderCode(purchaseOrderCode); |
|
|
|
warehouseStorageOrderDetail.setMaterialNo(purchaseOrderChild.getMaterialNo()); |
|
|
|
warehouseStorageOrderDetail.setMaterialName(purchaseOrderChild.getMaterialName()); |
|
|
|
warehouseStorageOrderDetail.setMaterialPhotourl(purchaseOrderChild.getMaterialPhotourl()); |
|
|
|
warehouseStorageOrderDetail.setMaterialBrand(purchaseOrderChild.getMaterialBrand()); |
|
|
|
warehouseStorageOrderDetail.setMaterialDescribe(purchaseOrderChild.getMaterialDescribe()); |
|
|
|
warehouseStorageOrderDetail.setMaterialModel(purchaseOrderChild.getMaterialModel()); |
|
|
|
warehouseStorageOrderDetail.setMaterialProcessMethod(purchaseOrderChild.getMaterialProcessMethod()); |
|
|
|
warehouseStorageOrderDetail.setMaterialUnit(purchaseOrderChild.getMaterialUnit()); |
|
|
|
warehouseStorageOrderDetail.setMaterialPhotourl(purchaseOrderChild.getMaterialPhotourl()); |
|
|
|
warehouseStorageOrderDetail.setMaterialType(purchaseOrderChild.getMaterialType()); |
|
|
|
warehouseStorageOrderDetail.setMaterialDeptType(purchaseOrderChild.getWarehouseDept()); |
|
|
|
warehouseStorageOrderDetail.setArrivedTime(purchaseOrderChild.getPlanDeliveryTime()); |
|
|
|
warehouseStorageOrderDetail.setCreateTime(new Date()); |
|
|
|
warehouseStorageOrderDetail.setCreateBy(ShiroUtils.getLoginName()); |
|
|
|
Integer notifyArriveNum = purchaseOrderChild.getNotifyArriveNum(); |
|
|
|
Integer notifyHasArrivedNum = purchaseOrderChild.getNotifyHasArrivedNum(); |
|
|
|
|
|
|
|
//通知到货数<= 实际采购数
|
|
|
|
if (notifyArriveNum > purchaseOrderChild.getActualPurchaseNum()){ |
|
|
|
throw new BusinessException("通知到货数不能大于实际采购数"); |
|
|
|
} |
|
|
|
|
|
|
|
if (notifyHasArrivedNum == null){ |
|
|
|
warehouseStorageOrderDetail.setNotifyHasArrivedNum(notifyArriveNum); |
|
|
|
}else { |
|
|
|
warehouseStorageOrderDetail.setNotifyHasArrivedNum(notifyHasArrivedNum + notifyArriveNum); |
|
|
|
} |
|
|
|
warehouseStorageOrderDetail.setActualArriveNum(notifyArriveNum); |
|
|
|
warehouseStorageOrderDetailChildren.add(warehouseStorageOrderDetail); |
|
|
|
} |
|
|
|
int result = warehouseStorageOrderDetailMapper.insertBatchWarehouseStorageOrderDetail(warehouseStorageOrderDetailChildren); |
|
|
|
if (result <= 0){ |
|
|
|
throw new RuntimeException("生成仓库入库子表数据失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//采购入库生成采购入库子表数据
|
|
|
|
private void buildPurchaseStorageChild(PurchaseOrder purchaseOrder, String warehouseStorageCode, List<PurchaseOrderChild> purchaseOrderChildList) { |
|
|
|
String purchaseOrderCode = purchaseOrder.getPurchaseOrderCode(); |
|
|
|
List<PurchaseStorageChild> purchaseStorageChildren = new ArrayList<>(); |
|
|
|
for (PurchaseOrderChild purchaseOrderChild : purchaseOrderChildList) { |
|
|
|
PurchaseStorageChild purchaseStorageChild = new PurchaseStorageChild(); |
|
|
|
purchaseStorageChild.setWarehouseStorageCode(warehouseStorageCode); |
|
|
|
purchaseStorageChild.setRelatedOrderCode(purchaseOrderCode); |
|
|
|
purchaseStorageChild.setMaterialNo(purchaseOrderChild.getMaterialNo()); |
|
|
|
purchaseStorageChild.setMaterialName(purchaseOrderChild.getMaterialName()); |
|
|
|
purchaseStorageChild.setMaterialBrand(purchaseOrderChild.getMaterialBrand()); |
|
|
|
purchaseStorageChild.setMaterialDescribe(purchaseOrderChild.getMaterialDescribe()); |
|
|
|
purchaseStorageChild.setMaterialPhotourl(purchaseOrderChild.getMaterialPhotourl()); |
|
|
|
purchaseStorageChild.setMaterialModel(purchaseOrderChild.getMaterialModel()); |
|
|
|
purchaseStorageChild.setMaterialProcessMethod(purchaseOrderChild.getMaterialProcessMethod()); |
|
|
|
purchaseStorageChild.setMaterialUnit(purchaseOrderChild.getMaterialUnit()); |
|
|
|
purchaseStorageChild.setMaterialPhotourl(purchaseOrderChild.getMaterialPhotourl()); |
|
|
|
purchaseStorageChild.setMaterialType(purchaseOrderChild.getMaterialType()); |
|
|
|
purchaseStorageChild.setMaterialDeptType(purchaseOrderChild.getWarehouseDept()); |
|
|
|
purchaseStorageChild.setArrivedTime(purchaseOrderChild.getPlanDeliveryTime()); |
|
|
|
purchaseStorageChild.setCreateTime(new Date()); |
|
|
|
purchaseStorageChild.setCreateBy(ShiroUtils.getLoginName()); |
|
|
|
Integer notifyArriveNum = purchaseOrderChild.getNotifyArriveNum(); |
|
|
|
Integer notifyHasArrivedNum = purchaseOrderChild.getNotifyHasArrivedNum(); |
|
|
|
|
|
|
|
//通知到货数<= 实际采购数
|
|
|
|
if (notifyArriveNum > purchaseOrderChild.getActualPurchaseNum()){ |
|
|
|
throw new BusinessException("通知到货数不能大于实际采购数"); |
|
|
|
} |
|
|
|
|
|
|
|
if (notifyHasArrivedNum == null){ |
|
|
|
purchaseStorageChild.setNotifyHasArrivedNum(notifyArriveNum); |
|
|
|
}else { |
|
|
|
purchaseStorageChild.setNotifyHasArrivedNum(notifyHasArrivedNum + notifyArriveNum); |
|
|
|
} |
|
|
|
purchaseStorageChild.setActualArriveNum(notifyArriveNum); |
|
|
|
purchaseStorageChildren.add(purchaseStorageChild); |
|
|
|
} |
|
|
|
int result = purchaseStorageChildMapper.insertBatchPurchaseStorageChild(purchaseStorageChildren); |
|
|
|
if (result <= 0){ |
|
|
|
throw new RuntimeException("生成采购入库子表数据失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 启动流程实例 |
|
|
|
* */ |
|
|
|