Commit 17a8e916 authored by 姬鋆屾's avatar 姬鋆屾
parents 511383a9 a9a27b5f
......@@ -8,9 +8,9 @@ module.exports = {
hot: true,//自动保存
proxy: {
'/attendance': {
target: 'http://192.168.0.98:11039',
//target: 'http://192.168.0.98:11039',
// target: 'http://112.19.80.237:11039',
// target: 'http://localhost:17500',
target: 'http://localhost:17500',
changeOrigin: true,
secure: false,
cookieDomainRewrite: 'localhost',
......
package com.mortals.xhx.busiz;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.PageUtil;
import cn.hutool.core.util.StrUtil;
......@@ -9,32 +8,30 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.util.DateUtils;
import com.mortals.framework.utils.ServletUtils;
import com.mortals.xhx.base.system.idgenerator.service.IdgeneratorService;
import com.mortals.xhx.base.system.upload.service.UploadService;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.busiz.h5.rsp.ApiResp;
import com.mortals.xhx.common.code.ApiRespCodeEnum;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.module.attendance.model.AttendanceLeaveRecordEntity;
import com.mortals.xhx.module.attendance.model.AttendanceRecordHikEntity;
import com.mortals.xhx.module.attendance.model.AttendanceRecordHikQuery;
import com.mortals.xhx.module.attendance.service.AttendanceLeaveRecordService;
import com.mortals.xhx.module.attendance.service.AttendanceRecordHikService;
import com.mortals.xhx.module.dept.model.DeptEntity;
import com.mortals.xhx.module.dept.model.DeptQuery;
import com.mortals.xhx.module.dept.service.DeptService;
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.HikDoorEventReq;
import com.mortals.xhx.module.hik.door.model.rsp.door.DoorEventDataInfo;
import com.mortals.xhx.module.hik.door.service.IHikDoorService;
import com.mortals.xhx.module.hik.face.model.req.img.ImgReq;
import com.mortals.xhx.module.hik.face.service.IHikFaceService;
import com.mortals.xhx.module.perform.service.PerformPerposeStaffService;
import com.mortals.xhx.module.hik.staff.service.IHikStaffService;
import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.model.StaffQuery;
import com.mortals.xhx.module.staff.service.StaffService;
......@@ -45,9 +42,11 @@ import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -61,10 +60,6 @@ import java.util.stream.Collectors;
@Slf4j
@RequestMapping("/test")
public class TestController {
@Autowired
private IdgeneratorService idgeneratorService;
@Autowired
private ICacheService cacheService;
@Autowired
......@@ -77,15 +72,15 @@ public class TestController {
private UploadService uploadService;
@Autowired
private DeptService deptService;
@Autowired
private PerformPerposeStaffService performPerposeStaffService;
@Autowired
private AttendanceRecordHikService recordHikService;
@Autowired
private IHikDoorService hikDoorService;
@Autowired
private DoorService doorService;
@Autowired
private IHikStaffService hikStaffService;
/**
* 同步指定日期的海康数据
......@@ -174,26 +169,8 @@ public class TestController {
} catch (Exception e) {
log.error("异常", e);
}
}
}
/*
List<String> eventIds = attRecords.parallelStream().filter(f -> !ObjectUtils.isEmpty(f) && !ObjectUtils.isEmpty(f.getRemark())).map(i -> i.getRemark()).collect(Collectors.toList());
//查询当天考勤记录是否有重复的 有的 则不添加
AttendanceRecordHikQuery recordHikQuery = new AttendanceRecordHikQuery();
recordHikQuery.setAttendanceDateStart(DateUtil.format(DateUtil.beginOfDay(new Date()), "yyyy-MM-dd"));
recordHikQuery.setAttendanceDateEnd(DateUtil.format(DateUtil.beginOfDay(new Date()), "yyyy-MM-dd"));
recordHikQuery.setRemarkList(eventIds);
Set<String> eventIdSet = recordHikService.find(recordHikQuery).parallelStream().map(i -> i.getRemark()).collect(Collectors.toSet());
List<AttendanceRecordHikEntity> saveRecordList = attRecords.stream().filter(f -> !eventIdSet.contains(f.getRemark())).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(saveRecordList)) {
recordHikService.save(saveRecordList);
}
log.info("saveRecordList size:{}", saveRecordList.size());*/
}
......@@ -241,73 +218,15 @@ public class TestController {
// updateDeptPersonNum(parentDept);
}
}
}
/*
//更新父部门的人数归集
collect.entrySet().stream().forEach(item -> {
Long deptId = item.getKey();
DeptEntity deptEntity = deptService.get(deptId);
if (!ObjectUtils.isEmpty(deptEntity) && !ObjectUtils.isEmpty(deptEntity.getParentId())) {
int sum = deptService.find(new DeptQuery().parentId(deptEntity.getId())).stream().mapToInt(i -> i.getPersonNum()).sum();
DeptEntity parentDept = deptService.get(deptEntity.getParentId());
if (ObjectUtils.isEmpty(parentDept)) {
parentDept.setPersonNum(sum);
deptService.update(parentDept);
updateDeptPersonNum(parentDept);
}
}
// updateDeptPersonNum(deptEntity);
});*/
return "ok";
}
public static void calculateParentValue(DeptEntity root) {
if (root == null) {
return;
}
// 递归处理叶子节点
if (root.getChildren().isEmpty()) {
return;
}
// 递归计算所有子节点的值之和
int sum = 0;
for (DeptEntity child : root.getChildren()) {
calculateParentValue(child);
sum += child.getPersonNum();
}
// 更新当前节点的值为所有子节点值之和
root.setPersonNum(sum);
}
private void updateDeptPersonNum(DeptEntity deptEntity) {
if (!ObjectUtils.isEmpty(deptEntity) && !ObjectUtils.isEmpty(deptEntity.getParentId())) {
int sum = deptService.find(new DeptQuery().parentId(deptEntity.getId())).stream().mapToInt(i -> i.getPersonNum()).sum();
DeptEntity parentDept = deptService.get(deptEntity.getParentId());
if (ObjectUtils.isEmpty(parentDept)) {
parentDept.setPersonNum(sum);
deptService.update(parentDept);
updateDeptPersonNum(parentDept);
}
}
}
//
@GetMapping("updatePersons")
@UnAuth
public String updatePersons() {
log.info("更新用户手机号码");
cacheService.select(1);
Map<String, String> map = cacheService.hgetAll("com:mortals:xhx:module:workman:model:WorkmanEntity");
cacheService.select(14);
......@@ -363,7 +282,6 @@ public class TestController {
ImgReq imgReq = new ImgReq();
imgReq.setUrl(staffEntity.getPicUri());
imgReq.setServerIndexCode(staffEntity.getServerIndexCode());
//Rest<String> rest = faceService.downloadPicture(imgReq);
try {
InputStream in = faceService.callPostImgs(imgReq);
if (!ObjectUtils.isEmpty(in)) {
......@@ -375,20 +293,6 @@ public class TestController {
} catch (Exception e) {
log.error("下载出错");
}
/*
if (YesNoEnum.YES.getValue() == rest.getCode()) {
byte[] bytes = Base64.decode(rest.getData());
if (!org.springframework.util.ObjectUtils.isEmpty(bytes)) {
InputStream inputStream = new ByteArrayInputStream(bytes);
MultipartFile file = ServletUtils.getMultipartFile(inputStream, "snap.jpg");
String filePath = uploadService.saveFileUpload(file, "file/fileupload/snap/" + DateUtil.today(), null);
staffEntity.setPhotoPath(filePath);
updateList.add(staffEntity);
}
} else {
log.info("download:{}", JSON.toJSONString(rest));
}*/
}
}
if (!ObjectUtils.isEmpty(updateList)) {
......@@ -462,11 +366,44 @@ public class TestController {
try {
attendanceLeaveRecordService.doUpdateRecord(processInstanceId, leaveRecordEntity);
} catch (Exception e) {
log.error("异常",e);
log.error("异常", e);
}
return Rest.ok();
}
return Rest.ok();
/**
* 同步指定设备人员信息
*
* @param testReq
* @return
*/
@PostMapping("updatePersonsByDevices")
@UnAuth
public String updatePersonsByDevices(@RequestBody TestReq testReq) {
log.info("更新设备人员==>{}",JSON.toJSONString(testReq));
staffService.syncPersonsByDevices(null);
return "ok";
}
/**
* 查询设备考勤事件信息
*
* @param testReq
* @return
*/
@PostMapping("searchEventsByDevices")
@UnAuth
public String searchEventsByDevices(@RequestBody TestReq testReq) {
log.info("查询设备考勤信息==>{}",JSON.toJSONString(testReq));
HikDoorEventReq hikDoorEventReq = new HikDoorEventReq();
hikDoorEventReq.setStartTime(testReq.getCreateTimeStart());
hikDoorEventReq.setEndTime(testReq.getCreateTimeEnd());
DoorEntity doorEntity = doorService.get(testReq.getDeviceId());
doorService.syncDoorDeviceEvents(doorEntity, hikDoorEventReq);
return "ok";
}
......
......@@ -11,4 +11,8 @@ public class TestReq {
private Date createTimeStart;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTimeEnd;
private Long deviceId;
}
......@@ -42,12 +42,6 @@ public class SyncDoorsEventAfterTaskImpl implements ITaskExcuteService {
@Autowired
private AttendanceRecordHikService recordHikService;
@Autowired
private StaffService staffService;
@Autowired
private IHikDoorService hikDoorService;
@Autowired
private AttendanceStatService attendanceStatService;
......
......@@ -38,7 +38,7 @@ import java.util.stream.Collectors;
* 同步获取当天海康门禁事件
*/
@Slf4j
@Service("SyncDoorsEventByDevicesTask")
//@Service("SyncDoorsEventByDevicesTask")
public class SyncDoorsEventByDevicesTaskImpl implements ITaskExcuteService {
@Autowired
......@@ -87,110 +87,6 @@ public class SyncDoorsEventByDevicesTaskImpl implements ITaskExcuteService {
}
}
/**
* 查询当前间隔时间的门禁事件
*
* @param doorEntity
*/
private void syncDoorEvents(DoorEntity doorEntity) {
HikDoorEventReq hikDoorEventReq = new HikDoorEventReq();
//当前时间前一个小时
// Date startTime = DateUtil.offsetHour(new Date(), -1).toJdkDate();
Date startTime = DateUtil.offsetDay(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();
String jobNo = "";
byte[] byEmployeeNo = item.getStruAcsEventInfo().getByEmployeeNo();
if (ObjectUtils.isEmpty(new String(byEmployeeNo).trim())) {
int dwEmployeeNo = item.getStruAcsEventInfo().getDwEmployeeNo();
if (dwEmployeeNo == 0) {
//log.info("jobNo is null ==>{}", JSON.toJSONString(item));
return null;
} else {
jobNo = String.valueOf(dwEmployeeNo);
}
} else {
jobNo = new String(byEmployeeNo).trim();
}
log.info("jobNo==>{}",jobNo);
//查看考勤状态
int dwMajor = item.getDwMajor();//报警主类型
int dwMinor = item.getDwMinor();//报警次类型
String dwMinorStr = Integer.toHexString(dwMinor);
//判断次类型 是否在白名单里面
Set<String> dwSet = DwMinorEnum.getEnumMap().keySet();
if (dwSet.contains(dwMinorStr)) {
//符号考勤 添加到考勤里面
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;
} else {
log.info("考勤次类型dwMinorCode:" + dwMinorStr);
return null;
}
}).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());
}
}
}
}
}
@Override
public void stopTask(ITask task) throws AppException {
......
......@@ -50,24 +50,13 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService {
@Autowired
private AttendanceRecordHikService recordHikService;
@Autowired
private StaffService staffService;
@Autowired
private IHikDoorService hikDoorService;
private Integer day;
@Autowired
private ICacheService cacheService;
@Value("${hik.host:}")
protected String hikhost;
@Autowired
private DoorService doorService;
@Override
public void excuteTask(ITask task) throws AppException {
//同步多久时间段的 偏移量为天 默认当天
......@@ -77,20 +66,20 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService {
} else {
day = 0;
}
Date beginDateTime=DateUtil.parseDateTime(DateUtil.today()+" 08:00:00");
Date endDateTime=DateUtil.parseDateTime(DateUtil.today()+" 23:30:00");
Date beginDateTime = DateUtil.parseDateTime(DateUtil.today() + " 08:00:00");
Date endDateTime = DateUtil.parseDateTime(DateUtil.today() + " 23:30:00");
boolean in = DateUtil.isIn(new Date(), beginDateTime, endDateTime);
if(in){
if (in) {
AttendanceRecordHikQuery hikQuery = new AttendanceRecordHikQuery();
DateTime startTime = DateUtil.offsetDay(new Date(), day > 0 ? -day : 0);
hikQuery.setAttendanceDateStart( startTime.toDateStr());
hikQuery.setAttendanceDateStart(startTime.toDateStr());
// 获取当天的结束时间
hikQuery.setAttendanceDateEnd(DateUtil.today());
if (!ObjectUtils.isEmpty(hikhost)) {
recordHikService.syncDoorEvents(hikQuery);
recordHikService.deletFakeRecord(hikQuery, null);
}else{
} else {
log.info("同步设备上门禁事件!");
HikDoorEventReq hikDoorEventReq = new HikDoorEventReq();
hikDoorEventReq.setStartTime(startTime.toJdkDate());
......@@ -104,114 +93,6 @@ public class SyncDoorsEventTaskImpl implements ITaskExcuteService {
}
}
private void syncDoorEvents() {
DoorEventReq doorEventReq = new DoorEventReq();
List<Integer> eventTypes = new ArrayList<>();
eventTypes.add(196885);
eventTypes.add(196887);
eventTypes.add(196893);
eventTypes.add(196888);
eventTypes.add(196889);
eventTypes.add(196890);
eventTypes.add(196891);
// eventTypes.add(196893);//人脸认证通过
doorEventReq.setEventTypes(eventTypes);
// 获取当天的开始时间
//Date todayStart = DateUtil.offsetHour(new Date(), -5).toJdkDate();
Date todayStart = DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), day > 0 ? -day : 0));
// 获取当天的结束时间
Date todayEnd = DateUtil.endOfDay(new Date());
doorEventReq.setStartTime(todayStart);
doorEventReq.setEndTime(todayEnd);
doorEventReq.setPageNo(1);
doorEventReq.setPageSize(1);
Rest<DoorEventDataInfo> doorEventsRest = hikDoorService.getDoorEvents(doorEventReq);
log.info("doorEventsRest:{} msg:{}", doorEventsRest.getCode(), doorEventsRest.getMsg());
if (doorEventsRest.getCode() == YesNoEnum.YES.getValue()) {
//分页获取考勤数据
Integer total = doorEventsRest.getData().getTotal();
int pageCount = PageUtil.totalPage(total, 1000);
for (int i = 1; i <= pageCount; i++) {
doorEventReq.setPageNo(i);
doorEventReq.setPageSize(1000);
doorEventsRest = hikDoorService.getDoorEvents(doorEventReq);
log.info("doorEventsRest:{} msg:{},page:{}", doorEventsRest.getCode(), doorEventsRest.getMsg(), doorEventReq.getPageNo());
getDoorEvents(doorEventsRest);
}
}
}
private void getDoorEvents(Rest<DoorEventDataInfo> doorEventsRest) {
//同步当前考勤数据
List<AttendanceRecordHikEntity> attRecords = doorEventsRest.getData().getList().stream().map(item -> {
AttendanceRecordHikEntity recordHikEntity = new AttendanceRecordHikEntity();
recordHikEntity.initAttrValue();
if (ObjectUtils.isEmpty(item.getJobNo())) {
log.info("jobNo is null ==>{}", JSON.toJSONString(item));
return null;
}
StaffEntity staffCache = staffService.getExtCache(StrUtil.padPre(item.getJobNo(), 8, "0"));
if (ObjectUtils.isEmpty(staffCache)) {
log.info("staff is null !staffCode:{}", item.getJobNo());
return null;
}
recordHikEntity.setStaffId(staffCache.getId());
recordHikEntity.setStaffName(staffCache.getName());
recordHikEntity.setWorkNum(staffCache.getWorkNum());
recordHikEntity.setDeptId(staffCache.getDeptId());
recordHikEntity.setDeptName(staffCache.getDeptName());
recordHikEntity.setSalaId(staffCache.getSalaId());
recordHikEntity.setSalaName(staffCache.getSalaName());
recordHikEntity.setPositionId(staffCache.getPositionId());
recordHikEntity.setPositionName(staffCache.getPositionName());
recordHikEntity.setAttendanceDate(item.getEventTime());
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());
List<String> eventIds = attRecords.parallelStream().filter(f -> !ObjectUtils.isEmpty(f) && !ObjectUtils.isEmpty(f.getRemark())).map(i -> i.getRemark()).collect(Collectors.toList());
//查询当天考勤记录是否有重复的 有的 则不添加
AttendanceRecordHikQuery recordHikQuery = new AttendanceRecordHikQuery();
recordHikQuery.setAttendanceDateStart(DateUtil.format(DateUtil.beginOfDay(new Date()), "yyyy-MM-dd"));
recordHikQuery.setAttendanceDateEnd(DateUtil.format(DateUtil.beginOfDay(new Date()), "yyyy-MM-dd"));
recordHikQuery.setRemarkList(eventIds);
Set<String> eventIdSet = recordHikService.find(recordHikQuery).parallelStream().map(i -> i.getRemark()).collect(Collectors.toSet());
//去重 时分秒打卡的 也要去掉重复。
List<AttendanceRecordHikEntity> saveRecordList = attRecords.stream().filter(f -> !eventIdSet.contains(f.getRemark())).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(saveRecordList)) {
//单个插入 去掉重复时间段的打卡记录
for (AttendanceRecordHikEntity recordHikEntity : saveRecordList) {
try {
recordHikService.getDao().insert(recordHikEntity);
} catch (Exception e) {
//log.error("基础考勤数据保存异常", e.getMessage());
}
}
// recordHikService.save(saveRecordList);
}
log.info("saveRecordList size:{}", saveRecordList.size());
AttendanceRecordHikQuery hikQuery = new AttendanceRecordHikQuery();
hikQuery.setAttendanceDateStart(DateUtil.beginOfMonth(new Date()).toDateStr());
hikQuery.setAttendanceDateEnd(DateUtil.today());
Long totalCache = recordHikService.find(hikQuery).parallelStream().map(item -> item.getStaffId()).distinct().count();
cacheService.hset(RedisKey.KEY_ATTENC_TOTOAL_CACHE, DateUtil.format(new Date(), "yyyy-MM"), totalCache);
}
@Override
public void stopTask(ITask task) throws AppException {
......
......@@ -67,10 +67,6 @@ public class SyncPortalUserTaskImpl implements ITaskExcuteService {
//当前用户map
Map<String, UserEntity> oldUserMap = oldUserList.parallelStream().collect(Collectors.toMap(x -> x.getLoginName(), y -> y, (o, n) -> n));
//门户用户map
// Map<String, UserEntity> newUserMap = newUserList.stream().collect(Collectors.toMap(x -> x.getLoginName(), y -> y, (o, n) -> n));
List<UserEntity> saveUserList = newUserList.stream().map(item -> {
if (!oldUserMap.containsKey(item.getLoginName())) {
item.setCreateUserId(1L);
......@@ -88,10 +84,7 @@ public class SyncPortalUserTaskImpl implements ITaskExcuteService {
userService.getUserDao().insert(item);
});
}
}
//查找新增 与更新
}
}
......
......@@ -53,41 +53,13 @@ public class SyncRegisterUserPicTaskImpl implements ITaskExcuteService {
} else {
List<DoorEntity> doorEntities = doorService.find(new DoorQuery());
for (DoorEntity doorEntity : doorEntities) {
//todo 直连设备
//todo 直连设备获取员工照片
}
}
// syncRegisterUsersPhotos();
log.info("同步员工任务照片完成");
}
private void syncRegisterUsersPhotos() {
List<StaffEntity> staffList = staffService.find(new StaffQuery().source(1)).stream()
.filter(item -> ObjectUtils.isEmpty(item.getPhotoPath()))
.filter(item -> !ObjectUtils.isEmpty(item.getPicUri())).collect(Collectors.toList());
for (StaffEntity staff : staffList) {
ImgReq imgReq = new ImgReq();
imgReq.setServerIndexCode(staff.getServerIndexCode());
imgReq.setPicUri(staff.getPicUri());
try {
InputStream inputStream = hikFaceService.callPostImgs(imgReq);
if (!ObjectUtils.isEmpty(inputStream)) {
MultipartFile file = ServletUtils.getMultipartFile(inputStream, "photo.jpg");
String filePath = uploadService.saveFileUpload(file, "file/fileupload/staff", null);
staff.setPhotoPath(filePath);
staffService.update(staff);
} else {
log.error("获取图片异常!");
}
} catch (Exception e) {
log.error("下载图片异常", e.getMessage());
}
}
}
@Override
public void stopTask(ITask task) throws AppException {
......
......@@ -30,7 +30,7 @@ import java.util.List;
* 同步海康用户
*/
@Slf4j
@Service("SyncUserByDeviceDoorsTask")
//@Service("SyncUserByDeviceDoorsTask")
public class SyncUserByDeviceDoorsTaskImpl implements ITaskExcuteService {
@Autowired
......
......@@ -99,16 +99,9 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
log.error("同步钉钉usreId失败");
}
} else {
//todo 设备直连
deptService.syncDeptByDevice(null);
log.info("设备直连同步人员信息");
staffService.syncPersonsByDevices(null);
}
} catch (Exception e) {
log.error("同步人事异常", e);
}
......
......@@ -92,7 +92,7 @@ public class AcsMain {
/**登录*/
login_V40("192.168.0.111","admin","asd12345",(short)8000);
login_V40("10.102.221.201","admin","10.102.221.201",(short)8000);
/**远程控门*/
......
......@@ -53,13 +53,9 @@ public class DoorServiceImpl extends AbstractCRUDServiceImpl<DoorDao, DoorEntity
@Override
public Rest<Void> syncDoorDeviceEvents(DoorEntity doorEntity, HikDoorEventReq hikDoorEventReq) {
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();
......
......@@ -33,4 +33,21 @@ public interface IHikStaffService {
/**
* 获取人员人脸信息
*
* @param personReq
* @return
*/
Rest<UserSearchInfo> getPersonPicByDevices(StaffReq personReq, DoorEntity doorEntity);
/**
* 下发图片到指定设备
*
* @param personReq
* @return
*/
Rest<UserSearchInfo> downPersonPicToDevice(StaffReq personReq, DoorEntity doorEntity);
}
......@@ -202,4 +202,14 @@ public class HikStaffServiceImpl extends AbstractHikService implements IHikStaff
}
}
@Override
public Rest<UserSearchInfo> getPersonPicByDevices(StaffReq personReq, DoorEntity doorEntity) {
return null;
}
@Override
public Rest<UserSearchInfo> downPersonPicToDevice(StaffReq personReq, DoorEntity doorEntity) {
return null;
}
}
......@@ -352,10 +352,6 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta
//设置初始密码
entity.setLoginPwd("123456");
}
//生成用户id,不与门户服务用户相同
// Long userId = idgeneratorService.getLongId(USER_KEY);
// entity.setId(userId);
userEntity.setLoginName(StrUtil.cleanBlank(entity.getLoginName()));
userEntity.setRealName(entity.getName());
userEntity.setUserType(UserType.WORK_PERSON.getValue());
......@@ -505,6 +501,11 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta
public Rest<Void> syncPersonsByDevices(Context context) {
log.info("同步人员!");
//todo 门禁获取人员
StaffQuery staffQuery = new StaffQuery();
staffQuery.setSource(1);
staffQuery.setStatusNotList(Arrays.asList(StaffSatusEnum.离职.getValue()));
Map<String, StaffEntity> staffCollect = this.find(staffQuery).stream().collect(Collectors.toMap(x -> x.getWorkNum(), y -> y, (o, n) -> n));
List<DoorEntity> doorEntities = doorService.find(new DoorQuery());
for (DoorEntity doorEntity : doorEntities) {
StaffReq staffReq = new StaffReq();
......@@ -519,14 +520,7 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta
searchReq.setPageSize(size);
Rest<UserSearchInfo> rest = hikStaffService.getPersonList(searchReq, doorEntity);
if (rest.getCode() == YesNoEnum.YES.getValue()) {
//做差集 更新本地用户为离职员工
StaffQuery staffQuery = new StaffQuery();
staffQuery.setSource(1);
staffQuery.setStatusNotList(Arrays.asList(StaffSatusEnum.离职.getValue()));
Map<String, StaffEntity> staffCollect = this.find(staffQuery).stream().collect(Collectors.toMap(x -> x.getWorkNum(), y -> y, (o, n) -> n));
UserInfoSearch userInfoSearch = rest.getData().getUserInfoSearch();
List<UserInfoItem> userInfoList = userInfoSearch.getUserInfo();
for (UserInfoItem userInfoItem : userInfoList) {
......@@ -539,96 +533,86 @@ public class StaffServiceImpl extends AbstractCRUDCacheServiceImpl<StaffDao, Sta
staffCollect.remove(userInfoItem.getEmployeeNo());
}
StaffEntity staffEntity = this.getExtCache(StrUtil.padPre(userInfoItem.getEmployeeNo(), 8, "0"));
DeptEntity deptEntity = deptService.selectOne(new DeptQuery().deptCode(userInfoItem.getBelongGroup()));
//设置到默认部门
//判断本地数据是否为空
if (ObjectUtils.isEmpty(staffEntity)) {
//新增员工信息
staffEntity = new StaffEntity();
staffEntity.initAttrValue();
DeptQuery deptQuery = new DeptQuery();
deptQuery.setParentId(0L);
DeptEntity deptEntity = deptService.selectOne(deptQuery);
if (!ObjectUtils.isEmpty(deptEntity)) {
staffEntity.setDeptId(deptEntity.getId());
staffEntity.setDeptName(deptEntity.getDeptName());
}
staffEntity.setName(userInfoItem.getName());
staffEntity.setDeptName(userInfoItem.getBelongGroup());
staffEntity.setGender("male".equals(userInfoItem.getGender()) ? 1 : 2);
staffEntity.setWorkNum(userInfoItem.getEmployeeNo());
staffEntity.setCreateUserId(1L);
staffEntity.setCreateTime(new Date());
this.save(staffEntity);
} else {
//更新
if (!ObjectUtils.isEmpty(deptEntity)) {
staffEntity.setDeptId(deptEntity.getId());
}
staffEntity.setName(userInfoItem.getName());
staffEntity.setDeptName(userInfoItem.getBelongGroup());
staffEntity.setGender("male".equals(userInfoItem.getGender()) ? 1 : 2);
staffEntity.setWorkNum(userInfoItem.getEmployeeNo());
staffEntity.setUpdateUserId(1L);
staffEntity.setUpdateTime(new Date());
this.update(staffEntity);
}
}
if (staffCollect.size() > 0) {
//需要将此人员变更为离职
staffCollect.entrySet().stream().forEach(item -> {
String key = item.getKey();
if (!ObjectUtils.isEmpty(key)) {
StaffEntity staff = item.getValue();
staff.setStatus(StaffSatusEnum.离职.getValue());
staff.setUpdateTime(new Date());
staff.setUpdateUserId(1L);
this.update(staff);
//新增离职人员
StaffLeaveEntity staffLeaveEntity = new StaffLeaveEntity();
staffLeaveEntity.initAttrValue();
staffLeaveEntity.setStaffId(staff.getId());
staffLeaveEntity.setStaffName(staff.getName());
staffLeaveEntity.setGender(staff.getGender());
staffLeaveEntity.setBirthday(staff.getBirthday());
staffLeaveEntity.setPhotoPath(staff.getPhotoPath());
staffLeaveEntity.setPhoneNumber(staff.getPhoneNumber());
staffLeaveEntity.setIdCard(staff.getIdCard());
staffLeaveEntity.setWorkNum(staff.getWorkNum());
staffLeaveEntity.setPoliticalstatus(staff.getPoliticalstatus());
staffLeaveEntity.setDeptId(staff.getDeptId());
staffLeaveEntity.setDeptName(staff.getDeptName());
staffLeaveEntity.setJobId(staff.getPositionId());
staffLeaveEntity.setJobName(staff.getPositionName());
staffLeaveEntity.setStaffType(staff.getStaffType());
staffLeaveEntity.setStatus(StaffSatusEnum.离职.getValue());
staffLeaveEntity.setLeaveDate(new Date());
staffLeaveEntity.setLeaveReason("");
staffLeaveEntity.setAuditStatus(AuditStatusEnum.通过.getValue());
staffLeaveEntity.setCreateUserId(1L);
staffLeaveEntity.setCreateTime(new Date());
StaffLeaveQuery staffLeaveQuery = new StaffLeaveQuery();
staffLeaveQuery.setWorkNum(staff.getWorkNum());
int count = staffLeaveService.count(staffLeaveQuery, null);
if (count == 0) {
staffLeaveService.save(staffLeaveEntity);
}
Long[] groudStaffIds = attendanceGroupStaffService.find(new AttendanceGroupStaffQuery().staffId(staff.getId())).stream().map(m -> m.getId()).toArray(Long[]::new);
if (!ObjectUtils.isEmpty(groudStaffIds)) {
attendanceGroupStaffService.remove(groudStaffIds, null);
}
}
});
}
}
}
}
}
if (staffCollect.size() > 0) {
//需要将此人员变更为离职
staffCollect.entrySet().stream().forEach(item -> {
String key = item.getKey();
if (!ObjectUtils.isEmpty(key)) {
StaffEntity staff = item.getValue();
staff.setStatus(StaffSatusEnum.离职.getValue());
staff.setUpdateTime(new Date());
staff.setUpdateUserId(1L);
this.update(staff);
//新增离职人员
StaffLeaveEntity staffLeaveEntity = new StaffLeaveEntity();
staffLeaveEntity.initAttrValue();
staffLeaveEntity.setStaffId(staff.getId());
staffLeaveEntity.setStaffName(staff.getName());
staffLeaveEntity.setGender(staff.getGender());
staffLeaveEntity.setBirthday(staff.getBirthday());
staffLeaveEntity.setPhotoPath(staff.getPhotoPath());
staffLeaveEntity.setPhoneNumber(staff.getPhoneNumber());
staffLeaveEntity.setIdCard(staff.getIdCard());
staffLeaveEntity.setWorkNum(staff.getWorkNum());
staffLeaveEntity.setPoliticalstatus(staff.getPoliticalstatus());
staffLeaveEntity.setDeptId(staff.getDeptId());
staffLeaveEntity.setDeptName(staff.getDeptName());
staffLeaveEntity.setJobId(staff.getPositionId());
staffLeaveEntity.setJobName(staff.getPositionName());
staffLeaveEntity.setStaffType(staff.getStaffType());
staffLeaveEntity.setStatus(StaffSatusEnum.离职.getValue());
staffLeaveEntity.setLeaveDate(new Date());
staffLeaveEntity.setLeaveReason("");
staffLeaveEntity.setAuditStatus(AuditStatusEnum.通过.getValue());
staffLeaveEntity.setCreateUserId(1L);
staffLeaveEntity.setCreateTime(new Date());
StaffLeaveQuery staffLeaveQuery = new StaffLeaveQuery();
staffLeaveQuery.setWorkNum(staff.getWorkNum());
int count = staffLeaveService.count(staffLeaveQuery, null);
if (count == 0) {
staffLeaveService.save(staffLeaveEntity);
}
Long[] groudStaffIds = attendanceGroupStaffService.find(new AttendanceGroupStaffQuery().staffId(staff.getId())).stream().map(m -> m.getId()).toArray(Long[]::new);
if (!ObjectUtils.isEmpty(groudStaffIds)) {
attendanceGroupStaffService.remove(groudStaffIds, null);
}
}
});
}
return Rest.ok();
}
@Override
public Rest<Void> syncRegisterUsersPhotos() {
List<StaffEntity> staffList = this.find(new StaffQuery().source(1)).stream()
......
......@@ -33,6 +33,7 @@ import com.mortals.xhx.module.staff.model.vo.StaffCheckAuthorizePdu;
import com.mortals.xhx.module.staff.model.vo.StaffInfoVo;
import com.mortals.xhx.module.staff.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -70,6 +71,9 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ
@Autowired
private AttendanceLeaveRecordService leaveRecordService;
@Value("${hik.host:}")
protected String hikhost;
public StaffController() {
super.setModuleDesc("员工基本信息");
......@@ -227,11 +231,15 @@ public class StaffController extends BaseCRUDJsonBodyMappingController<StaffServ
JSONObject jsonObject = new JSONObject();
String busiDesc = this.getModuleDesc() + "同步";
try {
//同步部门
deptService.syncDept(getContext());
Rest<Void> rest = this.service.syncPersons(getContext());
if (rest.getCode() == YesNoEnum.NO.getValue()) {
throw new AppException("同步异常!");
if (!ObjectUtils.isEmpty(hikhost)) {
//同步部门
deptService.syncDept(getContext());
Rest<Void> rest = this.service.syncPersons(getContext());
if (rest.getCode() == YesNoEnum.NO.getValue()) {
throw new AppException("同步异常!");
}
}else{
this.service.syncPersonsByDevices(null);
}
recordSysLog(request, busiDesc + " 【成功】");
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
......
......@@ -11,6 +11,12 @@
"baseLogin": "http://192.168.0.98:11078/base"
},
"pengxi": {
"baseUrl": "http://10.102.252.13:11039/attendance",
"baseLogin": "http://192.168.0.98:11078/base"
},
"portal": {
"baseUrl": "http://192.168.0.98:11072/zwfw",
"baseLogin": "http://192.168.0.98:11078/base"
......
......@@ -146,3 +146,8 @@ Content-Type: application/json
"windowNum": "123123"
}
###设备直连更新人员
GET {{baseUrl}}/test/updatePersonsByDevices
Content-Type: application/json
{}
\ No newline at end of file
<?xml version="1.0" encoding="GB2312"?>
<SdkLocal>
<SdkLog>
<logLevel>3</logLevel><!--req, 1-ERROR, 2-DEBUG, 3-INFO-->
<logDirectory>./SDKLOG/</logDirectory><!--the end of the string must be '/'-->
<autoDelete>true</autoDelete><!--true: There are less than 10 files in the directory, it will be auto deleted by sdk when the files are more than 10; false: No upper limit to the number of log files-->
</SdkLog>
<HeartbeatCfg>
<Interval>120</Interval> <!-- 心跳时间间隔,单位秒,等于0,使用默认值120s,取值范围为[30, 120] 小于30s,间隔为30s,大于120s,间隔为120s-->
<Count>1</Count> <!-- 触发异常回调需要心跳交互异常的次数,等于0,使用默认值1次-->
</HeartbeatCfg>
</SdkLocal>
\ No newline at end of file
File added
File added
File added
File added
File added
【Demo内容说明】
-------------------------------------
1. 该Demo主要介绍以卡为中心的卡参数下发、人脸下发、指纹下发、人脸采集、事件查询等功能。
2. 该Demo使用Eclipse开发和编译运行。
【注意事项】
------------------------------------
1. 请到海康威视官网下载最新版本设备网络SDK:https://open.hikvision.com/download/5cda567cf47ae80dd41a54b3?type=10
2. 请修改程序代码,其中AcsMain.java中CreateSDKInstance()接口中指定SDK动态库的路径。此Demo在Win和Linux系统下通用,切换到Linux系统运行,CreateSDKInstance()接口中设置Linux系统SDK库文件路径。
3. Windows开发时需要将“库文件”文件夹中的HCNetSDK.dll、HCCore.dll、HCNetSDKCom文件夹、libssl-1_1-x64.dll、libcrypto-1_1-x64.dll、hlog.dll、hpr.dll、zlib1.dll等文件拷贝到lib文件夹下,HCNetSDKCom文件夹(包含里面的功能组件dll库文件)需要和HCNetSDK.dll、HCCore.dll一起加载,放在同一个目录下,且HCNetSDKCom文件夹名不能修改。如果自行开发软件不能正常实现相应功能,而且程序没有指定加载的dll库路径,请在程序运行的情况下尝试删除HCNetSDK.dll。如果可以删除,说明程序可能调用到系统盘Windows->System32目录下的dll文件,建议删除或者更新该目录下的相关dll文件;如果不能删除,dll文件右键选择属性确认SDK库版本。
4. Linux开发时需要将“库文件”文件夹中libhcnetsdk.so、libHCCore.so、libcrypto.so.1.1、libssl.so.1.1、libhpr.so、libz.so等文件拷贝到lib文件夹下。HCNetSDKCom文件夹(包含里面的功能组件dll库文件)需要和libhcnetsdk.so、libHCCore.so一起加载,放在同一个目录下,且HCNetSDKCom文件夹名不能修改。如果库文件加载有问题,初始化失败,也可以尝试将SDK所在路径添加到LD_LIBRARY_PATH环境变量中。
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