|
@@ -3,10 +3,15 @@ package com.pj.project.tb_gate_terminal;
|
|
|
import java.io.IOException;
|
|
|
import java.net.InetSocketAddress;
|
|
|
import java.net.Socket;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.cache.CacheUtil;
|
|
|
+import cn.hutool.cache.impl.TimedCache;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -15,13 +20,27 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.pj.current.config.MyConfig;
|
|
|
import com.pj.current.global.BusinessException;
|
|
|
import com.pj.current.satoken.StpUserUtil;
|
|
|
+import com.pj.current.task.TaskService;
|
|
|
+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.project.tb_gate_command_log.TbGateCommandLog;
|
|
|
import com.pj.project.tb_gate_command_log.TbGateCommandLogService;
|
|
|
+import com.pj.project.tb_gate_terminal.bo.ReqBO;
|
|
|
+import com.pj.project.tb_gate_terminal.task.GateTerminalBase64ToImage;
|
|
|
import com.pj.project.tb_venues.TbVenues;
|
|
|
import com.pj.project.tb_venues.TbVenuesService;
|
|
|
+import com.pj.utils.cache.RedisUtil;
|
|
|
import com.pj.utils.zkt.GateCommandUtils;
|
|
|
import com.pj.utils.zkt.ZKTecoUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import com.pj.utils.so.*;
|
|
@@ -36,6 +55,7 @@ import javax.annotation.Resource;
|
|
|
*/
|
|
|
@Service
|
|
|
@Transactional
|
|
|
+@Slf4j
|
|
|
public class TbGateTerminalService extends ServiceImpl<TbGateTerminalMapper, TbGateTerminal> implements IService<TbGateTerminal> {
|
|
|
|
|
|
|
|
@@ -53,6 +73,20 @@ public class TbGateTerminalService extends ServiceImpl<TbGateTerminalMapper, TbG
|
|
|
@Resource
|
|
|
private TbGateCommandLogService tbGateCommandLogService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private TbCarVisitRecordService tbCarVisitRecordService;
|
|
|
+ @Resource
|
|
|
+ private TaskService taskService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TbCarFilingService tbCarFilingService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TbDeptService tbDeptService;
|
|
|
+ @Resource
|
|
|
+ @Lazy
|
|
|
+ private TbCarBlackService tbCarBlackService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 增
|
|
@@ -70,8 +104,6 @@ public class TbGateTerminalService extends ServiceImpl<TbGateTerminalMapper, TbG
|
|
|
Date now = new Date();
|
|
|
String loginId = StpUtil.getLoginIdAsString();
|
|
|
t.setSn(sn).setCreateTime(now).setUpdateTime(now).setCreateBy(loginId).setUpdateBy(loginId);
|
|
|
- TbVenues tbVenues = tbVenuesService.getById(t.getVenuesId());
|
|
|
- t.setDeptId(tbVenues.getDeptId());
|
|
|
this.save(t);
|
|
|
}
|
|
|
|
|
@@ -161,9 +193,134 @@ public class TbGateTerminalService extends ServiceImpl<TbGateTerminalMapper, TbG
|
|
|
throw new BusinessException("开闸失败");
|
|
|
}
|
|
|
TbGateCommandLog log = new TbGateCommandLog();
|
|
|
- log.setTerminalName(tbGateTerminal.getName()).setVenuesName(tbVenues.getName()).setDeptId(tbGateTerminal.getDeptId())
|
|
|
+ log.setTerminalName(tbGateTerminal.getName()).setVenuesName(tbVenues.getName())
|
|
|
.setCommand(GateCommandUtils.openCommand()).setResponseContent(result).setSn(tbGateTerminal.getSn())
|
|
|
.setCreateBy(StpUserUtil.getAdminName()).setCreateTime(new Date());
|
|
|
tbGateCommandLogService.save(log);
|
|
|
}
|
|
|
+
|
|
|
+ private static TimedCache<Long, String> RECORD_CACHE = CacheUtil.newTimedCache(40000);
|
|
|
+
|
|
|
+ public void record(ReqBO bo) {
|
|
|
+ String ip = bo.getIpaddr();
|
|
|
+ TbGateTerminal tbGateTerminal = this.findByIp(ip);
|
|
|
+ ReqBO.ResultBean.PlateResultBean plateResultBean = bo.getResult().getPlateResult();
|
|
|
+ String carNo = plateResultBean.getLicense();
|
|
|
+ if (tbGateTerminal == null) {
|
|
|
+ log.error("===========非法设备============");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long terminalId = tbGateTerminal.getId();
|
|
|
+ String cacheCarNo = RECORD_CACHE.get(terminalId);
|
|
|
+ if (StrUtil.isNotEmpty(cacheCarNo)) {
|
|
|
+ log.error("===========40秒内重复识别:{}============", carNo);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (tbGateTerminal.getDirection().equals(2)) {
|
|
|
+ handlerOut(tbGateTerminal, bo);
|
|
|
+ return;
|
|
|
+ } else {
|
|
|
+ handlerIn(tbGateTerminal, bo);
|
|
|
+ }
|
|
|
+
|
|
|
+ RECORD_CACHE.put(tbGateTerminal.getId(), carNo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 入场===>缓存是否开闸
|
|
|
+ *
|
|
|
+ * @param tbGateTerminal
|
|
|
+ * @param bo
|
|
|
+ */
|
|
|
+ private void handlerIn(TbGateTerminal tbGateTerminal, ReqBO bo) {
|
|
|
+ ReqBO.ResultBean.PlateResultBean plateResultBean = bo.getResult().getPlateResult();
|
|
|
+ String base64Image = plateResultBean.getImageFragmentFile();
|
|
|
+ String carNo = plateResultBean.getLicense();
|
|
|
+ String now = DateUtil.now();
|
|
|
+ cacheResult(carNo, now, tbGateTerminal.getVenuesId(),tbGateTerminal.getId());
|
|
|
+ saveRecord(carNo, base64Image, tbGateTerminal, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 离场车辆 直接放行
|
|
|
+ *
|
|
|
+ * @param tbGateTerminal
|
|
|
+ */
|
|
|
+ private void handlerOut(TbGateTerminal tbGateTerminal, ReqBO bo) {
|
|
|
+ ReqBO.ResultBean.PlateResultBean plateResultBean = bo.getResult().getPlateResult();
|
|
|
+ String base64Image = plateResultBean.getImageFragmentFile();
|
|
|
+ String carNo = plateResultBean.getLicense();
|
|
|
+ log.info("车辆离场:{}", carNo);
|
|
|
+ saveRecord(carNo, base64Image, tbGateTerminal, 2);
|
|
|
+ try {
|
|
|
+ this.open(tbGateTerminal.getId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("抬杆失败:{}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存记录
|
|
|
+ *
|
|
|
+ * @param carNo
|
|
|
+ * @param base64Image
|
|
|
+ * @param tbGateTerminal
|
|
|
+ * @param direction
|
|
|
+ */
|
|
|
+ private void saveRecord(String carNo, String base64Image, TbGateTerminal tbGateTerminal, Integer direction) {
|
|
|
+ Long channelId = tbGateTerminal.getVenuesId();
|
|
|
+ Date now = new Date();
|
|
|
+ TbVenues tbVenues = tbVenuesService.getById(channelId);
|
|
|
+ TbCarVisitRecord tbCarVisitRecord = new TbCarVisitRecord();
|
|
|
+ tbCarVisitRecord.setCarNo(carNo)
|
|
|
+ .setChannelId(tbGateTerminal.getVenuesId())
|
|
|
+ .setChannel(tbVenues.getName()).setDirection(direction)
|
|
|
+ .setVisitTime(now).setUpdateTime(now).setCreateTime(now).setRecordType(2);
|
|
|
+ TbCarFiling carFiling = tbCarFilingService.findByCarNo(carNo);
|
|
|
+ if (carFiling != null) {
|
|
|
+ TbDept tbDept=tbDeptService.getById(carFiling.getDeptId());
|
|
|
+ tbCarVisitRecord.setDriverName(carFiling.getDriverName()).setDeptId(carFiling.getDeptId()).setDeptName(tbDept.getName())
|
|
|
+ .setDriverIdCard(carFiling.getDriverIdCard()).setType(carFiling.getType())
|
|
|
+ .setDriverContact(carFiling.getDriverContact());
|
|
|
+ }
|
|
|
+ tbCarVisitRecordService.save(tbCarVisitRecord);
|
|
|
+ taskService.addTask(new GateTerminalBase64ToImage(RandomUtil.randomNumbers(5), 1423, tbCarVisitRecord.getId(), base64Image));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void cacheResult(String carNo, String now, Long venuesId,Long terminalId) {
|
|
|
+ TbCarBlack tbCarBlack = tbCarBlackService.findByCarNo(carNo, now);
|
|
|
+ //是否在黑名单上
|
|
|
+ if (tbCarBlack != null) {
|
|
|
+ log.error("黑名单车辆:{}",carNo);
|
|
|
+ RedisUtil.set("result:" + venuesId, "0");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ TbCarFiling tbCarFiling = tbCarFilingService.findByCarNo(carNo);
|
|
|
+ //是否备案
|
|
|
+ if (tbCarFiling == null) {
|
|
|
+ log.error("车辆未备案:{}",carNo);
|
|
|
+ //没备案
|
|
|
+ RedisUtil.set("result:" + venuesId, "0");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //备案车,如果属于的组织只需要满足一个条件的直接放行
|
|
|
+ Long deptId = tbCarFiling.getDeptId();
|
|
|
+ TbDept tbDept = tbDeptService.getById(deptId);
|
|
|
+ if (TbDept.PassTypeEnum.ONE.getType().equals(tbDept.getPassType())){
|
|
|
+ log.error("组织满足条件二,直接放行:{}",carNo);
|
|
|
+ try {
|
|
|
+ open(terminalId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("开闸失败:{}",e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ RedisUtil.set("result:" + venuesId, "1");
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<TbGateTerminal> findByVenuesId(Long venuesId) {
|
|
|
+ QueryWrapper<TbGateTerminal>ew=new QueryWrapper<>();
|
|
|
+ ew.eq("venues_id",venuesId);
|
|
|
+ return list(ew);
|
|
|
+ }
|
|
|
}
|