| | |
| | | package com.ycl.smoke.task; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.aliyuncs.utils.StringUtils; |
| | | 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.OdsAlarmMsg; |
| | | import com.ycl.smoke.remote.dto.*; |
| | | import com.ycl.smoke.entity.*; |
| | | import com.ycl.smoke.dto.*; |
| | | import com.ycl.smoke.remote.service.ISmokeDetectionService; |
| | | import com.ycl.smoke.service.IOdsAlarmMsgService; |
| | | import com.ycl.smoke.service.*; |
| | | import com.ycl.smoke.utils.HttpUtil; |
| | | import com.ycl.utils.redis.RedisKey; |
| | | import org.apache.velocity.runtime.directive.Foreach; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.text.DateFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | |
| | | @Component |
| | | public class ScheduledTask { |
| | | |
| | | private final String host = "http://116.62.234.187:8120"; |
| | | ISmokeDetectionService smokeDetectionService; |
| | | |
| | | IOdsAlarmMsgService alarmMsgService; |
| | | |
| | | IOdsDetectorDailyService detectorDailyService; |
| | | |
| | | IOdsTenMinDataService tenMinDataService; |
| | | |
| | | IOdsInTimeService inTimeService; |
| | | |
| | | IOdsInTimeCountService iOdsInTimeCountService; |
| | | |
| | | IOdsLocaleService localeService; |
| | | |
| | | IOdsCustomerService customerService; |
| | | |
| | | IOdsAlarmRecordService alarmRecordService; |
| | | |
| | | IOdsCurAlarmService curAlarmService; |
| | | |
| | | IOdsStatisticsService odsStatisticsService; |
| | | IOdsLocaleDocumentService localeDocumentService; |
| | | |
| | | @Resource |
| | | private RedisService redisService; |
| | |
| | | } |
| | | |
| | | @Autowired |
| | | public void setIOdsInTimeCountService(IOdsInTimeCountService iOdsInTimeCountService) { |
| | | this.iOdsInTimeCountService = iOdsInTimeCountService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setAlarmMsgService(IOdsAlarmMsgService alarmMsgService) { |
| | | this.alarmMsgService = alarmMsgService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setTenMinDataService(IOdsTenMinDataService tenMinDataService) { |
| | | this.tenMinDataService = tenMinDataService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setInTimeService(IOdsInTimeService inTimeService) { |
| | | this.inTimeService = inTimeService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setLocaleService(IOdsLocaleService localeService) { |
| | | this.localeService = localeService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setCustomerService(IOdsCustomerService customerService) { |
| | | this.customerService = customerService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setAlarmRecordService(IOdsAlarmRecordService alarmRecordService) { |
| | | this.alarmRecordService = alarmRecordService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setCurAlarmService(IOdsCurAlarmService curAlarmService) { |
| | | this.curAlarmService = curAlarmService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setDetectorDailyService(IOdsDetectorDailyService detectorDailyService) { |
| | | this.detectorDailyService = detectorDailyService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setOdsStatisticsService(IOdsStatisticsService odsStatisticsService) { |
| | | this.odsStatisticsService = odsStatisticsService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setLocaleDocumentService(IOdsLocaleDocumentService localeDocumentService) { |
| | | this.localeDocumentService = localeDocumentService; |
| | | } |
| | | |
| | | @PostConstruct |
| | | public void start() { |
| | | alarmMsgTask(); |
| | | queryDataDetectorDaily2Task(); |
| | | queryTenMinData(); |
| | | listLocale(); |
| | | listAlarmRecord(); |
| | | listCurAlarm(); |
| | | listDataDetectorDailyStats(); |
| | | listDetectorDaily(); |
| | | } |
| | | |
| | | |
| | | @Scheduled(cron = "0 0 1 * * ?") // 每天零点执行 |
| | | // @Scheduled(cron = "0 */2 * * * ?") // 每一个分钟执行 0 0/1 * ? |
| | | // @Scheduled(cron = "0/1 * * * * ?") // 每秒执行 |
| | | public void alarmMsgTask() { |
| | | try { |
| | | AlarmMsgParamDto paramDto = AlarmMsgParamDto.builder().StartAt(0).Size(100).build(); |
| | | String json = smokeDetectionService.getListAlarmMsg(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | |
| | | SmokeResultResponseDto<AlarmMsgResponseDto> responseDto = smokeDetectionService.getListAlarmMsg(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | if (responseDto.getStatus() == 200) { |
| | | AlarmMsgResponseDto dto = responseDto.getData(); |
| | | AlarmMsgResponseDto dto = JSON.parseObject(responseDto.getData().toString(), AlarmMsgResponseDto.class); |
| | | List<OdsAlarmMsg> list = dto.getContent(); |
| | | System.out.println(list.size()); |
| | | list.forEach(o->{ |
| | | // System.out.println(list.size()); |
| | | list.forEach(o -> { |
| | | try { |
| | | alarmMsgService.save(o); |
| | | } |
| | | catch (Exception ex){ |
| | | |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | | } |
| | | }); |
| | | // alarmMsgService.saveBatch(list); |
| | | } else if (responseDto.getStatus() == 114) { |
| | | login(); |
| | | alarmMsgTask(); |
| | | } else { |
| | | System.out.printf(responseDto.getData().toString()); |
| | | } |
| | | } catch (Exception ex) { |
| | | |
| | | System.out.printf(ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Scheduled(cron = "0 0 1 * * ?") // 每天零点执行 |
| | | // @Scheduled(cron = "0 */2 * * * ?") // 每一个分钟执行 0 0/1 * ? |
| | | // @Scheduled(cron = "0/1 * * * * ?") // 每秒执行 |
| | | // @Scheduled(cron = "0/1 * * * * ?") // 每秒执行 |
| | | public void queryDataDetectorDaily2Task() { |
| | | try { |
| | | AlarmMsgParamDto paramDto = AlarmMsgParamDto.builder().StartAt(0).Size(100).build(); |
| | | LocalDateTime ldt = LocalDateTime.now(); |
| | | ldt = ldt.plusDays(-1); |
| | | DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | |
| | | SmokeResultResponseDto<AlarmMsgResponseDto> responseDto = smokeDetectionService.getListAlarmMsg(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | DetectorDailyParamDto paramDto = DetectorDailyParamDto.builder().AcquitDate(ldt.format(pattern)).build(); |
| | | |
| | | String json = smokeDetectionService.queryDataDetectorDaily2(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | if (responseDto.getStatus() == 200) { |
| | | AlarmMsgResponseDto dto = responseDto.getData(); |
| | | List<OdsAlarmMsg> list = dto.getContent(); |
| | | System.out.println(list.size()); |
| | | list.forEach(o->{ |
| | | DetectorDailyResponseDto dto = JSON.parseObject(responseDto.getData().toString(), DetectorDailyResponseDto.class); |
| | | List<OdsDetectorDaily> list = dto.getContent(); |
| | | list.forEach(o -> { |
| | | try { |
| | | alarmMsgService.save(o); |
| | | } |
| | | catch (Exception ex){ |
| | | detectorDailyService.save(o); |
| | | } catch (Exception ex) { |
| | | |
| | | System.out.printf(ex.getMessage()); |
| | | } |
| | | }); |
| | | // alarmMsgService.saveBatch(list); |
| | | } else if (responseDto.getStatus() == 114) { |
| | | login(); |
| | | queryDataDetectorDaily2Task(); |
| | | } 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 queryTenMinData() { |
| | | try { |
| | | TenMinParamDto paramDto = TenMinParamDto.builder().build(); |
| | | String json = smokeDetectionService.queryTenMinData(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | |
| | | if (responseDto.getStatus() == 200) { |
| | | List<OdsTenMinData> list = JSON.parseArray(responseDto.getData().toString(), OdsTenMinData.class); |
| | | list.forEach(o -> { |
| | | try { |
| | | tenMinDataService.save(o); |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | | } |
| | | }); |
| | | // alarmMsgService.saveBatch(list); |
| | | } else if (responseDto.getStatus() == 114) { |
| | | queryDataDetectorDaily2Task(); |
| | | } else { |
| | | System.out.printf(responseDto.getData().toString()); |
| | | } |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Scheduled(cron = "0 */30 * * * ?") // 每30分钟执行 |
| | | public void loginTask() { |
| | | login(); |
| | | } |
| | | |
| | | // @Scheduled(cron = "0 0 1 * * ?") // 每天零点执行 |
| | | @Scheduled(cron = "0 */5 * * * ?") // 每5分钟执行 |
| | | public void listDataInTime() { |
| | | DataIntimeParamDto paramDto = DataIntimeParamDto.builder().build(); |
| | | // {"StartAt":0,"Size":20,"Typ":2,"SortBy":"status","SortMode":"asc","Param":{"StatusOfRecord":"NORMAL"}} |
| | | paramDto.setSize(20); |
| | | paramDto.setStartAt(0); |
| | | paramDto.setTyp(2); |
| | | paramDto.setSortBy("status"); |
| | | paramDto.setSortMode("asc"); |
| | | |
| | | DataIntimeParamChildDto paramChildDto = new DataIntimeParamChildDto(); |
| | | paramChildDto.setStatusOfRecord("NORMAL"); |
| | | paramDto.setParam(paramChildDto); |
| | | |
| | | getInTimeData(paramDto); |
| | | |
| | | paramDto.setTyp(1); |
| | | getInTimeData(paramDto); |
| | | } |
| | | |
| | | private void getInTimeData(DataIntimeParamDto paramDto) { |
| | | try { |
| | | String json = smokeDetectionService.listDataIntime(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | |
| | | if (responseDto.getStatus() == 200) { |
| | | DataIntimeResponseDto dataIntimeResponseDto = JSON.parseObject(responseDto.getData().toString(), DataIntimeResponseDto.class); |
| | | List<OdsInTime> list = dataIntimeResponseDto.getContent(); |
| | | |
| | | OdsInTimeCount odsInTimeCount = new OdsInTimeCount(); |
| | | LambdaQueryWrapper<OdsInTimeCount> queryWrapper = new LambdaQueryWrapper<OdsInTimeCount>().eq(OdsInTimeCount::getType, paramDto.getTyp()); |
| | | List<OdsInTimeCount> countList = iOdsInTimeCountService.list(queryWrapper); |
| | | if (countList.size() > 0) { |
| | | odsInTimeCount = countList.get(0); |
| | | } |
| | | odsInTimeCount.setDeviceNum(dataIntimeResponseDto.getDeviceNum()); |
| | | odsInTimeCount.setLocaleNum(dataIntimeResponseDto.getLocaleNum()); |
| | | odsInTimeCount.setOnlineNum(dataIntimeResponseDto.getOnlineNum()); |
| | | odsInTimeCount.setTotal(dataIntimeResponseDto.getTotal()); |
| | | iOdsInTimeCountService.saveOrUpdate(odsInTimeCount); |
| | | |
| | | list.forEach(o -> { |
| | | try { |
| | | o.setModifyTime(LocalDateTime.now()); |
| | | o.setTyp(paramDto.getTyp()); |
| | | inTimeService.saveOrUpdate(o); |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | | } |
| | | }); |
| | | // alarmMsgService.saveBatch(list); |
| | | } else if (responseDto.getStatus() == 114) { |
| | | queryDataDetectorDaily2Task(); |
| | | } 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 listLocale() { |
| | | try { |
| | | LocaleParamDto paramDto = LocaleParamDto.builder().build(); |
| | | |
| | | String json = smokeDetectionService.listLocale(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | |
| | | if (responseDto.getStatus() == 200) { |
| | | LocaleResponseDto responseDataDto = JSON.parseObject(responseDto.getData().toString(), LocaleResponseDto.class); |
| | | List<OdsLocale> list = responseDataDto.getContent(); |
| | | list.forEach(o -> { |
| | | try { |
| | | o.setCustomerString(JSON.toJSONString(o.getCustomer())); |
| | | localeService.saveOrUpdate(o); |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | | } |
| | | }); |
| | | // alarmMsgService.saveBatch(list); |
| | | } else if (responseDto.getStatus() == 114) { |
| | | queryDataDetectorDaily2Task(); |
| | | } 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 queryCustomer() { |
| | | try { |
| | | CustomerParamDto paramDto = CustomerParamDto.builder().build(); |
| | | |
| | | String json = smokeDetectionService.queryCustomer(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | |
| | | if (responseDto.getStatus() == 200) { |
| | | CustomerResponseDto responseDataDto = JSON.parseObject(responseDto.getData().toString(), CustomerResponseDto.class); |
| | | List<OdsCustomer> list = responseDataDto.getContent(); |
| | | list.forEach(o -> { |
| | | try { |
| | | o.setAreasString(o.getAreas() == null ? "" : JSON.toJSONString(o.getAreas())); |
| | | o.setAreaIdsString(o.getAreaIds() == null ? "" : JSON.toJSONString(o.getAreaIds())); |
| | | o.setAreaIdCascadsString(o.getAreaIdCascads() == null ? "" : JSON.toJSONString(o.getAreaIdCascads())); |
| | | customerService.save(o); |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | | } |
| | | }); |
| | | // alarmMsgService.saveBatch(list); |
| | | } else if (responseDto.getStatus() == 114) { |
| | | queryDataDetectorDaily2Task(); |
| | | } 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 listAlarmRecord() { |
| | | try { |
| | | AlarmMsgParamDto paramDto = AlarmMsgParamDto.builder().build(); |
| | | |
| | | String json = smokeDetectionService.getListAlarmRecord(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | |
| | | if (responseDto.getStatus() == 200) { |
| | | AlarmRecordResponseDto responseDataDto = JSON.parseObject(responseDto.getData().toString(), AlarmRecordResponseDto.class); |
| | | List<OdsAlarmRecord> list = responseDataDto.getContent(); |
| | | list.forEach(o -> { |
| | | try { |
| | | o.setAlarmRecordPicsString(JSON.toJSONString(o.getAlarmRecordPics())); |
| | | alarmRecordService.saveOrUpdate(o); |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | | } |
| | | }); |
| | | // alarmMsgService.saveBatch(list); |
| | | } else if (responseDto.getStatus() == 114) { |
| | | queryDataDetectorDaily2Task(); |
| | | } 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 listCurAlarm() { |
| | | try { |
| | | CurAlarmParamDto paramDto = CurAlarmParamDto.builder().StartAt(0).Size(20).SortBy("status").SortMode("asc").Typ(2).build(); |
| | | CurAlarmParamChildDto childDto = CurAlarmParamChildDto.builder().build(); |
| | | Long[] dates = getTodayAndLastMonth(); |
| | | childDto.setStartAt(dates[0]); |
| | | childDto.setEndAt(dates[1]); |
| | | childDto.setLocaleWithDevice(true); |
| | | paramDto.setParam(childDto); |
| | | |
| | | String json = smokeDetectionService.getListCurAlarm(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | |
| | | if (responseDto.getStatus() == 200) { |
| | | CurAlarmResponseDto responseDataDto = JSON.parseObject(responseDto.getData().toString(), CurAlarmResponseDto.class); |
| | | List<OdsCurAlarm> list = responseDataDto.getContent(); |
| | | list.forEach(o -> { |
| | | try { |
| | | curAlarmService.saveByLocalId(o); |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | | } |
| | | }); |
| | | // alarmMsgService.saveBatch(list); |
| | | } else if (responseDto.getStatus() == 114) { |
| | | listCurAlarm(); |
| | | } 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 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) { |
| | | 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(); |
| | | |
| | | Long[] dates = getTodayAndLastMonth(); |
| | | childDto.setStartAt(dates[0]); |
| | | childDto.setEndAt(dates[1]); |
| | | 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()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 实时档案 |
| | | */ |
| | | @Scheduled(cron = "0 */10 * * * ?") // 每10分钟执行 |
| | | // @Scheduled(cron = "0/1 * * * * ?") // 每秒执行 |
| | | public void listLocaleDocument() { |
| | | String auth = redisService.get(RedisKey.SMOKE_TOKEN).toString(); |
| | | String host = "http://116.62.234.187:8120"; |
| | | try { |
| | | List<OdsLocale> odsLocales = localeService.list(); |
| | | for (OdsLocale locale : odsLocales) { |
| | | if (!StringUtils.isEmpty(locale.getMnLast())) { |
| | | Long[] dates = getTodayAndLastMonth(); |
| | | String detectorDailySumDayJson = "{\"LocaleId\":\"" + locale.getId() + "\",\"AcquitAtBegin\":" + dates[1] + ",\"AcquitAtEnd\":" + (dates[1] + 86400) + "}"; |
| | | String detectorDailySumDays = HttpUtil.HttpPostWithJson(host + "/admin/listDataDetectorDailySumDaysByLocaleId", detectorDailySumDayJson, auth); |
| | | |
| | | String listLocaleJson = "{\"Param\":{\"id\":\"" + locale.getId() + "\"}}"; |
| | | String listLocale = HttpUtil.HttpPostWithJson(host + "/admin/listLocale", listLocaleJson, auth); |
| | | |
| | | String detectorDailyJson = "{\"LocaleId\":\"" + locale.getId() + "\",\"AcquitAtBegin\":" + (dates[1] - 7 * 86400) + ",\"AcquitAtEnd\":" + dates[1] + "}"; |
| | | String detectorDaily = HttpUtil.HttpPostWithJson(host + "/admin/queryDataDetectorDaily", detectorDailyJson, auth); |
| | | |
| | | String listIntimeDataJson = "{\"StartAt\":0,\"Size\":20,\"mn\":\"" + locale.getMnLast() + "\",\"typ\":2,\"at\":0}"; |
| | | String listIntimeData = HttpUtil.HttpPostWithJson(host + "/admin/listIntimeData", listIntimeDataJson, auth); |
| | | |
| | | String listTenMinDataJson = "{\"mn\":\"" + locale.getMnLast() + "\",\"at\":" + dates[1] + "}"; |
| | | String listTenMinData = HttpUtil.HttpPostWithJson(host + "/admin/listTenMinData", listTenMinDataJson, auth); |
| | | |
| | | Map<String, Object> tenHourMap = new HashMap<>(); |
| | | tenHourMap.put("at", dates[1]); |
| | | tenHourMap.put("mn", locale.getMnLast()); |
| | | String listTenHourData = HttpUtil.doGet(host + "/admin/listTenHourData", tenHourMap, auth); |
| | | |
| | | String devicesJson = "{\"LocaleId\":\"" + locale.getId() + "\",\"AcquitAtBegin\":" + dates[1] + ",\"AcquitAtEnd\":" + (dates[1] + 86400) + "}"; |
| | | String devices = HttpUtil.HttpPostWithJson(host + "/admin/getDevicesOfLocale", devicesJson, auth); |
| | | |
| | | String maintenanceJson = "{\"StartAt\":0,\"Size\":20,\"FormType\":1,\"Param\":{\"maintenance.locale_id\":{\"S\":2,\"V\":\"cg1uk9j1lf29c3qf3gvg\"}}}"; |
| | | String maintenance = HttpUtil.HttpPostWithJson(host + "/admin/listMaintenance", maintenanceJson, auth); |
| | | |
| | | OdsLocaleDocument document = OdsLocaleDocument.builder().localeId(locale.getId()).mn(locale.getMnLast()) |
| | | .detectorDailySumDays(detectorDailySumDays).detectorDaily(detectorDaily).listLocale(listLocale) |
| | | .intimeData(listIntimeData).tenMinData(listTenMinData).tenHourData(listTenHourData) |
| | | .devices(devices).maintenance(maintenance).build(); |
| | | |
| | | localeDocumentService.saveByLocaleId(document); |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private Long[] getTodayAndLastMonth() { |
| | | 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(); |
| | | Long[] dates = new Long[2]; |
| | | dates[0] = lastMonthZero / 1000; |
| | | dates[1] = todayZero / 1000; |
| | | return dates; |
| | | } |
| | | |
| | | void login() { |
| | | LoginParamDto loginParamDto = LoginParamDto.builder().username("connect_test2").password("test@234").noCode(true).build(); |
| | | SmokeResultResponseDto<LoginResponseDto> responseDto = smokeDetectionService.loginAction(loginParamDto); |
| | | LoginParamDto loginParamDto = LoginParamDto.builder().username("遂昌城管局").password("123456").noCode(true).build(); |
| | | String json = smokeDetectionService.loginAction(loginParamDto); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | if (responseDto.getStatus() == 200) { |
| | | System.out.println(responseDto.getData().getToken()); |
| | | redisService.set(RedisKey.SMOKE_TOKEN, responseDto.getData().getToken()); |
| | | LoginResponseDto loginResponseDto = JSON.parseObject(responseDto.getData().toString(), LoginResponseDto.class); |
| | | System.out.println(loginResponseDto.getToken()); |
| | | redisService.set(RedisKey.SMOKE_TOKEN, loginResponseDto.getToken()); |
| | | } |
| | | } |
| | | } |