fix: 校验批量新增行标识重复
This commit is contained in:
@@ -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<SubPackageRelationBatchCreateRespVO.Failure> failures = new ArrayList<>();
|
||||
List<BatchItemContext> validItems = new ArrayList<>();
|
||||
Map<String, Integer> 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)) {
|
||||
|
||||
Reference in New Issue
Block a user