From 46251c20b66bb1ca05058ae63a92a195e5543b90 Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期四, 02 十一月 2023 21:27:37 +0800
Subject: [PATCH] 优化

---
 ycl-smoke/src/main/java/com/ycl/smoke/task/ScheduledTask.java |   55 +++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/ycl-smoke/src/main/java/com/ycl/smoke/task/ScheduledTask.java b/ycl-smoke/src/main/java/com/ycl/smoke/task/ScheduledTask.java
index d3c8abb..8038a21 100644
--- a/ycl-smoke/src/main/java/com/ycl/smoke/task/ScheduledTask.java
+++ b/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());
                     }

--
Gitblit v1.8.0