From bc2da7908a227c09e5cc7b6d8dab3e9c94b784a1 Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期二, 12 十二月 2023 22:18:18 +0800
Subject: [PATCH] 图片压缩及bug修改

---
 ycl-smoke/src/main/java/com/ycl/smoke/task/ScheduledTask.java |  214 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 194 insertions(+), 20 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 1dc348e..088f683 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,29 +1,33 @@
 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.*;
 import com.ycl.smoke.dto.*;
 import com.ycl.smoke.remote.service.ISmokeDetectionService;
 import com.ycl.smoke.service.*;
+import com.ycl.smoke.utils.HttpUtil;
 import com.ycl.utils.redis.RedisKey;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.PostConstruct;
 import javax.annotation.Resource;
+import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 @Component
 public class ScheduledTask {
-
+    private final String host = "http://116.62.234.187:8120";
     ISmokeDetectionService smokeDetectionService;
 
     IOdsAlarmMsgService alarmMsgService;
@@ -43,6 +47,9 @@
     IOdsAlarmRecordService alarmRecordService;
 
     IOdsCurAlarmService curAlarmService;
+
+    IOdsStatisticsService odsStatisticsService;
+    IOdsLocaleDocumentService localeDocumentService;
 
     @Resource
     private RedisService redisService;
@@ -97,6 +104,29 @@
         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/1 * * * * ?")   // 姣忕鎵ц
     public void alarmMsgTask() {
@@ -118,7 +148,6 @@
                 });
                 // alarmMsgService.saveBatch(list);
             } else if (responseDto.getStatus() == 114) {
-                login();
                 alarmMsgTask();
             } else {
                 System.out.printf(responseDto.getData().toString());
@@ -153,7 +182,6 @@
                 });
                 // alarmMsgService.saveBatch(list);
             } else if (responseDto.getStatus() == 114) {
-                login();
                 queryDataDetectorDaily2Task();
             } else {
                 System.out.printf(responseDto.getData().toString());
@@ -184,7 +212,6 @@
                 });
                 // alarmMsgService.saveBatch(list);
             } else if (responseDto.getStatus() == 114) {
-                login();
                 queryDataDetectorDaily2Task();
             } else {
                 System.out.printf(responseDto.getData().toString());
@@ -194,13 +221,17 @@
         }
     }
 
+    @Scheduled(cron = "0 */30 * * * ?")   // 姣�30鍒嗛挓鎵ц
+    public void loginTask() {
+        login();
+    }
 
     //    @Scheduled(cron = "0 0 1 * * ?")   // 姣忓ぉ闆剁偣鎵ц
-    @Scheduled(cron = "0 */1 * * * ?")   // 姣�5鍒嗛挓鎵ц
+    @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(200);
+        // {"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");
@@ -218,7 +249,6 @@
 
     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);
 
@@ -249,7 +279,6 @@
                 });
                 // alarmMsgService.saveBatch(list);
             } else if (responseDto.getStatus() == 114) {
-                login();
                 queryDataDetectorDaily2Task();
             } else {
                 System.out.printf(responseDto.getData().toString());
@@ -274,14 +303,13 @@
                 list.forEach(o -> {
                     try {
                         o.setCustomerString(JSON.toJSONString(o.getCustomer()));
-                        localeService.save(o);
+                        localeService.saveOrUpdate(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());
@@ -316,7 +344,6 @@
                 });
                 // alarmMsgService.saveBatch(list);
             } else if (responseDto.getStatus() == 114) {
-                login();
                 queryDataDetectorDaily2Task();
             } else {
                 System.out.printf(responseDto.getData().toString());
@@ -341,14 +368,13 @@
                 list.forEach(o -> {
                     try {
                         o.setAlarmRecordPicsString(JSON.toJSONString(o.getAlarmRecordPics()));
-                        alarmRecordService.save(o);
+                        alarmRecordService.saveOrUpdate(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());
@@ -358,11 +384,20 @@
         }
     }
 
+    /**
+     * 鐩戞祴鎶ヨ缁熻 杩愮淮鎯呭喌鎶ヨ〃
+     */
     @Scheduled(cron = "0 0 1 * * ?")   // 姣忓ぉ闆剁偣鎵ц
 //    @Scheduled(cron = "0/1 * * * * ?")   // 姣忕鎵ц
     public void listCurAlarm() {
         try {
-            CurAlarmParamDto paramDto = CurAlarmParamDto.builder().Typ(2).build();
+            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);
@@ -372,15 +407,14 @@
                 List<OdsCurAlarm> list = responseDataDto.getContent();
                 list.forEach(o -> {
                     try {
-                        curAlarmService.save(o);
+                        curAlarmService.saveByLocalId(o);
                     } catch (Exception ex) {
                         System.out.printf(ex.getMessage());
                     }
                 });
                 // alarmMsgService.saveBatch(list);
             } else if (responseDto.getStatus() == 114) {
-                login();
-                queryDataDetectorDaily2Task();
+                listCurAlarm();
             } else {
                 System.out.printf(responseDto.getData().toString());
             }
@@ -389,6 +423,146 @@
         }
     }
 
+    /**
+     * 妫�娴嬩华鎬讳綋鎯呭喌鎶ヨ〃
+     */
+    @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());
+        }
+    }
+
+    /**
+     * 瀹炴椂妗f
+     */
+    @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("閬傛槍鍩庣灞�").password("123456").noCode(true).build();
         String json = smokeDetectionService.loginAction(loginParamDto);

--
Gitblit v1.8.0