|
@ -1,6 +1,7 @@ |
|
|
package com.ruoyi.aftersales.service.impl; |
|
|
package com.ruoyi.aftersales.service.impl; |
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
|
|
|
import java.util.function.Function; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
import com.ruoyi.aftersales.domain.AfterSalesShippingDevice; |
|
|
import com.ruoyi.aftersales.domain.AfterSalesShippingDevice; |
|
@ -670,6 +671,9 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService |
|
|
aftersalesOutOrder.setOutOrderCode(sysSalesShippingInform.getOutOrderCode()); |
|
|
aftersalesOutOrder.setOutOrderCode(sysSalesShippingInform.getOutOrderCode()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//更新销售订单子表的数据
|
|
|
|
|
|
confirmCheckUpdateSalesOrderChild(shippingInformDetailList,sysSalesShippingInform); |
|
|
|
|
|
|
|
|
String salesOrderCode = oldsSalesShippingInform.getSalesOrderCode(); |
|
|
String salesOrderCode = oldsSalesShippingInform.getSalesOrderCode(); |
|
|
|
|
|
|
|
|
List<String> salesOrderCodes = new ArrayList<>(); |
|
|
List<String> salesOrderCodes = new ArrayList<>(); |
|
@ -714,29 +718,49 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置为全部验收
|
|
|
|
|
|
if (allWithoutCheckFlag == 1 && allWithCheckFlag == 1){ |
|
|
// 检查所有详情记录的验收数与已售后数对比,确定最终状态
|
|
|
|
|
|
boolean allChecked = false; |
|
|
|
|
|
boolean partiallyChecked = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int allHasCheckNum = shippingInformDetailList.stream().mapToInt(SysSalesShippingInformDetail::getHasCheckNum).sum(); |
|
|
|
|
|
int allHasReceivingNum = shippingInformDetailList.stream().mapToInt(SysSalesShippingInformDetail::getHasReceivingNum).sum(); |
|
|
|
|
|
|
|
|
|
|
|
if (allHasReceivingNum == allHasCheckNum) { |
|
|
|
|
|
allChecked = true; |
|
|
|
|
|
} else if (allHasCheckNum > 0 && allHasCheckNum < allHasReceivingNum) { |
|
|
|
|
|
partiallyChecked = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (allChecked) { |
|
|
|
|
|
// 已验收数等于已收货数
|
|
|
aftersalesOutOrder.setWarehouseOutStatus("12"); |
|
|
aftersalesOutOrder.setWarehouseOutStatus("12"); |
|
|
sysSalesShippingInform.setWarehouseOutStatus("12"); |
|
|
sysSalesShippingInform.setWarehouseOutStatus("12");//设置为全部验收
|
|
|
// sysSalesOrders.forEach(item->{
|
|
|
} else if (partiallyChecked) { |
|
|
// item.setDeliveryStatus("8");//全部验收
|
|
|
|
|
|
// });
|
|
|
|
|
|
}else { |
|
|
|
|
|
//设置为部分验收
|
|
|
//设置为部分验收
|
|
|
aftersalesOutOrder.setWarehouseOutStatus("11"); |
|
|
aftersalesOutOrder.setWarehouseOutStatus("11");//设置为部分验收
|
|
|
// sysSalesOrders.forEach(item->{
|
|
|
} else { |
|
|
// item.setDeliveryStatus("7");//部分验收
|
|
|
// 已验收数等于0
|
|
|
// });
|
|
|
aftersalesOutOrder.setWarehouseOutStatus("10");//设置为待验收
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// for (SysSalesOrder sysSalesOrder : sysSalesOrders) {
|
|
|
|
|
|
// sysSalesOrder.setUpdateTime(new Date());
|
|
|
|
|
|
// sysSalesOrder.setUpdateBy(loginName);
|
|
|
|
|
|
// int updateSysSalesOrderResult = sysSalesOrderMapper.updateSysSalesOrderBySalesOrderCode(sysSalesOrder);
|
|
|
// //设置为全部验收
|
|
|
// if (updateSysSalesOrderResult <= 0){
|
|
|
// if (allWithoutCheckFlag == 1 && allWithCheckFlag == 1){
|
|
|
// throw new BusinessException("更新销售订单数据失败");
|
|
|
// aftersalesOutOrder.setWarehouseOutStatus("12");
|
|
|
// }
|
|
|
// sysSalesShippingInform.setWarehouseOutStatus("12");
|
|
|
|
|
|
// }else {
|
|
|
|
|
|
// //设置为部分验收
|
|
|
|
|
|
// aftersalesOutOrder.setWarehouseOutStatus("11");
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sysSalesShippingInform.setSalesOrderCode(oldsSalesShippingInform.getSalesOrderCode()); |
|
|
sysSalesShippingInform.setSalesOrderCode(oldsSalesShippingInform.getSalesOrderCode()); |
|
|
int updateShippingInformResult = shippingInformMapper.updateSysSalesShippingInformByOutOrderCode(sysSalesShippingInform); |
|
|
int updateShippingInformResult = shippingInformMapper.updateSysSalesShippingInformByOutOrderCode(sysSalesShippingInform); |
|
|
if (updateShippingInformResult <= 0){ |
|
|
if (updateShippingInformResult <= 0){ |
|
@ -755,32 +779,19 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService |
|
|
return updateAftersalesOutOrderResult; |
|
|
return updateAftersalesOutOrderResult; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void confirmCheckUpdateSalesOrderChild(List<SysSalesShippingInformDetail> shippingInformDetailList, SysSalesShippingInform sysSalesShippingInform) { |
|
|
private Integer processWithoutShippingDeviceId(List<SysSalesShippingInformDetail> withoutShippingDeviceIdList,Integer allWithoutCheckFlag,SysSalesShippingInform sysSalesShippingInform) { |
|
|
// 根据 shipping_inform_detail_id 分组,并合计每组的 getThisReceivingNum
|
|
|
|
|
|
Map<Long, SysSalesShippingInformDetail> groupedDetails = shippingInformDetailList.stream() |
|
|
|
|
|
.collect(Collectors.toMap( |
|
|
String loginName = ShiroUtils.getLoginName(); |
|
|
SysSalesShippingInformDetail::getShippingInformDetailId, |
|
|
|
|
|
Function.identity(), |
|
|
for (SysSalesShippingInformDetail sysSalesShippingInformDetail : withoutShippingDeviceIdList) { |
|
|
(existing, replacement) -> { |
|
|
Long shippingInformDetailId = sysSalesShippingInformDetail.getShippingInformDetailId(); |
|
|
existing.setThisReceivingNum(existing.getThisReceivingNum() + replacement.getThisReceivingNum()); |
|
|
SysSalesShippingInformDetail tempShippingInformDetail = shippingInformDetailMapper.selectSysSalesShippingInformDetailById(shippingInformDetailId); |
|
|
return existing; |
|
|
|
|
|
}, |
|
|
if (tempShippingInformDetail.getHasCheckNum() == null || tempShippingInformDetail.getHasCheckNum() == 0) { |
|
|
LinkedHashMap::new // 保持插入顺序
|
|
|
sysSalesShippingInformDetail.setHasCheckNum(sysSalesShippingInformDetail.getThisCheckNum()); |
|
|
)); |
|
|
} else { |
|
|
for (SysSalesShippingInformDetail sysSalesShippingInformDetail : groupedDetails.values()) { |
|
|
sysSalesShippingInformDetail.setHasCheckNum(tempShippingInformDetail.getHasCheckNum() + sysSalesShippingInformDetail.getThisCheckNum()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (sysSalesShippingInformDetail.getHasCheckNum() > sysSalesShippingInformDetail.getHasReceivingNum()) { |
|
|
|
|
|
throw new BusinessException("已验收数和本次验收数之和不能大于已收货数"); |
|
|
|
|
|
} |
|
|
|
|
|
sysSalesShippingInformDetail.setThisCheckNum(null); |
|
|
|
|
|
sysSalesShippingInformDetail.setUpdateTime(new Date()); |
|
|
|
|
|
sysSalesShippingInformDetail.setUpdateBy(loginName); |
|
|
|
|
|
if (Objects.equals(tempShippingInformDetail.getThisShippingNum(), sysSalesShippingInformDetail.getHasCheckNum())){ |
|
|
|
|
|
allWithoutCheckFlag = 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 当前时间
|
|
|
// 当前时间
|
|
|
Date now = new Date(); |
|
|
Date now = new Date(); |
|
|
|
|
|
|
|
@ -818,7 +829,7 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
orderChild.setUpdateTime(new Date()); |
|
|
orderChild.setUpdateTime(new Date()); |
|
|
orderChild.setUpdateBy(loginName); |
|
|
orderChild.setUpdateBy(ShiroUtils.getLoginName()); |
|
|
|
|
|
|
|
|
// 检查数据库中是否有已有的 hasCheckNum,如果有则进行合计
|
|
|
// 检查数据库中是否有已有的 hasCheckNum,如果有则进行合计
|
|
|
Integer existingHasCheckNum = orderChild.getHasCheckNum(); |
|
|
Integer existingHasCheckNum = orderChild.getHasCheckNum(); |
|
@ -842,8 +853,34 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService |
|
|
shouldContinue = false; |
|
|
shouldContinue = false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Integer processWithoutShippingDeviceId(List<SysSalesShippingInformDetail> withoutShippingDeviceIdList,Integer allWithoutCheckFlag,SysSalesShippingInform sysSalesShippingInform) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String loginName = ShiroUtils.getLoginName(); |
|
|
|
|
|
|
|
|
|
|
|
for (SysSalesShippingInformDetail sysSalesShippingInformDetail : withoutShippingDeviceIdList) { |
|
|
|
|
|
Long shippingInformDetailId = sysSalesShippingInformDetail.getShippingInformDetailId(); |
|
|
|
|
|
SysSalesShippingInformDetail tempShippingInformDetail = shippingInformDetailMapper.selectSysSalesShippingInformDetailById(shippingInformDetailId); |
|
|
|
|
|
|
|
|
|
|
|
if (tempShippingInformDetail.getHasCheckNum() == null || tempShippingInformDetail.getHasCheckNum() == 0) { |
|
|
|
|
|
sysSalesShippingInformDetail.setHasCheckNum(sysSalesShippingInformDetail.getThisCheckNum()); |
|
|
|
|
|
} else { |
|
|
|
|
|
sysSalesShippingInformDetail.setHasCheckNum(tempShippingInformDetail.getHasCheckNum() + sysSalesShippingInformDetail.getThisCheckNum()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (sysSalesShippingInformDetail.getHasCheckNum() > sysSalesShippingInformDetail.getHasReceivingNum()) { |
|
|
|
|
|
throw new BusinessException("已验收数和本次验收数之和不能大于已收货数"); |
|
|
|
|
|
} |
|
|
|
|
|
sysSalesShippingInformDetail.setThisCheckNum(null); |
|
|
|
|
|
sysSalesShippingInformDetail.setUpdateTime(new Date()); |
|
|
|
|
|
sysSalesShippingInformDetail.setUpdateBy(loginName); |
|
|
|
|
|
if (Objects.equals(tempShippingInformDetail.getThisShippingNum(), sysSalesShippingInformDetail.getHasCheckNum())){ |
|
|
|
|
|
allWithoutCheckFlag = 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
int updateShippingInformDetailResult = shippingInformDetailMapper.updateSysSalesShippingInformDetail(sysSalesShippingInformDetail); |
|
|
int updateShippingInformDetailResult = shippingInformDetailMapper.updateSysSalesShippingInformDetail(sysSalesShippingInformDetail); |
|
|
if (updateShippingInformDetailResult <= 0) { |
|
|
if (updateShippingInformDetailResult <= 0) { |
|
@ -866,7 +903,21 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService |
|
|
throw new BusinessException("本次验收数量只能为0或1"); |
|
|
throw new BusinessException("本次验收数量只能为0或1"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for (SysSalesShippingInformDetail sysSalesShippingInformDetail : withShippingDeviceIdList) { |
|
|
|
|
|
|
|
|
// 根据 shipping_inform_detail_id 分组,并合计每组的 getThisReceivingNum
|
|
|
|
|
|
Map<Long, SysSalesShippingInformDetail> groupedDetails = withShippingDeviceIdList.stream() |
|
|
|
|
|
.collect(Collectors.toMap( |
|
|
|
|
|
SysSalesShippingInformDetail::getShippingInformDetailId, |
|
|
|
|
|
Function.identity(), |
|
|
|
|
|
(existing, replacement) -> { |
|
|
|
|
|
existing.setThisCheckNum(existing.getThisCheckNum() + replacement.getThisCheckNum()); |
|
|
|
|
|
return existing; |
|
|
|
|
|
}, |
|
|
|
|
|
LinkedHashMap::new // 保持插入顺序
|
|
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (SysSalesShippingInformDetail sysSalesShippingInformDetail : groupedDetails.values()) { |
|
|
String shippingDeviceId = sysSalesShippingInformDetail.getShippingDeviceId(); |
|
|
String shippingDeviceId = sysSalesShippingInformDetail.getShippingDeviceId(); |
|
|
AfterSalesShippingDevice afterSalesShippingDevice = afterSalesShippingDeviceMapper.selectAfterSalesShippingDeviceByShippingDeviceId(shippingDeviceId); |
|
|
AfterSalesShippingDevice afterSalesShippingDevice = afterSalesShippingDeviceMapper.selectAfterSalesShippingDeviceByShippingDeviceId(shippingDeviceId); |
|
|
if (sysSalesShippingInformDetail.getThisCheckNum() == 1){ |
|
|
if (sysSalesShippingInformDetail.getThisCheckNum() == 1){ |
|
@ -881,108 +932,23 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Integer allCheckNum = withShippingDeviceIdList.stream() |
|
|
// 只更新每个分组中的一个代表性记录
|
|
|
.mapToInt(SysSalesShippingInformDetail::getThisCheckNum) |
|
|
for (SysSalesShippingInformDetail sysSalesShippingInformDetail : groupedDetails.values()) { |
|
|
.sum(); |
|
|
Long shippingInformDetailId = sysSalesShippingInformDetail.getShippingInformDetailId(); |
|
|
|
|
|
SysSalesShippingInformDetail tempShippingInformDetail = shippingInformDetailMapper.selectSysSalesShippingInformDetailById(shippingInformDetailId); |
|
|
SysSalesShippingInformDetail sysSalesShippingInformDetail = withShippingDeviceIdList.get(0); |
|
|
|
|
|
Long shippingInformDetailId = sysSalesShippingInformDetail.getShippingInformDetailId(); |
|
|
|
|
|
SysSalesShippingInformDetail tempShippingInformDetail = shippingInformDetailMapper.selectSysSalesShippingInformDetailById(shippingInformDetailId); |
|
|
|
|
|
|
|
|
|
|
|
if (tempShippingInformDetail.getHasCheckNum() == null) { |
|
|
|
|
|
tempShippingInformDetail.setHasCheckNum(allCheckNum); |
|
|
|
|
|
} else { |
|
|
|
|
|
tempShippingInformDetail.setHasCheckNum(tempShippingInformDetail.getHasCheckNum() + allCheckNum); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (Objects.equals(tempShippingInformDetail.getThisShippingNum(), tempShippingInformDetail.getHasCheckNum())){ |
|
|
|
|
|
allWithCheckFlag = 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// //当前时间
|
|
|
|
|
|
// Date now = new Date();
|
|
|
|
|
|
// SysSalesShippingInform sysSalesShippingInform = shippingInformMapper.selectSysSalesShippingInformByCode(sysSalesShippingInformDetail.getOutOrderCode());
|
|
|
|
|
|
// String salesOrderCode = sysSalesShippingInform.getSalesOrderCode();
|
|
|
|
|
|
// String materialNo = sysSalesShippingInformDetail.getMaterialNo();
|
|
|
|
|
|
// List<String> salesOrderCodes = new ArrayList<>();
|
|
|
|
|
|
//
|
|
|
|
|
|
// if (StringUtils.isNotEmpty(salesOrderCode)){
|
|
|
|
|
|
// String[] splitSalesOrderCode = salesOrderCode.split(",");
|
|
|
|
|
|
// salesOrderCodes = Arrays.asList(splitSalesOrderCode);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// for (String orderCode : salesOrderCodes) {
|
|
|
|
|
|
// SysSalesOrderChild sysSalesOrderChild = new SysSalesOrderChild();
|
|
|
|
|
|
// sysSalesOrderChild.setMaterialCode(materialNo);
|
|
|
|
|
|
// sysSalesOrderChild.setQuoteId(orderCode);
|
|
|
|
|
|
// SysSalesOrderChild tempSalesOrderChild = salesOrderChildMapper.selectSalesOrderChildByCodeAndNo(sysSalesOrderChild);
|
|
|
|
|
|
// long time = tempSalesOrderChild.getDeliveryTime().getTime();
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 当前时间
|
|
|
|
|
|
Date now = new Date(); |
|
|
|
|
|
|
|
|
|
|
|
// 从数据库中查询销售出库单信息
|
|
|
|
|
|
sysSalesShippingInform = shippingInformMapper.selectSysSalesShippingInformByCode(sysSalesShippingInform.getOutOrderCode()); |
|
|
|
|
|
String salesOrderCode = sysSalesShippingInform.getSalesOrderCode(); |
|
|
|
|
|
String materialNo = sysSalesShippingInformDetail.getMaterialNo(); |
|
|
|
|
|
List<String> salesOrderCodes = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(salesOrderCode)) { |
|
|
|
|
|
salesOrderCodes = Arrays.asList(salesOrderCode.split(",")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 存储每个销售订单详情及其计划交付时间
|
|
|
|
|
|
List<SysSalesOrderChild> orderChildren = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
for (String orderCode : salesOrderCodes) { |
|
|
|
|
|
SysSalesOrderChild sysSalesOrderChild = new SysSalesOrderChild(); |
|
|
|
|
|
sysSalesOrderChild.setMaterialCode(materialNo); |
|
|
|
|
|
sysSalesOrderChild.setQuoteId(orderCode); |
|
|
|
|
|
SysSalesOrderChild tempSalesOrderChild = salesOrderChildMapper.selectSalesOrderChildByCodeAndNo(sysSalesOrderChild); |
|
|
|
|
|
if (tempSalesOrderChild != null) { |
|
|
|
|
|
orderChildren.add(tempSalesOrderChild); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 按照计划交付时间与当前时间的差值排序
|
|
|
|
|
|
orderChildren.sort(Comparator.comparing(o -> Math.abs(o.getDeliveryTime().getTime() - now.getTime()))); |
|
|
|
|
|
|
|
|
|
|
|
// 更新 HasCheckNum 数据
|
|
|
|
|
|
boolean shouldContinue = true; |
|
|
|
|
|
for (SysSalesOrderChild orderChild : orderChildren) { |
|
|
|
|
|
if (!shouldContinue) { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查数据库中是否有已有的 hasCheckNum,如果有则进行合计
|
|
|
|
|
|
Integer existingHasCheckNum = orderChild.getHasCheckNum(); |
|
|
|
|
|
Integer currentHasCheckNum = tempShippingInformDetail.getHasCheckNum(); |
|
|
|
|
|
|
|
|
|
|
|
if (existingHasCheckNum != null) { |
|
|
Integer checkNumToAdd = sysSalesShippingInformDetail.getThisCheckNum(); |
|
|
orderChild.setHasCheckNum(existingHasCheckNum + currentHasCheckNum); |
|
|
if (tempShippingInformDetail.getHasCheckNum() == null) { |
|
|
|
|
|
sysSalesShippingInformDetail.setHasCheckNum(checkNumToAdd); |
|
|
} else { |
|
|
} else { |
|
|
orderChild.setHasCheckNum(currentHasCheckNum); |
|
|
sysSalesShippingInformDetail.setHasCheckNum(tempShippingInformDetail.getHasCheckNum() + checkNumToAdd); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int updateSalesOrderChildResult = salesOrderChildMapper.updateSysSalesOrderChildByCodeAndQuoteId(orderChild); |
|
|
|
|
|
if (updateSalesOrderChildResult <= 0) { |
|
|
|
|
|
throw new RuntimeException("更新销售订单子表数据失败"); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 检查是否需要继续更新下一个
|
|
|
int updateShippingInformDetailResult = shippingInformDetailMapper.updateSysSalesShippingInformDetail(sysSalesShippingInformDetail); |
|
|
if (orderChild.getHasCheckNum().equals(orderChild.getMaterialNum())) { |
|
|
if (updateShippingInformDetailResult <= 0) { |
|
|
shouldContinue = true; |
|
|
throw new BusinessException("更新销售出货通知单详情数据失败"); |
|
|
} else { |
|
|
|
|
|
shouldContinue = false; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int updateShippingInformDetailResult = shippingInformDetailMapper.updateSysSalesShippingInformDetail(tempShippingInformDetail); |
|
|
|
|
|
if (updateShippingInformDetailResult <= 0) { |
|
|
|
|
|
throw new BusinessException("更新销售出货通知单详情数据失败"); |
|
|
|
|
|
} |
|
|
|
|
|
return allWithCheckFlag; |
|
|
return allWithCheckFlag; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|