Browse Source

代码暂存

dev_shibei_match
jianjun 4 years ago
parent
commit
29c57a98e9
  1. 2
      epmet-commons/epmet-commons-tools/pom.xml
  2. BIN
      epmet-commons/epmet-commons-tools/src/main/resources/jar/easypoi-base-4.4.0.jar
  3. 136
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java

2
epmet-commons/epmet-commons-tools/pom.xml

@ -89,6 +89,8 @@
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>${easypoi.version}</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/jar/easypoi-base-4.4.0.jar</systemPath>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>

BIN
epmet-commons/epmet-commons-tools/src/main/resources/jar/easypoi-base-4.4.0.jar

Binary file not shown.

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

@ -20,6 +20,7 @@ package com.epmet.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.export.ExcelExportService;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.exception.EpmetErrorCode;
@ -37,21 +38,21 @@ import com.epmet.dto.IcResiUserDTO;
import com.epmet.dto.form.CustomerFormQueryDTO;
import com.epmet.dto.form.IcResiUserFormDTO;
import com.epmet.dto.result.CustomerFormResultDTO;
import com.epmet.dto.result.FormGroupDTO;
import com.epmet.dto.result.FormItem;
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.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.jetbrains.annotations.NotNull;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
@ -63,6 +64,7 @@ import java.util.Map;
@RestController
@RequestMapping("icresiuser")
public class IcResiUserController {
private static final String BASE_TABLE_NAME = "ic_resi_user";
@Autowired
private OperCustomizeOpenFeignClient operCustomizeOpenFeignClient;
@ -136,80 +138,124 @@ public class IcResiUserController {
CustomerFormQueryDTO queryDTO = new CustomerFormQueryDTO();
queryDTO.setFormCode("resi_base_info");
queryDTO.setCustomerId(customerId);
Result<CustomerFormResultDTO> resultForm = operCustomizeOpenFeignClient.getCustomerForm(queryDTO);
if (resultForm == null || !resultForm.success() ||resultForm.getData() == null){
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode());
}
System.out.println(JSON.toJSONString(resultForm.getData()));
List<ExcelExportEntity> firstHeaderList = new ArrayList<>();
resultForm.getData().getItemList().forEach(item->{
Map<String, List<ExcelExportEntity>> sheetHeaderMap = buildHeaderByItem(resultForm);
Workbook workbook = null;
for (Map.Entry<String, List<ExcelExportEntity>> entry : sheetHeaderMap.entrySet()) {
String sheetName = entry.getKey();
List<ExcelExportEntity> headers = entry.getValue();
ExportParams exportParams = new ExportParams(null, sheetName);
if (workbook == null) {
List<Map<String, String>> dataList =new ArrayList<>();
Map<String, String> dataMap = new HashMap<>();
dataMap.put("GENDER0", "1");
dataMap.put("ID_CARD0", "371888991");
dataList.add(dataMap);
workbook = ExcelExportUtil.exportExcel(exportParams, headers, dataList);
}
new ExcelExportService().createSheetForMap(workbook, exportParams, headers,new ArrayList<>());
}
//exportParams.setDictHandler(new ExcelDiceAddressListHandlerImpl());
System.out.println("header:"+JSON.toJSONString(sheetHeaderMap));
//Workbook workbook = ExcelExportUtil.exportExcel( new ExportParams(), sheetHeaderMap.get(), dataList);
FileOutputStream fos = new FileOutputStream("//Users/liujianjun/Downloads/基础信息表/Dow.tt.xls");
workbook.write(fos);
fos.close();
}
@NotNull
private Map<String,List<ExcelExportEntity>> buildHeaderByItem(Result<CustomerFormResultDTO> resultForm) {
List<FormItem> itemList = resultForm.getData().getItemList();
List<FormGroupDTO> groupList = resultForm.getData().getGroupList();
Map<String,List<ExcelExportEntity>> everySheetHeaderMap = new LinkedHashMap<>();
itemList.forEach(item->{
if (StringUtils.isBlank(item.getColumnName())){
return;
}
ExcelExportEntity header = new ExcelExportEntity(item.getLabel(),item.getColumnName().concat(String.valueOf(item.getColumnNum())));
header.setNeedMerge(true);
firstHeaderList.add(header);
String baseTableName = "resi_base_info";
//这些是动态的 formGroup
if (item.getChildGroup() != null){
//baseTableName单独的一个sheet
if (baseTableName.equals(item.getTableName())){
header = new ExcelExportEntity(item.getChildGroup().getLabel(),item.getChildGroup().getTableName());
header.setNeedMerge(true);
}else{
System.out.println(item.getLabel());
if (BASE_TABLE_NAME.equals(item.getTableName())){
header = new ExcelExportEntity(item.getChildGroup().getLabel(),item.getChildGroup().getTableName());
header.setNeedMerge(true);
buildHeader(everySheetHeaderMap, item, header);
}
if (item.getColumnName().equals("GENDER")){
header.setReplace(new String[]{"男_1","女_2"});
}
});
List<ExcelExportEntity> firstSheetHeaderList = new ArrayList<>();
groupList.forEach(item->{
/* if (!"兴趣爱好".equals(item.getLabel()) && !"宗教信仰".equals(item.getLabel())){
return;
}*/
if (!BASE_TABLE_NAME.equals(item.getTableName())){
System.out.println(item.getLabel()+"--"+item.getTableName());
return;
}
ExcelExportEntity header = new ExcelExportEntity(item.getLabel(),item.getTableName());
header.setNeedMerge(true);
List<ExcelExportEntity> secondHeaderList = new ArrayList<>();
item.getChildGroup().getItemList().forEach(item2->{
ExcelExportEntity secondHeader = new ExcelExportEntity(item2.getLabel(),item2.getColumnName().concat(String.valueOf(item2.getColumnNum())));
item.getItemList().forEach(item2->{
ExcelExportEntity secondHeader = new ExcelExportEntity(item2.getLabel(),item2.getColumnName().concat(String.valueOf(item2.getColumnNum())),30);
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());
ExcelExportEntity thirdHeader = new ExcelExportEntity(child.getLabel(),child.getValue()+ new Random(1).nextInt(2),30);
thirdHeader.setNeedMerge(true);
thirdHeaderList.add(thirdHeader);
});
secondHeader.setList(thirdHeaderList);
}
});
header.setList(secondHeaderList);
firstHeaderList.add(header);
}
firstSheetHeaderList.add(header);
System.out.println(JSON.toJSONString(firstSheetHeaderList));
});
return everySheetHeaderMap;
}
private void buildHeader(Map<String, List<ExcelExportEntity>> everySheetHeaderMap, FormItem item, ExcelExportEntity header) {
/* ExcelExportEntity desginGroup = new ExcelExportEntity("表头名称","键");
desginGroup.setNeedMerge(true);
List<ExcelExportEntity> paramCols = new ArrayList<>();
List<String> headerList = Arrays.asList("头1","头2","头3");
headerList.forEach(e->{
paramCols.add(new ExcelExportEntity(e,e,30));
List<ExcelExportEntity> firstSheetHeaderList = new ArrayList<>();
List<ExcelExportEntity> secondHeaderList = new ArrayList<>();
item.getChildGroup().getItemList().forEach(item2->{
if (!BASE_TABLE_NAME.equals(item2.getTableName())){
everySheetHeaderMap.putIfAbsent(item.getLabel(),firstSheetHeaderList);
}
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());
thirdHeaderList.add(thirdHeader);
});
secondHeader.setList(thirdHeaderList);
}
desginGroup.setList(paramCols);
colList.add(desginGroup);*/
List<Map<String, String>> dataList =new ArrayList<>();
Map<String,String> dataMap = new HashMap<>();
dataMap.put("GENDER0","1");
dataMap.put("ID_CARD0","371888991");
dataList.add(dataMap);
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);
fos.close();
});
header.setList(secondHeaderList);
firstSheetHeaderList.add(header);
}
}

Loading…
Cancel
Save