Commit 2c37042a authored by 赵啸非's avatar 赵啸非

添加钉钉对接流程代码

parent 2debb3ba
......@@ -105,7 +105,7 @@ public class StartedService implements IApplicationStartedService {
//deptService.syncDeptByDingTalk(null);
//staffService.syncPersonsByDingTalk(null);
String attendStart = "2025-03-05";
/* String attendStart = "2025-03-05";
String attendEnd = "2025-03-25";
......@@ -115,7 +115,7 @@ public class StartedService implements IApplicationStartedService {
hikQuery.setStaffId(8L);
checkDingDingEvent(DateUtil.parseDate(attendStart), DateUtil.parseDate(attendEnd), hikQuery);
checkDingDingEvent(DateUtil.parseDate(attendStart), DateUtil.parseDate(attendEnd), hikQuery);*/
// groupService.syncGroupByDingTalk();
......
package com.mortals.xhx.daemon.task;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
......@@ -10,6 +12,9 @@ import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.AttendSourceTypeEnum;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.module.attendance.model.AttendanceLeaveRecordQuery;
import com.mortals.xhx.module.attendance.model.AttendanceRecordHikQuery;
import com.mortals.xhx.module.attendance.service.AttendanceLeaveRecordService;
import com.mortals.xhx.module.attendance.service.AttendanceStatService;
import com.mortals.xhx.module.attendance.service.AttendanceVacationBalanceService;
import com.mortals.xhx.module.dept.model.DeptEntity;
......@@ -57,6 +62,9 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
@Value("${source.type:''}")
protected String sourceType;
@Autowired
private AttendanceLeaveRecordService attendanceLeaveRecordService;
@Override
public void excuteTask(ITask task) throws AppException {
......@@ -80,12 +88,35 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
log.info("同步钉钉usreId");
syncDingDingLocalUserIds();
log.info("钉钉直连同步人员信息");
//同步最近10天请假信息
DateTime weekStart = DateUtil.offsetDay(new Date(), -30);
AttendanceRecordHikQuery hikQuery = new AttendanceRecordHikQuery();
hikQuery.setAttendanceDateStart(DateUtil.format(weekStart, "yyyy-MM-dd"));
hikQuery.setAttendanceDateEnd(DateUtil.today());
checkDingDingEvent(hikQuery);
} else {
log.info("未配置考勤源类型!");
}
}
private void checkDingDingEvent(AttendanceRecordHikQuery hikEntity) {
log.info("开始同步钉钉请假事件!");
AttendanceLeaveRecordQuery query = new AttendanceLeaveRecordQuery();
query.setStartTimeStart(hikEntity.getAttendanceDateStart());
query.setEndTimeEnd(hikEntity.getAttendanceDateEnd());
query.setStaffId(hikEntity.getStaffId());
new Thread(() -> {
attendanceLeaveRecordService.syncLeaveRecord(query, null);
}).start();
}
private void syncDingDingUserIds() {
try {
List<UserEntity> userList = userService.getCacheList().stream()
......@@ -139,7 +170,7 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
StaffEntity staffCache = staffService.getCache(item.getCustomerId().toString());
if (!ObjectUtils.isEmpty(staffCache) ) {
if (!ObjectUtils.isEmpty(staffCache)) {
userEntity.setDingUserId(staffCache.getWorkNum());
}
......
......@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.dingtalkworkflow_1_0.models.ListProcessInstanceIdsResponse;
import com.aliyun.dingtalkworkflow_1_0.models.ListProcessInstanceIdsResponseBody;
import com.google.common.collect.Lists;
import com.mortals.framework.common.Rest;
import com.mortals.framework.model.OrderCol;
import com.mortals.framework.service.ICacheService;
......@@ -228,7 +229,24 @@ public class AttendanceLeaveRecordServiceImpl extends AbstractCRUDServiceImpl<At
}
private void getLeaveRecordByUserList(AttendanceLeaveRecordQuery query, List<UserEntity> userEntityList, List<AttendanceLeaveRecordEntity> waitSyncLeaveRecords) {
for (UserEntity item : userEntityList) {
List<List<UserEntity>> partition = Lists.partition(userEntityList, 10);
for (List<UserEntity> userList : partition) {
//String dingUserId = item.getDingUserId();
List<String> dingUserIds = userList.stream().map(m -> m.getDingUserId()).collect(Collectors.toList());
long startTime = DateUtil.parseDateTime(query.getStartTimeStart() + " 00:00:00").getTime();
long endTime = DateUtil.parseDateTime(query.getEndTimeEnd() + " 23:59:59").getTime();
Long nextToken = 0L;
long maxResults = 20L;
for (ProcessInstanceEnum processInstanceEnum : ProcessInstanceEnum.values()) {
try {
getRecords(waitSyncLeaveRecords, processInstanceEnum, startTime, endTime, nextToken, maxResults, dingUserIds);
} catch (Exception e) {
log.error("同步请假记录异常", e);
}
}
}
/* for (UserEntity item : userEntityList) {
String dingUserId = item.getDingUserId();
long startTime = DateUtil.parseDateTime(query.getStartTimeStart() + " 00:00:00").getTime();
long endTime = DateUtil.parseDateTime(query.getEndTimeEnd() + " 23:59:59").getTime();
......@@ -241,25 +259,24 @@ public class AttendanceLeaveRecordServiceImpl extends AbstractCRUDServiceImpl<At
log.error("同步请假记录异常", e);
}
}
}
}*/
}
private void getRecords(List<AttendanceLeaveRecordEntity> waitSyncLeaveRecords, UserEntity item, ProcessInstanceEnum processInstanceEnum, long startTime, long endTime, Long nextToken, long maxResults, String dingUserId) throws Exception {
Rest<ListProcessInstanceIdsResponseBody.ListProcessInstanceIdsResponseBodyResult> rest = dingPersonService.getProcessInstanceIdByUserIds(processInstanceEnum.getValue(), startTime, endTime, nextToken, maxResults, dingUserId);
private void getRecords(List<AttendanceLeaveRecordEntity> waitSyncLeaveRecords, ProcessInstanceEnum processInstanceEnum, long startTime, long endTime, Long nextToken, long maxResults, List<String> dingUserIds) throws Exception {
Rest<ListProcessInstanceIdsResponseBody.ListProcessInstanceIdsResponseBodyResult> rest = dingPersonService.getProcessInstanceIdByUserIds(processInstanceEnum.getValue(), startTime, endTime, nextToken, maxResults, dingUserIds);
if (YesNoEnum.YES.getValue() == rest.getCode()) {
if (ObjectUtils.isEmpty(rest.getData().getNextToken())) {
List<String> processInstanceList = rest.getData().getList();
for (String process : processInstanceList) {
AttendanceLeaveRecordEntity leaveRecord = new AttendanceLeaveRecordEntity();
leaveRecord.setRemark(process);
leaveRecord.setStaffId(item.getCustomerId());
// leaveRecord.setStaffId(item.getCustomerId());
waitSyncLeaveRecords.add(leaveRecord);
log.info("更新记录成功==>" + process);
}
} else {
nextToken = DataUtil.converStr2Long(rest.getData().getNextToken(), 0L);
getRecords(waitSyncLeaveRecords, item, processInstanceEnum, startTime, endTime, nextToken, maxResults, dingUserId);
getRecords(waitSyncLeaveRecords, processInstanceEnum, startTime, endTime, nextToken, maxResults, dingUserIds);
}
}
}
......
......@@ -92,7 +92,7 @@ public interface IDingPersonService extends IDingTalkService {
* @param maxResults 分页参数,每页大小,最多传20。
* @param userIds 发起人id列表 最大列表长度为10
*/
Rest<ListProcessInstanceIdsResponseBody.ListProcessInstanceIdsResponseBodyResult> getProcessInstanceIdByUserIds(String processCode, long startTime, long endTime, Long nextToken, long maxResults, String userIds) throws Exception;
Rest<ListProcessInstanceIdsResponseBody.ListProcessInstanceIdsResponseBodyResult> getProcessInstanceIdByUserIds(String processCode, long startTime, long endTime, Long nextToken, long maxResults, List<String> userIds) throws Exception;
/**
......
......@@ -208,30 +208,27 @@ public class DingPersonServiceImpl extends AbstractDingTalkService implements ID
* "success" : true
* }
*/
public Rest<ListProcessInstanceIdsResponseBody.ListProcessInstanceIdsResponseBodyResult> getProcessInstanceIdByUserIds(String processCode, long startTime, long endTime, Long nextToken, long maxResults, String userIds) throws Exception {
if (!userIds.equals("")) {
public Rest<ListProcessInstanceIdsResponseBody.ListProcessInstanceIdsResponseBodyResult> getProcessInstanceIdByUserIds(String processCode, long startTime, long endTime, Long nextToken, long maxResults, List<String> userIds) throws Exception {
if (!ObjectUtils.isEmpty(userIds)) {
com.aliyun.dingtalkworkflow_1_0.Client client = new com.aliyun.dingtalkworkflow_1_0.Client(setConfig());
com.aliyun.dingtalkworkflow_1_0.models.ListProcessInstanceIdsHeaders listProcessInstanceIdsHeaders = new com.aliyun.dingtalkworkflow_1_0.models.ListProcessInstanceIdsHeaders();
listProcessInstanceIdsHeaders.xAcsDingtalkAccessToken = getToken();
HashMap<String, String> map = new HashMap<>();
listProcessInstanceIdsHeaders.setCommonHeaders(map);
// log.info("oaUrl===>{}",oaUrl);
/* if (!ObjectUtils.isEmpty(oaUrl)) {
if (!ObjectUtils.isEmpty(oaUrl)) {
listProcessInstanceIdsHeaders.getCommonHeaders().put("host", oaUrl);
}*/
}
// listProcessInstanceIdsHeaders.getCommonHeaders().put("host", "172.15.28.113:8919");
com.aliyun.dingtalkworkflow_1_0.models.ListProcessInstanceIdsRequest listProcessInstanceIdsRequest = new ListProcessInstanceIdsRequest()
.setProcessCode(processCode)
/* .setStartTime(startTime)
.setStartTime(startTime)
.setEndTime(endTime)
.setNextToken(nextToken)*/
.setStartTime(1742732000000L)
.setEndTime(1742918399000L)
.setNextToken(0L)
.setNextToken(nextToken)
.setMaxResults(maxResults)
.setStatuses(Arrays.asList("COMPLETED"))
.setUserIds(java.util.Arrays.asList(userIds));
.setUserIds(userIds);
try {
RuntimeOptions runtimeOptions = new RuntimeOptions();
runtimeOptions.setReadTimeout(60000);
......
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