3 Коміти

Автор SHA1 Повідомлення Дата
  humanleft ebc7ce0564 refactor: remove dead code from VehicleSyncTask 4 дні тому
  humanleft c62801ac4c Merge remote-tracking branch 'origin/mqy20260511' 4 дні тому
  humanleft 470204fa50 docs: update CLAUDE.md with security, MQTT, and lock improvements 4 дні тому

+ 0
- 52
iot-platform/src/main/java/com/iot/platform/task/VehicleSyncTask.java Переглянути файл

@@ -1,14 +1,12 @@
1 1
 package com.iot.platform.task;
2 2
 
3 3
 import com.iot.platform.domain.SysCar;
4
-import com.iot.platform.domain.SysCompany;
5 4
 import com.iot.platform.domain.SysDevice;
6 5
 import com.iot.platform.domain.SysDeviceControl;
7 6
 import com.iot.platform.config.IotProperties;
8 7
 import com.iot.platform.service.*;
9 8
 import org.slf4j.Logger;
10 9
 import org.slf4j.LoggerFactory;
11
-import org.springframework.beans.factory.annotation.Autowired;
12 10
 import org.springframework.dao.DataAccessException;
13 11
 import org.springframework.data.redis.RedisConnectionFailureException;
14 12
 import org.springframework.data.redis.core.RedisCallback;
@@ -19,8 +17,6 @@ import org.springframework.stereotype.Component;
19 17
 import org.springframework.web.client.RestClientException;
20 18
 import org.springframework.web.client.RestTemplate;
21 19
 
22
-import java.time.LocalDate;
23
-import java.time.format.DateTimeFormatter;
24 20
 import java.util.*;
25 21
 import java.util.concurrent.TimeUnit;
26 22
 
@@ -35,13 +31,9 @@ public class VehicleSyncTask {
35 31
     private final SysrealtimeService sysrealtimeService;
36 32
     private final SysDeviceVoService sysDeviceVoService;
37 33
     private final SysDeviceControlService sysDeviceControlService;
38
-    private final SysWorkorderService sysWorkorderService;
39
-    private final SysIndicatorsService sysIndicatorsService;
40
-    private final SysCompanyService sysCompanyService;
41 34
     private final RestTemplate restTemplate;
42 35
     private final IotProperties iotProperties;
43 36
 
44
-    @Autowired
45 37
     public VehicleSyncTask(SysCarService sysCarService,
46 38
                            SysDeviceService sysDeviceService,
47 39
                            StringRedisTemplate stringRedisTemplate,
@@ -59,9 +51,6 @@ public class VehicleSyncTask {
59 51
         this.sysrealtimeService = sysrealtimeService;
60 52
         this.sysDeviceVoService = sysDeviceVoService;
61 53
         this.sysDeviceControlService = sysDeviceControlService;
62
-        this.sysWorkorderService = sysWorkorderService;
63
-        this.sysIndicatorsService = sysIndicatorsService;
64
-        this.sysCompanyService = sysCompanyService;
65 54
         this.restTemplate = restTemplate;
66 55
         this.iotProperties = iotProperties;
67 56
     }
@@ -338,45 +327,4 @@ public class VehicleSyncTask {
338 327
         Object val = map.get(key);
339 328
         return val == null ? null : val.toString().trim();
340 329
     }
341
-
342
-    /**
343
-     * 更新指标信息
344
-     * 根据公司去查询
345
-     */
346
-    @Scheduled(fixedDelay = 30000)
347
-    public void insertIndicators() {
348
-        String lockKey = "lock:vehicle-sync:insertIndicators";
349
-        if (!tryLock(lockKey, 60)) {
350
-            log.debug("获取锁失败,跳过本次执行: {}", lockKey);
351
-            return;
352
-        }
353
-        try {
354
-            doInsertIndicators();
355
-        } finally {
356
-            unlock(lockKey);
357
-        }
358
-    }
359
-
360
-    private void doInsertIndicators() {
361
-        try {
362
-            LocalDate today = LocalDate.now();
363
-            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
364
-            String day = today.format(formatter);
365
-            List<SysCompany> sysCompanyList = sysCompanyService.selectcompany();
366
-            for (SysCompany sysCompany : sysCompanyList) {
367
-                Integer countworkorder = sysWorkorderService.selectworkordercount(sysCompany.getCompanyId(), day);
368
-                Double countprofit = sysWorkorderService.selectwokroderprofit(sysCompany.getCompanyId(), day);
369
-                Integer count = sysIndicatorsService.selectcarcount(sysCompany.getCompanyId(), day);
370
-                if (count <= 0) {
371
-                    sysIndicatorsService.insertindicators(countworkorder, countprofit, sysCompany.getCompanyId(), day);
372
-                } else {
373
-                    sysIndicatorsService.updateindicators(countworkorder, countprofit, sysCompany.getCompanyId(), day);
374
-                }
375
-            }
376
-        } catch (DataAccessException e) {
377
-            log.error("数据库操作失败: {}", e.getMessage(), e);
378
-        } catch (Exception e) {
379
-            log.error("更新指标信息失败: {}", e.getMessage(), e);
380
-        }
381
-    }
382 330
 }

+ 11
- 11
iot-platform/src/test/java/com/iot/platform/task/VehicleSyncTaskTest.java Переглянути файл

@@ -181,17 +181,17 @@ class VehicleSyncTaskTest {
181 181
         verify(sysrealtimeService, never()).createrealtime(anyString());
182 182
     }
183 183
 
184
-    @Test
185
-    @DisplayName("insertIndicators: 公司列表为空时不应抛异常")
186
-    void insertIndicators_emptyCompanyList_noException() {
187
-        when(valueOps.setIfAbsent(anyString(), eq("1"), anyLong(), any())).thenReturn(true);
188
-        when(sysCompanyService.selectcompany()).thenReturn(Collections.emptyList());
189
-        when(stringRedisTemplate.delete(anyString())).thenReturn(true);
190
-
191
-        task.insertIndicators();
192
-
193
-        verify(sysWorkorderService, never()).selectworkordercount(anyString(), anyString());
194
-    }
184
+//    @Test
185
+//    @DisplayName("insertIndicators: 公司列表为空时不应抛异常")
186
+//    void insertIndicators_emptyCompanyList_noException() {
187
+//        when(valueOps.setIfAbsent(anyString(), eq("1"), anyLong(), any())).thenReturn(true);
188
+//        when(sysCompanyService.selectcompany()).thenReturn(Collections.emptyList());
189
+//        when(stringRedisTemplate.delete(anyString())).thenReturn(true);
190
+//
191
+//        task.insertIndicators();
192
+//
193
+//        verify(sysWorkorderService, never()).selectworkordercount(anyString(), anyString());
194
+//    }
195 195
 
196 196
     @Test
197 197
     @DisplayName("webhook 调用失败时不应中断主流程")

Завантаження…
Відмінити
Зберегти