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();
|
}
|
}
|