20 files modified
1 files added
771 ■■■■■ changed files
src/main/java/com/dji/sample/common/model/ResponseResult.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/droneairport/controller/RegistController.java 62 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/droneairport/service/RegistService.java 12 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/droneairport/service/impl/RegistServiceImpl.java 149 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/droneairport/utils/AuthUtil.java 12 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/droneairport/utils/SM2/Test.java 10 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/droneairport/utils/SM4Util.java 26 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/media/model/MediaFileEntity.java 3 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/media/service/IFileService.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java 183 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/controller/PatchesController.java 20 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/patches/utils/TimerUtil.java 194 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/speak/controller/SpeakVoiceController.java 6 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/speak/util/AudioConverter.java 55 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/wayline/controller/WaylineFileController.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/wayline/dao/IWaylineJobBreakPointMapper.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/wayline/model/dto/WaylineFileDTO.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/wayline/model/entity/WaylineFileEntity.java 3 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/wayline/plane/controller/CreateWayLineController.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/wayline/service/IWaylineFileService.java 8 ●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/wayline/service/impl/WaylineFileServiceImpl.java 14 ●●●●● patch | view | raw | blame | history
src/main/java/com/dji/sample/common/model/ResponseResult.java
@@ -48,7 +48,7 @@
                .build();
    }
    public static<T> ResponseResult success(int code, String message,String traceid,T data) {
    public static<T> ResponseResult success(int code, String message,T data,String traceid) {
        return ResponseResult.builder()
                .code(code)
                .data(data)
src/main/java/com/dji/sample/droneairport/controller/RegistController.java
@@ -5,12 +5,19 @@
import com.dji.sample.droneairport.dao.DeviceExpanSionMapper;
import com.dji.sample.droneairport.model.param.ReturnTaskParam;
import com.dji.sample.droneairport.service.RegistService;
import com.dji.sample.droneairport.utils.SM2.Utils;
import com.dji.sample.droneairport.utils.SM4Util;
import com.dji.sample.manage.service.impl.DeviceRedisServiceImpl;
import org.bouncycastle.crypto.InvalidCipherTextException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import static com.dji.sample.component.AuthInterceptor.TOKEN_CLAIM;
@@ -41,43 +48,60 @@
        return ResponseResult.success(registService.addDrone(workspaceId));
    }
    @GetMapping("/getDroneStatus/{deviceid}")
    public ResponseResult droneStatus(@PathVariable(name = "deviceid") String deviceid, HttpServletResponse response) throws Exception {
        return ResponseResult.success(registService.getDroneState(deviceid));
    @GetMapping("/getDroneStatus")
    public ResponseResult droneStatus(@RequestParam String deviceid, HttpServletResponse response) throws Exception {
        Map<String, String> info=registService.getDroneState(deviceid);
        response.setHeader("x-lc-secret", info.get("serect"));
        return ResponseResult.success(info.get("text"));
    }
    @PostMapping("/AddTask")
    public ResponseResult AddTask(HttpServletRequest request, @RequestBody String body) throws Exception {
    public ResponseResult AddTask(HttpServletRequest request, @RequestBody String body,HttpServletResponse response) throws Exception {
        String headerValue = request.getHeader("x-lc-secret");
        CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM);
        String creator = customClaim.getUsername();
        ReturnTaskParam param = registService.AddTask(body, headerValue, creator);
        return ResponseResult.success(200, "无人机机场任务添加成功", param.getTraceId(), param.getJobId());
    }
    @GetMapping("/cancelTask/{taskId}")
    public ResponseResult cancelTask(@PathVariable(name = "taskId") String taskId) {
        return ResponseResult.success(registService.cancelTask(taskId));
        Map<String, String> info = registService.AddTask(body, headerValue, creator);
        response.setHeader("x-lc-secret", info.get("serect"));
        return ResponseResult.success(200, "无人机机场任务添加成功", info.get("traceId"), info.get("jobId"));
    }
    @PostMapping("/updateTask")
    public ResponseResult updateTask(HttpServletRequest request, @RequestBody String body) throws Exception {
    public ResponseResult updateTask(HttpServletRequest request, @RequestBody String body,HttpServletResponse response) throws Exception {
        String headerValue = request.getHeader("x-lc-secret");
        CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM);
        String creator = customClaim.getUsername();
        ReturnTaskParam param = registService.updateTask(body, headerValue, creator);
        return ResponseResult.success(200, "无人机机场任务添加成功", param.getTraceId(), param.getJobId());
        Map<String, String>  info = registService.updateTask(body, headerValue, creator);
        response.setHeader("x-lc-secret", info.get("serect"));
        return ResponseResult.success(200, "无人机机场任务更新成功", info.get("traceId"), info.get("jobId"));
    }
    @GetMapping("/cancelTask")
    public ResponseResult cancelTask(@RequestParam String taskid) {
        return ResponseResult.success(registService.cancelTask(taskid));
    }
    @PostMapping("/queryTaskStatus")
    public ResponseResult queryTaskStatus(HttpServletRequest request, @RequestParam String taskid) throws Exception {
        return registService.queryTaskStatus(taskid);
    }
    @GetMapping("/getResult/{taskId}")
    public ResponseResult getResult(@PathVariable(name = "taskId") String taskId) {
        return ResponseResult.success(200, "无人机成果获取成功!",registService.findDbFilesByTaskId(taskId));
    @GetMapping("/getResult")
    public ResponseResult getResult(@RequestParam String taskid,HttpServletResponse response) throws InvalidCipherTextException, IOException {
        Map<String, String>  info = registService.findDbFilesByTaskId(taskid);
        response.setHeader("x-lc-secret", info.get("serect"));
        return ResponseResult.success(200, "无人机成果获取成功!",info.get("data"), info.get("traceId"));
    }
    @PostMapping("/test")
    public ResponseResult test(@RequestParam String workspaceId) {
        return ResponseResult.success(registService.getDistinctTaskIdCount(workspaceId));
    public ResponseResult test(HttpServletRequest request,@RequestBody String param,HttpServletResponse response) throws Exception {
        String headerValue = request.getHeader("x-lc-secret");
        headerValue=Utils.convertBase64ToHex(headerValue);
        headerValue=Utils.decrypt(headerValue, "00D631FD5615416EAB63D33A9E66E801F95DE840567504210080006081DE877AE3");
        System.out.println(headerValue);
        String value=SM4Util.decrypt(headerValue,param);
        System.out.println(value);
        String sm= SM4Util.generateSM4Key();
        String values=SM4Util.encrypt(sm,value);
        String pub=Utils.encrypt(sm,"04225AACF606D800EA3C2C31FCF8FB161B15F7A8D0460DEB91013D4F228C455E76A2ED8D71BC6525B5DC5CC015C155479D8839950344AEE438A3A6305C90F8269F");
        pub=Utils.hexToBase64(pub);
        response.setHeader("x-lc-secret", pub);
        return ResponseResult.success(values);
    }
}
src/main/java/com/dji/sample/droneairport/service/RegistService.java
@@ -3,8 +3,12 @@
import com.dji.sample.common.model.ResponseResult;
import com.dji.sample.droneairport.model.Entity.DeviceExpanSionEntity;
import com.dji.sample.droneairport.model.param.ReturnTaskParam;
import org.bouncycastle.crypto.InvalidCipherTextException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public interface RegistService {
@@ -28,7 +32,7 @@
     * @return 返回一个包含无人机状态信息的ResponseResult对象
     * @throws Exception 如果在获取无人机状态过程中发生错误,将抛出异常
     */
    String getDroneState(String deviceId) throws Exception;
    Map<String, String>  getDroneState(String deviceId) throws Exception;
    /**
     * 执行授权操作
@@ -49,7 +53,7 @@
     * @return 返回一个包含任务添加结果的ReturnParam对象,具体结果包括成功与否、错误信息等
     * @throws Exception 如果在任务添加过程中发生错误,将抛出异常
     */
    ReturnTaskParam AddTask(String base64, String Secret, String username) throws Exception;
    Map<String, String> AddTask(String base64, String Secret, String username) throws Exception;
    /**
     * 更新任务状态
@@ -60,7 +64,7 @@
     * @return 包含更新后任务状态信息的返回参数
     * @throws Exception 如果更新任务状态过程中发生错误,将抛出异常
     */
    ReturnTaskParam updateTask(String base64, String Secret, String username) throws Exception;
    Map<String, String>  updateTask(String base64, String Secret, String username) throws Exception;
    /**
     * 取消指定任务
@@ -86,7 +90,7 @@
     * @return 返回一个包含无人机状态信息的ResponseResult对象
     * @throws Exception 如果在获取无人机状态过程中发生错误,将抛出异常
     */
    String findDbFilesByTaskId(String taskId);
    Map<String,String> findDbFilesByTaskId(String taskId) throws InvalidCipherTextException, IOException;
    /**
     * 获取指定工作空间中不同任务的总数
     *
src/main/java/com/dji/sample/droneairport/service/impl/RegistServiceImpl.java
@@ -47,6 +47,7 @@
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
@@ -54,9 +55,9 @@
import java.util.*;
import java.util.stream.Collectors;
import static com.dji.sample.droneairport.utils.AuthUtil.getToken;
import static com.dji.sample.droneairport.utils.TaskAllocator.assignTasks;
import static com.dji.sample.patches.utils.TimerUtil.getCurrentTimestampPlus8Hours;
import static com.dji.sample.patches.utils.TimerUtil.getNextDayEightAMTimestamp;
import static com.dji.sample.patches.utils.TimerUtil.*;
@Service
public class RegistServiceImpl implements RegistService {
@@ -84,26 +85,39 @@
    public String registPort(DeviceExpanSionEntity airport) {
        try {
            RegistDto registDto = airportEntityToDto(airport);
            String secret = SM4Util.generateSM4Key();
            String jsonBody = buildRequestBody(registDto);
            String base64 = SM4Util.encrypt("jsimjrby3wqb7dbq", jsonBody);
            String base64 = SM4Util.encrypt(secret, jsonBody);
            String keys=Utils.encrypt(secret,"04225AACF606D800EA3C2C31FCF8FB161B15F7A8D0460DEB91013D4F228C455E76A2ED8D71BC6525B5DC5CC015C155479D8839950344AEE438A3A6305C90F8269F");
            String enSM2=Utils.hexToBase64(keys);
            // 设置请求头
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            headers.setAccept(List.of(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN, MediaType.ALL));
            headers.set("Accept-Language", "zh-CN,zh;q=0.9");
            headers.setConnection("keep-alive");
            headers.set("x-auth-token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ3b3Jrc3BhY2VfaWQiOiJlM2RlYTBmNS0zN2YyLTRkNzktYWU1OC00OTBhZjMyMjgwNjkiLCJzdWIiOiJDbG91ZEFwaVNhbXBsZSIsInVzZXJfdHlwZSI6IjEiLCJuYmYiOjE3MjA2NTg3NDMsImxvZyI6IkxvZ2dlcltjb20uZGppLnNhbXBsZS5jb21tb24ubW9kZWwuQ3VzdG9tQ2xhaW1dIiwiaXNzIjoiREpJIiwiaWQiOiI5Y2MwMGY3Zi0yODMwLTRmM2UtYjdmNC1lN2E1ZjIzYjNjNGYiLCJleHAiOjE4MDcwNTg3NDMsImlhdCI6MTcyMDY1ODc0MywidXNlcm5hbWUiOiJhZG1pbkRQIn0.CrRFYUTK357HleqrrfL7nLdwFJw5Bcv3ms33n_Or8eM");
            headers.set("x-lc-token", "");
            headers.set("x-lc-token", getToken());
            headers.set("x-auth-token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ3b3Jrc3BhY2VfaWQiOiJlM2RlYTBmNS0zN2YyLTRkNzktYWU1OC00OTBhZjMyMjgwNjkiLCJzdWIiOiJDbG91ZEFwaVNhbXBsZSIsInVzZXJfdHlwZSI6IjEiLCJuYmYiOjE3MTg1ODUxNTQsImxvZyI6IkxvZ2dlcltjb20uZGppLnNhbXBsZS5jb21tb24ubW9kZWwuQ3VzdG9tQ2xhaW1dIiwiaXNzIjoiREpJIiwiaWQiOiI5Y2MwMGY3Zi0yODMwLTRmM2UtYjdmNC1lN2E1ZjIzYjNjNGYiLCJleHAiOjE4MDQ5ODUxNTQsImlhdCI6MTcxODU4NTE1NCwidXNlcm5hbWUiOiJhZG1pbkRQIn0.eTi9DTYGwcTvnIZasKTFq9OHQgMFS1-m840terb7ss0");
            headers.set("x-lc-secret", enSM2);
            // 构建请求实体
            HttpEntity<String> requestEntity = new HttpEntity<>(base64, headers);
            // 发送请求
            ResponseEntity<String> response = restTemplate.exchange(
                    "http://localhost:6789/droneAirport/test",
                    "https://xcx.geoway.com.cn:8033/v1/droneAirport/RegistService",
                    HttpMethod.POST,
                    requestEntity,
                    String.class);
            return response.getBody();
            HttpHeaders responseHeaders = response.getHeaders();
            String responseSecret = responseHeaders.getFirst("x-lc-secret");
            String data=deSM2(responseSecret, "00D631FD5615416EAB63D33A9E66E801F95DE840567504210080006081DE877AE3");
            // 使用 Hutool 的 JSONUtil 解析 JSON 字符串
            JSONObject jsonObject = JSONUtil.parseObj(response.getBody());
            // 提取 data 字段的值
            String dataValue = jsonObject.getStr("data");
            return SM4Util.decrypt(data,dataValue);
        } catch (Exception e) {
            // 异常处理
            throw new IllegalArgumentException("无人机机场注册失败: " + e.getMessage());
@@ -136,41 +150,57 @@
                    .eq(DeviceExpanSionEntity::getWorkspaceId, workspaceId)
                    .eq(DeviceExpanSionEntity::getType, 1));
            AddDeviceDto dto = deviceEntityToDto(drone);
            String secret = SM4Util.generateSM4Key();
            // 构建请求体
            String jsonBody = buildRequestBody(dto);
            String base64 = SM4Util.encrypt("jsimjrby3wqb7dbq", jsonBody);
            String base64 = SM4Util.encrypt(secret, jsonBody);
            String keys=Utils.encrypt(secret,"04225AACF606D800EA3C2C31FCF8FB161B15F7A8D0460DEB91013D4F228C455E76A2ED8D71BC6525B5DC5CC015C155479D8839950344AEE438A3A6305C90F8269F");
            String enSM2=Utils.hexToBase64(keys);
//            registPort(airport);
            // 设置请求头
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            headers.setAccept(List.of(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN, MediaType.ALL));
            headers.set("Accept-Language", "zh-CN,zh;q=0.9");
            headers.setConnection("keep-alive");
            headers.set("x-auth-token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ3b3Jrc3BhY2VfaWQiOiJlM2RlYTBmNS0zN2YyLTRkNzktYWU1OC00OTBhZjMyMjgwNjkiLCJzdWIiOiJDbG91ZEFwaVNhbXBsZSIsInVzZXJfdHlwZSI6IjEiLCJuYmYiOjE3MjA2NTg3NDMsImxvZyI6IkxvZ2dlcltjb20uZGppLnNhbXBsZS5jb21tb24ubW9kZWwuQ3VzdG9tQ2xhaW1dIiwiaXNzIjoiREpJIiwiaWQiOiI5Y2MwMGY3Zi0yODMwLTRmM2UtYjdmNC1lN2E1ZjIzYjNjNGYiLCJleHAiOjE4MDcwNTg3NDMsImlhdCI6MTcyMDY1ODc0MywidXNlcm5hbWUiOiJhZG1pbkRQIn0.CrRFYUTK357HleqrrfL7nLdwFJw5Bcv3ms33n_Or8eM");
            headers.set("x-lc-token", "");
            headers.set("x-auth-token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ3b3Jrc3BhY2VfaWQiOiJlM2RlYTBmNS0zN2YyLTRkNzktYWU1OC00OTBhZjMyMjgwNjkiLCJzdWIiOiJDbG91ZEFwaVNhbXBsZSIsInVzZXJfdHlwZSI6IjEiLCJuYmYiOjE3MTg1ODUxNTQsImxvZyI6IkxvZ2dlcltjb20uZGppLnNhbXBsZS5jb21tb24ubW9kZWwuQ3VzdG9tQ2xhaW1dIiwiaXNzIjoiREpJIiwiaWQiOiI5Y2MwMGY3Zi0yODMwLTRmM2UtYjdmNC1lN2E1ZjIzYjNjNGYiLCJleHAiOjE4MDQ5ODUxNTQsImlhdCI6MTcxODU4NTE1NCwidXNlcm5hbWUiOiJhZG1pbkRQIn0.eTi9DTYGwcTvnIZasKTFq9OHQgMFS1-m840terb7ss0");
            headers.set("x-lc-token", getToken());
            headers.set("x-lc-secret", (enSM2));
            // 构建请求实体
            HttpEntity<String> requestEntity = new HttpEntity<>(base64, headers);
            // 发送请求
            ResponseEntity<String> response = restTemplate.exchange(
                    "http://localhost:6789/droneAirport/test",
                    "https://xcx.geoway.com.cn:8033/v1/droneAirport/addDevice",
                    HttpMethod.POST,
                    requestEntity,
                    String.class);
            registPort(airport);
            return response.getBody();
            HttpHeaders responseHeaders = response.getHeaders();
            String responseSecret = responseHeaders.getFirst("x-lc-secret");
            String data=deSM2(responseSecret, "00D631FD5615416EAB63D33A9E66E801F95DE840567504210080006081DE877AE3");
            // 使用 Hutool 的 JSONUtil 解析 JSON 字符串
            JSONObject jsonObject = JSONUtil.parseObj(response.getBody());
            // 提取 data 字段的值
            String dataValue = jsonObject.getStr("data");
            return SM4Util.decrypt(data,dataValue);
        } catch (Exception e) {
            // 异常处理
            throw new IllegalArgumentException("无人机机场设备注册失败: " + e.getMessage());
            return ("无人机机场设备注册失败: " + e.getMessage());
        }
    }
    @Override
    public String getDroneState(String deviceId) throws Exception {
    public Map<String, String> getDroneState(String deviceId) throws Exception {
        String key = SM4Util.generateSM4Key();
        String secret = Utils.encrypt(key, "04225AACF606D800EA3C2C31FCF8FB161B15F7A8D0460DEB91013D4F228C455E76A2ED8D71BC6525B5DC5CC015C155479D8839950344AEE438A3A6305C90F8269F");
        DroneStateDto data = getAirportFromCache(deviceId);
        String json = JSON.toJSONString(data);
        String SM4Screct = SM4Util.encrypt("jsimjrby3wqb7dbq", json);
        return SM4Screct;
        String SM4Screct = SM4Util.encrypt(key, json);
        Map<String, String> info = new HashMap<>();
        info.put("text", SM4Screct);
        info.put("serect", secret);
        return info;
    }
    //    @Override
@@ -191,20 +221,20 @@
        dto.setSn(sn);
        dto.setStatus(0);
        String jsonBody = buildRequestBody(dto);
        String base64 = SM4Util.encrypt("jsimjrby3wqb7dbq", jsonBody);
        String base64 = SM4Util.encrypt(SM4Util.generateSM4Key(), jsonBody);
        // 设置请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.setAccept(List.of(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN, MediaType.ALL));
        headers.set("Accept-Language", "zh-CN,zh;q=0.9");
        headers.setConnection("keep-alive");
        headers.set("x-auth-token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ3b3Jrc3BhY2VfaWQiOiJlM2RlYTBmNS0zN2YyLTRkNzktYWU1OC00OTBhZjMyMjgwNjkiLCJzdWIiOiJDbG91ZEFwaVNhbXBsZSIsInVzZXJfdHlwZSI6IjEiLCJuYmYiOjE3MjA2NTg3NDMsImxvZyI6IkxvZ2dlcltjb20uZGppLnNhbXBsZS5jb21tb24ubW9kZWwuQ3VzdG9tQ2xhaW1dIiwiaXNzIjoiREpJIiwiaWQiOiI5Y2MwMGY3Zi0yODMwLTRmM2UtYjdmNC1lN2E1ZjIzYjNjNGYiLCJleHAiOjE4MDcwNTg3NDMsImlhdCI6MTcyMDY1ODc0MywidXNlcm5hbWUiOiJhZG1pbkRQIn0.CrRFYUTK357HleqrrfL7nLdwFJw5Bcv3ms33n_Or8eM");
        headers.set("x-lc-token", "");
        headers.set("x-lc-token", "eyJvcmdjb2RlIjoiMDAwMDAwMDAwMDAwMDAwMDAwIiwib3JnbmFtZSI6IuWbveWcn+iwg+afpeS6keaXoOS6uuacuuaOpeWPo+a1i+ivleivgeS5puS4peemgeeUqOS6juato+W8j+eOr+WigyIsImNlcnRjb2RlIjoiVUFWMzJfV0hSNEUzVUFKWlRFM0tFNUlaRkRHTDdDQlUiLCJjZXJ0b3JnY29kZSI6IjEyMTAwMDAwNDAwMDEwMzk4UCIsImNlcnRvcmduYW1lIjoi5Lit5Zu95Zu95Zyf5YuY5rWL6KeE5YiS6ZmiIiwiZXhwaXJhdGlvbiI6IjIwMjQtMTItMzEgMTU6NDY6MzIiLCJwdWJsaWNrZXkiOiIwNDIyNUFBQ0Y2MDZEODAwRUEzQzJDMzFGQ0Y4RkIxNjFCMTVGN0E4RDA0NjBERUI5MTAxM0Q0RjIyOEM0NTVFNzZBMkVEOEQ3MUJDNjUyNUI1REM1Q0MwMTVDMTU1NDc5RDg4Mzk5NTAzNDRBRUU0MzhBM0E2MzA1QzkwRjgyNjlGIiwic2lnbiI6IkI4OTVGQUM1Qzk4NzM5RURGNzFBRkE2QjM4NDEzQUIzNDRCRTBDQjE1RTk3MDQ3Nzk5QTczNUM0MjBEMkZFMzdENkE1NjJFQTlFMUFBRjFBNjhBRDJERjE0QzhEMThBOEY5N0JENzUyOUE2NDRERDA3NkI2NDM1OTg5QkQxREIwIiwiY2VydHR5cGUiOiLml6DkurrmnLrkuL7or4Hor4HkuaYiLCJyZWdpb25jb2RlIjoiMDAwMDAwIn0=");
        headers.set("x-lc-secret", "00D631FD5615416EAB63D33A9E66E801F95DE840567504210080006081DE877AE3");
        // 构建请求实体
        HttpEntity<String> requestEntity = new HttpEntity<>(base64, headers);
        // 发送请求
        ResponseEntity<String> response = restTemplate.exchange(
                "http://localhost:6789/droneAirport/test",
                "https://xcx.geoway.com.cn:8033/v1/droneAirport/authorization",
                HttpMethod.POST,
                requestEntity,
                String.class);
@@ -216,31 +246,33 @@
        dto.setSn(sn);
        dto.setStatus(1);
        String jsonBody = buildRequestBody(dto);
        String base64 = SM4Util.encrypt("jsimjrby3wqb7dbq", jsonBody);
        String base64 = SM4Util.encrypt(SM4Util.generateSM4Key(), jsonBody);
        // 设置请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.setAccept(List.of(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN, MediaType.ALL));
        headers.set("Accept-Language", "zh-CN,zh;q=0.9");
        headers.setConnection("keep-alive");
        headers.set("x-auth-token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ3b3Jrc3BhY2VfaWQiOiJlM2RlYTBmNS0zN2YyLTRkNzktYWU1OC00OTBhZjMyMjgwNjkiLCJzdWIiOiJDbG91ZEFwaVNhbXBsZSIsInVzZXJfdHlwZSI6IjEiLCJuYmYiOjE3MjA2NTg3NDMsImxvZyI6IkxvZ2dlcltjb20uZGppLnNhbXBsZS5jb21tb24ubW9kZWwuQ3VzdG9tQ2xhaW1dIiwiaXNzIjoiREpJIiwiaWQiOiI5Y2MwMGY3Zi0yODMwLTRmM2UtYjdmNC1lN2E1ZjIzYjNjNGYiLCJleHAiOjE4MDcwNTg3NDMsImlhdCI6MTcyMDY1ODc0MywidXNlcm5hbWUiOiJhZG1pbkRQIn0.CrRFYUTK357HleqrrfL7nLdwFJw5Bcv3ms33n_Or8eM");
        headers.set("x-lc-token", "");
        headers.set("x-lc-token", "eyJvcmdjb2RlIjoiMDAwMDAwMDAwMDAwMDAwMDAwIiwib3JnbmFtZSI6IuWbveWcn+iwg+afpeS6keaXoOS6uuacuuaOpeWPo+a1i+ivleivgeS5puS4peemgeeUqOS6juato+W8j+eOr+WigyIsImNlcnRjb2RlIjoiVUFWMzJfV0hSNEUzVUFKWlRFM0tFNUlaRkRHTDdDQlUiLCJjZXJ0b3JnY29kZSI6IjEyMTAwMDAwNDAwMDEwMzk4UCIsImNlcnRvcmduYW1lIjoi5Lit5Zu95Zu95Zyf5YuY5rWL6KeE5YiS6ZmiIiwiZXhwaXJhdGlvbiI6IjIwMjQtMTItMzEgMTU6NDY6MzIiLCJwdWJsaWNrZXkiOiIwNDIyNUFBQ0Y2MDZEODAwRUEzQzJDMzFGQ0Y4RkIxNjFCMTVGN0E4RDA0NjBERUI5MTAxM0Q0RjIyOEM0NTVFNzZBMkVEOEQ3MUJDNjUyNUI1REM1Q0MwMTVDMTU1NDc5RDg4Mzk5NTAzNDRBRUU0MzhBM0E2MzA1QzkwRjgyNjlGIiwic2lnbiI6IkI4OTVGQUM1Qzk4NzM5RURGNzFBRkE2QjM4NDEzQUIzNDRCRTBDQjE1RTk3MDQ3Nzk5QTczNUM0MjBEMkZFMzdENkE1NjJFQTlFMUFBRjFBNjhBRDJERjE0QzhEMThBOEY5N0JENzUyOUE2NDRERDA3NkI2NDM1OTg5QkQxREIwIiwiY2VydHR5cGUiOiLml6DkurrmnLrkuL7or4Hor4HkuaYiLCJyZWdpb25jb2RlIjoiMDAwMDAwIn0=");
        headers.set("x-lc-secret", "00D631FD5615416EAB63D33A9E66E801F95DE840567504210080006081DE877AE3");
        // 构建请求实体
        HttpEntity<String> requestEntity = new HttpEntity<>(base64, headers);
        // 发送请求
        ResponseEntity<String> response = restTemplate.exchange(
                "http://localhost:6789/droneAirport/test",
                "https://xcx.geoway.com.cn:8033/v1/droneAirport/authorization",
                HttpMethod.POST,
                requestEntity,
                String.class);
    }
    @Override
    public ReturnTaskParam AddTask(String base64, String Secret, String username) throws Exception {
    public Map<String, String> AddTask(String base64, String Secret, String username) throws Exception {
        ReturnTaskParam param = new ReturnTaskParam();
        String secret = SM4Util.generateSM4Key();
        String retse = Utils.encrypt(secret, "04225AACF606D800EA3C2C31FCF8FB161B15F7A8D0460DEB91013D4F228C455E76A2ED8D71BC6525B5DC5CC015C155479D8839950344AEE438A3A6305C90F8269F");
        String taskId = UUID.randomUUID().toString();
        String traceid = UUID.randomUUID().toString();
        String sm4Secrect = deSM2(Secret, "23E57DA1E4AB865CCBC325B668762207DEF74345B782237808AE0BABDF26734D");
        String sm4Secrect = deSM2(Secret, "00D631FD5615416EAB63D33A9E66E801F95DE840567504210080006081DE877AE3");
        String decryptedJson = SM4Util.decrypt(sm4Secrect, base64);
        JSONObject jsonObject = new JSONObject(decryptedJson);
        AddTaskDto addTaskDto = jsonToDto(jsonObject);
@@ -283,7 +315,8 @@
                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(getDistinctTaskIdCount(airport.getWorkspaceId()));
//                Long time = getNextDayEightAMTimestamp(getDistinctTaskIdCount(airport.getWorkspaceId()));
                Long time = getAdjustedTimestamp(50);
                List<List<Long>> listOfLists = new ArrayList<>();
                List<Long> sublist = new ArrayList<>();
                sublist.add(time);
@@ -291,21 +324,26 @@
                List<Long> lists1 = new ArrayList<>();
                lists1.add(time);
                String times = TimerUtil.convertTimestampToFormattedString(time);
                param.setJobId(SM4Util.encrypt("jsimjrby3wqb7dbq", taskId));
                param.setJobId(SM4Util.encrypt(secret, taskId));
                timerUtil.sendPostWithParameters(waylineName, waylineFile.getWaylineId(), times, lists1, listOfLists, taskId + "~" + airport.getWorkspaceId(), airport.getDockSn());
                timerUtil.updatePatchesStatu(lotInfosForAirport);
            }
        }
        return param;
        Map<String, String> info = new HashMap<>();
        info.put("taskid", param.getJobId());
        info.put("traceid", param.getTraceId());
        info.put("serect", retse);
        return info;
    }
    @Override
    public ReturnTaskParam updateTask(String base64, String Secret, String username) throws Exception {
    public Map<String, String>  updateTask(String base64, String Secret, String username) throws Exception {
        ReturnTaskParam param = new ReturnTaskParam();
        String secret = SM4Util.generateSM4Key();
        String retse = Utils.encrypt(secret, "04225AACF606D800EA3C2C31FCF8FB161B15F7A8D0460DEB91013D4F228C455E76A2ED8D71BC6525B5DC5CC015C155479D8839950344AEE438A3A6305C90F8269F");
        String traceid = UUID.randomUUID().toString();
        String sm4Secrect = deSM2(Secret, "23E57DA1E4AB865CCBC325B668762207DEF74345B782237808AE0BABDF26734D");
        String sm4Secrect = deSM2(Secret, "00D631FD5615416EAB63D33A9E66E801F95DE840567504210080006081DE877AE3");
        String decryptedJson = SM4Util.decrypt(sm4Secrect, base64);
        JSONObject jsonObject = new JSONObject(decryptedJson);
        UpdataTaskDto addTaskDto = UpjsonToDto(jsonObject);
@@ -363,13 +401,16 @@
                List<Long> lists1 = new ArrayList<>();
                lists1.add(time);
                String times = TimerUtil.convertTimestampToFormattedString(time);
                param.setJobId(taskId);
                param.setJobId(SM4Util.encrypt(secret, taskId));
                timerUtil.sendPostWithParameters(waylineName, waylineFile.getWaylineId(), times, lists1, listOfLists, airport.getWorkspaceId() + "~" + taskId, airport.getDockSn());
                timerUtil.updatePatchesStatu(lotInfosForAirport);
            }
        }
        return param;
        Map<String, String> info = new HashMap<>();
        info.put("taskid", param.getJobId());
        info.put("traceid", param.getTraceId());
        info.put("serect", retse);
        return info;
    }
    @Override
@@ -425,34 +466,28 @@
     * @param taskId 任务 ID
     * @return 匹配的 DB 文件路径列表
     */
    public String findDbFilesByTaskId(String taskId) {
    public Map<String,String> findDbFilesByTaskId(String taskId) throws InvalidCipherTextException, IOException {
        DbUploadEntity entity = dbUploadMapper.selectOne(new LambdaQueryWrapper<DbUploadEntity>()
                .eq(DbUploadEntity::getTaskId, taskId));
        String secret = SM4Util.generateSM4Key();
        String traceId = UUID.randomUUID().toString();
        Map<String,String> info =new HashMap<>();
        String retse = Utils.encrypt(secret, "04225AACF606D800EA3C2C31FCF8FB161B15F7A8D0460DEB91013D4F228C455E76A2ED8D71BC6525B5DC5CC015C155479D8839950344AEE438A3A6305C90F8269F");
        if (entity != null) {
            DbUploadDto dto = DbEntityToDto(entity);
            return SM4Util.encrypt("jsimjrby3wqb7dbq", buildRequestBody(dto));
            String data=buildRequestBody(dto);
            String text=SM4Util.encrypt(secret,data);
            info.put("data", text);
            info.put("serect", retse);
            info.put("traceId",traceId);
            return info;
        }
        return null;
//        File baseDir = new File(BASE_DIR);
//
//        // 检查基础目录是否存在并且是目录
//        if (!baseDir.exists() || !baseDir.isDirectory()) {
//            throw new IllegalStateException("Base directory does not exist or is not a directory.");
//        }
//
//        // 构建文件路径
//        File targetDir = new File(baseDir, taskId);
//        File dbFile = new File(targetDir, ".db");
//
//        // 如果文件存在,则返回文件路径
//        if (dbFile.exists()) {
//            return dbFile.getAbsolutePath();
//        }
//
//        return null; // 或者抛出异常,视需求而定
    }
    public static void main(String[] args) {
        getToken();
    }
    public void delPatchesByTaskId(String taskId) {
        patchesMapper.delete(new LambdaUpdateWrapper<LotInfo>().eq(LotInfo::getTaskId, taskId));
src/main/java/com/dji/sample/droneairport/utils/AuthUtil.java
@@ -34,19 +34,19 @@
        //签名
        byte[] signData = sm2.sign(needSignDataByte);
        String signDataHex = HexUtil.encodeHexStr(signData);
        System.out.println("sign Hex:" + signDataHex);
//        System.out.println("sign Hex:" + signDataHex);
        String signDataBase64 = Base64.encode(signData);
        System.out.println("sign Base64:" + signDataBase64);
//        System.out.println("sign Base64:" + signDataBase64);
        //生成token
        String token = certCode + "." + timestamp + "." + signDataBase64;
        System.out.println("token:" + token);
//        System.out.println("token:" + token);
        //SM2 token验证
        boolean rst1 = sm2.verify(needSignDataByte, signData);
        System.out.println("verify result:" + rst1);
//        System.out.println("verify result:" + rst1);
        boolean rst2 = sm2.verify(needSignDataByte, HexUtil.decodeHex(signDataHex));
        System.out.println("verify result:" + rst2);
//        System.out.println("verify result:" + rst2);
        boolean rst3 = sm2.verify(needSignDataByte, Base64.decode(signDataBase64));
        System.out.println("verify result:" + rst3);
//        System.out.println("verify result:" + rst3);
        return certCode + "." + timestamp + "." + signDataBase64;
    }
src/main/java/com/dji/sample/droneairport/utils/SM2/Test.java
@@ -9,11 +9,11 @@
        System.out.println("秘钥对:" + createKeyPair);
        String privateKey = createKeyPair.get(KeyConstant.PRIVATE_KEY);
        String publicKey = createKeyPair.get(KeyConstant.PUBLIC_KEY);
        String text = "jsimjrby3wqb7dbq";
        String encrypt = Utils.encrypt(text, "044D6061FC08A19D3F32CEAA8CF6679B40500008FD741FC26DE7E50AEBF3A9115D47274437730EADEDAEF0CCC4853C5F0B35B30C6AEA83A5F6FBCA4ABEAC9E3B98",ModeTypeEnum.BASE_MODE.getType());
        System.out.println("加密后密文:" + encrypt);
        String decrypt = Utils.decrypt("04c294d1e7ebc488ede6344e2c207a33cb1e3f6fd4f7585012931a50fab43c907a8486f1df5c61e49d443ddd709aa08585a2814a766cec41ca2af908ef5a230d7d27b5600dd0b388df85616c63f711e06e32f9228129f8fece31e3a1a5eda92cdfee64ef32aa8a7a6451c7b36d32e8a4d0", "23E57DA1E4AB865CCBC325B668762207DEF74345B782237808AE0BABDF26734D",ModeTypeEnum.BASE_MODE.getType());
        System.out.println("解密后明文:" + decrypt);
        String text = "2bc304ccba171672";
        String encrypt = Utils.encrypt(text, "04225AACF606D800EA3C2C31FCF8FB161B15F7A8D0460DEB91013D4F228C455E76A2ED8D71BC6525B5DC5CC015C155479D8839950344AEE438A3A6305C90F8269F",ModeTypeEnum.BASE_MODE.getType());
        System.out.println("加密后密文:" + Utils.hexToBase64(encrypt));
        String decrypt = Utils.decrypt(text, "00D631FD5615416EAB63D33A9E66E801F95DE840567504210080006081DE877AE3",ModeTypeEnum.BASE_MODE.getType());
//        System.out.println("解密后明文:" + decrypt);
    }
}
src/main/java/com/dji/sample/droneairport/utils/SM4Util.java
@@ -108,8 +108,8 @@
    }
    public static void main(String[] args) {
//        System.out.println(generateSM4Key());
        byte[] key = "jsimjrby3wqb7dbq".getBytes(StandardCharsets.UTF_8); // 16字节密钥
        System.out.println(generateSM4Key());
        byte[] key = "2bc304ccba171672".getBytes(StandardCharsets.UTF_8); // 16字节密钥
        // 原始明文
        String plaintext = "{\n" +
@@ -117,7 +117,7 @@
                "    \"1581F6QAD241800B6V95\",\n" +
                "    \"1581F6QAD241500BDZ3J\"\n" +
                "  ],\n" +
                "  \"taskid\": \"f78aed9f-86cd-4a49-87da-bbb9c7a1941d\",\n" +
                "  \"bizidname\": \"test\",\n" +
                "  \"tasklist\": [\n" +
                "    {\n" +
                "      \"bsm\": \"20281071717177177\",\n" +
@@ -126,21 +126,9 @@
                "      \"dklx\": \"ndbg2774\",\n" +
                "      \"dkmc\": \"桥头\",\n" +
                "      \"dkmj\": 20.574,\n" +
                "      \"dkfw\": \"POLYGON((116.0216 25.8926,116.0217 25.8921,116.0205 25.8919,116.0204 25.8928,116.0214 25.8931,116.0216 25.8926))\",\n" +
                "      \"bz\": null\n" +
                "    },\n" +
                "    {\n" +
                "      \"bsm\": \"177177\",\n" +
                "      \"xzqdm\": \"3\",\n" +
                "      \"dkbh\": \"n1\",\n" +
                "      \"dklx\": \"ndbg2774\",\n" +
                "      \"dkmc\": \"大桥头\",\n" +
                "      \"dkmj\": 20.54,\n" +
                "      \"dkfw\": \"POLYGON((116.0126 25.8866,116.0127 25.8849,116.0125 25.885,116.0125 25.8866,116.0126 25.8866))\",\n" +
                "      \"bz\": null\n" +
                "    }\n" +
                "  ]\n" +
                "}\n";
                "      \"dkfw\": \"POLYGON((116.0216 25.8926,116.0217 25.8921,116.0205 25.8919,116.0204 25.8928,116.0214 25.8931,116.0216 25.8926))\"\n" +
                "    }  ]\n" +
                "}";
        String secert =encrypt(key,plaintext.getBytes());
//        System.out.println(secert);
@@ -148,7 +136,7 @@
        byte[] ming= Base64.getDecoder().decode(secert);
        byte[] text=decrypt(key,ming);
//        System.out.println(new String(text, StandardCharsets.UTF_8));
        System.out.println(encrypt("jsimjrby3wqb7dbq",plaintext));
        System.out.println(encrypt("2bc304ccba171672",plaintext));
//        System.out.println(generateSM4Key());
//        System.out.println("封装"+decrypt("8a217699714b0fc0","N0KrVFiFdPlpoRF/pugsgOFjDSymxnhUHe9xbuF4XhO3/uVYC83dCixg9estZC67YdP3R/H9oGQ3uDV1OuSV/dYTnli8nb6hMBCcMhcGMeY0UOoWL00tMOqJMaQQ903C9BaozQ1AjdUu1zaA3uisNdkj3O0jMBZRv7JVWuOYpjaPAElRehLFf25wbDxjAtz8p13OWoUZuCfawcfL2B45H2OOUFzr/a91X26NJvkkRrr4dEngeubTldC53JXF+poD92xfw0f9e+7weLcB4QR01F2mpCNTW4nEdj/aBQxoLtt+zVYOBWFSEBsqu5ExdpRxpRTyN7Sh1inEUVYN0f9OT3mzeF8oaRe/AyI2I50dQrh1pBvNH7uCzjPtSrl8HvhKzv5l+G++3VFb2fDWqconrmt9AOCyxLhOkso6yC8MH9ZtEAVhB20LLVYN0qQrdZHIzJNXgWTDXlTVcPcGUjkTYbKYDk8q/+ToLg7BNCsMVKjwCE/ehbS4aU/3/M3rdXlRxXSuNylT1MZYKy1giRbkVnVHHl4Dw4ZYe5ydm6y1VRS1fcAkEhlcKrmgHGcWDf0i9mBjUqXGRs0ZmD7gsTXDf5/I4Pwhwk7VAJAIQqYElOWnopE4uzjIsY/NzZ6PnBsmLwBuwSvOL+ooZbRTenfmWK7r42dxJNuSkKUl78+igxyYGkD70DsLtx2SlVR+W0Kac2T3Atl4aYxVSBIDn81ngQdLCze+BuzN9L4DRDzsFc0ACg3zoDcvDeWWi39KgJNqjMW25gio7jLQaHRM//sVsVFWf3IFzIjfpYcvPBlqlRZNOTvcSarfQWKECKVP7ltI0RqRx8AiRkLWjI6zntIW+JPHt8PHIXDukMWiOU+uMsMdf4R1zV18XcM6VgtNMiLCO2f8sR5OIM8UfEuNCXyyHiHGRxXrv5SRdTU/FRh1h+dcxI+TvCDmADKf+19KK5owTcLy8LsP08hYOFmkayDXQm3C8ZqUjF5Bxaz0Tz50hrUfwVhd3vifAEZbTjVuYqWaOghpXdl6e/I/vkSbcDT3IuL2WzMIvl+ZoL7U9zKEPFmghBBDhGieJQ0Lq+5Cd961+hBooSeOxletN735xp27DhAllU4Ps+qA0m3gSzDWnSWjd2eHvFDAG2Zd99E0CYUVk7jzAhEg6ihVU56Dxs9b9LfzE0IO6mMl+mpPEhuJWgnHdANGGiwgyAKBdey73f1D0NR9R3X42RgSIJeZSp6YJKmNqZOjWQI3IUKywL0lKsN5zACZYmw0maaK//tRt+ab1jxvh2fkwaQe4Y7EB9brZomYEhUzoHOH6uUK9sMs9ICVFAmV+5eFEpVcFF3mbYTsXaakI1NbicR2P9oFDGgu2/Zw0e9m619q6A3RSYVp5/JiEjwP/3gg7CZTrjR4k52FP9d0WjMeUKWMAfjLMvC3IxA5pmpzsihicdt6Nl0jRyEVpL22sUHYfsXro4JG0AlN3OA2x+8VxffiEv/A9zHbgkjwMC1Ygod4hAlF5/c0rnyBppnRxbk6WEvxwc2rtI4Kv7kYGkomdzYEFrhmlSfLgpL+mfE/TVWR15Abv7Wt2ZfrU140MoH43j0J6fWn1m1HK7sq+Ww2+HH8G6ucPgxsr7zoj1UlP2LF0o3z5kz8upGIzGn2jnJse3M0VFMmLxVicesbgPkxPiYbvnFR6iI0ND24HMMxRtZIWLlg+TGs8BQh0RRm3uTEwtyBs2z9bjsFQhioPDXuyWwyXx90RXJlrli3gMIpTR8lYgfOVGFBi5lIIFAakKMEL4cu/odxCCLEoqYQAkO53hyi9zJ5fO/aaKH7k7CTUgviLLofJUgh9aaHdR1MNpIx+dfO4g3TPVnofCb7/PPOa9U0U87wjb7kTGRx5yK494qfslNofwpRZa9bKT3aZl04XVVQ/v1/zTs49VqxWnv2C0uwg+KT4HWcA5+UyXy2uC8LLBmdYI3h8qmzG57K50wL/AJ7ZMN/MFeKD8ulg1CPupAJxlduH/Zu40F6y1fFqinQfqeVOhXX7lNJoWEycdo0XGsVGq3kdEay0mpLVHUPQVW+wDxN/O7tWdJqS1R1D0FVvsA8Tfzu7VmQyL9Eq3f7OvmqAdFHzQkFQFyd4KpMAlWySab4tCbL+4YVOYfaRysmmui2NZdUW2GcFtceaROR6KNL0KeROxrehgxZeKBn25gneLP9G40kiXhkGRk0ufZ2DGBoHQ7/y9DTwVYGonvJBsJcvM4Kg5Abhy25CzIH75dRVThNHSiWaVAao9yMrQEQFz4PJwysIJnu1jYkrCvQ32t+NkBMN5nZOj8XEyOqtaYh9mVl0oeAfz/XdFozHlCljAH4yzLwtyMQOaZqc7IoYnHbejZdI0chNiZteN46775aU0MC+weqGLYUq4ehBXxq3Yd5ds2Tx+RcxI+TvCDmADKf+19KK5owV2APRlFTvPv6tyO8vu/c0EvSEPMPotb7wtVEOuBGd7+iJ5aKPkiG62ikXLqYAjbDe238+pAN1hCVRcUEkdmzhgN7MdMdB1OSJJ+CC4Om7GZv2xRIYYE3cEOrHCIYlRCT7d5TCatHmJN5Y7HEg2AgSl2/6CoCZbGQaCj8qsqnS7I="));
        String encryptedBase64 = encrypt(key, plaintext.getBytes(StandardCharsets.UTF_8));
src/main/java/com/dji/sample/media/model/MediaFileEntity.java
@@ -84,6 +84,9 @@
    @TableField("job_name")
    private String jobName;
    @TableField("dkbh")
    private String dkbh;
    @TableField(value = "drone_data", typeHandler = FastjsonTypeHandler.class)
    private Object droneData;
src/main/java/com/dji/sample/media/service/IFileService.java
@@ -62,7 +62,7 @@
     */
    List<MediaFileDTO> getAllFilesByWorkspaceId(String workspaceId);
    void saveMarkFile(String workspaceId, MediaFileEntity file, File file1);
    void saveMarkFile(String workspaceId, FileUploadDTO files, File file1);
    PaginationData<MediaFileEntity> mediaQuery(Integer page, Integer pageSize, Long updateStart, Long updateEnd, Long photoStart, Long photoEnd, String jobName,String worksapceId,String isVedio,String jobId);
    PaginationData<MediaFileNailEntity> mediaNailQuery(Integer page, Integer pageSize, Long updateStart, Long updateEnd, Long photoStart, Long photoEnd, String jobName, String workspaceId, String type);
src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java
@@ -32,6 +32,10 @@
import com.dji.sample.territory.service.impl.TbFjServiceImpl;
import com.dji.sample.territory.utils.ImgZipUtil;
import com.dji.sample.territory.utils.WaterMarkUtil;
import com.dji.sample.wayline.dao.IWaylineFileMapper;
import com.dji.sample.wayline.dao.IWaylineJobMapper;
import com.dji.sample.wayline.model.entity.WaylineFileEntity;
import com.dji.sample.wayline.model.entity.WaylineJobEntity;
import com.dji.sample.wayline.service.IWaylineFileService;
import com.dji.sample.wayline.service.IWaylineJobService;
import com.drew.imaging.ImageProcessingException;
@@ -61,6 +65,7 @@
import java.util.stream.Collectors;
import static com.dji.sample.media.util.ImageDownloaderAndCompressor.*;
import static com.dji.sample.patches.utils.TimerUtil.getDkbh;
/**
 * @author sean
@@ -95,6 +100,10 @@
    private MinioPojo pojo;
    private ObjectMapper objectMapper = new ObjectMapper();
    @Autowired
    private IWaylineJobMapper jobMapper;
    @Autowired
    private IWaylineFileMapper fileMapper;
    private Optional<MediaFileEntity> getMediaByFingerprint(String workspaceId, String fingerprint) {
@@ -110,22 +119,25 @@
                .eq(MediaFileEntity::getFileId, fileId));
        return Optional.ofNullable(fileEntity);
    }
    public void saveMarkFile(String workspaceId, MediaFileEntity file,File file1) {
    public void saveMarkFile(String workspaceId, FileUploadDTO files, File file1) {
        try {
            MediaFileMarkEntity mediaFileMarkEntity= new MediaFileMarkEntity();
            MediaFileMarkEntity file=fileUploadConvertToMarkEntity(files);
            MediaFileMarkEntity mediaFileMarkEntity = new MediaFileMarkEntity();
            mediaFileMarkEntity.setWorkspaceId(workspaceId);
            mediaFileMarkEntity.setIsadd(0);
            mediaFileMarkEntity.setIsOriginal(false);
            mediaFileMarkEntity.setFileId(UUID.randomUUID().toString());
            mediaFileMarkEntity.setObjectKey("/mark" + file.getFilePath()+ "/" + file.getFileName());
            mediaFileMarkEntity.setObjectKey("/mark" + file.getFilePath() + "/" + file.getFileName());
            mediaFileMarkEntity.setFileName("mark" + file.getFileName());
            mediaFileMarkEntity.setFilePath("mark" + file.getFilePath());
            uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), mediaFileMarkEntity.getObjectKey(), file1, "image/jpeg");
//            uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", mediaFileMarkEntity.getObjectKey(), nailFile, "image/jpeg");
            markMapper.insert(mediaFileMarkEntity);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Override
    public Boolean checkExist(String workspaceId, String fingerprint) {
        return this.getMediaByFingerprint(workspaceId, fingerprint).isPresent();
@@ -136,59 +148,47 @@
        MediaFileEntity fileEntity = this.fileUploadConvertToEntity(file);
        fileEntity.setWorkspaceId(workspaceId);
        fileEntity.setFileId(UUID.randomUUID().toString());
        int isPlane=checkWaylineType(file.getExt().getFlightId());
        //避免对视频处理引发报错
        if (file.getObjectKey().endsWith("jpeg")){
        if (file.getObjectKey().endsWith("jpeg")&&isPlane!=2) {
            fileEntity.setIsadd(0);
            String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey();
            File downloadedFile = TbFjServiceImpl.downloadFile(url);
            Object data = ImgUtil.getInfo(downloadedFile);
            fileEntity.setDroneData(data);
            updateStatue(file.getName());
            saveFiles(workspaceId,file,downloadedFile);
            saveFiles(workspaceId, file, downloadedFile);
            if (isPlane==1){
                saveMarkFile(workspaceId, file, downloadedFile);
            }
        }
        if (fileEntity.getFileName().endsWith("~")) {
            fileEntity.setDkbh(getDkbh(fileEntity.getFileName()));
        }
        waylineJobService.getName(fileEntity.getJobId());
        return mapper.insert(fileEntity);
    }
    public void saveFiles(String workspaceId, FileUploadDTO file,File mediaFile) {
    public void saveFiles(String workspaceId, FileUploadDTO file, File mediaFile) {
        // 更新文件状态
//        updateStatue(file.getName());
        try {
                // 处理图片文件
                File nailFile = new File(ImgZipUtil.compressImage(mediaFile, 50).toURI());
                MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity(file);
                Object data = ImgUtil.getInfo(mediaFile);
            // 处理图片文件
            File nailFile = new File(ImgZipUtil.compressImage(mediaFile, 50).toURI());
            MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity(file);
            Object data = ImgUtil.getInfo(mediaFile);
//                nailEntity.setIsadd(0);
                nailEntity.setIsOriginal(false);
                nailEntity.setDronedata(data);
                nailEntity.setWorkspaceId(workspaceId);
                nailEntity.setFileName("nail" + file.getName());
                nailEntity.setObjectKey("/nail" + file.getPath() + "/" + file.getName());
                nailEntity.setFilePath("nail" + file.getPath());
                String nailName = nailEntity.getObjectKey();
                nailEntity.setFileId(UUID.randomUUID().toString());
                // 上传图片文件
//            uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket",nailName, nailFile, "image/jpeg");
            uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), nailName, nailFile, "image/jpeg");
            nailEntity.setIsOriginal(false);
            nailEntity.setDronedata(data);
            nailEntity.setWorkspaceId(workspaceId);
            nailEntity.setFileName("nail" + file.getName());
            nailEntity.setObjectKey("/nail" + file.getPath() + "/" + file.getName());
            nailEntity.setFilePath("nail" + file.getPath());
            String nailName = nailEntity.getObjectKey();
            nailEntity.setFileId(UUID.randomUUID().toString());
            uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", nailName, nailFile, "image/jpeg");
                nailMapper.insert(nailEntity);
                // 处理压缩后的图片文件(如果有)
            File zipFile = new File(ImgZipUtil.compressImageAndGetFile(mediaFile, 0.5f).toURI());
            MediaFileZipEntity zipEntity = this.fileUploadConvertToZipEntity(file);
            zipEntity.setIsOriginal(false);
            zipEntity.setWorkspaceId(workspaceId);
            zipEntity.setFileName("zip" + file.getName());
            zipEntity.setObjectKey("/zip" + file.getPath() + "/" + file.getName());
            zipEntity.setFilePath("zip" + file.getPath());
            String zipName = zipEntity.getObjectKey();
            zipEntity.setFileId(UUID.randomUUID().toString());
                // 上传压缩文件
            uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), zipName, zipFile, "image/jpeg");
            uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", zipName, zipFile, "image/jpeg");
            zipMapper.insert(zipEntity);
            nailMapper.insert(nailEntity);
        } catch (IOException | ImageProcessingException e) {
            // 处理异常
            e.printStackTrace();
@@ -198,7 +198,7 @@
    public void updateStatue(String filename) {
        if (filename.contains("~")) {
            String name = TimerUtil.getDkbh(filename);
            String name = getDkbh(filename);
            List<LotInfo> lotInfos = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getDkbh, name));
            if (!lotInfos.isEmpty()) {
                LambdaUpdateWrapper<LotInfo> updateWrapper = new LambdaUpdateWrapper<>();
@@ -219,19 +219,6 @@
            for (MediaFileEntity entity : entitys) {
                if (entity.getDroneData() != null) {
                    return entity.getDroneData();
                }
            }
        }
        if (!filename.contains("mark")) {
            name = "mark" + filename;
        }
        List<MediaFileMarkEntity> entity = markMapper.selectList(new LambdaQueryWrapper<MediaFileMarkEntity>()
                .eq(MediaFileMarkEntity::getFileName, name));
        if (entity != null && !entity.isEmpty()) {
            for (MediaFileMarkEntity markEntity : entity) {
                if (markEntity.getDronedata() != null) {
                    return markEntity.getDronedata();
                }
            }
        } else {
@@ -259,7 +246,7 @@
    }
    @Override
    public PaginationData<MediaFileEntity> mediaQuery(Integer page, Integer pageSize, Long updateStart, Long updateEnd, Long photoStart, Long photoEnd, String jobName, String workspaceId, String type,String jobId) {
    public PaginationData<MediaFileEntity> mediaQuery(Integer page, Integer pageSize, Long updateStart, Long updateEnd, Long photoStart, Long photoEnd, String jobName, String workspaceId, String type, String jobId) {
        // 创建查询条件对象
        LambdaQueryWrapper<MediaFileEntity> queryWrapper = new LambdaQueryWrapper<>();
@@ -282,7 +269,7 @@
            queryWrapper.in(MediaFileEntity::getJobId, jobIds);
        }
        if (jobId != null && !jobId.isEmpty()) {
            queryWrapper.eq(MediaFileEntity::getJobId,jobId);
            queryWrapper.eq(MediaFileEntity::getJobId, jobId);
        }
        if (type != null && !type.isEmpty()) {
@@ -514,18 +501,18 @@
    @Override
    public ResponseResult downloadImages(List<String> jobIds) {
        String localSaveDir = "/home/drone/web/zip";
        String downPath="https://wrj.shuixiongit.com/downloadZip/";
        String filepath=TimerUtil.getNowDay()+".zip";
        String downPath = "https://wrj.shuixiongit.com/downloadZip/";
        String filepath = TimerUtil.getNowDay() + ".zip";
        try {
            String bucketPath = "/data/software/minio-data/cloud-bucket";
            List<String> prefixes = getUniqueFilePaths(jobIds);
            MinioFileDownloader downloader = new MinioFileDownloader(bucketPath);
            downloader.downloadAndZipFolders(prefixes, localSaveDir,filepath);
            downloader.downloadAndZipFolders(prefixes, localSaveDir, filepath);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.error("下载失败" + e.getMessage());
        }
        return ResponseResult.success(downPath+filepath);
        return ResponseResult.success(downPath + filepath);
    }
    @Override
@@ -622,8 +609,8 @@
        return builder.build();
    }
    private MediaFileZipEntity fileUploadConvertToZipEntity(FileUploadDTO file) {
        MediaFileZipEntity.MediaFileZipEntityBuilder builder = MediaFileZipEntity.builder();
    private MediaFileMarkEntity fileUploadConvertToMarkEntity(FileUploadDTO file) {
        MediaFileMarkEntity.MediaFileMarkEntityBuilder builder = MediaFileMarkEntity.builder();
        if (file != null) {
            builder.fileName(file.getName())
@@ -711,16 +698,23 @@
                .eq(MediaFileEntity::getJobId, jobId));
    }
    public int checkWaylineType(String jobId) {
        WaylineJobEntity jobEntity = jobMapper.selectOne(new LambdaQueryWrapper<WaylineJobEntity>().eq(WaylineJobEntity::getJobId, jobId));
        WaylineFileEntity fileEntity=fileMapper.selectOne(new LambdaQueryWrapper<WaylineFileEntity>().eq(WaylineFileEntity::getWaylineId, jobEntity.getFileId()));
        return fileEntity.getWaylineType();
    }
    public void updateMediaFileNames(String jobId) {
        // 查询符合条件的数据
        List<MediaFileEntity> mediaFiles = mapper.selectList(new LambdaQueryWrapper<MediaFileEntity>()
                .eq(MediaFileEntity::getJobId, jobId));
        boolean allContainTilde = mediaFiles.stream().allMatch(file -> file.getFileName().contains("~"));
        boolean noneContainTilde = mediaFiles.stream().noneMatch(file -> file.getFileName().contains("~"));
        // 如果所有 fileName 都包含 '~' 或者都不包含 '~',将 is_add 字段改为 1
        if (allContainTilde || noneContainTilde) {
        // 判断所有的dkbh字段是否都不为空或者都为空
        boolean allHaveDkbh = mediaFiles.stream().allMatch(file -> file.getDkbh() != null && !file.getDkbh().isEmpty());
        boolean noneHaveDkbh = mediaFiles.stream().noneMatch(file -> file.getDkbh() != null && !file.getDkbh().isEmpty());
        // 如果所有dkbh字段都不为空或者都为空,将is_add字段改为1
        if (allHaveDkbh || noneHaveDkbh) {
            mediaFiles.forEach(file -> {
                file.setIsadd(1);
                updateMediaById(file.getId(), file);
@@ -728,21 +722,22 @@
            return;
        }
        // 筛选出name字段不包含'~'的数据
        // 筛选出dkbh字段为空的数据
        List<MediaFileEntity> filteredFiles = mediaFiles.stream()
                .filter(file -> !file.getFileName().contains("~"))
                .filter(file -> file.getDkbh() == null || file.getDkbh().isEmpty())
                .collect(Collectors.toList());
        for (MediaFileEntity currentFile : filteredFiles) {
            String currentName = currentFile.getFileName();
            Map<String, Object> currentMetadata = JSON.parseObject(JSON.toJSONString(currentFile.getMetadata()), Map.class);
            Long currentCreatedTime = (Long) currentMetadata.get("createdTime");
            // 找到metadata中的createdTime小于当前数据的createdTime且最接近的那条数据
            Optional<MediaFileEntity> closestFileOpt = mediaFiles.stream()
                    .filter(file -> {
                        Map<String, Object> metadata = JSON.parseObject(JSON.toJSONString(file.getMetadata()), Map.class);
                        Long createdTime = (Long) metadata.get("createdTime");
                        String filename = file.getFileName();
                        return createdTime < currentCreatedTime && filename.contains("~");
                        return createdTime < currentCreatedTime && file.getDkbh() != null && !file.getDkbh().isEmpty();
                    })
                    .min((file1, file2) -> {
                        Map<String, Object> metadata1 = JSON.parseObject(JSON.toJSONString(file1.getMetadata()), Map.class);
@@ -751,14 +746,14 @@
                        Long time2 = (Long) metadata2.get("createdTime");
                        return Long.compare(currentCreatedTime - time1, currentCreatedTime - time2);
                    });
            if (closestFileOpt.isEmpty()) {
                // 找不到小于的文件,尝试找大于且最接近的文件
                closestFileOpt = mediaFiles.stream()
                        .filter(file -> {
                            Map<String, Object> metadata = JSON.parseObject(JSON.toJSONString(file.getMetadata()), Map.class);
                            Long createdTime = (Long) metadata.get("createdTime");
                            String filename = file.getFileName();
                            return createdTime > currentCreatedTime && filename.contains("~");
                            return createdTime > currentCreatedTime && file.getDkbh() != null && !file.getDkbh().isEmpty();
                        })
                        .min((file1, file2) -> {
                            Map<String, Object> metadata1 = JSON.parseObject(JSON.toJSONString(file1.getMetadata()), Map.class);
@@ -768,40 +763,16 @@
                            return Long.compare(time1 - currentCreatedTime, time2 - currentCreatedTime);
                        });
            }
            // 提取并替换name字段
            // 将最接近的文件的dkbh值赋给当前文件
            closestFileOpt.ifPresent(closestFile -> {
                String closestName = closestFile.getFileName();
                int startIndex = closestName.indexOf("V");
                if (startIndex == -1) startIndex = closestName.indexOf("W");
                if (startIndex == -1) startIndex = closestName.indexOf("Z");
                if (startIndex == -1) startIndex = closestName.indexOf("T");
                if (startIndex == -1) {
                    return;
                }
                int endIndex = closestName.indexOf(".", startIndex);
                if (endIndex == -1) {
                    return;
                }
                String replacement = closestName.substring(startIndex, endIndex);
                int currentStartIndex = currentName.indexOf("V");
                if (currentStartIndex == -1) currentStartIndex = currentName.indexOf("W");
                if (currentStartIndex == -1) currentStartIndex = currentName.indexOf("Z");
                if (currentStartIndex == -1) currentStartIndex = currentName.indexOf("T");
                if (currentStartIndex == -1) {
                    return;
                }
                int currentEndIndex = currentName.indexOf(".", currentStartIndex);
                if (currentEndIndex == -1) {
                    return;
                }
                String newName = currentName.substring(0, currentStartIndex)
                        + replacement
                        + currentName.substring(currentEndIndex);
                currentFile.setFileName(newName);
                currentFile.setDkbh(closestFile.getDkbh());
                currentFile.setIsadd(1);
                updateMediaById(currentFile.getId(), currentFile);
            });
        }
    }
    public void updateMediaZipFileNames(String jobId) {
        // 查询符合条件的数据
@@ -1037,10 +1008,6 @@
    }
    @Override
    public PaginationData<MediaFileEntity> getPhotoByJobId(int pageNum, int pageSize, String workspaceId, String jobId) {
        // 分页查询
@@ -1051,7 +1018,7 @@
        // 添加查询条件
        queryWrapper.eq(MediaFileEntity::getWorkspaceId, workspaceId);
        queryWrapper.eq(MediaFileEntity::getJobId,jobId);
        queryWrapper.eq(MediaFileEntity::getJobId, jobId);
        queryWrapper.last("ORDER BY JSON_EXTRACT(metadata, '$.createdTime') DESC");
        Page<MediaFileEntity> resultPage = mapper.selectPage(page, queryWrapper);
        List<MediaFileEntity> result = resultPage.getRecords();
@@ -1080,8 +1047,6 @@
        Pagination pagination = new Pagination(newPage);
        return new PaginationData<>(uniqueFiles, pagination);
    }
    public List<MediaFileEntity> getMedia(String jobId) {
src/main/java/com/dji/sample/patches/controller/PatchesController.java
@@ -155,7 +155,7 @@
        CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM);
        String creator = customClaim.getUsername();
        MultipartFile file = timerUtil.getFile(waylineName, lotInfos, lat, lon);
        waylineFileService.importKmzFile(file, workspaceId, creator, patchesId, isTemp);
        waylineFileService.importKmzFile(file, workspaceId, creator, patchesId, isTemp,1);
        WaylineFileEntity entity = waylineFileService.selectByName(waylineName);
        Map<String, String> infoMap = new HashMap<>();
        URL url = null;
@@ -200,14 +200,14 @@
        executor.shutdown();
        return ResponseResult.success();
    }
    @PostMapping("/way")
    public void getway(@RequestParam("file") MultipartFile file,
                       @RequestParam String workspaceId,
                       @RequestParam String waylineName,
                       @RequestParam String username) {
        waylineFileService.importKmzFileBack(file, workspaceId, username);
    }
//
//    @PostMapping("/way")
//    public void getway(@RequestParam("file") MultipartFile file,
//                       @RequestParam String workspaceId,
//                       @RequestParam String waylineName,
//                       @RequestParam String username) {
//        waylineFileService.importKmzFileBack(file, workspaceId, username);
//    }
    /**
     * 根据图斑的地块编号获取相对应音视频
@@ -263,7 +263,7 @@
        CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM);
        String creator = customClaim.getUsername();
        MultipartFile multipartFile = shpToDataSourceService.insertGeo(file, workspaceId, waylineName, airportLat, airportLon, creator);
        waylineFileService.importKmzFileBack(multipartFile, workspaceId, creator);
        waylineFileService.importKmzFileBack(multipartFile, workspaceId, creator,1);
        WaylineFileEntity entity = waylineFileService.selectByName(waylineName);
        Map<String, String> infoMap = new HashMap<>();
        URL url = null;
src/main/java/com/dji/sample/patches/utils/TimerUtil.java
@@ -17,9 +17,13 @@
import com.dji.sample.patches.xml.utils.CreateWaylineFileUtils;
import com.dji.sample.territory.pojo.TerritoryConfigPojo;
import com.dji.sample.territory.service.ITbFJService;
import com.dji.sample.wayline.dao.IWaylineJobBreakPointMapper;
import com.dji.sample.wayline.dao.IWaylineJobMapper;
import com.dji.sample.wayline.model.dto.WaylineFileDTO;
import com.dji.sample.wayline.model.dto.WaylineJobDTO;
import com.dji.sample.wayline.model.entity.WaylineFileEntity;
import com.dji.sample.wayline.model.entity.WaylineJobBreakPointEntity;
import com.dji.sample.wayline.model.entity.WaylineJobEntity;
import com.dji.sample.wayline.model.param.CreateJobParam;
import com.dji.sample.wayline.service.IWaylineFileService;
import com.dji.sample.wayline.service.IWaylineJobBreakPointService;
@@ -39,16 +43,13 @@
import org.springframework.web.multipart.MultipartFile;
import java.nio.file.StandardCopyOption;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.*;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.SQLException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ExecutorService;
@@ -69,7 +70,8 @@
    private PatchesConfigPojo patchesConfigPojo;
    @Autowired
    public IWaylineFileService waylineFileService;
    @Autowired
    private IWaylineJobService waylineJobService;
    @Autowired
    private ITbFJService tbFJService;
    @Autowired
@@ -78,7 +80,10 @@
    @Autowired
    private GetPatchesMapper patchesMapper;
    @Autowired
    private IWaylineJobService waylineJobService;
    private IWaylineJobMapper waylineJobMapper;
    @Autowired
    private IWaylineJobBreakPointMapper jobBreakPointMapper;
    @Autowired
    private TerritoryConfigPojo territoryConfigPojo;
    @Autowired
@@ -87,6 +92,7 @@
    private IDeviceMapper deviceMapper;
    @Autowired
    private DbUploadMapper dbUploadMapper;
    /**
     * 定时器,将没有规划的图斑生成航线,并将航线飞完后的成果数据进行保存推送
     *
@@ -141,6 +147,16 @@
        executor.shutdown();
    }
    @Scheduled(cron = "0 45 8-18 * * ?")
    public void runTask() throws SQLException {
        WaylineJobEntity job = processWaylineJobs();
        if (job != null) {
            // 调用其他方法进行后续处理
            handleJobId(job);
        } else {
            System.out.println("未找到符合条件的对象");
        }
    }
    //    public void myTask3() throws SQLException {
//        String workspaceId = "4a574db8-4ad3-48f7-9f16-3edbcd8056e1";
//        String name = getNowDay();
@@ -257,7 +273,7 @@
        String taskId = "";
        String dkbh = null;
        List<List<LotInfo>> lists = convertToLists(getNoPush(workspaceId));
        if (lists.isEmpty()){
        if (lists.isEmpty()) {
            return;
        }
        for (List<LotInfo> lotInfo : lists) {
@@ -283,55 +299,56 @@
        }
    }
    @Scheduled(cron = "0 3 17 * * ?")
   public void GtdbOperation() throws Exception {
    String taskId = "";
    String dkbh = null;
    String code="";
    int count = 0;
    Set<String> dkbhSet = new HashSet<>(); // 用于存储不同的dkbh
    List<List<LotInfo>> lists = convertToLists(getNoPush());
        if (lists.isEmpty()){
    public void GtdbOperation() throws Exception {
        String taskId = "";
        String dkbh = null;
        String code = "";
        int count = 0;
        Set<String> dkbhSet = new HashSet<>(); // 用于存储不同的dkbh
        List<List<LotInfo>> lists = convertToLists(getNoPush());
        if (lists.isEmpty()) {
            return;
        }
        tbFJService.deleteData();
    for (List<LotInfo> lotInfo : lists) {
        for (LotInfo lotInfo1 : lotInfo) {
            List<MediaFileEntity> media = getPatchesService.listPohto(lotInfo1.getDkbh());
            // 清空FJ表
            for (MediaFileEntity mediaFile : media) {
                // 获取媒体文件名里的dkbh和taskId
                dkbh = getDkbh(mediaFile.getFileName());
                dkbhSet.add(dkbh); // 添加dkbh到set中
                // 获取该媒体文件的图斑信息
                LotInfo lotInfo2 = getPatchesService.getLotinfo(dkbh);
                taskId = lotInfo2.getTaskId();
                code=lotInfo2.getXzqdm();
                count++;
                // 插入数据到数据库
                tbFJService.insertOneData(mediaFile, lotInfo2);
                getPatchesService.patchesPushed(taskId, dkbh);
        for (List<LotInfo> lotInfo : lists) {
            for (LotInfo lotInfo1 : lotInfo) {
                List<MediaFileEntity> media = getPatchesService.listPohto(lotInfo1.getDkbh());
                // 清空FJ表
                for (MediaFileEntity mediaFile : media) {
                    // 获取媒体文件名里的dkbh和taskId
                    dkbh = getDkbh(mediaFile.getFileName());
                    dkbhSet.add(dkbh); // 添加dkbh到set中
                    // 获取该媒体文件的图斑信息
                    LotInfo lotInfo2 = getPatchesService.getLotinfo(dkbh);
                    taskId = lotInfo2.getTaskId();
                    code = lotInfo2.getXzqdm();
                    count++;
                    // 插入数据到数据库
                    tbFJService.insertOneData(mediaFile, lotInfo2);
                    getPatchesService.patchesPushed(taskId, dkbh);
                }
            }
        }
        // 存储db到服务器
        String dbName = dbSaveGt(territoryConfigPojo.getResult(), territoryConfigPojo.getResultGtsave(), taskId);
        DbUploadEntity entity = new DbUploadEntity();
        File file = new File(territoryConfigPojo.getResult());
        byte[] bytesArray = Files.readAllBytes(file.toPath());
        long currentTimeMillis = System.currentTimeMillis();
        entity.setTimestamp(currentTimeMillis);
        entity.setSize(getFileSize(file))  ;
        entity.setHash(sm3(bytesArray));
        entity.setCount(dkbhSet.size());// 统计dkbh的数量
        entity.setUrl(territoryConfigPojo.getResultGtsave()+dbName);
        entity.setRegioncode(code);
        entity.setExtension(".db");
        entity.setAttachmentCount(count);
        entity.setTaskId(taskId);
        dbUploadMapper.insert(entity);
            // 存储db到服务器
            String dbName = dbSaveGt(territoryConfigPojo.getResult(), territoryConfigPojo.getResultGtsave(), taskId);
            DbUploadEntity entity = new DbUploadEntity();
            File file = new File(territoryConfigPojo.getResult());
            byte[] bytesArray = Files.readAllBytes(file.toPath());
            long currentTimeMillis = System.currentTimeMillis();
            entity.setTimestamp(currentTimeMillis);
            entity.setSize(getFileSize(file));
            entity.setHash(sm3(bytesArray));
            entity.setCount(dkbhSet.size());// 统计dkbh的数量
            entity.setUrl(territoryConfigPojo.getResultGtsave() + dbName);
            entity.setRegioncode(code);
            entity.setExtension(".db");
            entity.setAttachmentCount(count);
            entity.setTaskId(taskId);
            dbUploadMapper.insert(entity);
        }
    }
}
    /**
@@ -364,7 +381,7 @@
     * @return
     */
    public WaylineFileEntity backWayline(MultipartFile multipartFile, String waylineName, String workspaceId, String username) {
        waylineFileService.importKmzFileBack(multipartFile, workspaceId, username);
        waylineFileService.importKmzFileBack(multipartFile, workspaceId, username, 1);
        WaylineFileEntity entity = waylineFileService.selectByName(waylineName);
        try {
            waylineFileService.getObjectUrl(workspaceId, entity.getWaylineId());
@@ -417,6 +434,7 @@
                .eq(LotInfo::getWorkspaceId, workspaceId));
        return groupTasks(list);
    }
    public List<List<LotInfo>> getNoPush() {
        List<LotInfo> list = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>()
                .eq(LotInfo::getIsPush, 0)
@@ -562,13 +580,13 @@
        return Files.readAllBytes(path);
    }
    public  void sendPostWithParameters(String name, String fileId, String time, List<Long> taskDays, List<List<Long>> taskPeriods, String jobId,String docksn) throws IOException {
    public void sendPostWithParameters(String name, String fileId, String time, List<Long> taskDays, List<List<Long>> taskPeriods, String jobId, String docksn) throws IOException {
        try {
            RestTemplate restTemplate = new RestTemplate();
            // 构建请求体
            String jsonBody = buildRequestBody(name, fileId, time, taskDays, taskPeriods, jobId,docksn);
            String workspaceId =getWorkspaceIdByDocksn(docksn);
            String jsonBody = buildRequestBody(name, fileId, time, taskDays, taskPeriods, jobId, docksn);
            String workspaceId = getWorkspaceIdByDocksn(docksn);
            // 设置请求头
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
@@ -583,7 +601,7 @@
            // 发送请求
            ResponseEntity<String> response = restTemplate.exchange(
//                    "https://wrj.shuixiongit.com/drone-api/wayline/api/v1/workspaces/4a574db8-4ad3-48f7-9f16-3edbcd8056e1/flight-tasks",
                    "http://localhost:6789/wayline/api/v1/workspaces/"+workspaceId+"/flight-tasks",
                    "http://localhost:6789/wayline/api/v1/workspaces/" + workspaceId + "/flight-tasks",
                    HttpMethod.POST,
                    requestEntity,
                    String.class);
@@ -592,10 +610,11 @@
        }
    }
    public String getWorkspaceIdByDocksn(String docksn){
      DeviceEntity entity=  deviceMapper.selectOne(new LambdaQueryWrapper<DeviceEntity>().eq(DeviceEntity::getDeviceSn,docksn));
      return entity.getWorkspaceId();
    public String getWorkspaceIdByDocksn(String docksn) {
        DeviceEntity entity = deviceMapper.selectOne(new LambdaQueryWrapper<DeviceEntity>().eq(DeviceEntity::getDeviceSn, docksn));
        return entity.getWorkspaceId();
    }
    public static void sendPostWithParameters(String name, String fileId, String time, List<Long> taskDays, List<List<Long>> taskPeriods) throws IOException {
        try {
            RestTemplate restTemplate = new RestTemplate();
@@ -725,6 +744,7 @@
            throw new RuntimeException("Db文件复制失败", e); // 捕获并抛出原始异常
        }
    }
    public String dbSaveGt(String path, String folder, String taskId) {
        try {
            String fileName = taskId + ".db";
@@ -766,7 +786,8 @@
        }
        return folder;
    }
    private static File fileFold(String fold,String taskId) {
    private static File fileFold(String fold, String taskId) {
        // 获取当前时间
        LocalDateTime currentTime = LocalDateTime.now();
@@ -782,6 +803,7 @@
        }
        return folder;
    }
    public static Long getCurrentTimestampPlus8Hours(long hours) {
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();
@@ -796,12 +818,13 @@
        // 将毫秒级时间戳转换为秒级时间戳
        return timestamp / 1000;
    }
    public static long getNextDayEightAMTimestamp(int hour) {
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();
        // 获取第二天的日期并设置时间为08:00
        LocalDateTime nextDayEightAM = now.plusDays(1).withHour(8).withMinute(0).withSecond(0).withNano(0);
        LocalDateTime nextDayEightAM = now.plusDays(1).withHour(8).withMinute(30).withSecond(0).withNano(0);
        // 根据传入的hour参数增加小时
        LocalDateTime adjustedTime = nextDayEightAM.plusHours(hour);
@@ -811,7 +834,17 @@
        return zonedDateTime.toEpochSecond();
    }
    public static long getAdjustedTimestamp(int hour) {
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();
        // 根据传入的hour参数增加小时
        LocalDateTime adjustedTime = now.plusSeconds(hour);
        // 转换为时间戳(秒级)
        ZonedDateTime zonedDateTime = adjustedTime.atZone(ZoneId.systemDefault());
        return zonedDateTime.toEpochSecond();
    }
    public static Long addOneHourToTimestamp(Long timestampInSeconds, long hours, long min) {
        // 将输入的秒级时间戳转换为Instant对象
        Instant instant = Instant.ofEpochSecond(timestampInSeconds);
@@ -857,6 +890,7 @@
        // 格式化时间,生成当前时间
        return currentTime.format(DateTimeFormatter.ofPattern("MMddHHmmssSSS"));
    }
    public static long getFileSize(File file) {
        if (file == null || !file.exists() || !file.isFile()) {
            return -1L; // 文件不存在或不是普通文件
@@ -869,8 +903,46 @@
        long size = getFileSize(file);
        System.out.println("文件大小: " + size + " 字节");
    }
    public static void  getFileInfo(File file){
        long size=getFileSize(file);
    public static void getFileInfo(File file) {
        long size = getFileSize(file);
    }
    public WaylineJobEntity processWaylineJobs() {
        // 获取昨天 00:00 和 23:59:59 的时间戳
        LocalDate yesterday = LocalDate.now().minusDays(1);
        long startOfDayMillis = LocalDateTime.of(yesterday, LocalTime.MIN).toInstant(ZoneOffset.UTC).toEpochMilli();
        long endOfDayMillis = LocalDateTime.of(yesterday, LocalTime.MAX).toInstant(ZoneOffset.UTC).toEpochMilli();
        // 查询符合条件的 wayline_job_break_point 对象
        List<WaylineJobBreakPointEntity> breakPoints = jobBreakPointMapper.selectList(
                new LambdaQueryWrapper<WaylineJobBreakPointEntity>()
                        .ge(WaylineJobBreakPointEntity::getCreateTime, startOfDayMillis)
                        .le(WaylineJobBreakPointEntity::getCreateTime, endOfDayMillis)
                        .like(WaylineJobBreakPointEntity::getJobId, "~")
                        .orderByAsc(WaylineJobBreakPointEntity::getCreateTime)
        );
        for (WaylineJobBreakPointEntity breakPoint : breakPoints) {
            String jobId = breakPoint.getJobId();
            // 根据 jobId 查询 wayline_job 表
            WaylineJobEntity job = waylineJobMapper.selectOne(
                    new LambdaQueryWrapper<WaylineJobEntity>()
                            .eq(WaylineJobEntity::getJobId, jobId)
            );
            // 检查 statues 是否等于 3
            if (job != null && job.getStatus() != 3) {
                // 返回符合条件的对象
                return job;
            }
        }
        return null;
    }
    private void handleJobId(WaylineJobEntity entity) throws SQLException {
        Optional<WaylineJobDTO> waylineJobDTO = waylineJobService.getJobByJobId(entity.getWorkspaceId(), entity.getJobId(),true);
        waylineJobService.publishOneFlightTask(waylineJobDTO.get());
    }
}
src/main/java/com/dji/sample/speak/controller/SpeakVoiceController.java
@@ -18,6 +18,9 @@
import java.io.File;
import java.io.IOException;
import static com.dji.sample.speak.util.AudioConverter.convertAudio;
import static com.dji.sample.speak.util.AudioConverter.convertToFile;
@RestController
@RequestMapping("${url.speak.prefix}${url.speak.version}")
public class SpeakVoiceController {
@@ -33,7 +36,8 @@
                                    @RequestParam Integer volumn,
                                    @RequestParam MultipartFile file) throws UnsupportedAudioFileException, IOException {
        File file1 = MultipartFileTOFileUtil.multipartFile2File(file, patchesConfigPojo.getUnzip());
        return ResponseResult.success(voiceServicel.takeVoice(sn, psdk_index, name, file1, volumn));
        File convertFile = convertAudio(file1);
        return ResponseResult.success(voiceServicel.takeVoice(sn, psdk_index, name, convertFile, volumn));
    }
    @PostMapping("/stopVoice")
src/main/java/com/dji/sample/speak/util/AudioConverter.java
New file
@@ -0,0 +1,55 @@
package com.dji.sample.speak.util;
import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
public class AudioConverter {
    public static File convertToFile(File file) throws UnsupportedAudioFileException, IOException {
        int channels =analyzeAudio(file);
        if (channels != 1){
            return convertAudio(file);
        }
        return file;
    }
    public static int  analyzeAudio(File inputFile)
            throws IOException, UnsupportedAudioFileException {
        AudioInputStream audioStream = AudioSystem.getAudioInputStream(inputFile);
        AudioFormat format = audioStream.getFormat();
        int channels = format.getChannels();
        audioStream.close();
        return channels;
    }
    public static File convertAudio(File inputFile)
            throws IOException, UnsupportedAudioFileException {
        // 固定参数:声道数 1,采样率 16 kHz,位宽 16 bit
        float sampleRate = 16000;
        int channels = 1;
        int bitDepth = 16;
        AudioInputStream sourceStream = AudioSystem.getAudioInputStream(inputFile);
        AudioFormat targetFormat = new AudioFormat(
                AudioFormat.Encoding.PCM_SIGNED,
                sampleRate,
                bitDepth,
                channels,
                (bitDepth / 8) * channels,
                sampleRate,
                false
        );
        AudioInputStream convertedStream = AudioSystem.getAudioInputStream(targetFormat, sourceStream);
        // 使用源文件名生成输出文件名
        File outputFile = new File("converted_" + inputFile.getName());
        AudioSystem.write(convertedStream, AudioFileFormat.Type.WAVE, outputFile);
        sourceStream.close();
        convertedStream.close();
        return outputFile;
    }
}
src/main/java/com/dji/sample/wayline/controller/WaylineFileController.java
@@ -237,7 +237,7 @@
        }
        CustomClaim customClaim = (CustomClaim) request.getAttribute(TOKEN_CLAIM);
        String creator = customClaim.getUsername();
        String back = waylineFileService.importKmzFile(file, workspaceId, creator, patchesId,isTemp);
        String back = waylineFileService.importKmzFile(file, workspaceId, creator, patchesId,isTemp,0);
        if (back != null) {
            return ResponseResult.error(back);
        }
src/main/java/com/dji/sample/wayline/dao/IWaylineJobBreakPointMapper.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dji.sample.wayline.model.entity.WaylineJobBreakPointEntity;
import org.apache.ibatis.annotations.Mapper;
/**
 * @PROJECT_NAME: drone
@@ -9,5 +10,6 @@
 * @USER: aix
 * @DATE: 2024/3/23 11:09
 */
@Mapper
public interface IWaylineJobBreakPointMapper extends BaseMapper<WaylineJobBreakPointEntity> {
}
src/main/java/com/dji/sample/wayline/model/dto/WaylineFileDTO.java
@@ -46,4 +46,6 @@
    private String spotInFreckle;
    private String isTemp;
    private int waylineType;
}
src/main/java/com/dji/sample/wayline/model/entity/WaylineFileEntity.java
@@ -63,6 +63,9 @@
    @TableField("is_temp")
    private String isTemp;
    @TableField("wayline_type")
    private int waylineType;
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Long createTime;
src/main/java/com/dji/sample/wayline/plane/controller/CreateWayLineController.java
@@ -61,7 +61,7 @@
        String destKMZFile = patchesConfigPojo.getPlaneKMZFile() + param.getWaylineName() + ".kmz"; // 输出的KMZ文件路径
        ZipUtil.zipFolder(patchesConfigPojo.getSourceDir(), destKMZFile);
        MultipartFile multipartFile = MultipartFileTOFileUtil.convert(new File(destKMZFile));
        waylineFileService.importKmzFile(multipartFile, workspaceId, creator, null, "1");
        waylineFileService.importKmzFile(multipartFile, workspaceId, creator, null, "1",2);
        return ResponseResult.success();
    }
@@ -82,7 +82,7 @@
        String destKMZFile = patchesConfigPojo.getPlaneKMZFile() + param.getWaylineName() + ".kmz"; // 输出的KMZ文件路径
        ZipUtil.zipFolder(patchesConfigPojo.getSourceDir(), destKMZFile);
        MultipartFile multipartFile = MultipartFileTOFileUtil.convert(new File(destKMZFile));
        waylineFileService.importPlaneKmzFile(multipartFile, workspaceId, creator, null, "1");
        waylineFileService.importPlaneKmzFile(multipartFile, workspaceId, creator, null, "1",1);
        return ResponseResult.success();
    }
}
src/main/java/com/dji/sample/wayline/service/IWaylineFileService.java
@@ -55,7 +55,7 @@
     * @return
     */
    Integer saveWaylineFile(String workspaceId, WaylineFileDTO metadata);
    Integer saveWaylineFiles(String workspaceId, WaylineFileDTO metadata,String patchesId,String isTemp);
    Integer saveWaylineFiles(String workspaceId, WaylineFileDTO metadata,String patchesId,String isTemp,int waylineType);
    /**
     * Updates whether the file is collected or not based on the passed parameters.
     * @param workspaceId
@@ -87,7 +87,7 @@
     * @param creator
     * @return
     */
    String importKmzFile(MultipartFile file, String workspaceId, String creator,String patchesId,String isTemp);
     String importKmzFile(MultipartFile file, String workspaceId, String creator, String patchesId,String isTemp,int waylineType);
    /**
@@ -97,9 +97,9 @@
     * @param creator
     * @return
     */
    WaylineFileDTO importKmzFileBack (MultipartFile file, String workspaceId, String creator);
    WaylineFileDTO importKmzFileBack(MultipartFile file, String workspaceId, String creator,int waylineType);
    WaylineFileEntity selectByName(String name);
    WaylineFileDTO importPlaneKmzFile (MultipartFile file, String workspaceId, String creator,String newName,String id);
    WaylineFileDTO importPlaneKmzFile(MultipartFile file, String workspaceId, String creator,String newName,String id,int waylineType);
    List<WaylineListDTO> waylineList(String workspaceId,String droneName);
    int updateWayline(WaylineFileEntity entity);
src/main/java/com/dji/sample/wayline/service/impl/WaylineFileServiceImpl.java
@@ -138,6 +138,7 @@
        WaylineFileEntity file = this.dtoConvertToEntity(metadata);
        file.setWaylineId(UUID.randomUUID().toString());
        file.setWorkspaceId(workspaceId);
        file.setWaylineType(metadata.getWaylineType());
        if (!StringUtils.hasText(file.getSign())) {
            try (InputStream object = ossService.getObject(OssConfiguration.bucket, metadata.getObjectKey())) {
                if (object.available() == 0) {
@@ -154,12 +155,13 @@
    }
    @Override
    public Integer saveWaylineFiles(String workspaceId, WaylineFileDTO metadata, String patchesId,String isTemp) {
    public Integer saveWaylineFiles(String workspaceId, WaylineFileDTO metadata, String patchesId,String isTemp,int waylineType) {
        metadata.setPatchesId(patchesId);
        WaylineFileEntity file = this.dtoConvertToEntity(metadata);
        file.setWaylineId(UUID.randomUUID().toString());
        file.setWorkspaceId(workspaceId);
        file.setIsTemp(isTemp);
        file.setWaylineType(waylineType);
        if (!StringUtils.hasText(file.getSign())) {
            try (InputStream object = ossService.getObject(OssConfiguration.bucket, metadata.getObjectKey())) {
                if (object.available() == 0) {
@@ -218,7 +220,7 @@
    }
    @Override
    public String importKmzFile(MultipartFile file, String workspaceId, String creator, String patchesId,String isTemp) {
    public String importKmzFile(MultipartFile file, String workspaceId, String creator, String patchesId,String isTemp,int waylineType) {
        Optional<WaylineFileDTO> waylineFileOpt = validKmzFile(file);
        if (waylineFileOpt.isEmpty()) {
            throw new RuntimeException("文件格式错误");
@@ -229,9 +231,10 @@
            waylineFile.setWaylineId(workspaceId);
            waylineFile.setUsername(creator);
            waylineFile.setIsTemp(isTemp);
            waylineFile.setWaylineType(waylineType);
            back = ossService.putObject(OssConfiguration.bucket, waylineFile.getObjectKey(), file.getInputStream());
            if (back == null) {
                this.saveWaylineFiles(workspaceId, waylineFile, patchesId,isTemp);
                this.saveWaylineFiles(workspaceId, waylineFile, patchesId,isTemp, waylineType);
            }
        } catch (IOException e) {
            e.printStackTrace();
@@ -241,7 +244,7 @@
    @Override
    public WaylineFileDTO importKmzFileBack(MultipartFile file, String workspaceId, String creator) {
    public WaylineFileDTO importKmzFileBack(MultipartFile file, String workspaceId, String creator,int waylineType) {
        WaylineFileDTO waylineFile = null;
        Optional<WaylineFileDTO> waylineFileOpt = validKmzFile(file);
        if (waylineFileOpt.isEmpty()) {
@@ -252,6 +255,7 @@
            waylineFile = waylineFileOpt.get();
            waylineFile.setWaylineId(workspaceId);
            waylineFile.setUsername(creator);
            waylineFile.setWaylineType(waylineType);
            ossService.putObject(OssConfiguration.bucket, waylineFile.getObjectKey(), file.getInputStream());
            this.saveWaylineFile(workspaceId, waylineFile);
@@ -261,7 +265,7 @@
        return waylineFile;
    }
    @Override
    public WaylineFileDTO importPlaneKmzFile(MultipartFile file, String workspaceId, String creator,String newName,String id) {
    public WaylineFileDTO importPlaneKmzFile(MultipartFile file, String workspaceId, String creator,String newName,String id,int waylineType) {
        WaylineFileDTO waylineFile = null;
        Optional<WaylineFileDTO> waylineFileOpt = validKmzFile(file);
        if (waylineFileOpt.isEmpty()) {