Procházet zdrojové kódy

修改导出控制层返回值

wyyay před 2 roky
rodič
revize
38820dee15

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

@@ -119,8 +119,7 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
             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(1).setCellValue(date);
+                row.createCell(1).setCellValue(dateStr);
             }
             if (vo.getLineDir() != null) {
                 row.createCell(2).setCellValue(vo.getLineDir());
@@ -141,12 +140,13 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
         //第六步,输出Excel文件
         OutputStream output = response.getOutputStream();
         response.reset();
-        response.setContentType("application/json;charset=utf-8");
+        response.setContentType("application/vnd.ms-excel");
+
         //设置文件头:最后一个参数是设置下载文件名
         long filename = System.currentTimeMillis();
         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
         String fileName = "报警数据详情";
-        response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xlsx");
+        response.addHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
         wb.write(output);
         output.close();
     }
@@ -213,19 +213,18 @@ public class MsgAlarmServiceImpl extends ServiceImpl<MsgAlarmMapper, MsgAlarm> i
             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);
+                row.createCell(4).setCellValue(dateStr);
             }
         }
         //第六步,输出Excel文件
         OutputStream output = response.getOutputStream();
         response.reset();
-        response.setContentType("application/json;charset=utf-8");
+        response.setContentType("application/vnd.ms-excel");
         //设置文件头:最后一个参数是设置下载文件名
         long filename = System.currentTimeMillis();
         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
         String fileName = "报警月统计数据";
-        response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xlsx");
+        response.addHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
         wb.write(output);
         output.close();
     }

+ 2 - 6
hazard-admin/src/main/java/com/ozs/web/controller/accountmanagment/MsgAlarmController.java

@@ -318,18 +318,16 @@ public class MsgAlarmController extends BaseController {
             @ApiImplicitParam(paramType = "query", name = "endMonth", value = "结束月份"),
             @ApiImplicitParam(paramType = "query", name = "alarmType", value = "灾害类型"),
     })
-    public AjaxResult exportDataStatistic(HttpServletResponse response, @RequestBody AlarmStatisticResVo alarmStatisticResVo) {
+    public void exportDataStatistic(HttpServletResponse response, @RequestBody AlarmStatisticResVo alarmStatisticResVo) {
         String userId = "1";//getUserId();
         if ("1".equals(userId)) {
             userId = "";
         }
         try {
             msgAlarmService.exportExcel(response, alarmStatisticResVo, userId);
-            return AjaxResult.success("导出成功");
         } catch (Exception e) {
             e.printStackTrace();
             log.info(e.getMessage());
-            return AjaxResult.error("导出错误");
         }
     }
 
@@ -347,18 +345,16 @@ public class MsgAlarmController extends BaseController {
             @ApiImplicitParam(paramType = "query", name = "endMonth", value = "结束月份"),
             @ApiImplicitParam(paramType = "query", name = "alarmType", value = "灾害类型"),
     })
-    public AjaxResult exportDataStatisticMonth(HttpServletResponse response, @RequestBody AlarmStatisticResVo alarmStatisticResVo) {
+    public void 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("导出错误");
         }
     }
 }