yangys
2024-04-01 86cdd920b68274185233383f69ddb974052b6b6f
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
package com.qianwen.smartman.modules.system.handler.field;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import java.util.stream.Collectors;
 
import org.springframework.stereotype.Component;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.common.constant.CommonConstant;
import com.qianwen.smartman.common.constant.DncConstant;
import com.qianwen.smartman.modules.cps.entity.Employee;
import com.qianwen.smartman.modules.cps.service.IEmployeeService;
import com.qianwen.smartman.modules.system.constant.FieldConstant;
import com.qianwen.smartman.modules.system.entity.CustomTemplateField;
import com.qianwen.smartman.modules.system.entity.CustomTemplateFieldOption;
import com.qianwen.smartman.modules.system.enums.ConfigTypeEnum;
import com.qianwen.smartman.modules.system.enums.CustomFieldTypeEnums;
import com.qianwen.smartman.modules.system.service.ICustomTemplateFieldService;
import com.qianwen.smartman.modules.system.service.impl.CustomTemplateFieldServiceImpl;
 
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
 
@Component
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/system/handler/field/ExtendFieldResultParse.class */
public class ExtendFieldResultParse {
    private final ICustomTemplateFieldService customTemplateFieldService;
    private final IEmployeeService employeeService;
    private static final List<Integer> CHECK_LIST = Arrays.asList(CustomFieldTypeEnums.CASCADE_SELECT.getType(), CustomFieldTypeEnums.MULTI_SELECT.getType(), CustomFieldTypeEnums.BUSINESS.getType());
    private static final List<Integer> IS_CHECK_TYPE = Arrays.asList(CustomFieldTypeEnums.INPUT.getType(), CustomFieldTypeEnums.DIGITAL_INPUT.getType(), CustomFieldTypeEnums.DATE.getType(), CustomFieldTypeEnums.MULTI_TEXT.getType());
 
    public ExtendFieldResultParse(final ICustomTemplateFieldService customTemplateFieldService, final IEmployeeService employeeService) {
        this.customTemplateFieldService = customTemplateFieldService;
        this.employeeService = employeeService;
    }
 
    public String handlerFieldQueryResult(Long templateId, String resultJson) {
        Map<String, CustomTemplateField> showFields = FieldCodeCache.getInstance().getFields(templateId, ConfigTypeEnum.VIEW_PAGE.getCode());
        if (Func.isEmpty(showFields)) {
            return resultJson;
        }
        JSONObject resJsonObj = JSONUtil.parseObj(resultJson);
        resJsonObj.forEach((fieldCode, value) -> {
            if (!showFields.containsKey(fieldCode) || Func.isEmpty(value)) {
                return;
            }
            CustomTemplateField field = (CustomTemplateField) showFields.get(fieldCode);
            if (Func.isEmpty(field)) {
                return;
            }
            Object val = filedResHandler(field, resJsonObj);
            resJsonObj.put(fieldCode, val);
        });
        return resJsonObj.toString();
    }
 
    public String handlerFieldDetailResult(Long templateId, String resultJson) {
        Map<String, CustomTemplateField> editFields = FieldCodeCache.getInstance().getFields(templateId, ConfigTypeEnum.EDIT_PAGE.getCode());
        if (Func.isEmpty(resultJson) || Func.isEmpty(editFields)) {
            return "";
        }
        JSONObject resObj = JSONUtil.parseObj(resultJson);
        resObj.forEach((fieldCode, value) -> {
            if (!editFields.containsKey(fieldCode)) {
                return;
            }
            CustomTemplateField field = (CustomTemplateField) editFields.get(fieldCode);
            if (Func.isEmpty(field) || !CHECK_LIST.contains(field.getFieldType())) {
                return;
            }
            List<String> temp = Func.toStrList(",", String.valueOf(value));
            resObj.put(fieldCode, temp);
        });
        return resObj.toString();
    }
 
