src/main/java/com/dji/sample/common/model/ResponseResult.java
@@ -56,6 +56,13 @@ .traceid(traceid) .build(); } public static<T> ResponseResult success(int code, String message,T data) { return ResponseResult.builder() .code(code) .data(data) .message(message) .build(); } public static ResponseResult success(int code, String message,String traceid) { return ResponseResult.builder() .code(code) src/main/java/com/dji/sample/droneairport/controller/RegistController.java
@@ -29,12 +29,12 @@ // public ResponseResult resgitePort(@RequestBody RegistDto param) { // return ResponseResult.success(registService.registPort(param)); // } @PostMapping("/authorization") public ResponseResult checkDeviceOnline(@RequestBody String body, HttpServletRequest request) throws Exception { String headerValue = request.getHeader("x-lc-secret"); return registService.authorization(body, headerValue); } // @PostMapping("/authorization") // public ResponseResult checkDeviceOnline(@RequestBody String body, HttpServletRequest request) throws Exception { // String headerValue = request.getHeader("x-lc-secret"); // return registService.authorization(body, headerValue); // // } @PostMapping("/addDevice/{workspace_id}") public ResponseResult registeDrone(@PathVariable(name = "workspace_id") String workspaceId) { @@ -70,11 +70,14 @@ } @PostMapping("/queryTaskStatus") public ResponseResult queryTaskStatus(HttpServletRequest request, @RequestParam String taskid) throws Exception { return ResponseResult.success(registService.queryTaskStatus(taskid)); return registService.queryTaskStatus(taskid); } @GetMapping("/getResult/{taskId}") public ResponseResult getResult(@PathVariable(name = "taskId") String taskId) { return ResponseResult.success(registService.findDbFilesByTaskId(taskId)); return ResponseResult.success(200, "无人机成果获取成功!",registService.findDbFilesByTaskId(taskId)); } @PostMapping("/test") public ResponseResult test(@RequestBody String param) { return ResponseResult.success(param); } } src/main/java/com/dji/sample/droneairport/dao/DbUploadMapper.java
New file @@ -0,0 +1,9 @@ package com.dji.sample.droneairport.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.dji.sample.droneairport.model.Entity.DbUploadEntity; import org.apache.ibatis.annotations.Mapper; @Mapper public interface DbUploadMapper extends BaseMapper<DbUploadEntity> { } src/main/java/com/dji/sample/droneairport/model/Entity/DbUploadEntity.java
New file @@ -0,0 +1,40 @@ package com.dji.sample.droneairport.model.Entity; import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @Data @Builder @NoArgsConstructor @AllArgsConstructor @TableName(value = "db_info") public class DbUploadEntity { @TableField("task_id") private String taskId; @TableField("code") private String regioncode; @TableField("size") private long size; @TableField("count") private int count; @TableField("attachment") private int attachmentCount; @TableField("extension") private String extension; @TableField("hash") private String hash; @TableField(value = "timestamp", fill = FieldFill.INSERT) private Long timestamp; @TableField("url") private String url; @TableField("decrypt") private String decrypt; @TableField("data_sign") private String dataSign; } src/main/java/com/dji/sample/droneairport/model/dto/AuthorDto.java
New file @@ -0,0 +1,15 @@ package com.dji.sample.droneairport.model.dto; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @Data @Builder @NoArgsConstructor @AllArgsConstructor public class AuthorDto { private String sn; private int status; } src/main/java/com/dji/sample/droneairport/model/dto/DbUploadDto.java
New file @@ -0,0 +1,38 @@ package com.dji.sample.droneairport.model.dto; import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @Data @Builder @NoArgsConstructor @AllArgsConstructor public class DbUploadDto { private String taskId; private String regioncode; private long size; private int count; private int attachmentCount; private String extension; private String hash; private Long timestamp; private String url; private String key; private String sign; } src/main/java/com/dji/sample/droneairport/service/RegistService.java
@@ -39,8 +39,10 @@ * @return 返回授权结果,包括成功与否、错误信息等 * @throws Exception 如果授权过程中出现错误,可能会抛出异常 */ ResponseResult authorization(String base64, String Secret) throws Exception; // ResponseResult authorization(String base64, String Secret) throws Exception; void noAuthorization(String sn); void Authorization(String sn); /** * 添加任务接口 * 该方法将基础64编码的配置信息、密钥和用户名作为参数,实现任务的添加 @@ -76,10 +78,17 @@ * 查询任务状态 * 此方法用于根据设备ID查询设备任务的状态 * * @param deviceId 设备ID,用于标识特定的设备 * @param taskid 设备ID,用于标识特定的设备 * @return 返回一个ResponseResult对象,包含查询到的任务状态信息 */ ResponseResult queryTaskStatus(String taskid); List<String> findDbFilesByTaskId(String taskId); /** * 获取无人机拍摄的成果DB包下载地址 * * @param taskId 无人机的设备ID,用于唯一标识一台无人机 * @return 返回一个包含无人机状态信息的ResponseResult对象 * @throws Exception 如果在获取无人机状态过程中发生错误,将抛出异常 */ String findDbFilesByTaskId(String taskId); } src/main/java/com/dji/sample/droneairport/service/impl/RegistServiceImpl.java
@@ -10,7 +10,9 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.dji.sample.common.model.ResponseResult; import com.dji.sample.component.redis.RedisOpsUtils; import com.dji.sample.droneairport.dao.DbUploadMapper; import com.dji.sample.droneairport.dao.DeviceExpanSionMapper; import com.dji.sample.droneairport.model.Entity.DbUploadEntity; import com.dji.sample.droneairport.model.Entity.DeviceExpanSionEntity; import com.dji.sample.droneairport.model.dto.*; import com.dji.sample.droneairport.model.param.ReturnTaskParam; @@ -47,11 +49,15 @@ 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.util.*; import java.util.stream.Collectors; 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; @Service public class RegistServiceImpl implements RegistService { @@ -73,13 +79,13 @@ private IWaylineJobMapper waylineJobMapper; @Autowired private IWaylineFileMapper fileMapper; @Autowired private DbUploadMapper dbUploadMapper; public String registPort(DeviceExpanSionEntity airport) { try { RegistDto registDto = airportEntityToDto(airport); // 构建请求体 String jsonBody = buildRequestBody(registDto); // 设置请求头 String base64 = SM4Util.encrypt("jsimjrby3wqb7dbq", jsonBody); // 设置请求头 HttpHeaders headers = new HttpHeaders(); @@ -87,13 +93,13 @@ 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-lc-token", AuthUtil.getToken()); headers.set("x-lc-secret", Utils.hexToBase64(Utils.encrypt("jsimjrby3wqb7dbq", "044D6061FC08A19D3F32CEAA8CF6679B40500008FD741FC26DE7E50AEBF3A9115D47274437730EADEDAEF0CCC4853C5F0B35B30C6AEA83A5F6FBCA4ABEAC9E3B98"))); headers.set("x-auth-token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ3b3Jrc3BhY2VfaWQiOiJlM2RlYTBmNS0zN2YyLTRkNzktYWU1OC00OTBhZjMyMjgwNjkiLCJzdWIiOiJDbG91ZEFwaVNhbXBsZSIsInVzZXJfdHlwZSI6IjEiLCJuYmYiOjE3MjA2NTg3NDMsImxvZyI6IkxvZ2dlcltjb20uZGppLnNhbXBsZS5jb21tb24ubW9kZWwuQ3VzdG9tQ2xhaW1dIiwiaXNzIjoiREpJIiwiaWQiOiI5Y2MwMGY3Zi0yODMwLTRmM2UtYjdmNC1lN2E1ZjIzYjNjNGYiLCJleHAiOjE4MDcwNTg3NDMsImlhdCI6MTcyMDY1ODc0MywidXNlcm5hbWUiOiJhZG1pbkRQIn0.CrRFYUTK357HleqrrfL7nLdwFJw5Bcv3ms33n_Or8eM"); headers.set("x-lc-token", ""); // 构建请求实体 HttpEntity<String> requestEntity = new HttpEntity<>(base64, headers); // 发送请求 ResponseEntity<String> response = restTemplate.exchange( "https://xcx.geoway.com.cn:8033/v1/droneAirport/RegistService", "http://localhost:6789/droneAirport/test", HttpMethod.POST, requestEntity, String.class); @@ -105,11 +111,19 @@ } } private String buildRequestBody(RegistDto dto) { // private String buildRequestBody(RegistDto dto) { // try { // return objectMapper.writeValueAsString(dto); // } catch (JsonProcessingException e) { // throw new RuntimeException("数据有误", e); // } // } public <T> String buildRequestBody(T obj) { try { return objectMapper.writeValueAsString(dto); return objectMapper.writeValueAsString(obj); } catch (JsonProcessingException e) { throw new RuntimeException("数据有误", e); throw new RuntimeException("对象转换为JSON字符串时发生错误", e); } } @@ -126,24 +140,25 @@ // 构建请求体 String jsonBody = buildRequestBody(dto); String base64 = SM4Util.encrypt("jsimjrby3wqb7dbq", jsonBody); String secret = enSM2("jsimjrby3wqb7dbq", "044D6061FC08A19D3F32CEAA8CF6679B40500008FD741FC26DE7E50AEBF3A9115D47274437730EADEDAEF0CCC4853C5F0B35B30C6AEA83A5F6FBCA4ABEAC9E3B98"); // 设置请求头 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-lc-token", AuthUtil.getToken()); headers.set("x-lc-secret", secret); headers.set("x-auth-token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ3b3Jrc3BhY2VfaWQiOiJlM2RlYTBmNS0zN2YyLTRkNzktYWU1OC00OTBhZjMyMjgwNjkiLCJzdWIiOiJDbG91ZEFwaVNhbXBsZSIsInVzZXJfdHlwZSI6IjEiLCJuYmYiOjE3MjA2NTg3NDMsImxvZyI6IkxvZ2dlcltjb20uZGppLnNhbXBsZS5jb21tb24ubW9kZWwuQ3VzdG9tQ2xhaW1dIiwiaXNzIjoiREpJIiwiaWQiOiI5Y2MwMGY3Zi0yODMwLTRmM2UtYjdmNC1lN2E1ZjIzYjNjNGYiLCJleHAiOjE4MDcwNTg3NDMsImlhdCI6MTcyMDY1ODc0MywidXNlcm5hbWUiOiJhZG1pbkRQIn0.CrRFYUTK357HleqrrfL7nLdwFJw5Bcv3ms33n_Or8eM"); headers.set("x-lc-token", ""); // 构建请求实体 HttpEntity<String> requestEntity = new HttpEntity<>(base64, headers); // 发送请求 RestTemplate restTemplate = new RestTemplate(); String response = restTemplate.postForObject("https://xcx.geoway.com.cn:8033/v1/droneAirport/addDevice", requestEntity, String.class); ResponseEntity<String> response = restTemplate.exchange( "http://localhost:6789/droneAirport/test", HttpMethod.POST, requestEntity, String.class); registPort(airport); return response; return response.getBody(); } catch (Exception e) { // 异常处理 @@ -159,17 +174,66 @@ return SM4Screct; } // @Override // public ResponseResult authorization(String base64, String Secret) throws Exception { // String sm4Secrect = deSM2(Secret, "23E57DA1E4AB865CCBC325B668762207DEF74345B782237808AE0BABDF26734D"); // String decryptedJson = SM4Util.decrypt(sm4Secrect, base64); // JSONObject jsonObject = new JSONObject(decryptedJson); // String deviceId = jsonObject.getStr("deviceid"); // boolean online = redisService.checkDeviceOnline(deviceId); // if (online) { // return ResponseResult.success(200, "无人机机场授权成功!", "", ""); // } // return ResponseResult.error(500, "无人机机场授权失败!"); // } @Override public ResponseResult authorization(String base64, String Secret) throws Exception { String sm4Secrect = deSM2(Secret, "23E57DA1E4AB865CCBC325B668762207DEF74345B782237808AE0BABDF26734D"); String decryptedJson = SM4Util.decrypt(sm4Secrect, base64); JSONObject jsonObject = new JSONObject(decryptedJson); String deviceId = jsonObject.getStr("deviceid"); boolean online = redisService.checkDeviceOnline(deviceId); if (online) { return ResponseResult.success(200, "无人机机场授权成功!", "", ""); public void noAuthorization(String sn) { AuthorDto dto = new AuthorDto(); dto.setSn(sn); dto.setStatus(0); String jsonBody = buildRequestBody(dto); String base64 = SM4Util.encrypt("jsimjrby3wqb7dbq", 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", ""); // 构建请求实体 HttpEntity<String> requestEntity = new HttpEntity<>(base64, headers); // 发送请求 ResponseEntity<String> response = restTemplate.exchange( "http://localhost:6789/droneAirport/test", HttpMethod.POST, requestEntity, String.class); } return ResponseResult.error(500, "无人机机场授权失败!"); @Override public void Authorization(String sn) { AuthorDto dto = new AuthorDto(); dto.setSn(sn); dto.setStatus(1); String jsonBody = buildRequestBody(dto); String base64 = SM4Util.encrypt("jsimjrby3wqb7dbq", 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", ""); // 构建请求实体 HttpEntity<String> requestEntity = new HttpEntity<>(base64, headers); // 发送请求 ResponseEntity<String> response = restTemplate.exchange( "http://localhost:6789/droneAirport/test", HttpMethod.POST, requestEntity, String.class); } @Override @@ -197,7 +261,7 @@ for (TaskListDto taskListDto : tasklist) { LotInfo lotInfo = convertToLotInfo(taskListDto); lotInfo.setTaskId(taskId); lotInfo.setType(0); lotInfo.setType(1); lotInfo.setTaskName(addTaskDto.getBizidname()); lotInfo.setUserName(username); lotInfos.add(lotInfo); @@ -220,7 +284,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 = getCurrentTimestampPlus8Hours(14); Long time = getNextDayEightAMTimestamp(countDistinctTaskIdsForToday(airport.getWorkspaceId())); List<List<Long>> listOfLists = new ArrayList<>(); List<Long> sublist = new ArrayList<>(); sublist.add(time); @@ -228,7 +292,7 @@ List<Long> lists1 = new ArrayList<>(); lists1.add(time); String times = TimerUtil.convertTimestampToFormattedString(time); param.setJobId(taskId); param.setJobId(SM4Util.encrypt("jsimjrby3wqb7dbq", taskId)); timerUtil.sendPostWithParameters(waylineName, waylineFile.getWaylineId(), times, lists1, listOfLists, taskId + "~" + airport.getWorkspaceId(), airport.getDockSn()); timerUtil.updatePatchesStatu(lotInfosForAirport); } @@ -267,7 +331,7 @@ for (TaskListDto taskListDto : tasklist) { LotInfo lotInfo = convertToLotInfo(taskListDto); lotInfo.setTaskId(taskId); lotInfo.setType(0); lotInfo.setType(1); lotInfo.setTaskName(Bizidname); lotInfo.setUserName(username); lotInfos.add(lotInfo); @@ -292,7 +356,7 @@ WaylineFileEntity waylineFile = timerUtil.backWayline(multipartFile, waylineName, airport.getWorkspaceId(), username); // 将为规划的图斑状态更新为已规划 Long time = getCurrentTimestampPlus8Hours(14); Long time = getNextDayEightAMTimestamp(countDistinctTaskIdsForToday(airport.getWorkspaceId())); List<List<Long>> listOfLists = new ArrayList<>(); List<Long> sublist = new ArrayList<>(); sublist.add(time); @@ -333,28 +397,28 @@ @Override public ResponseResult queryTaskStatus(String taskid) { WaylineJobEntity jobEntity = waylineJobMapper.selectOne(new LambdaQueryWrapper<WaylineJobEntity>().eq(WaylineJobEntity::getJobId, taskid)); if (jobEntity == null) { List<WaylineJobEntity> jobEntity = waylineJobMapper.selectList(new LambdaQueryWrapper<WaylineJobEntity>().like(WaylineJobEntity::getJobId, taskid)); if (jobEntity == null || jobEntity.isEmpty()) { return ResponseResult.error(201, "查询无人机机场任务状态失败!"); } int code = jobEntity.getStatus(); //1: 待执行; 2: 执行中; 3: 完成; 4: 取消; 5: 失败 if (code == 1) { return ResponseResult.success(200, "查询无人机机场任务状态成功!", "", ""); } else if (code == 2) { return ResponseResult.success(202, "查询无人机机场任务状态成功!", "", ""); } else if (code == 3) { return ResponseResult.success(203, "查询无人机机场任务状态成功!", "", ""); } else if (code == 4) { return ResponseResult.success(204, "查询无人机机场任务状态成功!", "", ""); } else if (code == 5) { return ResponseResult.success(205, "查询无人机机场任务状态成功!", "", ""); } return null; } // 检查是否所有 status 都等于 4 boolean allStatusAreFour = jobEntity.stream() .allMatch(job -> job.getStatus() == 4); private static final String BASE_DIR = "src/main/resources/tmp"; // 检查是否所有 status 都等于 3 boolean allStatusAreThree = jobEntity.stream() .allMatch(job -> job.getStatus() == 3); if (allStatusAreFour) { return ResponseResult.error(204, "查询无人机机场任务状态成功!"); } else if (allStatusAreThree) { return ResponseResult.error(200, "查询无人机机场任务状态成功!"); } else { return ResponseResult.error(202, "查询无人机机场任务状态成功!"); } } /** * 根据任务 ID 查找对应的 DB 文件路径 @@ -362,49 +426,65 @@ * @param taskId 任务 ID * @return 匹配的 DB 文件路径列表 */ public List<String> findDbFilesByTaskId(String taskId) { List<String> dbFilePaths = new ArrayList<>(); File baseDir = new File(BASE_DIR); 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)); } return null; // 检查基础目录是否存在 if (!baseDir.exists() || !baseDir.isDirectory()) { throw new IllegalStateException("Base directory does not exist or is not a directory."); // 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; // 或者抛出异常,视需求而定 } // 遍历基础目录下的所有文件夹 File[] subDirs = baseDir.listFiles(File::isDirectory); if (subDirs != null) { for (File subDir : subDirs) { // 如果文件夹名称包含任务 ID,则查找该文件夹中的 DB 文件 if (subDir.getName().contains(taskId)) { File[] files = subDir.listFiles((dir, name) -> name.endsWith(".db")); if (files != null) { for (File file : files) { dbFilePaths.add(file.getAbsolutePath()); } } } } } return dbFilePaths; } public void delPatchesByTaskId(String taskId) { patchesMapper.delete(new LambdaUpdateWrapper<LotInfo>().eq(LotInfo::getTaskId, taskId)); } public DbUploadDto DbEntityToDto(DbUploadEntity entity) { DbUploadDto dto = new DbUploadDto(); dto.setAttachmentCount(entity.getAttachmentCount()); dto.setCount(entity.getCount()); dto.setSign(entity.getDataSign()); dto.setExtension(entity.getExtension()); dto.setHash(entity.getHash()); dto.setRegioncode(entity.getRegioncode()); dto.setTaskId(entity.getTaskId()); dto.setKey(entity.getDecrypt()); dto.setTimestamp(entity.getTimestamp()); dto.setSize(entity.getSize()); dto.setUrl(entity.getUrl()); return dto; } public void delTaskInfo(String taskId) { taskInfoMapper.delete(new LambdaUpdateWrapper<TaskInfo>().eq(TaskInfo::getTaskId, taskId)); } private String buildRequestBody(AddDeviceDto dto) { try { return objectMapper.writeValueAsString(dto); } catch (JsonProcessingException e) { throw new RuntimeException("数据有误", e); } } // private String buildRequestBody(AddDeviceDto dto) { // try { // return objectMapper.writeValueAsString(dto); // } catch (JsonProcessingException e) { // throw new RuntimeException("数据有误", e); // } // } public String getWorkspaceId(String devicesn) { DeviceEntity entity = deviceMapper.selectOne(new LambdaQueryWrapper<DeviceEntity>() @@ -499,9 +579,8 @@ int mode; int sne = osdDockReceiver.getModeCode().getVal(); if (sne==0){ mode=1; } else { mode = 0; } else { mode=2; } DroneStateDto.DroneStateDtoBuilder builder = DroneStateDto.builder(); @@ -669,4 +748,19 @@ // 调用 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) ); } } src/main/java/com/dji/sample/droneairport/utils/SM4Util.java
@@ -108,15 +108,16 @@ } public static void main(String[] args) { // System.out.println(generateSM4Key()); byte[] key = "jsimjrby3wqb7dbq".getBytes(StandardCharsets.UTF_8); // 16字节密钥 // 原始明文 String plaintext = "{\n" + " \"deviceid\": [\n" + " \"1581F6QAD241800B6V95\",\n" + " \"1581F5BMD22CK0014H2U\"\n" + " \"1581F6QAD241500BDZ3J\"\n" + " ],\n" + " \"bizidname\": \"南昌市西湖区图斑下发\",\n" + " \"bizidname\": \"2023年度全国国土变更调查举证模块\",\n" + " \"tasklist\": [\n" + " {\n" + " \"bsm\": \"2028107171717717107171017\",\n" + @@ -125,7 +126,7 @@ " \"dklx\": \"ndbg2024\",\n" + " \"dkmc\": \"小桥头\",\n" + " \"dkmj\": 20.5,\n" + " \"dkfw\": \"MULTIPOLYGON(((115.86528871951153 28.625287925196325,115.86561708513025 28.625787612007546,115.86815834948467 28.624602640426623,115.86773004650362 28.62425999804172,115.86528871951153 28.625287925196325)))\",\n" + " \"dkfw\": \"MULTIPOLYGON(((115.85261028414699 28.628065910491646,115.85234952636368 28.627469892700983,115.85043542990357 28.628240439727712,115.85050295853954 28.62842805760428,115.85071376127738 28.628739229859185,115.85080329411801 28.628869938164858,115.85261028414699 28.628065910491646)))\",\n" + " \"bz\": null\n" + " },\n" + " {\n" + @@ -135,7 +136,7 @@ " \"dklx\": \"n4\",\n" + " \"dkmc\": \"小桥\",\n" + " \"dkmj\": 20.5,\n" + " \"dkfw\": \"MULTIPOLYGON(((115.86262525992014 28.634623244731678,115.86214341906647 28.63383445340825,115.86164016306374 28.63418423417594,115.86204348170406 28.63485524217979,115.86262525992014 28.634623244731678)))\",\n" + " \"dkfw\": \"MULTIPOLYGON(((115.86528871951153 28.625287925196325,115.86561708513025 28.625787612007546,115.86815834948467 28.624602640426623,115.86773004650362 28.62425999804172,115.86528871951153 28.625287925196325)))\",\n" + " \"bz\": null\n" + " },\n" + " {\n" + @@ -145,7 +146,7 @@ " \"dklx\": \"ndbg2774\",\n" + " \"dkmc\": \"桥头\",\n" + " \"dkmj\": 20.574,\n" + " \"dkfw\": \"MULTIPOLYGON(((115.86528871951153 28.625287925196325,115.86561708513025 28.625787612007546,115.86815834948467 28.624602640426623,115.86773004650362 28.62425999804172,115.86528871951153 28.625287925196325)))\",\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" + @@ -155,28 +156,7 @@ " \"dklx\": \"ndbg2774\",\n" + " \"dkmc\": \"大桥头\",\n" + " \"dkmj\": 20.54,\n" + " \"dkfw\": \"MULTIPOLYGON(((115.84891670917342 28.62884019080562,115.84861068074487 28.628310237250474,115.84801105657137 28.628543424429186,115.84836943314201 28.629060290948733,115.84891670917342 28.62884019080562)))\",\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\": \"MULTIPOLYGON(((115.85261028414699 28.628065910491646,115.85234952636368 28.627469892700983,115.85043542990357 28.628240439727712,115.85050295853954 28.62842805760428,115.85071376127738 28.628739229859185,115.85080329411801 28.628869938164858,115.85261028414699 28.628065910491646)))\",\n" + " \"bz\": null\n" + " }\n" + ",\n" + " {\n" + " \"bsm\": \"177177\",\n" + " \"xzqdm\": \"3\",\n" + " \"dkbh\": \"n1\",\n" + " \"dklx\": \"ndbg2774\",\n" + " \"dkmc\": \"大桥头\",\n" + " \"dkmj\": 20.54,\n" + " \"dkfw\": \"MULTIPOLYGON(((115.85063001998248 28.61939504315339,115.85047227189142 28.619025124342414,115.8490255596 28.6190394011085,115.8491588094162 28.61949625762165,115.84966325514971 28.61989600707048,115.84993419451101 28.620007388652688,115.85063001998248 28.61939504315339)))\",\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" + src/main/java/com/dji/sample/manage/controller/DeviceController.java
@@ -6,6 +6,7 @@ import com.dji.sample.component.mqtt.model.ChannelName; import com.dji.sample.component.mqtt.model.CommonTopicReceiver; import com.dji.sample.component.mqtt.model.CommonTopicResponse; import com.dji.sample.droneairport.service.RegistService; import com.dji.sample.manage.model.dto.DeviceDTO; import com.dji.sample.manage.model.dto.DeviceFirmwareUpgradeDTO; import com.dji.sample.manage.model.enums.DeviceSetPropertyEnum; @@ -32,6 +33,8 @@ @Autowired private IDeviceService deviceService; @Autowired private RegistService registService; /** * Handles the message that the drone goes online. @@ -49,6 +52,9 @@ .timestamp(System.currentTimeMillis()) .method(receiver.getMethod()) .build()); } if (receiver.getData().getSn().length()==14){ registService.Authorization(receiver.getData().getSn()); } } @@ -71,6 +77,9 @@ .build()); } if (receiver.getData().getSn().length()==14){ registService.noAuthorization(receiver.getData().getSn()); } } /** src/main/java/com/dji/sample/media/service/IFileService.java
@@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletResponse; import java.awt.*; import java.io.File; import java.io.IOException; import java.net.URL; import java.util.List; @@ -61,6 +62,7 @@ */ List<MediaFileDTO> getAllFilesByWorkspaceId(String workspaceId); void saveMarkFile(String workspaceId, MediaFileEntity file, 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
@@ -110,7 +110,22 @@ .eq(MediaFileEntity::getFileId, fileId)); return Optional.ofNullable(fileEntity); } public void saveMarkFile(String workspaceId, MediaFileEntity file,File file1) { try { 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.setFileName("mark" + file.getFileName()); mediaFileMarkEntity.setFilePath("mark" + file.getFilePath()); uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), mediaFileMarkEntity.getObjectKey(), file1, "image/jpeg"); markMapper.insert(mediaFileMarkEntity); } catch (Exception e) { e.printStackTrace(); } } @Override public Boolean checkExist(String workspaceId, String fingerprint) { return this.getMediaByFingerprint(workspaceId, fingerprint).isPresent(); @@ -121,6 +136,7 @@ MediaFileEntity fileEntity = this.fileUploadConvertToEntity(file); fileEntity.setWorkspaceId(workspaceId); fileEntity.setFileId(UUID.randomUUID().toString()); //避免对视频处理引发报错 if (file.getObjectKey().endsWith("jpeg")){ fileEntity.setIsadd(0); String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey(); src/main/java/com/dji/sample/media/util/ImgUtil.java
@@ -91,7 +91,16 @@ return null; } } /** * 获取图片的XMP信息 * * @param file 图片文件 * @return 包含图片XMP信息的JSONObject对象 * @throws ImageProcessingException 图像处理异常 * @throws IOException 输入输出异常 */ public static Object getInfo(File file) throws ImageProcessingException, IOException { // 从文件中提取XMP信息 String str =getXmp(file); // 解析 JSON 字符串为 JSON 对象 JSONObject jsonObject = JSON.parseObject(str); @@ -101,15 +110,19 @@ String flightYawDegree = jsonObject.getString("drone-dji:FlightYawDegree"); String flightPitchDegree = jsonObject.getString("drone-dji:FlightPitchDegree"); String gimbalPitchDegree = jsonObject.getString("drone-dji:GimbalPitchDegree"); // 读取图片的XMP信息中的焦距 String mm=readPicExifInfo(file).get("Focal Length 35"); // 构造新的 JSON 对象 JSONObject newJsonObject = new JSONObject(); // 将获取到的信息添加到新的 JSON 对象中 newJsonObject.put("GimbalYawDegree", gimbalYawDegree); newJsonObject.put("FlightYawDegree", flightYawDegree); newJsonObject.put("FlightPitchDegree", flightPitchDegree); newJsonObject.put("GimbalPitchDegree", gimbalPitchDegree); newJsonObject.put("FocalLength", mm); // 返回包含图片XMP信息的JSON对象 return newJsonObject; } } src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java
@@ -82,7 +82,7 @@ LotInfo lotInfo = new LotInfo(); lotInfo.setWorkspaceId(workspaceId); lotInfo.setTaskId(id); lotInfo.setType(1); lotInfo.setType(2); lotInfo.setTaskName(name); lotInfo = dbConvertToEntity(list.get(i), workspaceId, id, name); shpToDataSourceMapper.insert(lotInfo); src/main/java/com/dji/sample/patches/utils/TimerUtil.java
@@ -2,6 +2,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.dji.sample.common.model.CustomClaim; import com.dji.sample.droneairport.dao.DbUploadMapper; import com.dji.sample.droneairport.model.Entity.DbUploadEntity; import com.dji.sample.manage.dao.IDeviceMapper; import com.dji.sample.manage.model.entity.DeviceEntity; import com.dji.sample.media.dao.IFileMapper; @@ -55,6 +57,7 @@ import static com.dji.sample.patches.utils.MultipartFileTOFileUtil.convert; import static com.dji.sample.patches.utils.ZipUtil.zipFolder; import static com.dji.sample.territory.utils.SM3.sm3; import static com.dji.sample.wayline.model.enums.WaylineTaskTypeEnum.TIMED; import static com.dji.sample.wayline.model.enums.WaylineTemplateTypeEnum.WAYPOINT; @@ -82,6 +85,8 @@ private IWaylineJobBreakPointService jobBreakPointService; @Autowired private IDeviceMapper deviceMapper; @Autowired private DbUploadMapper dbUploadMapper; /** * 定时器,将没有规划的图斑生成航线,并将航线飞完后的成果数据进行保存推送 * @@ -252,6 +257,9 @@ String taskId = ""; String dkbh = null; List<List<LotInfo>> lists = convertToLists(getNoPush(workspaceId)); if (lists.isEmpty()){ return; } for (List<LotInfo> lotInfo : lists) { for (LotInfo lotInfo1 : lotInfo) { List<MediaFileEntity> media = getPatchesService.listPohto(lotInfo1.getDkbh(), workspaceId); @@ -279,26 +287,52 @@ 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表 tbFJService.deleteData(); 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到服务器 dbSaveGt(territoryConfigPojo.getResult(), territoryConfigPojo.getResultGtsave(), taskId); 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); } } /** * 创建航线 @@ -378,7 +412,7 @@ public List<List<LotInfo>> getNoPush(String workspaceId) { List<LotInfo> list = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>() .eq(LotInfo::getIsPush, 0) .eq(LotInfo::getType, 1) .eq(LotInfo::getType, 2) .eq(LotInfo::getInvestigate, 1) .eq(LotInfo::getWorkspaceId, workspaceId)); return groupTasks(list); @@ -386,7 +420,7 @@ public List<List<LotInfo>> getNoPush() { List<LotInfo> list = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>() .eq(LotInfo::getIsPush, 0) .eq(LotInfo::getType, 0) .eq(LotInfo::getType, 1) .eq(LotInfo::getInvestigate, 1)); return groupTasks(list); } @@ -691,30 +725,17 @@ throw new RuntimeException("Db文件复制失败", e); // 捕获并抛出原始异常 } } public void dbSaveGt(String path, String folder, String taskId) { String sourceFilePath = path; // 源文件路径 String targetFolderPath = fileFold(folder,taskId).getPath(); // 目标文件夹路径 public String dbSaveGt(String path, String folder, String taskId) { try { // 创建目标文件夹 File targetFolder = new File(targetFolderPath); if (!targetFolder.exists()) { targetFolder.mkdirs(); } // 获取当前时间 LocalDateTime currentTime = LocalDateTime.now(); // 格式化时间,生成文件名 String timeName = currentTime.format(DateTimeFormatter.ofPattern("HHmmss")); String fileName = timeName + "_" + taskId + ".db"; String fileName = taskId + ".db"; // 构建目标文件路径 String targetFilePath = targetFolderPath + File.separator + fileName; String targetFilePath = folder + File.separator + fileName; // 复制文件到目标文件夹 Path sourcePath = Paths.get(sourceFilePath); // 复制文件到目标位置 Path sourcePath = Paths.get(path); Path targetPath = Paths.get(targetFilePath); Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING); return fileName; } catch (IOException e) { throw new RuntimeException("Db文件复制失败", e); // 捕获并抛出原始异常 } @@ -775,6 +796,21 @@ // 将毫秒级时间戳转换为秒级时间戳 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); // 根据传入的hour参数增加小时 LocalDateTime adjustedTime = nextDayEightAM.plusHours(hour); // 转换为时间戳(秒级) ZonedDateTime zonedDateTime = adjustedTime.atZone(ZoneId.systemDefault()); return zonedDateTime.toEpochSecond(); } public static Long addOneHourToTimestamp(Long timestampInSeconds, long hours, long min) { // 将输入的秒级时间戳转换为Instant对象 @@ -821,4 +857,20 @@ // 格式化时间,生成当前时间 return currentTime.format(DateTimeFormatter.ofPattern("MMddHHmmssSSS")); } public static long getFileSize(File file) { if (file == null || !file.exists() || !file.isFile()) { return -1L; // 文件不存在或不是普通文件 } return file.length(); } public static void main(String[] args) { File file = new File("DB/result_db.db"); long size = getFileSize(file); System.out.println("文件大小: " + size + " 字节"); } public static void getFileInfo(File file){ long size=getFileSize(file); } } src/main/java/com/dji/sample/territory/service/ITbFJService.java
@@ -27,5 +27,5 @@ * @param lotInfo * @throws Exception */ void insertOneData(MediaFileEntity mediaFile, LotInfo lotInfo) throws Exception; int insertOneData(MediaFileEntity mediaFile, LotInfo lotInfo) throws Exception; } src/main/java/com/dji/sample/territory/service/impl/TbFjServiceImpl.java
@@ -5,6 +5,7 @@ import com.baomidou.dynamic.datasource.annotation.DS; import com.dji.sample.media.dao.IMarkMapper; import com.dji.sample.media.model.*; import com.dji.sample.media.service.IFileService; import com.dji.sample.media.util.ImgUtil; import com.dji.sample.patches.config.pojo.PatchesConfigPojo; import com.dji.sample.patches.model.entity.LotInfo; @@ -48,7 +49,9 @@ @Autowired private MinioPojo pojo; @Autowired private IMarkMapper markMapper; private IFileService fileService; @Autowired private WaterMarkUtil waterMarkUtil; /** * 按照地块编号所对应的信息和音视频文件存入sqlite数据库 * @@ -72,11 +75,10 @@ return count; } public void insertOneData(MediaFileEntity mediaFile, LotInfo lotInfo) throws Exception { public int insertOneData(MediaFileEntity mediaFile, LotInfo lotInfo) throws Exception { TbFjEntity tbFj = dbConvertToEntity(mediaFile, lotInfo); if (tbFj.getFjysgd() == 3000) { tbFjMapper.insert(tbFj); } return 0; } @Override @@ -141,11 +143,11 @@ //对应图片和视频文件进行不同处理 boolean endsWith = key.endsWith(".mp4"); if (!endsWith) { file1 = WaterMarkUtil.addWatermark(file, sj, lat, lng, gimbalYawDegree); file1 = waterMarkUtil.addWatermark(file, sj, lat, lng, gimbalYawDegree,lotInfo.getType()); byte[] bytesArray = Files.readAllBytes(file1.toPath()); fjhxz= sm3(bytesArray); FJ = fileToByteArray(file1); saveMarkFile(lotInfo.getWorkspaceId(),mediaFile,file1); // fileService.saveMarkFile(lotInfo.getWorkspaceId(),mediaFile,file1); } else { file1 = VideoZipUtil.compressVideo(file, 800000, 128000, 1280, 720); FJ = fileToByteArray(file1); @@ -188,7 +190,7 @@ } /** * 将音视频文件转换成字节流 * 文件下载 * * @param fileUrl * @return @@ -235,23 +237,6 @@ fis.close(); return data; } public void saveMarkFile(String workspaceId, MediaFileEntity file,File file1) { try { 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.setFileName("mark" + file.getFileName()); mediaFileMarkEntity.setFilePath("mark" + file.getFilePath()); uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), mediaFileMarkEntity.getObjectKey(), file1, "image/jpeg"); markMapper.insert(mediaFileMarkEntity); } catch (Exception e) { e.printStackTrace(); } } public static String convertTimestampToDateTime(long timestamp) { // 将时间戳转换为 Instant 对象 Instant instant = Instant.ofEpochMilli(timestamp); src/main/java/com/dji/sample/territory/utils/WaterMarkUtil.java
@@ -1,5 +1,7 @@ package com.dji.sample.territory.utils; import com.dji.sample.media.service.IFileService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.imageio.ImageIO; @@ -12,7 +14,8 @@ import java.util.Date; @Component public class WaterMarkUtil { @Autowired private IFileService fileService; /** * 将图片加上水印并压缩 * @@ -23,7 +26,7 @@ * @return 添加水印并压缩后的图片文件。 * @throws IOException 如果读取或保存图片失败。 */ public static File addWatermark(File file, Long pssj, Double lat, Double lng, Double angles) throws IOException, FontFormatException { public File addWatermark(File file, Long pssj, Double lat, Double lng, Double angles, int type) throws IOException, FontFormatException { double anglses = convertAngle(angles); String angel = angle(anglses); Long timestamp = pssj; // 例如:Unix 时间戳(以秒为单位) @@ -36,12 +39,15 @@ } catch (IOException e) { throw new IllegalArgumentException("读取图片失败" + e.getMessage()); } // fileService.saveMarkFile(lotInfo.getWorkspaceId(),mediaFile,file1); // 创建 Graphics2D 对象以在图像上绘制水印 Graphics2D g2d = originalImage.createGraphics(); // 设置水印文字 "江西调查云" String watermarkText = "江西调查云"; if (type == 1){ watermarkText = "国土调查云"; } float alpha = 0.8f; // 设置透明度为 0.7 AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha); g2d.setComposite(alphaComposite);