Commit 297a9edd authored by 赵啸非's avatar 赵啸非

同步人员方法添加

parent 8d5f850a
package com.mortals.xhx.daemon.task; package com.mortals.xhx.daemon.task;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.PageUtil; import cn.hutool.core.util.PageUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
...@@ -18,17 +19,27 @@ import com.mortals.xhx.common.key.RedisKey; ...@@ -18,17 +19,27 @@ import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.module.attendance.model.AttendanceRecordHikEntity; import com.mortals.xhx.module.attendance.model.AttendanceRecordHikEntity;
import com.mortals.xhx.module.attendance.model.AttendanceRecordHikQuery; import com.mortals.xhx.module.attendance.model.AttendanceRecordHikQuery;
import com.mortals.xhx.module.attendance.service.AttendanceRecordHikService; import com.mortals.xhx.module.attendance.service.AttendanceRecordHikService;
import com.mortals.xhx.module.door.model.DoorEntity;
import com.mortals.xhx.module.door.model.DoorQuery;
import com.mortals.xhx.module.door.service.DoorService;
import com.mortals.xhx.module.hik.door.model.req.door.DoorEventReq; import com.mortals.xhx.module.hik.door.model.req.door.DoorEventReq;
import com.mortals.xhx.module.hik.door.model.req.door.HikDoorEventReq;
import com.mortals.xhx.module.hik.door.model.rsp.door.DoorEventDataInfo; import com.mortals.xhx.module.hik.door.model.rsp.door.DoorEventDataInfo;
import com.mortals.xhx.module.hik.door.model.rsp.door.info.EventInfo;
import com.mortals.xhx.module.hik.door.model.rsp.door.info.StruTime;
import com.mortals.xhx.module.hik.door.service.IHikDoorService; import com.mortals.xhx.module.hik.door.service.IHikDoorService;
import com.mortals.xhx.module.staff.model.StaffEntity; import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.service.StaffService; import com.mortals.xhx.module.staff.service.StaffService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.aspectj.weaver.ast.Var;
import org.checkerframework.checker.units.qual.A; import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -39,7 +50,7 @@ import java.util.stream.Collectors; ...@@ -39,7 +50,7 @@ import java.util.stream.Collectors;
* 同步获取当天海康门禁事件 * 同步获取当天海康门禁事件
*/ */
@Slf4j @Slf4j
//@Service("SyncDoorsEventTask") @Service("SyncDoorsEventTask")
public class SyncDoorsEventTaskImpl implements ITaskExcuteService { public class SyncDoorsEventTaskImpl implements ITaskExcuteService {
@Autowired @Autowired
...@@ -55,6 +66,9 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService { ...@@ -55,6 +66,9 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService {
@Autowired @Autowired
private ICacheService cacheService; private ICacheService cacheService;
@Autowired
private DoorService doorService;
@Override @Override
public void excuteTask(ITask task) throws AppException { public void excuteTask(ITask task) throws AppException {
...@@ -65,15 +79,116 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService { ...@@ -65,15 +79,116 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService {
} else { } else {
day = 0; day = 0;
} }
Date beginDateTime=DateUtil.parseDateTime(DateUtil.today()+" 08:00:00"); Date beginDateTime = DateUtil.parseDateTime(DateUtil.today() + " 08:00:00");
Date endDateTime=DateUtil.parseDateTime(DateUtil.today()+" 20:30:00"); Date endDateTime = DateUtil.parseDateTime(DateUtil.today() + " 20:30:00");
boolean in = DateUtil.isIn(new Date(), beginDateTime, endDateTime); boolean in = DateUtil.isIn(new Date(), beginDateTime, endDateTime);
if(in){ if (in) {
syncDoorEvents(); List<DoorEntity> doorEntities = doorService.find(new DoorQuery());
for (DoorEntity doorEntity : doorEntities) {
syncDoorEvents(doorEntity);
//hikDoorService.searchDoorEventsList()
}
//syncDoorEvents();
} }
} }
/**
* 查询当前间隔时间的门禁事件
*
* @param doorEntity
*/
private void syncDoorEvents(DoorEntity doorEntity) {
HikDoorEventReq hikDoorEventReq = new HikDoorEventReq();
//当前时间前一个小时
Date startTime = DateUtil.offsetHour(new Date(), -1).toJdkDate();
Date endTime = new Date();
hikDoorEventReq.setStartTime(startTime);
hikDoorEventReq.setEndTime(endTime);
Rest<List<EventInfo>> listRest = hikDoorService.searchDoorEventsList(hikDoorEventReq, doorEntity);
if (listRest.getCode() == YesNoEnum.YES.getValue()) {
List<EventInfo> list = listRest.getData();
List<AttendanceRecordHikEntity> attRecords = list.stream().map(item -> {
AttendanceRecordHikEntity recordHikEntity = new AttendanceRecordHikEntity();
recordHikEntity.initAttrValue();
byte[] byEmployeeNo = item.getStruAcsEventInfo().getByEmployeeNo();
if (ObjectUtils.isEmpty(byEmployeeNo)) {
int dwEmployeeNo = item.getStruAcsEventInfo().getDwEmployeeNo();
if (dwEmployeeNo == 0) {
log.info("jobNo is null ==>{}", JSON.toJSONString(item));
return null;
}
}
String jobNo = new String(byEmployeeNo).trim();
//查看考勤状态
int dwMajor = item.getDwMajor();//报警主类型
int dwMinor = item.getDwMinor();//报警次类型
int byStatusValue = item.getStruAcsEventInfo().getByStatusValue();//考勤状态值
StruTime struTime = item.getStruTime();
//格式化时间 年月日 时分秒 yyyy-MM-dd HH:mm:ss
int dwYear = struTime.getDwYear();
int dwMonth = struTime.getDwMonth();
int dwDay = struTime.getDwDay();
int dwHour = struTime.getDwHour();
int dwMinute = struTime.getDwMinute();
int dwSecond = struTime.getDwSecond();
LocalDateTime localDateTime = LocalDateTime.of(dwYear, dwMonth, dwDay, dwHour, dwMinute, dwSecond);
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime zdt = localDateTime.atZone(zoneId);
Date attendDate = Date.from(zdt.toInstant());
StaffEntity staffCache = staffService.getExtCache(StrUtil.padPre(jobNo, 8, "0"));
if (ObjectUtils.isEmpty(staffCache)) {
log.info("staff is null !staffCode:{}", jobNo);
return null;
}
recordHikEntity.setStaffId(staffCache.getId());
recordHikEntity.setStaffName(staffCache.getName());
recordHikEntity.setWorkNum(staffCache.getWorkNum());
recordHikEntity.setDeptId(staffCache.getDeptId());
recordHikEntity.setDeptName(staffCache.getDeptName());
recordHikEntity.setPositionId(staffCache.getPositionId());
recordHikEntity.setPositionName(staffCache.getPositionName());
recordHikEntity.setAttendanceDate(attendDate);
// recordHikEntity.setAttendanceAddress(item.getDoorName());
recordHikEntity.setEventSource("门禁点");
//recordHikEntity.setRemark(item.getEventId());
recordHikEntity.setCreateTime(new Date());
recordHikEntity.setCreateUserName("系统管理员");
recordHikEntity.setCreateUserId(1L);
return recordHikEntity;
}).filter(f -> f != null).collect(Collectors.toList());
log.info("attRecords size:{}", attRecords.size());
if (!ObjectUtils.isEmpty(attRecords)) {
//单个插入 去掉重复时间段的打卡记录
for (AttendanceRecordHikEntity recordHikEntity : attRecords) {
try {
recordHikService.getDao().insert(recordHikEntity);
} catch (Exception e) {
log.error("基础考勤数据保存异常", e.getMessage());
}
}
// recordHikService.save(saveRecordList);
}
}
}
private void syncDoorEvents() { private void syncDoorEvents() {
DoorEventReq doorEventReq = new DoorEventReq(); DoorEventReq doorEventReq = new DoorEventReq();
List<Integer> eventTypes = new ArrayList<>(); List<Integer> eventTypes = new ArrayList<>();
......
...@@ -38,7 +38,7 @@ import java.util.stream.Collectors; ...@@ -38,7 +38,7 @@ import java.util.stream.Collectors;
* 同步海康用户 * 同步海康用户
*/ */
@Slf4j @Slf4j
//@Service("SyncUserTask") @Service("SyncUserTask")
public class SyncUserTaskImpl implements ITaskExcuteService { public class SyncUserTaskImpl implements ITaskExcuteService {
@Autowired @Autowired
......
...@@ -32,7 +32,7 @@ public class StruAcsEventInfo{ ...@@ -32,7 +32,7 @@ public class StruAcsEventInfo{
private int dwAlarmInNo; private int dwAlarmInNo;
private boolean autoRead; private boolean autoRead;
private int byCardReaderKind; private int byCardReaderKind;
private String byEmployeeNo; private byte[] byEmployeeNo;
private int byMask; private int byMask;
private int byStatusValue; private int byStatusValue;
private int dwSize; private int dwSize;
......
...@@ -115,8 +115,6 @@ public class HikDoorServiceImpl extends AbstractHikService implements IHikDoorSe ...@@ -115,8 +115,6 @@ public class HikDoorServiceImpl extends AbstractHikService implements IHikDoorSe
struAcsEventCfg.dwSize = struAcsEventCfg.size(); struAcsEventCfg.dwSize = struAcsEventCfg.size();
struAcsEventCfg.write(); struAcsEventCfg.write();
Pointer ptrStruEventCfg = struAcsEventCfg.getPointer(); Pointer ptrStruEventCfg = struAcsEventCfg.getPointer();
while (true) { while (true) {
int dwEventSearch = hCNetSDK.NET_DVR_GetNextRemoteConfig(m_lSearchEventHandle, ptrStruEventCfg, struAcsEventCfg.size()); int dwEventSearch = hCNetSDK.NET_DVR_GetNextRemoteConfig(m_lSearchEventHandle, ptrStruEventCfg, struAcsEventCfg.size());
if (dwEventSearch <= -1) { if (dwEventSearch <= -1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment