|
@@ -0,0 +1,158 @@
|
|
|
+package com.zjugis.module.adm.controller.admin.staff.vo.records;
|
|
|
+
|
|
|
+
|
|
|
+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 com.zjugis.framework.common.pojo.CommonResult;
|
|
|
+import com.zjugis.module.adm.constants.DictConstants;
|
|
|
+import com.zjugis.module.adm.framework.spring.ApplicationContextProvider;
|
|
|
+import com.zjugis.module.system.api.dict.DictDataApi;
|
|
|
+import com.zjugis.module.system.api.dict.dto.DictDataRespDTO;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+public class StaffConverter implements Converter<String> {
|
|
|
+
|
|
|
+
|
|
|
+ private final String[] dictFieldName = {"drzw", "sex", "zgxl", "hkxz", "zzmm", "hyzk", "jjlxrgx", "nation", "state", "nldj"};
|
|
|
+
|
|
|
+ private final Map<String, Map<String, String>> dictMap = new HashMap<>();
|
|
|
+
|
|
|
+ private final Map<String, String> drzw = new HashMap<>();
|
|
|
+
|
|
|
+ private final Map<String, String> sex = new HashMap<>();
|
|
|
+
|
|
|
+ private final Map<String, String> zgxl = new HashMap<>();
|
|
|
+
|
|
|
+ private final Map<String, String> hkxz = new HashMap<>();
|
|
|
+
|
|
|
+ private final Map<String, String> zzmm = new HashMap<>();
|
|
|
+
|
|
|
+ private final Map<String, String> hyzk = new HashMap<>();
|
|
|
+
|
|
|
+ private final Map<String, String> jjlxrgx = new HashMap<>();
|
|
|
+
|
|
|
+ private final Map<String, String> nation = new HashMap<>();
|
|
|
+
|
|
|
+ private final Map<String, String> state = new HashMap<>();
|
|
|
+
|
|
|
+ private final Map<String, String> nldj = new HashMap<>();
|
|
|
+
|
|
|
+ public StaffConverter() {
|
|
|
+
|
|
|
+ //字典查询
|
|
|
+ List<String> types = getTypeList();
|
|
|
+ DictDataApi dictDataApi = ApplicationContextProvider.getBean(DictDataApi.class);
|
|
|
+ CommonResult<List<DictDataRespDTO>> res = dictDataApi.getDictDataListByTypes(types);
|
|
|
+ List<DictDataRespDTO> resData = res.getCheckedData();
|
|
|
+
|
|
|
+ resData.forEach(dict -> {
|
|
|
+ switch (dict.getDictType()) {
|
|
|
+ case DictConstants.post_type:
|
|
|
+ this.drzw.put(dict.getValue(), dict.getLabel());
|
|
|
+ break;
|
|
|
+
|
|
|
+ case DictConstants.sex_type:
|
|
|
+ this.sex.put(dict.getValue(), dict.getLabel());
|
|
|
+ break;
|
|
|
+
|
|
|
+ case DictConstants.xl_type:
|
|
|
+ this.zgxl.put(dict.getValue(), dict.getLabel());
|
|
|
+ break;
|
|
|
+
|
|
|
+ case DictConstants.hk_type:
|
|
|
+ this.hkxz.put(dict.getValue(), dict.getLabel());
|
|
|
+ break;
|
|
|
+
|
|
|
+ case DictConstants.polity_type:
|
|
|
+ this.zzmm.put(dict.getValue(), dict.getLabel());
|
|
|
+ break;
|
|
|
+
|
|
|
+ case DictConstants.hy_type:
|
|
|
+ this.hyzk.put(dict.getValue(), dict.getLabel());
|
|
|
+ break;
|
|
|
+
|
|
|
+ case DictConstants.contact_type:
|
|
|
+ this.jjlxrgx.put(dict.getValue(), dict.getLabel());
|
|
|
+ break;
|
|
|
+
|
|
|
+ case DictConstants.nation_type:
|
|
|
+ this.nation.put(dict.getValue(), dict.getLabel());
|
|
|
+ break;
|
|
|
+
|
|
|
+ case DictConstants.staff_state_type:
|
|
|
+ this.state.put(dict.getValue(), dict.getLabel());
|
|
|
+ break;
|
|
|
+
|
|
|
+ case DictConstants.ABILITY_LEVEL:
|
|
|
+ this.nldj.put(dict.getValue(), dict.getLabel());
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ dictMap.put("drzw", drzw);
|
|
|
+ dictMap.put("sex", sex);
|
|
|
+ dictMap.put("zgxl", zgxl);
|
|
|
+ dictMap.put("hkxz", hkxz);
|
|
|
+ dictMap.put("zzmm", zzmm);
|
|
|
+ dictMap.put("hyzk", hyzk);
|
|
|
+ dictMap.put("jjlxrgx", jjlxrgx);
|
|
|
+ dictMap.put("nation", nation);
|
|
|
+ dictMap.put("state", state);
|
|
|
+ dictMap.put("nldj", nldj);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> getTypeList() {
|
|
|
+ List<String> res = new ArrayList<>();
|
|
|
+ res.add(DictConstants.sex_type);
|
|
|
+ res.add(DictConstants.staff_state_type);
|
|
|
+ res.add(DictConstants.polity_type);
|
|
|
+ res.add(DictConstants.hk_type);
|
|
|
+ res.add(DictConstants.hy_type);
|
|
|
+ res.add(DictConstants.xl_type);
|
|
|
+ res.add(DictConstants.contact_type);
|
|
|
+ res.add(DictConstants.nation_type);
|
|
|
+ res.add(DictConstants.post_type);
|
|
|
+ res.add(DictConstants.ABILITY_LEVEL);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ @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(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
|
|
|
+
|
|
|
+ Field field = contentProperty.getField();
|
|
|
+ String fieldName = field.getName();
|
|
|
+ String excelValue;
|
|
|
+ if (StringUtils.equalsAnyIgnoreCase(fieldName, dictFieldName)) {
|
|
|
+ Map<String, String> dict = dictMap.get(fieldName);
|
|
|
+ Set<String> dictKeys = dict.keySet();
|
|
|
+ excelValue = dictKeys.contains(value) ? dict.get(value) : "";
|
|
|
+ } else {
|
|
|
+ excelValue = value;
|
|
|
+ }
|
|
|
+ return new WriteCellData<>(excelValue);
|
|
|
+ }
|
|
|
+}
|