diff --git a/nl-module-lms/nl-module-lms-server/src/main/java/cn/code/nl/module/lms/service/subpackagerelation/SubPackageRelationServiceImpl.java b/nl-module-lms/nl-module-lms-server/src/main/java/cn/code/nl/module/lms/service/subpackagerelation/SubPackageRelationServiceImpl.java index ef3fdadb..2a3e98ac 100644 --- a/nl-module-lms/nl-module-lms-server/src/main/java/cn/code/nl/module/lms/service/subpackagerelation/SubPackageRelationServiceImpl.java +++ b/nl-module-lms/nl-module-lms-server/src/main/java/cn/code/nl/module/lms/service/subpackagerelation/SubPackageRelationServiceImpl.java @@ -34,6 +34,8 @@ 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 BOX_TYPE_NOT_FOUND = "BOX_TYPE_NOT_FOUND"; /** 木箱容量超限错误码 */ @@ -60,6 +62,12 @@ public class SubPackageRelationServiceImpl implements SubPackageRelationService public SubPackageRelationBatchCreateRespVO batchCreateSubPackageRelation(SubPackageRelationBatchCreateReqVO reqVO) { List failures = new ArrayList<>(); List validItems = new ArrayList<>(); + Map clientKeyCounts = new HashMap<>(); + for (SubPackageRelationBatchCreateItemReqVO item : reqVO.getItems()) { + if (item != null && StringUtils.hasText(item.getClientKey())) { + clientKeyCounts.merge(item.getClientKey(), 1, Integer::sum); + } + } for (int index = 0; index < reqVO.getItems().size(); index++) { SubPackageRelationBatchCreateItemReqVO item = reqVO.getItems().get(index); int rowIndex = index + 1; @@ -94,6 +102,11 @@ public class SubPackageRelationServiceImpl implements SubPackageRelationService "缺失字段:" + String.join("、", missingFields))); continue; } + if (clientKeyCounts.get(item.getClientKey()) > 1) { + failures.add(buildFailure(item.getClientKey(), rowIndex, DUPLICATE_CLIENT_KEY, + "前端行标识 clientKey 重复")); + continue; + } validItems.add(new BatchItemContext(item, rowIndex)); } if (CollUtil.isEmpty(validItems)) {