|
|
@ -33,10 +33,12 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
import java.math.BigDecimal; |
|
|
import java.math.BigDecimal; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.Date; |
|
|
import java.util.Date; |
|
|
|
|
|
import java.util.HashSet; |
|
|
import java.util.LinkedHashMap; |
|
|
import java.util.LinkedHashMap; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
import java.util.Objects; |
|
|
import java.util.Objects; |
|
|
|
|
|
import java.util.Set; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -212,7 +214,7 @@ public class HaiAnIssureNotifyServiceImpl implements HaiAnIssureNotifyService { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @author rqrq |
|
|
* @author rqrq |
|
|
* @Description 保存海安工单与物料(仅申请数据,删除后重建)并落到haian表 - rqrq |
|
|
|
|
|
|
|
|
* @Description 追加保存海安工单与物料:同一领料单下允许多工单共存,不清理既有父子行 - rqrq |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@ -241,10 +243,6 @@ public class HaiAnIssureNotifyServiceImpl implements HaiAnIssureNotifyService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 编辑场景统一删后重存:直接清理父子后按新数据重建 - rqrq |
|
|
|
|
|
haiAnIssureNotifyMapper.haiAnDeleteMaterialRowsByNotifyNo(data.getSite(), data.getNotifyNo()); |
|
|
|
|
|
haiAnIssureNotifyMapper.haiAnDeleteOrderRowsByNotifyNo(data.getSite(), data.getNotifyNo()); |
|
|
|
|
|
|
|
|
|
|
|
// 以工单三元组+subsite聚合,避免同单跨子站点明细被错误合并到同一父行 - rqrq |
|
|
// 以工单三元组+subsite聚合,避免同单跨子站点明细被错误合并到同一父行 - rqrq |
|
|
Map<HaiAnGroupKey, List<HaiAnShoporderAndMaterialDto>> groupedMap = materialRows.stream() |
|
|
Map<HaiAnGroupKey, List<HaiAnShoporderAndMaterialDto>> groupedMap = materialRows.stream() |
|
|
.collect(Collectors.groupingBy( |
|
|
.collect(Collectors.groupingBy( |
|
|
@ -253,11 +251,18 @@ public class HaiAnIssureNotifyServiceImpl implements HaiAnIssureNotifyService { |
|
|
Collectors.toList() |
|
|
Collectors.toList() |
|
|
)); |
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
// 工单重复校验:同一领料单下 orderNo+releaseNo+sequenceNo 不可重复 - rqrq |
|
|
|
|
|
validateDuplicateShopOrders(data.getSite(), data.getNotifyNo(), groupedMap.keySet()); |
|
|
|
|
|
|
|
|
|
|
|
// 从当前最大itemNo续号追加,保留领料单下已有工单数据 - rqrq |
|
|
BigDecimal nextItem = haiAnIssureNotifyMapper.haiAnGetNextItemForSOIssueNotifyOrderList(buildParentSeed(data)); |
|
|
BigDecimal nextItem = haiAnIssureNotifyMapper.haiAnGetNextItemForSOIssueNotifyOrderList(buildParentSeed(data)); |
|
|
if (nextItem == null) { |
|
|
|
|
|
|
|
|
if (nextItem == null || nextItem.compareTo(BigDecimal.ONE) < 0) { |
|
|
nextItem = BigDecimal.ONE; |
|
|
nextItem = BigDecimal.ONE; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<String> newItemNos = new ArrayList<>(); |
|
|
|
|
|
List<HaiAnSOIssueNotifyOrderMaterialList> allChildren = new ArrayList<>(); |
|
|
|
|
|
|
|
|
for (Map.Entry<HaiAnGroupKey, List<HaiAnShoporderAndMaterialDto>> entry : groupedMap.entrySet()) { |
|
|
for (Map.Entry<HaiAnGroupKey, List<HaiAnShoporderAndMaterialDto>> entry : groupedMap.entrySet()) { |
|
|
HaiAnGroupKey groupKey = entry.getKey(); |
|
|
HaiAnGroupKey groupKey = entry.getKey(); |
|
|
List<HaiAnShoporderAndMaterialDto> groupDtos = entry.getValue(); |
|
|
List<HaiAnShoporderAndMaterialDto> groupDtos = entry.getValue(); |
|
|
@ -271,10 +276,18 @@ public class HaiAnIssureNotifyServiceImpl implements HaiAnIssureNotifyService { |
|
|
fillOrderDefaultValues(parent); |
|
|
fillOrderDefaultValues(parent); |
|
|
haiAnIssureNotifyMapper.haiAnSaveSOIssueNotifyOrderList(parent); |
|
|
haiAnIssureNotifyMapper.haiAnSaveSOIssueNotifyOrderList(parent); |
|
|
|
|
|
|
|
|
List<HaiAnSOIssueNotifyOrderMaterialList> children = buildChildren(data.getNotifyNo(), data.getSite(), subSite, groupDtos, nextItem, parent.getOrderType()); |
|
|
|
|
|
haiAnIssureNotifyMapper.haiAnBatchSaveSOIssueNotifyOrderMaterialList(children); |
|
|
|
|
|
|
|
|
newItemNos.add(nextItem.toPlainString()); |
|
|
|
|
|
allChildren.addAll(buildChildren(data.getNotifyNo(), data.getSite(), subSite, groupDtos, nextItem, parent.getOrderType())); |
|
|
nextItem = nextItem.add(BigDecimal.ONE); |
|
|
nextItem = nextItem.add(BigDecimal.ONE); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 仅清理本次新增item下的子行后重插,不影响既有工单明细 - rqrq |
|
|
|
|
|
if (!newItemNos.isEmpty()) { |
|
|
|
|
|
haiAnIssureNotifyMapper.haiAnDeleteSOIssueNotifyOrderMaterialInList(data.getNotifyNo(), data.getSite(), newItemNos); |
|
|
|
|
|
} |
|
|
|
|
|
if (!allChildren.isEmpty()) { |
|
|
|
|
|
haiAnIssureNotifyMapper.haiAnBatchSaveSOIssueNotifyOrderMaterialList(allChildren); |
|
|
|
|
|
} |
|
|
return "200"; |
|
|
return "200"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -595,6 +608,51 @@ public class HaiAnIssureNotifyServiceImpl implements HaiAnIssureNotifyService { |
|
|
return seed; |
|
|
return seed; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @author rqrq |
|
|
|
|
|
* @Description 校验领料单内工单是否重复:按orderNo+releaseNo+sequenceNo判重,含库内已有与本次请求内部重复 - rqrq |
|
|
|
|
|
*/ |
|
|
|
|
|
private void validateDuplicateShopOrders(String site, String notifyNo, Set<HaiAnGroupKey> requestGroups) { |
|
|
|
|
|
HaiAnSOIssueNotifyHeaderData query = new HaiAnSOIssueNotifyHeaderData(); |
|
|
|
|
|
query.setSite(site); |
|
|
|
|
|
query.setNotifyNo(notifyNo); |
|
|
|
|
|
List<HaiAnSOIssueNotifyOrderListData> existingOrders = haiAnIssureNotifyMapper.haiAnGetNotifyNoDetail(query); |
|
|
|
|
|
|
|
|
|
|
|
Set<String> existingKeys = new HashSet<>(); |
|
|
|
|
|
if (existingOrders != null) { |
|
|
|
|
|
for (HaiAnSOIssueNotifyOrderListData order : existingOrders) { |
|
|
|
|
|
if (order == null) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
existingKeys.add(buildShopOrderUniqueKey(order.getSoorderNo(), order.getReleaseNo(), order.getSequenceNo())); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Set<String> requestKeys = new HashSet<>(); |
|
|
|
|
|
List<String> duplicateMsgs = new ArrayList<>(); |
|
|
|
|
|
for (HaiAnGroupKey groupKey : requestGroups) { |
|
|
|
|
|
if (groupKey == null) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
String key = buildShopOrderUniqueKey(groupKey.getOrderNo(), groupKey.getReleaseNo(), groupKey.getSequenceNo()); |
|
|
|
|
|
String display = groupKey.getOrderNo() + "/" + groupKey.getReleaseNo() + "/" + groupKey.getSequenceNo(); |
|
|
|
|
|
if (existingKeys.contains(key)) { |
|
|
|
|
|
duplicateMsgs.add(display + "(已存在于当前领料单)"); |
|
|
|
|
|
} else if (!requestKeys.add(key)) { |
|
|
|
|
|
duplicateMsgs.add(display + "(本次提交重复)"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (!duplicateMsgs.isEmpty()) { |
|
|
|
|
|
throw new RuntimeException("工单重复,无法保存:" + String.join(";", duplicateMsgs)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String buildShopOrderUniqueKey(String orderNo, String releaseNo, String sequenceNo) { |
|
|
|
|
|
return StringUtils.defaultString(orderNo) + "|" |
|
|
|
|
|
+ StringUtils.defaultString(releaseNo) + "|" |
|
|
|
|
|
+ StringUtils.defaultString(sequenceNo); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private void fillOrderDefaultValues(HaiAnSOIssueNotifyOrderList parentItem) { |
|
|
private void fillOrderDefaultValues(HaiAnSOIssueNotifyOrderList parentItem) { |
|
|
String normalizedOrderType = resolveHeaderOrderType(parentItem.getOrderType()); |
|
|
String normalizedOrderType = resolveHeaderOrderType(parentItem.getOrderType()); |
|
|
String productionArea; |
|
|
String productionArea; |
|
|
|