|
@@ -1,6 +1,7 @@
|
|
|
package org.dromara.server.hik.event.handler;
|
|
package org.dromara.server.hik.event.handler;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import io.seata.common.util.StringUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.dromara.backstage.api.RemoteUserAccountService;
|
|
import org.dromara.backstage.api.RemoteUserAccountService;
|
|
@@ -8,6 +9,7 @@ import org.dromara.backstage.api.domain.vo.RemoteUserAccountVo;
|
|
|
import org.dromara.common.core.constant.CacheConstants;
|
|
import org.dromara.common.core.constant.CacheConstants;
|
|
|
import org.dromara.common.core.constant.CacheNames;
|
|
import org.dromara.common.core.constant.CacheNames;
|
|
|
import org.dromara.common.redis.utils.RedisUtils;
|
|
import org.dromara.common.redis.utils.RedisUtils;
|
|
|
|
|
+import org.dromara.server.hik.domain.vo.XfTermVo;
|
|
|
import org.dromara.server.hik.event.HikEventHandler;
|
|
import org.dromara.server.hik.event.HikEventHandler;
|
|
|
import org.dromara.server.hik.event.domain.FileContent;
|
|
import org.dromara.server.hik.event.domain.FileContent;
|
|
|
import org.dromara.server.hik.event.domain.HeatBeatData;
|
|
import org.dromara.server.hik.event.domain.HeatBeatData;
|
|
@@ -40,45 +42,48 @@ public class HeatBeatHandler implements HikEventHandler {
|
|
|
// mac -> ip 和 心跳的IP 是否相等,不相等则更新
|
|
// mac -> ip 和 心跳的IP 是否相等,不相等则更新
|
|
|
String ipAddress = heatBeatData.getIpAddress();
|
|
String ipAddress = heatBeatData.getIpAddress();
|
|
|
String macAddress = heatBeatData.getMacAddress();
|
|
String macAddress = heatBeatData.getMacAddress();
|
|
|
- boolean b = xfTermService.updateByMac(macAddress, ipAddress);
|
|
|
|
|
|
|
+ XfTermVo termVo = xfTermService.getByMac(macAddress);
|
|
|
|
|
+ if(termVo == null) return null;
|
|
|
|
|
+ if(!StringUtils.equals(ipAddress, termVo.getTermIp())){
|
|
|
|
|
+ log.info("设备IP地址更新:{} -> {}", ipAddress, termVo.getTermIp());
|
|
|
|
|
+ xfTermService.updateByMac(macAddress, ipAddress);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if(b){
|
|
|
|
|
- //增量下发 人脸数据和卡数据
|
|
|
|
|
- Long cacheObject = RedisUtils.getCacheObject(CacheNames.XF_TERM_IP + ipAddress);
|
|
|
|
|
- if(cacheObject == null){
|
|
|
|
|
- // 第一次上线 默认只下发最近1天的 新增或修改的数据
|
|
|
|
|
- //记录每天第一次上来的心跳数据时 下发最近3天的 新增或修改的数据
|
|
|
|
|
- // t_pt_useraccount表 update_time 更新人脸
|
|
|
|
|
- // t_pt_card表 change_time、create_time 更新卡片
|
|
|
|
|
- //下发数据
|
|
|
|
|
- // 获取当前时间的前一天的时间
|
|
|
|
|
- LocalDateTime localDate = LocalDateTime.now();
|
|
|
|
|
- LocalDateTime minus = localDate.minus(1, ChronoUnit.DAYS);
|
|
|
|
|
- // LocalDateTime 转 date
|
|
|
|
|
- Date date = Date.from(minus.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
|
|
- System.err.println("minus: " + minus);
|
|
|
|
|
- System.err.println("date: " + date);
|
|
|
|
|
- sendDeviceService.upLoadEmpToDevice(macAddress,date,true);
|
|
|
|
|
|
|
+ //增量下发 人脸数据和卡数据
|
|
|
|
|
+ Long cacheObject = RedisUtils.getCacheObject(CacheNames.XF_TERM_IP + ipAddress);
|
|
|
|
|
+ if(cacheObject == null){
|
|
|
|
|
+ // 第一次上线 默认只下发最近1天的 新增或修改的数据
|
|
|
|
|
+ //记录每天第一次上来的心跳数据时 下发最近3天的 新增或修改的数据
|
|
|
|
|
+ // t_pt_useraccount表 update_time 更新人脸
|
|
|
|
|
+ // t_pt_card表 change_time、create_time 更新卡片
|
|
|
|
|
+ //下发数据
|
|
|
|
|
+ // 获取当前时间的前一天的时间
|
|
|
|
|
+ LocalDateTime localDate = LocalDateTime.now();
|
|
|
|
|
+ LocalDateTime minus = localDate.minus(1, ChronoUnit.DAYS);
|
|
|
|
|
+ // LocalDateTime 转 date
|
|
|
|
|
+ Date date = Date.from(minus.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
|
|
+ System.err.println("minus: " + minus);
|
|
|
|
|
+ System.err.println("date: " + date);
|
|
|
|
|
+ sendDeviceService.upLoadEmpToDevice(macAddress,date,true);
|
|
|
|
|
|
|
|
- RedisUtils.setCacheObject(CacheNames.XF_TERM_IP + ipAddress, date.getTime());
|
|
|
|
|
- }else{
|
|
|
|
|
- // 当前时间-上次下发时间 >= 1天 就下发
|
|
|
|
|
- Date now = new Date();
|
|
|
|
|
- Date last = new Date(cacheObject);
|
|
|
|
|
- // 舍弃时分秒,只保留日期部分
|
|
|
|
|
- LocalDate nowDate = now.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
|
|
- LocalDate lastDate = last.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
|
|
- System.err.println("nowDate: " + nowDate);
|
|
|
|
|
- System.err.println("lastDate: " + lastDate);
|
|
|
|
|
- // 计算两个日期之间的天数差
|
|
|
|
|
- long daysBetween = ChronoUnit.DAYS.between(lastDate, nowDate);
|
|
|
|
|
|
|
+ RedisUtils.setCacheObject(CacheNames.XF_TERM_IP + ipAddress, date.getTime());
|
|
|
|
|
+ }else{
|
|
|
|
|
+ // 当前时间-上次下发时间 >= 1天 就下发
|
|
|
|
|
+ Date now = new Date();
|
|
|
|
|
+ Date last = new Date(cacheObject);
|
|
|
|
|
+ // 舍弃时分秒,只保留日期部分
|
|
|
|
|
+ LocalDate nowDate = now.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
|
|
+ LocalDate lastDate = last.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
|
|
+ System.err.println("nowDate: " + nowDate);
|
|
|
|
|
+ System.err.println("lastDate: " + lastDate);
|
|
|
|
|
+ // 计算两个日期之间的天数差
|
|
|
|
|
+ long daysBetween = ChronoUnit.DAYS.between(lastDate, nowDate);
|
|
|
|
|
|
|
|
- // 判断是否相差 1 天或以上
|
|
|
|
|
- if (daysBetween >= 1) {
|
|
|
|
|
- // 相差一天以上,执行下发逻辑
|
|
|
|
|
- sendDeviceService.upLoadEmpToDevice(macAddress, last, true);
|
|
|
|
|
- RedisUtils.setCacheObject(CacheNames.XF_TERM_IP + ipAddress, now.getTime());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 判断是否相差 1 天或以上
|
|
|
|
|
+ if (daysBetween >= 1) {
|
|
|
|
|
+ // 相差一天以上,执行下发逻辑
|
|
|
|
|
+ sendDeviceService.upLoadEmpToDevice(macAddress, last, true);
|
|
|
|
|
+ RedisUtils.setCacheObject(CacheNames.XF_TERM_IP + ipAddress, now.getTime());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|