Selaa lähdekoodia

Merge branch 'master' of http://124.70.58.209:3000/ytrd-project-management/GeoHazardMonitor

hexiao 2 vuotta sitten
vanhempi
commit
dca77aeb74

+ 3 - 0
business-service/src/main/java/com/ozs/service/service/MsgAlarmService.java

@@ -26,4 +26,7 @@ public interface MsgAlarmService extends IService<MsgAlarm> {
 
     //web数据统计 报警数据详情导出
     void exportExcel(HttpServletResponse response, AlarmStatisticResVo alarmStatisticResVo, String userId) throws Exception;
+
+    //web数据统计 报警月统计数据导出
+    void exportExcelMonth(HttpServletResponse response, AlarmStatisticResVo alarmStatisticResVo, String userId) throws Exception;
 }

+ 90 - 8
business-service/src/main/java/com/ozs/service/service/impl/MsgAlarmServiceImpl.java

@@ -110,29 +110,32 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
                 alarmStatisticResVo.getEndMonth(), alarmStatisticResVo.getAlarmType(), userId);
         //将数据写入表格
         for (int i = 0; i < list.size(); i++) {
-            HSSFCell cel = row.createCell(i + 1);
+            row = sheet.createRow(i + 1);
             AlarmStatisticVo vo = list.get(i);
             // 第四步,创建单元格,并设置值
             if (StringUtils.isNotEmpty(vo.getBaseCameraManagement().getRailwayCode())) {
-                cel.setCellValue(vo.getBaseCameraManagement().getRailwayCode());
+                row.createCell(0).setCellValue(vo.getBaseCameraManagement().getRailwayCode());
             }
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
             if (vo.getAlarmTime() != null) {
-                cel.setCellValue(vo.getAlarmTime());
+                String dateStr = sdf.format(vo.getAlarmTime());
+                Date date = sdf.parse(dateStr);
+                row.createCell(1).setCellValue(date);
             }
             if (vo.getLineDir() != null) {
-                cel.setCellValue(vo.getLineDir());
+                row.createCell(2).setCellValue(vo.getLineDir());
             }
             if (vo.getAlarmType() != null) {
-                cel.setCellValue(vo.getAlarmType());
+                row.createCell(3).setCellValue(vo.getAlarmType());
             }
             if (vo.getBaseCameraManagement().getInstallMile() != null) {
-                cel.setCellValue(vo.getBaseCameraManagement().getInstallMile());
+                row.createCell(4).setCellValue(vo.getBaseCameraManagement().getInstallMile());
             }
             if (vo.getBaseCameraManagement().getBeginMile() != null) {
-                cel.setCellValue(vo.getBaseCameraManagement().getBeginMile());
+                row.createCell(5).setCellValue(vo.getBaseCameraManagement().getBeginMile());
             }
             if (vo.getBaseCameraManagement().getEndMile() != null) {
-                cel.setCellValue(vo.getBaseCameraManagement().getEndMile());
+                row.createCell(6).setCellValue(vo.getBaseCameraManagement().getEndMile());
             }
         }
         //第六步,输出Excel文件
@@ -147,4 +150,83 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
         wb.write(output);
         output.close();
     }
