|
@@ -1,6 +1,11 @@
|
|
|
package com.zcxk.rmcp.pay.excel.download.template;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
+import com.alibaba.excel.write.metadata.fill.FillConfig;
|
|
|
import com.bz.zoneiot.core.common.pojo.AjaxMessage;
|
|
|
import com.zcxk.rmcp.api.dto.OrgDto;
|
|
|
import com.zcxk.rmcp.api.dto.product.ProductVo;
|
|
@@ -12,6 +17,9 @@ import com.zcxk.rmcp.pay.dto.LoginUser;
|
|
|
import com.zcxk.rmcp.pay.entity.Community;
|
|
|
import com.zcxk.rmcp.pay.entity.Customer;
|
|
|
import com.zcxk.rmcp.pay.excel.AbstractDownloadExcelTemplate;
|
|
|
+import com.zcxk.rmcp.pay.excel.model.CommImportData;
|
|
|
+import com.zcxk.rmcp.pay.excel.model.InstallPlanExcelData;
|
|
|
+import com.zcxk.rmcp.pay.excel.model.InstallPlanInfoData;
|
|
|
import com.zcxk.rmcp.pay.service.CommunityService;
|
|
|
import com.zcxk.rmcp.pay.service.CustomerService;
|
|
|
import com.zcxk.rmcp.pay.service.pay.PaySyncDataService;
|
|
@@ -21,9 +29,15 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.google.common.collect.Lists.newArrayList;
|
|
|
|
|
@@ -55,46 +69,71 @@ public class InstallPlanDownloadExcelTemplate extends AbstractDownloadExcelTempl
|
|
|
|
|
|
@Override
|
|
|
protected void setParam() {
|
|
|
+ String filesPath=getFilePath();
|
|
|
+ templatePath="excel/installPlanTemplate.xlsx";
|
|
|
LoginUser loginUser = UserUtil.getCurrentUser();
|
|
|
- filePath = getFilePath();
|
|
|
- templatePath = "excel/payBaseAccountTemplate20210130.xlsx";
|
|
|
-
|
|
|
- DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
- LocalDateTime date = LocalDateTime.now();
|
|
|
- downloadName = "批量创建装表计划模板"+ "_" + date.format(f);
|
|
|
-
|
|
|
-
|
|
|
+ InputStream in = this.getClass().getClassLoader().getResourceAsStream(templatePath);
|
|
|
+ ExcelWriter excelWriter = EasyExcel.write(filesPath).withTemplate(in).build();
|
|
|
+ OrgDto dto=new OrgDto();
|
|
|
+ dto.setOrgType("company");
|
|
|
+ List<OrgDto> companys = syncDataClient.getOrgs(dto);
|
|
|
+ //填充设备数据
|
|
|
+ WriteSheet installPalnSheet = EasyExcel.writerSheet("安装计划模板").build();
|
|
|
+ WriteSheet deviceTypeSheet = EasyExcel.writerSheet("设备型号").build();
|
|
|
+ WriteSheet orgSheet = EasyExcel.writerSheet("公司").build();
|
|
|
+ WriteSheet communitySheet = EasyExcel.writerSheet("小区").build();
|
|
|
//1、获取小区列表数据
|
|
|
List<Community> communityList = communityService.findByCustomerId(loginUser.getTenantId());
|
|
|
+ //4、获取水表类型数据
|
|
|
+ List<ProductVo> productList = syncDataClient.getProductLists();
|
|
|
|
|
|
-
|
|
|
- //2、获取建筑列表数据
|
|
|
- //List<Building> buildingList = buildingMapper.findBySiteId(loginUser.getSiteId(),null, UserUtil.getCustomerIds());
|
|
|
+ excelWriter.fill(convertProductData(productList), deviceTypeSheet);
|
|
|
+ excelWriter.fill(convertOrgData(companys), orgSheet);
|
|
|
+ excelWriter.fill(convertCommunityData(communityList), communitySheet);
|
|
|
|
|
|
|
|
|
|
|
|
- //3、获取客户列表数据
|
|
|
- List<Customer> customerList = customerService.getCustomerList(loginUser.getSiteId());
|
|
|
- OrgDto dto=new OrgDto();
|
|
|
- dto.setOrgType("company");
|
|
|
- List<OrgDto> companys = syncDataClient.getOrgs(dto);
|
|
|
- dto.setOrgType("department");
|
|
|
- List<OrgDto> departs = syncDataClient.getOrgs(dto);
|
|
|
+ FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
|
|
+ List<InstallPlanExcelData>installPlanExcelDataList=new ArrayList<>();
|
|
|
+ excelWriter.fill(new InstallPlanInfoData(), fillConfig, installPalnSheet);
|
|
|
+ excelWriter.fill(installPlanExcelDataList, fillConfig, installPalnSheet);
|
|
|
+ DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
+ LocalDateTime date = LocalDateTime.now();
|
|
|
+ String downloadName = "批量创建装表计划模板"+ "_" + date.format(f)+".xlsx";
|
|
|
+ // 千万别忘记关闭流
|
|
|
+ excelWriter.finish();
|
|
|
+ downloadExcel(filesPath,downloadName);
|
|
|
+ }
|
|
|
|
|
|
+ private List<CommImportData> convertCommunityData(List<Community> list){
|
|
|
+ return list.stream().map(vo ->new CommImportData(vo.getName(),Math.toIntExact(vo.getId()))).collect(Collectors.toList());
|
|
|
+ }
|
|
|
|
|
|
- this.context = new Context();
|
|
|
- this.context.putVar("communityList", communityList);
|
|
|
- this.context.putVar("buildingList", newArrayList());
|
|
|
- //this.context.putVar("customerList", customerList);
|
|
|
- this.context.putVar("companyList", companys);
|
|
|
- this.context.putVar("departList", departs);
|
|
|
- //this.context.putVar("deviceTypeList", deviceTypeList);
|
|
|
+ private List<CommImportData> convertOrgData(List<OrgDto> list){
|
|
|
+ return list.stream().map(vo ->new CommImportData(vo.getOrgName(),Math.toIntExact(vo.getId()))).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ private List<CommImportData> convertProductData(List<ProductVo> list){
|
|
|
+ return list.stream().map(vo ->new CommImportData(vo.getManufacturerName()+"/"+vo.getProductName()+"/"+vo.getProductModel(),Math.toIntExact(vo.getId()))).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ private final void downloadExcel(String filesPath,String downLoadName){
|
|
|
+ try (FileInputStream fileInputStream = new FileInputStream(filesPath)){
|
|
|
+ String filename = URLEncoder.encode( downLoadName, "UTF-8");
|
|
|
+ //设置下载头
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + filename);
|
|
|
+ ServletOutputStream outputStream =response.getOutputStream();
|
|
|
+
|
|
|
+ //将文件写入浏览器
|
|
|
+ byte[] bys = new byte[fileInputStream.available()];
|
|
|
+ fileInputStream.read(bys);
|
|
|
+ outputStream.write(bys);
|
|
|
+ outputStream.flush();
|
|
|
+ outputStream.close();
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ FileUtil.del(filesPath);
|
|
|
+ }
|
|
|
|
|
|
- //4、获取水表类型数据
|
|
|
- List<ProductVo> productList = syncDataClient.getProductLists();
|
|
|
- if(!CollectionUtils.isEmpty(productList)){
|
|
|
- this.context.putVar("deviceTypeList", productList);
|
|
|
|
|
|
- }
|
|
|
}
|
|
|
}
|