receiption.uts
8.69 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
import http from "@/api/request/http.uts";
import { logger } from "@/services/logger";
/**
* 统一 API 日志包装(避免到处散落 logger 调用)
* - UTS 里不依赖 uni.logger(项目已改为显式 import 使用)
*/
function safeToJson(value: any): string {
try {
return JSON.stringify(value);
} catch (e) {
return "[unserializable]";
}
}
function logAndReturn(
name: string,
task: Promise<any>,
meta: UTSJSONObject
): Promise<UTSJSONObject> {
return (async (): Promise<UTSJSONObject> => {
const startAt = Date.now();
const startPayload: UTSJSONObject = { name: name, startAt: startAt };
for (const k in meta) {
startPayload[k] = meta[k];
}
logger.info(startPayload, "API");
try {
const res = await task;
const costMs = Date.now() - startAt;
// ✅ 临时禁用:注释掉响应日志,避免控制台输出大量数据
// logger.info({ name: name, costMs: costMs, res: safeToJson(res) } as UTSJSONObject, "API");
return res as UTSJSONObject;
} catch (err) {
const costMs = Date.now() - startAt;
const errPayload: UTSJSONObject = { name: name, costMs: costMs, err: `${err}` };
for (const k in meta) {
errPayload[k] = meta[k];
}
logger.error(errPayload, "API");
// UTS 侧 throw 需要 Throwable,这里统一转 Error(带上 name 便于与网关原始文案对照)
throw new Error(`[API:${name}] ${err}`);
}
})();
}
function withProjectName(projectName: string, params: UTSJSONObject): UTSJSONObject {
const data: UTSJSONObject = { projectName: projectName };
for (const k in params) {
data[k] = params[k];
}
return data;
}
function fetchWithLog(
name: string,
api: string,
params: UTSJSONObject,
needToken: boolean,
env: string
): Promise<UTSJSONObject> {
const meta: UTSJSONObject = {
method: "FETCH",
api: api,
needToken: needToken,
env: env,
params: safeToJson(params)
};
return logAndReturn(name, http.fetch(api, params, needToken, env), meta);
}
function shukeRequestWithLog(
name: string,
url: string,
params: UTSJSONObject,
method: string,
showLoading: boolean
): Promise<UTSJSONObject> {
const meta: UTSJSONObject = {
method: method,
url: url,
showLoading: showLoading,
params: safeToJson(params)
};
return logAndReturn(name, http.shukeRequest(url, params, method, showLoading), meta);
}
// export async function getToken(params: UTSJSONObject): Promise<UTSJSONObject> {
// const data: UTSJSONObject = {
// projectName: "boutique",
// ...params
// };
// return http.fetch("dj.api.smartcarlife.recepiton.customer.oss.getToken", data, false, "dj");
// }
// export async function saveRecCustomer(params: UTSJSONObject): Promise<boolean> {
// try{
// const data: UTSJSONObject = {
// projectName: "boutique",
// ...params
// };
// return await http.fetch("dj.api.smartcarlife.recepiton.customer.saveRecCustomer", data, false, "dj");
// }catch (error) {
// return false;
// }
// }
export async function searchRecordingEndTime(params: UTSJSONObject): Promise<string> {
const data = withProjectName("boutique", params);
// returnAll=true:避免 ROP 在 code!=0 时直接 reject 被 logAndReturn 二次包装;在此统一解析业务码与 data
const res = await fetchWithLog(
"searchRecordingEndTime",
"dj.api.smartcarlife.recepiton.customer.searchRecordingEndTime",
data,
true,
"dj"
) as UTSJSONObject;
const code = res["code"];
if (`${code}` != "0") {
const msg = res["message"] != null && `${res["message"]}` != "" ? `${res["message"]}` : "searchRecordingEndTime 调用失败";
throw new Error(msg);
}
const biz = res["data"];
if (biz == null) {
return "";
}
if (typeof biz === "string") {
return biz;
}
// 后端若将时间包在对象内,至少给出可观测字符串(调用方 RecordSave 会再 toStr / 日期归一化)
return `${biz}`;
}
export async function getMerchantPerformance(params: UTSJSONObject): Promise<any> {
const data = withProjectName("boutique", params);
return await fetchWithLog(
"getMerchantPerformance",
"dj.api.car.boutique.inspection.findMerchantPerformance",
data,
true,
"dj"
);
}
/** 查询当前门店客户档案列表(预录列表) */
export async function getCustomerFileList(params: UTSJSONObject): Promise<any> {
const data = withProjectName("boutique", params);
return await fetchWithLog(
"getCustomerFileList",
"dj.api.smartcarlife.customervisits.customerInfoPage",
data,
true,
"dj"
);
}
/** 查询当前门店接待复盘列表(接待复盘列表) */
export async function getReceptionList(params: UTSJSONObject): Promise<any> {
const data = withProjectName("boutique", params);
return await fetchWithLog(
"getReceptionList",
"dj.api.smartcarlife.reception.customer.page",
data,
true,
"dj"
);
}
export async function findAllSence(params: UTSJSONObject): Promise<any> {
const data = withProjectName("boutique", params);
return await fetchWithLog(
"findAllSence",
"dj.api.smartcarlife.customervisits.findAllSence",
data,
true,
"dj"
);
}
// 根据客户标签
export async function findCustomerTags(params: UTSJSONObject): Promise<any> {
const data = withProjectName("boutique", params);
return await fetchWithLog(
"findCustomerTags",
"dj.api.smartcarlife.customervisits.findSenceTag",
data,
true,
"dj"
);
}
export async function saveVisitsInfo(params: UTSJSONObject): Promise<any> {
const data = withProjectName("boutique", params);
return await fetchWithLog(
"saveVisitsInfo",
"dj.api.smartcarlife.customervisits.saveVisitsInfo",
data,
true,
"dj"
);
}
export async function updateVisitsInfo(params: UTSJSONObject): Promise<any> {
const data = withProjectName("boutique", params);
return await fetchWithLog(
"updateVisitsInfo",
"dj.api.smartcarlife.customervisits.updateVisitsInfo",
data,
true,
"dj"
);
}
export async function findVisitsInfo(params: UTSJSONObject): Promise<any> {
const data = withProjectName("boutique", params);
return await fetchWithLog(
"findVisitsInfo",
"dj.api.smartcarlife.customervisits.findVisitsInfo",
data,
true,
"dj"
);
}
export async function findCheckResultByBatchId(params: UTSJSONObject): Promise<any> {
const data = withProjectName("pad", params);
return await fetchWithLog(
"findCheckResultByBatchId",
"dj.pad.api.reception.findCheckResultByBatchId",
data,
true,
"dj"
);
}
export async function getShortUrl(params: UTSJSONObject): Promise<any> {
const data = withProjectName("boutique", params);
return await fetchWithLog(
"getShortUrl",
"dj.api.car.boutique.inspection.batch.file.short.url",
data,
true,
"dj"
);
}
export async function getAiagent(params: UTSJSONObject): Promise<any> {
const data = withProjectName("pad", params);
return await fetchWithLog(
"getAiagent",
"dj.pad.api.aiagent.get.special.agent",
data,
true,
"dj"
);
}
export async function apiShukeLoginInit(params: UTSJSONObject): Promise<UTSJSONObject> {
return await shukeRequestWithLog(
"apiShukeLoginInit",
"linkwe-gateway/auth/accountLoginSp/init",
params,
"POST",
true
);
}
export async function saveRecCustomer(params: UTSJSONObject): Promise<UTSJSONObject> {
return await shukeRequestWithLog(
"saveRecCustomer",
"linkwe-gateway/reception/reception/save",
params,
"POST",
true
);
}
export async function getList(params: UTSJSONObject): Promise<UTSJSONObject> {
return await shukeRequestWithLog(
"getList",
"linkwe-gateway/reception/reception/page",
params,
"POST",
false
);
}
export async function getToken(params: UTSJSONObject): Promise<UTSJSONObject> {
return await shukeRequestWithLog(
"getToken",
"linkwe-gateway/file/get/config",
params,
"GET",
true
);
}
export async function findCheckResultListByReceptionId(params: UTSJSONObject): Promise<UTSJSONObject> {
const name = "findCheckResultListByReceptionId";
logger.info(
{
name: name,
phase: "request",
params: safeToJson(params)
} as UTSJSONObject,
"API"
);
const res = await shukeRequestWithLog(
"findCheckResultListByReceptionId",
"linkwe-gateway/reception/reception/findCheckResultListByReceptionId",
params,
"GET",
true
);
logger.info(
{
name: name,
phase: "response",
res: safeToJson(res)
} as UTSJSONObject,
"API"
);
return res;
}
export async function findConversationDetailByReceptionId(params: UTSJSONObject): Promise<UTSJSONObject> {
const name = "findConversationDetailByReceptionId";
logger.info(
{
name: name,
phase: "request",
params: safeToJson(params)
} as UTSJSONObject,
"API"
);
const res = await shukeRequestWithLog(
"findConversationDetailByReceptionId",
"linkwe-gateway/reception/reception/findConversationDetailByReceptionId",
params,
"GET",
true
);
logger.info(
{
name: name,
phase: "response",
res: safeToJson(res)
} as UTSJSONObject,
"API"
);
return res;
}