+
+    @Override
+    public void exportExcelMonth(HttpServletResponse response, AlarmStatisticResVo alarmStatisticResVo, String userId) throws Exception {
+        // 第一步,创建一个webbook,对应一个Excel文件
+        HSSFWorkbook wb = new HSSFWorkbook();
+        // 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
+        HSSFSheet sheet = wb.createSheet("报警月统计数据");
+        // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
+        HSSFRow row = sheet.createRow(0);
+        // 第四步,创建单元格,并设置值表头 设置表头居中
+        HSSFCellStyle style = wb.createCellStyle();
+        //单元格边框
+        //style.setAlignment(BorderStyle.THIN); // 创建一个居中格式
+        style.setBorderBottom(BorderStyle.THIN); //下边框
+        style.setBorderLeft(BorderStyle.THIN);//左边框
+        style.setBorderTop(BorderStyle.THIN);//上边框
+        style.setBorderRight(BorderStyle.THIN);//右边框
+        //设置单元格字体大小
+        HSSFFont font = wb.createFont();
+        font.setFontName("宋体");
+        font.setFontHeightInPoints((short) 11);//设置字体大小
+        //font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
+        style.setFont(font);//选择需要用到的字体格式
+
+        HSSFCell cell = row.createCell(0);
+        cell.setCellValue("线路");
+        cell.setCellStyle(style);
+        cell = row.createCell(1);
+        cell.setCellValue("报警类型");
+        cell.setCellStyle(style);
+        cell = row.createCell(2);
+        cell.setCellValue("报警月份");
+        cell.setCellStyle(style);
+        cell = row.createCell(3);
+        cell.setCellValue("报警次数");
+        cell.setCellStyle(style);
+        cell = row.createCell(4);
+        cell.setCellValue("报警时间");
+        cell.setCellStyle(style);
+
+        //调取数据
+        List<AlarmStatisticVo> list = msgAlarmMapper.listMonth(alarmStatisticResVo.getRailwayCode(), alarmStatisticResVo.getStartMonth(),
+                alarmStatisticResVo.getEndMonth(), alarmStatisticResVo.getAlarmType(), userId);
+        //将数据写入表格
+        for (int i = 0; i < list.size(); i++) {
+            row = sheet.createRow(i + 1);
+            AlarmStatisticVo vo = list.get(i);
+            // 第四步,创建单元格,并设置值
+            if (StringUtils.isNotEmpty(vo.getBaseCameraManagement().getRailwayCode())) {
+                row.createCell(0).setCellValue(vo.getBaseCameraManagement().getRailwayCode());
+            }
+            if (vo.getAlarmType() != null) {
+                row.createCell(1).setCellValue(vo.getAlarmType());
+            }
+            if (vo.getMonthsta() != null) {
+                row.createCell(2).setCellValue(vo.getMonthsta());
+            }
+            if (vo.getFrequency() != null) {
+                row.createCell(3).setCellValue(vo.getFrequency());
+            }
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            if (vo.getAlarmTime() != null) {
+                String dateStr = sdf.format(vo.getAlarmTime());
+                Date date = sdf.parse(dateStr);
+                row.createCell(4).setCellValue(date);
+            }
+        }
+        //第六步,输出Excel文件
+        OutputStream output = response.getOutputStream();
+        response.reset();
+        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+        //设置文件头:最后一个参数是设置下载文件名
+        long filename = System.currentTimeMillis();
+        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
+        String fileName = "报警月统计数据";
+        response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xlsx");
+        wb.write(output);
+        output.close();
+    }
 }

+ 29 - 0
hazard-admin/src/main/java/com/ozs/web/controller/accountmanagment/MsgAlarmController.java

@@ -310,5 +310,34 @@ public class MsgAlarmController extends BaseController {
             return AjaxResult.error("导出错误");
         }
     }
+
+    /**
+     * web数据统计 数据导出
+     *
+     * @param
+     * @return
+     */
+    @PostMapping("/exportDataStatisticMonth")
+    @ApiOperation(value = "报警月统计数据导出")
+    @ApiImplicitParams(value = {
+            @ApiImplicitParam(paramType = "query", name = "railwayCode", value = "线路编码"),
+            @ApiImplicitParam(paramType = "query", name = "startMonth", value = "起始月份"),
+            @ApiImplicitParam(paramType = "query", name = "endMonth", value = "结束月份"),
+            @ApiImplicitParam(paramType = "query", name = "alarmType", value = "灾害类型"),
+    })
+    public AjaxResult exportDataStatisticMonth(HttpServletResponse response, @RequestBody AlarmStatisticResVo alarmStatisticResVo) {
+        String userId = "1";//getUserId();
+        if ("1".equals(userId)) {
+            userId = "";
+        }
+        try {
+            msgAlarmService.exportExcelMonth(response, alarmStatisticResVo, userId);
+            return AjaxResult.success("导出成功");
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.info(e.getMessage());
+            return AjaxResult.error("导出错误");
+        }
+    }
 }