| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Component |
| | |
| | | ISmokeDetectionService smokeDetectionService; |
| | | |
| | | IOdsAlarmMsgService alarmMsgService; |
| | | |
| | | IOdsDetectorDailyService detectorDailyService; |
| | | |
| | | IOdsTenMinDataService tenMinDataService; |
| | | |
| | |
| | | this.curAlarmService = curAlarmService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setDetectorDailyService(IOdsDetectorDailyService detectorDailyService) { |
| | | this.detectorDailyService = detectorDailyService; |
| | | } |
| | | |
| | | @Scheduled(cron = "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 -> { |
| | | try { |
| | | alarmMsgService.save(o); |
| | | } 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/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()); |
| | | DetectorDailyResponseDto dto = JSON.parseObject(responseDto.getData().toString(), DetectorDailyResponseDto.class); |
| | | List<OdsDetectorDaily> list = dto.getContent(); |
| | | list.forEach(o -> { |
| | | try { |
| | | alarmMsgService.save(o); |
| | | 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()); |
| | | } |
| | | } |
| | | |
| | |
| | | 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); |
| | | |
| | | SmokeResultResponseDto<List<OdsTenMinData>> responseDto = smokeDetectionService.queryTenMinData(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | if (responseDto.getStatus() == 200) { |
| | | List<OdsTenMinData> list = responseDto.getData(); |
| | | 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) { |
| | | login(); |
| | | queryDataDetectorDaily2Task(); |
| | | } else { |
| | | System.out.printf(responseDto.getData().toString()); |
| | | } |
| | | } catch (Exception ex) { |
| | | |
| | | System.out.printf(ex.getMessage()); |
| | | } |
| | | } |
| | | |
| | |
| | | try { |
| | | DataIntimeParamDto paramDto = DataIntimeParamDto.builder().build(); |
| | | |
| | | SmokeResultResponseDto<DataIntimeResponseDto> responseDto = smokeDetectionService.listDataIntime(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | String json = smokeDetectionService.listDataIntime(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | |
| | | if (responseDto.getStatus() == 200) { |
| | | DataIntimeResponseDto dataIntimeResponseDto = responseDto.getData(); |
| | | DataIntimeResponseDto dataIntimeResponseDto = JSON.parseObject(responseDto.getData().toString(), DataIntimeResponseDto.class); |
| | | List<OdsInTime> list = dataIntimeResponseDto.getContent(); |
| | | list.forEach(o -> { |
| | | try { |
| | |
| | | } else if (responseDto.getStatus() == 114) { |
| | | login(); |
| | | queryDataDetectorDaily2Task(); |
| | | } else { |
| | | System.out.printf(responseDto.getData().toString()); |
| | | } |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | |
| | | try { |
| | | LocaleParamDto paramDto = LocaleParamDto.builder().build(); |
| | | |
| | | SmokeResultResponseDto<LocaleResponseDto> responseDto = smokeDetectionService.listLocale(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | String json = smokeDetectionService.listLocale(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | |
| | | if (responseDto.getStatus() == 200) { |
| | | LocaleResponseDto responseDataDto = responseDto.getData(); |
| | | LocaleResponseDto responseDataDto = JSON.parseObject(responseDto.getData().toString(), LocaleResponseDto.class); |
| | | List<OdsLocale> list = responseDataDto.getContent(); |
| | | list.forEach(o -> { |
| | | try { |
| | |
| | | } else if (responseDto.getStatus() == 114) { |
| | | login(); |
| | | queryDataDetectorDaily2Task(); |
| | | } else { |
| | | System.out.printf(responseDto.getData().toString()); |
| | | } |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | |
| | | try { |
| | | CustomerParamDto paramDto = CustomerParamDto.builder().build(); |
| | | |
| | | SmokeResultResponseDto<CustomerResponseDto> responseDto = smokeDetectionService.queryCustomer(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | String json = smokeDetectionService.queryCustomer(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | |
| | | if (responseDto.getStatus() == 200) { |
| | | CustomerResponseDto responseDataDto = responseDto.getData(); |
| | | CustomerResponseDto responseDataDto = JSON.parseObject(responseDto.getData().toString(), CustomerResponseDto.class); |
| | | List<OdsCustomer> list = responseDataDto.getContent(); |
| | | list.forEach(o -> { |
| | | try { |
| | |
| | | } else if (responseDto.getStatus() == 114) { |
| | | login(); |
| | | queryDataDetectorDaily2Task(); |
| | | } else { |
| | | System.out.printf(responseDto.getData().toString()); |
| | | } |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | |
| | | try { |
| | | AlarmMsgParamDto paramDto = AlarmMsgParamDto.builder().build(); |
| | | |
| | | SmokeResultResponseDto<AlarmRecordResponseDto> responseDto = smokeDetectionService.getListAlarmRecord(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | String json = smokeDetectionService.getListAlarmRecord(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | |
| | | if (responseDto.getStatus() == 200) { |
| | | AlarmRecordResponseDto responseDataDto = responseDto.getData(); |
| | | AlarmRecordResponseDto responseDataDto = JSON.parseObject(responseDto.getData().toString(), AlarmRecordResponseDto.class); |
| | | List<OdsAlarmRecord> list = responseDataDto.getContent(); |
| | | list.forEach(o -> { |
| | | try { |
| | |
| | | } else if (responseDto.getStatus() == 114) { |
| | | login(); |
| | | queryDataDetectorDaily2Task(); |
| | | } else { |
| | | System.out.printf(responseDto.getData().toString()); |
| | | } |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | |
| | | try { |
| | | CurAlarmParamDto paramDto = CurAlarmParamDto.builder().Typ(2).build(); |
| | | |
| | | SmokeResultResponseDto<CurAlarmResponseDto> responseDto = smokeDetectionService.getListCurAlarm(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | String json = smokeDetectionService.getListCurAlarm(paramDto, redisService.get(RedisKey.SMOKE_TOKEN).toString()); |
| | | SmokeResultResponseDto responseDto = JSON.parseObject(json, SmokeResultResponseDto.class); |
| | | |
| | | if (responseDto.getStatus() == 200) { |
| | | CurAlarmResponseDto responseDataDto = responseDto.getData(); |
| | | CurAlarmResponseDto responseDataDto = JSON.parseObject(responseDto.getData().toString(), CurAlarmResponseDto.class); |
| | | List<OdsCurAlarm> list = responseDataDto.getContent(); |
| | | list.forEach(o -> { |
| | | try { |
| | |
| | | } else if (responseDto.getStatus() == 114) { |
| | | login(); |
| | | queryDataDetectorDaily2Task(); |
| | | } else { |
| | | System.out.printf(responseDto.getData().toString()); |
| | | } |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | |
| | | |
| | | void login() { |
| | | LoginParamDto loginParamDto = LoginParamDto.builder().username("connect_test2").password("test@234").noCode(true).build(); |
| | | SmokeResultResponseDto<LoginResponseDto> responseDto = smokeDetectionService.loginAction(loginParamDto); |
| | | 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()); |
| | | } |
| | | } |
| | | } |