5 changed files with 237 additions and 402 deletions
			
			
		| @ -1,47 +0,0 @@ | |||||
| /** |  | ||||
|  * Copyright 2018 人人开源 https://www.renren.io
 |  | ||||
|  * <p> |  | ||||
|  * This program is free software: you can redistribute it and/or modify |  | ||||
|  * it under the terms of the GNU General Public License as published by |  | ||||
|  * the Free Software Foundation, either version 3 of the License, or |  | ||||
|  * (at your option) any later version. |  | ||||
|  * <p> |  | ||||
|  * This program is distributed in the hope that it will be useful, |  | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of |  | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the |  | ||||
|  * GNU General Public License for more details. |  | ||||
|  * <p> |  | ||||
|  * You should have received a copy of the GNU General Public License |  | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 |  | ||||
|  */ |  | ||||
| 
 |  | ||||
| package com.epmet.redis; |  | ||||
| 
 |  | ||||
| import com.epmet.commons.tools.redis.RedisUtils; |  | ||||
| import org.springframework.beans.factory.annotation.Autowired; |  | ||||
| import org.springframework.stereotype.Component; |  | ||||
| 
 |  | ||||
| /** |  | ||||
|  * 用户基础信息 |  | ||||
|  * |  | ||||
|  * @author generator generator@elink-cn.com |  | ||||
|  * @since v1.0.0 2021-10-26 |  | ||||
|  */ |  | ||||
| @Component |  | ||||
| public class IcResiUserRedis { |  | ||||
|     @Autowired |  | ||||
|     private RedisUtils redisUtils; |  | ||||
| 
 |  | ||||
|     public void delete(Object[] ids) { |  | ||||
| 
 |  | ||||
|     } |  | ||||
| 
 |  | ||||
|     public void set(){ |  | ||||
| 
 |  | ||||
|     } |  | ||||
| 
 |  | ||||
|     public String get(String id){ |  | ||||
|         return null; |  | ||||
|     } |  | ||||
| 
 |  | ||||
| } |  | ||||
| @ -0,0 +1,183 @@ | |||||
|  | package com.epmet.epmetuser.test; | ||||
|  | 
 | ||||
|  | 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.baomidou.mybatisplus.core.toolkit.CollectionUtils; | ||||
|  | import com.epmet.commons.tools.exception.EpmetErrorCode; | ||||
|  | import com.epmet.commons.tools.exception.RenException; | ||||
|  | import com.epmet.commons.tools.utils.Result; | ||||
|  | import com.epmet.dto.form.CustomerFormQueryDTO; | ||||
|  | import com.epmet.dto.result.CustomerFormResultDTO; | ||||
|  | import com.epmet.dto.result.FormGroupDTO; | ||||
|  | import com.epmet.dto.result.FormItem; | ||||
|  | import com.epmet.feign.OperCustomizeOpenFeignClient; | ||||
|  | import org.apache.commons.lang3.StringUtils; | ||||
|  | import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||||
|  | import org.jetbrains.annotations.NotNull; | ||||
|  | import org.junit.Test; | ||||
|  | import org.junit.runner.RunWith; | ||||
|  | import org.springframework.beans.factory.annotation.Autowired; | ||||
|  | import org.springframework.boot.test.context.SpringBootTest; | ||||
|  | import org.springframework.test.context.junit4.SpringRunner; | ||||
|  | import org.springframework.web.bind.annotation.RequestParam; | ||||
|  | 
 | ||||
|  | import java.io.FileOutputStream; | ||||
|  | import java.util.*; | ||||
|  | 
 | ||||
