fix: 子卷包装关系ui调整
This commit is contained in:
@@ -41,4 +41,18 @@ public interface SubPackageRelationMapper extends BaseMapperX<SubPackageRelation
|
||||
.eq(SubPackageRelationDO::getBoxType, boxType));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据子卷号集合查询已存在的包装关系
|
||||
*/
|
||||
default List<SubPackageRelationDO> selectListByContainerNames(Collection<String> containerNames) {
|
||||
return selectList(SubPackageRelationDO::getContainerName, containerNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据木箱唯一码集合查询包装关系
|
||||
*/
|
||||
default List<SubPackageRelationDO> selectListByPackageBoxSns(Collection<String> packageBoxSns) {
|
||||
return selectList(SubPackageRelationDO::getPackageBoxSn, packageBoxSns);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,8 +36,12 @@ public class SubPackageRelationServiceImpl implements SubPackageRelationService
|
||||
private static final String REQUIRED_FIELD_MISSING = "REQUIRED_FIELD_MISSING";
|
||||
/** 前端行标识重复错误码 */
|
||||
private static final String DUPLICATE_CLIENT_KEY = "DUPLICATE_CLIENT_KEY";
|
||||
/** 子卷号重复错误码 */
|
||||
private static final String DUPLICATE_CONTAINER_NAME = "DUPLICATE_CONTAINER_NAME";
|
||||
/** 木箱类型不存在错误码 */
|
||||
private static final String BOX_TYPE_NOT_FOUND = "BOX_TYPE_NOT_FOUND";
|
||||
/** 木箱已绑定其他类型错误码 */
|
||||
private static final String BOX_TYPE_MISMATCH = "BOX_TYPE_MISMATCH";
|
||||
/** 木箱容量超限错误码 */
|
||||
private static final String BOX_CAPACITY_EXCEEDED = "BOX_CAPACITY_EXCEEDED";
|
||||
/** 分组保存失败错误码 */
|
||||
@@ -63,10 +67,14 @@ public class SubPackageRelationServiceImpl implements SubPackageRelationService
|
||||
List<SubPackageRelationBatchCreateRespVO.Failure> failures = new ArrayList<>();
|
||||
List<BatchItemContext> validItems = new ArrayList<>();
|
||||
Map<String, Integer> clientKeyCounts = new HashMap<>();
|
||||
Map<String, Integer> containerNameCounts = new HashMap<>();
|
||||
for (SubPackageRelationBatchCreateItemReqVO item : reqVO.getItems()) {
|
||||
if (item != null && StringUtils.hasText(item.getClientKey())) {
|
||||
clientKeyCounts.merge(item.getClientKey(), 1, Integer::sum);
|
||||
}
|
||||
if (item != null && StringUtils.hasText(item.getContainerName())) {
|
||||
containerNameCounts.merge(item.getContainerName().trim(), 1, Integer::sum);
|
||||
}
|
||||
}
|
||||
for (int index = 0; index < reqVO.getItems().size(); index++) {
|
||||
SubPackageRelationBatchCreateItemReqVO item = reqVO.getItems().get(index);
|
||||
@@ -85,6 +93,12 @@ public class SubPackageRelationServiceImpl implements SubPackageRelationService
|
||||
"前端行标识 clientKey 重复"));
|
||||
continue;
|
||||
}
|
||||
if (StringUtils.hasText(item.getContainerName())
|
||||
&& containerNameCounts.get(item.getContainerName().trim()) > 1) {
|
||||
failures.add(buildFailure(item.getClientKey(), rowIndex, DUPLICATE_CONTAINER_NAME,
|
||||
"子卷号重复:" + item.getContainerName().trim()));
|
||||
continue;
|
||||
}
|
||||
List<String> missingFields = new ArrayList<>();
|
||||
if (!StringUtils.hasText(item.getPackageBoxSn())) {
|
||||
missingFields.add("packageBoxSn");
|
||||
@@ -119,6 +133,34 @@ public class SubPackageRelationServiceImpl implements SubPackageRelationService
|
||||
.build();
|
||||
}
|
||||
|
||||
Set<String> containerNames = validItems.stream()
|
||||
.map(context -> context.item().getContainerName().trim())
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
Set<String> existingContainerNames = subPackageRelationMapper.selectListByContainerNames(containerNames)
|
||||
.stream()
|
||||
.map(SubPackageRelationDO::getContainerName)
|
||||
.filter(Objects::nonNull)
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toSet());
|
||||
List<BatchItemContext> nonDuplicateItems = new ArrayList<>();
|
||||
for (BatchItemContext context : validItems) {
|
||||
String containerName = context.item().getContainerName().trim();
|
||||
if (existingContainerNames.contains(containerName)) {
|
||||
failures.add(buildFailure(context.item().getClientKey(), context.rowIndex(),
|
||||
DUPLICATE_CONTAINER_NAME, "子卷号已存在:" + containerName));
|
||||
continue;
|
||||
}
|
||||
nonDuplicateItems.add(context);
|
||||
}
|
||||
validItems = nonDuplicateItems;
|
||||
if (CollUtil.isEmpty(validItems)) {
|
||||
return SubPackageRelationBatchCreateRespVO.builder()
|
||||
.successCount(0)
|
||||
.failureCount(failures.size())
|
||||
.failures(failures)
|
||||
.build();
|
||||
}
|
||||
|
||||
Set<String> boxTypes = validItems.stream()
|
||||
.map(context -> context.item().getBoxType())
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
@@ -127,11 +169,31 @@ public class SubPackageRelationServiceImpl implements SubPackageRelationService
|
||||
Map<GroupKey, List<BatchItemContext>> groups = validItems.stream()
|
||||
.collect(Collectors.groupingBy(context -> new GroupKey(context.item().getPackageBoxSn(),
|
||||
context.item().getBoxType()), LinkedHashMap::new, Collectors.toList()));
|
||||
Set<String> packageBoxSns = groups.keySet().stream()
|
||||
.map(GroupKey::packageBoxSn)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
Map<String, Set<String>> existingBoxTypesByPackageBoxSn = subPackageRelationMapper
|
||||
.selectListByPackageBoxSns(packageBoxSns).stream()
|
||||
.filter(relation -> relation.getPackageBoxSn() != null && relation.getBoxType() != null)
|
||||
.collect(Collectors.groupingBy(SubPackageRelationDO::getPackageBoxSn,
|
||||
Collectors.mapping(SubPackageRelationDO::getBoxType,
|
||||
Collectors.toCollection(LinkedHashSet::new))));
|
||||
|
||||
int successCount = 0;
|
||||
for (Map.Entry<GroupKey, List<BatchItemContext>> entry : groups.entrySet()) {
|
||||
GroupKey key = entry.getKey();
|
||||
List<BatchItemContext> group = entry.getValue();
|
||||
Set<String> existingBoxTypes = existingBoxTypesByPackageBoxSn.getOrDefault(
|
||||
key.packageBoxSn(), Collections.emptySet());
|
||||
if (existingBoxTypes.stream().anyMatch(boxType -> !Objects.equals(boxType, key.boxType()))) {
|
||||
String message = String.format("木箱 %s 已绑定木箱类型 %s,不能使用类型 %s",
|
||||
key.packageBoxSn(), String.join("、", existingBoxTypes), key.boxType());
|
||||
for (BatchItemContext context : group) {
|
||||
failures.add(buildFailure(context.item().getClientKey(), context.rowIndex(),
|
||||
BOX_TYPE_MISMATCH, message));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
BoxTypeDO boxType = boxTypeMap.get(key.boxType());
|
||||
if (boxType == null) {
|
||||
for (BatchItemContext context : group) {
|
||||
@@ -152,6 +214,7 @@ public class SubPackageRelationServiceImpl implements SubPackageRelationService
|
||||
continue;
|
||||
}
|
||||
|
||||
int qualityInBox = Math.toIntExact(existingCount + group.size());
|
||||
List<SubPackageRelationDO> saveGroup = new ArrayList<>();
|
||||
for (BatchItemContext context : group) {
|
||||
SubPackageRelationBatchCreateItemReqVO item = context.item();
|
||||
@@ -161,6 +224,7 @@ public class SubPackageRelationServiceImpl implements SubPackageRelationService
|
||||
relation.setBoxLength(item.getBoxLength());
|
||||
relation.setBoxWidth(item.getBoxWidth());
|
||||
relation.setBoxHigh(item.getBoxHigh());
|
||||
relation.setQualityInBox(qualityInBox);
|
||||
relation.setQualityGuaranPeriod(item.getQualityGuaranPeriod());
|
||||
relation.setDateOfFgInbound(item.getDateOfFgInbound());
|
||||
relation.setContainerName(item.getContainerName());
|
||||
|
||||
Reference in New Issue
Block a user