|
@@ -1,10 +1,14 @@
|
|
|
-package com.gzlh.hksdk;
|
|
|
+package com.gzlh.config.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.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.gzlh.device.capture.task.HandlerCarImage;
|
|
|
+import com.gzlh.config.FilePropertiesConfig;
|
|
|
+import com.gzlh.config.task.TaskService;
|
|
|
import com.sun.jna.Pointer;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
@@ -17,8 +21,8 @@ import java.io.IOException;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.nio.ByteBuffer;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 报警处理
|
|
@@ -32,12 +36,18 @@ public class AlarmParseService {
|
|
|
@Resource
|
|
|
@Lazy
|
|
|
private HCNetSDK hcNetSDK;
|
|
|
+ @Resource
|
|
|
+ @Lazy
|
|
|
+ private FilePropertiesConfig filePropertiesConfig;
|
|
|
+ @Resource
|
|
|
+ TaskService taskService;
|
|
|
|
|
|
|
|
|
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是传的报警类型
|
|
|
+ String separator=File.separator;
|
|
|
if (lCommand == HCNetSDK.COMM_ITS_PLATE_RESULT) {//交通抓拍结果(新报警信息)
|
|
|
HCNetSDK.NET_ITS_PLATE_RESULT strItsPlateResult = new HCNetSDK.NET_ITS_PLATE_RESULT();
|
|
|
strItsPlateResult.write();
|
|
@@ -51,10 +61,9 @@ public class AlarmParseService {
|
|
|
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();
|
|
|
+// int color = strItsPlateResult.struPlateInfo.byColor;
|
|
|
+// byte VehicleType = strItsPlateResult.byVehicleType; //0-其他车辆,1-小型车,2-大型车,3- 行人触发,4- 二轮车触发,5- 三轮车触发,6- 机动车触发
|
|
|
+// log.info("车牌号:{} ;车辆类型:{}", sLicense, VehicleType);
|
|
|
sLicense = StrUtil.trim(StrUtil.sub(sLicense, 1, -1));
|
|
|
if (CACHE_MAP.get(sLicense) != null) {
|
|
|
log.error("重复上传:{}", sLicense);
|
|
@@ -69,16 +78,18 @@ public class AlarmParseService {
|
|
|
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");
|
|
|
+ String currDateFolder = new SimpleDateFormat("MM-dd").format(nowTime);
|
|
|
+ String newName = DateUtil.format(nowTime, "yyyyMMddHHmm");
|
|
|
FileOutputStream fout;
|
|
|
try {
|
|
|
// 文件名
|
|
|
- String fileName = newName + "_ItsPlate.jpg";
|
|
|
+ String fileName =sLicense+"-" +newName + ".jpg";
|
|
|
// 需要保存到的文件夹地址
|
|
|
- String fileFolder="";
|
|
|
+ String fileFolder=filePropertiesConfig.getRootPath()+ LocalDate.now().getYear() +currDateFolder;;
|
|
|
FileUtil.mkdir(fileFolder);
|
|
|
- fout = new FileOutputStream(fileFolder + fileName);
|
|
|
+ String filePath=fileFolder +separator+ fileName;
|
|
|
+ log.info("车牌保存路径:{},{}",sLicense,filePath);
|
|
|
+ fout = new FileOutputStream(filePath);
|
|
|
//将字节写入文件
|
|
|
long offset = 0;
|
|
|
ByteBuffer buffers = net_its_picture_info.pBuffer.getByteBuffer(offset, net_its_picture_info.dwDataLen);
|
|
@@ -87,7 +98,7 @@ public class AlarmParseService {
|
|
|
buffers.get(bytes);
|
|
|
fout.write(bytes);
|
|
|
fout.close();
|
|
|
-
|
|
|
+ taskService.addTask(new HandlerCarImage(RandomUtil.randomNumbers(10),100,filePath,sLicense));
|
|
|
} catch (IOException e) {
|
|
|
// TODO Auto-generated catch block
|
|
|
e.printStackTrace();
|