Commit 15d2a115 authored by 赵啸非's avatar 赵啸非

添加适配直连考勤机定时任务代码

parent c993d21a
package com.mortals.xhx.daemon.task; package com.mortals.xhx.daemon.task;
import cn.hutool.http.HttpUtil;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask; import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService; import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.framework.utils.ServletUtils; import com.mortals.framework.utils.ServletUtils;
import com.mortals.xhx.base.system.upload.service.UploadService; import com.mortals.xhx.base.system.upload.service.UploadService;
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.face.model.req.img.ImgReq; 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.hik.face.service.IHikFaceService;
import com.mortals.xhx.module.staff.model.StaffEntity; import com.mortals.xhx.module.staff.model.StaffEntity;
import com.mortals.xhx.module.staff.model.StaffQuery; import com.mortals.xhx.module.staff.model.StaffQuery;
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.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -38,11 +38,25 @@ public class SyncRegisterUserPicTaskImpl implements ITaskExcuteService { ...@@ -38,11 +38,25 @@ public class SyncRegisterUserPicTaskImpl implements ITaskExcuteService {
@Autowired @Autowired
private StaffService staffService; private StaffService staffService;
@Value("${hik.host:}")
protected String hikhost;
@Autowired
private DoorService doorService;
@Override @Override
public void excuteTask(ITask task) throws AppException { public void excuteTask(ITask task) throws AppException {
log.info("同步员工照片任务"); log.info("同步员工照片任务");
syncRegisterUsersPhotos(); if (!ObjectUtils.isEmpty(hikhost)) {
staffService.syncRegisterUsersPhotos();
} else {
List<DoorEntity> doorEntities = doorService.find(new DoorQuery());
for (DoorEntity doorEntity : doorEntities) {
//todo 直连设备
}
}
// syncRegisterUsersPhotos();
log.info("同步员工任务照片完成"); log.info("同步员工任务照片完成");
} }
...@@ -53,7 +67,6 @@ public class SyncRegisterUserPicTaskImpl implements ITaskExcuteService { ...@@ -53,7 +67,6 @@ public class SyncRegisterUserPicTaskImpl implements ITaskExcuteService {
.filter(item -> ObjectUtils.isEmpty(item.getPhotoPath())) .filter(item -> ObjectUtils.isEmpty(item.getPhotoPath()))
.filter(item -> !ObjectUtils.isEmpty(item.getPicUri())).collect(Collectors.toList()); .filter(item -> !ObjectUtils.isEmpty(item.getPicUri())).collect(Collectors.toList());
for (StaffEntity staff : staffList) { for (StaffEntity staff : staffList) {
ImgReq imgReq = new ImgReq(); ImgReq imgReq = new ImgReq();
imgReq.setServerIndexCode(staff.getServerIndexCode()); imgReq.setServerIndexCode(staff.getServerIndexCode());
......
...@@ -23,6 +23,7 @@ import com.mortals.xhx.module.staff.service.StaffLeaveService; ...@@ -23,6 +23,7 @@ import com.mortals.xhx.module.staff.service.StaffLeaveService;
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.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -47,53 +48,67 @@ public class SyncUserTaskImpl implements ITaskExcuteService { ...@@ -47,53 +48,67 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
private IHikPersonService hikPersonService; private IHikPersonService hikPersonService;
@Autowired @Autowired
private IDingPersonService dingPersonService; private IDingPersonService dingPersonService;
@Value("${hik.host:}")
protected String hikhost;
@Override @Override
public void excuteTask(ITask task) throws AppException { public void excuteTask(ITask task) throws AppException {
try { try {
log.info("同步部门"); if (!ObjectUtils.isEmpty(hikhost)) {
deptService.syncDept(null); log.info("同步部门");
log.info("同步用户"); deptService.syncDept(null);
staffService.syncPersons(null); log.info("同步用户");
log.info("同步钉钉usreId"); staffService.syncPersons(null);
try { log.info("同步钉钉usreId");
List<UserEntity> userList = userService.getCacheList().stream() try {
.filter(f -> !ObjectUtils.isEmpty(f.getCustomerId())) List<UserEntity> userList = userService.getCacheList().stream()
.filter(f -> ObjectUtils.isEmpty(f.getDingUserId())).collect(Collectors.toList()); .filter(f -> !ObjectUtils.isEmpty(f.getCustomerId()))
List<UserEntity> updateUserList = userList.stream().map(item -> { .filter(f -> ObjectUtils.isEmpty(f.getDingUserId())).collect(Collectors.toList());
UserEntity userEntity = new UserEntity(); List<UserEntity> updateUserList = userList.stream().map(item -> {
userEntity.setId(item.getId()); UserEntity userEntity = new UserEntity();
userEntity.setId(item.getId());
String mobile = "";
StaffEntity staffCache = staffService.getCache(item.getCustomerId().toString()); String mobile = "";
if (!ObjectUtils.isEmpty(staffCache) && !ObjectUtils.isEmpty(staffCache.getPhoneNumber())) { StaffEntity staffCache = staffService.getCache(item.getCustomerId().toString());
mobile = staffCache.getPhoneNumber(); if (!ObjectUtils.isEmpty(staffCache) && !ObjectUtils.isEmpty(staffCache.getPhoneNumber())) {
if (ObjectUtils.isEmpty(item.getMobile())) { mobile = staffCache.getPhoneNumber();
userEntity.setMobile(mobile); if (ObjectUtils.isEmpty(item.getMobile())) {
userEntity.setMobile(mobile);
}
} }
}
if (!ObjectUtils.isEmpty(mobile)) { if (!ObjectUtils.isEmpty(mobile)) {
Rest<String> personByMobile = dingPersonService.getPersonByMobile(mobile); Rest<String> personByMobile = dingPersonService.getPersonByMobile(mobile);
if (!ObjectUtils.isEmpty(personByMobile) && if (!ObjectUtils.isEmpty(personByMobile) &&
YesNoEnum.YES.getValue() == personByMobile.getCode() YesNoEnum.YES.getValue() == personByMobile.getCode()
&& !ObjectUtils.isEmpty(personByMobile.getData())) { && !ObjectUtils.isEmpty(personByMobile.getData())) {
userEntity.setDingUserId(personByMobile.getData()); userEntity.setDingUserId(personByMobile.getData());
}
} }
}
userEntity.setUpdateTime(new Date()); userEntity.setUpdateTime(new Date());
userEntity.setUpdateUserId(1L); userEntity.setUpdateUserId(1L);
return userEntity; return userEntity;
}).filter(f -> !ObjectUtils.isEmpty(f.getDingUserId())).collect(Collectors.toList()); }).filter(f -> !ObjectUtils.isEmpty(f.getDingUserId())).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(updateUserList)) { if (!ObjectUtils.isEmpty(updateUserList)) {
log.info("更新用户钉钉id信息数量:{}", updateUserList.size()); log.info("更新用户钉钉id信息数量:{}", updateUserList.size());
userService.getUserDao().updateBatch(updateUserList); userService.getUserDao().updateBatch(updateUserList);
}
} catch (Exception e) {
log.error("同步钉钉usreId失败");
} }
} catch (Exception e) { } else {
log.error("同步钉钉usreId失败"); //todo 设备直连
deptService.syncDeptByDevice(null);
staffService.syncPersonsByDevices(null);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("同步人事异常", e); log.error("同步人事异常", e);
} }
......
...@@ -91,4 +91,12 @@ public interface DeptService extends ICRUDService<DeptEntity, Long> { ...@@ -91,4 +91,12 @@ public interface DeptService extends ICRUDService<DeptEntity, Long> {
*/ */
Rest<String> syncDept(Context context); Rest<String> syncDept(Context context);
/**
* 通过设备同步部门信息
* @param context
* @return
*/
Rest<String> syncDeptByDevice(Context context);
} }
\ No newline at end of file
...@@ -341,4 +341,12 @@ public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity ...@@ -341,4 +341,12 @@ public class DeptServiceImpl extends AbstractCRUDServiceImpl<DeptDao, DeptEntity
return Rest.ok(); return Rest.ok();
} }
@Override
public Rest<String> syncDeptByDevice(Context context) {
//todo
return Rest.ok();
}
} }
package com.mortals.xhx.module.door.model; package com.mortals.xhx.module.door.model;
import java.util.List;
import java.util.ArrayList;
import java.math.BigDecimal;
import cn.hutool.core.date.DateUtil;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mortals.framework.annotation.Excel;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.door.model.vo.DoorVo; import com.mortals.xhx.module.door.model.vo.DoorVo;
import lombok.Data; import lombok.Data;
/** /**
* 门禁设备实体对象 * 门禁设备实体对象
* *
* @author zxfei * @author zxfei
* @date 2023-11-22 * @date 2024-03-18
*/ */
@Data @Data
public class DoorEntity extends DoorVo { public class DoorEntity extends DoorVo {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* 设备名称 * 设备名称
*/ */
private String deviceName; private String deviceName;
/** /**
* 设备编码 * 设备编码
*/ */
private String deviceCode; private String deviceCode;
/** /**
* Ip地址 * Ip地址
*/ */
private String ip; private String ip;
/** /**
* 端口 * 端口
*/ */
private Integer port; private Integer port;
/** /**
* 用户名 * 用户名
*/ */
private String username; private String username;
/** /**
* 密码 * 密码
*/ */
private String password; private String password;
/**
* 所属部门id
*/
private String deptId;
/**
* 所属部门名称
*/
private String deptName;
/**
* 备注
*/
private String remark;
@Override @Override
public int hashCode() { public int hashCode() {
return this.getId().hashCode(); return this.getId().hashCode();
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
...@@ -45,18 +65,21 @@ public class DoorEntity extends DoorVo { ...@@ -45,18 +65,21 @@ public class DoorEntity extends DoorVo {
if (obj instanceof DoorEntity) { if (obj instanceof DoorEntity) {
DoorEntity tmp = (DoorEntity) obj; DoorEntity tmp = (DoorEntity) obj;
if (this.getId() == tmp.getId()) { if (this.getId() == tmp.getId()) {
return true; return true;
} }
} }
return false; return false;
} }
public void initAttrValue(){ public void initAttrValue(){
this.deviceName = ""; this.deviceName = "";
this.deviceCode = ""; this.deviceCode = "";
this.ip = ""; this.ip = "";
this.port = 0; this.port = 0;
this.username = ""; this.username = "";
this.password = ""; this.password = "";
this.deptId = "";
this.deptName = "";
this.remark = "";
} }
} }
\ No newline at end of file
...@@ -51,11 +51,6 @@ public class DoorServiceImpl extends AbstractCRUDServiceImpl<DoorDao, DoorEntity ...@@ -51,11 +51,6 @@ public class DoorServiceImpl extends AbstractCRUDServiceImpl<DoorDao, DoorEntity
@Autowired @Autowired
private IHikDoorService hikDoorService; private IHikDoorService hikDoorService;
private Integer day;
@Autowired
private ICacheService cacheService;
@Override @Override
public Rest<Void> syncDoorDeviceEvents(DoorEntity doorEntity, HikDoorEventReq hikDoorEventReq) { public Rest<Void> syncDoorDeviceEvents(DoorEntity doorEntity, HikDoorEventReq hikDoorEventReq) {
......
...@@ -53,4 +53,10 @@ public interface StaffService extends ICRUDCacheService<StaffEntity,Long> { ...@@ -53,4 +53,10 @@ public interface StaffService extends ICRUDCacheService<StaffEntity,Long> {
*/ */
void doUpdateSala(); void doUpdateSala();
/**
* 通过海康云同步用户 照片
* @return
*/
Rest<Void> syncRegisterUsersPhotos();
} }
\ No newline at end of file
...@@ -1175,29 +1175,6 @@ ADD COLUMN `salaId` bigint(20) COMMENT '所属大厅' AFTER `deptName`, ...@@ -1175,29 +1175,6 @@ ADD COLUMN `salaId` bigint(20) COMMENT '所属大厅' AFTER `deptName`,
ADD COLUMN `salaName` varchar(128) COMMENT '所属大厅名称' AFTER `salaId`; ADD COLUMN `salaName` varchar(128) COMMENT '所属大厅名称' AFTER `salaId`;
-- ----------------------------
2024-02-29
-- ----------------------------
-- ----------------------------
-- 门禁设备表
-- ----------------------------
DROP TABLE IF EXISTS `mortals_xhx_door`;
CREATE TABLE mortals_xhx_door(
`id` bigint(20) AUTO_INCREMENT COMMENT '序号,主键,自增长',
`deviceName` varchar(64) COMMENT '设备名称',
`deviceCode` varchar(64) COMMENT '设备编码',
`ip` varchar(64) COMMENT 'Ip地址',
`port` int(9) COMMENT '端口',
`username` varchar(64) COMMENT '用户名',
`password` varchar(64) COMMENT '密码',
`createTime` datetime COMMENT '创建时间',
`createUserId` bigint(20) COMMENT '创建用户',
`updateUserId` bigint(20) COMMENT '更新用户',
`updateTime` datetime COMMENT '修改时间',
PRIMARY KEY (`id`)
,KEY `deviceCode` (`deviceCode`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='门禁设备';
-- ------------------ -- ------------------
-- 2024-03-12 -- 2024-03-12
-- 绩效表增加人员大厅字段 -- 绩效表增加人员大厅字段
...@@ -1270,4 +1247,31 @@ ALTER TABLE `mortals_xhx_staff_perform_stat` ...@@ -1270,4 +1247,31 @@ ALTER TABLE `mortals_xhx_staff_perform_stat`
ALTER TABLE `mortals_xhx_staff_perform_summary` ALTER TABLE `mortals_xhx_staff_perform_summary`
ADD COLUMN `salaId` bigint(20) DEFAULT NULL COMMENT '所属大厅' AFTER `deptName`, ADD COLUMN `salaId` bigint(20) DEFAULT NULL COMMENT '所属大厅' AFTER `deptName`,
ADD COLUMN `salaName` varchar(128) DEFAULT NULL COMMENT '所属大厅名称' AFTER `salaId`; ADD COLUMN `salaName` varchar(128) DEFAULT NULL COMMENT '所属大厅名称' AFTER `salaId`;
\ No newline at end of file
-- ----------------------------
2024-03-18
-- ----------------------------
-- ----------------------------
-- 门禁设备表
-- ----------------------------
DROP TABLE IF EXISTS `mortals_xhx_door`;
CREATE TABLE mortals_xhx_door(
`id` bigint(20) AUTO_INCREMENT COMMENT '序号,主键,自增长',
`deviceName` varchar(64) COMMENT '设备名称',
`deviceCode` varchar(64) COMMENT '设备编码',
`ip` varchar(64) COMMENT 'Ip地址',
`port` int(9) COMMENT '端口',
`username` varchar(64) COMMENT '用户名',
`password` varchar(64) COMMENT '密码',
`createTime` datetime COMMENT '创建时间',
`createUserId` bigint(20) COMMENT '创建用户',
`updateUserId` bigint(20) COMMENT '更新用户',
`updateTime` datetime COMMENT '修改时间',
`deptId` bigint (20) COMMENT '所属部门id',
`deptName` varchar(64) COMMENT '所属部门名称',
`remark` varchar(256) COMMENT '备注',
PRIMARY KEY (`id`)
,KEY `deviceCode` (`deviceCode`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='门禁设备';
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