| | |
| | | package com.ycl.smoke.task; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | 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.ycl.service.redis.RedisService; |
| | | import com.ycl.smoke.entity.*; |
| | | import com.ycl.smoke.dto.*; |
| | |
| | | |
| | | IOdsInTimeService inTimeService; |
| | | |
| | | IOdsInTimeCountService iOdsInTimeCountService; |
| | | |
| | | IOdsLocaleService localeService; |
| | | |
| | | IOdsCustomerService customerService; |
| | |
| | | @Autowired |
| | | public void setSmokeDetectionService(ISmokeDetectionService smokeDetectionService) { |
| | | this.smokeDetectionService = smokeDetectionService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setIOdsInTimeCountService(IOdsInTimeCountService iOdsInTimeCountService) { |
| | | this.iOdsInTimeCountService = iOdsInTimeCountService; |
| | | } |
| | | |
| | | @Autowired |
| | |
| | | } |
| | | |
| | | |
| | | @Scheduled(cron = "0 0 1 * * ?") // 每天零点执行 |
| | | // @Scheduled(cron = "0/1 * * * * ?") // 每秒执行 |
| | | public void listDataIntime() { |
| | | try { |
| | | DataIntimeParamDto paramDto = DataIntimeParamDto.builder().build(); |
| | | // @Scheduled(cron = "0 0 1 * * ?") // 每天零点执行 |
| | | @Scheduled(cron = "0 */1 * * * ?") // 每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 jj = JSON.toJSONString(paramDto); |
| | | 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 { |
| | | inTimeService.save(o); |
| | | o.setModifyTime(LocalDateTime.now()); |
| | | o.setTyp(paramDto.getTyp()); |
| | | inTimeService.saveOrUpdate(o); |
| | | } catch (Exception ex) { |
| | | System.out.printf(ex.getMessage()); |
| | | } |