Browse Source

提交导出代码

hjc 5 months ago
parent
commit
d5b23c9f91

+ 6 - 6
unis-plugin/unis-plugin-biz/src/main/java/com/unis/equipmentOnlineRateAssessment/modular/monitorCamera/controller/MonitorCameraController.java

@@ -28,6 +28,7 @@ import com.unis.equipmentOnlineRateAssessment.modular.monitorCamera.entity.Monit
28 28
 import com.unis.equipmentOnlineRateAssessment.modular.monitorCamera.service.MonitorCameraService;
29 29
 
30 30
 import javax.annotation.Resource;
31
+import javax.servlet.http.HttpServletResponse;
31 32
 import javax.validation.Valid;
32 33
 
33 34
 /**
@@ -146,9 +147,8 @@ public class MonitorCameraController {
146 147
     @ApiOperation("在线统计分析-导出")
147 148
     //@SaCheckPermission("/equipmentOnlineRateAssessment/monitorCamera/page")
148 149
     @GetMapping("/equipmentOnlineRateAssessment/monitorCamera/statisticalAnalysisExport")
149
-    public CommonResult<String> statisticalAnalysisExport() {
150
-        monitorCameraService.statisticalAnalysisExport();
151
-        return CommonResult.ok();
150
+    public void statisticalAnalysisExport(String fileName, HttpServletResponse response) {
151
+        monitorCameraService.statisticalAnalysisExport(fileName,response);
152 152
     }
153 153
 
154 154
     /**
@@ -205,9 +205,9 @@ public class MonitorCameraController {
205 205
     @ApiOperation("自动考核-导出")
206 206
     //@SaCheckPermission("/equipmentOnlineRateAssessment/monitorCamera/page")
207 207
     @GetMapping("/equipmentOnlineRateAssessment/monitorCamera/AutomatedAssessmentsExport")
208
-    public CommonResult<String> AutomatedAssessmentsExport() {
209
-        monitorCameraService.AutomatedAssessmentsExport();
210
-        return CommonResult.ok();
208
+    public void AutomatedAssessmentsExport(String fileName, HttpServletResponse response) {
209
+        monitorCameraService.AutomatedAssessmentsExport(fileName,response);
210
+
211 211
     }
212 212
 
213 213
 }

+ 3 - 2
unis-plugin/unis-plugin-biz/src/main/java/com/unis/equipmentOnlineRateAssessment/modular/monitorCamera/service/MonitorCameraService.java

@@ -18,6 +18,7 @@ import com.unis.equipmentOnlineRateAssessment.modular.monitorCamera.entity.Monit
18 18
 import com.unis.equipmentOnlineRateAssessment.modular.monitorCamera.param.*;
19 19
 import com.unis.equipmentOnlineRateAssessment.modular.monitorCamera.vo.*;
20 20
 
21
+import javax.servlet.http.HttpServletResponse;
21 22
 import java.util.List;
22 23
 
23 24
 /**
@@ -90,7 +91,7 @@ public interface MonitorCameraService extends IService<MonitorCamera> {
90 91
      * @author hjc
91 92
      * @date  2024/06/21 10:07
92 93
      */
93
-    void statisticalAnalysisExport();
94
+    void statisticalAnalysisExport(String fileName, HttpServletResponse response);
94 95
 
95 96
 
96 97
     /**
@@ -124,6 +125,6 @@ public interface MonitorCameraService extends IService<MonitorCamera> {
124 125
      * @author hjc
125 126
      * @date 2024/06/21 10:07
126 127
      */
127
-    void AutomatedAssessmentsExport();
128
+    void AutomatedAssessmentsExport(String fileName, HttpServletResponse response);
128 129
 
129 130
 }

+ 43 - 30
unis-plugin/unis-plugin-biz/src/main/java/com/unis/equipmentOnlineRateAssessment/modular/monitorCamera/service/impl/MonitorCameraServiceImpl.java

@@ -19,10 +19,12 @@ import cn.hutool.core.date.DateUnit;
19 19
 import cn.hutool.core.date.DateUtil;
20 20
 import cn.hutool.core.util.ObjectUtil;
21 21
 import com.alibaba.excel.EasyExcel;
22
+import com.alibaba.excel.support.ExcelTypeEnum;
22 23
 import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
23 24
 import com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy;
24 25
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
25 26
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
27
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
26 28
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
27 29
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
28 30
 import com.unis.basic.info.modular.orgInfo.entity.OrgInfo;
@@ -32,6 +34,7 @@ import com.unis.equipmentOnlineRateAssessment.modular.monitorCamera.param.*;
32 34
 import com.unis.equipmentOnlineRateAssessment.modular.monitorCamera.vo.*;
33 35
 import com.unis.equipmentOnlineRateAssessment.modular.monitorNvr.entity.MonitorNvr;
34 36
 import com.unis.equipmentOnlineRateAssessment.modular.monitorNvr.mapper.MonitorNvrMapper;
37
+import com.unis.statisticalReport.info.modular.grainTempCheck.entity.GrainTempExcel;
35 38
 import org.springframework.beans.factory.annotation.Autowired;
36 39
 import org.springframework.stereotype.Service;
