|
@@ -1,20 +1,36 @@
|
|
|
package com.pj.current.netty.command.handler.impl;
|
|
|
|
|
|
+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.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.pj.current.config.MyConfig;
|
|
|
+import com.pj.current.config.WxConfig;
|
|
|
import com.pj.current.netty.command.constants.CommandType;
|
|
|
import com.pj.current.netty.command.handler.IHandler;
|
|
|
import com.pj.current.netty.command.handler.dto.ChecklogDTO;
|
|
|
+import com.pj.current.netty.command.handler.dto.HealthlogDTO;
|
|
|
import com.pj.current.netty.dto.OKMsg;
|
|
|
import com.pj.current.netty.dto.RequestPackageDTO;
|
|
|
import com.pj.current.task.TaskService;
|
|
|
+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_terminal.TbGateTerminal;
|
|
|
+import com.pj.project.tb_gate_terminal.TbGateTerminalService;
|
|
|
+import com.pj.project.tb_gate_terminal.bo.ResultDTO;
|
|
|
import com.pj.project.tb_manager.TbManager;
|
|
|
import com.pj.project.tb_manager.TbManagerService;
|
|
|
+import com.pj.project.tb_mini_user.TbMiniUser;
|
|
|
+import com.pj.project.tb_mini_user.TbMiniUserService;
|
|
|
import com.pj.project.tb_person_filing.TbPersonFiling;
|
|
|
import com.pj.project.tb_person_filing.TbPersonFilingService;
|
|
|
+import com.pj.project.tb_person_filing.task.Base64ToImage;
|
|
|
+import com.pj.project.tb_person_filing.task.DelayIsuued;
|
|
|
import com.pj.project.tb_person_visit_record.TbPersonVisitRecord;
|
|
|
import com.pj.project.tb_person_visit_record.TbPersonVisitRecordService;
|
|
|
import com.pj.project.tb_person_visit_record.task.ConvertBase64ToImage;
|
|
@@ -22,7 +38,11 @@ import com.pj.project.tb_terminal.TbTerminal;
|
|
|
import com.pj.project.tb_terminal.TbTerminalService;
|
|
|
import com.pj.project.tb_venues.TbVenues;
|
|
|
import com.pj.project.tb_venues.TbVenuesService;
|
|
|
+import com.pj.project.wx.WxService;
|
|
|
+import com.pj.project.wx.bo.MsgDataBO;
|
|
|
+import com.pj.project4sp.sms.DuanXinBaoSMSService;
|
|
|
import com.pj.project4sp.spcfg.SpCfgUtil;
|
|
|
+import com.pj.utils.cache.RedisUtil;
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -30,8 +50,10 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
+import java.time.ZoneOffset;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 人脸核验记录
|
|
@@ -47,10 +69,19 @@ public class CheckLogHandler implements IHandler {
|
|
|
@Resource
|
|
|
private TbPersonFilingService tbPersonFilingService;
|
|
|
@Resource
|
|
|
+ private TbDeptService tbDeptService;
|
|
|
+ @Resource
|
|
|
private TaskService taskService;
|
|
|
+
|
|
|
@Resource
|
|
|
- private TbDeptService tbDeptService;
|
|
|
+ private TbVenuesService tbVenuesService;
|
|
|
+ @Resource
|
|
|
+ private TbGateTerminalService tbGateTerminalService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TbCarVisitRecordService tbCarVisitRecordService;
|
|
|
|
|
|
+ TimedCache<String, Integer> CACHE_MAP = CacheUtil.newTimedCache(30000);
|
|
|
|
|
|
@Override
|
|
|
public CommandType commandType() {
|
|
@@ -62,30 +93,144 @@ public class CheckLogHandler implements IHandler {
|
|
|
log.info("============核验记录上传========:{}", JSONUtil.toJsonStr(packageDTO));
|
|
|
JSONObject params = JSONUtil.parseObj(packageDTO.getPayload().getParams());
|
|
|
String str = params.getStr("log");
|
|
|
- ChecklogDTO dto = JSONUtil.toBean(str, ChecklogDTO.class);
|
|
|
- TbPersonFiling tbPersonFiling = tbPersonFilingService.findByPin(dto.getPin());
|
|
|
+ HealthlogDTO dto = JSONUtil.toBean(str, HealthlogDTO.class);
|
|
|
+ String idCard = dto.getPin();
|
|
|
+ if (StrUtil.isEmpty(idCard)){
|
|
|
+ idCard=dto.getIdentity_number();
|
|
|
+ }
|
|
|
+ Date visitDate=dto.getDate();
|
|
|
+ Date expireDate=Date.from(LocalDateTime
|
|
|
+ .of(2024,5,1,0,0,0)
|
|
|
+ .atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ if (visitDate.compareTo(expireDate)<0){
|
|
|
+ log.info("expire----------");
|
|
|
+ ctx.write(OKMsg.ok());
|
|
|
+ ctx.flush();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (CACHE_MAP.get(idCard) != null) {
|
|
|
+ log.info("回复核验记录上传===重复数据:{}", OKMsg.ok());
|
|
|
+ ctx.write(OKMsg.ok());
|
|
|
+ ctx.flush();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ CACHE_MAP.put(idCard, 1);
|
|
|
+ //设备
|
|
|
String sn = params.getStr("sn");
|
|
|
TbTerminal tbTerminal = tbTerminalService.findBySN(sn);
|
|
|
+ Long channelId = tbTerminal.getChannelId();
|
|
|
+ //绑定场所的通道
|
|
|
+ TbVenues channel = tbVenuesService.getById(channelId);
|
|
|
+ TbPersonFiling tbPersonFiling = tbPersonFilingService.findByIdCard(idCard);
|
|
|
+ if (tbPersonFiling == null) {
|
|
|
+ if (!SpCfgUtil.termianlFilling()) {
|
|
|
+ log.error("系统不允许设备端进行备案============>删除设备端自动备份的信息,:{}", idCard);
|
|
|
+ tbPersonFilingService.deleteTerminalWhilte(idCard, true);
|
|
|
+ ctx.write(OKMsg.ok());
|
|
|
+ ctx.flush();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //增加人员信息
|
|
|
+ Date now = new Date();
|
|
|
+ List<TbDept> deptList = tbDeptService.findByVenuesId(tbTerminal.getVenuesId());
|
|
|
+ if (deptList.isEmpty()) {
|
|
|
+ log.error("设备上传备案,无备案组织====");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ TbDept dept = deptList.get(0);
|
|
|
+ boolean needJudge = TbDept.NeedJudgeEnum.MAN_JUDGE.getType().equals(dept.getNeedJudge());
|
|
|
+ tbPersonFiling = new TbPersonFiling();
|
|
|
+ tbPersonFiling.setPin(idCard).setIdCard(dto.getIdentity_number())
|
|
|
+ .setName(dto.getName()).setCreateBy("设备上传")
|
|
|
+ .setCreateTime(now).setUpdateTime(now)
|
|
|
+ .setDeptId(dept.getId()).setJudgeState(needJudge ? 0 : 1)
|
|
|
+ .setJudgeBy("设备上传").setJudgeTime(needJudge ? null : now);
|
|
|
+ tbPersonFilingService.save(tbPersonFiling);
|
|
|
+ taskService.addTask(new Base64ToImage(RandomUtil.randomNumbers(10), 50, tbPersonFiling.getId(), dto.getPicture()));
|
|
|
+ //分发人员信息到其他终端
|
|
|
+ if (!needJudge) {
|
|
|
+ taskService.addTask(new DelayIsuued(RandomUtil.randomNumbers(11), 4000, tbPersonFiling.getId(), sn));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //备案组织
|
|
|
Long deptId = tbPersonFiling.getDeptId();
|
|
|
TbDept tbDept = tbDeptService.getById(deptId);
|
|
|
- Date date = dto.getDate();
|
|
|
- LocalDateTime dayTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
- Integer direction = dto.getDirection();
|
|
|
- String idCard = tbPersonFiling.getIdCard();
|
|
|
- TbPersonVisitRecord record = tbPersonVisitRecordService.findTheNearRecord(idCard, deptId, direction, dayTime.minusSeconds(8));
|
|
|
- if (record == null) {
|
|
|
- record = new TbPersonVisitRecord();
|
|
|
+ Boolean allowPass = dto.isAllow_through();
|
|
|
+ //车辆道闸判断
|
|
|
+ if (channel != null && TbVenues.TypeEnum.CAR_CHANNEL.getType().equals(channel.getType())) {
|
|
|
+ String key = "result:" + channelId;
|
|
|
+ String resultStr = RedisUtil.get(key);
|
|
|
+ ResultDTO resultDTO = JSONUtil.toBean(resultStr, ResultDTO.class);
|
|
|
+ //备案的组织满足其一就可放行
|
|
|
+ if (TbDept.PassTypeEnum.ONE.getType().equals(tbDept.getPassType())) {
|
|
|
+ List<TbGateTerminal> gateTerminals = tbGateTerminalService.findByChannelId(channelId);
|
|
|
+ // 找到入口的设备,开闸
|
|
|
+ if (allowPass) {//上传的记录是可开闸
|
|
|
+ gateTerminals.stream().filter(tbGateTerminal -> tbGateTerminal.getDirection() == 1)
|
|
|
+ .forEach(tbGateTerminal -> openGate(tbGateTerminal.getId(), channelId));
|
|
|
+ }
|
|
|
+ if (resultDTO.getResult() != null && resultDTO.getResult() == 0) {
|
|
|
+ resultDTO.setReason("人脸识别放行");
|
|
|
+ this.updateCarRecord(resultDTO, dto, tbPersonFiling);
|
|
|
+ }
|
|
|
+ } else if (resultDTO.getResult() != null && resultDTO.getResult() == 1 && allowPass) {
|
|
|
+ openGate(resultDTO.getGateTerminalId(), channelId);
|
|
|
+ resultDTO.setReason("人车识别一致放行");
|
|
|
+ this.updateCarRecord(resultDTO, dto, tbPersonFiling);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ TbPersonVisitRecord record = new TbPersonVisitRecord();
|
|
|
+ if (channel != null) {
|
|
|
+ record.setVenuesId(channel.getPId());
|
|
|
}
|
|
|
record.setDeptId(deptId).setType(TbPersonVisitRecord.TypeEnum.UPLOAD.getType())
|
|
|
.setVenues(tbTerminal.getVenuesName()).setChannel(tbTerminal.getChannelName())
|
|
|
+ .setDepartmentId(tbPersonFiling.getDepartmentId())
|
|
|
.setTerminalName(tbTerminal.getName()).setVisitDate(dto.getDate()).setCreateTime(new Date())
|
|
|
- .setSn(sn).setUpdateTime(new Date()).setAllowPass(dto.isAllow_through())
|
|
|
+ .setSn(sn).setUpdateTime(new Date()).setAllowPass(allowPass)
|
|
|
.setDirection(dto.getDirection()).setTemperature(dto.getTemperature()).setDeptName(tbDept.getName())
|
|
|
.setName(tbPersonFiling.getName()).setPhone(tbPersonFiling.getPhone()).setIdCard(tbPersonFiling.getIdCard());
|
|
|
+ if (!allowPass) {
|
|
|
+ if (SpCfgUtil.getMinTemperature() < Double.valueOf(dto.getTemperature())) {
|
|
|
+ record.setReason("体温异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
tbPersonVisitRecordService.saveOrUpdate(record);
|
|
|
+ tbTerminal.setLastOnLine(DateUtil.now());
|
|
|
+ tbTerminalService.updateById(tbTerminal);
|
|
|
ctx.write(OKMsg.ok());
|
|
|
ctx.flush();
|
|
|
-
|
|
|
taskService.addTask(new ConvertBase64ToImage(RandomUtil.randomNumbers(8), 2000, record.getId(), dto.getPicture()));
|
|
|
+ String alarm = SpCfgUtil.getAlarmConfig();
|
|
|
+ if (Integer.parseInt(alarm) == 0) {
|
|
|
+ log.error("========系统未设置预警==========");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //预警人员
|
|
|
+ if (channel == null) {
|
|
|
+ log.error("设备未绑定场所,不进行预警==========");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void updateCarRecord(ResultDTO resultDTO, HealthlogDTO dto, TbPersonFiling tbPersonFiling) {
|
|
|
+ Long recordId = resultDTO.getRecordId();
|
|
|
+ TbCarVisitRecord tbCarVisitRecord = tbCarVisitRecordService.getById(recordId);
|
|
|
+ tbCarVisitRecord.setDriverIdCard(dto.getIdentity_number()).setDriverName(dto.getName()).setReason(resultDTO.getReason())
|
|
|
+ .setDriverContact(tbPersonFiling.getPhone()).setAllowPass(1).setDepartmentId(tbPersonFiling.getDepartmentId());
|
|
|
+ tbCarVisitRecordService.updateById(tbCarVisitRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void openGate(Long gateTerminalId, Long channelId) {
|
|
|
+ try {
|
|
|
+ tbGateTerminalService.open(gateTerminalId);
|
|
|
+ String recordId = RedisUtil.get("record:" + channelId);
|
|
|
+ RedisUtil.del("record:" + channelId);
|
|
|
+ tbCarVisitRecordService.updatePass(Long.valueOf(recordId));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("开闸失败:{}", e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
}
|