Sfoglia il codice sorgente

海康设备抬杆

qzyReal 2 anni fa
parent
commit
804b596815

+ 1 - 5
sp-core/src/main/java/com/pj/project/hc_camera/HcCameraService.java

@@ -81,10 +81,6 @@ public class HcCameraService extends ServiceImpl<HcCameraMapper, HcCamera> imple
 
 
     public void open(HcCamera h) {
-        HCNetSDK.NET_DVR_SNAPCFG net_dvr_snapcfg=new HCNetSDK.NET_DVR_SNAPCFG();
-        net_dvr_snapcfg.dwSize=net_dvr_snapcfg.size();
-        boolean result= hcNetSDK.NET_DVR_ContinuousShoot(h.getUserId(),net_dvr_snapcfg);
-        log.error("操作,错误码为" + result);
-        log.error("操作,错误码为" + hcNetSDK.NET_DVR_GetLastError());
+        hkUtils.handlerUp(hcNetSDK, h.getUserId());
     }
 }

+ 92 - 15
sp-core/src/main/java/com/pj/project/hksdk/AlarmParseService.java

@@ -1,19 +1,33 @@
 package com.pj.project.hksdk;
 
+import cn.hutool.cache.CacheUtil;
+import cn.hutool.cache.impl.TimedCache;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.ByteUtil;
 import cn.hutool.core.util.StrUtil;
+import com.pj.current.config.SystemObject;
+import com.pj.project.tb_car_black.TbCarBlack;
+import com.pj.project.tb_car_black.TbCarBlackService;
+import com.pj.project.tb_car_filing.TbCarFiling;
+import com.pj.project.tb_car_filing.TbCarFilingService;
+import com.pj.project.tb_car_visit_record.TbCarVisitRecord;
+import com.pj.project.tb_car_visit_record.TbCarVisitRecordService;
+import com.pj.project.tb_dept.TbDept;
+import com.pj.project.tb_dept.TbDeptService;
+import com.pj.project4sp.uploadfile.UploadConfig;
+import com.pj.project4sp.uploadfile.UploadUtil;
 import com.sun.jna.Pointer;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
+import java.io.*;
 import java.nio.ByteBuffer;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 报警处理
