| | |
| | | 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; |
| | |
| | | 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 |
| | |
| | | private HistoryHourlyService historyHourlyService; |
| | | @Autowired |
| | | private HistoryMonthlyService historyMonthlyService; |
| | | @Autowired |
| | | private DeviceService deviceService; |
| | | |
| | | @Autowired |
| | | private ManageCoordinateDetailService manageCoordinateDetailService; |
| | | |
| | | @Autowired |
| | | private HistorySecondCruiserService historySecondCruiserService; |
| | | |
| | | private final EmailSpringUtil emailSpringUtil; |
| | | private final CityWeatherForecastService cityWeatherForecastService; |
| | | |
| | | public PubController(EmailSpringUtil emailSpringUtil, CityWeatherForecastService cityWeatherForecastService) { |
| | | this.emailSpringUtil = emailSpringUtil; |
| | | this.cityWeatherForecastService = cityWeatherForecastService; |
| | | } |
| | | |
| | | @GetMapping("insertHistoryDaily") |
| | | @ApiOperation(value = "天数据补录", notes = "天数据补录") |
| | |
| | | } |
| | | |
| | | @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"; |
| | | @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 start = DateUtils.getDate(s,format); |
| | | // Date end = DateUtils.getDate(s1,format); |
| | | historyHourlyService.dateInsertHistoryHourlyJKAvg(start, end); |
| | | // Date start1 = DateUtils.getDate(start,format); |
| | | // Date end1 = DateUtils.getDate(end,format); |
| | | |
| | | return new ResultMessage(); |
| | | } |
| | | |
| | |
| | | @ApiOperation(value = "过控制战补偿", notes = "过控制战补偿") |
| | | public ResultMessage insertHistoryAqi(String time) { |
| | | historyAqiService.insertHistoryAqi(time); |
| | | return new ResultMessage(); |
| | | } |
| | | |
| | | @GetMapping("insertHistoryHourly") |
| | | @ApiOperation(value = "缺失小时数据补充", notes = "缺失小时数据补充") |
| | | public ResultMessage insertHistoryHourly() { |
| | | historyHourlyService.insertHistoryHourly(); |
| | | return new ResultMessage(); |
| | | } |
| | | |
| | |
| | | return new ResultMessage(); |
| | | } |
| | | |
| | | @GetMapping("insertCityWeatherForecast") |
| | | @ApiOperation(value = "城市每日天气预测", notes = "城市每日天气预测") |
| | | public ResultMessage insertCityWeatherForecast() { |
| | | cityWeatherForecastService.insertCityWeatherForecast(); |
| | | return new ResultMessage(); |
| | | } |
| | | |
| | | @GetMapping("insertHistoryMonthly") |
| | | @ApiOperation(value = "月数据", notes = "月数据") |
| | | public ResultMessage insertHistoryMonthly() { |
| | | historyMonthlyService.insertHistoryMonthly(); |
| | | return new ResultMessage(); |
| | | } |
| | | |
| | | @GetMapping("secondCruiserSort") |
| | | @ApiOperation(value = "走航车排名", notes = "走航车排名") |
| | | public ResultMessage secondCruiserSort() { |
| | | String startTime ="2024-11-13 00:00:00"; |
| | | String endTime ="2024-11-14 00:00:00"; |
| | | historySecondCruiserService.sort(startTime,endTime); |
| | | return new ResultMessage(); |
| | | } |
| | | |
| | | @GetMapping("insertCoordinateDetail") |
| | | @ApiOperation(value = "路段录入", notes = "路段录入") |
| | | public ResultMessage insertCoordinateDetail() { |
| | | String startTime ="2024-06-06 00:07:01"; |
| | | String endTime ="2024-06-06 23:07:01"; |
| | | manageCoordinateDetailService.insertCoordinateDetail(startTime,endTime); |
| | | return new ResultMessage(); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | @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 = 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 { |
| | | // 生成excel文件 |
| | | out = ExcelUtil.generateExcel(list, DeviceExcelDTO.class); |
| | | // 发送邮件 |
| | | String content = startTime+"疾控中心设备统计数据"; |
| | | String toMail = "ad@7drlb.com"; |
| | | emailSpringUtil.sendEmail("设备分钟数据",content,false,"909710561@qq.com", |
| | | toMail,"909710561@qq.com",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(); |
| | | } |
| | | } |
| | | } |
| | | } |