@bit-sun/business-component 2.4.29 → 2.4.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Solution/RuleSetter/RuleInstance.d.ts +3 -0
- package/dist/components/Solution/RuleSetter/baseRule.d.ts +3 -0
- package/dist/components/Solution/RuleSetter/function.d.ts +26 -0
- package/dist/components/Solution/RuleSetter/index.d.ts +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +966 -56
- package/dist/index.js +969 -55
- package/dist/utils/LocalstorageUtils.d.ts +5 -0
- package/package.json +1 -1
- package/src/components/Business/DetailPageWrapper/index.tsx +2 -3
- package/src/components/Business/HomePageWrapper/index.tsx +8 -8
- package/src/components/Solution/RuleComponent/index.js +81 -51
- package/src/components/Solution/RuleComponent/index.less +0 -1
- package/src/components/Solution/RuleComponent/ruleFiled.js +25 -13
- package/src/components/Solution/RuleSetter/RuleInstance.tsx +6 -0
- package/src/components/Solution/RuleSetter/baseRule.tsx +368 -0
- package/src/components/Solution/RuleSetter/function.ts +336 -0
- package/src/components/Solution/RuleSetter/index.less +221 -0
- package/src/components/Solution/RuleSetter/index.tsx +208 -0
- package/src/components/Solution/RuleSetter/service.js +276 -0
- package/src/index.ts +1 -0
- package/src/utils/LocalstorageUtils.ts +24 -7
- package/src/utils/auth.ts +1 -1
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useEffect,
|
|
3
|
+
useState,
|
|
4
|
+
forwardRef,
|
|
5
|
+
useImperativeHandle,
|
|
6
|
+
useCallback,
|
|
7
|
+
useMemo,
|
|
8
|
+
} from 'react';
|
|
9
|
+
import _ from 'lodash';
|
|
10
|
+
import RuleObjectComponent from '../RuleComponent/index.js';
|
|
11
|
+
import { Spin, Space, Modal, message } from 'antd';
|
|
12
|
+
import styles from './index.less';
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
import { history } from 'umi';
|
|
15
|
+
import { request } from 'bssula';
|
|
16
|
+
import {
|
|
17
|
+
handleRuleResultList,
|
|
18
|
+
handleRuleShowBack,
|
|
19
|
+
handleRuleRequireCheck,
|
|
20
|
+
getInitClassData,
|
|
21
|
+
} from './function';
|
|
22
|
+
|
|
23
|
+
export default forwardRef((props: any, ref) => {
|
|
24
|
+
const {
|
|
25
|
+
scenceParams,
|
|
26
|
+
operationList = [],
|
|
27
|
+
regularDataList = [],
|
|
28
|
+
baseRuleDetailList = [],
|
|
29
|
+
systemVariableList = [],
|
|
30
|
+
defRuleDetail = {},
|
|
31
|
+
} = props;
|
|
32
|
+
const sceneId = scenceParams?.sceneId;
|
|
33
|
+
const sceneName = scenceParams?.sceneName;
|
|
34
|
+
const type = scenceParams?.type;
|
|
35
|
+
const ruleGroupList = scenceParams?.ruleGroupList;
|
|
36
|
+
const isGetDefRuleDataRes = scenceParams?.isGetDefRuleDataRes;
|
|
37
|
+
const isGetRuleDataRes = scenceParams?.isGetRuleDataRes;
|
|
38
|
+
const groupOtherPriorityList = scenceParams?.groupOtherPriorityList;
|
|
39
|
+
const extStrField01 = scenceParams?.extStrField01;
|
|
40
|
+
const instanceName = scenceParams?.instanceName;
|
|
41
|
+
|
|
42
|
+
const initialThresholdQuery = {};
|
|
43
|
+
|
|
44
|
+
const [loading, setLoading] = useState(false);
|
|
45
|
+
const [baseClassData, setBaseClassData] = useState<any>([]);
|
|
46
|
+
const [callbackData, setCallbackData] = useState<any>([]);
|
|
47
|
+
const [ruleTypeData, setRuleTypeData] = useState<any>([]);
|
|
48
|
+
const [ruleReturnConfig, setRuleReturnConfig] = useState<any>({});
|
|
49
|
+
const [templateData, setTemplateData] = useState<any>({});
|
|
50
|
+
|
|
51
|
+
const loadRuleReturnConfig = (currentSceneId: string) => {
|
|
52
|
+
request({
|
|
53
|
+
url: `/basic/ruleTemplate/${currentSceneId}`,
|
|
54
|
+
method: 'GET',
|
|
55
|
+
converter: (res: any) => {
|
|
56
|
+
return res;
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
.then(({ response }: any) => {
|
|
60
|
+
const rRConfig =
|
|
61
|
+
(response?.data?.ext && JSON.parse(response?.data?.ext)?.config) ||
|
|
62
|
+
{};
|
|
63
|
+
setRuleReturnConfig(rRConfig);
|
|
64
|
+
})
|
|
65
|
+
.catch(() => {});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const loadRuleConfigList = (currentSceneId: string) => {
|
|
69
|
+
request({
|
|
70
|
+
url: '/basic/ruleTemplate/result',
|
|
71
|
+
method: 'GET',
|
|
72
|
+
convertParams: () => {
|
|
73
|
+
return {
|
|
74
|
+
templateId: currentSceneId,
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
converter: (res: any) => {
|
|
78
|
+
return res;
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
.then(({ response }: any) => {
|
|
82
|
+
const functionRuleConfigList =
|
|
83
|
+
(Array.isArray(response?.data) &&
|
|
84
|
+
response?.data?.length &&
|
|
85
|
+
response.data.map((i: any) => {
|
|
86
|
+
const item = { ...i };
|
|
87
|
+
const ruleConfigList =
|
|
88
|
+
(Array.isArray(i.valueList) &&
|
|
89
|
+
i.valueList?.length &&
|
|
90
|
+
i.valueList.map((s: any) => JSON.parse(s))) ||
|
|
91
|
+
[];
|
|
92
|
+
if (ruleConfigList?.length) {
|
|
93
|
+
item.valueList = ruleConfigList.sort(
|
|
94
|
+
(a: any, b: any) => a.priority - b.priority,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
return item;
|
|
98
|
+
})) ||
|
|
99
|
+
[];
|
|
100
|
+
setRuleTypeData(functionRuleConfigList);
|
|
101
|
+
})
|
|
102
|
+
.catch(() => {});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (sceneId) {
|
|
107
|
+
loadRuleReturnConfig(sceneId);
|
|
108
|
+
loadRuleConfigList(sceneId);
|
|
109
|
+
}
|
|
110
|
+
}, [sceneId]);
|
|
111
|
+
|
|
112
|
+
const defRuleDetailId = defRuleDetail?.id;
|
|
113
|
+
const baseRuleDetailListFirstId = baseRuleDetailList?.[0]?.id;
|
|
114
|
+
// 处理规则设计器/规则实例 差异
|
|
115
|
+
const handleDiff = () => {
|
|
116
|
+
let diffResult: any = {};
|
|
117
|
+
if (!type) {
|
|
118
|
+
diffResult = {
|
|
119
|
+
title: `规则设计器${sceneName ? `【${sceneName}】` : ''}`,
|
|
120
|
+
onlyOneRule: true,
|
|
121
|
+
ruleList: (defRuleDetailId && [defRuleDetail]) || [],
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
if (type == 'instance') {
|
|
125
|
+
diffResult = {
|
|
126
|
+
title: sceneName || '规则实例',
|
|
127
|
+
onlyOneRule: false,
|
|
128
|
+
ruleList:
|
|
129
|
+
baseRuleDetailList?.sort(
|
|
130
|
+
(a: any, b: any) => a.priority - b.priority,
|
|
131
|
+
) || [],
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return diffResult;
|
|
135
|
+
};
|
|
136
|
+
const ruleList = useMemo(() => {
|
|
137
|
+
const rList = handleDiff().ruleList;
|
|
138
|
+
return rList;
|
|
139
|
+
}, [defRuleDetailId, baseRuleDetailListFirstId]);
|
|
140
|
+
|
|
141
|
+
const isTemplateRuleEdit = ruleList?.length;
|
|
142
|
+
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
// 新增设计器模板
|
|
145
|
+
if (isGetDefRuleDataRes && !defRuleDetailId && !type) {
|
|
146
|
+
const initData = getInitClassData(ruleTypeData);
|
|
147
|
+
setCallbackData(initData);
|
|
148
|
+
setBaseClassData(initData);
|
|
149
|
+
}
|
|
150
|
+
// 新增规则实例
|
|
151
|
+
if (
|
|
152
|
+
isGetRuleDataRes &&
|
|
153
|
+
isGetDefRuleDataRes &&
|
|
154
|
+
!baseRuleDetailList?.[0]?.id &&
|
|
155
|
+
type == 'instance'
|
|
156
|
+
) {
|
|
157
|
+
const templateList =
|
|
158
|
+
(defRuleDetail && defRuleDetailId && [defRuleDetail]) || [];
|
|
159
|
+
const isExitTemplateOne = templateList?.length;
|
|
160
|
+
const temp = handleRuleShowBack(
|
|
161
|
+
_.cloneDeep(templateList),
|
|
162
|
+
ruleTypeData,
|
|
163
|
+
)[0];
|
|
164
|
+
const templateInitOne = [_.omit(_.cloneDeep(temp), ['id', 'ruleId'])]; // 自动显示一条规则实例不能过滤ruleName,防止删除报错
|
|
165
|
+
const initData = isExitTemplateOne
|
|
166
|
+
? templateInitOne
|
|
167
|
+
: getInitClassData(ruleTypeData);
|
|
168
|
+
setCallbackData(initData);
|
|
169
|
+
setBaseClassData(initData);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// 编辑
|
|
173
|
+
if (isTemplateRuleEdit) {
|
|
174
|
+
const newData = handleRuleShowBack(ruleList, ruleTypeData);
|
|
175
|
+
setCallbackData(newData);
|
|
176
|
+
setBaseClassData(newData);
|
|
177
|
+
}
|
|
178
|
+
// 设置规则实例模板数据
|
|
179
|
+
if (defRuleDetailId && type == 'instance') {
|
|
180
|
+
const templateList = (defRuleDetailId && [defRuleDetail]) || [];
|
|
181
|
+
const isExitTemplateOne = templateList?.length;
|
|
182
|
+
if (isExitTemplateOne) {
|
|
183
|
+
const temp = handleRuleShowBack(
|
|
184
|
+
_.cloneDeep(templateList),
|
|
185
|
+
ruleTypeData,
|
|
186
|
+
)[0];
|
|
187
|
+
setTemplateData(
|
|
188
|
+
_.omit(_.cloneDeep(temp), ['id', 'ruleId', 'ruleName']),
|
|
189
|
+
); // 设置默认模板数据需要带上ruleName,因为这个ruleName不准确,在点击新增按钮还会重新生成
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}, [
|
|
193
|
+
isTemplateRuleEdit,
|
|
194
|
+
ruleTypeData?.length,
|
|
195
|
+
isGetDefRuleDataRes,
|
|
196
|
+
isGetRuleDataRes,
|
|
197
|
+
]);
|
|
198
|
+
|
|
199
|
+
const upDateData = (newData: any) => {
|
|
200
|
+
const upNewData = _.cloneDeep(newData);
|
|
201
|
+
setCallbackData(upNewData);
|
|
202
|
+
const handleBaseClassData = upNewData.map((item: any, index: string) => {
|
|
203
|
+
const itemData = {
|
|
204
|
+
...item,
|
|
205
|
+
extraInfo: {
|
|
206
|
+
response: {
|
|
207
|
+
inputType: item?.extraInfo?.response?.inputType,
|
|
208
|
+
formulaName: item?.extraInfo?.response?.formulaName,
|
|
209
|
+
enable: item?.extraInfo?.response?.enable !== false,
|
|
210
|
+
value: item?.extraInfo?.response?.value || '',
|
|
211
|
+
},
|
|
212
|
+
execute: ruleTypeData.map((s: any) => {
|
|
213
|
+
const mItem = (item?.extraInfo?.execute || []).find(
|
|
214
|
+
(u: any) => u.code === s.code,
|
|
215
|
+
);
|
|
216
|
+
if (mItem) {
|
|
217
|
+
return mItem;
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
priority: 1,
|
|
221
|
+
code: s.code,
|
|
222
|
+
properties: {
|
|
223
|
+
configPropertyCode: 'configPropertyValue',
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
}),
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
return itemData;
|
|
230
|
+
});
|
|
231
|
+
setBaseClassData(handleBaseClassData);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const handleSave = (needCheckOnlyOne: boolean = false) => {
|
|
235
|
+
const ruleResultList = handleRuleResultList(callbackData, ruleTypeData);
|
|
236
|
+
if (needCheckOnlyOne && ruleResultList?.length === 0) {
|
|
237
|
+
message.warning('请至少配置一个规则!');
|
|
238
|
+
return Promise.reject();
|
|
239
|
+
}
|
|
240
|
+
const actionRequiredCheckObject = handleRuleRequireCheck(
|
|
241
|
+
ruleResultList,
|
|
242
|
+
ruleTypeData,
|
|
243
|
+
);
|
|
244
|
+
if (actionRequiredCheckObject?.checkResult) {
|
|
245
|
+
const modal = Modal.warning({
|
|
246
|
+
title: '保存校验提示',
|
|
247
|
+
content: actionRequiredCheckObject.checkInfo.map((i: any) => (
|
|
248
|
+
<div>{i}</div>
|
|
249
|
+
)),
|
|
250
|
+
});
|
|
251
|
+
setTimeout(() => {
|
|
252
|
+
modal.destroy();
|
|
253
|
+
}, 10000);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// setLoading(true);
|
|
258
|
+
|
|
259
|
+
// 兼容没有规则组的情况
|
|
260
|
+
const params = ruleGroupList?.length
|
|
261
|
+
? ruleGroupList.map((groupItem: any) => ({
|
|
262
|
+
ruleDetailList: ruleResultList.map((i: any) => ({
|
|
263
|
+
...i,
|
|
264
|
+
status: i.status || 0, // 状态:0-待发布,1-已发布,2-停用
|
|
265
|
+
ruleId: groupItem.id,
|
|
266
|
+
templateId: sceneId, // 模板id
|
|
267
|
+
...(extStrField01
|
|
268
|
+
? { extStrField01: extStrField01 || i?.extStrField01 }
|
|
269
|
+
: {}),
|
|
270
|
+
...(instanceName ? { name: instanceName || i?.name } : {}),
|
|
271
|
+
})),
|
|
272
|
+
...(extStrField01 ? { extStrField01 } : {}),
|
|
273
|
+
ruleId: groupItem.id,
|
|
274
|
+
templateId: sceneId,
|
|
275
|
+
}))
|
|
276
|
+
: [
|
|
277
|
+
{
|
|
278
|
+
ruleDetailList: ruleResultList.map((i: any) => ({
|
|
279
|
+
...i,
|
|
280
|
+
status: i.status || 0,
|
|
281
|
+
templateId: sceneId,
|
|
282
|
+
...(extStrField01
|
|
283
|
+
? { extStrField01: extStrField01 || i?.extStrField01 }
|
|
284
|
+
: {}),
|
|
285
|
+
...(instanceName ? { name: instanceName || i?.name } : {}),
|
|
286
|
+
})),
|
|
287
|
+
...(extStrField01 ? { extStrField01 } : {}),
|
|
288
|
+
templateId: sceneId,
|
|
289
|
+
},
|
|
290
|
+
];
|
|
291
|
+
|
|
292
|
+
const handleUrl = `/basic/ruleDetail/addAndUpdate`;
|
|
293
|
+
const handleMethod = 'POST';
|
|
294
|
+
|
|
295
|
+
return request({
|
|
296
|
+
url: handleUrl,
|
|
297
|
+
method: handleMethod,
|
|
298
|
+
convertParams: () => {
|
|
299
|
+
return params;
|
|
300
|
+
},
|
|
301
|
+
converter: (res: any) => {
|
|
302
|
+
return res;
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
// .then(({ response }: any) => {
|
|
306
|
+
// setLoading(false);
|
|
307
|
+
// if (handleError(response)) {
|
|
308
|
+
// message.success('保存成功');
|
|
309
|
+
// !type ? loadDefRuleData(sceneId) : loadRuleData(sceneId,extStrField01);
|
|
310
|
+
// }
|
|
311
|
+
// })
|
|
312
|
+
// .catch(() => {
|
|
313
|
+
// setLoading(false);
|
|
314
|
+
// });
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
useImperativeHandle(ref, () => ({
|
|
318
|
+
handleSave,
|
|
319
|
+
}));
|
|
320
|
+
|
|
321
|
+
return (
|
|
322
|
+
<Spin spinning={loading}>
|
|
323
|
+
<div className={styles.base_rule}>
|
|
324
|
+
<div className={styles.base_rule_content}>
|
|
325
|
+
<p className={styles.base_rule_line_title}>
|
|
326
|
+
<span className={styles.rule_title}>{handleDiff()?.title}</span>
|
|
327
|
+
<p style={{ float: 'right' }} />
|
|
328
|
+
</p>
|
|
329
|
+
<div>
|
|
330
|
+
{/* @ts-ignore */}
|
|
331
|
+
{sceneId ? (<RuleObjectComponent
|
|
332
|
+
{...props?.RuleObjectComponentProps}
|
|
333
|
+
onlyOneRule={handleDiff()?.onlyOneRule}
|
|
334
|
+
ruleGroupInfo={{
|
|
335
|
+
ruleGroupList,
|
|
336
|
+
type,
|
|
337
|
+
templateData,
|
|
338
|
+
groupOtherPriorityList,
|
|
339
|
+
}}
|
|
340
|
+
ruleClassData={baseClassData}
|
|
341
|
+
initialThresholdQuery={initialThresholdQuery}
|
|
342
|
+
ruleTypeData={ruleTypeData}
|
|
343
|
+
ruleReturnConfig={ruleReturnConfig}
|
|
344
|
+
operationList={operationList}
|
|
345
|
+
regularDataList={regularDataList}
|
|
346
|
+
systemVariableList={systemVariableList}
|
|
347
|
+
callBack={(newData: any) => {
|
|
348
|
+
upDateData(newData);
|
|
349
|
+
}}
|
|
350
|
+
/>
|
|
351
|
+
) : (
|
|
352
|
+
<div style={{ padding: 20 }}>
|
|
353
|
+
请先选择
|
|
354
|
+
<a
|
|
355
|
+
onClick={() =>
|
|
356
|
+
history.push('/rules-center/rules-of-the-scene')
|
|
357
|
+
}
|
|
358
|
+
>
|
|
359
|
+
模板
|
|
360
|
+
</a>
|
|
361
|
+
</div>
|
|
362
|
+
)}
|
|
363
|
+
</div>
|
|
364
|
+
</div>
|
|
365
|
+
</div>
|
|
366
|
+
</Spin>
|
|
367
|
+
);
|
|
368
|
+
});
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
// expression规则集合
|
|
2
|
+
//{
|
|
3
|
+
// complex,
|
|
4
|
+
// dataTypeCode,
|
|
5
|
+
// elementId,
|
|
6
|
+
// elementName,
|
|
7
|
+
// metaObjectCode,
|
|
8
|
+
// operationCode,
|
|
9
|
+
// operationType,
|
|
10
|
+
// paramNames: [],
|
|
11
|
+
// params: [],
|
|
12
|
+
// propertyPath,
|
|
13
|
+
// subExpression: [
|
|
14
|
+
// complex,
|
|
15
|
+
// dataTypeCode,
|
|
16
|
+
// elementId,
|
|
17
|
+
// elementName,
|
|
18
|
+
// metaObjectCode,
|
|
19
|
+
// operationCode,
|
|
20
|
+
// operationType,
|
|
21
|
+
// paramNames: [],
|
|
22
|
+
// params: [],
|
|
23
|
+
// propertyPath,
|
|
24
|
+
// subExpression: [.....] // 继续嵌套
|
|
25
|
+
// ]
|
|
26
|
+
// }
|
|
27
|
+
// result 执行返回值/执行动作
|
|
28
|
+
//{
|
|
29
|
+
// "return": {
|
|
30
|
+
// "enable": true,
|
|
31
|
+
// "value": "ticketId"
|
|
32
|
+
// },
|
|
33
|
+
// "execute": [
|
|
34
|
+
// {
|
|
35
|
+
// "priority": 1,
|
|
36
|
+
// "code": "functionCode",
|
|
37
|
+
// "properties": {
|
|
38
|
+
// "${logisticsNum}": "dasdadasdadas"
|
|
39
|
+
// }
|
|
40
|
+
// },
|
|
41
|
+
// {
|
|
42
|
+
// "priority": 2,
|
|
43
|
+
// "code": "",
|
|
44
|
+
// "properties": {
|
|
45
|
+
// "${detailList.skuCode}": "ccxcx",
|
|
46
|
+
// "${logisticsNum}": "cxcxcx"
|
|
47
|
+
// }
|
|
48
|
+
// }
|
|
49
|
+
// ]
|
|
50
|
+
// }
|
|
51
|
+
export const formatOperationList = (data: any) => {
|
|
52
|
+
let result = data||[];
|
|
53
|
+
result = result.concat([{
|
|
54
|
+
code: 32,
|
|
55
|
+
name: 'dateTime',
|
|
56
|
+
operationList: result.find((s: any)=> s.code ==41)?.operationList || []
|
|
57
|
+
}])
|
|
58
|
+
// 新版基础中对象字段编码valueType和旧版中valueType枚举不一致,如果没有取到符号值--需要排查数据后端是否做了映射转化; 按照oldValueType进行匹配符号和第三个参数框的
|
|
59
|
+
// const oldValueType = Object.freeze({
|
|
60
|
+
// 10: '对象',
|
|
61
|
+
// 21: '字符串',
|
|
62
|
+
// 23: '长整数',
|
|
63
|
+
// 22: '小数',
|
|
64
|
+
// 41: '日期',
|
|
65
|
+
// 40: '时间',
|
|
66
|
+
// 30: '数组',
|
|
67
|
+
// 24: '布尔值',
|
|
68
|
+
// });
|
|
69
|
+
// const newValueType = {
|
|
70
|
+
// 10: '字符串',
|
|
71
|
+
// 20: '短整数',
|
|
72
|
+
// 21: '长整数',
|
|
73
|
+
// 22: '小数',
|
|
74
|
+
// 40: '数组',
|
|
75
|
+
// 41: '布尔值',
|
|
76
|
+
// 12: '富文本',
|
|
77
|
+
// 30: '日期',
|
|
78
|
+
// 31: '时间',
|
|
79
|
+
// 32: '日期时间',
|
|
80
|
+
// }
|
|
81
|
+
return result;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const formatRegularList = (data: any) => {
|
|
85
|
+
let result = data;
|
|
86
|
+
return result;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// 回显规则处理数据
|
|
90
|
+
export const handleRuleShowBack = (data: any, functionRuleList: any) => {
|
|
91
|
+
let result = data?.map((item: any, index: number) => {
|
|
92
|
+
const handleResult = {
|
|
93
|
+
response: {
|
|
94
|
+
inputType: item?.result?.response?.inputType,
|
|
95
|
+
formulaName: item?.result?.response?.formulaName,
|
|
96
|
+
enable: item?.result?.response?.enable !== false,
|
|
97
|
+
value: item?.result?.response?.value || '',
|
|
98
|
+
},
|
|
99
|
+
execute:
|
|
100
|
+
(functionRuleList?.length &&
|
|
101
|
+
functionRuleList.map((s: any, index: number) => {
|
|
102
|
+
const Item = (item?.result?.execute || []).find(
|
|
103
|
+
(u: any) => u.code === s.code,
|
|
104
|
+
);
|
|
105
|
+
if (Item) {
|
|
106
|
+
return {
|
|
107
|
+
...Item,
|
|
108
|
+
properties: Item?.frontendProperties || Item?.properties,
|
|
109
|
+
isSelected: true,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
priority: index + 1,
|
|
114
|
+
code: s.code,
|
|
115
|
+
properties: {
|
|
116
|
+
configPropertyCode: 'configPropertyValue',
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
})) ||
|
|
120
|
+
[],
|
|
121
|
+
};
|
|
122
|
+
const restObject = {
|
|
123
|
+
extraInfo: handleResult,
|
|
124
|
+
id: item.id,
|
|
125
|
+
ruleId: item.ruleId,
|
|
126
|
+
priority: item.priority,
|
|
127
|
+
status: item.status,
|
|
128
|
+
extStrField01: item?.extStrField01,
|
|
129
|
+
name: item?.name,
|
|
130
|
+
};
|
|
131
|
+
if (item?.expression) {
|
|
132
|
+
return {
|
|
133
|
+
ruleName: item.ruleName || `规则${index + 1}`,
|
|
134
|
+
subExpression: item.expression,
|
|
135
|
+
...restObject,
|
|
136
|
+
};
|
|
137
|
+
} else {
|
|
138
|
+
return {
|
|
139
|
+
ruleName: `规则${index + 1}`,
|
|
140
|
+
subExpression: {
|
|
141
|
+
expressionType: 'relation',
|
|
142
|
+
operationType: 'relation',
|
|
143
|
+
propertyPath: '',
|
|
144
|
+
params: [],
|
|
145
|
+
paramNames: [],
|
|
146
|
+
},
|
|
147
|
+
...restObject,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
return result;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const isNoEmpty = (data: any) =>
|
|
155
|
+
(Array.isArray(data) && data.length > 0) ||
|
|
156
|
+
!(data == null || data == undefined || String(data).trim() == '');
|
|
157
|
+
|
|
158
|
+
// 校验执行动作必填数据
|
|
159
|
+
export const handleRuleRequireCheck = (saveData: any, ruleActionData: any) => {
|
|
160
|
+
let checkResult = false; // 默认通过校验
|
|
161
|
+
const checkInfo: any = []; // 没有选必填执行动作(暂不考虑);执行动作下的对象未选
|
|
162
|
+
if (Array.isArray(ruleActionData) && ruleActionData?.length && Array.isArray(saveData) && saveData.length) {
|
|
163
|
+
let requireList: any = [];
|
|
164
|
+
ruleActionData.forEach((s: any) => {
|
|
165
|
+
s.valueList.forEach((n: any) => {
|
|
166
|
+
if (n.required) {
|
|
167
|
+
if (requireList.some((m: any) => m.functionCode === s.code)) {
|
|
168
|
+
requireList = requireList.map((k: any) => {
|
|
169
|
+
if (k.functionCode === s.code) {
|
|
170
|
+
k.propertiesCode = [...k.propertiesCode, ...n.code];
|
|
171
|
+
}
|
|
172
|
+
return k;
|
|
173
|
+
});
|
|
174
|
+
} else {
|
|
175
|
+
requireList.push({
|
|
176
|
+
functionCode: s.code,
|
|
177
|
+
functionName: s.functionName,
|
|
178
|
+
propertiesCode: [n.code],
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
requireList?.length &&
|
|
186
|
+
saveData.forEach((s: any, index: number) => {
|
|
187
|
+
s.result.execute.length &&
|
|
188
|
+
s.result.execute.forEach((e: any) => {
|
|
189
|
+
if (requireList.some((r: any) => r.functionCode === e.code)) {
|
|
190
|
+
const currentRequireList = requireList.find(
|
|
191
|
+
(r: any) => r.functionCode === e.code,
|
|
192
|
+
);
|
|
193
|
+
const currentPropertiesCode = currentRequireList.propertiesCode;
|
|
194
|
+
const isComplete = currentPropertiesCode.every((c: any) =>
|
|
195
|
+
Object.keys(e.properties).some(
|
|
196
|
+
(p: any) => p === c && isNoEmpty(e.properties[p]),
|
|
197
|
+
),
|
|
198
|
+
);
|
|
199
|
+
if (!isComplete) {
|
|
200
|
+
checkResult = true;
|
|
201
|
+
checkInfo.push(
|
|
202
|
+
`规则${index + 1}: 执行动作【${
|
|
203
|
+
currentRequireList.functionName
|
|
204
|
+
}】信息填写不完整`,
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
return { checkResult, checkInfo };
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
function isObj(object: any) {
|
|
215
|
+
return (
|
|
216
|
+
object &&
|
|
217
|
+
typeof object == 'object' &&
|
|
218
|
+
Object.prototype.toString.call(object).toLowerCase() == '[object object]'
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// 保存规则处理数据
|
|
223
|
+
export const handleRuleResultList = (data: any, ruleTypeData: any) => {
|
|
224
|
+
let result = data || [];
|
|
225
|
+
if (Array.isArray(result) && result?.length) {
|
|
226
|
+
result = result.map((i: any) => {
|
|
227
|
+
return {
|
|
228
|
+
expression: i?.subExpression, // 左侧规则
|
|
229
|
+
result: {
|
|
230
|
+
...i?.extraInfo,
|
|
231
|
+
...(i?.extraInfo.execute
|
|
232
|
+
? {
|
|
233
|
+
execute: i?.extraInfo.execute
|
|
234
|
+
.filter((s: any) => s.isSelected)
|
|
235
|
+
?.map((s: any) => {
|
|
236
|
+
const saveP = s.properties;
|
|
237
|
+
// 处理在执行动作配置中设置了默认值的
|
|
238
|
+
const ruleValueList = ruleTypeData.find(
|
|
239
|
+
(r: any) => r.code === s.code,
|
|
240
|
+
)?.valueList;
|
|
241
|
+
if (ruleValueList?.length) {
|
|
242
|
+
ruleValueList.forEach((r: any) => {
|
|
243
|
+
if (
|
|
244
|
+
r.defaultValue &&
|
|
245
|
+
r?.inputType === 10 &&
|
|
246
|
+
r?.valueType === 21 &&
|
|
247
|
+
saveP[r.code] === undefined
|
|
248
|
+
) {
|
|
249
|
+
saveP[r.code] = ' ';
|
|
250
|
+
} else if (r.defaultValue && !saveP[r.code]) {
|
|
251
|
+
saveP[r.code] = r.defaultValue;
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
delete saveP.configPropertyCode;
|
|
257
|
+
// 前端所需回显数据
|
|
258
|
+
s.frontendProperties = { ...s.properties };
|
|
259
|
+
// 格式化后端需要的数据
|
|
260
|
+
Object.keys(s.properties).forEach((p: any) => {
|
|
261
|
+
const v = s.properties[p];
|
|
262
|
+
if (Array.isArray(v)) {
|
|
263
|
+
s.properties = {
|
|
264
|
+
...s.properties,
|
|
265
|
+
[p]: v.map((m: any) => m.value || m).join(','),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
if (isObj(v)) {
|
|
269
|
+
s.properties = {
|
|
270
|
+
...s.properties,
|
|
271
|
+
[p]: v.value || v.PCDCode?.join('/'),
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
return s;
|
|
276
|
+
}),
|
|
277
|
+
}
|
|
278
|
+
: {}),
|
|
279
|
+
}, // 右侧信息
|
|
280
|
+
ruleName: i.ruleName,
|
|
281
|
+
ruleId: i.ruleId,
|
|
282
|
+
id: i.id,
|
|
283
|
+
priority: i.priority,
|
|
284
|
+
status: i.status,
|
|
285
|
+
extStrField01: i?.extStrField01,
|
|
286
|
+
name: i?.name,
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
return result;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
export const getInitClassData = (ruleTypeData: any) => {
|
|
294
|
+
const initClassData = [
|
|
295
|
+
{
|
|
296
|
+
ruleName: `规则1`,
|
|
297
|
+
subExpression: {
|
|
298
|
+
// "expressionType": "relation",
|
|
299
|
+
operationType: 'relation',
|
|
300
|
+
propertyPath: '',
|
|
301
|
+
params: [],
|
|
302
|
+
paramNames: [],
|
|
303
|
+
},
|
|
304
|
+
extraInfo: {
|
|
305
|
+
response: {
|
|
306
|
+
enable: false,
|
|
307
|
+
value: '',
|
|
308
|
+
},
|
|
309
|
+
execute: ruleTypeData?.map((s: any) => {
|
|
310
|
+
return {
|
|
311
|
+
priority: 1,
|
|
312
|
+
code: s.code,
|
|
313
|
+
properties: {
|
|
314
|
+
configPropertyCode: 'configPropertyValue',
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
}),
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
];
|
|
321
|
+
return initClassData;
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
export const formatGroupOtherPriorityList = (data: any, templateId: string) => {
|
|
325
|
+
const result = data.filter((i: any) => i.templateId !== templateId);
|
|
326
|
+
return result;
|
|
327
|
+
};
|
|
328
|
+
export const formatOtherPriorityList = (
|
|
329
|
+
data: any,
|
|
330
|
+
templateId: string,
|
|
331
|
+
extStr: string,
|
|
332
|
+
) => {
|
|
333
|
+
return data.filter(
|
|
334
|
+
(i: any) => i.templateId != templateId || i.extStrField01 != extStr,
|
|
335
|
+
);
|
|
336
|
+
};
|