Browse Source

暂存

dev_shibei_match
jianjun 4 years ago
parent
commit
2d4b0c7343
  1. 60
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java
  2. 64
      epmet-user/epmet-user-server/src/main/java/com/epmet/handler/ExcelDiceAddressListHandlerImpl.java

60
epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java

@ -39,14 +39,19 @@ import com.epmet.dto.form.IcResiUserFormDTO;
import com.epmet.dto.result.CustomerFormResultDTO;
import com.epmet.excel.IcResiUserExcel;
import com.epmet.feign.OperCustomizeOpenFeignClient;
import com.epmet.handler.ExcelDiceAddressListHandlerImpl;
import com.epmet.service.IcResiUserService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@ -137,18 +142,52 @@ public class IcResiUserController {
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode());
}
System.out.println(JSON.toJSONString(resultForm.getData()));
List<ExcelExportEntity> colList = new ArrayList<>();
List<ExcelExportEntity> firstHeaderList = new ArrayList<>();
resultForm.getData().getItemList().forEach(item->{
ExcelExportEntity header = new ExcelExportEntity(item.getLabel(),item.getColumnName().concat(String.valueOf(item.getColumnNum())));
header.setNeedMerge(true);
firstHeaderList.add(header);
String baseTableName = "resi_base_info";
if (item.getChildGroup() != null){
//baseTableName单独的一个sheet
if (baseTableName.equals(item.getTableName())){
header = new ExcelExportEntity(item.getChildGroup().getLabel(),item.getChildGroup().getTableName());
header.setNeedMerge(true);
}else{
header = new ExcelExportEntity(item.getChildGroup().getLabel(),item.getChildGroup().getTableName());
header.setNeedMerge(true);
}
if (item.getColumnName().equals("GENDER")){
header.setReplace(new String[]{"男_1","女_2"});
}
List<ExcelExportEntity> secondHeaderList = new ArrayList<>();
item.getChildGroup().getItemList().forEach(item2->{
ExcelExportEntity secondHeader = new ExcelExportEntity(item2.getLabel(),item2.getColumnName().concat(String.valueOf(item2.getColumnNum())));
secondHeader.setNeedMerge(true);
secondHeaderList.add(secondHeader);
if (CollectionUtils.isNotEmpty(item2.getOptions())){
List<ExcelExportEntity> thirdHeaderList = new ArrayList<>();
item2.getOptions().forEach(child->{
ExcelExportEntity thirdHeader = new ExcelExportEntity(child.getLabel());
thirdHeader.setNeedMerge(true);
thirdHeaderList.add(thirdHeader);
});
secondHeader.setList(thirdHeaderList);
}
});
header.setList(secondHeaderList);
firstHeaderList.add(header);
}
});
ExcelExportEntity desginGroup = new ExcelExportEntity("表头名称","键");
/* ExcelExportEntity desginGroup = new ExcelExportEntity("表头名称","键");
desginGroup.setNeedMerge(true);
List<ExcelExportEntity> paramCols = new ArrayList<>();
List<String> headerList = Arrays.asList("头1","头2","头3");
@ -157,15 +196,16 @@ public class IcResiUserController {
});
desginGroup.setList(paramCols);
colList.add(desginGroup);
colList.add(desginGroup);*/
List<Map<String, String>> dataList =new ArrayList<>();
Map<String,String> dataMap = new HashMap<>();
dataMap.put("头1","1");
dataMap.put("头2","2");
dataMap.put("头3","3");
dataMap.put("GENDER0","1");
dataMap.put("ID_CARD0","371888991");
dataList.add(dataMap);
ExportParams entity = new ExportParams();
Workbook workbook = ExcelExportUtil.exportExcel(entity, colList, dataList);
ExportParams exportParams = new ExportParams();
exportParams.setDictHandler(new ExcelDiceAddressListHandlerImpl());
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, firstHeaderList, dataList);
//ExcelExportUtil.exportExcel
FileOutputStream fos = new FileOutputStream("//Users/liujianjun/Downloads/基础信息表/Dow.tt.xls");
workbook.write(fos);

64
epmet-user/epmet-user-server/src/main/java/com/epmet/handler/ExcelDiceAddressListHandlerImpl.java

@ -0,0 +1,64 @@
package com.epmet.handler;
import cn.afterturn.easypoi.handler.inter.IExcelDictHandler;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 模拟使用,生产请用真实字典
*
* @author jueyue on 20-4-26.
*/
public class ExcelDiceAddressListHandlerImpl implements IExcelDictHandler {
/**
* 返回字典所有值
* key: dictKey
*
* @param dict 字典Key
* @return
*/
public List<Map> getList(String dict) {
List<Map> list = new ArrayList<>();
Map<String, String> dictMap = new HashMap<>();
dictMap.put("dictKey", "1");
dictMap.put("dictValue", "男");
list.add(dictMap);
dictMap = new HashMap<>();
dictMap.put("dictKey", "2");
dictMap.put("dictValue", "女");
list.add(dictMap);
return list;
}
@Override
public String toName(String dict, Object obj, String name, Object value) {
if ("level".equals(dict)) {
int level = Integer.parseInt(value.toString());
switch (level) {
case 1:
return "男";
case 2:
return "女";
}
}
return null;
}
@Override
public String toValue(String dict, Object obj, String name, Object value) {
if ("level".equals(dict)) {
int level = Integer.parseInt(value.toString());
switch (level) {
case 1:
return "男";
case 2:
return "女";
}
}
return null;
}
}
Loading…
Cancel
Save