    public void handlerFieldSaveOrUpdateCheck(String resultJson, Integer busType) {
        if (Func.isEmpty(resultJson)) {
            return;
        }
        JSONObject exJson = JSONUtil.parseObj(resultJson);
        for (Map.Entry<String, Object> entry : exJson.entrySet()) {
            CustomTemplateField field = this.customTemplateFieldService.getField(entry.getKey(), busType);
            if (!Func.isEmpty(field.getFieldCode()) && IS_CHECK_TYPE.contains(field.getFieldType())) {
                this.customTemplateFieldService.fieldCheck(busType, field.getFieldCode(), String.valueOf(entry.getValue()));
            }
        }
    }
 
    /* JADX WARN: Multi-variable type inference failed */
    private Map<String, CustomTemplateFieldOption> getOptionFieldOptionMap(CustomTemplateField field) {
        Map<String, CustomTemplateFieldOption> optionMap = new HashMap<>(16);
        if (CustomTemplateFieldServiceImpl.CUSTOM_FIELD_TYPE_LIST.contains(field.getFieldType())) {
            List<CustomTemplateFieldOption> fieldOptions = field.getOptionList();
            if (Func.isEmpty(fieldOptions)) {
                return optionMap;
            }
            optionMap = fieldOptions.stream().collect(Collectors.toMap(c -> {
                return String.valueOf(c.getId());
            }, o -> {
                return o;
            }, (old, newVal) -> {
                return old;
            }));
        }
        return optionMap;
    }
 
    private String filedResHandler(CustomTemplateField field, JSONObject resJsonObj) {
        Integer fieldType = field.getFieldType();
        CustomFieldTypeEnums fieldTypeEnums = CustomFieldTypeEnums.getEnum(fieldType);
        
        switch (fieldTypeEnums) {
        case MULTI_SELECT:
          return multiValueToStr(resJsonObj, field);
        case BUSINESS:
          return businessEmpToStr(resJsonObj, field.getFieldCode());
        case CASCADE_SELECT:
          return cascadeValueToStr(resJsonObj, field);
        case DIGITAL_INPUT:
          return digitalValueToStr(resJsonObj, field);
        case DROP_DOWN:
        case SELECT:
          return selectValueToStr(resJsonObj, field);
        default:
            return defaultValueToStr(resJsonObj, field);
      } 
      
        /*
        switch (AnonymousClass1.$SwitchMap$org$springblade$modules$system$enums$CustomFieldTypeEnums[fieldTypeEnums.ordinal()]) {
            case 1:
                return multiValueToStr(resJsonObj, field);
            case 2:
                return businessEmpToStr(resJsonObj, field.getFieldCode());
            case 3:
                return cascadeValueToStr(resJsonObj, field);
            case 4:
                return digitalValueToStr(resJsonObj, field);
            case RegionCache.VILLAGE_LEVEL // 5
            case 6:
                return selectValueToStr(resJsonObj, field);
            default:
                return defaultValueToStr(resJsonObj, field);
        }*/
    }
 
    private String defaultValueToStr(JSONObject resJsonObj, CustomTemplateField field) {
        return resJsonObj.getStr(field.getFieldCode());
    }
 
    private String digitalValueToStr(JSONObject resJsonObj, CustomTemplateField field) {
        double value = resJsonObj.getDouble(field.getFieldCode()).doubleValue();
        if (Func.isEmpty(Double.valueOf(value))) {
            return "";
        }
        String propertyJson = field.getPropertyJson();
        if (Func.isEmpty(propertyJson)) {
            return "";
        }
        JSONObject filedJson = JSONUtil.parseObj(propertyJson);
        Integer format = filedJson.getInt(FieldConstant.NUM_FORMAT);
        Boolean isShowPercentage = filedJson.getBool(FieldConstant.IS_SHOW_PERCENTAGE);
        Integer saveNum = filedJson.getInt(FieldConstant.SAVE_DECIMAL_NUM);
        String valueStr = decimalHandler(Double.valueOf(value), saveNum);
        if (format.equals(FieldConstant.IS_NUM)) {
            return isShowPercentage.booleanValue() ? numToKillSplit(valueStr) : valueStr;
        }
        return valueStr + "%";
    }
 
