feat(freight-rpa): 支持从来源站点复制为未保存草稿
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
31434f8424
commit
95e7db0831
8 files changed
+426
-16
No files matched your search
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* features/admin/modules/freight-rpa/sourceCloneDraft.ts
|
||||
* 用途:把已有来源站点配置变成一份尚未落库的新建草稿。
|
||||
* 依赖:无。
|
||||
* 逻辑:FreightRpaPage 在卡片或抽屉点击「复制新增」时调用;保存仍走既有新建接口。
|
||||
*/
|
||||
|
||||
export type SourceCloneParameter = {
|
||||
name: string;
|
||||
mode: string;
|
||||
values: string[];
|
||||
required: boolean;
|
||||
select_all: boolean;
|
||||
joiner?: string;
|
||||
};
|
||||
|
||||
export type SourceCloneReportConfig = {
|
||||
report_path_json: Record<string, string>;
|
||||
query_parameters_json: SourceCloneParameter[];
|
||||
parsing_profile_id: number | null;
|
||||
};
|
||||
|
||||
export type SourceCloneInput = {
|
||||
source_code: string;
|
||||
display_name: string;
|
||||
connector_type: string;
|
||||
rpa_profile_id: number;
|
||||
excel_template_id: number;
|
||||
warehouse_resolution_mode: string;
|
||||
fixed_warehouse_id: string;
|
||||
snapshot_ttl_seconds: number;
|
||||
onhand_report_config: {
|
||||
report_path_json: Record<string, string>;
|
||||
query_parameters_json: SourceCloneParameter[];
|
||||
parsing_profile_id: number;
|
||||
};
|
||||
inbound_report_config: SourceCloneReportConfig | null;
|
||||
outbound_report_config: SourceCloneReportConfig | null;
|
||||
};
|
||||
|
||||
export type SourceCloneDraft = {
|
||||
source_code: '';
|
||||
display_name: string;
|
||||
connector_type: string;
|
||||
rpa_profile_id: number;
|
||||
excel_template_id: number;
|
||||
warehouse_resolution_mode: string;
|
||||
fixed_warehouse_id: string;
|
||||
snapshot_ttl_seconds: number;
|
||||
enabled: false;
|
||||
onhand_report_config: {
|
||||
report_path_json: Record<string, string>;
|
||||
query_parameters_json: SourceCloneParameter[];
|
||||
parsing_profile_id: number;
|
||||
};
|
||||
inbound_report_config: SourceCloneReportConfig | null;
|
||||
outbound_report_config: SourceCloneReportConfig | null;
|
||||
clone_from: { source_code: string; display_name: string };
|
||||
};
|
||||
|
||||
/**
|
||||
* 深拷贝查询条件,避免草稿里改值时回写到来源对象。
|
||||
* @param parameters - 来源站点上的查询条件。
|
||||
* @returns 条件与取值都是新数组的副本。
|
||||
*/
|
||||
function cloneParameters(parameters: SourceCloneParameter[] | undefined): SourceCloneParameter[] {
|
||||
return (parameters || []).map((parameter) => ({
|
||||
...parameter,
|
||||
values: [...(parameter.values || [])],
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制一份报表配置;没有配置时返回 null,避免保存时建出空的入站或出站行。
|
||||
* @param config - 已有报表配置;空表示该站点没有这块配置。
|
||||
* @returns 深拷贝后的配置,或 null。
|
||||
*/
|
||||
function cloneReport(config: SourceCloneReportConfig | null | undefined): SourceCloneReportConfig | null {
|
||||
if (!config) return null;
|
||||
return {
|
||||
report_path_json: { ...(config.report_path_json || {}) },
|
||||
query_parameters_json: cloneParameters(config.query_parameters_json),
|
||||
parsing_profile_id: config.parsing_profile_id ? Number(config.parsing_profile_id) : null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 从来源站点生成未保存草稿。
|
||||
* 核心逻辑:配置字段逐项深拷贝;库存源编号清空;名称追加副本后缀;启用状态固定为停用。
|
||||
* 不复制主键、启用检查、快照、仓库映射和路由规则。
|
||||
* @param input - 来源站点当前可见配置,入站或出站没有配置时传 null。
|
||||
* @param copySuffix - 追加在名称后的本地化后缀,例如「副本」。
|
||||
* @returns 可直接填入新建表单的草稿,source_code 恒为空字符串。
|
||||
*/
|
||||
export function buildSourceCloneDraft(input: SourceCloneInput, copySuffix: string): SourceCloneDraft {
|
||||
const displayName = String(input.display_name || input.source_code || '').trim();
|
||||
const suffix = String(copySuffix || '').trim();
|
||||
return {
|
||||
source_code: '',
|
||||
display_name: suffix ? `${displayName} ${suffix}` : displayName,
|
||||
connector_type: input.connector_type,
|
||||
rpa_profile_id: Number(input.rpa_profile_id) || 0,
|
||||
excel_template_id: Number(input.excel_template_id) || 0,
|
||||
warehouse_resolution_mode: input.warehouse_resolution_mode,
|
||||
fixed_warehouse_id: input.fixed_warehouse_id || '',
|
||||
snapshot_ttl_seconds: Number(input.snapshot_ttl_seconds) || 86400,
|
||||
enabled: false,
|
||||
onhand_report_config: {
|
||||
report_path_json: { ...(input.onhand_report_config?.report_path_json || {}) },
|
||||
query_parameters_json: cloneParameters(input.onhand_report_config?.query_parameters_json),
|
||||
parsing_profile_id: Number(input.onhand_report_config?.parsing_profile_id) || 0,
|
||||
},
|
||||
inbound_report_config: cloneReport(input.inbound_report_config),
|
||||
outbound_report_config: cloneReport(input.outbound_report_config),
|
||||
clone_from: {
|
||||
source_code: String(input.source_code || ''),
|
||||
display_name: displayName,
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user