37 40
 import org.springframework.transaction.annotation.Transactional;
@@ -40,15 +43,15 @@ import com.unis.equipmentOnlineRateAssessment.modular.monitorCamera.entity.Monit
40 43
 import com.unis.equipmentOnlineRateAssessment.modular.monitorCamera.mapper.MonitorCameraMapper;
41 44
 import com.unis.equipmentOnlineRateAssessment.modular.monitorCamera.service.MonitorCameraService;
42 45
 
46
+import javax.servlet.http.HttpServletResponse;
43 47
 import javax.xml.crypto.Data;
44 48
 import java.io.File;
49
+import java.io.IOException;
45 50
 import java.math.BigDecimal;
51
+import java.net.URLEncoder;
46 52
 import java.text.DecimalFormat;
47 53
 import java.text.SimpleDateFormat;
48
-import java.time.Instant;
49
-import java.time.LocalDateTime;
50
-import java.time.LocalTime;
51
-import java.time.ZoneId;
54
+import java.time.*;
52 55
 import java.util.ArrayList;
53 56
 import java.util.Date;
54 57
 import java.util.List;
@@ -215,22 +218,25 @@ public class MonitorCameraServiceImpl extends ServiceImpl<MonitorCameraMapper, M
215 218
      * @date 2024/06/21 10:07
216 219
      */
217 220
     @Override
218
-    public void statisticalAnalysisExport() {
219
-        //TODO 路径改变
220
-        String path = "D://";
221
-        File folder = new File(path);
222
-        if (!folder.isDirectory()) {
223
-            folder.mkdirs();
221
+    public void statisticalAnalysisExport(String fileName, HttpServletResponse response) {
222
+
223
+        try {
224
+            if (StringUtils.isEmpty(fileName))
225
+                fileName = LocalDate.now()+"在线统计分析表";
226
+            fileName = URLEncoder.encode(fileName, "UTF-8");
227
+            // 设置响应信息,让浏览器下载文件
228
+            response.setContentType("application/vnd.ms-excel");
229
+            response.setCharacterEncoding("utf-8");
230
+            response.setHeader("Content-disposition", "attachment;filename=" + fileName + ExcelTypeEnum.XLSX.getValue());
231
+            EasyExcel.write(response.getOutputStream()) // 或, GrainTempExcel.class
232
+                    .head(StatisticalAnalysisVO.class) // write 中, GrainTempExcel.class 二选一
233
+                    .excelType(ExcelTypeEnum.XLSX)
234
+                    .sheet(fileName)
235
+                    .doWrite(orgInfoMapper.statisticalAnalysis());
236
+        } catch (IOException e) {
237
+            log.error("在线统计分析导出异常:{}",e);
238
+            throw new RuntimeException(e);
224 239
         }
225
-
226
-        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
227
-        String dateStr = format.format(new Date());
228
-        String fileName = path + dateStr + "设备在线率考核统计分析" + ".xlsx";
229
-
230
-        EasyExcel.write(fileName, StatisticalAnalysisVO.class)
231
-                .sheet("设备在线率考核统计分析表")
232
-                .doWrite(orgInfoMapper.statisticalAnalysis());
233
-
234 240
     }
235 241
 
236 242
     /**
@@ -344,19 +350,26 @@ public class MonitorCameraServiceImpl extends ServiceImpl<MonitorCameraMapper, M
344 350
      * @date 2024/06/21 10:07
345 351
      */
346 352
     @Override
347
-    public void AutomatedAssessmentsExport() {
348
-        String path = "D://";
349
-        File folder = new File(path);
350
-        if (!folder.isDirectory()) {
351
-            folder.mkdirs();
353
+    public void AutomatedAssessmentsExport(String fileName, HttpServletResponse response) {
354
+
355
+        try {
356
+            if (StringUtils.isEmpty(fileName))
357
+                fileName = LocalDate.now()+ "自动考核数据表";
358
+            fileName = URLEncoder.encode(fileName, "UTF-8");
359
+            // 设置响应信息,让浏览器下载文件
360
+            response.setContentType("application/vnd.ms-excel");
361
+            response.setCharacterEncoding("utf-8");
362
+            response.setHeader("Content-disposition", "attachment;filename=" + fileName + ExcelTypeEnum.XLSX.getValue());
363
+            EasyExcel.write(response.getOutputStream()) // 或, GrainTempExcel.class
364
+                    .head(AutomatedAssessmentsExportVO.class) // write 中, GrainTempExcel.class 二选一
365
+                    .excelType(ExcelTypeEnum.XLSX)
366
+                    .sheet(fileName)
367
+                    .doWrite(this::data);
368
+        } catch (IOException e) {
369
+            log.error("自动考核导出异常:{}",e);
370
+            throw new RuntimeException(e);
352 371
         }
353
-        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
354
-        String dateStr = format.format(new Date());
355
-        String fileName = path + dateStr + "自动考核数据表" + ".xlsx";
356 372
 
357
-        EasyExcel.write(fileName, AutomatedAssessmentsExportVO.class)
358
-                .sheet("自动考核数据表")
359
-                .doWrite(this::data);
360 373
     }
361 374
 
362 375
     private List<AutomatedAssessmentsExportVO> data() {