|  | @SpringBootTest | ||||
|  | @RunWith(SpringRunner.class) | ||||
|  | public class IcResiUserControllerTest { | ||||
|  |     private static final String BASE_TABLE_NAME = "BASE_TABLE_NAME"; | ||||
|  |     @Autowired | ||||
|  |     private OperCustomizeOpenFeignClient operCustomizeOpenFeignClient; | ||||
|  | 
 | ||||
|  |     @Test | ||||
|  |     public void downloadTemplate(@RequestParam String customerId) throws Exception { | ||||
|  |         CustomerFormResultDTO resultForm = getResiFormItems(customerId); | ||||
|  | 
 | ||||
|  |         XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
|  |         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(); | ||||
|  |             System.out.println("headers:"+sheetName+JSON.toJSONString(headers)); | ||||
|  |             ExportParams exportParams = new ExportParams(null,sheetName); | ||||
|  |             //exportParams.setAutoSize(true);
 | ||||
|  |             List<Map<String,String>> dataSet = new ArrayList<>(); | ||||
|  |             HashMap<String, String> map = new HashMap<>(); | ||||
|  |             map.put("1","2"); | ||||
|  |             dataSet.add(map); | ||||
|  |             new ExcelExportService().createSheetForMap(workbook, exportParams, headers, dataSet); | ||||
|  |         } | ||||
|  | 
 | ||||
|  |         FileOutputStream fos = new FileOutputStream("//Users/liujianjun/Downloads/基础信息表/Dow.tt.xls"); | ||||
|  |         workbook.write(fos); | ||||
|  |         fos.close(); | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     @NotNull | ||||
|  |     private CustomerFormResultDTO getResiFormItems(String customerId) { | ||||
|  |         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())); | ||||
|  |         return resultForm.getData(); | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     @NotNull | ||||
|  |     private Map<String,List<ExcelExportEntity>> buildHeaderByItem(CustomerFormResultDTO resultForm) { | ||||
|  |         //form中的itemlist 为一级表头 但是要排除每个item中含有childGroup的
 | ||||
|  | 
 | ||||
|  |         List<FormItem> itemList = resultForm.getItemList(); | ||||
|  |         List<FormGroupDTO> groupList = resultForm.getGroupList(); | ||||
|  | 
 | ||||
|  |         Map<String,List<ExcelExportEntity>> everySheetHeaderMap = new LinkedHashMap<>(); | ||||
|  | 
 | ||||
|  |         List<ExcelExportEntity> firstSheetHeaderList = new ArrayList<>(); | ||||
|  |         //Map<String, String> groupNameMap = groupList.stream().collect(Collectors.toMap(FormGroupDTO::getGroupId,FormGroupDTO::getLabel));
 | ||||
|  |         itemList.forEach(item->{ | ||||
|  |             if (StringUtils.isBlank(item.getColumnName())){ | ||||
|  |                 return; | ||||
|  |             } | ||||
|  | 
 | ||||
|  |             if (item.getChildGroup() == null){ | ||||
|  |                 ExcelExportEntity header = new ExcelExportEntity(item.getLabel(),item.getColumnName().concat(String.valueOf(item.getColumnNum())),30); | ||||
|  |                 header.setNeedMerge(true); | ||||
|  |                 firstSheetHeaderList.add(header); | ||||
|  |                 return; | ||||
|  |             } | ||||
|  |             everySheetHeaderMap.putIfAbsent(resultForm.getFormName(),firstSheetHeaderList); | ||||
|  | 
 | ||||
|  |             //这些是动态的 formGroup
 | ||||
|  |             if (item.getChildGroup() != null){ | ||||
|  |                 //baseTableName单独的一个sheet
 | ||||
|  |                 System.out.println("childGroup:"+item.getLabel()); | ||||
|  |                 if (BASE_TABLE_NAME.equals(item.getTableName())){ | ||||
|  |                     List<ExcelExportEntity> otherSheetHeaderList = new ArrayList<>(); | ||||
|  |                     //这里是设置除基础信息之外的sheet的表头
 | ||||
|  |                     item.getChildGroup().getItemList().forEach(item2->{ | ||||
|  |                         if (!BASE_TABLE_NAME.equals(item2.getTableName())){ | ||||
|  |                             everySheetHeaderMap.putIfAbsent(item.getLabel(),otherSheetHeaderList); | ||||
|  |                         } | ||||
|  |                         ExcelExportEntity secondHeader = new ExcelExportEntity(item2.getLabel(),item2.getColumnName().concat(String.valueOf(item2.getColumnNum()))); | ||||
|  | 
 | ||||
|  |                         otherSheetHeaderList.add(secondHeader); | ||||
|  |                         if (!"radio".equals(item2.getItemType()) && CollectionUtils.isNotEmpty(item2.getOptions())){ | ||||
|  |                             secondHeader.setNeedMerge(true); | ||||
|  |                             List<ExcelExportEntity> thirdHeaderList = new ArrayList<>(); | ||||
|  |                             item2.getOptions().forEach(child->{ | ||||
|  |                                 ExcelExportEntity thirdHeader = new ExcelExportEntity(child.getLabel()); | ||||
|  |                                 thirdHeaderList.add(thirdHeader); | ||||
|  |                             }); | ||||
|  |                             secondHeader.setList(thirdHeaderList); | ||||
|  |                         } | ||||
|  | 
 | ||||
|  |                     }); | ||||
|  |                 } | ||||
|  |             } | ||||
|  |         }); | ||||
|  |         groupList.forEach(item->{ | ||||
|  |            /* if (!"兴趣爱好".equals(item.getLabel()) && !"宗教信仰".equals(item.getLabel())){ | ||||
|  |                 return; | ||||
|  |             }*/ | ||||
|  |             if (!BASE_TABLE_NAME.equals(item.getTableName())){ | ||||
|  |                 return; | ||||
|  |             } | ||||
|  |             ExcelExportEntity header = new ExcelExportEntity(item.getLabel(),item.getTableName()); | ||||
|  |             header.setNeedMerge(true); | ||||
|  |             List<ExcelExportEntity> secondHeaderList = new ArrayList<>(); | ||||
|  |             item.getItemList().forEach(item2->{ | ||||
|  |                 ExcelExportEntity secondHeader = new ExcelExportEntity(item2.getLabel(),item2.getColumnName().concat(String.valueOf(item2.getColumnNum()))); | ||||
|  |                 secondHeader.setNeedMerge(true); | ||||
|  |                 secondHeaderList.add(secondHeader); | ||||
|  |                 if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isNotEmpty(item2.getOptions())){ | ||||
|  |                     List<ExcelExportEntity> thirdHeaderList = new ArrayList<>(); | ||||
|  |                     item2.getOptions().forEach(child->{ | ||||
|  |                         ExcelExportEntity thirdHeader = new ExcelExportEntity(child.getLabel(),child.getValue()+ new Random(1).nextInt(2)); | ||||
|  |                         thirdHeader.setNeedMerge(true); | ||||
|  |                         thirdHeaderList.add(thirdHeader); | ||||
|  |                     }); | ||||
|  |                     secondHeader.setList(thirdHeaderList); | ||||
|  |                 } | ||||
|  | 
 | ||||
|  |             }); | ||||
|  |             header.setList(secondHeaderList); | ||||
|  |             firstSheetHeaderList.add(header); | ||||
|  |             System.out.println(JSON.toJSONString(firstSheetHeaderList)); | ||||
|  |         }); | ||||
|  |         return everySheetHeaderMap; | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     private void buildHeader(Map<String, List<ExcelExportEntity>> everySheetHeaderMap, FormItem item, ExcelExportEntity header) { | ||||
|  |         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); | ||||
|  |             } | ||||
|  | 
 | ||||
|  |         }); | ||||
|  |         header.setList(secondHeaderList); | ||||
|  |         firstSheetHeaderList.add(header); | ||||
|  |         everySheetHeaderMap.putIfAbsent(item.getLabel(),firstSheetHeaderList); | ||||
|  |     } | ||||
|  | 
 | ||||
|  | } | ||||
					Loading…
					
					
				
		Reference in new issue