@@ -22,7 +36,23 @@ import java.util.Date;
 @Slf4j
 public class AlarmParseService {
     @Resource
+    @Lazy
     private HkUtils hkUtils;
+    @Resource
+    @Lazy
+    private HCNetSDK hcNetSDK;
+    @Resource
+    private TbCarFilingService tbCarFilingService;
+    @Resource
+    private TbCarBlackService tbCarBlackService;
+    @Resource
+    public UploadConfig uploadConfig;
+    @Resource
+    private TbCarVisitRecordService tbCarVisitRecordService;
+    @Resource
+    private TbDeptService tbDeptService;
+
+    TimedCache<String, Integer> CACHE_MAP = CacheUtil.newTimedCache(20000);
 
     public void alarmDataHandle(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
         //lCommand是传的报警类型
@@ -32,41 +62,88 @@ public class AlarmParseService {
             Pointer pItsPlateInfo = strItsPlateResult.getPointer();
             pItsPlateInfo.write(0, pAlarmInfo.getByteArray(0, strItsPlateResult.size()), 0, strItsPlateResult.size());
             strItsPlateResult.read();
-            String sLicense = null;
+            String sLicense;
             try {
                 sLicense = new String(strItsPlateResult.struPlateInfo.sLicense, "GBK");
             } catch (UnsupportedEncodingException e) {
-                e.printStackTrace();
+                log.error("上传车牌为空:{}", e.getMessage());
+                return;
             }
             int color = strItsPlateResult.struPlateInfo.byColor;
             byte VehicleType = strItsPlateResult.byVehicleType;  //0-其他车辆,1-小型车,2-大型车,3- 行人触发,4- 二轮车触发,5- 三轮车触发,6- 机动车触发
             log.info("车牌号:{} ;车辆类型:{}", sLicense, VehicleType);
-
+            String now = DateUtil.now();
+            sLicense = StrUtil.trim(StrUtil.sub(sLicense, 1, -1));
+            if (CACHE_MAP.get(sLicense) != null) {
+                log.error("重复上传:{}", sLicense);
+                return;
+            }
+            TbCarBlack tbCarBlack = tbCarBlackService.findByCarNo(sLicense, now);
+            TbCarVisitRecord record = new TbCarVisitRecord();
+            boolean allowPass = true;
+            Date nowTime = new Date();
+            String reason = "";
+            if (tbCarBlack != null) {
+                allowPass = false;
+                reason = "车辆黑名单,不抬杆";
+                log.error(reason + ":{}", sLicense);
+            }
+            List<TbCarFiling> carFilingList = tbCarFilingService.findByCarNo(sLicense);
+            if (carFilingList.isEmpty()) {
+                allowPass = false;
+                reason = "车辆未备案,不抬杆";
+                log.error(reason + ":{}", sLicense);
+            } else {
+                TbCarFiling tbCarFiling = carFilingList.get(0);
+                record.setDepartmentId(tbCarFiling.getDepartmentId()).setVenuesId(tbCarFiling.getVenuesId())
+                        .setVisitTime(nowTime).setDriverContact(tbCarFiling.getDriverContact()).setDriverName(tbCarFiling.getDriverName())
+                        .setDriverIdCard(tbCarFiling.getDriverIdCard());
+                TbDept tbDept = tbDeptService.getById(tbCarFiling.getDeptId());
+                record.setDeptName(tbDept.getName());
+            }
+            if (allowPass) {
+                log.info("开始抬杆:{}", sLicense);
+                hkUtils.handlerUp(hcNetSDK, pAlarmer.lUserID);
+            }
+            record.setReason(reason).setAllowPass(allowPass ? 1 : 0).setRecordType(2)
+                    .setVisitTime(nowTime)
+                    .setCreateTime(nowTime).setUpdateTime(nowTime)
+                    .setCarNo(sLicense).setDirection(1);
             /**
              * 报警图片保存,车牌,车辆图片
              */
-            for (int i = 0; i < strItsPlateResult.dwPicNum; i++) {
-                if (strItsPlateResult.struPicInfo[i].dwDataLen > 0) {
-                    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
-                    String newName = sf.format(new Date());
+            if (strItsPlateResult.struPicInfo.length > 0) {
+                HCNetSDK.NET_ITS_PICTURE_INFO net_its_picture_info = strItsPlateResult.struPicInfo[0];
+                if (net_its_picture_info.dwDataLen > 0) {
+                    String currDateFolder = new SimpleDateFormat("/yyyy/MM-dd").format(nowTime);
+                    String newName = DateUtil.format(nowTime, "yyyyMMddHHmmss");
                     FileOutputStream fout;
                     try {
-                        String filename = "../pic/" + newName + "_type[" + strItsPlateResult.struPicInfo[i].byType + "]_ItsPlate.jpg";
-                        fout = new FileOutputStream(filename);
+                        // 文件名
+                        String fileName = newName + "_ItsPlate.jpg";
+                        // 需要保存到的文件夹地址
+                        String fileFolder = new File(uploadConfig.rootFolder).getAbsolutePath() + "/" +
+                                uploadConfig.httpPrefix + "/hk" + currDateFolder + "/";
+                        FileUtil.mkdir(fileFolder);
+                        fout = new FileOutputStream(fileFolder + fileName);
                         //将字节写入文件
                         long offset = 0;
-                        ByteBuffer buffers = strItsPlateResult.struPicInfo[i].pBuffer.getByteBuffer(offset, strItsPlateResult.struPicInfo[i].dwDataLen);
-                        byte[] bytes = new byte[strItsPlateResult.struPicInfo[i].dwDataLen];
+                        ByteBuffer buffers = net_its_picture_info.pBuffer.getByteBuffer(offset, net_its_picture_info.dwDataLen);
+                        byte[] bytes = new byte[net_its_picture_info.dwDataLen];
                         buffers.rewind();
                         buffers.get(bytes);
                         fout.write(bytes);
                         fout.close();
+                        String httpUrl = SystemObject.config.getDomain() + uploadConfig.httpPrefix + "/hk" + currDateFolder + "/" + fileName;
+                        record.setImage(httpUrl);
                     } catch (IOException e) {
                         // TODO Auto-generated catch block
                         e.printStackTrace();
                     }
                 }
             }
+            tbCarVisitRecordService.save(record);
+            CACHE_MAP.put(sLicense, 1);
         }
     }
 }

+ 15 - 6
sp-core/src/main/java/com/pj/project/hksdk/HCNetSDK.java

@@ -685,6 +685,7 @@ public interface HCNetSDK extends Library {
 
     public static final int NET_DVR_GET_SUPPLEMENTLIGHT = 3728;  //获取内置补光灯配置协议
     public static final int NET_DVR_SET_SUPPLEMENTLIGHT = 3729;  //设置内置补光灯配置协议
+    public static final int NET_DVR_BARRIERGATE_CTRL = 3128;  //远程控制道闸
 
     public static final int NET_DVR_GET_FACECONTRAST_TRIGGER = 3965;//获取人脸比对联动配置
     public static final int NET_DVR_SET_FACECONTRAST_TRIGGER = 3966;//设置人脸比对联动配置
@@ -3469,7 +3470,7 @@ DVR实现巡航数据结构
         public short wTransProtol;        //传输协议,0-TCP, 1-UDP, 2-MCAST
         public short wPassivePort;        //TCP,UDP时为TCP,UDP端口, MCAST时为MCAST端口
         public NET_DVR_IPADDR struMcastIP;        //TCP,UDP时无效, MCAST时为多播地址
-        public byte  byStreamType;  //数据播放模式:1- 实时流,2- 文件流
+        public byte byStreamType;  //数据播放模式:1- 实时流,2- 文件流
         public byte[] res = new byte[7];
     }
 /************************************多路解码器(end)***************************************/
@@ -3947,7 +3948,6 @@ DVR实现巡航数据结构
     ;
 
 
-
     public static class NET_DVR_STREAM_INFO extends Structure {
         public int dwSize;
         public byte[] byID = new byte[32];
@@ -4203,7 +4203,6 @@ DVR实现巡航数据结构
     }
 
 
-
     //图片查找条件
     public static class NET_DVR_FIND_PICTURE_PARAM extends Structure {
         public int dwSize;         // 结构体大小
@@ -5141,6 +5140,14 @@ DVR实现巡航数据结构
         public byte[] byRes2 = new byte[16];
     }
 
+    class NET_DVR_GATELAMP_INFO extends Structure {
+        public int dwSize;
+        public int dwChannel;
+        public byte byLaneNo;
+        public byte byBrightlampCtrl ;
+        public byte[] byRes = new byte[12];
+    }
+
     // 道闸控制
     public static class NET_DVR_BARRIERGATE_CFG extends Structure {
         public int dwSize;
@@ -7134,7 +7141,7 @@ DVR实现巡航数据结构
         public byte byModelingStatus;// 建模状态
         public byte byLivenessDetectionStatus;//活体检测状态:0-保留,1-未知(检测失败),2-非真人人脸,3-真人人脸,4-未开启活体检测
         public byte cTimeDifferenceH;         /*与UTC的时差(小时),-12 ... +14, +表示东区,0xff无效*/
-        public byte cTimeDifferenceM;      	/*与UTC的时差(分钟),-30, 30, 45, +表示东区,0xff无效*/
+        public byte cTimeDifferenceM;        /*与UTC的时差(分钟),-30, 30, 45, +表示东区,0xff无效*/
         public byte byMask;                //抓拍图是否戴口罩,0-保留,1-未知,2-不戴口罩,3-戴口罩
         public byte bySmile;               //抓拍图是否微笑,0-保留,1-未知,2-不微笑,3-微笑
         public byte byContrastStatus;      //比对结果,0-保留,1-比对成功,2-比对失败
@@ -9410,7 +9417,6 @@ DVR实现巡航数据结构
     }
 
 
-
     public static interface FStdDataCallBack extends Callback {
         public void invoke(int lRealHandle, int dwDataType, ByteByReference pBuffer, int dwBufSize, int dwUser);
     }
@@ -9507,7 +9513,6 @@ DVR实现巡航数据结构
     boolean NET_DVR_UnlockFileByName(int lUserID, String sUnlockFileName);
 
 
-
     boolean NET_DVR_PlayBackControl(int lPlayHandle, int dwControlCode, int dwInValue, IntByReference LPOutValue);
 
     boolean NET_DVR_PlayBackControl_V40(int lPlayHandle, int dwControlCode, Pointer lpInBuffer, int dwInLen, Pointer lpOutBuffer, IntByReference lpOutLen);
@@ -9977,8 +9982,11 @@ DVR实现巡航数据结构
     boolean NET_DVR_MatrixGetLoopDecChanInfo_V41(int lUserID, int dwDecChanNum, NET_DVR_MATRIX_LOOP_DECINFO_V41 lpOuter);
 
     boolean NET_DVR_MatrixSetLoopDecChanInfo_V41(int lUserID, int dwDecChanNum, NET_DVR_MATRIX_LOOP_DECINFO_V41 lpInter);
+
     int NET_DVR_MatrixStartPassiveDecode(int lUserID, int dwDecChanNum, Pointer lpPassiveMode);
+
     boolean NET_DVR_MatrixSendData(int lPassiveHandle, Pointer pSendBuf, int dwBufSize);
+
     boolean NET_DVR_MatrixStopPassiveDecode(int lPassiveHandle);
 
     //2007-12-22 增加支持接口 //18
@@ -10097,6 +10105,7 @@ DVR实现巡航数据结构
     boolean NET_DVR_StopRemoteConfig(int lHandle);
 
     boolean NET_DVR_RemoteControl(int lUserID, int dwCommand, Pointer lpInBuffer, int dwInBufferSize);
+//    boolean NET_DVR_RemoteControl(int lUserID, int dwCommand, NET_DVR_BARRIERGATE_CFG lpInBuffer, int dwInBufferSize);
 
     boolean NET_DVR_STDXMLConfig(int lUserID, NET_DVR_XML_CONFIG_INPUT lpInputParam, NET_DVR_XML_CONFIG_OUTPUT lpOutputParam);
 

+ 19 - 0
sp-core/src/main/java/com/pj/project/hksdk/HkUtils.java

@@ -1,6 +1,7 @@
 package com.pj.project.hksdk;
 
 import cn.hutool.log.StaticLog;
+import com.sun.jna.Pointer;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
@@ -66,6 +67,24 @@ public class HkUtils {
 
     }
 
+    public boolean handlerUp(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_BARRIERGATE_CTRL,pointer,net_dvr_barriergate_cfg.size());
+        log.error("抬杆结果:{},{}" ,userId, result);
+        log.error("操作结果码" + hCNetSDK.NET_DVR_GetLastError());
+        return result;
+    }
+
+
     /**
      * 解析时间日期
      * @param time

+ 1 - 1
sp-core/src/main/java/com/pj/utils/cache/RedisUtil.java

@@ -130,7 +130,7 @@ public class RedisUtil {
 
     public static void lPush(String key, String value) {
         redisTemplate.opsForList().leftPush(key, value);
-        redisTemplate.expire(key, 80, TimeUnit.SECONDS);
+        redisTemplate.expire(key, 60, TimeUnit.MINUTES);
     }
 
     public static String rPorp(String key) {

+ 2 - 2
sp-start/src/main/resources/application-dev.yml

@@ -47,8 +47,8 @@ spring:
     myconfig:
         # 本项目部署到的服务器域名(文件上传等等模块  要用到)
         domain: http://127.0.0.1:8099/pro
-        ip: 192.168.88.119
-        net-ip: 192.168.88.119
+        ip: 192.168.88.128
+        net-ip: 192.168.88.128
         heart-port: 9999
         command-port: 8888
         command-prefix: "command:"