zhanghua
2023-11-02 46251c20b66bb1ca05058ae63a92a195e5543b90
ycl-smoke/src/main/java/com/ycl/smoke/task/ScheduledTask.java
@@ -1,6 +1,9 @@
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.*;
@@ -31,6 +34,8 @@
    IOdsInTimeService inTimeService;
    IOdsInTimeCountService iOdsInTimeCountService;
    IOdsLocaleService localeService;
    IOdsCustomerService customerService;
@@ -45,6 +50,11 @@
    @Autowired
    public void setSmokeDetectionService(ISmokeDetectionService smokeDetectionService) {
        this.smokeDetectionService = smokeDetectionService;
    }
    @Autowired
    public void setIOdsInTimeCountService(IOdsInTimeCountService iOdsInTimeCountService) {
        this.iOdsInTimeCountService = iOdsInTimeCountService;
    }
    @Autowired
@@ -185,21 +195,54 @@
    }
    @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());
                    }