优化
This commit is contained in:
@@ -323,6 +323,7 @@ public class MerchantBatchImportService {
|
||||
if (items.size() >= MAX_ROWS) throw new BizException(ResultCode.VALIDATION_FAILED, "Excel 最多 50 条订单");
|
||||
String rowId = "excel-row-" + (rowNo + 1);
|
||||
try {
|
||||
validateRequiredColumns(row);
|
||||
var draft = json.createObjectNode();
|
||||
draft.put("customerName", customerName);
|
||||
draft.put("tradeTerm", "FOB");
|
||||
@@ -347,6 +348,8 @@ public class MerchantBatchImportService {
|
||||
}
|
||||
validateDestination(draft.path("destinationType").asText(null),
|
||||
fbaSelected, overseasSelected, privateSelected);
|
||||
validatePickup(draft.path("pickupMethod").asText(null),
|
||||
draft.hasNonNull("requestedPickupAt"), draft.hasNonNull("senderAddressId"));
|
||||
draft.set("cargoes", json.createArrayNode().add(cargo));
|
||||
items.add(new MerchantBatchDraftDtos.Item(rowId,
|
||||
json.treeToValue(draft, OrderRequests.SaveRequest.class)));
|
||||
@@ -496,6 +499,15 @@ public class MerchantBatchImportService {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void validateRequiredColumns(Row row) {
|
||||
for (int col = 0; col < COLUMNS.size(); col++) {
|
||||
Column column = COLUMNS.get(col);
|
||||
if (column.required() && !StringUtils.hasText(text(row.getCell(col)))) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, column.title() + "不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int excelRowNumber(String clientRowId) {
|
||||
String prefix = "excel-row-";
|
||||
if (!StringUtils.hasText(clientRowId) || !clientRowId.startsWith(prefix)) {
|
||||
@@ -576,6 +588,16 @@ public class MerchantBatchImportService {
|
||||
});
|
||||
}
|
||||
|
||||
private static void validatePickup(String pickupMethod, boolean requestedPickupAt, boolean senderAddress) {
|
||||
if (!"PICKUP".equals(pickupMethod)) return;
|
||||
if (!requestedPickupAt) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, "平台上门提货时预约提货时间不能为空");
|
||||
}
|
||||
if (!senderAddress) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, "平台上门提货时取货地址不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
private static String label(String name, String code) {
|
||||
if (!StringUtils.hasText(name)) return code;
|
||||
return name.equalsIgnoreCase(code) ? code : name + "|" + code;
|
||||
|
||||
Reference in New Issue
Block a user