try { if (field.getEnum() != null && field.getEnum() && !StringUtils.isEmpty(field.getEnumString())) { Map<String, Object> enumMap = JSON.parseObject(field.getEnumString(), Map.class); if (!(isExport && null != field.getSelfDefine() && field.getSelfDefine() && null != field.getRefType() && "u8c-userdefine.pb_userdefine".equalsIgnoreCase(field.getRefType()))) { String enumType = field.getEnumType(); if ("BooleanEnum".equals(enumType) && isExport) { if (null == value) { String defaultValue = field.getDefaultValue(); value = BooleanUtils.b(defaultValue, false); } Map<String, String> valueMap = elasticEnumCache.get("aa_boolean"); if (MapUtils.isEmpty(valueMap)) { valueMap = mddMultiLangEnumService.getEnumMap("aa_boolean"); } if (MapUtils.isNotEmpty(valueMap)) { elasticEnumCache.put("aa_boolean", valueMap); } Object booleanValue = value; if (CalculationUtil.isNumeric(booleanValue.toString())) { booleanValue = BooleanUtils.b(booleanValue,false); } value = valueMap.get(Boolean.toString((Boolean) booleanValue)); } else if ("aa_boolean".equals(enumType) && isExport) { if (null == value) { String defaultValue = field.getDefaultValue(); value = BooleanUtils.b(defaultValue, false); } Object booleanValue = value; if (CalculationUtil.isNumeric(booleanValue.toString())) { booleanValue = BooleanUtils.b(booleanValue,false); } value = getEnumValue(booleanValue, enumMap); } else { value = getEnumValue(value, enumMap); } } if (isExport) { map.put(fieldCode, buildCellData(value, null)); } else { map.put(fieldCode, value); } } else if (isExport) { // 布尔类型进行特殊翻译 Property fieldProperty = null; if (null != iMetaEntity && StringUtils.isNotBlank(field.getFieldName())) { fieldProperty = POIUtils.getAttributeByFieldName(iMetaEntity, field.getFieldName()); } if (null != fieldProperty && fieldProperty.type() instanceof DataType && ((DataType) fieldProperty.type()).isBoolean()) { if (null == value) { String defaultValue = field.getDefaultValue(); value = BooleanUtils.b(defaultValue, false); } Map<String, String> enumMap = elasticEnumCache.get("aa_boolean"); if (MapUtils.isEmpty(enumMap)) { enumMap = mddMultiLangEnumService.getEnumMap("aa_boolean"); } if (MapUtils.isNotEmpty(enumMap)) { elasticEnumCache.put("aa_boolean", enumMap); } Object enumValue = null; Object booleanValue = value; if (CalculationUtil.isNumeric(booleanValue.toString())) { booleanValue = BooleanUtils.b(booleanValue,false); } enumValue = enumMap.get(Boolean.toString((Boolean) booleanValue)); if (MapUtils.isNotEmpty(enumMap) && null != enumValue) { map.put(fieldCode, buildCellData(enumValue, null)); } } else { String controlType = field.getControlType(); if (StringUtils.isNotBlank(controlType)) { if (controlType.equals("switch")) { Map<String, String> enumMap = elasticEnumCache.get("aa_boolean"); if (MapUtils.isEmpty(enumMap)) { enumMap = mddMultiLangEnumService.getEnumMap("aa_boolean"); } if (MapUtils.isNotEmpty(enumMap)) { elasticEnumCache.put("aa_boolean", enumMap); } Object enumValue = enumMap.get(Boolean.toString(PoiBooleanUtils.b(value))); if (MapUtils.isNotEmpty(enumMap) && null != enumValue) { map.put(fieldCode, buildCellData(enumValue, null)); } } } } } } catch (Exception e) { if (isExport) { map.put(fieldCode, buildCellData(value, null)); } else { map.put(fieldCode, value); } }

2023-04-19by@happylimy-O9biz&@GPT-4.Model: gpt-3.5
happylimy-O9biz

try {
if (field.getEnum() != null && field.getEnum() && !StringUtils.isEmpty(field.getEnumString())) {
Map<String, Object> enumMap = JSON.parseObject(field.getEnumString(), Map.class);
if (!(isExport && null != field.getSelfDefine() && field.getSelfDefine() && null != field.getRefType() && "u8c-userdefine.pb_userdefine".equalsIgnoreCase(field.getRefType()))) {
String enumType = field.getEnumType();
if ("BooleanEnum".equals(enumType) && isExport) {
if (null == value) {
String defaultValue = field.getDefaultValue();
value = BooleanUtils.b(defaultValue, false);
}
Map<String, String> valueMap = elasticEnumCache.get("aa_boolean");
if (MapUtils.isEmpty(valueMap)) {
valueMap = mddMultiLangEnumService.getEnumMap("aa_boolean");
}
if (MapUtils.isNotEmpty(valueMap)) {
elasticEnumCache.put("aa_boolean", valueMap);
}
Object booleanValue = value;
if (CalculationUtil.isNumeric(booleanValue.toString())) {
booleanValue = BooleanUtils.b(booleanValue,false);
}
value = valueMap.get(Boolean.toString((Boolean) booleanValue));
} else if ("aa_boolean".equals(enumType) && isExport) {
if (null == value) {
String defaultValue = field.getDefaultValue();
value = BooleanUtils.b(defaultValue, false);
}
Object booleanValue = value;
if (CalculationUtil.isNumeric(booleanValue.toString())) {
booleanValue = BooleanUtils.b(booleanValue,false);
}
value = getEnumValue(booleanValue, enumMap);
} else {
value = getEnumValue(value, enumMap);
}
}
if (isExport) {
map.put(fieldCode, buildCellData(value, null));
} else {
map.put(fieldCode, value);
}
} else if (isExport) {
// 布尔类型进行特殊翻译
Property fieldProperty = null;
if (null != iMetaEntity && StringUtils.isNotBlank(field.getFieldName())) {
fieldProperty = POIUtils.getAttributeByFieldName(iMetaEntity, field.getFieldName());
}
if (null != fieldProperty && fieldProperty.type() instanceof DataType && ((DataType) fieldProperty.type()).isBoolean()) {
if (null == value) {
String defaultValue = field.getDefaultValue();
value = BooleanUtils.b(defaultValue, false);
}
Map<String, String> enumMap = elasticEnumCache.get("aa_boolean");
if (MapUtils.isEmpty(enumMap)) {
enumMap = mddMultiLangEnumService.getEnumMap("aa_boolean");
}
if (MapUtils.isNotEmpty(enumMap)) {
elasticEnumCache.put("aa_boolean", enumMap);
}
Object enumValue = null;
Object booleanValue = value;
if (CalculationUtil.isNumeric(booleanValue.toString())) {
booleanValue = BooleanUtils.b(booleanValue,false);
}
enumValue = enumMap.get(Boolean.toString((Boolean) booleanValue));
if (MapUtils.isNotEmpty(enumMap) && null != enumValue) {
map.put(fieldCode, buildCellData(enumValue, null));
}
} else {
String controlType = field.getControlType();
if (StringUtils.isNotBlank(controlType)) {
if (controlType.equals("switch")) {
Map<String, String> enumMap = elasticEnumCache.get("aa_boolean");
if (MapUtils.isEmpty(enumMap)) {
enumMap = mddMultiLangEnumService.getEnumMap("aa_boolean");
}
if (MapUtils.isNotEmpty(enumMap)) {
elasticEnumCache.put("aa_boolean", enumMap);
}
Object enumValue = enumMap.get(Boolean.toString(PoiBooleanUtils.b(value)));
if (MapUtils.isNotEmpty(enumMap) && null != enumValue) {
map.put(fieldCode, buildCellData(enumValue, null));
}
}
}
}
}
} catch (Exception e) {
if (isExport) {
map.put(fieldCode, buildCellData(value, null));
} else {
map.put(fieldCode, value);
}
}

Avatar
Avatar

The code above is a try-catch block that handles the mapping of field values to their corresponding enum values. It first checks if the field has an enum and if it is not null and not empty. If it has an enum, it parses the enum string into a map using JSON, and then checks if the enum type is either "BooleanEnum" or "aa_boolean". If it is "BooleanEnum" and is being exported, it converts the value to a boolean and retrieves the corresponding value from the "aa_boolean" enum map. If it is "aa_boolean" and is being exported, it retrieves the corresponding value from the enum map directly. Otherwise, it retrieves the corresponding value from the enum map based on the value of the field. If it is being exported, it puts the mapped value in the map with the field code as its key. If it is not being exported, it simply puts the mapped value in the map.

If the field does not have an enum and is being exported, it checks if the field is a boolean type and