From fd8b23735d350a1a85bbce654df145c60c5f4033 Mon Sep 17 00:00:00 2001
From: 101captain <237651143@qq.com>
Date: 星期一, 15 十一月 2021 17:21:44 +0800
Subject: [PATCH] 1115修改提交
---
springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/ComActReserveApi.java | 117 +++++++++++++++++++---------
springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/excel/CustemSecondhandler.java | 73 ++++++++++++++++++
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/HomeQuarantineUtil.java | 14 +++
3 files changed, 164 insertions(+), 40 deletions(-)
diff --git a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/HomeQuarantineUtil.java b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/HomeQuarantineUtil.java
index 2123a4d..47a4947 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/HomeQuarantineUtil.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/HomeQuarantineUtil.java
@@ -48,7 +48,7 @@
continue;
}
if(count%16==2){
- conditions.append(DateUtils.format(userAnswers.getTime(),new SimpleDateFormat("yyyy-MM-dd"))+" "+"当日隔离情况:"+userAnswers.getAnswerContent()+"℃"+"\n");
+ conditions.append(DateUtils.format(userAnswers.getTime(),new SimpleDateFormat("yyyy-MM-dd"))+" "+"当日隔离情况:"+userAnswers.getAnswerContent()+"\n");
conditions.append("————————"+"\n");
count++;
continue;
@@ -203,7 +203,17 @@
String answer = sb.toString();
userData.add(answer.substring(0, answer.length() - 1));
}
- resultList.add(userData);
+ for(List<Object> result:resultList){
+ if(result.get(4).equals(userData.get(4))){
+ String condition=result.get(result.size()-1)+userData.get(userData.size()-1).toString();
+ result.set(result.size()-1,condition);
+ userData.set(userData.size()-1,null);
+ break;
+ }
+ }
+ if(userData.get(userData.size()-1)!=null){
+ resultList.add(userData);
+ }
}
return resultList;
}
diff --git a/springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/ComActReserveApi.java b/springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/ComActReserveApi.java
index bdfe478..a455cee 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/ComActReserveApi.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/ComActReserveApi.java
@@ -25,6 +25,7 @@
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.common.utlis.*;
import com.panzhihua.community_backstage.config.SFTPConfig;
+import com.panzhihua.community_backstage.excel.CustemSecondhandler;
import com.panzhihua.community_backstage.excel.Custemhandler;
import com.panzhihua.community_backstage.excel.CustomSheetWriteHandler;
import io.swagger.annotations.Api;
@@ -527,6 +528,45 @@
headList.add(head2);
//数据转换
datalist = HomeQuarantineUtil.ReserveData(questnaireAnswersDTOS.getAnswers());
+ WriteCellStyle headWriteCellStyle = new WriteCellStyle();
+ //设置头居中
+ headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
+ //设置头字体
+ WriteFont headWriteFont = new WriteFont();
+ headWriteFont.setFontHeightInPoints((short)6);
+ headWriteFont.setBold(true);
+ headWriteCellStyle.setWriteFont(headWriteFont);
+
+
+ WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
+ //设置表格内容字体
+ WriteFont writeFont = new WriteFont();
+ writeFont.setFontHeightInPoints((short)6);
+ //设置 水平居中
+ contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.LEFT);
+ //设置 垂直居中
+ contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+ contentWriteCellStyle.setWriteFont(writeFont);
+
+ contentWriteCellStyle.setWrapped(true);
+ HorizontalCellStyleStrategy horizontalCellStyleStrategy =
+ new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
+
+
+ excelWriter = EasyExcel.write(fileName)
+ .registerWriteHandler(horizontalCellStyleStrategy).registerWriteHandler(new CustemSecondhandler())
+ .build();
+ WriteSheet writeSheet = EasyExcel.writerSheet("登记明细导出数据").head(headList).build();
+ excelWriter.write(datalist, writeSheet);
+ excelWriter.finish();
+ File file = new File(fileName);
+ inputStream = new FileInputStream(file);
+ sftp.uploadMore(ftpUrl, name, inputStream);
+ sftp.logout();
+ inputStream.close();
+ String absolutePath = file.getAbsolutePath();
+ boolean delete = file.delete();
+ log.info("删除excel【{}】结果【{}】", absolutePath, delete);
}
else {
String firstRowContent = "登记明细";
@@ -554,48 +594,49 @@
});
//数据转换
datalist = AssemblyUtils.ReserveData(questnaireAnswersDTOS.getAnswers());
+ WriteCellStyle headWriteCellStyle = new WriteCellStyle();
+ //设置头居中
+ headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
+ //设置头字体
+ WriteFont headWriteFont = new WriteFont();
+ headWriteFont.setFontHeightInPoints((short)6);
+ headWriteFont.setBold(true);
+ headWriteCellStyle.setWriteFont(headWriteFont);
+
+
+ WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
+ //设置表格内容字体
+ WriteFont writeFont = new WriteFont();
+ writeFont.setFontHeightInPoints((short)6);
+ //设置 水平居中
+ contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
+ //设置 垂直居中
+ contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+ contentWriteCellStyle.setWriteFont(writeFont);
+
+ contentWriteCellStyle.setWrapped(true);
+ HorizontalCellStyleStrategy horizontalCellStyleStrategy =
+ new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
+
+
+ excelWriter = EasyExcel.write(fileName)
+ .registerWriteHandler(horizontalCellStyleStrategy).registerWriteHandler(new Custemhandler())
+ .build();
+ WriteSheet writeSheet = EasyExcel.writerSheet("登记明细导出数据").head(headList).build();
+ excelWriter.write(datalist, writeSheet);
+ excelWriter.finish();
+ File file = new File(fileName);
+ inputStream = new FileInputStream(file);
+ sftp.uploadMore(ftpUrl, name, inputStream);
+ sftp.logout();
+ inputStream.close();
+ String absolutePath = file.getAbsolutePath();
+ boolean delete = file.delete();
+ log.info("删除excel【{}】结果【{}】", absolutePath, delete);
}
- WriteCellStyle headWriteCellStyle = new WriteCellStyle();
- //设置头居中
- headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
- //设置头字体
- WriteFont headWriteFont = new WriteFont();
- headWriteFont.setFontHeightInPoints((short)6);
- headWriteFont.setBold(true);
- headWriteCellStyle.setWriteFont(headWriteFont);
-
- WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
- //设置表格内容字体
- WriteFont writeFont = new WriteFont();
- writeFont.setFontHeightInPoints((short)6);
- //设置 水平居中
- contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
- //设置 垂直居中
- contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
- contentWriteCellStyle.setWriteFont(writeFont);
-
- contentWriteCellStyle.setWrapped(true);
- HorizontalCellStyleStrategy horizontalCellStyleStrategy =
- new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
-
-
- excelWriter = EasyExcel.write(fileName)
- .registerWriteHandler(horizontalCellStyleStrategy).registerWriteHandler(new Custemhandler())
- .registerWriteHandler(new CustomSheetWriteHandler()).build();
- WriteSheet writeSheet = EasyExcel.writerSheet("登记明细导出数据").head(headList).build();
- excelWriter.write(datalist, writeSheet);
- excelWriter.finish();
- File file = new File(fileName);
- inputStream = new FileInputStream(file);
- sftp.uploadMore(ftpUrl, name, inputStream);
- sftp.logout();
- inputStream.close();
- String absolutePath = file.getAbsolutePath();
- boolean delete = file.delete();
- log.info("删除excel【{}】结果【{}】", absolutePath, delete);
} finally {
// 千万别忘记finish 会帮忙关闭流
if (inputStream != null) {
diff --git a/springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/excel/CustemSecondhandler.java b/springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/excel/CustemSecondhandler.java
new file mode 100644
index 0000000..021592d
--- /dev/null
+++ b/springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/excel/CustemSecondhandler.java
@@ -0,0 +1,73 @@
+package com.panzhihua.community_backstage.excel;
+
+import com.alibaba.excel.enums.CellDataTypeEnum;
+import com.alibaba.excel.metadata.CellData;
+import com.alibaba.excel.metadata.Head;
+import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
+import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy;
+import org.apache.poi.ss.usermodel.Cell;
+import org.springframework.util.CollectionUtils;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class CustemSecondhandler extends AbstractColumnWidthStyleStrategy {
+
+ private Map<Integer, Map<Integer, Integer>> CACHE = new HashMap(8);
+
+ public CustemSecondhandler() {
+ }
+
+ @Override
+ protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List<CellData> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
+ boolean needSetWidth = isHead || !CollectionUtils.isEmpty(cellDataList);
+ if (needSetWidth) {
+ Map<Integer, Integer> maxColumnWidthMap = (Map)CACHE.get(writeSheetHolder.getSheetNo());
+ if (maxColumnWidthMap == null) {
+ maxColumnWidthMap = new HashMap(16);
+ CACHE.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap);
+ }
+
+ Integer columnWidth = this.dataLength(cellDataList, cell, isHead);
+ if (columnWidth >= 0) {
+ if (columnWidth > 25) {
+ columnWidth = 25;
+ }
+
+ Integer maxColumnWidth = (Integer)((Map)maxColumnWidthMap).get(cell.getColumnIndex());
+ if (maxColumnWidth == null || columnWidth > maxColumnWidth) {
+ ((Map)maxColumnWidthMap).put(cell.getColumnIndex(), columnWidth);
+ writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), columnWidth * 75);
+ }
+ if(cell.getStringCellValue().equals("隔离体温情况")){
+ writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(),70*75);
+ }
+
+ }
+ }
+ }
+
+ private Integer dataLength(List<CellData> cellDataList, Cell cell, Boolean isHead) {
+ if (isHead) {
+ return cell.getStringCellValue().getBytes().length;
+ } else {
+ CellData cellData = cellDataList.get(0);
+ CellDataTypeEnum type = cellData.getType();
+ if (type == null) {
+ return -1;
+ } else {
+ switch(type) {
+ case STRING:
+ return cellData.getStringValue().getBytes().length;
+ case BOOLEAN:
+ return cellData.getBooleanValue().toString().getBytes().length;
+ case NUMBER:
+ return cellData.getNumberValue().toString().getBytes().length;
+ default:
+ return -1;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--
Gitblit v1.7.1