diff --git a/src/main/java/com/uva/DataCenterApplication.java b/src/main/java/com/uva/DataCenterApplication.java index 0a97ee85080c810317f916e78a1c32160399193d..29643397d2ad5a46d48c682e950d069e88314397 100644 --- a/src/main/java/com/uva/DataCenterApplication.java +++ b/src/main/java/com/uva/DataCenterApplication.java @@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.scheduling.annotation.EnableAsync; - +import org.springframework.scheduling.annotation.EnableScheduling; import java.awt.*; /** @@ -17,6 +17,7 @@ import java.awt.*; @SpringBootApplication @MapperScan({"com.uva.**.mapper"}) @EnableAsync +@EnableScheduling // 启用定时任务支持 public class DataCenterApplication extends SpringBootServletInitializer { public static void main(String[] args) { diff --git a/src/main/java/com/uva/api/task/TaskService.java b/src/main/java/com/uva/api/task/TaskService.java index 934e905cfe54859fb9e9d9c3591ed97e8aa0dcf7..09081642f820130f15443c792a2b5e9b9d2abb8e 100644 --- a/src/main/java/com/uva/api/task/TaskService.java +++ b/src/main/java/com/uva/api/task/TaskService.java @@ -208,7 +208,7 @@ public class TaskService { public String execDisTask(String projectId, String inputPath) { PropertiesUtil propertiesUtil = new PropertiesUtil(); - log.info("任务识别开始。"); + log.info("任务识别开始!!!!!"); String sep = "/|\\\\"; String[] sourcePaths = inputPath.split(sep); String taskId = sourcePaths[sourcePaths.length - 2]; @@ -235,131 +235,137 @@ public class TaskService { param.put("videoPath", targetVideoFile); // wensilin 2024-12-01 param.put("model_type", model_type); - String result = HttpUtil.sendPostUrl(url, param); - JSONObject resultJson = JSONObject.parseObject(result); - List> dataList = new ArrayList>(); - int code = resultJson.getInteger("code"); + try{ + String result = HttpUtil.sendPostUrl(url, param); + JSONObject resultJson = JSONObject.parseObject(result); + List> dataList = new ArrayList>(); + int code = resultJson.getInteger("code"); // int code = 200; - if (500 == code) { - String message = resultJson.getString("message"); - taskMapper.updateDistResultMessage(infoId, message); - } else { - FileInputStream fis = null; - try { - log.info("程序开始等待一分钟..."); - Thread.sleep(60 * 1000); // 等待一分钟,1分钟 = 60秒,每秒等待1000毫秒 - log.info("一分钟已过,程序继续执行。"); - } catch (InterruptedException e) { - e.printStackTrace(); - } + if (500 == code) { + String message = resultJson.getString("message"); + taskMapper.updateDistResultMessage(infoId, message); + } else { + FileInputStream fis = null; + try { + log.info("程序开始等待一分钟..."); + Thread.sleep(60 * 1000); // 等待一分钟,1分钟 = 60秒,每秒等待1000毫秒 + log.info("一分钟已过,程序继续执行。"); + } catch (InterruptedException e) { + e.printStackTrace(); + } - try { - log.info("更新任务表:" + infoId + ";" + targetFile); - taskMapper.updateDistResult(infoId, targetFile); + try { + log.info("更新任务表:" + infoId + ";" + targetFile); + taskMapper.updateDistResult(infoId, targetFile); // targetFile = "D:\\mnt\\202403281606.json"; - log.info("识别算法解析json开始"); - fis = new FileInputStream(targetFile); - String data = IOUtils.toString(fis, "UTF-8"); - JSONObject jsonObject = JSONObject.parseObject(data); - JSONArray jsonArray = jsonObject.getJSONArray("results"); - int len = jsonArray.size(); - for (int i = 0; i < len; i++) { - JSONObject js = jsonArray.getJSONObject(i); - String fileDir = js.getString("file_path"); - JSONArray js1 = js.getJSONArray("correct_results"); - Map map = new HashMap<>(); - int len1 = js1.size(); - for (int j = 0; j < len1; j++) { - JSONObject js2 = js1.getJSONObject(j); - JSONObject js3 = js2.getJSONObject("datas"); - String picName = js2.getString("image_name"); - JSONObject bboxObject = js3.getJSONObject("bbox"); - String bbox = formatOne(bboxObject.getString("[x1][y1]")) + "," + formatOne(bboxObject.getString("[x2][y2]")) + "," - + formatOne(bboxObject.getString("[x3][y3]")) + "," + formatOne(bboxObject.getString("[x4][y4]")); - String type = js3.getString("class_name"); - String area = js3.getString("area"); - String key = picName + ";" + type; - if (map.containsKey(key)) { - String[] box = map.get(key).split("-"); - map.put(key, box[0] + ";" + bbox + "-" + box[1]); - } else { - map.put(key, bbox + "-" + area); + log.info("识别算法解析json开始"); + fis = new FileInputStream(targetFile); + String data = IOUtils.toString(fis, "UTF-8"); + JSONObject jsonObject = JSONObject.parseObject(data); + JSONArray jsonArray = jsonObject.getJSONArray("results"); + int len = jsonArray.size(); + for (int i = 0; i < len; i++) { + JSONObject js = jsonArray.getJSONObject(i); + String fileDir = js.getString("file_path"); + JSONArray js1 = js.getJSONArray("correct_results"); + Map map = new HashMap<>(); + int len1 = js1.size(); + for (int j = 0; j < len1; j++) { + JSONObject js2 = js1.getJSONObject(j); + JSONObject js3 = js2.getJSONObject("datas"); + String picName = js2.getString("image_name"); + JSONObject bboxObject = js3.getJSONObject("bbox"); + String bbox = formatOne(bboxObject.getString("[x1][y1]")) + "," + formatOne(bboxObject.getString("[x2][y2]")) + "," + + formatOne(bboxObject.getString("[x3][y3]")) + "," + formatOne(bboxObject.getString("[x4][y4]")); + String type = js3.getString("class_name"); + String area = js3.getString("area"); + String key = picName + ";" + type; + if (map.containsKey(key)) { + String[] box = map.get(key).split("-"); + map.put(key, box[0] + ";" + bbox + "-" + box[1]); + } else { + map.put(key, bbox + "-" + area); + } + } + for (Map.Entry set : map.entrySet()) { + Map dataMap = new HashMap<>(); + String key = set.getKey(); + String[] keyValues = key.split(";"); + String[] bbox = set.getValue().split("-"); + dataMap.put("PIC_NAME", keyValues[0]); + dataMap.put("B_BOX", bbox[0]); + dataMap.put("TYPE_NAME", keyValues[1]); + dataMap.put("AREA", bbox[1]); + dataList.add(dataMap); } } - for (Map.Entry set : map.entrySet()) { - Map dataMap = new HashMap<>(); - String key = set.getKey(); - String[] keyValues = key.split(";"); - String[] bbox = set.getValue().split("-"); - dataMap.put("PIC_NAME", keyValues[0]); - dataMap.put("B_BOX", bbox[0]); - dataMap.put("TYPE_NAME", keyValues[1]); - dataMap.put("AREA", bbox[1]); - dataList.add(dataMap); + log.info("识别算法解析json开始"); + } catch (Exception e) { + log.error("识别算法解析失败:" + e.getMessage()); + } finally { + if (null != fis) { + try { + fis.close(); + } catch (IOException e) { + } } } - log.info("识别算法解析json开始"); - } catch (Exception e) { - log.error("识别算法解析失败:" + e.getMessage()); - } finally { - if (null != fis) { - try { - fis.close(); - } catch (IOException e) { - } + log.info("识别结果入库:" + dataList.size()); + int size = dataList.size(); + if (size == 0) { + return "no result"; } + taskMapper.addDistrbute(infoId, dataList); + taskMapper.addVideo(projectId, taskId, targetVideoFile); + + String projectName = taskMapper.getProjectName(projectId); + Task task = new Task(); + task.setProjectName(projectName); + task.setProjectId(projectId); +// task.setTaskName(taskName); + task.setTaskId(taskId); + task.setDateTime(time); + sendWebSocket(task); } - log.info("识别结果入库:" + dataList.size()); - int size = dataList.size(); - if (size == 0) { - return "no result"; + log.info("任务识别结束!!!!!"); + + log.info("实时对比开始!!!!!"); + Map currentTaskMap = taskMapper.getTaskInfoById(infoId); + String lineName = currentTaskMap.get("line_name").toString().trim(); + Map taskMap = taskMapper.getIdByProjectId(projectId, lineName); + int baseId = Integer.parseInt(taskMap.get("id") + ""); + if (baseId == infoId) { + log.info("没有基任务,实时对比结束"); + return "sucessful"; } - taskMapper.addDistrbute(infoId, dataList); - taskMapper.addVideo(projectId, taskId, targetVideoFile); + String wordPath = targetProductPath + File.separator + "dist" + File.separator + "word"; + File wordFile = new File(wordPath); + if (!wordFile.exists()) { + wordFile.mkdirs(); + } + compareTask(infoId, baseId, targetFile, taskMap.get("dis_path") + ""); + String fileName = wordPath + File.separator + infoId + "-" + baseId + ".docx"; + XWPFDocument document = null; + String resultWord = pointService.writeToWord(document, fileName, infoId, baseId); + if ("".equals(resultWord)) { - String projectName = taskMapper.getProjectName(projectId); - Task task = new Task(); - task.setProjectName(projectName); - task.setProjectId(projectId); -// task.setTaskName(taskName); - task.setTaskId(taskId); - task.setDateTime(time); - sendWebSocket(task); - } - log.info("任务识别结束。"); - - log.info("实时对比开始:"); - Map currentTaskMap = taskMapper.getTaskInfoById(infoId); - String lineName = currentTaskMap.get("line_name").toString().trim(); - Map taskMap = taskMapper.getIdByProjectId(projectId, lineName); - int baseId = Integer.parseInt(taskMap.get("id") + ""); - if (baseId == infoId) { - log.info("没有基任务,实时对比结束"); - return "sucessful"; - } - String wordPath = targetProductPath + File.separator + "dist" + File.separator + "word"; - File wordFile = new File(wordPath); - if (!wordFile.exists()) { - wordFile.mkdirs(); - } - compareTask(infoId, baseId, targetFile, taskMap.get("dis_path") + ""); - String fileName = wordPath + File.separator + infoId + "-" + baseId + ".docx"; - XWPFDocument document = null; - String resultWord = pointService.writeToWord(document, fileName, infoId, baseId); - if ("".equals(resultWord)) { + } else { + pointMapper.addWordProduct(infoId, baseId, fileName, projectId, time + "00", taskMap.get("ddatetime") + ""); + } - } else { - pointMapper.addWordProduct(infoId, baseId, fileName, projectId, time + "00", taskMap.get("ddatetime") + ""); - } + try { + if (null != document) { + document.close(); + } + } catch (Exception e) { - try { - if (null != document) { - document.close(); } - } catch (Exception e) { - + log.info("实时对比结束!!!!!"); + }catch (Exception e){ + log.error("算法服务运行失败:" + e.toString()); + return "fail"; } - log.info("实时对比结束"); + // return "sucessful"; } diff --git a/src/main/java/com/uva/api/util/TimeUtil.java b/src/main/java/com/uva/api/util/TimeUtil.java index 4e6453718b39a9c903b23c078bfcd9e1a60608fa..4b5e19a798f0661d2f1003b33ca1902997997021 100644 --- a/src/main/java/com/uva/api/util/TimeUtil.java +++ b/src/main/java/com/uva/api/util/TimeUtil.java @@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -415,4 +416,24 @@ public class TimeUtil { } return time; } + + /** + * 将给定的日期时间字符串转换为自定义的无分隔符格式。 + * + * @param dateTimeStr 要转换的日期时间字符串 + * @return 转换后的无分隔符日期时间字符串 + */ + public static String convertDateTimeToCustomFormat(String dateTimeStr) { + // 定义原始日期时间格式 + DateTimeFormatter originalFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSX"); + // 定义目标日期时间格式(无分隔符,24小时制) + DateTimeFormatter targetFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmm"); + // 解析原始日期时间字符串 + // 解析字符串为 ZonedDateTime + ZonedDateTime zonedDateTime = ZonedDateTime.parse(dateTimeStr); + +// LocalDateTime dateTimeParsed = LocalDateTime.parse(dateTime, originalFormatter); + // 格式化日期时间为目标格式 + return zonedDateTime.format(targetFormatter); + } } diff --git a/src/main/java/com/uva/api/uvadata/UVADataScheduledTask.java b/src/main/java/com/uva/api/uvadata/UVADataScheduledTask.java new file mode 100644 index 0000000000000000000000000000000000000000..3ffc0840c546cb2902489a435336e987115904d0 --- /dev/null +++ b/src/main/java/com/uva/api/uvadata/UVADataScheduledTask.java @@ -0,0 +1,60 @@ +package com.uva.api.uvadata; +import com.alibaba.fastjson.JSONObject; +import com.uva.api.util.HttpUtil; +import com.uva.api.util.PropertiesUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +@Service +@Slf4j +public class UVADataScheduledTask { + @Resource + private WebhookHandler webhookHandler; + private boolean isRunning = false; + // 每隔 2 分钟执行一次 //120000 + @Scheduled(initialDelay = 10000, fixedRate = 120000) + public void uvaDataStreamTask() { + // 1.请求任务信息数据 + if (!isRunning){ + try{ + // 读取配置文件中接口的url + PropertiesUtil propertiesUtil = new PropertiesUtil(); + String url = propertiesUtil.getProperty("taskMessageInfo"); + log.info("任务流请求URL:" + url); + // 执行任务数据流 + String result = HttpUtil.sendGetUrl(url); + JSONObject resultJson = JSONObject.parseObject(result); + int code = resultJson.getInteger("code"); + if (0 == code) { + // 处理结果 + JSONObject data_info = resultJson.getJSONObject("data"); + if (data_info == null || data_info.isEmpty()){ + log.info("未查询到无人机飞行的任务和采集的图片数据!"); + return; + } + // 设置正在运行 + isRunning = true; + // 执行任务数据流 + if (webhookHandler.processUVAMsg(data_info)) { + JSONObject taskDataInfo = data_info.getJSONObject("task"); + JSONObject waylineInfo = taskDataInfo.getJSONObject("wayline"); + String wayLineName = waylineInfo.getString("name"); + log.info("任务流数据处理完成!" + wayLineName); + } + } else { + // 不处理结果 + log.info("任务流请求失败,这URL是:" + url); + } + }catch (Exception e){ + log.error("任务流请求URL:" + e,toString()); + } + // 切换未运行状态 + isRunning = false; + } else{ + log.info("数据流任务正在运行, 请稍后重试!"); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/uva/api/uvadata/WebhookHandler.java b/src/main/java/com/uva/api/uvadata/WebhookHandler.java index aae064187ddea98bc85650d663c5491494147b85..206b0482946eec3cdd7c9e90471c7577b35850ac 100644 --- a/src/main/java/com/uva/api/uvadata/WebhookHandler.java +++ b/src/main/java/com/uva/api/uvadata/WebhookHandler.java @@ -13,11 +13,13 @@ import com.aliyun.oss.model.GetObjectRequest; import com.google.common.collect.Lists; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; +import com.sun.org.apache.xpath.internal.operations.Bool; import com.uva.api.entity.Task; import com.uva.api.task.TaskService; import com.uva.api.task.mapper.TaskMapper; import com.uva.api.util.ImageUtil; import com.uva.api.util.PropertiesUtil; +import com.uva.api.util.TimeUtil; import com.uva.api.uvadata.mapper.UvaDataMapper; import lombok.extern.slf4j.Slf4j; import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; @@ -52,7 +54,9 @@ public class WebhookHandler implements HttpHandler { public static String taskName; - public void handle (HttpExchange exchange) { + private PropertiesUtil propertiesUtil; + + public void handle(HttpExchange exchange) { String method = exchange.getRequestMethod(); if (method.contains("GET")) { @@ -105,7 +109,7 @@ public class WebhookHandler implements HttpHandler { public String processMsg(String msg1, String msg2) { List> dataList = new ArrayList>(); - PropertiesUtil propertiesUtil = new PropertiesUtil(); + propertiesUtil = new PropertiesUtil(); String endpoint = propertiesUtil.getProperty("endPoint"); String bucketName = propertiesUtil.getProperty("bucketName"); String ossId = propertiesUtil.getProperty("OSS_ACCESS_KEY_ID"); @@ -202,7 +206,7 @@ public class WebhookHandler implements HttpHandler { dataList.add(dataMap); } } - }catch (Exception e) { + } catch (Exception e) { log.error(e.toString()); return "fail received callback"; } finally { @@ -266,6 +270,214 @@ public class WebhookHandler implements HttpHandler { return response; } + public boolean processUVAMsg(JSONObject data) { + // 解析uva_data info + propertiesUtil = new PropertiesUtil(); + JSONObject uvaDataInfo = data.getJSONObject("uva_data"); + JSONObject taskDataInfo = data.getJSONObject("task"); + // 如果data中不包含此类信息 + if(uvaDataInfo.isEmpty() || taskDataInfo.isEmpty()) + return false; + String timeStr = getUVADataRecieveTime(uvaDataInfo); + if (timeStr.equals("")) + return false; + // + String projectId = uvaDataInfo.getString("prj_id"); + // task_info + JSONObject taskInfo = uvaDataInfo.getJSONObject("task_info"); + String taskId = taskInfo.getString("task_id"); + String taskType = taskInfo.getString("task_type"); + if ("way_line".equals(taskType)) { + taskType = "计划任务"; + } + // 继续下载数据判断并入库 + int id = uvaDataMapper.isExistLineTask(projectId, taskId); + Integer maxId = uvaDataMapper.getMaxId(); + if (null == maxId) { + maxId = -1; + } + // 表示数据库中不存在当前任务的信息 + String dataSource = propertiesUtil.getProperty("targetDataPath"); + String tarPath = dataSource + File.separator + taskId + File.separator + timeStr; + // + if (id == 0) { + // 下载数据 + List filenames = new ArrayList(); + List> dataList = new ArrayList>(); + if (processUVAData(taskId, tarPath, uvaDataInfo, filenames, dataList)) { + log.info("文件下载完成:" + dataList.size()); + long size = getDirectorySize(tarPath); + float dirSize = size / (1024f * 1024f * 1024f); + Collections.sort(filenames); + int fileListSize = filenames.size(); + // 计算飞行数据采集的时长 + float time_diff = timeDiff(filenames.get(0).split("_")[1], + filenames.get(fileListSize - 1).split("_")[1]); + // 航线名称 + String taskName = taskDataInfo.getString("name"); + String hangar_name = taskDataInfo.getString("hangar_name"); + // 解析航线信息 + JSONObject waylineInfo = taskDataInfo.getJSONObject("wayline"); + String wayLineName = waylineInfo.getString("name"); + //其他信息 + String orgId = uvaDataInfo.getString("org_id"); + String orgName = uvaDataInfo.getString("org_name"); + maxId = maxId + 1; + log.info("最大任务ID:" + maxId); + Task task = new Task(); + String dataTime = timeStr + "00"; + task.setDateTime(dataTime); + task.setOrgId(orgId); + task.setOrgName(orgName); + task.setProjectId(projectId); + task.setProjectName(hangar_name); + task.setLineName(wayLineName); + task.setTaskId(taskId); + task.setTaskName(taskName); + task.setTaskType(taskType); + task.setFilePath(tarPath); + task.setFlightDuration(time_diff); + task.setDirSize(dirSize); + + try { + log.info("程序开始等待一分钟..."); + Thread.sleep(60 * 1000); // 等待一分钟,1分钟 = 60秒,每秒等待1000毫秒 + log.info("一分钟已过,程序继续执行。"); + } catch (InterruptedException e) { + e.printStackTrace(); + } + //入航线任务表 + uvaDataMapper.addLineTaskInfo(maxId, task); + log.info("任务入库完成。"); + //源数据入库 + List>> groupLists = Lists.partition(dataList, 30); + for (List> groupList : groupLists) { + uvaDataMapper.addUvaData(maxId, groupList); + } + log.info("数据入库完成。"); + //数据识别 + taskService.execDisTask(projectId, tarPath); + log.info("任务识别入库完成。"); + } + } else { + //数据识别 + taskService.execDisTask(projectId, tarPath); + log.info("任务识别入库完成。"); + } + // + return true; + } + + private boolean processUVAData(String taskId, + String tarPath, + JSONObject uva_data, + List filenames, + List> dataList) { + String endpoint = propertiesUtil.getProperty("endPoint"); + String bucketName = propertiesUtil.getProperty("bucketName"); + String ossId = propertiesUtil.getProperty("OSS_ACCESS_KEY_ID"); + String ossSecret = propertiesUtil.getProperty("OSS_ACCESS_KEY_SECRET"); + //EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider(); + //OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider); + OSS ossClient = new OSSClientBuilder().build(endpoint, ossId, ossSecret); + // 解析文件地址信息 + JSONObject folderInfo = uva_data.getJSONObject("folder_info"); + int count = Integer.parseInt(folderInfo.getString("uploaded_file_count")); + JSONArray fileData = uva_data.getJSONArray("files"); + // 返回状态 + boolean bSuccessed = false; + try { + String dataSource = propertiesUtil.getProperty("targetDataPath"); + for (int i = 0; i < count; i++) { + JSONObject fileInfo = fileData.getJSONObject(i); + String key = fileInfo.getString("key"); + String[] path = key.split("\\/"); + int len = path.length; + if (len <= 2) { + continue; + } + // 判断文件类型 + String fileName = path[len - 1]; + if (fileName.endsWith("mp4")) { + String targetPath = dataSource + File.separator + taskId + File.separator + fileName; + //下载视频 + downloadFile(key, targetPath, bucketName, ossClient); + List fileNames = taskService.map4ToJPG(targetPath, tarPath); + Collections.sort(fileNames); + for (int file_index = 0, file_count = fileNames.size(); file_index < file_count; ++file_index) { + File fileNew = new File(fileNames.get(file_index)); + String newFileName = fileNew.getName(); + filenames.add(newFileName); + Map dataMap = new HashMap(); + dataMap.put("FILE_NAME", newFileName); + dataMap.put("CREATE_TIME", null); + dataMap.put("LON", null); + dataMap.put("LAT", null); + dataMap.put("ALTITUDE", null); + dataMap.put("DEGREE", null); + dataMap.put("ORDER", file_index + 1); + dataList.add(dataMap); + } + } else { + int file_type = fileInfo.getInteger("file_type"); + // file_type 表示图片, 12表示Data数据 + if (file_type == 10) { + String targetPath = tarPath + File.separator + fileName; + File targetFile = new File(targetPath); + if (!targetFile.exists()) { + //下载图片 + downloadFile(key, targetPath, bucketName, ossClient); + } + filenames.add(fileName); + String[] fileNames = fileName.split("_"); + Map dataMap = new HashMap(); + dataMap.put("FILE_NAME", fileName); + ImageUtil util = new ImageUtil(); + String[] latlonInfo = util.getImageParm(targetPath); + dataMap.put("CREATE_TIME", latlonInfo[4]); + dataMap.put("LON", Double.parseDouble(latlonInfo[2])); + dataMap.put("LAT", Double.parseDouble(latlonInfo[1])); + dataMap.put("ALTITUDE", Double.parseDouble(latlonInfo[3])); + dataMap.put("DEGREE", Double.parseDouble(latlonInfo[0])); + dataMap.put("ORDER", Integer.parseInt(fileNames[2])); + dataList.add(dataMap); + } else if (file_type == 12) { + continue; + } + } + } + // + bSuccessed = true; + } catch (Exception e) { + log.error(e.toString()); + } finally { + if (null != ossClient) { + ossClient.shutdown(); + } + } + // + return bSuccessed; + } + + private String getUVADataRecieveTime(JSONObject uva_data){ + JSONObject folderInfo = uva_data.getJSONObject("folder_info"); + int count = Integer.parseInt(folderInfo.getString("uploaded_file_count")); + if (count > 0){ + JSONArray fileData = uva_data.getJSONArray("files"); + JSONObject fileInfo = fileData.getJSONObject(0); + String key = fileInfo.getString("key"); + String[] path = key.split("\\/"); + int len = path.length; + if (len <= 2) { + return ""; + } + // 获取文件的拍摄日期 + String taskTimeStr = path[len - 2].substring(4, 16); + return taskTimeStr; + } + // 返回文件的接收时间 + return ""; + } public long getDirectorySize(String directoryPath) { Path path = Paths.get(directoryPath); @@ -294,7 +506,7 @@ public class WebhookHandler implements HttpHandler { Date date1 = sdf.parse(time1); Date date2 = sdf.parse(time2); long diff = date2.getTime() - date1.getTime(); - float t = diff /(60 * 1000f); + float t = diff / (60 * 1000f); return t; } catch (Exception e) { @@ -302,7 +514,7 @@ public class WebhookHandler implements HttpHandler { return 0; } - public void downloadFile(String key, String path, String bucketName,OSS ossClient) { + public void downloadFile(String key, String path, String bucketName, OSS ossClient) { File filePath = new File(path); File parentPath = filePath.getParentFile(); if (!parentPath.exists()) { @@ -311,7 +523,7 @@ public class WebhookHandler implements HttpHandler { ossClient.getObject(new GetObjectRequest(bucketName, key), filePath); } - public List downloadVideoFile(String key, String path, String picturePath, String bucketName,OSS ossClient) { + public List downloadVideoFile(String key, String path, String picturePath, String bucketName, OSS ossClient) { List filenames = new ArrayList(); File videoFile = new File(path); String[] videoNames = videoFile.getName().split("\\.")[0].split("_"); @@ -337,7 +549,7 @@ public class WebhookHandler implements HttpHandler { for (long i = 0; i < delayedTime; i++) { String style1 = String.format(style, i * 1000, width, height); // 指定过期时间为10分钟。 - Date expiration = new Date(new Date().getTime() + 1000 * 60 * 10 ); + Date expiration = new Date(new Date().getTime() + 1000 * 60 * 10); GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucketName, key, HttpMethod.GET); req.setExpiration(expiration); req.setProcess(style1); diff --git a/src/main/java/com/uva/config/websocket/WebSocketClientConfig.java b/src/main/java/com/uva/config/websocket/WebSocketClientConfig.java index e073fd9626dc138980bcbc235621c37142596ba5..7274f0ddbe48a93e27719c7bd415a74f2430e4e6 100644 --- a/src/main/java/com/uva/config/websocket/WebSocketClientConfig.java +++ b/src/main/java/com/uva/config/websocket/WebSocketClientConfig.java @@ -75,14 +75,14 @@ public class WebSocketClientConfig{ JSONObject jsonObject = JSONObject.parseObject(s); int msg_type = jsonObject.getInteger("msg_type"); if (0 == msg_type) { - log.info("接收心跳, 直播状态:" + liveService.liveStatus); - Date currentDate = new Date(); - long interval = HEARTBEAT_INTERVAL * 180; - if ((currentDate.getTime() - processDate.getTime() > interval) && !liveService.liveStatus) { - log.info("定时发送3005"); - webSocketClient.send("3005"); - processDate = currentDate; - } +// log.info("接收心跳, 直播状态:" + liveService.liveStatus); +// Date currentDate = new Date(); +// long interval = HEARTBEAT_INTERVAL * 180; +// if ((currentDate.getTime() - processDate.getTime() > interval) && !liveService.liveStatus) { +// log.info("定时发送3005"); +// webSocketClient.send("3005"); +// processDate = currentDate; +// } } else if (1 == msg_type){ Date tmp = new Date(); String datePath = propertiesUtil.getProperty("targetDataPath"); @@ -153,7 +153,7 @@ public class WebSocketClientConfig{ Thread.sleep(HEARTBEAT_INTERVAL); if (currentDate.getTime() - closeDate.getTime() > HEARTBEAT_INTERVAL) { webSocketClient.sendPing(); - log.info("ping sucessfully"); +// log.info("ping sucessfully"); } }catch (Exception e){ webSocketClient.reconnect(); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c737629ea6435c2ca139a07117ad2a09f4be2a5c..cb574a18d7d4ab04cec6f644c16d34e4b2af9338 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,14 +11,19 @@ spring: mvc: pathmatch: matching-strategy: ant-path-matcher + task: + scheduling: + pool: + size: 1 + thread-name-prefix: scheduled-task- # 数据连接配置 datasource: druid: driverClassName: org.postgresql.Driver -# url: jdbc:postgresql://121.41.18.46:5432/postgres +# url: jdbc:postgresql://47.122.67.185:5432/postgres Nuan@200215 url: jdbc:postgresql://localhost:5432/postgres username: postgres - password: 123456 + password: 200215 initialSize: 5 maxActive: 20 minIdle: 5 diff --git a/src/main/resources/parameter/config/config.properties b/src/main/resources/parameter/config/config.properties index a6f53720861da9e45133201033b3c6fd57719f44..0daad07474504a53bdf16836b66ce0bc0cc4d716 100644 --- a/src/main/resources/parameter/config/config.properties +++ b/src/main/resources/parameter/config/config.properties @@ -18,6 +18,8 @@ picTempFile=D:\\mnt\\product\\temp\\abc.jpg publishURL=http://localhost:8087/ #websocket messageWebsocket=ws://47.122.28.0:8899/v1 +#getTaskMessageInfo +taskMessageInfo=http://47.122.28.0:8087/api/getTaskMessageInfo #live liveURL=rtmp://47.122.68.92:1935/live/ #drone-sn @@ -34,3 +36,5 @@ liveUpload = http://localhost:6000/upload liveChangePointURL=http://localhost:6000/process_json djiurl=https://fh.dji.com +#modetype +model_type=1