优化
This commit is contained in:
@@ -21,13 +21,14 @@ public class ExportProviderClient {
|
||||
@Resource private WarehouseExportProviderClient warehouse;
|
||||
@Resource private FirstlegExportProviderClient firstleg;
|
||||
@Resource private FinanceExportProviderClient finance;
|
||||
@Resource private LastlegExportProviderClient lastleg;
|
||||
@Resource
|
||||
private MeterRegistry meters;
|
||||
@PostConstruct
|
||||
void initializeClients() {
|
||||
this.clients = Map.of("iam-service", iam, "order-service", order,
|
||||
"warehouse-service", warehouse, "firstleg-service", firstleg,
|
||||
"finance-service", finance);
|
||||
"finance-service", finance, "lastleg-service", lastleg);
|
||||
}
|
||||
|
||||
public ApiResponse<ExportBatchResponse> batch(String internalToken, String exportType,
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.baiyue.file.client;
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
|
||||
@FeignClient(name="lastleg-service", contextId="lastlegExportProviderClient",
|
||||
url="${baiyue.clients.lastleg.url:}", configuration=ExportProviderFeignConfiguration.class)
|
||||
interface LastlegExportProviderClient extends ExportProviderFeignClient { }
|
||||
@@ -11,7 +11,7 @@ import java.util.regex.Pattern;
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "baiyue.file.export")
|
||||
public class ExportDefinitionRegistry {
|
||||
private static final Set<String> SERVICES = Set.of("iam-service", "order-service", "warehouse-service", "firstleg-service", "finance-service");
|
||||
private static final Set<String> SERVICES = Set.of("iam-service", "order-service", "warehouse-service", "firstleg-service", "finance-service", "lastleg-service");
|
||||
private static final Pattern TYPE = Pattern.compile("[A-Z0-9_]+");
|
||||
private static final Pattern PATH = Pattern.compile("/internal/exports/v1/([A-Z0-9_]+)/batches");
|
||||
private static final Pattern PERMISSION = Pattern.compile("[a-z]+(?::[a-z-]+){2,}");
|
||||
|
||||
@@ -46,7 +46,11 @@ public class ExportTaskService {
|
||||
}
|
||||
validateParameters(type, request.parameters());
|
||||
validateTypeParameters(type, request.parameters());
|
||||
String parametersJson = parametersJson(request.parameters());
|
||||
Map<String, Object> parameters = new TreeMap<>(request.parameters() == null ? Map.of() : request.parameters());
|
||||
if ("TRIP_OPERATIONS_LIST".equals(type)) {
|
||||
parameters.put("costVisible", user.permissions().contains("platform:fleet:trip:list"));
|
||||
}
|
||||
String parametersJson = parametersJson(parameters);
|
||||
long id = IdWorker.getId();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
FileExportTask task = new FileExportTask();
|
||||
@@ -92,6 +96,7 @@ public class ExportTaskService {
|
||||
|
||||
public DownloadResource download(AuthenticatedUser user, long id) {
|
||||
FileExportTask task = ownedTask(user, id);
|
||||
requireExportCostAccess(user, task);
|
||||
if (!"SUCCEEDED".equals(task.getStatus())) {
|
||||
throw new BizException(ResultCode.CONFLICT, "导出任务尚未完成或文件已过期");
|
||||
}
|
||||
@@ -103,6 +108,7 @@ public class ExportTaskService {
|
||||
|
||||
public ExportTaskResponse retry(AuthenticatedUser user, long id) {
|
||||
FileExportTask task = ownedTask(user, id);
|
||||
requireExportCostAccess(user, task);
|
||||
var definition = registry.require(task.getExportType());
|
||||
if (!definition.isEnabled()) throw new BizException(ResultCode.CONFLICT, "该导出类型已停用");
|
||||
String permission = definition.getRequiredPermission();
|
||||
@@ -128,6 +134,18 @@ public class ExportTaskService {
|
||||
return response(repository.find(id));
|
||||
}
|
||||
|
||||
private void requireExportCostAccess(AuthenticatedUser user, FileExportTask task) {
|
||||
if (!"TRIP_OPERATIONS_LIST".equals(task.getExportType())) return;
|
||||
try {
|
||||
if (objectMapper.readTree(task.getParametersJson()).path("costVisible").asBoolean(false)
|
||||
&& !user.permissions().contains("platform:fleet:trip:list")) {
|
||||
throw new BizException(ResultCode.FORBIDDEN, "缺少出车成本读取权限,请重新创建不含成本的导出任务");
|
||||
}
|
||||
} catch (JsonProcessingException exception) {
|
||||
throw new BizException(ResultCode.CONFLICT, "导出筛选快照无效,请重新创建任务");
|
||||
}
|
||||
}
|
||||
|
||||
private FileExportTask ownedTask(AuthenticatedUser user, long id) {
|
||||
requirePlatform(user);
|
||||
FileExportTask task = repository.find(id);
|
||||
|
||||
@@ -35,6 +35,9 @@ spring:
|
||||
firstlegExportProviderClient:
|
||||
connect-timeout: 3000
|
||||
read-timeout: 15000
|
||||
lastlegExportProviderClient:
|
||||
connect-timeout: 3000
|
||||
read-timeout: 15000
|
||||
financeExportProviderClient:
|
||||
connect-timeout: 3000
|
||||
read-timeout: 15000
|
||||
@@ -203,4 +206,76 @@ baiyue:
|
||||
max-rows: 200000
|
||||
max-attempts: 3
|
||||
batch-size: 500
|
||||
LAST_MILE_ORDER_LIST:
|
||||
provider-service: lastleg-service
|
||||
provider-path: /internal/exports/v1/LAST_MILE_ORDER_LIST/batches
|
||||
required-permission: platform:overseas-warehouse:last-mile-order:export
|
||||
app-scope: PLATFORM
|
||||
enabled: true
|
||||
max-rows: 200000
|
||||
max-attempts: 3
|
||||
batch-size: 200
|
||||
OVERSEAS_INVENTORY_BALANCE:
|
||||
provider-service: lastleg-service
|
||||
provider-path: /internal/exports/v1/OVERSEAS_INVENTORY_BALANCE/batches
|
||||
required-permission: platform:overseas-warehouse:inventory:export
|
||||
app-scope: PLATFORM
|
||||
enabled: true
|
||||
max-rows: 200000
|
||||
max-attempts: 3
|
||||
batch-size: 200
|
||||
OVERSEAS_INVENTORY_LEDGER:
|
||||
provider-service: lastleg-service
|
||||
provider-path: /internal/exports/v1/OVERSEAS_INVENTORY_LEDGER/batches
|
||||
required-permission: platform:overseas-warehouse:inventory:export
|
||||
app-scope: PLATFORM
|
||||
enabled: true
|
||||
max-rows: 200000
|
||||
max-attempts: 3
|
||||
batch-size: 200
|
||||
OVERSEAS_QUOTE_LIST:
|
||||
provider-service: lastleg-service
|
||||
provider-path: /internal/exports/v1/OVERSEAS_QUOTE_LIST/batches
|
||||
required-permission: platform:overseas-master-data:quote:export
|
||||
app-scope: PLATFORM
|
||||
enabled: true
|
||||
max-rows: 200000
|
||||
max-attempts: 3
|
||||
batch-size: 200
|
||||
MONTHLY_EXCHANGE_RATE_LIST:
|
||||
provider-service: lastleg-service
|
||||
provider-path: /internal/exports/v1/MONTHLY_EXCHANGE_RATE_LIST/batches
|
||||
required-permission: platform:overseas-master-data:exchange-rate:export
|
||||
app-scope: PLATFORM
|
||||
enabled: true
|
||||
max-rows: 200000
|
||||
max-attempts: 3
|
||||
batch-size: 200
|
||||
VEHICLE_LIST:
|
||||
provider-service: lastleg-service
|
||||
provider-path: /internal/exports/v1/VEHICLE_LIST/batches
|
||||
required-permission: platform:overseas-master-data:vehicle:export
|
||||
app-scope: PLATFORM
|
||||
enabled: true
|
||||
max-rows: 200000
|
||||
max-attempts: 3
|
||||
batch-size: 200
|
||||
FLEET_QUOTE_LIST:
|
||||
provider-service: lastleg-service
|
||||
provider-path: /internal/exports/v1/FLEET_QUOTE_LIST/batches
|
||||
required-permission: platform:fleet:quote:export
|
||||
app-scope: PLATFORM
|
||||
enabled: true
|
||||
max-rows: 200000
|
||||
max-attempts: 3
|
||||
batch-size: 200
|
||||
TRIP_OPERATIONS_LIST:
|
||||
provider-service: lastleg-service
|
||||
provider-path: /internal/exports/v1/TRIP_OPERATIONS_LIST/batches
|
||||
required-permission: platform:fleet:operations:export
|
||||
app-scope: PLATFORM
|
||||
enabled: true
|
||||
max-rows: 200000
|
||||
max-attempts: 3
|
||||
batch-size: 200
|
||||
management.endpoints.web.exposure.include: health,info,prometheus
|
||||
|
||||
Reference in New Issue
Block a user