From 61b91c80f3d7526eb3caa04e6e781e591f48ec93 Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Sat, 17 Aug 2024 08:40:19 +0800
Subject: [PATCH] 时间分析任务下发

---
 src/main/java/com/dji/sample/droneairport/service/impl/RegistServiceImpl.java |   58 ++++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/src/main/java/com/dji/sample/droneairport/service/impl/RegistServiceImpl.java b/src/main/java/com/dji/sample/droneairport/service/impl/RegistServiceImpl.java
index 74d0d85..ff0632e 100644
--- a/src/main/java/com/dji/sample/droneairport/service/impl/RegistServiceImpl.java
+++ b/src/main/java/com/dji/sample/droneairport/service/impl/RegistServiceImpl.java
@@ -8,6 +8,7 @@
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.dji.sample.common.model.ResponseResult;
 import com.dji.sample.component.redis.RedisOpsUtils;
 import com.dji.sample.droneairport.dao.DbUploadMapper;
@@ -49,9 +50,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.security.NoSuchAlgorithmException;
-import java.time.LocalDate;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
+import java.time.*;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -284,7 +283,7 @@
                 String waylineName = TimerUtil.getTimeName();
                 MultipartFile multipartFile = timerUtil.getFile(waylineName, lotInfosForAirport, airport.getLat(), airport.getLon());
                 WaylineFileEntity waylineFile = timerUtil.backWayline(multipartFile, waylineName, airport.getWorkspaceId(), username);
-                Long time = getNextDayEightAMTimestamp(countDistinctTaskIdsForToday(airport.getWorkspaceId()));
+                Long time = getNextDayEightAMTimestamp(getDistinctTaskIdCount(airport.getWorkspaceId()));
                 List<List<Long>> listOfLists = new ArrayList<>();
                 List<Long> sublist = new ArrayList<>();
                 sublist.add(time);
@@ -356,7 +355,7 @@
                 WaylineFileEntity waylineFile = timerUtil.backWayline(multipartFile, waylineName, airport.getWorkspaceId(), username);
 
                 // 将为规划的图斑状态更新为已规划
-                Long time = getNextDayEightAMTimestamp(countDistinctTaskIdsForToday(airport.getWorkspaceId()));
+                Long time = getNextDayEightAMTimestamp(getDistinctTaskIdCount(airport.getWorkspaceId()));
                 List<List<Long>> listOfLists = new ArrayList<>();
                 List<Long> sublist = new ArrayList<>();
                 sublist.add(time);
@@ -429,9 +428,9 @@
     public String findDbFilesByTaskId(String taskId) {
         DbUploadEntity entity = dbUploadMapper.selectOne(new LambdaQueryWrapper<DbUploadEntity>()
                 .eq(DbUploadEntity::getTaskId, taskId));
-        if (entity!=null){
-            DbUploadDto dto=DbEntityToDto(entity);
-           return SM4Util.encrypt("jsimjrby3wqb7dbq",buildRequestBody(dto));
+        if (entity != null) {
+            DbUploadDto dto = DbEntityToDto(entity);
+            return SM4Util.encrypt("jsimjrby3wqb7dbq", buildRequestBody(dto));
         }
         return null;
 
@@ -474,6 +473,7 @@
         dto.setUrl(entity.getUrl());
         return dto;
     }
+
     public void delTaskInfo(String taskId) {
         taskInfoMapper.delete(new LambdaUpdateWrapper<TaskInfo>().eq(TaskInfo::getTaskId, taskId));
     }
@@ -748,19 +748,37 @@
         // 调用 update 方法进行更新操作
         waylineJobMapper.update(null, updateWrapper);
     }
-    public int countDistinctTaskIdsForToday(String workspaceId) {
-        // 获取当天的开始和结束时间戳
-        long startOfDay = LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli();
-        long startOfNextDay = LocalDate.now().plusDays(1).atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli();
 
-        // 查询数据库,计算不同 taskId 的数量
-        return patchesMapper.selectCount(new LambdaQueryWrapper<LotInfo>()
-                .eq(LotInfo::getWorkspaceId, workspaceId)
-                .ge(LotInfo::getCreateTime, startOfDay)
-                .lt(LotInfo::getCreateTime, startOfNextDay)
-                .select(LotInfo::getTaskId)
-                .groupBy(LotInfo::getTaskId)
-        );
+    /**
+     * 统计给定工作空间下,创建时间为当天的不同 taskId 的数量。
+     *
+     * @param workspaceId 工作空间 ID
+     * @return 不同 taskId 的数量
+     */
+    public Integer getDistinctTaskIdCount(String workspaceId) {
+        // 获取当前日期的开始和结束时间
+        LocalDate today = LocalDate.now();
+        LocalDateTime startTime = today.atStartOfDay();
+        LocalDateTime endTime = today.plusDays(1).atStartOfDay();
+
+        // 转换为毫秒时间戳
+        long startTimestamp = startTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
+        long endTimestamp = endTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
+
+        // 使用 LambdaQueryWrapper 进行查询
+        LambdaQueryWrapper<LotInfo> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.eq(LotInfo::getWorkspaceId, workspaceId)
+                .ge(LotInfo::getCreateTime, startTimestamp)
+                .lt(LotInfo::getCreateTime, endTimestamp);
+
+        // 获取符合条件的所有 taskId
+        Set<String> taskIdSet = patchesMapper.selectList(queryWrapper).stream()
+                .map(LotInfo::getTaskId)
+                .collect(Collectors.toSet());
+
+        // 返回不同 taskId 的数量
+        return taskIdSet.size();
     }
 
+
 }

--
Gitblit v1.9.3