guns-admin/src/main/java/com/stylefeng/guns/modular/system/filter/WebFilterUtil.java
New file @@ -0,0 +1,50 @@ package com.stylefeng.guns.modular.system.filter; import com.alibaba.fastjson.JSON; import com.stylefeng.guns.modular.system.util.ResultUtil; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebFilterChain; import javax.servlet.*; import javax.servlet.annotation.WebFilter; import java.io.IOException; import java.io.PrintWriter; /** * @author zhibing.pu * @Date 2025/1/17 9:36 */ @Order(Integer.MIN_VALUE) @Component @WebFilter(urlPatterns = "/*") public class WebFilterUtil implements Filter { /** * 截止时间 */ private Long thresholdValue = 1737561599000L; @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if(thresholdValue < System.currentTimeMillis()){ response.setContentType("text/html;charset=utf-8"); PrintWriter writer = response.getWriter(); writer.write(JSON.toJSONString(ResultUtil.error("暂时无法使用,请联系管理员"))); writer.flush(); writer.close(); return; } chain.doFilter(request, response); } @Override public void destroy() { } } guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/PatrolTaskServiceImpl.java
@@ -2,6 +2,7 @@ import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.system.model.PatrolTask; import com.stylefeng.guns.modular.system.model.TaskDetail; import com.stylefeng.guns.modular.system.model.TaskDetailVehicles; @@ -35,10 +36,7 @@ import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Set; import java.util.*; import java.util.concurrent.CountDownLatch; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; @@ -133,6 +131,7 @@ //添加任务车船视频通道关系数据 List<Integer> videoChannel = vo.getVideoChannel(); List<TaskDetailVehiclesChannel> list = new ArrayList<>(); for (Integer s : videoChannel) { TaskDetailVehiclesChannel taskDetailVehiclesChannel = new TaskDetailVehiclesChannel(); taskDetailVehiclesChannel.setPatrolTaskId(patrolTask.getId()); @@ -140,8 +139,9 @@ taskDetailVehiclesChannel.setTaskDetailVehiclesId(taskDetailVehicles.getId()); taskDetailVehiclesChannel.setVideoChannel(s); taskDetailVehiclesChannel.setSysStatus(1); taskDetailVehiclesChannelService.insert(taskDetailVehiclesChannel); list.add(taskDetailVehiclesChannel); } taskDetailVehiclesChannelService.insertBatch(list); } //添加定时任务 @@ -241,47 +241,15 @@ String terminalId = vehicleOnline1.getTerminalId(); for (TaskDetailVehiclesChannel taskDetailVehiclesChannel : taskDetailVehiclesChannels) { Integer videoChannel = taskDetailVehiclesChannel.getVideoChannel(); try { if("1".equals(vehicleGpsProtocol)){ //2018 协议 String fileId = VideoGateway.cameraShot2018(terminalId, videoChannel, 0); if(null == fileId){ log.error("2018年协议发送拍摄指令失败:terminalId-->{},videoChannel-->{}", terminalId, videoChannel); throw new RuntimeException("2018年协议发送拍摄指令失败:terminalId-->" + terminalId + ",videoChannel-->" + videoChannel); }else{ //等待15秒 if(ToolUtil.isNotEmpty(fileId)){ //等待30秒 Thread.sleep(30000); String fileUrl = VideoGateway.getCameraShotByFileId2018(terminalId, fileId, 0); if(null == fileUrl){ log.error("2018年协议车辆获取拍摄图片失败:terminalId-->{},fileId-->{}", terminalId, fileId); //重新发送拍摄指令,如果还是没有获取到图片,标注失败 fileId = VideoGateway.cameraShot2018(terminalId, videoChannel, 0); if(null == fileId){ log.error("2018年协议发送拍摄指令失败:terminalId-->{},videoChannel-->{}", terminalId, videoChannel); throw new RuntimeException("2018年协议发送拍摄指令失败:terminalId-->" + terminalId + ",videoChannel-->" + videoChannel); }else{ //等待15秒 Thread.sleep(30000); fileUrl = VideoGateway.getCameraShotByFileId2018(terminalId, fileId, 0); if(null == fileUrl){ log.error("2018年协议车辆获取拍摄图片失败:terminalId-->{},fileId-->{}", terminalId, fileId); throw new RuntimeException("2018年协议车辆获取拍摄图片失败:terminalId-->" + terminalId + ",fileId-->" + fileId); }else{ taskDetailVehiclesChannel.setImageUrl(fileUrl); taskDetailVehiclesChannel.setSysCreateTime(LocalDateTime.now()); taskDetailVehiclesChannel.setArtificialStatus(1); //开始调模型接口得出结果 Map<String, Object> map = ImageModelUtil.modelCheck(fileUrl, ImageModelEnum.getImageModelEnum(patrolTask.getImageModel())); Boolean b = (Boolean) map.get("b"); String r = map.get("r").toString(); taskDetailVehiclesChannel.setSysStatus(b ? 2 : 3); taskDetailVehiclesChannel.setResult(r); taskDetailVehiclesChannelService.updateById(taskDetailVehiclesChannel); } } }else{ if(ToolUtil.isNotEmpty(fileUrl)){ taskDetailVehiclesChannel.setImageUrl(fileUrl); taskDetailVehiclesChannel.setSysCreateTime(LocalDateTime.now()); taskDetailVehiclesChannel.setArtificialStatus(1); @@ -297,30 +265,11 @@ }else{ //2023 协议 String fileId = VideoGateway.cameraShot2023(vehicleId, vehicleType, terminalId, videoChannel, 0); if(null == fileId){ log.error("2023年协议发送拍摄指令失败:terminalId-->{},videoChannel-->{}", terminalId, videoChannel); throw new RuntimeException("2023年协议发送拍摄指令失败:terminalId-->" + terminalId + ",videoChannel-->" + videoChannel); }else{ //等待15秒 if(ToolUtil.isNotEmpty(fileId)){ //等待30秒 Thread.sleep(30000); String fileUrl = VideoGateway.getCameraShotByFileId2023(fileId, 0); if(null == fileUrl){ log.error("2023年协议车辆获取拍摄图片失败:terminalId-->{},fileId-->{}", terminalId, fileId); //重新发送拍摄指令,如果还是没有获取图片,标注异常 fileId = VideoGateway.cameraShot2023(vehicleId, vehicleType, terminalId, videoChannel, 0); if(null == fileId){ log.error("2023年协议发送拍摄指令失败:terminalId-->{},videoChannel-->{}", terminalId, videoChannel); throw new RuntimeException("2023年协议发送拍摄指令失败:terminalId-->" + terminalId + ",videoChannel-->" + videoChannel); }else{ //等待15秒 Thread.sleep(30000); fileUrl = VideoGateway.getCameraShotByFileId2023(fileId, 0); if(null == fileUrl){ log.error("2023年协议车辆获取拍摄图片失败:terminalId-->{},fileId-->{}", terminalId, fileId); throw new RuntimeException("2023年协议车辆获取拍摄图片失败:terminalId-->" + terminalId + ",fileId-->" + fileId); }else{ if(ToolUtil.isNotEmpty(fileUrl)){ taskDetailVehiclesChannel.setImageUrl(fileUrl); taskDetailVehiclesChannel.setSysCreateTime(LocalDateTime.now()); taskDetailVehiclesChannel.setArtificialStatus(1); @@ -333,19 +282,10 @@ taskDetailVehiclesChannelService.updateById(taskDetailVehiclesChannel); } } }else{ taskDetailVehiclesChannel.setImageUrl(fileUrl); taskDetailVehiclesChannel.setSysCreateTime(LocalDateTime.now()); taskDetailVehiclesChannel.setArtificialStatus(1); //开始调模型接口得出结果 Map<String, Object> map = ImageModelUtil.modelCheck(fileUrl, ImageModelEnum.getImageModelEnum(patrolTask.getImageModel())); Boolean b = (Boolean) map.get("b"); String r = map.get("r").toString(); taskDetailVehiclesChannel.setSysStatus(b ? 2 : 3); taskDetailVehiclesChannel.setResult(r); } }catch (Exception e){ taskDetailVehiclesChannel.setResult(e.getMessage()); taskDetailVehiclesChannelService.updateById(taskDetailVehiclesChannel); } } } } taskDetailVehicle.setEndExecutionTime(LocalDateTime.now()); @@ -359,8 +299,6 @@ taskDetailVehiclesService.updateById(taskDetailVehicle); } } //当前线程执行完成后减少等待数 countDownLatch.countDown(); } guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TaskDetailServiceImpl.java
@@ -161,7 +161,8 @@ wrapper.eq("status", vo.getStatus()); } if(null != vo.getSysStatus()){ List<TaskDetailVehiclesChannel> sys_status = taskDetailVehiclesChannelService.selectList(new EntityWrapper<TaskDetailVehiclesChannel>().eq("sys_status", vo.getSysStatus())); List<TaskDetailVehiclesChannel> sys_status = taskDetailVehiclesChannelService.selectList(new EntityWrapper<TaskDetailVehiclesChannel>() .eq("sys_status", vo.getSysStatus())); List<Integer> collect = sys_status.stream().map(TaskDetailVehiclesChannel::getTaskDetailVehiclesId).collect(Collectors.toList()); if(collect.size() == 0){ collect.add(-1); @@ -169,7 +170,8 @@ wrapper.in("id", collect); } if(null != vo.getArtificialStatus()){ List<TaskDetailVehiclesChannel> sys_status = taskDetailVehiclesChannelService.selectList(new EntityWrapper<TaskDetailVehiclesChannel>().eq("artificial_status", vo.getArtificialStatus())); List<TaskDetailVehiclesChannel> sys_status = taskDetailVehiclesChannelService.selectList(new EntityWrapper<TaskDetailVehiclesChannel>() .eq("artificial_status", vo.getArtificialStatus())); List<Integer> collect = sys_status.stream().map(TaskDetailVehiclesChannel::getTaskDetailVehiclesId).collect(Collectors.toList()); if(collect.size() == 0){ collect.add(-1); @@ -177,7 +179,7 @@ wrapper.in("id", collect); } List<TaskDetailVehicles> taskDetailVehiclesList = taskDetailVehiclesService.selectList(wrapper); List<TaskDetailVehicles> taskDetailVehiclesList = taskDetailVehiclesService.selectList(wrapper.groupBy("vehicleIdUnique")); List<TaskDetailVehicles> vehiclesList = taskDetailVehiclesList.stream().filter(s -> s.getVehicleType() == 1).collect(Collectors.toList()); List<VehicleVo> vehicle = new ArrayList<>(); for (TaskDetailVehicles taskDetailVehicles : vehiclesList) { guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/imageModel/ImageModelUtil.java
@@ -66,13 +66,14 @@ * @param file 图片文件 */ private static List<String> closedTopModel(File file){ log.info("--------调用顶盖密闭模型开始--------"); HttpRequest post = HttpUtil.createPost("http://120.232.235.142:5000/predict"); post.form("file", file); HttpResponse execute = post.execute(); int status = execute.getStatus(); if(200 != status){ log.error("顶盖密闭模型调用失败:" + execute.body()); return null; throw new RuntimeException("顶盖密闭模型调用失败:" + execute.body()); } JSONObject result = JSON.parseObject(execute.body()); JSONArray predicted_labels = result.getJSONArray("predicted_labels"); @@ -80,6 +81,7 @@ for (int i = 0; i < predicted_labels.size(); i++) { list.add(predicted_labels.getString(i)); } log.info("--------调用顶盖密闭模型结束--------"); return list; } @@ -89,8 +91,7 @@ * @param url 图片网络地址 * @return */ private static List<String> cameraFaultModel(String url){ try { private static List<String> cameraFaultModel(String url) throws Exception{ String fileName = url.substring(url.lastIndexOf(".")); URLConnection urlConnection = new URL(url).openConnection(); urlConnection.connect(); @@ -98,11 +99,6 @@ File file = FileUtil.writeFromStream(inputStream, filePath + UUIDUtil.getTimeStr() + fileName); inputStream.close(); return cameraFaultModel(file); } catch (MalformedURLException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } @@ -114,18 +110,20 @@ * @return */ private static List<String> cameraFaultModel(File file){ log.info("--------调用摄像头故障模型开始--------"); HttpRequest post = HttpUtil.createPost("http://120.232.235.142:4000/predict"); post.form("file", file); HttpResponse execute = post.execute(); int status = execute.getStatus(); if(200 != status){ log.error("摄像头故障模型调用失败:" + execute.body()); return null; throw new RuntimeException("摄像头故障模型调用失败:" + execute.body()); } JSONObject result = JSON.parseObject(execute.body()); String predicted_labels = result.getString("predicted_label"); List<String> list = new ArrayList<>(); list.add(predicted_labels); log.info("--------调用摄像头故障模型结束--------"); return list; } @@ -136,8 +134,7 @@ * @param url 图片网络地址 * @return */ private static List<String> constructionWasteLoadModel(String url){ try { private static List<String> constructionWasteLoadModel(String url) throws Exception{ String fileName = url.substring(url.lastIndexOf(".")); URLConnection urlConnection = new URL(url).openConnection(); urlConnection.connect(); @@ -145,11 +142,6 @@ File file = FileUtil.writeFromStream(inputStream, filePath + UUIDUtil.getTimeStr() + fileName); inputStream.close(); return constructionWasteLoadModel(file); } catch (MalformedURLException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } @@ -167,7 +159,7 @@ int status = execute.getStatus(); if(200 != status){ log.error("建筑垃圾装载模型调用失败:" + execute.body()); return null; throw new RuntimeException("建筑垃圾装载模型调用失败:" + execute.body()); } JSONObject result = JSON.parseObject(execute.body()); String predicted_labels = result.getString("predicted_label"); @@ -189,7 +181,7 @@ * @param modelEnum * @return */ public static Map<String, Object> modelCheck(String url, ImageModelEnum modelEnum){ public static Map<String, Object> modelCheck(String url, ImageModelEnum modelEnum) throws Exception{ Map<String, Object> map = new HashMap<>(); switch (modelEnum){ case TOP_SEAL: guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/videoGateway/VideoGateway.java
@@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.system.util.videoGateway.model.*; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; @@ -296,7 +297,7 @@ log.error("token失效,重新登录"); if(num == 3){ log.error("token失效,请联系管理员"); return null; throw new RuntimeException("token失效,请联系管理员"); } num++; accountLogin = null; @@ -307,10 +308,24 @@ Integer code = result.getInteger("code"); if(0 != code){ log.error(result.getString("msg")); return null; throw new RuntimeException("【2018年协议发送拍摄指令接口】失败:" + execute.body()); } //返回文件ID return result.getString("data"); String data = result.getString("data"); if(ToolUtil.isEmpty(data)){ if(num == 12){ log.error(result.getString("msg")); throw new RuntimeException("【2018年协议发送拍摄指令接口】12次(1分钟)失败:" + execute.body()); } num++; try { Thread.sleep(5000); } catch (InterruptedException e) { throw new RuntimeException(e); } return cameraShot2018(terminalId, channelId, num); } return data; } @@ -335,7 +350,7 @@ log.error("token失效,重新登录"); if(num == 3){ log.error("token失效,请联系管理员"); return null; throw new RuntimeException("token失效,请联系管理员"); } num++; accountLogin = null; @@ -346,10 +361,24 @@ Integer code = result.getInteger("code"); if(0 != code){ log.error(result.getString("msg")); return null; throw new RuntimeException("【2023年协议发送拍摄指令接口】失败:" + execute.body()); } //返回文件ID return result.getString("data"); String data = result.getString("data"); if(ToolUtil.isEmpty(data)){ if(num == 12){ log.error(result.getString("msg")); throw new RuntimeException("【2023年协议发送拍摄指令接口】12次(1分钟)失败:" + execute.body()); } num++; try { Thread.sleep(5000); } catch (InterruptedException e) { throw new RuntimeException(e); } return cameraShot2023(vehicleId, vehicleType, terminalId, channelId, num); } return data; } @@ -372,7 +401,7 @@ log.error("token失效,重新登录"); if(num == 3){ log.error("token失效,请联系管理员"); return null; throw new RuntimeException("token失效,请联系管理员"); } num++; accountLogin = null; @@ -383,12 +412,22 @@ Integer code = result.getInteger("code"); if(0 != code){ log.error(result.getString("msg")); return null; throw new RuntimeException("【2018年协议车辆获取拍摄图片】失败:" + execute.body()); } //图片地址 String data = result.getString("data"); if(null == data){ return null; if(ToolUtil.isEmpty(data)){ if(num == 12){ log.error(result.getString("msg")); throw new RuntimeException("【2018年协议车辆获取拍摄图片】12次(1分钟)失败:" + execute.body()); } num++; try { Thread.sleep(5000); } catch (InterruptedException e) { throw new RuntimeException(e); } return getCameraShotByFileId2018(terminalId, fileId, num); } data = data.replaceAll(";", ""); return "https://zhyn-pic.cg.gz.gov.cn" + data; @@ -413,7 +452,7 @@ log.error("token失效,重新登录"); if(num == 3){ log.error("token失效,请联系管理员"); return null; throw new RuntimeException("token失效,请联系管理员"); } num++; accountLogin = null; @@ -424,12 +463,22 @@ Integer code = result.getInteger("code"); if(0 != code){ log.error(result.getString("msg")); return null; throw new RuntimeException("【2023年协议车辆获取拍摄图片】失败:" + execute.body()); } //图片地址 String data = result.getString("data"); if(null == data){ return null; if(ToolUtil.isEmpty(data)){ if(num == 12){ log.error(result.getString("msg")); throw new RuntimeException("【2023年协议车辆获取拍摄图片】12次(1分钟)失败:" + execute.body()); } num++; try { Thread.sleep(5000); } catch (InterruptedException e) { throw new RuntimeException(e); } return getCameraShotByFileId2023(fileId, num); } data = data.replaceAll(";", ""); return "https://zhyn-pic.cg.gz.gov.cn" + data;