|
|
@ -112,6 +112,7 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService |
|
|
|
@Autowired |
|
|
|
private AfterSalesShippingDeviceMapper shippingDeviceMapper; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 查询仓库出库单 |
|
|
|
* |
|
|
@ -338,63 +339,117 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService |
|
|
|
@Override |
|
|
|
public int updateSalesOutWarehouse(WarehouseOutOrder warehouseOutOrder) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String loginName = ShiroUtils.getLoginName(); |
|
|
|
warehouseOutOrder.setUpdateBy(loginName); |
|
|
|
warehouseOutOrder.setUpdateTime(DateUtils.getNowDate()); |
|
|
|
//设置为已出库
|
|
|
|
warehouseOutOrder.setWarehouseOutStatus("7"); |
|
|
|
warehouseOutOrder.setOutOrderTime(DateUtils.getNowDate());//出库时间
|
|
|
|
//设置为全部出库
|
|
|
|
warehouseOutOrder.setWarehouseOutStatus("6"); |
|
|
|
|
|
|
|
WarehouseOutOrder tempOutOrder = warehouseOutOrderMapper.selectWarehouseOutOrderByCode(warehouseOutOrder.getOutOrderCode()); |
|
|
|
|
|
|
|
String relatedOrderCode = tempOutOrder.getRelatedOrderCode(); |
|
|
|
|
|
|
|
// 处理 relatedOrderCode 为空或空白的情况
|
|
|
|
List<String> relatedOrderCodes = new ArrayList<>(); |
|
|
|
if (StringUtils.isNotBlank(relatedOrderCode)) { |
|
|
|
String[] splitRelatedOrderCode = relatedOrderCode.split(","); |
|
|
|
relatedOrderCodes = Arrays.asList(splitRelatedOrderCode); |
|
|
|
} |
|
|
|
List<SysSalesOrderChild> oldSalesOrderChildList = salesOrderChildMapper.selectBatchOrderChildListBySalesOrderCode(relatedOrderCodes); |
|
|
|
|
|
|
|
// 将旧数据按物料编号分组
|
|
|
|
Map<String, List<SysSalesOrderChild>> oldDataGroupedByMaterialCode = oldSalesOrderChildList.stream() |
|
|
|
.collect(Collectors.groupingBy(SysSalesOrderChild::getMaterialCode)); |
|
|
|
|
|
|
|
// 当前时间
|
|
|
|
Date now = new Date(); |
|
|
|
|
|
|
|
|
|
|
|
List<WarehouseOutOrderDetail> warehouseOutOrderDetailList = warehouseOutOrder.getWarehouseOutOrderDetailList(); |
|
|
|
|
|
|
|
//判断是否存在实际出库数为零的
|
|
|
|
boolean anyMatchActualOutOrderSum = warehouseOutOrderDetailList.stream().anyMatch(detail -> detail.getActualOutOrderSum() == null); |
|
|
|
if (anyMatchActualOutOrderSum){ |
|
|
|
throw new BusinessException("实际出库数不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isEmpty(warehouseOutOrderDetailList)){ |
|
|
|
log.warn("保存销售单-出库,物料列表信息为空:{}",warehouseOutOrder); |
|
|
|
} |
|
|
|
for (WarehouseOutOrderDetail warehouseOutOrderDetail : warehouseOutOrderDetailList) { |
|
|
|
SysSalesOrderChild sysSalesOrderChild = new SysSalesOrderChild(); |
|
|
|
sysSalesOrderChild.setQuoteId(warehouseOutOrder.getSalesOrderCode()); |
|
|
|
sysSalesOrderChild.setMaterialCode(warehouseOutOrderDetail.getMaterialNo()); |
|
|
|
sysSalesOrderChild.setOutBoundQuantity(warehouseOutOrderDetail.getActualOutOrderSum()); |
|
|
|
sysSalesOrderChild.setUpdateBy(loginName); |
|
|
|
sysSalesOrderChild.setUpdateTime(new Date()); |
|
|
|
int updateSalesOrderChildResult = salesOrderChildMapper.updateSysSalesOrderChildByCodeAndQuoteId(sysSalesOrderChild); |
|
|
|
if (updateSalesOrderChildResult <= 0){ |
|
|
|
throw new BusinessException("更新销售订单子表数据失败"); |
|
|
|
} |
|
|
|
SysSalesShippingInformDetail sysSalesShippingInformDetail = new SysSalesShippingInformDetail(); |
|
|
|
sysSalesShippingInformDetail.setHasOutOrderNum(warehouseOutOrderDetail.getActualOutOrderSum()); |
|
|
|
sysSalesShippingInformDetail.setUpdateBy(loginName); |
|
|
|
sysSalesShippingInformDetail.setUpdateTime(new Date()); |
|
|
|
sysSalesShippingInformDetail.setOutOrderCode(warehouseOutOrder.getOutOrderCode()); |
|
|
|
sysSalesShippingInformDetail.setMaterialNo(warehouseOutOrderDetail.getMaterialNo()); |
|
|
|
int updateShippingInformDetailResult = shippingInformDetailMapper.updateSysSalesShippingInformDetailByCodeAndNo(sysSalesShippingInformDetail); |
|
|
|
if (updateShippingInformDetailResult <= 0){ |
|
|
|
throw new BusinessException("更新销售出库详情数据失败"); |
|
|
|
// 执行现有的逻辑
|
|
|
|
Integer prepareOutOrderSum = warehouseOutOrderDetail.getPrepareOutOrderSum(); |
|
|
|
Integer actualOutOrderSum = warehouseOutOrderDetail.getActualOutOrderSum(); |
|
|
|
if (!Objects.equals(prepareOutOrderSum, actualOutOrderSum)) { |
|
|
|
throw new BusinessException("实际出库数必须等于准备出库数"); |
|
|
|
} |
|
|
|
warehouseOutOrderDetail.setUpdateBy(loginName); |
|
|
|
warehouseOutOrderDetail.setUpdateTime(new Date()); |
|
|
|
warehouseOutOrderDetail.setRemark(warehouseOutOrder.getRemark()); |
|
|
|
warehouseOutOrderDetail.setDeliveryDate(warehouseOutOrder.getDeliveryDate()); |
|
|
|
int updateWarehouseOutOrderDetailResult = outOrderDetailMapper.updateWarehouseOutOrderDetail(warehouseOutOrderDetail); |
|
|
|
if (updateWarehouseOutOrderDetailResult <= 0){ |
|
|
|
throw new BusinessException("更新出库单详情数据失败"); |
|
|
|
}else { |
|
|
|
// 更新库存查询记录,新增库存历史
|
|
|
|
String materialNo = warehouseOutOrderDetail.getMaterialNo(); |
|
|
|
WarehouseInventoryInquiry inventoryInquiry = inventoryInquiryMapper.selectWarehouseInventoryInquiryByMaterialNo(materialNo); |
|
|
|
if(inventoryInquiry == null){ |
|
|
|
throw new BusinessException("更新库存查询数据失败!该物料不存在库存查询数据"); |
|
|
|
}else{ |
|
|
|
int inquiryUpdateResult = updateWarehouseInventoryInquiry(warehouseOutOrderDetail,inventoryInquiry); |
|
|
|
if (inquiryUpdateResult <= 0){ |
|
|
|
throw new BusinessException("更新库存查询数据失败"); |
|
|
|
} |
|
|
|
WarehouseInventoryInquiryDetail inquiryDetail = createWarehouseInventoryInquiryDetail(warehouseOutOrderDetail); |
|
|
|
inquiryDetail.setInventoryHistoricalType("8");//销售出库
|
|
|
|
int insertInquiryResult = inventoryInquiryDetailMapper.insertWarehouseInventoryInquiryDetail(inquiryDetail); |
|
|
|
if (insertInquiryResult <= 0){ |
|
|
|
throw new BusinessException("新增库存历史数据失败"); |
|
|
|
String salesOrderCode = warehouseOutOrder.getSalesOrderCode(); |
|
|
|
if (StringUtils.isNotEmpty(salesOrderCode)) { |
|
|
|
SysSalesOrderChild sysSalesOrderChild = new SysSalesOrderChild(); |
|
|
|
sysSalesOrderChild.setQuoteId(salesOrderCode); |
|
|
|
sysSalesOrderChild.setMaterialCode(warehouseOutOrderDetail.getMaterialNo()); |
|
|
|
sysSalesOrderChild.setOutBoundQuantity(warehouseOutOrderDetail.getActualOutOrderSum()); |
|
|
|
sysSalesOrderChild.setUpdateBy(loginName); |
|
|
|
sysSalesOrderChild.setUpdateTime(new Date()); |
|
|
|
int updateSalesOrderChildResult = salesOrderChildMapper.updateSysSalesOrderChildByCodeAndQuoteId(sysSalesOrderChild); |
|
|
|
if (updateSalesOrderChildResult <= 0) { |
|
|
|
throw new BusinessException("更新销售订单子表数据失败"); |
|
|
|
} |
|
|
|
} else { |
|
|
|
String materialCode = warehouseOutOrderDetail.getMaterialNo(); |
|
|
|
// 获取旧数据中相同物料编号的数据
|
|
|
|
List<SysSalesOrderChild> oldChildren = oldDataGroupedByMaterialCode.get(materialCode); |
|
|
|
|
|
|
|
if (oldChildren != null && !oldChildren.isEmpty()) { |
|
|
|
// 按照 deliveryTime 接近当前时间排序
|
|
|
|
oldChildren.sort(Comparator.comparing(oldChild -> Math.abs(now.getTime() - oldChild.getDeliveryTime().getTime()))); |
|
|
|
|
|
|
|
for (SysSalesOrderChild oldChild : oldChildren) { |
|
|
|
Integer outBoundQuantity = oldChild.getOutBoundQuantity(); |
|
|
|
if (outBoundQuantity == null) { |
|
|
|
outBoundQuantity = 0; // 确保 outBoundQuantity 不为 null
|
|
|
|
} |
|
|
|
|
|
|
|
// 计算新的已出库数
|
|
|
|
outBoundQuantity += actualOutOrderSum; |
|
|
|
oldChild.setOutBoundQuantity(outBoundQuantity); |
|
|
|
oldChild.setUpdateTime(new Date()); |
|
|
|
oldChild.setUpdateBy(loginName); |
|
|
|
oldChild.setQuoteId(oldChild.getQuoteId()); |
|
|
|
|
|
|
|
// 更新数据库
|
|
|
|
int updateSysSalesOrderChildResult = salesOrderChildMapper.updateSysSalesOrderChild(oldChild); |
|
|
|
if (updateSysSalesOrderChildResult <= 0) { |
|
|
|
throw new BusinessException("更新销售订单子表数据失败"); |
|
|
|
} |
|
|
|
|
|
|
|
// 更新完成后,跳出循环
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// 无论 salesOrderCode 是否为空,都更新销售出库单数据、售后出库单数据和出库单数据
|
|
|
|
this.updateSalesAndAfterSalesData(warehouseOutOrderDetail, warehouseOutOrder, loginName); |
|
|
|
//// 更新库存查询记录,新增库存历史
|
|
|
|
// String materialNo = warehouseOutOrderDetail.getMaterialNo();
|
|
|
|
// WarehouseInventoryInquiry inventoryInquiry = inventoryInquiryMapper.selectWarehouseInventoryInquiryByMaterialNo(materialNo);
|
|
|
|
// if(inventoryInquiry == null){
|
|
|
|
// throw new BusinessException("更新库存查询数据失败!该物料不存在库存查询数据");
|
|
|
|
// }else{
|
|
|
|
// int inquiryUpdateResult = updateWarehouseInventoryInquiry(warehouseOutOrderDetail,inventoryInquiry);
|
|
|
|
// if (inquiryUpdateResult <= 0){
|
|
|
|
// throw new BusinessException("更新库存查询数据失败");
|
|
|
|
// }
|
|
|
|
// WarehouseInventoryInquiryDetail inquiryDetail = createWarehouseInventoryInquiryDetail(warehouseOutOrderDetail);
|
|
|
|
// inquiryDetail.setInventoryHistoricalType("8");//销售出库
|
|
|
|
// int insertInquiryResult = inventoryInquiryDetailMapper.insertWarehouseInventoryInquiryDetail(inquiryDetail);
|
|
|
|
// if (insertInquiryResult <= 0){
|
|
|
|
// throw new BusinessException("新增库存历史数据失败");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
} |
|
|
|
//更新销售出货通知列表
|
|
|
|
SysSalesShippingInform sysSalesShippingInform = new SysSalesShippingInform(); |
|
|
@ -409,6 +464,20 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService |
|
|
|
throw new BusinessException("更新销售出库单数据失败"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//更新售后维护设备出库单
|
|
|
|
|
|
|
|
AftersalesOutOrder aftersalesOutOrder = new AftersalesOutOrder(); |
|
|
|
aftersalesOutOrder.setOutOrderCode(warehouseOutOrder.getOutOrderCode()); |
|
|
|
aftersalesOutOrder.setWarehouseOutStatus("6");//全部出库
|
|
|
|
aftersalesOutOrder.setUpdateBy(loginName); |
|
|
|
aftersalesOutOrder.setUpdateTime(new Date()); |
|
|
|
aftersalesOutOrder.setOutOrderTime(new Date()); |
|
|
|
int updateAftersalesOutOrderResult = aftersalesOutOrderMapper.updateAftersalesOutOrderByOutOrderCode(aftersalesOutOrder); |
|
|
|
if (updateAftersalesOutOrderResult <= 0){ |
|
|
|
throw new BusinessException("更新售后维护设备出库单数据失败"); |
|
|
|
} |
|
|
|
|
|
|
|
int updateWarehouseOutOrderResult = warehouseOutOrderMapper.updateWarehouseOutOrder(warehouseOutOrder); |
|
|
|
|
|
|
|
if (updateWarehouseOutOrderResult <= 0){ |
|
|
@ -418,6 +487,46 @@ public class WarehouseOutOrderServiceImpl implements IWarehouseOutOrderService |
|
|
|
return updateWarehouseOutOrderResult; |
|
|
|
} |
|
|
|
|
|
|
|
// 无论 salesOrderCode 是否为空,都更新销售出库单数据、售后出库单数据和出库单数据
|
|
|
|
private void updateSalesAndAfterSalesData(WarehouseOutOrderDetail warehouseOutOrderDetail, WarehouseOutOrder warehouseOutOrder, String loginName) { |
|
|
|
Integer actualOutOrderSum = warehouseOutOrderDetail.getActualOutOrderSum(); |
|
|
|
|
|
|
|
// 更新销售出库详情数据
|
|
|
|
SysSalesShippingInformDetail sysSalesShippingInformDetail = new SysSalesShippingInformDetail(); |
|
|
|
sysSalesShippingInformDetail.setHasOutOrderNum(actualOutOrderSum); |
|
|
|
sysSalesShippingInformDetail.setUpdateBy(loginName); |
|
|
|
sysSalesShippingInformDetail.setUpdateTime(new Date()); |
|
|
|
sysSalesShippingInformDetail.setOutOrderCode(warehouseOutOrder.getOutOrderCode()); |
|
|
|
sysSalesShippingInformDetail.setMaterialNo(warehouseOutOrderDetail.getMaterialNo()); |
|
|
|
int updateShippingInformDetailResult = shippingInformDetailMapper.updateSysSalesShippingInformDetailByCodeAndNo(sysSalesShippingInformDetail); |
|
|
|
if (updateShippingInformDetailResult <= 0) { |
|
|
|
throw new BusinessException("更新销售出库详情数据失败"); |
|
|
|
} |
|
|
|
|
|
|
|
// 更新售后出库详情数据
|
|
|
|
AftersalesOutOrderDetail aftersalesOutOrderDetail = new AftersalesOutOrderDetail(); |
|
|
|
aftersalesOutOrderDetail.setHasOutOrderSum(actualOutOrderSum); |
|
|
|
aftersalesOutOrderDetail.setUpdateBy(loginName); |
|
|
|
aftersalesOutOrderDetail.setUpdateTime(new Date()); |
|
|
|
aftersalesOutOrderDetail.setOutOrderCode(warehouseOutOrder.getOutOrderCode()); |
|
|
|
aftersalesOutOrderDetail.setMaterialNo(warehouseOutOrderDetail.getMaterialNo()); |
|
|
|
int updateAftersalesOutOrderDetailResult = aftersalesOutOrderDetailMapper.updateAftersalesOutOrderDetailByCodeAndNo(aftersalesOutOrderDetail); |
|
|
|
if (updateAftersalesOutOrderDetailResult <= 0) { |
|
|
|
throw new BusinessException("更新售后出库详情数据失败"); |
|
|
|
} |
|
|
|
|
|
|
|
// 更新出库单详情数据
|
|
|
|
warehouseOutOrderDetail.setUpdateBy(loginName); |
|
|
|
warehouseOutOrderDetail.setUpdateTime(new Date()); |
|
|
|
warehouseOutOrderDetail.setRemark(warehouseOutOrder.getRemark()); |
|
|
|
warehouseOutOrderDetail.setHasOutOrderSum(actualOutOrderSum); |
|
|
|
int updateWarehouseOutOrderDetailResult = outOrderDetailMapper.updateWarehouseOutOrderDetail(warehouseOutOrderDetail); |
|
|
|
if (updateWarehouseOutOrderDetailResult <= 0) { |
|
|
|
throw new BusinessException("更新出库单详情数据失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 销售单-出库 物料信息关联设备子表信息 |
|
|
|