package com.qianwen.smartman.modules.system.service.impl; import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.regex.Pattern; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.qianwen.core.log.exception.ServiceException; import com.qianwen.core.mp.base.BaseServiceImpl; import com.qianwen.core.redis.cache.BladeRedis; import com.qianwen.core.secure.utils.AuthUtil; import com.qianwen.core.tool.api.R; import com.qianwen.core.tool.utils.Func; import com.qianwen.core.tool.utils.StringUtil; import com.qianwen.smartman.common.constant.CommonConstant; import com.qianwen.smartman.common.constant.DncConstant; import com.qianwen.smartman.common.utils.MessageUtils; import com.qianwen.smartman.modules.cps.entity.Employee; import com.qianwen.smartman.modules.cps.service.IEmployeeService; import com.qianwen.smartman.modules.cps.vo.HierarchyVO; import com.qianwen.smartman.modules.system.constant.FieldConstant; import com.qianwen.smartman.modules.system.convert.CustomTemplateFieldConvert; import com.qianwen.smartman.modules.system.dto.CustomTemplateColumnDTO; import com.qianwen.smartman.modules.system.entity.CustomTemplate; import com.qianwen.smartman.modules.system.entity.CustomTemplateField; import com.qianwen.smartman.modules.system.entity.CustomTemplateFieldOption; import com.qianwen.smartman.modules.system.entity.CustomTemplateFieldRelation; import com.qianwen.smartman.modules.system.enums.ConfigTypeEnum; import com.qianwen.smartman.modules.system.enums.CustomFieldTypeEnums; import com.qianwen.smartman.modules.system.mapper.CustomTemplateFieldMapper; import com.qianwen.smartman.modules.system.service.ICustomTemplateFieldOptionService; import com.qianwen.smartman.modules.system.service.ICustomTemplateFieldRelationService; import com.qianwen.smartman.modules.system.service.ICustomTemplateFieldService; import com.qianwen.smartman.modules.system.service.ICustomTemplateService; import com.qianwen.smartman.modules.system.vo.CustomFieldRelationInfoVO; import com.qianwen.smartman.modules.system.vo.CustomFieldRelationListVO; import com.qianwen.smartman.modules.system.vo.CustomFieldRelationSelectVO; import com.qianwen.smartman.modules.system.vo.CustomTemplateFieldColumnVO; import com.qianwen.smartman.modules.system.vo.CustomTemplateFieldListVO; import com.qianwen.smartman.modules.system.vo.CustomTemplateFieldSubmitVO; import com.qianwen.smartman.modules.system.vo.CustomTemplateFieldUpdateVO; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.lang.Snowflake; import cn.hutool.core.util.IdUtil; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; @Service public class CustomTemplateFieldServiceImpl extends BaseServiceImpl implements ICustomTemplateFieldService { @Autowired private ICustomTemplateFieldOptionService customTemplateFieldOptionService; @Autowired @Lazy private ICustomTemplateService customTemplateService; @Autowired private CustomTemplateFieldMapper customTemplateFieldMapper; @Autowired private ICustomTemplateFieldRelationService customTemplateFieldRelationService; @Autowired private IEmployeeService employeeService; public static final List CUSTOM_FIELD_TYPE_LIST = Arrays.asList(CustomFieldTypeEnums.SELECT.getType(), CustomFieldTypeEnums.MULTI_SELECT.getType(), CustomFieldTypeEnums.DROP_DOWN.getType(), CustomFieldTypeEnums.CASCADE_SELECT.getType()); @Autowired private BladeRedis bladeRedis; @Override // org.springblade.modules.system.service.ICustomTemplateFieldService @Transactional(rollbackFor = {Exception.class}) public CustomTemplateField saveField(CustomTemplateFieldSubmitVO customTemplateFieldSubmitVO) { if (checkNameIsExist(customTemplateFieldSubmitVO.getId(), customTemplateFieldSubmitVO.getFieldName(), customTemplateFieldSubmitVO.getBusinessType())) { throw new ServiceException(MessageUtils.message("template.field.name.already.exist", new Object[0])); } CustomTemplateField customTemplateField = CustomTemplateFieldConvert.INSTANCE.convert(customTemplateFieldSubmitVO); Integer fieldType = customTemplateFieldSubmitVO.getFieldType(); if (CUSTOM_FIELD_TYPE_LIST.contains(fieldType) && Func.isNotEmpty(customTemplateFieldSubmitVO.getPropertyJson())) { JSONObject propertyJson = JSONUtil.parseObj(customTemplateField.getPropertyJson()); List customTemplateFieldOptions = optionFieldJsonToBean(propertyJson, customTemplateField.getId()); this.customTemplateFieldOptionService.saveBatch(customTemplateFieldOptions); propertyJson.remove(FieldConstant.OPTION_NAME); if (fieldType.equals(CustomFieldTypeEnums.SELECT.getType()) || fieldType.equals(CustomFieldTypeEnums.MULTI_SELECT.getType())) { Map optionMap = customTemplateFieldOptions.stream().collect(Collectors.toMap(c -> { return c.getKey() + ":" + c.getValue(); }, c2 -> { return String.valueOf(c2.getId()); })); Object vaStr = fieldType.equals(CustomFieldTypeEnums.SELECT.getType()) ? handlerSelectValue(customTemplateField.getPropertyJson(), optionMap) : handlerMultiValue(customTemplateField.getPropertyJson(), optionMap); propertyJson.put(FieldConstant.SELECT_OPTION, vaStr); } customTemplateField.setPropertyJson(propertyJson.toString()); } save(customTemplateField); return customTemplateField; } private String handlerSelectValue(String propertyJson, Map optionMap) { JSONObject json = JSONUtil.parseObj(propertyJson); String selectOption = json.getStr(FieldConstant.SELECT_OPTION); List optionBeans = json.getJSONArray(FieldConstant.OPTION_NAME).toList(OptionBean.class); return getOptionIdByDefaultValue(selectOption, optionBeans, optionMap); } private String getOptionIdByDefaultValue(String defaultValue, List optionBeans, Map optionMap) { for (OptionBean option : optionBeans) { if (option.getValue().equals(defaultValue)) { return optionMap.get(option.getValue() + ":" + option.getLabel()); } } return ""; } private List handlerMultiValue(String propertyJson, Map optionMap) { JSONObject json = JSONUtil.parseObj(propertyJson); JSONArray selectOptions = json.getJSONArray(FieldConstant.SELECT_OPTION); List optionBeans = json.getJSONArray(FieldConstant.OPTION_NAME).toList(OptionBean.class); List optionIds = new ArrayList<>(); selectOptions.forEach(op -> { optionIds.add(getOptionIdByDefaultValue(String.valueOf(op), optionBeans, optionMap)); }); return optionIds; } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/system/service/impl/CustomTemplateFieldServiceImpl$OptionBean.class */ public static class OptionBean { private String label; private String value; private List children; /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/system/service/impl/CustomTemplateFieldServiceImpl$OptionBean$OptionBeanBuilder.class */ public static class OptionBeanBuilder { private String label; private String value; private List children; OptionBeanBuilder() { } public OptionBeanBuilder label(final String label) { this.label = label; return this; } public OptionBeanBuilder value(final String value) { this.value = value; return this; } public OptionBeanBuilder children(final List children) { this.children = children; return this; } public OptionBean build() { return new OptionBean(this.label, this.value, this.children); } public String toString() { return "CustomTemplateFieldServiceImpl.OptionBean.OptionBeanBuilder(label=" + this.label + ", value=" + this.value + ", children=" + this.children + ")"; } } public void setLabel(final String label) { this.label = label; } public void setValue(final String value) { this.value = value; } public void setChildren(final List children) { this.children = children; } public boolean equals(final Object o) { if (o == this) { return true; } if (o instanceof OptionBean) { OptionBean other = (OptionBean) o; if (other.canEqual(this)) { Object this$label = getLabel(); Object other$label = other.getLabel(); if (this$label == null) { if (other$label != null) { return false; } } else if (!this$label.equals(other$label)) { return false; } Object this$value = getValue(); Object other$value = other.getValue(); if (this$value == null) { if (other$value != null) { return false; } } else if (!this$value.equals(other$value)) { return false; } Object this$children = getChildren(); Object other$children = other.getChildren(); return this$children == null ? other$children == null : this$children.equals(other$children); } return false; } return false; } protected boolean canEqual(final Object other) { return other instanceof OptionBean; } public int hashCode() { Object $label = getLabel(); int result = (1 * 59) + ($label == null ? 43 : $label.hashCode()); Object $value = getValue(); int result2 = (result * 59) + ($value == null ? 43 : $value.hashCode()); Object $children = getChildren(); return (result2 * 59) + ($children == null ? 43 : $children.hashCode()); } public String toString() { return "CustomTemplateFieldServiceImpl.OptionBean(label=" + getLabel() + ", value=" + getValue() + ", children=" + getChildren() + ")"; } OptionBean(final String label, final String value, final List children) { this.label = label; this.value = value; this.children = children; } public static OptionBeanBuilder builder() { return new OptionBeanBuilder(); } public String getLabel() { return this.label; } public String getValue() { return this.value; } public List getChildren() { return this.children; } } private List optionFieldJsonToBean(JSONObject propertyJson, Long fieldId) { Snowflake snowflake = IdUtil.getSnowflake(1L, 1L); JSONArray optionArray = propertyJson.getJSONArray(FieldConstant.OPTION_NAME); if (optionArray.isEmpty()) { return new ArrayList<>(); } return parseOptionJsonToBean(optionArray, fieldId, snowflake, FieldConstant.PARENT_ID); } private List parseOptionJsonToBean(JSONArray parentArray, Long fieldId, Snowflake snowflake, Long parentId) { List result = new ArrayList<>(); List tempList = new ArrayList<>(); Iterator it = parentArray.iterator(); while (it.hasNext()) { Object obj = it.next(); long id = snowflake.nextId(); JSONObject valueObj = (JSONObject) obj; JSONArray children = valueObj.getJSONArray(FieldConstant.CHILDREN_NAME); CustomTemplateFieldOption customTemplateFieldOption = new CustomTemplateFieldOption(); customTemplateFieldOption.setId(Long.valueOf(id)); customTemplateFieldOption.setFieldId(fieldId); customTemplateFieldOption.setValue(valueObj.getStr(FieldConstant.OPTION_LABEL)); customTemplateFieldOption.setKey(valueObj.getStr(FieldConstant.OPTION_KEY)); customTemplateFieldOption.setParentId(parentId); if (tempList.contains(customTemplateFieldOption.getValue())) { throw new ServiceException(MessageUtils.message("template.field.option.already.exist", new Object[0])); } tempList.add(customTemplateFieldOption.getValue()); result.add(customTemplateFieldOption); if (CollectionUtil.isNotEmpty(children)) { result.addAll(parseOptionJsonToBean(children, fieldId, snowflake, Long.valueOf(id))); } } return result; } @Override // org.springblade.modules.system.service.ICustomTemplateFieldService @Transactional public CustomTemplateField updateField(CustomTemplateFieldUpdateVO fieldSubmitVO) { if (checkNameIsExist(fieldSubmitVO.getId(), fieldSubmitVO.getFieldName(), fieldSubmitVO.getBusinessType())) { throw new ServiceException(MessageUtils.message("template.field.name.already.exist", new Object[0])); } CustomTemplateField customTemplateField = CustomTemplateFieldConvert.INSTANCE.convertUpdateVO(fieldSubmitVO); updateById(customTemplateField); CustomTemplateField field = (CustomTemplateField) getById(fieldSubmitVO.getId()); this.bladeRedis.del(FieldConstant.getFieldCacheKey(field.getFieldCode(), field.getBusinessType())); return field; } @Override // org.springblade.modules.system.service.ICustomTemplateFieldService public R removeFields(List ids) { if (!checkRemove(ids)) { throw new ServiceException(MessageUtils.message("template.field.use.not.remove", new Object[0])); } List fields = list(Wrappers.lambdaQuery().in(CustomTemplateField::getId, ids).in((ids.size() != 1), CustomTemplateField::getFieldType, CUSTOM_FIELD_TYPE_LIST)); /* List fields = list(((LambdaQueryWrapper) Wrappers.lambdaQuery().in((v0) -> { return v0.getId(); }, ids)).in(ids.size() != 1, (v0) -> { return v0.getFieldType(); }, CUSTOM_FIELD_TYPE_LIST));*/ if (CollectionUtil.isNotEmpty(fields)) { this.customTemplateFieldOptionService.remove(Wrappers.lambdaQuery().in(CustomTemplateFieldOption::getFieldId, ids)); /* this.customTemplateFieldOptionService.remove((Wrapper) Wrappers.lambdaQuery().in((v0) -> { return v0.getFieldId(); }, ids));*/ } fields.forEach(field -> { this.bladeRedis.del(FieldConstant.getFieldCacheKey(field.getFieldCode(), field.getBusinessType())); }); return R.status(removeByIds(ids)); } @Override // org.springblade.modules.system.service.ICustomTemplateFieldService public CustomFieldRelationSelectVO getSelectBox(Long templateId, Integer configType) { CustomTemplate customTemplate = this.customTemplateService.getOne(Wrappers.lambdaQuery().eq(CustomTemplate::getId, templateId)); /* CustomTemplate customTemplate = (CustomTemplate) this.customTemplateService.getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getId(); }, templateId));*/ List columnDTOList = fieldsOptionBeanToJson(CustomTemplateFieldConvert.INSTANCE.convertColumn(this.customTemplateFieldMapper.getSelectBox(customTemplate.getBusinessType(), templateId, configType))); List result = CustomTemplateFieldConvert.INSTANCE.convertRelationInfos(columnDTOList); CustomFieldRelationSelectVO customFieldRelationSelectVO = new CustomFieldRelationSelectVO(); if (Func.isNotEmpty(result)) { Map> groupResult = result.stream().collect(Collectors.groupingBy((v0) -> { return v0.getSystemField(); })); customFieldRelationSelectVO.setCustomFieldList(groupResult.get(0)); List customFieldRelationInfoVOS = groupResult.get(1); if (Func.equals(ConfigTypeEnum.ORDER_PAGE.getCode(), configType)) { customFieldRelationInfoVOS.forEach(item -> { item.setSysFieldMust(CommonConstant.DEACTIVATE); }); } customFieldRelationSelectVO.setSystemFieldList(customFieldRelationInfoVOS); } return customFieldRelationSelectVO; } @Override // org.springblade.modules.system.service.ICustomTemplateFieldService public CustomFieldRelationListVO listField(Long templateId, Integer configType) { List customTemplateFieldListVOS = this.customTemplateFieldMapper.listField(templateId, configType); CustomFieldRelationListVO customFieldRelationListVO = new CustomFieldRelationListVO(); if (Func.isNotEmpty(customTemplateFieldListVOS)) { Map> groupResult = customTemplateFieldListVOS.stream().collect(Collectors.groupingBy((v0) -> { return v0.getSystemField(); })); customFieldRelationListVO.setCustomFieldList(groupResult.get(0)); customFieldRelationListVO.setSystemFieldList(groupResult.get(1)); } return customFieldRelationListVO; } @Override // org.springblade.modules.system.service.ICustomTemplateFieldService public CustomTemplateField findFieldById(Long id) { CustomTemplateField customTemplateField = (CustomTemplateField) getById(id); if (Func.isNull(customTemplateField)) { return new CustomTemplateField(); } optionFieldHandler(customTemplateField); return customTemplateField; } private void optionFieldHandler(CustomTemplateField customTemplateField) { if (!CUSTOM_FIELD_TYPE_LIST.contains(customTemplateField.getFieldType())) { return; } List templateFieldOptions = this.customTemplateFieldOptionService.list(Wrappers.lambdaQuery().eq(CustomTemplateFieldOption::getFieldId, customTemplateField.getId())); /* List templateFieldOptions = this.customTemplateFieldOptionService.list((Wrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getFieldId(); }, customTemplateField.getId()));*/ if (CollectionUtil.isEmpty(templateFieldOptions)) { return; } String jsonHandler = optionFieldBeanToJson(templateFieldOptions, customTemplateField.getPropertyJson()); customTemplateField.setPropertyJson(jsonHandler); } /* JADX WARN: Multi-variable type inference failed */ @Override // org.springblade.modules.system.service.ICustomTemplateFieldService public Object fieldCheck(Integer businessType, String fieldCode, String value) { String[] split; CustomTemplateField customTemplateField = getField(fieldCode, businessType); if (Func.isEmpty(customTemplateField)) { throw new RuntimeException("扩展字段不存在"); } Integer fieldType = customTemplateField.getFieldType(); String propJson = customTemplateField.getPropertyJson(); if (Func.isEmpty(value)) { if (fieldType.equals(CustomFieldTypeEnums.MULTI_SELECT.getType()) || fieldType.equals(CustomFieldTypeEnums.CASCADE_SELECT.getType())) { return new ArrayList<>(); } return ""; } Object result = value; com.alibaba.fastjson.JSONObject propObject = com.alibaba.fastjson.JSONObject.parseObject(propJson); if (fieldType.equals(CustomFieldTypeEnums.INPUT.getType())) { Integer maxlength = propObject.getInteger("maxlength"); if (value.length() > maxlength.intValue()) { throw new RuntimeException(customTemplateField.getFieldName() + "超出长度"); } String formatName = propObject.getString("formatName"); if (formatName.equals("mobile")) { if (!Pattern.matches("^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$", value)) { throw new RuntimeException(customTemplateField.getFieldName() + "手机号码不匹配"); } } else if (formatName.equals("telephone")) { Boolean flag = Boolean.valueOf(Pattern.matches("^[0][1-9]{2,3}-[0-9]{5,10}$", value) || Pattern.matches("^[1-9]{1}[0-9]{5,8}$", value)); if (!flag.booleanValue()) { throw new RuntimeException(customTemplateField.getFieldName() + "电话号码不匹配"); } } else if (formatName.equals("email") && !Pattern.matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", value)) { throw new RuntimeException(customTemplateField.getFieldName() + "邮箱不匹配"); } } else if (fieldType.equals(CustomFieldTypeEnums.DIGITAL_INPUT.getType())) { if (!Pattern.matches("-?[0-9]+.?[0-9]{0,}", value)) { throw new RuntimeException(customTemplateField.getFieldName() + "非数字"); } Float floatValue = Float.valueOf(value); Integer rangeMin = propObject.getInteger("rangeMin"); Integer rangeMax = propObject.getInteger("rangeMax"); Integer saveDecimalNum = propObject.getInteger(FieldConstant.SAVE_DECIMAL_NUM); if (floatValue.floatValue() > rangeMax.intValue() || floatValue.floatValue() < rangeMin.intValue()) { throw new RuntimeException(customTemplateField.getFieldName() + "不在限定数值范围内"); } if (value.contains(DncConstant.POINT)) { result = BigDecimal.valueOf(floatValue.floatValue()).setScale(saveDecimalNum.intValue(), 1).toString(); } } else if (fieldType.equals(CustomFieldTypeEnums.MULTI_TEXT.getType())) { Integer maxlength2 = propObject.getInteger("maxlength"); if (value.length() > maxlength2.intValue()) { throw new RuntimeException(customTemplateField.getFieldName() + "超出长度"); } } else if (fieldType.equals(CustomFieldTypeEnums.DATE.getType())) { com.alibaba.fastjson.JSONObject valObject = propObject.getJSONObject("val"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat(valObject.getString(FieldConstant.NUM_FORMAT)); try { simpleDateFormat.parse(value); } catch (ParseException e) { throw new RuntimeException(customTemplateField.getFieldName() + "时间格式错误"); } } else if (fieldType.equals(CustomFieldTypeEnums.SELECT.getType())) { if (Func.isEmpty(customTemplateField)) { throw new RuntimeException(customTemplateField.getFieldName() + "导入字段不存在"); } Map transMap = customTemplateField.getOptionList().stream().collect(Collectors.toMap((v0) -> { return v0.getValue(); }, o -> { return o; })); if (transMap.containsKey(value)) { result = String.valueOf(transMap.get(value).getId()); } else { throw new RuntimeException(customTemplateField.getFieldName() + "输入内容在选项值中不存在"); } } else if (fieldType.equals(CustomFieldTypeEnums.MULTI_SELECT.getType())) { if (Func.isEmpty(customTemplateField)) { throw new RuntimeException(customTemplateField.getFieldName() + "导入字段不存在"); } Map transMap2 = customTemplateField.getOptionList().stream().collect(Collectors.toMap((v0) -> { return v0.getValue(); }, o2 -> { return o2; })); List optionIds = new ArrayList<>(); if (value.contains(",")) { for (String split2 : value.split(",")) { if (transMap2.containsKey(split2)) { optionIds.add(String.valueOf(transMap2.get(split2).getId())); } else { throw new RuntimeException(customTemplateField.getFieldName() + "输入内容在选项值中不存在"); } } } else if (transMap2.containsKey(value)) { optionIds.add(String.valueOf(transMap2.get(value).getId())); } else { throw new RuntimeException(customTemplateField.getFieldName() + "输入内容在选项值中不存在"); } result = optionIds; } else if (fieldType.equals(CustomFieldTypeEnums.DROP_DOWN.getType())) { if (Func.isEmpty(customTemplateField)) { throw new RuntimeException(customTemplateField.getFieldName() + "导入字段不存在"); } Map transMap3 = customTemplateField.getOptionList().stream().collect(Collectors.toMap((v0) -> { return v0.getValue(); }, o3 -> { return o3; })); if (transMap3.containsKey(value)) { result = String.valueOf(transMap3.get(value).getId()); } else { throw new RuntimeException(customTemplateField.getFieldName() + "输入内容在选项值中不存在"); } } else if (fieldType.equals(CustomFieldTypeEnums.CASCADE_SELECT.getType())) { Boolean flag2 = Boolean.valueOf(!value.contains(",") || value.startsWith(",") || value.endsWith(",") || value.length() < 3); if (flag2.booleanValue()) { throw new RuntimeException(customTemplateField.getFieldName() + "级联选择器需按逗号分隔填入两个值"); } if (Func.isEmpty(customTemplateField)) { throw new RuntimeException(customTemplateField.getFieldName() + "导入字段不存在"); } List customTemplateFieldOptions = customTemplateField.getOptionList(); Map parentMap = customTemplateFieldOptions.stream().filter(o4 -> { return o4.getParentId().equals(0L); }).collect(Collectors.toMap((v0) -> { return v0.getValue(); }, o5 -> { return o5; })); List optionIds2 = new ArrayList<>(); String[] values = value.split(","); if (parentMap.containsKey(values[0])) { CustomTemplateFieldOption pCustomTemplateFieldOption = parentMap.get(values[0]); optionIds2.add(String.valueOf(pCustomTemplateFieldOption.getId())); Map childMap = customTemplateFieldOptions.stream().filter(o6 -> { return o6.getParentId().equals(pCustomTemplateFieldOption.getId()); }).collect(Collectors.toMap((v0) -> { return v0.getValue(); }, o7 -> { return o7; })); if (childMap.containsKey(values[1])) { optionIds2.add(String.valueOf(childMap.get(values[1]).getId())); result = optionIds2; } else { throw new RuntimeException(customTemplateField.getFieldName() + "输入内容在选项值中不存在"); } } else { throw new RuntimeException(customTemplateField.getFieldName() + "输入内容在选项值中不存在"); } } else if (fieldType.equals(CustomFieldTypeEnums.BUSINESS.getType())) { Employee employee = this.employeeService.getOne(Wrappers.lambdaQuery().eq(Employee::getJobNumber, value)); /* Employee employee = (Employee) this.employeeService.getOne((Wrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getJobNumber(); }, value));*/ if (Func.isEmpty(employee)) { throw new RuntimeException(customTemplateField.getFieldName() + "员工不存在"); } HierarchyVO employeeHierarchy = this.employeeService.getEmployeeHierarchy(employee.getId()); result = StringUtil.join(employeeHierarchy.getIdList(), ","); } return result; } @Override // org.springblade.modules.system.service.ICustomTemplateFieldService public CustomTemplateField getField(String fieldCode, Integer busType) { Object cacheObj = this.bladeRedis.get(FieldConstant.getFieldCacheKey(fieldCode, busType)); if (Func.isNotEmpty(cacheObj)) { return (CustomTemplateField) Convert.convert(CustomTemplateField.class, cacheObj); } if (Func.isEmpty(fieldCode)) { return null; } CustomTemplateField customTemplateField = getOne(Wrappers.lambdaQuery().eq(CustomTemplateField::getFieldCode, fieldCode).eq(CustomTemplateField::getBusinessType, busType)); /* CustomTemplateField customTemplateField = (CustomTemplateField) getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getFieldCode(); }, fieldCode)).eq((v0) -> { return v0.getBusinessType(); }, busType));*/ if (Func.isEmpty(customTemplateField)) { customTemplateField = new CustomTemplateField(1); } if (CUSTOM_FIELD_TYPE_LIST.contains(customTemplateField.getFieldType())) { optionFieldHandler(customTemplateField); List templateFieldOptions = this.customTemplateFieldOptionService.list(Wrappers.lambdaQuery().eq(CustomTemplateFieldOption::getFieldId, customTemplateField.getId())); /* List templateFieldOptions = this.customTemplateFieldOptionService.list((Wrapper) Wrappers.lambdaQuery().eq((v0) -> { return v0.getFieldId(); }, customTemplateField.getId()));*/ customTemplateField.setOptionList(templateFieldOptions); } this.bladeRedis.setEx(FieldConstant.getFieldCacheKey(fieldCode, busType), customTemplateField, FieldConstant.CACHE_TIMEOUT); return customTemplateField; } @Override // org.springblade.modules.system.service.ICustomTemplateFieldService public List getColumns(Long templateId, Integer configType) { List result = this.customTemplateFieldMapper.getColumns(templateId, configType); editPageMustFieldHandler(result, templateId, configType); fieldsOptionBeanToJson(result); return CustomTemplateFieldConvert.INSTANCE.convertColumns(result); } private void editPageMustFieldHandler(List result, Long templateId, Integer configType) { if (!ConfigTypeEnum.EDIT_PAGE.getCode().equals(configType)) { return; } List addList = this.customTemplateFieldMapper.getColumns(templateId, ConfigTypeEnum.NEW_PAGE.getCode()); Map tempMap = (Map) addList.stream().collect(Collectors.toMap((v0) -> { return v0.getFieldCode(); }, o -> { return o; }, (o2, n) -> { return o2; })); result.forEach(r -> { CustomTemplateColumnDTO customTemplateColumnDTO = (CustomTemplateColumnDTO) tempMap.get(r.getFieldCode()); if (Func.isEmpty(customTemplateColumnDTO)) { return; } r.setMustField(customTemplateColumnDTO.getMustField()); }); System.out.println("---"); } private List fieldsOptionBeanToJson(List result) { if (Func.isEmpty(result)) { return result; } List optionFields = result.stream().filter(field -> { return CUSTOM_FIELD_TYPE_LIST.contains(field.getFieldType()); }).collect(Collectors.toList()); if (Func.isEmpty(optionFields)) { return result; } List ids = optionFields.stream().map((v0) -> { return v0.getFieldId(); }).collect(Collectors.toList()); List templateFieldOptions = this.customTemplateFieldOptionService.list(Wrappers.lambdaQuery().in(CustomTemplateFieldOption::getFieldId, ids)); /* List templateFieldOptions = this.customTemplateFieldOptionService.list((Wrapper) Wrappers.lambdaQuery().in((v0) -> { return v0.getFieldId(); }, ids));*/ Map> optionMap = templateFieldOptions.stream().collect(Collectors.groupingBy((v0) -> { return v0.getFieldId(); })); result.forEach(field2 -> { List customTemplateFieldOptions = optionMap.get(field2.getFieldId()); if (CollectionUtil.isEmpty(customTemplateFieldOptions)) { return; } field2.setOptionList(customTemplateFieldOptions); String fieldJsonHandler = optionFieldBeanToJson(customTemplateFieldOptions, field2.getPropertyJson()); field2.setPropertyJson(fieldJsonHandler); }); return result; } private String optionFieldBeanToJson(List customTemplateFields, String propertyJsonStr) { if (Func.isEmpty(customTemplateFields)) { return ""; } JSONObject propertyJson = JSONUtil.parseObj(propertyJsonStr); List optionBeanList = parseOptionBeanToJson(customTemplateFields, FieldConstant.PARENT_ID); propertyJson.put(FieldConstant.OPTION_NAME, new JSONArray(optionBeanList)); return propertyJson.toString(); } private static List parseOptionBeanToJson(List options, Long parentId) { List result = new ArrayList<>(); List parentOptions = options.stream().filter(o -> { return o.getParentId().equals(parentId); }).collect(Collectors.toList()); if (CollectionUtil.isEmpty(parentOptions)) { return null; } parentOptions.forEach(option -> { OptionBean optionBean = OptionBean.builder().label(option.getValue()).value(String.valueOf(option.getId())).children(parseOptionBeanToJson(options, option.getId())).build(); result.add(optionBean); }); return result; } private boolean checkNameIsExist(Long id, String name, Integer businessType) { List result = this.baseMapper.selectList(Wrappers.query().lambda() .eq(Func.isNotEmpty(AuthUtil.getTenantId()), CustomTemplateField::getTenantId, AuthUtil.getTenantId()) .eq(Func.isNotBlank(name), CustomTemplateField::getFieldName, name) .eq(Func.isNotEmpty(businessType), CustomTemplateField::getBusinessType, businessType) .ne(Func.isNotEmpty(id), CustomTemplateField::getId, id)); /* List result = ((CustomTemplateFieldMapper) this.baseMapper).selectList(Wrappers.query().lambda().eq(Func.isNotEmpty(AuthUtil.getTenantId()), (v0) -> { return v0.getTenantId(); }, AuthUtil.getTenantId()).eq(Func.isNotBlank(name), (v0) -> { return v0.getFieldName(); }, name).eq(Func.isNotEmpty(businessType), (v0) -> { return v0.getBusinessType(); }, businessType).ne(Func.isNotEmpty(id), (v0) -> { return v0.getId(); }, id));*/ return result != null && result.size() > 0; } private boolean checkRemove(List ids) { long count = this.customTemplateFieldRelationService.count(Wrappers.lambdaQuery().in(CustomTemplateFieldRelation::getFieldId, ids)); /* long count = this.customTemplateFieldRelationService.count((Wrapper) Wrappers.lambdaQuery().in((v0) -> { return v0.getFieldId(); }, ids));*/ return count <= 0; } }