diff --git a/web/pom.xml b/web/pom.xml index 400d4cb..b99f801 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -19,6 +19,12 @@ + + cn.hutool + hutool-all + 5.8.25 + + com.zhehekeji base-assembly @@ -111,6 +117,14 @@ true + + org.apache.maven.plugins + maven-compiler-plugin + + 9 + 9 + + diff --git a/web/src/main/java/com/zhehekeji/web/config/CacheConfig.java b/web/src/main/java/com/zhehekeji/web/config/CacheConfig.java index 53c130a..01f5f5d 100644 --- a/web/src/main/java/com/zhehekeji/web/config/CacheConfig.java +++ b/web/src/main/java/com/zhehekeji/web/config/CacheConfig.java @@ -11,6 +11,7 @@ import org.springframework.cache.jcache.JCacheCache; import org.springframework.cache.support.SimpleCacheManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; import java.util.ArrayList; import java.util.Arrays; @@ -21,6 +22,11 @@ import java.util.concurrent.TimeUnit; @EnableCaching public class CacheConfig { + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } + @Bean public CacheManager localCacheManager() { SimpleCacheManager simpleCacheManager = new SimpleCacheManager(); diff --git a/web/src/main/java/com/zhehekeji/web/config/ConfigProperties.java b/web/src/main/java/com/zhehekeji/web/config/ConfigProperties.java index 8a4c13b..2ee48ee 100644 --- a/web/src/main/java/com/zhehekeji/web/config/ConfigProperties.java +++ b/web/src/main/java/com/zhehekeji/web/config/ConfigProperties.java @@ -37,8 +37,16 @@ public class ConfigProperties { private LightSource lightSource; private ScanCodeMode scanCodeMode; + private Zlm zlm; + @Data + public static class Zlm { + private String ip; + private Integer apiPort; + private String secret; + } + @Data public static class CameraConfig{ diff --git a/web/src/main/java/com/zhehekeji/web/config/JsonUtils.java b/web/src/main/java/com/zhehekeji/web/config/JsonUtils.java new file mode 100644 index 0000000..3312d02 --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/config/JsonUtils.java @@ -0,0 +1,202 @@ +package com.zhehekeji.web.config; + +import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONUtil; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +/** + * JSON 工具类 + * + * @author 芋道源码 + */ +@Slf4j +public class JsonUtils { + + private static ObjectMapper objectMapper = new ObjectMapper(); + + static { + objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // 忽略 null 值 + objectMapper.registerModules(new JavaTimeModule()); // 解决 LocalDateTime 的序列化 + } + + /** + * 初始化 objectMapper 属性 + *

+ * 通过这样的方式,使用 Spring 创建的 ObjectMapper Bean + * + * @param objectMapper ObjectMapper 对象 + */ + public static void init(ObjectMapper objectMapper) { + JsonUtils.objectMapper = objectMapper; + } + + @SneakyThrows + public static String toJsonString(Object object) { + return objectMapper.writeValueAsString(object); + } + + @SneakyThrows + public static byte[] toJsonByte(Object object) { + return objectMapper.writeValueAsBytes(object); + } + + @SneakyThrows + public static String toJsonPrettyString(Object object) { + return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(object); + } + + public static T parseObject(String text, Class clazz) { + if (StrUtil.isEmpty(text)) { + return null; + } + try { + return objectMapper.readValue(text, clazz); + } catch (IOException e) { + log.error("json parse err,json:{}", text, e); + throw new RuntimeException(e); + } + } + + public static T parseObject(String text, String path, Class clazz) { + if (StrUtil.isEmpty(text)) { + return null; + } + try { + JsonNode treeNode = objectMapper.readTree(text); + JsonNode pathNode = treeNode.path(path); + return objectMapper.readValue(pathNode.toString(), clazz); + } catch (IOException e) { + log.error("json parse err,json:{}", text, e); + throw new RuntimeException(e); + } + } + + public static T parseObject(String text, Type type) { + if (StrUtil.isEmpty(text)) { + return null; + } + try { + return objectMapper.readValue(text, objectMapper.getTypeFactory().constructType(type)); + } catch (IOException e) { + log.error("json parse err,json:{}", text, e); + throw new RuntimeException(e); + } + } + + /** + * 将字符串解析成指定类型的对象 + * 使用 {@link #parseObject(String, Class)} 时,在@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS) 的场景下, + * 如果 text 没有 class 属性,则会报错。此时,使用这个方法,可以解决。 + * + * @param text 字符串 + * @param clazz 类型 + * @return 对象 + */ + public static T parseObject2(String text, Class clazz) { + if (StrUtil.isEmpty(text)) { + return null; + } + return JSONUtil.toBean(text, clazz); + } + + public static T parseObject(byte[] bytes, Class clazz) { + if (ArrayUtil.isEmpty(bytes)) { + return null; + } + try { + return objectMapper.readValue(bytes, clazz); + } catch (IOException e) { + log.error("json parse err,json:{}", bytes, e); + throw new RuntimeException(e); + } + } + + public static T parseObject(String text, TypeReference typeReference) { + try { + return objectMapper.readValue(text, typeReference); + } catch (IOException e) { + log.error("json parse err,json:{}", text, e); + throw new RuntimeException(e); + } + } + + /** + * 解析 JSON 字符串成指定类型的对象,如果解析失败,则返回 null + * + * @param text 字符串 + * @param typeReference 类型引用 + * @return 指定类型的对象 + */ + public static T parseObjectQuietly(String text, TypeReference typeReference) { + try { + return objectMapper.readValue(text, typeReference); + } catch (IOException e) { + return null; + } + } + + public static List parseArray(String text, Class clazz) { + if (StrUtil.isEmpty(text)) { + return new ArrayList<>(); + } + try { + return objectMapper.readValue(text, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz)); + } catch (IOException e) { + log.error("json parse err,json:{}", text, e); + throw new RuntimeException(e); + } + } + + public static List parseArray(String text, String path, Class clazz) { + if (StrUtil.isEmpty(text)) { + return null; + } + try { + JsonNode treeNode = objectMapper.readTree(text); + JsonNode pathNode = treeNode.path(path); + return objectMapper.readValue(pathNode.toString(), objectMapper.getTypeFactory().constructCollectionType(List.class, clazz)); + } catch (IOException e) { + log.error("json parse err,json:{}", text, e); + throw new RuntimeException(e); + } + } + + public static JsonNode parseTree(String text) { + try { + return objectMapper.readTree(text); + } catch (IOException e) { + log.error("json parse err,json:{}", text, e); + throw new RuntimeException(e); + } + } + + public static JsonNode parseTree(byte[] text) { + try { + return objectMapper.readTree(text); + } catch (IOException e) { + log.error("json parse err,json:{}", text, e); + throw new RuntimeException(e); + } + } + + public static boolean isJson(String text) { + return JSONUtil.isTypeJSON(text); + } + +} diff --git a/web/src/main/java/com/zhehekeji/web/config/MyInitializer.java b/web/src/main/java/com/zhehekeji/web/config/MyInitializer.java new file mode 100644 index 0000000..7943388 --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/config/MyInitializer.java @@ -0,0 +1,210 @@ +package com.zhehekeji.web.config; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.zhehekeji.web.config.zlm.RtspSessionResponse; +import com.zhehekeji.web.entity.Camera; +import com.zhehekeji.web.lib.CameraConnMap; +import com.zhehekeji.web.service.CameraService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; + +import javax.annotation.Resource; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Slf4j +@Component +public class MyInitializer { + + + + @Resource + private RestTemplate restTemplate; + + + @Resource + private CameraService cameraService; + @Resource + ConfigProperties configProperties; + + + public static void main(String[] args) { + MyInitializer myInitializer = new MyInitializer(); + myInitializer.checkAndAddRtspProxies(); + } + @Scheduled(fixedRate = 30000) // 每分钟执行一次 + public void checkAndAddRtspProxies() { + + + List list =cameraService.allCameras(); + //添加流信息 + zlmConf(list); + + } + + + private void zlmConf( List list) { + + String zlmApiUrl = "http://"+configProperties.getZlm().getIp()+":"+configProperties.getZlm().getApiPort()+"/index/api/"; + String zlmApiSecret = configProperties.getZlm().getSecret(); + try { + // 查询当前的RTSP拉流代理 + Map queryParams = new HashMap<>(); + queryParams.put("secret", zlmApiSecret); + String queryUrl = buildUrl(zlmApiUrl +"getMediaList" , queryParams); + String response = get(queryUrl); + RtspSessionResponse rtspSessionResponse = JsonUtils.parseObject(response, RtspSessionResponse.class); + // 检查并添加缺失的RTSP代理 + for (Camera entry : list) { + boolean isRtspProxyExists = false; + if (rtspSessionResponse != null && rtspSessionResponse.getData()!=null && rtspSessionResponse.getData().size()>0) { + for (RtspSessionResponse.RtspSession rtspSession : rtspSessionResponse.getData()){ + if (rtspSession.getApp().equals("live")&&rtspSession.getStream().equals("camera"+entry.getId())){ + isRtspProxyExists = true; + break; + } + } + } + //不存在则重新注入 + if (!isRtspProxyExists){ + try { + + addRtspProxy(entry, zlmApiUrl, zlmApiSecret); + }catch (Exception e){ + e.printStackTrace(); + } + } + + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + + public void stopRecord(Camera camera) { + + String zlmApiUrl = "http://"+configProperties.getZlm().getIp()+":"+configProperties.getZlm().getApiPort()+"/index/api/"; + String zlmApiSecret = configProperties.getZlm().getSecret(); + Map addParams = new HashMap<>(); + addParams.put("secret", zlmApiSecret); + addParams.put("vhost", "__defaultVhost__"); + addParams.put("app", "live"); + addParams.put("type", "1"); + addParams.put("stream","camera"+ camera.getId()); + + String addUrl = buildUrl(zlmApiUrl+"stopRecord", addParams); + String response = get(addUrl); + + log.info("stopRecord camera:"+camera.getId()+" response:"+response); + + } + + public String startRecord(Camera camera){ + + String zlmApiUrl = "http://"+configProperties.getZlm().getIp()+":"+configProperties.getZlm().getApiPort()+"/index/api/"; + String zlmApiSecret = configProperties.getZlm().getSecret(); + Map addParams = new HashMap<>(); + addParams.put("secret", zlmApiSecret); + addParams.put("vhost", "__defaultVhost__"); + addParams.put("app", "live"); + addParams.put("type", "1"); + addParams.put("stream","camera"+ camera.getId()); + + String addUrl = buildUrl(zlmApiUrl+"startRecord", addParams); + String response = get(addUrl); + log.info("startRecord camera:"+camera.getId()+" response:"+response); + String path = checkHiddenFilesInDirectory(camera); + ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + + Runnable task = () -> { + stopRecord(camera); + + }; + + // 延迟5分钟后执行停止任务,不会将录像文件录5分钟 + long delay =5; + scheduler.schedule(task, delay, TimeUnit.MINUTES); + return path; + } + + // 新增方法:检查指定文件夹下是否有以.为开头的文件 + public String checkHiddenFilesInDirectory(Camera camera) { + + // 获取当前日期 + LocalDate currentDate = LocalDate.now(); + + // 定义日期格式 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + // 格式化日期 + String formattedDate = currentDate.format(formatter); + + String directoryPath = configProperties.getSavePath().getMp4Path()+"record/live/camera"+camera.getId()+"/"+formattedDate; + + + Path directory = Paths.get(directoryPath); + List hiddenFiles = new ArrayList<>(); + + try (Stream paths = Files.walk(directory, 1)) { + hiddenFiles= paths + .filter(Files::isRegularFile) + .map(Path::getFileName) + .map(Path::toString) + .filter(name -> name.startsWith(".")) + .collect(Collectors.toList()); + return hiddenFiles.isEmpty() ? "" : "record/live/camera"+camera.getId()+"/"+formattedDate+"/"+removeLeadingDot(hiddenFiles.get(0)); + } catch (IOException e) { + e.printStackTrace(); + hiddenFiles= List.of(); // 返回空列表 + } + return ""; + } + public static String removeLeadingDot(String input) { + if (input == null || input.isEmpty()) { + return input; + } + if (input.startsWith(".")) { + return input.substring(1); + } + return input; + } + private void addRtspProxy(Camera camera, String zlmApiUrl, String zlmApiSecret) throws IOException { + Map addParams = new HashMap<>(); + addParams.put("secret", zlmApiSecret); + addParams.put("vhost", "__defaultVhost__"); + addParams.put("app", "live"); + addParams.put("stream","camera"+ camera.getId()); + addParams.put("url", camera.getRtsp()); + String addUrl = buildUrl(zlmApiUrl+"addStreamProxy" , addParams); + String response = get(addUrl); + System.out.println("Add RTSP Proxy Response: " + response); + } + + private String buildUrl(String baseUrl, Map params) { + UriComponentsBuilder urlBuilder = UriComponentsBuilder.fromHttpUrl(baseUrl); + + for (Map.Entry entry : params.entrySet()) { + urlBuilder.queryParam(entry.getKey(), entry.getValue().toString()); + } + return urlBuilder.toUriString(); + } + + private String get(String url) { + return restTemplate.getForObject(url, String.class); + } + +} diff --git a/web/src/main/java/com/zhehekeji/web/config/zlm/RtspSessionResponse.java b/web/src/main/java/com/zhehekeji/web/config/zlm/RtspSessionResponse.java new file mode 100644 index 0000000..110a2f6 --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/config/zlm/RtspSessionResponse.java @@ -0,0 +1,77 @@ +package com.zhehekeji.web.config.zlm; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class RtspSessionResponse { + + private int code; + private List data; + + @Data + public static class RtspSession { + private int aliveSecond; + private String app; + private Integer loss; // 映射 JSON 中的 "loss" 字段 + private long bytesSpeed; + private long createStamp; + @JsonProperty("isRecordingHLS") + private boolean recordingHLS; + @JsonProperty("isRecordingMP4") + private boolean recordingMP4; + private OriginSock originSock; + private int originType; + private String originTypeStr; + private String originUrl; + private String params; + private int readerCount; + private String schema; + private String stream; + private int totalReaderCount; + private List tracks; + private String vhost; + + @Data + public static class OriginSock { + private String identifier; + @JsonProperty("local_ip") + private String localIp; + @JsonProperty("local_port") + private int localPort; + @JsonProperty("peer_ip") + private String peerIp; + @JsonProperty("peer_port") + private int peerPort; + } + + @Data + public static class Track { + @JsonProperty("codec_id") + private int codecId; + @JsonProperty("codec_id_name") + private String codecIdName; + @JsonProperty("codec_type") + private int codecType; + private long duration; + private int fps; + private int frames; + @JsonProperty("gop_interval_ms") + private int gopIntervalMs; + @JsonProperty("gop_size") + private int gopSize; + private int height; + @JsonProperty("key_frames") + private int keyFrames; + private boolean ready; + private int width; + private int channels; + @JsonProperty("sample_bit") + private int sampleBit; + @JsonProperty("sample_rate") + private int sampleRate; + } + } +} \ No newline at end of file diff --git a/web/src/main/java/com/zhehekeji/web/entity/Order.java b/web/src/main/java/com/zhehekeji/web/entity/Order.java index 55c8354..776e4c3 100644 --- a/web/src/main/java/com/zhehekeji/web/entity/Order.java +++ b/web/src/main/java/com/zhehekeji/web/entity/Order.java @@ -83,6 +83,14 @@ public class Order { @ApiModelProperty("视频图片地址") @TableField("`video_path_2`") private String videoPath2; + @ApiModelProperty("视频图片地址") + @TableField("`video_path_3`") + private String videoPath3; + + @ApiModelProperty("视频图片地址") + @TableField("`video_path_4`") + private String videoPath4; + @ApiModelProperty("图片地址,分隔") private String picPaths; diff --git a/web/src/main/java/com/zhehekeji/web/entity/SteeringEngine.java b/web/src/main/java/com/zhehekeji/web/entity/SteeringEngine.java index 80549b9..bb3e9bc 100644 --- a/web/src/main/java/com/zhehekeji/web/entity/SteeringEngine.java +++ b/web/src/main/java/com/zhehekeji/web/entity/SteeringEngine.java @@ -26,8 +26,8 @@ public class SteeringEngine { plcCmdInfo.setPlcId(String.valueOf(steeringEngine.getWorkunitid())); if(steeringEngine.getSloc()!=null && steeringEngine.getSloc().endsWith("000")){ plcCmdInfo.setLeftRight1(Integer.valueOf(steeringEngine.getSloc().substring(3,4))); - plcCmdInfo.setColumn1(Integer.valueOf(steeringEngine.getSloc().substring(4,6))); - plcCmdInfo.setRow1(Integer.valueOf(steeringEngine.getSloc().substring(6,8))); + plcCmdInfo.setColumn1(Integer.valueOf(steeringEngine.getSloc().substring(4,7))); + plcCmdInfo.setRow1(Integer.valueOf(steeringEngine.getSloc().substring(7,10))); plcCmdInfo.setSeparation1(1); }else { plcCmdInfo.setLeftRight1(0); @@ -37,8 +37,8 @@ public class SteeringEngine { } if(steeringEngine.getDloc()!=null && steeringEngine.getDloc().endsWith("000")){ plcCmdInfo.setLeftRight2(Integer.valueOf(steeringEngine.getDloc().substring(3,4))); - plcCmdInfo.setColumn2(Integer.valueOf(steeringEngine.getDloc().substring(4,6))); - plcCmdInfo.setRow2(Integer.valueOf(steeringEngine.getDloc().substring(6,8))); + plcCmdInfo.setColumn2(Integer.valueOf(steeringEngine.getDloc().substring(4,7))); + plcCmdInfo.setRow2(Integer.valueOf(steeringEngine.getDloc().substring(7,10))); plcCmdInfo.setSeparation2(1); }else { plcCmdInfo.setLeftRight2(0); @@ -48,4 +48,11 @@ public class SteeringEngine { } return plcCmdInfo; } + + public static void main(String[] args) { + SteeringEngine steeringEngine = new SteeringEngine(); + steeringEngine.setDloc("0041002003000"); + PlcCmdInfo plcCmdInfo = SteeringEngine.getPlcCmdInfo(steeringEngine); + System.out.println(plcCmdInfo); + } } \ No newline at end of file diff --git a/web/src/main/java/com/zhehekeji/web/lib/hik/HikCameraControlModuleImpl.java b/web/src/main/java/com/zhehekeji/web/lib/hik/HikCameraControlModuleImpl.java index dc814da..9c15508 100644 --- a/web/src/main/java/com/zhehekeji/web/lib/hik/HikCameraControlModuleImpl.java +++ b/web/src/main/java/com/zhehekeji/web/lib/hik/HikCameraControlModuleImpl.java @@ -421,7 +421,6 @@ public class HikCameraControlModuleImpl implements CameraControlModule { * 设置预置点 * * @param ptzId 预置点ID - * @param name 预置点的名称 * @param cameraId 球机ID,来获取登录句柄 */ public void ptz(Integer ptzId, String name, Integer cameraId) diff --git a/web/src/main/java/com/zhehekeji/web/pojo/OrderSearch.java b/web/src/main/java/com/zhehekeji/web/pojo/OrderSearch.java index c70d7e3..4caadcb 100644 --- a/web/src/main/java/com/zhehekeji/web/pojo/OrderSearch.java +++ b/web/src/main/java/com/zhehekeji/web/pojo/OrderSearch.java @@ -21,4 +21,6 @@ public class OrderSearch { private Integer pageSize; private Integer pageNum; + + private String streetId; } diff --git a/web/src/main/java/com/zhehekeji/web/service/CameraService.java b/web/src/main/java/com/zhehekeji/web/service/CameraService.java index 23f7c8e..dec010c 100644 --- a/web/src/main/java/com/zhehekeji/web/service/CameraService.java +++ b/web/src/main/java/com/zhehekeji/web/service/CameraService.java @@ -354,6 +354,11 @@ public class CameraService { return null; } + public Camera getId(Integer id){ + Camera camera = cameraMapper.selectById(id); + return camera; + } + public Integer getPtzId(Integer ioId){ CameraIO cameraIO = ioMapper.selectById(ioId); Assert.notNull(cameraIO,"IO配置不存在"); diff --git a/web/src/main/java/com/zhehekeji/web/service/CronTab.java b/web/src/main/java/com/zhehekeji/web/service/CronTab.java index 1544995..8beb1f9 100644 --- a/web/src/main/java/com/zhehekeji/web/service/CronTab.java +++ b/web/src/main/java/com/zhehekeji/web/service/CronTab.java @@ -59,7 +59,7 @@ public class CronTab { File dir = new File(configProperties.getSavePath().getMediaPath()); long space = dir.getFreeSpace() / gByte; log.info(" free space :{}",space); - if(space > 150){ + if(space > 300){ return; } checkFileTime(dir,configProperties.getDeleteFileDays()); @@ -70,7 +70,7 @@ public class CronTab { @Resource SteeringEngineService steeringEngineService; - @Scheduled(fixedDelay = 5000) + @Scheduled(fixedDelay = 1000) //@Scheduled(cron = "0 0/1 * * * *") public void check() { steeringEngineService.check(); diff --git a/web/src/main/java/com/zhehekeji/web/service/LightSourceService.java b/web/src/main/java/com/zhehekeji/web/service/LightSourceService.java index fb56c5a..f9c464f 100644 --- a/web/src/main/java/com/zhehekeji/web/service/LightSourceService.java +++ b/web/src/main/java/com/zhehekeji/web/service/LightSourceService.java @@ -23,7 +23,7 @@ import java.util.List; @Slf4j public class LightSourceService { - @Autowired + @Resource private LightSourceMapper lightSourceMapper; @Resource @@ -70,10 +70,13 @@ public class LightSourceService { public static void relay(String host, int port, int status) { byte[] data; + byte[] data1; if (status == 1) { data = new byte[]{0x01, 0x05, 0x00, 0x01, (byte) 0xFF, 0x00, (byte) 0xDD, (byte) 0xFA}; + data1 = new byte[]{0x01, 0x05, 0x00, 0x00, (byte) 0xFF, 0x00, (byte) 0x8C, (byte) 0x3A}; } else { data = new byte[]{0x01, 0x05, 0x00, 0x01, (byte) 0x00, 0x00, (byte) 0x9C, (byte) 0x0A}; + data1 = new byte[]{0x01, 0x05, 0x00, 0x00, (byte) 0x00, 0x00, (byte) 0xcd, (byte) 0xca}; } @@ -83,6 +86,8 @@ public class LightSourceService { // 发送数据 outputStream.write(data); outputStream.flush(); + outputStream.write(data1); + outputStream.flush(); System.out.println("Data sent successfully."); @@ -95,4 +100,5 @@ public class LightSourceService { public List getLightSourceByStreetId(Integer streetId) { return lightSourceMapper.selectList(new QueryWrapper().eq("street_id", streetId)); } + } diff --git a/web/src/main/java/com/zhehekeji/web/service/OrderService.java b/web/src/main/java/com/zhehekeji/web/service/OrderService.java index 9d4c336..66ed0c1 100644 --- a/web/src/main/java/com/zhehekeji/web/service/OrderService.java +++ b/web/src/main/java/com/zhehekeji/web/service/OrderService.java @@ -81,53 +81,25 @@ public class OrderService { public String location(OrderVO orderVO,Street street){ //from to 模型 + String from = ""; + String on =""; + //库内转库内 看 to + //从哪里 + if( orderVO.getRow1()==0 ){ + from = "库外"; + }else { + from =orderVO.getRow1()+"层"+orderVO.getColumn1()+"列"+( orderVO.getLeftRight1()==1?"左侧":"右侧"); + } - if (orderVO.getInOut1() != null && orderVO.getInOut2() != null) { - //左右货架 货位号 - //库内转库内 看 to - Integer column = 0; - Integer row = 0; - //左货架 ? 右货架 ? - Integer leftRight = 0; - if (orderVO.getInOut1() == 1 && orderVO.getInOut2() == 1) { - // 库内转库内 - leftRight = orderVO.getLeftRight2(); - column = orderVO.getColumn2(); - row = orderVO.getRow2(); - } else if (orderVO.getInOut1() == 1) { - // 库内到库外 - leftRight = orderVO.getLeftRight1(); - //看from - orderVO.setStreetType(orderVO.getLeftRight1()); - column = orderVO.getColumn1(); - row = orderVO.getRow1(); - } else if (orderVO.getInOut2() == 1) { - //库外到库内 - leftRight = orderVO.getLeftRight2(); - //看to - orderVO.setStreetType(orderVO.getLeftRight2()); - column = orderVO.getColumn2(); - row = orderVO.getRow2(); - }else { - return "库外转库外"; - } - if (leftRight > 0) { - //PLC 1是左 2是由 - if(street != null){ - if(leftRight == 1){ - orderVO.setStreetType(street.getLeftType()); - }else { - orderVO.setStreetType(street.getRightType()); - } - } - String leftRightS = leftRight == 1 ? "左" : "右"; - //里外 现在无法判断 这个项目全是 里 - String location = "%s-里-%s列%s行"; - return String.format(location, leftRightS, column, row); - } + //到哪里 + if( orderVO.getRow2()==0 ){ + on = "库外"; + }else { + on =orderVO.getRow2()+"层"+orderVO.getColumn2()+"列"+( orderVO.getLeftRight2()==1?"左侧":"右侧"); } - return null; + + return from+"->"+on; } diff --git a/web/src/main/java/com/zhehekeji/web/service/PlcService.java b/web/src/main/java/com/zhehekeji/web/service/PlcService.java index 6ff634a..cc2caca 100644 --- a/web/src/main/java/com/zhehekeji/web/service/PlcService.java +++ b/web/src/main/java/com/zhehekeji/web/service/PlcService.java @@ -4,6 +4,7 @@ import codeDetector.BarcodeDetector; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.zhehekeji.common.util.PathUtil; import com.zhehekeji.web.config.ConfigProperties; +import com.zhehekeji.web.config.MyInitializer; import com.zhehekeji.web.entity.*; import com.zhehekeji.web.lib.*; import com.zhehekeji.web.lib.hik.HCNetSDK; @@ -20,6 +21,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import javax.annotation.Resource; +import java.io.IOException; import java.time.Duration; import java.time.LocalDateTime; import java.util.HashSet; @@ -92,6 +94,8 @@ public class PlcService { return 0; } + @Resource + MyInitializer myInitializer; /** * 开始工单 robotic plcId是plcId,昆船的plcId是来自包体,即srmNumber * @@ -132,6 +136,44 @@ public class PlcService { //todo 昆船的项目 ,取货 放货是独立的 //取货是是不知道放货的位置的,所以订单开始的时候只写1位置 //订单结束写2位置 + + + String path =""; + String path1 =""; + if (street.getCamera1Id() != null) { + Camera camera = cameraService.getId(street.getCamera1Id()); + CameraIO cameraIO = ioMapper.selectOne(new QueryWrapper() + .eq("camera_id", camera.getId()) + .eq("code", "C5")); + + cameraControlModule.toPtz(cameraIO.getPtzId(),camera.getId()); + path = myInitializer.startRecord(camera); + order.setVideoPath1(path); + } + if (street.getCamera2Id() != null) { + Camera camera = cameraService.getId(street.getCamera2Id()); + + CameraIO cameraIO = ioMapper.selectOne(new QueryWrapper() + .eq("camera_id", camera.getId()) + .eq("code", "C5")); + + cameraControlModule.toPtz(cameraIO.getPtzId(),camera.getId()); + path = myInitializer.startRecord(camera); + order.setVideoPath2(path); + } + + if (street.getCamera3Id() != null) { + Camera camera = cameraService.getId(street.getCamera3Id()); + + path = myInitializer.startRecord(camera); + order.setVideoPath3(path); + } + if (street.getCamera4Id() != null) { + Camera camera = cameraService.getId(street.getCamera4Id()); + + path = myInitializer.startRecord(camera); + order.setVideoPath4(path); + } orderMapper.insert(order); OrderRealtime.startOrder(street.getId(), plcCmdInfo.getOrderNum()); } @@ -160,30 +202,34 @@ public class PlcService { Order update = new Order(); update.setId(order.getId()); //将最后一次的拍照算在工单时间 - LocalDateTime endDownLoadTime = endTime.plusNanos(configProperties.getCameraConfig().getC4DelayCaptureTime()*1000000); update.setEndTime(endTime); - Duration duration = Duration.between(order.getStartTime(),endDownLoadTime); - - if(duration.toMinutes() > 50){ - endDownLoadTime = order.getStartTime().plusMinutes(50); - } - String path =""; - String path1 =""; +// +// LocalDateTime endDownLoadTime = endTime.plusNanos(configProperties.getCameraConfig().getC4DelayCaptureTime()*1000000); +// +// Duration duration = Duration.between(order.getStartTime(),endDownLoadTime); +// +// if(duration.toMinutes() > 50){ +// endDownLoadTime = order.getStartTime().plusMinutes(50); +// } if (street.getCamera1Id() != null) { - path = cameraVideo(street.getCamera1Id(),order.getStartTime(),endDownLoadTime); - update.setVideoPath1(path); + Camera camera = cameraService.getId(street.getCamera1Id()); + + myInitializer.stopRecord(camera); } if (street.getCamera2Id() != null) { - path1 = cameraVideo(street.getCamera2Id(),order.getStartTime(),endDownLoadTime); - update.setVideoPath2(path); + Camera camera = cameraService.getId(street.getCamera2Id()); + myInitializer.stopRecord(camera); } if (street.getCamera3Id() != null) { - cameraVideo(street.getCamera1Id(),order.getStartTime(),endDownLoadTime ,path+".mp4"); + Camera camera = cameraService.getId(street.getCamera3Id()); + myInitializer.stopRecord(camera); } if (street.getCamera4Id() != null) { - cameraVideo(street.getCamera2Id(),order.getStartTime(),endDownLoadTime,path1+".mp4"); + Camera camera = cameraService.getId(street.getCamera4Id()); + + myInitializer.stopRecord(camera); } orderMapper.updateById(update); diff --git a/web/src/main/resources/application-prod.yml b/web/src/main/resources/application-prod.yml index 11b926f..e3b8c0a 100644 --- a/web/src/main/resources/application-prod.yml +++ b/web/src/main/resources/application-prod.yml @@ -95,4 +95,10 @@ scanCodeMode: trayCodeTypes: - 14 # 照片 視頻保存多久 -deleteFileDays: 365 \ No newline at end of file +deleteFileDays: 365 + +zlm: + ip: 127.0.0.1 + apiPort: 9000 + zlmApiUrl: http://127.0.0.1:9000/index/api + secret: w3qQt6NyUzSZ1STH9riCVhLbdIosuwf1 \ No newline at end of file diff --git a/web/src/main/resources/mapper/OrderMapper.xml b/web/src/main/resources/mapper/OrderMapper.xml index d0c157e..d9107ea 100644 --- a/web/src/main/resources/mapper/OrderMapper.xml +++ b/web/src/main/resources/mapper/OrderMapper.xml @@ -6,6 +6,9 @@ select t.* from `order` t + + and t.street_id like concat('%', #{streetId},'%') + and t.order_num like concat('%', #{req.orderNum},'%')