| | |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.ycl.service.redis.RedisService; |
| | | import com.ycl.smoke.entity.*; |
| | | import com.ycl.smoke.dto.*; |
| | | import com.ycl.smoke.remote.service.ISmokeDetectionService; |
| | | import com.ycl.smoke.service.*; |
| | | import com.ycl.smoke.utils.HttpUtil; |
| | | import com.ycl.utils.redis.RedisKey; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.DateFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Component |
| | | public class ScheduledTask { |
| | | |
| | | private final String host = "http://116.62.234.187:8120"; |
| | | ISmokeDetectionService smokeDetectionService; |
| | | |
| | | IOdsAlarmMsgService alarmMsgService; |
| | |
| | | IOdsAlarmRecordService alarmRecordService; |
| | | |
| | | IOdsCurAlarmService curAlarmService; |
| | | |
| | | IOdsStatisticsService odsStatisticsService; |
| | | |
| | | @Resource |
| | | private RedisService redisService; |
| | |
| | | @Autowired |
| | | public void setDetectorDailyService(IOdsDetectorDailyService detectorDailyService) { |
| | | this.detectorDailyService = detectorDailyService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setOdsStatisticsService(IOdsStatisticsService odsStatisticsService) { |
| | | this.odsStatisticsService = odsStatisticsService; |
| | | } |
| | | |
| | | @Scheduled(cron = "0 0 1 * * ?") // 每天零点执行 |
| | |
| | | } |
| | | } |
| | | |
| | | @Scheduled(cron = "0 */30 * * * ?") // 每5分钟执行 |
| | | public void loginTask() { |
| | | login(); |
| | | } |
| | | |
| | | // @Scheduled(cron = "0 0 1 * * ?") // 每天零点执行 |
| | | @Scheduled(cron = "0 */1 * * * ?") // 每5分钟执行 |
| | |
| | | |
| | | private void getInTimeData(DataIntimeParamDto paramDto) { |
| | | try { |
| | | String jj = JSON.toJSONString(paramDto); |
| | | String json = smokeDetectionService.listDataIntime(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 监测报警统计 运维情况报表 |
| | | */ |
| | | @Scheduled(cron = "0 0 1 * * ?") // 每天零点执行 |
| | | // @Scheduled(cron = "0/1 * * * * ?") // 每秒执行 |
| | | public void listCurAlarm() { |
| | | try { |
| | | CurAlarmParamDto paramDto = CurAlarmParamDto.builder().Typ(2).build(); |
| | | CurAlarmParamDto paramDto = CurAlarmParamDto.builder().StartAt(0).Size(20).SortBy("status").SortMode("asc").Typ(2).build(); |
| | | CurAlarmParamChildDto childDto = CurAlarmParamChildDto.builder().build(); |
| | | |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.add(Calendar.DAY_OF_MONTH, -1); |
| | | long todayZero = calendar.getTimeInMillis(); |
| | | |
| | | calendar.add(Calendar.DAY_OF_MONTH, 1); |
| | | calendar.add(Calendar.MONTH, -1); |
| | | long lastMonthZero = calendar.getTimeInMillis(); |
| | | |
| | | childDto.setStartAt(lastMonthZero / 1000); |
| | | childDto.setEndAt(todayZero / 1000); |
| | | childDto.setLocaleWithDevice(true); |
| | | paramDto.setParam(childDto); |
| | | |
| | | String json = smokeDetectionService.getListCurAlarm(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | |
| | | List<OdsCurAlarm> list = responseDataDto.getContent(); |
| | | list.forEach(o -> { |
| | | try { |
| | | curAlarmService.save(o); |
| | | curAlarmService.saveByLocalId(o); |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | | } |
| | |
| | | // alarmMsgService.saveBatch(list); |
| | | } else if (responseDto.getStatus() == 114) { |
| | | login(); |
| | | queryDataDetectorDaily2Task(); |
| | | listCurAlarm(); |
| | | } else { |
| | | System.out.printf(responseDto.getData().toString()); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 检测仪总体情况报表 |
| | | */ |
| | | @Scheduled(cron = "0 0 1 * * ?") // 每天零点执行 |
| | | // @Scheduled(cron = "0/1 * * * * ?") // 每秒执行 |
| | | public void listDataDetectorDailyStats() { |
| | | try { |
| | | DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | String dateEnd = df.format(calendar.getTime()); |
| | | |
| | | calendar.add(Calendar.MONTH, -1); |
| | | String dateBegin = df.format(calendar.getTime()); |
| | | |
| | | DataDetectorDailyStatsParamDto paramDto = DataDetectorDailyStatsParamDto.builder().Typ(1).WithAreaLocaleReport(false) |
| | | .AcquitDateBegin(dateBegin).AcquitDateEnd(dateEnd).build(); |
| | | String json = smokeDetectionService.getListDataDetectorDailyStats(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | |
| | | if (responseDto.getStatus() == 200) { |
| | | LambdaUpdateWrapper<OdsStatistics> update = new LambdaUpdateWrapper<OdsStatistics>() |
| | | .eq(OdsStatistics::getTypeName, "listDataDetectorDailyStats") |
| | | .set(OdsStatistics::getContent, responseDto.getData().toString()); |
| | | |
| | | odsStatisticsService.update(update); |
| | | } else if (responseDto.getStatus() == 114) { |
| | | login(); |
| | | listDataDetectorDailyStats(); |
| | | } else { |
| | | System.out.printf(responseDto.getData().toString()); |
| | | } |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 油烟减排统计 |
| | | */ |
| | | @Scheduled(cron = "0 0 1 * * ?") // 每天零点执行 |
| | | // @Scheduled(cron = "0/1 * * * * ?") // 每秒执行 |
| | | public void listDetectorDaily() { |
| | | try { |
| | | CurAlarmParam2Dto paramDto = CurAlarmParam2Dto.builder().StartAt(0).Size(20).build(); |
| | | CurAlarmParamChild2Dto childDto = CurAlarmParamChild2Dto.builder().build(); |
| | | |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.add(Calendar.DAY_OF_MONTH, -1); |
| | | long todayZero = calendar.getTimeInMillis(); |
| | | |
| | | calendar.add(Calendar.DAY_OF_MONTH, 1); |
| | | calendar.add(Calendar.MONTH, -1); |
| | | long lastMonthZero = calendar.getTimeInMillis(); |
| | | |
| | | childDto.setStartAt(lastMonthZero / 1000); |
| | | childDto.setEndAt(todayZero / 1000); |
| | | paramDto.setParam(childDto); |
| | | // {"StartAt":0,"Size":20,"Param":{"startAt":1697040000,"endAt":1699631999}}: |
| | | String json = smokeDetectionService.getListDetectorDaily(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | |
| | | if (responseDto.getStatus() == 200) { |
| | | LambdaUpdateWrapper<OdsStatistics> update = new LambdaUpdateWrapper<OdsStatistics>() |
| | | .eq(OdsStatistics::getTypeName, "listDetectorDaily") |
| | | .set(OdsStatistics::getContent, responseDto.getData().toString()); |
| | | |
| | | odsStatisticsService.update(update); |
| | | } else if (responseDto.getStatus() == 114) { |
| | | login(); |
| | | listDetectorDaily(); |
| | | } else { |
| | | System.out.printf(responseDto.getData().toString()); |
| | | } |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | void login() { |
| | | LoginParamDto loginParamDto = LoginParamDto.builder().username("遂昌城管局").password("123456").noCode(true).build(); |
| | | String json = smokeDetectionService.loginAction(loginParamDto); |