mapDetailResponse.js
1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { mapSceneType } from "./mapSceneType";
function normalizeContextList(value) {
if (Array.isArray(value)) {
return value;
}
if (value == null || value === "") {
return [];
}
return String(value).split(",").filter(Boolean);
}
function resolveBusinessValue(...values) {
const value = values.find(item => item != null && item !== "");
return value ?? "";
}
/**
* 详情路由 query → dailyReport.detail.select 请求体
*/
export function buildDetailSelectParams({ id } = {}) {
return { id };
}
/**
* dailyReport.detail.select 响应 → 详情页 detail 对象
*/
export function mapDetailResponse(res = {}, fallback = {}) {
const sceneType = res.sceneType ?? fallback.sceneType;
const sceneContext = {
baseSceneCode: res.baseSceneCode ?? fallback.baseSceneCode,
sceneList: res.sceneList ?? fallback.sceneList,
};
const preciseScene = mapSceneType(undefined, sceneContext);
const legacyScene = mapSceneType(sceneType);
return {
...res,
id: res.id ?? res.dailyReportRecordId ?? fallback.id,
staffName: res.staffName ?? fallback.staffName,
merchantName: res.merchantName ?? fallback.merchantName,
templateType: res.templateType ?? fallback.templateType,
bizType: resolveBusinessValue(
res.bizType,
preciseScene.bizType,
fallback.bizType,
legacyScene.bizType,
),
bizTypeName: resolveBusinessValue(
res.bizTypeName,
preciseScene.bizTypeName,
fallback.bizTypeName,
legacyScene.bizTypeName,
),
reportDate: res.reportDate ?? fallback.reportDate,
jsonContent: res.jsonContent,
fieldDataList: res.fieldDataList,
subformDataList: res.subformDataList,
reportTemplateId: res.reportTemplateId,
baseSceneCode: sceneContext.baseSceneCode,
sceneType,
schema: res.schema,
brandIds: normalizeContextList(res.brandIds ?? fallback.brandIds),
sceneList: sceneContext.sceneList ?? [],
};
}
export default mapDetailResponse;