|
@@ -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);
|
|
|
}
|
|
|
}
|
|
|
}
|