Преглед на файлове

丰利源LED处理、xml接口文件处理

985653680@qq.com преди 1 година
родител
ревизия
69f16a15b9

+ 16 - 0
src/main/java/com/gzlh/config/hksdk/HkUtils.java

@@ -86,6 +86,22 @@ public class HkUtils {
     }
 
 
+    public boolean getStatus(HCNetSDK hCNetSDK,int userId){
+        HCNetSDK.NET_DVR_BARRIERGATE_CFG net_dvr_barriergate_cfg=new HCNetSDK.NET_DVR_BARRIERGATE_CFG();
+        net_dvr_barriergate_cfg.dwSize=net_dvr_barriergate_cfg.size();
+        net_dvr_barriergate_cfg.dwChannel=1;
+        net_dvr_barriergate_cfg.byLaneNo=1;
+        net_dvr_barriergate_cfg.byBarrierGateCtrl=1;
+        net_dvr_barriergate_cfg.byUnlock=0;
+        net_dvr_barriergate_cfg.byEntranceNo=1;
+        net_dvr_barriergate_cfg.byRes[0]=0;
+        Pointer pointer=  net_dvr_barriergate_cfg.getPointer();
+        net_dvr_barriergate_cfg.write();
+        boolean result=  hCNetSDK.NET_DVR_RemoteControl(userId,HCNetSDK.NET_DVR_CHECK_USER_STATUS,pointer,net_dvr_barriergate_cfg.size());
+//        log.error("检测结果:{},{}" ,userId, result);
+        return result;
+    }
+
     /**
      * 解析时间日期
      * @param time

+ 65 - 16
src/main/java/com/gzlh/device/camera/controller/CameraController.java

@@ -2,25 +2,32 @@ package com.gzlh.device.camera.controller;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.XmlUtil;
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
+import cn.hutool.json.JSONUtil;
+import com.gzlh.bus.EventDataManager;
+import com.gzlh.config.SystemObject;
 import com.gzlh.device.camera.factory.CameraFactory;
 import com.gzlh.device.camera.properties.CameraPropertiesConfig;
+import com.gzlh.entity.ReqBO;
 import com.gzlh.utils.FileUtils;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpHeaders;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 import javax.annotation.Resource;
 import java.io.IOException;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
 
 
 @RestController
-@RequestMapping("/Camera")
+@RequestMapping("/camera")
 public class CameraController {
     @Value("${file.root-path}")
     private String path;
@@ -40,7 +47,9 @@ public class CameraController {
 //        String xmlStr = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
 
         Map<String, Object> StringObjectMap = new HashMap<>();
-
+        Document document = XmlUtil.parseXml(xmlStr);
+        Element rootElement = XmlUtil.getRootElement(document);
+        String i_e_type = rootElement.getAttribute("I_E_TYPE");
         XmlUtil.xmlToMap(xmlStr, StringObjectMap);
 
         Map<String, Object> ic = BeanUtil.beanToMap(StringObjectMap.get("IC"));
@@ -50,30 +59,70 @@ public class CameraController {
         Map<String, Object> seal = BeanUtil.beanToMap(StringObjectMap.get("SEAL"));
 
 
-        Map<String, String> cacheMap = new HashMap<>();
-        cacheMap.put("carEcNo", (String) car.get("CAR_EC_NO"));
-        cacheMap.put("contaIdF", !StringUtils.isEmpty((String) car.get("CONTA_ID_F"))?(String) car.get("CONTA_ID_F"):"");
-        cacheMap.put("contaIdB", !StringUtils.isEmpty((String) car.get("CONTA_ID_B"))?(String) car.get("CONTA_ID_B"):"");
+        Map<String, String> boxNoMap = new HashMap<>();
+//        cacheMap.put("carEcNo", (String) car.get("CAR_EC_NO"));
+        boxNoMap.put("boxNoF", !StringUtils.isEmpty((String) conta.get("CONTA_ID_F"))?(String) conta.get("CONTA_ID_F"):"");
+        boxNoMap.put("boxNoB", !StringUtils.isEmpty((String) conta.get("CONTA_ID_B"))?(String) conta.get("CONTA_ID_B"):"");
 
+        EventDataManager.cacheData("boxNoList",boxNoMap);
 
         Calendar calendar = Calendar.getInstance();
-        String savePath=path+"/"+ calendar.get(Calendar.YEAR)+"-" + (calendar.get(Calendar.MONTH)+1);
 
-        Map<String, String> picMap = new HashMap<>();
+
+        String savePath=path+"/"+SystemObject.applicationConfig.getChannelCode()+"/"+ calendar.get(Calendar.YEAR)+(calendar.get(Calendar.MONTH)+1)+calendar.get(Calendar.DAY_OF_MONTH);
+
+        List<String> fList = new ArrayList();
+        List<String> bList = new ArrayList();
         for (Map.Entry<String, Object> entry : conta.entrySet()) {
             if(entry.getKey().contains("PIC")&& !StringUtils.isEmpty((String) entry.getValue())){
                 String filePath = FileUtils.downLoad((String) entry.getValue(),savePath);
-                String base64 = FileUtils.getBase64FromImg(filePath);
-                picMap.put(entry.getKey(),base64);
+//                String base64 = FileUtils.getBase64FromImg(filePath);
+                if (entry.getKey().contains("CONTA_F")){
+                    fList.add(filePath);
+                }else if (entry.getKey().contains("CONTA_B")){
+                    bList.add(filePath);
+                }
             }
         }
+        EventDataManager.cacheData("boxFImgList",fList);
+        EventDataManager.cacheData("boxBImgList",bList);
 
-        // TODO: 2023/11/10
-        cameraFactory.handler(cameraPropertiesConfig.getBrand()).handlerAction("");
-
+//        // TODO: 2023/11/10
+//        cameraFactory.handler(cameraPropertiesConfig.getBrand()).handlerAction("");
 
+        request("",JSONUtil.toJsonStr(EventDataManager.getCacheData()));
 
     }
 
 
+    public void request(String url,String json) {
+
+        HttpHeaders headers = new HttpHeaders();
+        url = "http://192.168.1.8:9191/open/submit";
+        long startTime = System.currentTimeMillis();
+        System.out.println(startTime);
+
+        String body = json;
+//        String method = Thread.currentThread().getStackTrace()[1].getMethodName();
+        try {
+//            System.out.printf("%s/请求地址:%s,请求头:%s,  请求体:%s ", method,url, headers, body);
+
+            System.out.println();
+//            log.info("【{}/{}】请求地址:{},请求头:{},  请求体:{} ", OperateTypeEnum.OPERATE_TYPE_2.desc, logContent, url, headers, body);
+            HttpResponse res = HttpRequest.post(url)
+                    .header("Content-Type", "application/json;character=utf-8;")
+                    .body(body)
+                    .execute();
+            String bodyResult = res.body();
+            System.out.printf("ReqStatus:%s,返回结果:{%s} ",res.getStatus(), bodyResult);
+
+//            if(200 == res.getStatus()){
+//
+//            }
+
+        } catch (Exception e) {
+
+        }
+    }
+
 }

+ 5 - 3
src/main/java/com/gzlh/device/led/handler/impl/LedHandlerFengLiYuan.java

@@ -2,6 +2,7 @@ package com.gzlh.device.led.handler.impl;
 
 import com.gzlh.device.infrared.brand.RedBrandType;
 import com.gzlh.device.led.action.FengLiYuanCmdEnum;
+import com.gzlh.device.led.action.LedAction;
 import com.gzlh.device.led.brand.LedBrandType;
 import com.gzlh.device.led.client.LedNettyConfig;
 import com.gzlh.device.led.handler.ILedHandler;
@@ -42,10 +43,11 @@ public class LedHandlerFengLiYuan implements ILedHandler {
     @Override
     public void handlerAction(String action) {
         String command=null;
-        if (action.contains("LED_SHOW_CONTENT")){
-            command= FengLiYuanCmdEnum.ETERNAL.getCode();
+        if (action.contains(LedAction.LED_SHOW_CONTENT)){
+            command= FengLiYuanCmdEnum.TEMP.getCode();
             String content = action.substring(action.indexOf("(")+1, action.indexOf(")"));
-            String pack = FengLiYuanPackage.buildPackage(command,WordHandlerUtils.msgToASCII(content));
+            String data = FengLiYuanPackage.tempMsg("", "", "", "", "", content);
+            String pack = FengLiYuanPackage.buildPackage(command,data);
             sendMsg(pack);
         }
         log.info("action:{}",action);

+ 76 - 5
src/main/java/com/gzlh/device/led/utils/FengLiYuanPackage.java

@@ -1,11 +1,11 @@
 package com.gzlh.device.led.utils;
 
+import com.gzlh.config.SystemObject;
 import com.gzlh.device.led.action.FengLiYuanCmdEnum;
 import com.gzlh.utils.WordHandlerUtils;
+import org.springframework.util.StringUtils;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
+import java.util.*;
 
 public class FengLiYuanPackage {
     /**
@@ -15,7 +15,7 @@ public class FengLiYuanPackage {
 
     private static final String LedAddr="01";
 
-    private static final String send="01";
+    private static final String send="00";
 
 
     public static String buildPackage(String command,String data) {
@@ -36,7 +36,7 @@ public class FengLiYuanPackage {
         }
         String dataStr = HEAD+len+str;
 
-        return xorComputeResult(dataStr);
+        return xorComputeResult(dataStr.toUpperCase());
     }
 
     //输入字符串进行异或校验,并加上校验结果
@@ -65,4 +65,75 @@ public class FengLiYuanPackage {
         String str = list.toString().substring(1, list.toString().length() - 1);
         return str.replaceAll(", ", "");
     }
+
+    public static String eternalMsg(String line,String showType, String date,String speed,String color,String data) {
+//        line 行号01为第一行,02为第二行,03为第三行,04为第四行,05为第五行,06为第六行,07为第七行,08为第八行
+//        showType 显示方式00 左移入 01 上移入 02 下移入 03 左展入 04 右展入 05 上展入 06 下展入 07 横向展开 08 横向闭合 09 纵向展开 0A 纵向闭合 0B 同时显示
+//        date 日期显示方式 00 固定信息 01日期+固定信息 02 日期
+//        speed 速度 00—05 备注:00最快,05最慢
+//        color 颜色 01 红色 02 绿色 03 黄色 04 蓝色 05 粉色 06 青色 07 白色
+        line=StringUtils.isEmpty(line)?"01":line;
+        showType=StringUtils.isEmpty(showType)?"00":showType;
+        date=StringUtils.isEmpty(date)?"00":date;
+        speed=StringUtils.isEmpty(speed)?"02":speed;
+        color=StringUtils.isEmpty(color)?"01":color;
+        String ascii = WordHandlerUtils.msgToASCII(data);
+        String len = Integer.toHexString(ascii.length() / 2).toUpperCase();
+        if (len.length() == 1) {
+            len = '0' + len;
+        }
+        return line+showType+date+speed+color+len+ascii;
+    }
+
+    public static String tempMsg(String line,String showType, String time,String speed,String color,String data) {
+//        line 行号01为第一行,02为第二行,03为第三行,04为第四行,05为第五行,06为第六行,07为第七行,08为第八行
+//        showType 显示方式00 左移入 01 上移入 02 下移入 03 左展入 04 右展入 05 上展入 06 下展入 07 横向展开 08 横向闭合 09 纵向展开 0A 纵向闭合 0B 同时显示
+//        time 停留时间 00—ff 备注:00表示0秒,0秒处理为永久显示 05表示停留5秒,FF表示停留255秒 停留时间到后,LED显示临时信息自动切换到显示固定信息
+//        speed 速度 00—05 备注:00最快,05最慢
+//        color 颜色 01 红色 02 绿色 03 黄色 04 蓝色 05 粉色 06 青色 07 白色
+        line=StringUtils.isEmpty(line)?"01":line;
+        showType=StringUtils.isEmpty(showType)?"00":showType;
+        time=StringUtils.isEmpty(time)?"00":time;
+        speed=StringUtils.isEmpty(speed)?"02":speed;
+        color=StringUtils.isEmpty(color)?"01":color;
+        String ascii = WordHandlerUtils.msgToASCII(data);
+        String len = Integer.toHexString(ascii.length() / 2).toUpperCase();
+        if (len.length() == 1) {
+            len = '0' + len;
+        }
+        return line+showType+time+speed+color+len+ascii;
+    }
+
+
+    public static void main(String[] args) {
+//        String line1=tempMsg("01", "0B", "05", "00", "", "粤A.12345");
+//        String line2=tempMsg("02", "00", "00", "00", "", "请交费10元");
+        Calendar calendar = Calendar.getInstance();
+        Date date = new Date();
+
+
+        String hour =""+ calendar.get(Calendar.HOUR_OF_DAY);
+        String minute =""+calendar.get(Calendar.MINUTE);
+        String second =""+calendar.get(Calendar.SECOND);
+        if (hour.length()<2){
+            hour="0"+hour;
+        }
+        if (minute.length()<2){
+            minute="0"+minute;
+        }
+        if (second.length()<2){
+            second="0"+second;
+        }
+        System.out.println(hour+","+minute+","+second);
+        String line1=eternalMsg("01", "00", "01", "00", "", "欢迎光临");
+        String line2=eternalMsg("02", "00", "00", "00", "", "深圳市[@2]丰利源[@3]有限公司");
+
+        System.out.println(line1+","+line1.length());
+
+        System.out.println(line2+","+line2.length());
+        String s = buildPackage(FengLiYuanCmdEnum.ETERNAL.getCode(), line1 + line2);
+
+//        String s = buildPackage(FengLiYuanCmdEnum.TEMP.getCode(), line1 + line2);
+        System.out.println(s);
+    }
 }

+ 7 - 6
src/main/java/com/gzlh/entity/ReqBO.java

@@ -5,9 +5,7 @@ import lombok.experimental.Accessors;
 import org.springframework.context.annotation.Lazy;
 
 import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 @Data
 @Accessors(chain = true)
@@ -35,11 +33,14 @@ public class ReqBO implements Serializable {
     /**
      * 车厢号
      */
