Commit 85f1e265 authored by 赵啸非's avatar 赵啸非

添加用户钉钉主动拉取请假记录

parent c01ca213
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author: finegirl
* @date: 2021/7/16 11:50
* @description: 组件枚举类
**/
public enum ProcessInstanceEnum {
请假("PROC-2E5C0DFF-3615-4409-A614-A2011FED5D38", "请假"),
外出("PROC-56D3ADEE-45A4-47BC-931A-2A0DC067DE32", "外出"),
出差("PROC-578CBDDF-B768-496D-9918-44A3F1D9CAE7", "出差");
private String value;
private String desc;
ProcessInstanceEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static ProcessInstanceEnum getByValue(String value) {
for (ProcessInstanceEnum componentEnum : ProcessInstanceEnum.values()) {
if (componentEnum.getValue() == value) {
return componentEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(String... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (ProcessInstanceEnum item : ProcessInstanceEnum.values()) {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
......@@ -73,15 +73,15 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
UserEntity userEntity = new UserEntity();
userEntity.setId(item.getId());
String mobile = item.getMobile();
if (ObjectUtils.isEmpty(mobile)) {
//根据customerId查询staff 看是否有
String mobile="";
StaffEntity staffCache = staffService.getCache(item.getCustomerId().toString());
if (!ObjectUtils.isEmpty(staffCache) && !ObjectUtils.isEmpty(staffCache.getPhoneNumber())) {
mobile = staffCache.getPhoneNumber();
if(ObjectUtils.isEmpty(item.getMobile())){
userEntity.setMobile(mobile);
}
}
if (!ObjectUtils.isEmpty(mobile)) {
Rest<String> personByMobile = dingPersonService.getPersonByMobile(mobile);
if (!ObjectUtils.isEmpty(personByMobile) &&
......
......@@ -33,4 +33,7 @@ public class AttendanceLeaveRecordVo extends BaseEntityLong {
/** 结束 创建时间 */
private String createTimeEnd;
private Long staffId;
}
\ No newline at end of file
package com.mortals.xhx.module.attendance.service;
import com.mortals.framework.common.Rest;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.attendance.model.AttendanceLeaveRecordEntity;
import com.mortals.xhx.module.attendance.model.AttendanceLeaveRecordQuery;
import org.springframework.web.bind.annotation.RequestBody;
/**
* AttendanceLeaveRecordService
......@@ -15,4 +18,7 @@ public interface AttendanceLeaveRecordService extends ICRUDService<AttendanceLea
//根据remark(钉钉返回的id)查询对象
AttendanceLeaveRecordEntity doUpdateRecord(String processInstanceId,AttendanceLeaveRecordEntity leaveRecordEntity) throws Exception;
Rest<String> syncLeaveRecord(AttendanceLeaveRecordQuery query, Context context);
}
\ No newline at end of file
package com.mortals.xhx.module.attendance.service.impl;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.dingtalkworkflow_1_0.models.ListProcessInstanceIdsResponse;
import com.aliyun.dingtalkworkflow_1_0.models.ListProcessInstanceIdsResponseBody;
import com.mortals.framework.common.Rest;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.util.DataUtil;
import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.ThreadPool;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.AppealResultEnum;
import com.mortals.xhx.common.code.AuditStatusEnum;
import com.mortals.xhx.common.code.ProcessInstanceEnum;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.utils.AddAttendThread;
import com.mortals.xhx.common.utils.AttendSummaryThread;
import com.mortals.xhx.module.attendance.model.AttendanceLeaveRecordQuery;
......@@ -14,6 +23,8 @@ import com.mortals.xhx.module.attendance.model.AttendanceRecordHikQuery;
import com.mortals.xhx.module.attendance.model.vo.AttendanceSummaryQuery;
import com.mortals.xhx.module.attendance.service.AttendanceRecordHikService;
import com.mortals.xhx.module.attendance.service.AttendanceStatService;
import com.mortals.xhx.module.dingding.personal.service.IDingPersonService;
import com.mortals.xhx.module.staff.service.StaffService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -24,7 +35,11 @@ import com.mortals.xhx.module.attendance.dao.AttendanceLeaveRecordDao;
import com.mortals.xhx.module.attendance.model.AttendanceLeaveRecordEntity;
import com.mortals.xhx.module.attendance.service.AttendanceLeaveRecordService;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import static com.mortals.xhx.common.key.RedisKey.KEY_ATTENDANCE_STAT_CACHE;
......@@ -42,9 +57,14 @@ public class AttendanceLeaveRecordServiceImpl extends AbstractCRUDServiceImpl<At
private AttendanceStatService attendanceStatService;
@Autowired
private ICacheService cacheService;
@Autowired
private StaffService staffService;
@Autowired
private UserService userService;
@Autowired
private AttendanceRecordHikService hikService;
@Autowired
private IDingPersonService dingPersonService;
@Override
protected void updateAfter(AttendanceLeaveRecordEntity entity, Context context) throws AppException {
......@@ -91,6 +111,7 @@ public class AttendanceLeaveRecordServiceImpl extends AbstractCRUDServiceImpl<At
/**
* 更新汇总信息
*
* @param entity
* @param context
*/
......@@ -102,7 +123,7 @@ public class AttendanceLeaveRecordServiceImpl extends AbstractCRUDServiceImpl<At
return;
}
//更新考勤记录与异常记录
if (AppealResultEnum.通过.getValue() == entity.getAuditResult()||AppealResultEnum.撤销审批通过.getValue() == entity.getAuditResult()) {
if (AppealResultEnum.通过.getValue() == entity.getAuditResult() || AppealResultEnum.撤销审批通过.getValue() == entity.getAuditResult()) {
AttendanceRecordHikQuery attendanceRecordHikQuery = new AttendanceRecordHikQuery();
attendanceRecordHikQuery.setStaffId(entity.getLeavePersonId());
//判断请假的开始日期与结束日期
......@@ -111,7 +132,7 @@ public class AttendanceLeaveRecordServiceImpl extends AbstractCRUDServiceImpl<At
//当前日期在请假期间,计算考勤结束时间为当前时间;
attendanceRecordHikQuery.setAttendanceDateStart(DateUtil.formatDate(entity.getStartTime()));
attendanceRecordHikQuery.setAttendanceDateEnd(DateUtil.today());
}else{
} else {
attendanceRecordHikQuery.setAttendanceDateStart(DateUtil.formatDate(entity.getStartTime()));
attendanceRecordHikQuery.setAttendanceDateEnd(DateUtil.formatDate(entity.getEndTime()));
}
......@@ -119,4 +140,69 @@ public class AttendanceLeaveRecordServiceImpl extends AbstractCRUDServiceImpl<At
ThreadPool.getInstance().execute(addAttendThread);
}
}
@Override
public Rest<String> syncLeaveRecord(AttendanceLeaveRecordQuery query, Context context) {
List<AttendanceLeaveRecordEntity> waitSyncLeaveRecords = new ArrayList<>();
Long staffId = query.getStaffId();
List<UserEntity> userCacheList = userService.getCacheList();
if (ObjectUtils.isEmpty(staffId)) {
//同步所有用户
List<UserEntity> userEntityList = userCacheList.stream()
.filter(f -> ObjectUtils.isEmpty(f.getDingUserId())).collect(Collectors.toList());
getLeaveRecordByUserList(query, userEntityList, waitSyncLeaveRecords);
} else {
//同步指定用户
List<UserEntity> userEntityList = userCacheList.stream()
.filter(f -> ObjectUtils.isEmpty(f.getDingUserId()))
.filter(f -> staffId == f.getCustomerId())
.collect(Collectors.toList());
getLeaveRecordByUserList(query, userEntityList, waitSyncLeaveRecords);
}
if (!ObjectUtils.isEmpty(waitSyncLeaveRecords)) {
//todo 同步查询详细记录 并更新
for (AttendanceLeaveRecordEntity waitSyncLeaveRecord : waitSyncLeaveRecords) {
dingPersonService.handleByProcessInstanceId(waitSyncLeaveRecord.getRemark());
}
}
return Rest.ok();
}
private void getLeaveRecordByUserList(AttendanceLeaveRecordQuery query, List<UserEntity> userEntityList, List<AttendanceLeaveRecordEntity> waitSyncLeaveRecords) {
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();
Long nextToken = null;
long maxResults = 20L;
for (ProcessInstanceEnum processInstanceEnum : ProcessInstanceEnum.values()) {
try {
getRecords(waitSyncLeaveRecords, item, processInstanceEnum, startTime, endTime, nextToken, maxResults, dingUserId);
} catch (Exception e) {
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);
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());
waitSyncLeaveRecords.add(leaveRecord);
}
} else {
nextToken = DataUtil.converStr2Long(rest.getData().getNextToken(), 0L);
getRecords(waitSyncLeaveRecords, item, processInstanceEnum, startTime, endTime, nextToken, maxResults, dingUserId);
}
}
}
}
\ No newline at end of file
package com.mortals.xhx.module.attendance.web;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.unit.DataUnit;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.ThreadPool;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.base.system.user.model.UserQuery;
......@@ -9,12 +17,16 @@ import com.mortals.xhx.common.code.ProcessStatusEnum;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.feign.user.IUserFeign;
import com.mortals.xhx.module.attendance.model.AttendanceLeaveRecordEntity;
import com.mortals.xhx.module.attendance.model.AttendanceLeaveRecordQuery;
import com.mortals.xhx.module.attendance.service.AttendanceLeaveRecordService;
import com.mortals.xhx.module.dept.model.DeptQuery;
import com.mortals.xhx.module.dept.service.DeptService;
import com.mortals.xhx.module.workman.model.WorkmanQuery;
import com.mortals.xhx.module.workman.service.WorkmanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -27,15 +39,14 @@ import java.util.stream.Collectors;
import static java.util.stream.Collectors.toMap;
/**
*
* 请假记录信息
*
* @author zxfei
* @date 2023-04-07
*/
* 请假记录信息
*
* @author zxfei
* @date 2023-04-07
*/
@RestController
@RequestMapping("attendance/leave/record")
public class AttendanceLeaveRecordController extends BaseCRUDJsonBodyMappingController<AttendanceLeaveRecordService,AttendanceLeaveRecordEntity,Long> {
public class AttendanceLeaveRecordController extends BaseCRUDJsonBodyMappingController<AttendanceLeaveRecordService, AttendanceLeaveRecordEntity, Long> {
@Autowired
private ParamService paramService;
......@@ -48,15 +59,15 @@ public class AttendanceLeaveRecordController extends BaseCRUDJsonBodyMappingCont
// @Autowired
// private IUserFeign iUserFeign;
public AttendanceLeaveRecordController(){
super.setModuleDesc( "请假记录信息");
public AttendanceLeaveRecordController() {
super.setModuleDesc("请假记录信息");
}
@Override
protected void init(Map<String, Object> model, Context context) {
this.addDict(model, "deptId", deptService.find(new DeptQuery()).stream().collect(toMap(x->x.getId().toString(), y->y.getDeptName(),(o, n)->n)));
this.addDict(model, "approverId", workmanService.find(new WorkmanQuery()).stream().collect(toMap(x->x.getId().toString(), y->y.getName(),(o, n)->n)));
this.addDict(model, "leaveType", paramService.getParamBySecondOrganize("AttendanceLeaveRecord","leaveType"));
this.addDict(model, "deptId", deptService.find(new DeptQuery()).stream().collect(toMap(x -> x.getId().toString(), y -> y.getDeptName(), (o, n) -> n)));
this.addDict(model, "approverId", workmanService.find(new WorkmanQuery()).stream().collect(toMap(x -> x.getId().toString(), y -> y.getName(), (o, n) -> n)));
this.addDict(model, "leaveType", paramService.getParamBySecondOrganize("AttendanceLeaveRecord", "leaveType"));
this.addDict(model, "auditResult", AppealResultEnum.getEnumMap());
this.addDict(model, "processStatus", ProcessStatusEnum.getEnumMap());
this.addDict(model, "createUserId", userService.find(new UserQuery()).stream().collect(toMap(x -> x.getId().toString(), y -> y.getRealName(), (o, n) -> n)));
......@@ -79,4 +90,41 @@ public class AttendanceLeaveRecordController extends BaseCRUDJsonBodyMappingCont
}
/**
* 主动同步拉取请假考勤记录
*/
@PostMapping(value = "syncLeaveRecord")
public String syncLeaveRecord(@RequestBody AttendanceLeaveRecordQuery query) {
JSONObject jsonObject = new JSONObject();
String busiDesc = this.getModuleDesc() + "主动同步拉取请假考勤记录";
try {
if(ObjectUtils.isEmpty(query.getStartTimeStart()))throw new AppException("开始时间不能为空");
if(ObjectUtils.isEmpty(query.getStartTimeEnd()))throw new AppException("结束时间不能为空");
long between = DateUtil.between(DateUtil.parseDate(query.getStartTimeStart()), DateUtil.parseDate(query.getStartTimeEnd()), DateUnit.DAY, true);
if(between>120){
throw new AppException("时间范围不能超过120天");
}
Context context = this.getContext();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
service.syncLeaveRecord(query, context);
}
});
ThreadPool.getInstance().execute(thread);
recordSysLog(request, busiDesc + " 【成功】");
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
} catch (Exception e) {
log.error("主动同步拉取请假考勤记录", e);
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
jsonObject.put(KEY_RESULT_MSG, super.convertException(e));
}
return jsonObject.toJSONString();
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ package com.mortals.xhx.module.dingding.personal.service;
import com.aliyun.dingtalkattendance_1_0.models.GetLeaveRecordsResponseBody;
import com.aliyun.dingtalkworkflow_1_0.models.GetProcessInstanceResponseBody;
import com.aliyun.dingtalkworkflow_1_0.models.ListProcessInstanceIdsResponse;
import com.aliyun.dingtalkworkflow_1_0.models.ListProcessInstanceIdsResponseBody;
import com.dingtalk.api.response.OapiAttendanceVacationQuotaListResponse;
import com.dingtalk.api.response.OapiV2UserGetResponse;
import com.mortals.framework.common.Rest;
......@@ -88,6 +89,8 @@ public interface IDingPersonService extends IDingTalkService {
* @param maxResults 分页参数,每页大小,最多传20。
* @param userIds 发起人id列表 最大列表长度为10
*/
Rest<ListProcessInstanceIdsResponse> 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, String userIds) throws Exception;
}
......@@ -82,7 +82,7 @@ POST {{baseUrl}}//attendance/stat/summary
Authorization: {{authToken}}
Content-Type: application/json
{"summaryTimeStart":"2023-12-01","summaryTimeEnd":"2023-12-31"}
{"summaryTimeStart":"2024-01-01","summaryTimeEnd":"2024-12-30"}
###短信设置编辑
......
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