    private static String decimalHandler(Double value, Integer num) {
        return String.format("%." + num + "f", value);
    }
 
    private static String numToKillSplit(String value) {
        String temp;
        if (Func.isEmpty(value)) {
            return value;
        }
        boolean isDec = false;
        if (value.contains(DncConstant.POINT)) {
            temp = value.substring(0, value.lastIndexOf(DncConstant.POINT));
        } else {
            temp = value;
            isDec = true;
        }
        if (temp.length() < 4) {
            return value;
        }
        StringJoiner joinStr = new StringJoiner(",");
        for (int i = 1; i <= temp.length(); i += 3) {
            if (i == 1) {
                joinStr.add(temp.substring(0, i));
            } else {
                joinStr.add(temp.substring(i - 3, i));
                if (i + 3 > temp.length()) {
                    String lastValue = temp.substring(i);
                    if (Func.isNotEmpty(lastValue)) {
                        joinStr.add(lastValue);
                    }
                }
            }
        }
        return isDec ? joinStr.toString() : joinStr.toString() + value.substring(value.lastIndexOf(DncConstant.POINT));
    }
 
    private String cascadeValueToStr(JSONObject resJson, CustomTemplateField field) {
        String valueStr = resJson.getStr(field.getFieldCode());
        if (Func.isEmpty(valueStr)) {
            return "";
        }
        List<String> arrayValue = Func.toStrList(",", valueStr);
        if (arrayValue.size() != FieldConstant.CASCADE_LENGTH.intValue()) {
            return "";
        }
        Object jsonValue = arrayValue.get(CommonConstant.ONE.intValue());
        Map<String, CustomTemplateFieldOption> optionMap = getOptionFieldOptionMap(field);
        CustomTemplateFieldOption customTemplateFieldOption = optionMap.get(String.valueOf(jsonValue));
        if (Func.isEmpty(customTemplateFieldOption)) {
            return "";
        }
        return customTemplateFieldOption.getValue();
    }
 
    private String multiValueToStr(JSONObject resJson, CustomTemplateField field) {
        String value = resJson.getStr(field.getFieldCode());
        if (Func.isEmpty(value)) {
            return "";
        }
        List<String> temp = new ArrayList<>();
        List<String> values = Func.toStrList(",", value);
        Map<String, CustomTemplateFieldOption> optionMap = getOptionFieldOptionMap(field);
        values.forEach(aValue -> {
            CustomTemplateFieldOption customTemplateFieldOption = (CustomTemplateFieldOption) optionMap.get(String.valueOf(aValue));
            if (Func.isNotEmpty(customTemplateFieldOption)) {
                temp.add(customTemplateFieldOption.getValue());
            }
        });
        return Func.join(temp, ",");
    }
 
    private String selectValueToStr(JSONObject resJson, CustomTemplateField field) {
        String selectValue = resJson.getStr(field.getFieldCode());
        if (Func.isEmpty(selectValue)) {
            return "";
        }
        Map<String, CustomTemplateFieldOption> optionMap = getOptionFieldOptionMap(field);
        CustomTemplateFieldOption customTemplateFieldOption = optionMap.get(selectValue);
        if (Func.isEmpty(customTemplateFieldOption)) {
            return "";
        }
        return customTemplateFieldOption.getValue();
    }
 
    private String businessEmpToStr(JSONObject resJson, String fieldCode) {
        String empId = resJson.getStr(fieldCode);
        if (Func.isEmpty(empId)) {
            return "";
        }
        List<String> empList = Func.toStrList(",", empId);
        if (empList.size() < 2) {
            return "";
        }
        Employee employee = this.employeeService.getOne(Wrappers.<Employee>lambdaQuery().eq(Employee::getId, empList.get(empList.size() - 1))
                .select(Employee::getName));
        /*
        Employee employee = (Employee) this.employeeService.getOne(((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getId();
        }, empList.get(empList.size() - 1))).select(new SFunction[]{(v0) -> {
            return v0.getName();
        }}));*/
        if (Func.isEmpty(employee) || Func.isEmpty(employee.getName())) {
            return "";
        }
        return employee.getName();
    }
}