Browse Source

Merge branch 'master' of http://git.aseanbusiness.cn/qzyReal/gather-server

# Conflicts:
#	src/main/java/com/gzlh/background/client/BackgroundClientHandler.java
#	src/main/java/com/gzlh/device/led/brand/LedBrandType.java
#	src/main/java/com/gzlh/device/led/handler/impl/LedHandlerFengLiYuan.java
#	src/main/java/com/gzlh/utils/WordHandlerUtils.java
qzyReal 11 months ago
parent
commit
55a0e4eef1

+ 8 - 4
src/main/java/com/gzlh/background/client/BackgroundClientHandler.java

@@ -3,6 +3,8 @@ package com.gzlh.background.client;
 import cn.hutool.json.JSONUtil;
 import com.gzlh.background.properties.BackgroundPropertiesConfig;
 import com.gzlh.bus.EventBus;
+import com.gzlh.bus.EventDataManager;
+import com.gzlh.config.SystemObject;
 import com.gzlh.utils.DeviceCache;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
@@ -31,15 +33,16 @@ public class BackgroundClientHandler extends SimpleChannelInboundHandler<String>
 
     @Override
     protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
-//        System.out.println("Client received: " + msg);
-        if (!"Heartbeat".equalsIgnoreCase(msg)){
-            eventBus.startEvent(msg);
-        }
+        System.out.println("Client received: " + msg);
+//        if (!"back message".equalsIgnoreCase(msg)){
+//            eventBus.startEvent(msg);
+//        }
     }
 
 
     protected void sendHeartbeat(ChannelHandlerContext context) {
 //        向后台发送设备信息json字符串
+        DeviceCache.add("channelCode", SystemObject.applicationConfig.getChannelCode());
         String jsonStr = JSONUtil.toJsonStr(DeviceCache.getCacheMap());
         context.writeAndFlush(jsonStr);
 //        System.out.println(" sent ping msg to " + context.channel().remoteAddress());
@@ -74,6 +77,7 @@ public class BackgroundClientHandler extends SimpleChannelInboundHandler<String>
     protected void handleWriterIdle(ChannelHandlerContext ctx) {
         //写空闲时发送心跳包
         sendHeartbeat(ctx);
+
 //        System.err.println("---WRITER_IDLE---");
     }
 

+ 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) {
+
+        }
+    }
+
 }

+ 40 - 0
src/main/java/com/gzlh/device/led/action/FengLiYuanCmdEnum.java

@@ -0,0 +1,40 @@
+package com.gzlh.device.led.action;
+
+public enum FengLiYuanCmdEnum {
+
+    ETERNAL("01","固定文字信息(永久保存)"),
+    TEMP("02","临时文字信息(不保存)"),
+    CLEAR_LINE("03","清除行临时信息"),
+    CLEAR_ALL("04","清除全部临时信息"),
+    ADJUST_BRIGHTNESS("05","亮度调节"),
+    CORRECTION_TIME("06","校正时间"),
+    TRAFFIC_LIGHT("07","控制红绿灯"),
+    VOICE_MSG("08","播放语音"),
+    PARKING_GUIDE("09","车位引导(不保存)"),
+    SEND_IMG_LEN("0A","发送图片的长度(bmp文件)(永久保存)"),
+    SEND_IMG_CONTENT("0B","发送图片的内容(永久保存)"),
+    SHOW_IMG("0C","显示固定图片(永久保存)"),
+    POWERUP_DISPLAY("0E","开机显示"),
+    RELAY_SWITCH("0F","控制继电器"),
+    TOTAL_PARKING_PLACE("10","总车位(关机保存)"),
+    QR_CODE("11","二维码");
+
+    private final String code;
+    private final String info;
+
+    FengLiYuanCmdEnum(String code, String info) {
+        this.code = code;
+        this.info = info;
+    }
+
+
+    public String getCode()
+    {
+        return code;
+    }
+
+    public String getInfo()
+    {
+        return info;
+    }
+}

+ 2 - 1
src/main/java/com/gzlh/device/led/brand/LedBrandType.java

@@ -8,7 +8,8 @@ import lombok.Getter;
 public enum  LedBrandType {
 
     SHANGHAI_YANGBAND_BX(1000,"上海仰邦科技股份有限公司BX-5(M)K/6K(YY)-V4.2"),
-    FEND_LI_YUAN(2000,"丰利源"),
+    FENGLIYUAN(2000,"深圳市丰利源光电有限公司")
+
 
     ;
 

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

@@ -27,7 +27,7 @@ public class LedHandlerFengLiYuan implements ILedHandler {
     @Override
     public void sendMsg(String content, LedOptions options) {
         log.info("丰利源发送led消息:{}",content);
-       String msgHex= FengLiYuanPackUtils.build(content,options);
+        String msgHex= FengLiYuanPackUtils.build(content,options);
         log.info("数据包:{}",msgHex);
         ledNettyConfig.send(msgHex);
     }

+ 139 - 0
src/main/java/com/gzlh/device/led/utils/FengLiYuanPackage.java

@@ -0,0 +1,139 @@
+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.*;
+
+public class FengLiYuanPackage {
+    /**
+     * 帧头
+     */
+    private static final String HEAD = "F501";
+
+    private static final String LedAddr="01";
+
+    private static final String send="00";
+
+
+    public static String buildPackage(String command,String data) {
+        //包数据= 起始字(两字节长度,固定0xF5,0x01)+长度(两字节长度)+屏地址+命令+发送+数据+总包校验
+        //长度=2Byte,从[屏地址]到[数据]最后字节。高字节在前,低字节在后。
+        //发送=0X00=发送,不需要应答,0X01=发送,需要应答
+        //数据=N Byte,可以为空
+        //总包校验=1byte,是从[起始字]到[数据]最后字节所有字节的异或校验
+
+        String str=LedAddr+command+send+data;
+
+        StringBuilder len = new StringBuilder(Integer.toHexString(str.length() / 2));
+        if (len.length()>4){
+            throw new RuntimeException("数据超出长度");
+        }
+        while (len.length()<4){
+            len.insert(0, "0");
+        }
+        String dataStr = HEAD+len+str;
+
+        return xorComputeResult(dataStr.toUpperCase());
+    }
+
+    //输入字符串进行异或校验,并加上校验结果
+    public static String xorComputeResult(String data) {
+
+        if (data.length()%2!=0){
+            return null;
+        }
+        int xorCheckSum = 0;
+        List<String> list= new ArrayList<>();
+        for (int i=0;i<data.length();i+=2){
+            list.add(data.substring(i,i+2));
+        }
+
+        for (int i = 0; i < list.size(); i++) {
+            xorCheckSum^=Integer.valueOf(list.get(i),16);
+        }
+//        System.out.println(xorCheckSum);
+        String hex = Integer.toHexString(xorCheckSum);
+        if (hex.length() == 1) {
+            hex = '0' + hex;
+        }
+
+        list.add(hex.toUpperCase(Locale.getDefault()));
+
+        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 {