|
@@ -0,0 +1,73 @@
|
|
|
+package com.zjugis.business.excel;
|
|
|
+
|
|
|
+
|
|
|
+import com.alibaba.excel.converters.Converter;
|
|
|
+import com.alibaba.excel.metadata.GlobalConfiguration;
|
|
|
+import com.alibaba.excel.metadata.data.WriteCellData;
|
|
|
+import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author ljy
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2023/11/23 15:26
|
|
|
+ */
|
|
|
+public class ProjectConverter implements Converter<Integer> {
|
|
|
+
|
|
|
+
|
|
|
+ private final String[] dictFieldName = {"hyId","xmzt"};
|
|
|
+
|
|
|
+ private final Map<String,Map<Integer,String>> dictMap = new HashMap<>();
|
|
|
+
|
|
|
+ private final Map<Integer,String> hyDict = new HashMap<>();
|
|
|
+
|
|
|
+ private final Map<Integer,String> xmztDict = new HashMap<>();
|
|
|
+
|
|
|
+ public ProjectConverter() {
|
|
|
+ this.hyDict.put(1,"公司内部项目");
|
|
|
+ this.hyDict.put(2,"IT行业");
|
|
|
+ this.hyDict.put(3,"政府行业");
|
|
|
+ this.hyDict.put(4,"其他");
|
|
|
+
|
|
|
+ this.xmztDict.put(0,"立项申请中");
|
|
|
+ this.xmztDict.put(1,"进行中");
|
|
|
+ this.xmztDict.put(2,"已结项");
|
|
|
+ this.xmztDict.put(3,"中止");
|
|
|
+ this.xmztDict.put(4,"已验收");
|
|
|
+
|
|
|
+ dictMap.put("hyId",hyDict);
|
|
|
+ dictMap.put("xmzt",xmztDict);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Class<?> supportJavaTypeKey() {
|
|
|
+ return Integer.class;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param value Java Data.NotNull.
|
|
|
+ * @param contentProperty Content property.Nullable.
|
|
|
+ * @param globalConfiguration Global configuration.NotNull.
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
|
|
|
+
|
|
|
+ Field field = contentProperty.getField();
|
|
|
+ String fieldName = field.getName();
|
|
|
+ String excelValue;
|
|
|
+ if (StringUtils.equalsAnyIgnoreCase(fieldName,dictFieldName)) {
|
|
|
+ Map<Integer, String> dict = dictMap.get(fieldName);
|
|
|
+ Set<Integer> dictKeys = dict.keySet();
|
|
|
+ excelValue = dictKeys.contains(value) ? dict.get(value) : "";
|
|
|
+ } else {
|
|
|
+ excelValue = String.valueOf(value);
|
|
|
+ }
|
|
|
+ return new WriteCellData<>(excelValue);
|
|
|
+ }
|
|
|
+}
|