| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.dji.sample.common.model.ResponseResult; |
| | | import com.dji.sample.component.redis.RedisOpsUtils; |
| | | import com.dji.sample.droneairport.dao.DbUploadMapper; |
| | | 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; |
| | |
| | | import com.dji.sample.droneairport.utils.SM4Util; |
| | | import com.dji.sample.manage.dao.IDeviceMapper; |
| | | import com.dji.sample.manage.model.entity.DeviceEntity; |
| | | import com.dji.sample.manage.model.enums.DeviceModeCodeEnum; |
| | | import com.dji.sample.manage.model.enums.DockModeCodeEnum; |
| | | import com.dji.sample.manage.model.receiver.OsdDockReceiver; |
| | | import com.dji.sample.manage.model.receiver.OsdSubDeviceReceiver; |
| | | import com.dji.sample.manage.service.IDeviceRedisService; |
| | | import com.dji.sample.patches.dao.GetPatchesMapper; |
| | |
| | | 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.model.enums.WaylineJobStatusEnum; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import org.bouncycastle.crypto.InvalidCipherTextException; |
| | |
| | | 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; |
| | | import java.time.*; |
| | | 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.*; |
| | | |
| | | @Service |
| | | public class RegistServiceImpl implements RegistService { |
| | |
| | | private IWaylineJobMapper waylineJobMapper; |
| | | @Autowired |
| | | private IWaylineFileMapper fileMapper; |
| | | @Autowired |
| | | private DbUploadMapper dbUploadMapper; |
| | | |
| | | 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-lc-token", AuthUtil.getToken()); |
| | | headers.set("x-lc-secret", Utils.hexToBase64(Utils.encrypt("jsimjrby3wqb7dbq", "044D6061FC08A19D3F32CEAA8CF6679B40500008FD741FC26DE7E50AEBF3A9115D47274437730EADEDAEF0CCC4853C5F0B35B30C6AEA83A5F6FBCA4ABEAC9E3B98"))); |
| | | 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); |
| | | // 发送请求 |
| | |
| | | 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("Request failed: " + e.getMessage(), e); |
| | | throw new IllegalArgumentException("无人机机场注册失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | .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 secret = enSM2("jsimjrby3wqb7dbq", "044D6061FC08A19D3F32CEAA8CF6679B40500008FD741FC26DE7E50AEBF3A9115D47274437730EADEDAEF0CCC4853C5F0B35B30C6AEA83A5F6FBCA4ABEAC9E3B98"); |
| | | 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-lc-token", AuthUtil.getToken()); |
| | | headers.set("x-lc-secret", secret); |
| | | |
| | | 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); |
| | | |
| | | // 发送请求 |
| | | RestTemplate restTemplate = new RestTemplate(); |
| | | String response = restTemplate.postForObject("https://xcx.geoway.com.cn:8033/v1/droneAirport/addDevice", requestEntity, String.class); |
| | | registPort(airport); |
| | | return response; |
| | | ResponseEntity<String> response = restTemplate.exchange( |
| | | "https://xcx.geoway.com.cn:8033/v1/droneAirport/addDevice", |
| | | HttpMethod.POST, |
| | | requestEntity, |
| | | String.class); |
| | | 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("Request failed: " + e.getMessage(), e); |
| | | return ("无人机机场设备注册失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public ResponseResult 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); |
| | | String SM2Screct = enSM2(SM4Screct, "23E57DA1E4AB865CCBC325B668762207DEF74345B782237808AE0BABDF26734D"); |
| | | return ResponseResult.success(SM2Screct); |
| | | String SM4Screct = SM4Util.encrypt(key, json); |
| | | Map<String, String> info = new HashMap<>(); |
| | | info.put("text", SM4Screct); |
| | | info.put("serect", secret); |
| | | return info; |
| | | } |
| | | |
| | | // @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 void noAuthorization(String sn) { |
| | | AuthorDto dto = new AuthorDto(); |
| | | dto.setSn(sn); |
| | | dto.setStatus(0); |
| | | String jsonBody = buildRequestBody(dto); |
| | | 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-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( |
| | | "https://xcx.geoway.com.cn:8033/v1/droneAirport/authorization", |
| | | HttpMethod.POST, |
| | | requestEntity, |
| | | String.class); |
| | | } |
| | | |
| | | @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, "无人机机场授权失败!"); |
| | | public void Authorization(String sn) { |
| | | AuthorDto dto = new AuthorDto(); |
| | | dto.setSn(sn); |
| | | dto.setStatus(1); |
| | | String jsonBody = buildRequestBody(dto); |
| | | 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-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( |
| | | "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); |
| | |
| | | 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); |
| | |
| | | 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(getDistinctTaskIdCount(airport.getWorkspaceId())); |
| | | Long time = getAdjustedTimestamp(50); |
| | | List<List<Long>> listOfLists = new ArrayList<>(); |
| | | List<Long> sublist = new ArrayList<>(); |
| | | sublist.add(time); |
| | |
| | | List<Long> lists1 = new ArrayList<>(); |
| | | lists1.add(time); |
| | | String times = TimerUtil.convertTimestampToFormattedString(time); |
| | | param.setWaylineId(taskId); |
| | | timerUtil.sendPostWithParameters(waylineName, waylineFile.getWaylineId(), times, lists1, listOfLists, taskId+"~"+airport.getWorkspaceId(),airport.getDockSn()); |
| | | 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); |
| | | String taskId = addTaskDto.getTaskid(); |
| | | String Bizidname=getBizidnameByTask(taskId); |
| | | String Bizidname = getBizidnameByTask(taskId); |
| | | delPatchesByTaskId(taskId); |
| | | delTaskInfo(taskId); |
| | | delWaylineJob(taskId); |
| | |
| | | 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); |
| | |
| | | WaylineFileEntity waylineFile = timerUtil.backWayline(multipartFile, waylineName, airport.getWorkspaceId(), username); |
| | | |
| | | // 将为规划的图斑状态更新为已规划 |
| | | Long time = getCurrentTimestampPlus8Hours(14); |
| | | Long time = getNextDayEightAMTimestamp(getDistinctTaskIdCount(airport.getWorkspaceId())); |
| | | List<List<Long>> listOfLists = new ArrayList<>(); |
| | | List<Long> sublist = new ArrayList<>(); |
| | | sublist.add(time); |
| | |
| | | List<Long> lists1 = new ArrayList<>(); |
| | | lists1.add(time); |
| | | String times = TimerUtil.convertTimestampToFormattedString(time); |
| | | param.setWaylineId(taskId); |
| | | timerUtil.sendPostWithParameters(waylineName, waylineFile.getWaylineId(), times, lists1, listOfLists, airport.getWorkspaceId()+"~"+taskId,airport.getDockSn()); |
| | | 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 |
| | |
| | | return null; |
| | | } |
| | | |
| | | public void processAndInsertTasks(List<AirportTasks> airportTasks) { |
| | | public void processAndInsertTasks(List<AirportTasks> airportTasks) { |
| | | for (AirportTasks airportTasksEntry : airportTasks) { |
| | | Airport airport = airportTasksEntry.getAirport(); |
| | | List<LotInfo> tasks = airportTasksEntry.getTasks(); |
| | |
| | | |
| | | @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, "查询无人机机场任务状态成功!", "", ""); |
| | | // 检查是否所有 status 都等于 4 |
| | | boolean allStatusAreFour = jobEntity.stream() |
| | | .allMatch(job -> job.getStatus() == 4); |
| | | |
| | | // 检查是否所有 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, "查询无人机机场任务状态成功!"); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private static final String BASE_DIR = "src/main/resources/tmp"; |
| | | |
| | | /** |
| | | * 根据任务 ID 查找对应的 DB 文件路径 |
| | |
| | | * @param taskId 任务 ID |
| | | * @return 匹配的 DB 文件路径列表 |
| | | */ |
| | | public List<String> findDbFilesByTaskId(String taskId) { |
| | | List<String> dbFilePaths = new ArrayList<>(); |
| | | File baseDir = new File(BASE_DIR); |
| | | |
| | | // 检查基础目录是否存在 |
| | | if (!baseDir.exists() || !baseDir.isDirectory()) { |
| | | throw new IllegalStateException("Base directory does not exist or is not a directory."); |
| | | 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); |
| | | 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[] 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 static void main(String[] args) { |
| | | getToken(); |
| | | } |
| | | |
| | | public void delPatchesByTaskId(String taskId) { |
| | | patchesMapper.delete(new LambdaUpdateWrapper<LotInfo>().eq(LotInfo::getTaskId, taskId)); |
| | | } |
| | | |
| | | public void delTaskInfo(String 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>() |
| | |
| | | return entity.getWorkspaceId(); |
| | | } |
| | | |
| | | public String getBizidnameByTask(String taskId){ |
| | | TaskInfo taskInfo= taskInfoMapper.selectOne(new LambdaQueryWrapper<TaskInfo>().eq(TaskInfo::getTaskId, taskId)); |
| | | return taskInfo.getName(); |
| | | public String getBizidnameByTask(String taskId) { |
| | | List<LotInfo> lotInfos = patchesMapper.selectList(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getTaskId, taskId)); |
| | | String taskName = lotInfos.get(0).getTaskName(); |
| | | return taskName; |
| | | } |
| | | |
| | | public static String enSM2(String data, String pubKey) throws InvalidCipherTextException, IOException { |
| | | String encrypt = Utils.encrypt(data, pubKey); |
| | | encrypt = Utils.hexToBase64(encrypt); |
| | |
| | | String hex = Utils.convertBase64ToHex(Base64); |
| | | return Utils.decrypt(hex, priKey); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public static Map<String, String> createKey() throws NoSuchAlgorithmException { |
| | |
| | | return builder.build(); |
| | | } |
| | | |
| | | public String getDroneFromCache(String sn) { |
| | | public OsdSubDeviceReceiver getDroneFromCache(String sn) { |
| | | String key = "osd:" + sn; |
| | | return RedisOpsUtils.get(key).toString(); |
| | | return (OsdSubDeviceReceiver) RedisOpsUtils.get(key); |
| | | } |
| | | |
| | | public void delWaylineJob(String taskId) { |
| | | waylineJobMapper.delete(new LambdaQueryWrapper<WaylineJobEntity>().like(WaylineJobEntity::getJobId, taskId)); |
| | | } |
| | | |
| | | public DroneStateDto getAirportFromCache(String deviceId) { |
| | | String receiver = getDroneFromCache(deviceId); |
| | | double gimbalYaw =0.0; |
| | | double gimbalPitch=0.0; |
| | | com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(receiver); |
| | | double latitude = jsonObject.getDoubleValue("latitude"); |
| | | double longitude = jsonObject.getDoubleValue("longitude"); |
| | | int modeCode = jsonObject.getInteger("mode_code"); |
| | | double elevation = jsonObject.getDoubleValue("elevation"); |
| | | double height = jsonObject.getDoubleValue("height"); |
| | | com.alibaba.fastjson.JSONArray payloads = jsonObject.getJSONArray("payloads"); |
| | | if (payloads != null && payloads.size() > 1) { |
| | | com.alibaba.fastjson.JSONArray payloadArray = payloads.getJSONArray(1); |
| | | for (int i = 0; i < payloadArray.size(); i++) { |
| | | com.alibaba.fastjson.JSONObject payload = payloadArray.getJSONObject(i); |
| | | gimbalYaw = payload.getDoubleValue("gimbal_yaw"); |
| | | gimbalPitch = payload.getDoubleValue("gimbal_pitch"); |
| | | Optional<OsdSubDeviceReceiver> deviceOsdOpt = redisService.getDeviceOsd(deviceId, OsdSubDeviceReceiver.class); |
| | | boolean result = deviceOsdOpt.isPresent(); |
| | | if (!result) { |
| | | String sn = deviceMapper.selectOne(new LambdaQueryWrapper<DeviceEntity>().eq(DeviceEntity::getChildSn, deviceId)).getDeviceSn(); |
| | | Optional<OsdDockReceiver> dockOsdOpt = redisService.getDeviceOsd(sn, OsdDockReceiver.class); |
| | | boolean results = dockOsdOpt.isPresent(); |
| | | if (!results) { |
| | | DroneStateDto.DroneStateDtoBuilder builder = DroneStateDto.builder(); |
| | | builder.gimbalYaw(0.0) |
| | | .gimbalPitch(0.0) |
| | | .batteryCapacityPercent(0) |
| | | .height(0) |
| | | .latitude(0) |
| | | .longitude(0) |
| | | .modeCode(1) |
| | | .elevation(0.0) |
| | | .gpsState(0) |
| | | .build(); |
| | | return builder.build(); |
| | | } |
| | | OsdDockReceiver osdDockReceiver = objectMapper.convertValue(dockOsdOpt.get(), OsdDockReceiver.class); |
| | | int mode; |
| | | int sne = osdDockReceiver.getModeCode().getVal(); |
| | | if (sne == 0) { |
| | | mode = 0; |
| | | } else { |
| | | mode = 2; |
| | | } |
| | | DroneStateDto.DroneStateDtoBuilder builder = DroneStateDto.builder(); |
| | | builder.gimbalYaw(0.0) |
| | | .gimbalPitch(0.0) |
| | | .batteryCapacityPercent(osdDockReceiver.getDroneChargeState().getCapacityPercent()) |
| | | .height(osdDockReceiver.getHeight()) |
| | | .latitude(osdDockReceiver.getLatitude()) |
| | | .longitude(osdDockReceiver.getLongitude()) |
| | | .modeCode(mode) |
| | | .elevation(0.0) |
| | | .gpsState(2) |
| | | .build(); |
| | | return builder.build(); |
| | | } |
| | | com.alibaba.fastjson.JSONObject battery = jsonObject.getJSONObject("battery"); |
| | | int batteryCapacityPercent = battery.getInteger("capacity_percent"); |
| | | OsdSubDeviceReceiver receiver = objectMapper.convertValue(deviceOsdOpt.get(), OsdSubDeviceReceiver.class); |
| | | DroneStateDto.DroneStateDtoBuilder builder = DroneStateDto.builder(); |
| | | |
| | | builder.gimbalYal(gimbalYaw) |
| | | .gimbalPitch(gimbalPitch) |
| | | .batteryCapacityPercent(batteryCapacityPercent) |
| | | .height(height) |
| | | .latitude(latitude) |
| | | .longitude(longitude) |
| | | .modeCode(modeCode) |
| | | .elevation(elevation) |
| | | .gpsState(3); |
| | | |
| | | builder.gimbalYaw(receiver.getPayloads().get(0).getGimbalYaw()) |
| | | .gimbalPitch(receiver.getPayloads().get(0).getGimbalPitch()) |
| | | .batteryCapacityPercent(receiver.getBattery().getCapacityPercent()) |
| | | .height(receiver.getHeight()) |
| | | .latitude(receiver.getLatitude()) |
| | | .longitude(receiver.getLongitude()) |
| | | .modeCode(2) |
| | | .elevation(receiver.getElevation()) |
| | | .gpsState(2) |
| | | .build(); |
| | | return builder.build(); |
| | | } |
| | | |
| | | |
| | | public static AddTaskDto jsonToDto(JSONObject jsonObject) { |
| | | AddTaskDto dto = new AddTaskDto(); |
| | |
| | | for (String sn : snList) { |
| | | DeviceExpanSionEntity entity = entityMap.get(sn); |
| | | if (entity != null) { |
| | | DeviceEntity deviceEntity = deviceMapper.selectOne(new LambdaQueryWrapper<DeviceEntity>().eq(DeviceEntity::getChildSn,sn)); |
| | | Airport airport = new Airport(entity.getWorkspaceId(),deviceEntity.getDeviceSn(),entity.getLatitude(), entity.getLongitude()); |
| | | DeviceEntity deviceEntity = deviceMapper.selectOne(new LambdaQueryWrapper<DeviceEntity>().eq(DeviceEntity::getChildSn, sn)); |
| | | Airport airport = new Airport(entity.getWorkspaceId(), deviceEntity.getDeviceSn(), entity.getLatitude(), entity.getLongitude()); |
| | | airports.add(airport); |
| | | } |
| | | } |
| | |
| | | // 执行更新操作 |
| | | taskInfoMapper.update(taskInfo, updateWrapper); |
| | | } |
| | | |
| | | public void updateJob(String jobid, String waylineId) { |
| | | LambdaUpdateWrapper<WaylineJobEntity> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.eq(WaylineJobEntity::getJobId, jobid) |
| | |
| | | // 调用 update 方法进行更新操作 |
| | | waylineJobMapper.update(null, updateWrapper); |
| | | } |
| | | |
| | | /** |
| | | * 统计给定工作空间下,创建时间为当天的不同 taskId 的数量。 |
| | | * |
| | | * @param workspaceId 工作空间 ID |
| | | * @return 不同 taskId 的数量 |
| | | */ |
| | | public Integer getDistinctTaskIdCount(String workspaceId) { |
| | | // 获取当前日期的开始和结束时间 |
| | | LocalDate today = LocalDate.now(); |
| | | LocalDateTime startTime = today.atStartOfDay(); |
| | | LocalDateTime endTime = today.plusDays(1).atStartOfDay(); |
| | | |
| | | // 转换为毫秒时间戳 |
| | | long startTimestamp = startTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
| | | long endTimestamp = endTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); |
| | | |
| | | // 使用 LambdaQueryWrapper 进行查询 |
| | | LambdaQueryWrapper<LotInfo> queryWrapper = Wrappers.lambdaQuery(); |
| | | queryWrapper.eq(LotInfo::getWorkspaceId, workspaceId) |
| | | .ge(LotInfo::getCreateTime, startTimestamp) |
| | | .lt(LotInfo::getCreateTime, endTimestamp); |
| | | |
| | | // 获取符合条件的所有 taskId |
| | | Set<String> taskIdSet = patchesMapper.selectList(queryWrapper).stream() |
| | | .map(LotInfo::getTaskId) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | // 返回不同 taskId 的数量 |
| | | return taskIdSet.size(); |
| | | } |
| | | |
| | | |
| | | } |