From 3dbc786738cdf005fac8ae5c27023e39a0554a68 Mon Sep 17 00:00:00 2001 From: cjl <909710561@qq.com> Date: Wed, 24 Jan 2024 15:43:42 +0800 Subject: [PATCH] fix:疾控中心设备分钟数据导出 --- screen-job/src/main/java/com/moral/api/controller/PubController.java | 74 ++++++++++++++++++++++++++++++++++--- 1 files changed, 68 insertions(+), 6 deletions(-) diff --git a/screen-job/src/main/java/com/moral/api/controller/PubController.java b/screen-job/src/main/java/com/moral/api/controller/PubController.java index 3a54e5b..e9eb49c 100644 --- a/screen-job/src/main/java/com/moral/api/controller/PubController.java +++ b/screen-job/src/main/java/com/moral/api/controller/PubController.java @@ -1,6 +1,9 @@ package com.moral.api.controller; import com.moral.api.service.*; +import com.moral.api.util.DeviceExcelDTO; +import com.moral.api.util.EmailSpringUtil; +import com.moral.api.util.ExcelUtil; import com.moral.api.util.HttpUtils; import com.moral.constant.ResultMessage; import com.moral.util.DateUtils; @@ -10,13 +13,15 @@ import org.apache.http.HttpResponse; import org.apache.http.util.EntityUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ByteArrayResource; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; +import javax.mail.MessagingException; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.*; /** * @ClassName UserController @@ -44,6 +49,12 @@ private HistoryAqiService historyAqiService; @Autowired private HistoryHourlyService historyHourlyService; + @Autowired + private HistoryMonthlyService historyMonthlyService; + @Autowired + private DeviceService deviceService; + @Autowired + private EmailSpringUtil emailSpringUtil; @GetMapping("insertHistoryDaily") @ApiOperation(value = "���������������", notes = "���������������") @@ -57,7 +68,24 @@ @GetMapping("insertHistoryFiveMinutely") @ApiOperation(value = "5������������", notes = "5������������") public ResultMessage insertHistoryFiveMinutely() { + String format = DateUtils.yyyy_MM_dd_HH_mm_EN; historyFiveMinutelyService.insertHistoryFiveMinutely(); + String s ="2023-10-13 03:35"; + String s1 ="2023-10-13 03:40"; + Date start = DateUtils.getDate(s,format); + Date end = DateUtils.getDate(s1,format); + return new ResultMessage(); + } + + @GetMapping("dateInsertHistoryHourlyJKAvg") + @ApiOperation(value = "������������������������", notes = "������������������������") + public ResultMessage dateInsertHistoryHourlyJKAvg(String start,String end) { +// String format = DateUtils.yyyy_MM_dd_HH_mm_EN; +// String start ="2023-11-19 09:00" +// String end ="2023-11-19 10:00"; +// Date start1 = DateUtils.getDate(start,format); +// Date end1 = DateUtils.getDate(end,format); + historyHourlyService.dateInsertHistoryHourlyJKAvg(start, end); return new ResultMessage(); } @@ -70,8 +98,8 @@ @GetMapping("insertHistoryAqi") @ApiOperation(value = "������������������", notes = "������������������") - public ResultMessage insertHistoryAqi() { - historyAqiService.insertHistoryAqi(); + public ResultMessage insertHistoryAqi(String time) { + historyAqiService.insertHistoryAqi(time); return new ResultMessage(); } @@ -98,6 +126,13 @@ @ApiOperation(value = "������������������������", notes = "������������������������") public ResultMessage insertCityWeather() { cityWeatherService.insertCityWeather(); + return new ResultMessage(); + } + + @GetMapping("insertHistoryMonthly") + @ApiOperation(value = "���������", notes = "���������") + public ResultMessage insertHistoryMonthly() { + historyMonthlyService.insertHistoryMonthly(); return new ResultMessage(); } @@ -133,5 +168,32 @@ } } - + @GetMapping("excelDevice") + @ApiOperation(value = "excle", notes = "excle") + public void excelDevice() throws IOException { + String startTime = DateUtils.dateToDateString(DateUtils.addDays(new Date(),-1),DateUtils.yyyy_MM_dd_EN); + List<DeviceExcelDTO> list = deviceService.ListDeviceExcel(startTime,null,72); + String path = Objects.requireNonNull(this.getClass().getClassLoader().getResource("")).getPath(); + String fileName = String.format("%s������������������-%s.xlsx",path,startTime); + ByteArrayOutputStream out = null; + try { + // ������excel������ + out = ExcelUtil.generateExcel(list, DeviceExcelDTO.class); + // ������������ + String content = startTime+"������������������������������"; + String toMail = "909710561@qq.com"; + emailSpringUtil.sendEmail("������������������",content,false,"909710561@qq.com", + toMail,"null",null, fileName, new ByteArrayResource(out.toByteArray())); + } catch (IOException e) { + log.error(String.format("������excel������������������%s",e)); + e.printStackTrace(); + } catch (MessagingException e) { + log.error(String.format("������������������������������%s",e)); + e.printStackTrace(); + }finally { + if(out != null){ + out.close(); + } + } + } } -- Gitblit v1.8.0