| | |
| | | import javax.mail.MessagingException; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.nio.file.Files; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | private HistoryMonthlyService historyMonthlyService; |
| | | @Autowired |
| | | private DeviceService deviceService; |
| | | @Autowired |
| | | private EmailSpringUtil emailSpringUtil; |
| | | |
| | | private final EmailSpringUtil emailSpringUtil; |
| | | |
| | | public PubController(EmailSpringUtil emailSpringUtil) { |
| | | this.emailSpringUtil = emailSpringUtil; |
| | | } |
| | | |
| | | @GetMapping("insertHistoryDaily") |
| | | @ApiOperation(value = "天数据补录", notes = "天数据补录") |
| | |
| | | @GetMapping("dateInsertHistoryHourlyJKAvg") |
| | | @ApiOperation(value = "疾控中心小时数据", notes = "疾控中心小时数据") |
| | | public ResultMessage dateInsertHistoryHourlyJKAvg(String start,String end) { |
| | | Date ks = DateUtils.getDate(start,"yyyy-MM-dd HH:mm:ss"); |
| | | Date js = DateUtils.getDate("2024-01-23 13:00:00","yyyy-MM-dd HH:mm:ss"); |
| | | Date ends = DateUtils.getDate(end,"yyyy-MM-dd HH:mm:ss"); |
| | | while (DateUtils.isTimeBefor(js,ks)){ |
| | | String dateString = DateUtils.dateToDateString(ks); |
| | | String dateString1 = DateUtils.dateToDateString(ends); |
| | | // historyHourlyService.dateInsertHistoryHourlyJKAvg(start, end); |
| | | historyHourlyService.dateInsertHistoryHourlyJKAvg(dateString, dateString1); |
| | | ks = DateUtils.getDateAddHour(ks,1); |
| | | ends = DateUtils.getDateAddHour(ends,1); |
| | | } |
| | | // 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(); |
| | | } |
| | | |
| | |
| | | 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 path = this.getClass().getClassLoader().getResource("/data/file").getPath(); |
| | | String path = System.getProperty("user.dir")+"/"; |
| | | String fileName = String.format("%s疾控中心数据-%s.xlsx",path,startTime); |
| | | ByteArrayOutputStream out = null; |
| | | try { |
| | |
| | | out = ExcelUtil.generateExcel(list, DeviceExcelDTO.class); |
| | | // 发送邮件 |
| | | String content = startTime+"疾控中心设备统计数据"; |
| | | String toMail = "909710561@qq.com"; |
| | | String toMail = "ad@7drlb.com"; |
| | | emailSpringUtil.sendEmail("设备分钟数据",content,false,"909710561@qq.com", |
| | | toMail,"null",null, fileName, new ByteArrayResource(out.toByteArray())); |
| | | toMail,"909710561@qq.com",null, fileName, new ByteArrayResource(out.toByteArray())); |
| | | } catch (IOException e) { |
| | | log.error(String.format("生成excel失败,原因:%s",e)); |
| | | e.printStackTrace(); |