-    private List<String> boxNoList=new ArrayList<>();
+    private Map<String,String> boxNoList=new HashMap<>();
     /**
-     * 箱号图片 base64
+     * 前后箱号图片List base64
      */
-    private List<String> boxImgList=new ArrayList<>();
+    private List<String> boxFImgList=new ArrayList<>();
+
+    private List<String> boxBImgList=new ArrayList<>();
+
     /**
      * 采集时间
      */

+ 6 - 6
src/main/java/com/gzlh/utils/DeviceCache.java

@@ -5,21 +5,21 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 public class DeviceCache {
-    private static Map<String,String> map = new ConcurrentHashMap<String,String>();
+    private static Map<String,Object> map = new ConcurrentHashMap<String,Object>();
 
-    public static void add(String k,String v){
+    public static void add(String k,Object v){
         map.put(k,v);
     }
 
-    public static String get(String k){
+    public static Object get(String k){
         return map.get(k);
     }
 
-    public static String remove(String k){
-        return map.remove(k);
+    public static void remove(String k){
+        map.remove(k);
     }
 
-    public static Map<String,String> getCacheMap(){
+    public static Map<String,Object> getCacheMap(){
         return map;
     }
 }

+ 17 - 2
src/main/java/com/gzlh/utils/FileUtils.java

@@ -27,7 +27,22 @@ public class FileUtils {
                 folder.mkdirs();
             }
             String fileName = new File(url.getFile()).getName();
-            out = new FileOutputStream(savePath+"/"+fileName);
+            String suffix = fileName.substring(fileName.lastIndexOf("."));
+            Calendar calendar = Calendar.getInstance();
+            String hour =""+ calendar.get(Calendar.HOUR_OF_DAY);
+            String minute =""+calendar.get(Calendar.MINUTE);
+            String second =""+calendar.get(Calendar.SECOND);
+            if (hour.length()<2){
+                hour="0"+hour;
+            }
+            if (minute.length()<2){
+                minute="0"+minute;
+            }
+            if (second.length()<2){
+                second="0"+second;
+            }
+            String path=savePath+"/"+hour+minute+second+suffix;
+            out = new FileOutputStream(path);
 
             byte[] buffer = new byte[1024];
             int bytesRead;
@@ -35,7 +50,7 @@ public class FileUtils {
                 out.write(buffer, 0, bytesRead);
             }
             System.out.println("文件下载完成!");
-            return savePath+"/"+fileName;
+            return path;
         } catch (Exception e) {
             throw e;
         }finally {

+ 2 - 2
src/main/java/com/gzlh/utils/WordHandlerUtils.java

@@ -21,8 +21,8 @@ public class WordHandlerUtils {
                 sb.append(chineseToASCII(bit));
             }else if (Character.isDigit(ch)){//数字
                 sb.append(Integer.parseInt(bit) + 30);
-            }else if (StrUtil.equals(".", bit)) {
-                sb.append("2E");
+            }else {
+                sb.append(Integer.toHexString(ch).toUpperCase());
             }
         }
         return sb.toString();