feat(file): register domestic order exports
This commit is contained in:
@@ -7,6 +7,7 @@ import java.util.List;
|
||||
|
||||
final class ExportSchemaContracts {
|
||||
static final String BUY_DECLARATION_ITEMS = "LOADING_LIST_BUY_DECLARATION_ITEMS";
|
||||
static final String DOMESTIC_WAREHOUSE_ORDER_LIST = "DOMESTIC_WAREHOUSE_ORDER_LIST";
|
||||
static final List<ExpectedColumn> BUY_DECLARATION_COLUMNS = List.of(
|
||||
column("customerName", "客户名称", ExportColumnType.STRING),
|
||||
column("orderNo", "订单号", ExportColumnType.STRING),
|
||||
@@ -21,20 +22,54 @@ final class ExportSchemaContracts {
|
||||
column("volume", "体积", ExportColumnType.DECIMAL),
|
||||
column("mark", "唛头", ExportColumnType.STRING),
|
||||
column("customerRemark", "客户备注", ExportColumnType.STRING));
|
||||
static final List<ExpectedColumn> DOMESTIC_WAREHOUSE_ORDER_COLUMNS = List.of(
|
||||
column("inboundCode", "入仓码", ExportColumnType.STRING),
|
||||
column("orderNo", "订单号", ExportColumnType.STRING),
|
||||
column("mainStatus", "订单主状态", ExportColumnType.STRING),
|
||||
column("customerName", "客户", ExportColumnType.STRING),
|
||||
column("channelName", "渠道", ExportColumnType.STRING),
|
||||
column("channelChanged", "曾变更渠道", ExportColumnType.BOOLEAN),
|
||||
column("receivingWarehouseName", "定位仓库", ExportColumnType.STRING),
|
||||
column("destinationWarehouseName", "交货仓", ExportColumnType.STRING),
|
||||
column("expectedShipDate", "预计出运日期", ExportColumnType.DATE),
|
||||
column("expectedArrivalAt", "预计到货时间", ExportColumnType.DATETIME),
|
||||
column("expectedVolumeCbm", "预计体积(m³)", ExportColumnType.DECIMAL),
|
||||
column("totalPackageCount", "箱数", ExportColumnType.INTEGER),
|
||||
column("totalQuantity", "产品数量", ExportColumnType.INTEGER),
|
||||
column("actualGrossWeightKg", "实测毛重(kg)", ExportColumnType.DECIMAL),
|
||||
column("actualVolumeCbm", "实测体积(m³)", ExportColumnType.DECIMAL),
|
||||
column("chargeableWeightKg", "计费重量(kg)", ExportColumnType.DECIMAL),
|
||||
column("chargeableVolumeCbm", "计费体积(m³)", ExportColumnType.DECIMAL),
|
||||
column("feeReviewStatus", "费用审核状态", ExportColumnType.STRING),
|
||||
column("skuNos", "SKU", ExportColumnType.STRING),
|
||||
column("taxMode", "报关方式", ExportColumnType.STRING),
|
||||
column("containerMode", "装柜方式", ExportColumnType.STRING),
|
||||
column("customsInspection", "是否商检", ExportColumnType.BOOLEAN),
|
||||
column("containerNo", "集装箱号", ExportColumnType.STRING),
|
||||
column("cabinetNo", "柜次号", ExportColumnType.STRING),
|
||||
column("vesselName", "船名", ExportColumnType.STRING),
|
||||
column("voyageNo", "航次", ExportColumnType.STRING),
|
||||
column("createdAt", "创建时间", ExportColumnType.DATETIME));
|
||||
|
||||
private ExportSchemaContracts() { }
|
||||
|
||||
static void validate(String exportType, List<ExportColumn> columns) {
|
||||
if (!BUY_DECLARATION_ITEMS.equals(exportType)) return;
|
||||
if (columns.size() != BUY_DECLARATION_COLUMNS.size()) {
|
||||
throw ExportFailure.permanent("买单报关导出列定义不匹配");
|
||||
if (BUY_DECLARATION_ITEMS.equals(exportType)) {
|
||||
validate(columns, BUY_DECLARATION_COLUMNS, "买单报关导出列定义不匹配");
|
||||
} else if (DOMESTIC_WAREHOUSE_ORDER_LIST.equals(exportType)) {
|
||||
validate(columns, DOMESTIC_WAREHOUSE_ORDER_COLUMNS, "国内仓订单导出列定义不匹配");
|
||||
}
|
||||
}
|
||||
|
||||
private static void validate(List<ExportColumn> columns, List<ExpectedColumn> expectedColumns,
|
||||
String failureMessage) {
|
||||
if (columns.size() != expectedColumns.size()) throw ExportFailure.permanent(failureMessage);
|
||||
for (int index = 0; index < columns.size(); index++) {
|
||||
ExportColumn actual = columns.get(index);
|
||||
ExpectedColumn expected = BUY_DECLARATION_COLUMNS.get(index);
|
||||
ExpectedColumn expected = expectedColumns.get(index);
|
||||
if (!expected.key.equals(actual.key()) || !expected.title.equals(actual.title())
|
||||
|| expected.type != actual.type()) {
|
||||
throw ExportFailure.permanent("买单报关导出列定义不匹配");
|
||||
throw ExportFailure.permanent(failureMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ExportTaskService {
|
||||
if (!user.permissions().contains(permission)) {
|
||||
throw new BizException(ResultCode.FORBIDDEN, "缺少该导出类型的操作权限");
|
||||
}
|
||||
validateParameters(request.parameters());
|
||||
validateParameters(type, request.parameters());
|
||||
validateTypeParameters(type, request.parameters());
|
||||
String parametersJson = parametersJson(request.parameters());
|
||||
long id = IdWorker.getId();
|
||||
@@ -140,15 +140,23 @@ public class ExportTaskService {
|
||||
catch (JsonProcessingException exception) { throw new BizException(ResultCode.BAD_REQUEST, "导出筛选条件无法序列化"); }
|
||||
}
|
||||
|
||||
private void validateParameters(Map<String, Object> parameters) {
|
||||
private void validateParameters(String type, Map<String, Object> parameters) {
|
||||
Map<String, Object> values = parameters == null ? Map.of() : parameters;
|
||||
if (values.size() > 20) throw new BizException(ResultCode.VALIDATION_FAILED, "导出筛选条件最多 20 项");
|
||||
int maxItems = ExportSchemaContracts.DOMESTIC_WAREHOUSE_ORDER_LIST.equals(type) ? 32 : 20;
|
||||
if (values.size() > maxItems) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED, "导出筛选条件最多 " + maxItems + " 项");
|
||||
}
|
||||
values.forEach((key, value) -> {
|
||||
if (key == null || key.isBlank() || key.length() > 64) throw new BizException(ResultCode.VALIDATION_FAILED, "导出筛选键无效");
|
||||
validateParameterValue(value, 1);
|
||||
});
|
||||
try {
|
||||
if (objectMapper.writeValueAsBytes(values).length > 4096) throw new BizException(ResultCode.VALIDATION_FAILED, "导出筛选条件不能超过 4KB");
|
||||
int maxBytes = ExportSchemaContracts.DOMESTIC_WAREHOUSE_ORDER_LIST.equals(type)
|
||||
? 512 * 1024 : 4096;
|
||||
if (objectMapper.writeValueAsBytes(values).length > maxBytes) {
|
||||
throw new BizException(ResultCode.VALIDATION_FAILED,
|
||||
"导出筛选条件不能超过 " + (maxBytes / 1024) + "KB");
|
||||
}
|
||||
} catch (JsonProcessingException exception) {
|
||||
throw new BizException(ResultCode.BAD_REQUEST, "导出筛选条件无法序列化");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user