Commit 6bcb80aa authored by 赵啸非's avatar 赵啸非

修改请假计算考勤

parent 79a8dbbe
package com.mortals.xhx.module.attendance.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.dingtalkworkflow_1_0.models.ListProcessInstanceIdsResponse;
......@@ -40,6 +42,7 @@ import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.module.attendance.dao.AttendanceLeaveRecordDao;
import com.mortals.xhx.module.attendance.service.AttendanceLeaveRecordService;
import org.springframework.util.StopWatch;
import java.math.BigDecimal;
import java.util.ArrayList;
......@@ -81,8 +84,10 @@ public class AttendanceLeaveRecordServiceImpl extends AbstractCRUDServiceImpl<At
@Autowired
private PerformRulesService performRulesService;
/** 员工事假请假数据key 员工id+开始时间+结束时间*/
private static String LEAVE_REIDS_KEY ="attendance:leave:";
/**
* 员工事假请假数据key 员工id+开始时间+结束时间
*/
private static String LEAVE_REIDS_KEY = "attendance:leave:";
@Override
protected void updateAfter(AttendanceLeaveRecordEntity entity, Context context) throws AppException {
......@@ -140,15 +145,15 @@ public class AttendanceLeaveRecordServiceImpl extends AbstractCRUDServiceImpl<At
int compare = DateUtil.compare(entity.getStartTime(), new Date());
if (compare > 0) {
//请假未来 不做处理
log.info("请假未来 不做处理! {}",entity.getLeavePerson());
log.info("请假未来 不做处理! {}", entity.getLeavePerson());
return;
}
//更新考勤记录与异常记录
if (AppealResultEnum.通过.getValue() == entity.getAuditResult() || AppealResultEnum.撤销审批通过.getValue() == entity.getAuditResult()) {
AttendanceRecordHikQuery attendanceRecordHikQuery = new AttendanceRecordHikQuery();
attendanceRecordHikQuery.setStaffId(entity.getLeavePersonId());
AttendanceRecordHikEntity hikEntity = new AttendanceRecordHikEntity();
hikEntity.setStaffId(entity.getLeavePersonId());
//判断请假的开始日期与结束日期
boolean in = DateUtil.isIn(new Date(), entity.getStartTime(), entity.getEndTime());
/* boolean in = DateUtil.isIn(new Date(), entity.getStartTime(), entity.getEndTime());
if (in) {
//当前日期在请假期间,计算考勤结束时间为当前时间;
attendanceRecordHikQuery.setAttendanceDateStart(DateUtil.formatDate(entity.getStartTime()));
......@@ -156,10 +161,30 @@ public class AttendanceLeaveRecordServiceImpl extends AbstractCRUDServiceImpl<At
} else {
attendanceRecordHikQuery.setAttendanceDateStart(DateUtil.formatDate(entity.getStartTime()));
attendanceRecordHikQuery.setAttendanceDateEnd(DateUtil.formatDate(entity.getEndTime()));
}*/
//todo: 存在多线程问题 这里不能使用
DateTime attendStart = DateUtil.parseDate(DateUtil.formatDate(entity.getStartTime()));
DateTime attendEnd = DateUtil.parseDate(DateUtil.formatDate(entity.getEndTime()));
Long compare1 = DateUtil.between(attendEnd, attendStart, DateUnit.DAY);
log.info("考勤计算天数区间:{}", compare1);
for (int i = 0; i <= compare1.intValue(); i++) {
DateTime curDate = DateUtil.offsetDay(attendStart, i);
hikEntity.setAttendanceDateStart(curDate.toDateStr());
hikEntity.setAttendanceDateEnd(curDate.toDateStr());
hikEntity.setOrderColList(Arrays.asList(new OrderCol("attendanceDate")));
try {
hikService.addAttendanceRecordByQuery(hikEntity, context);
} catch (Exception e) {
log.error("同步请假记录异常", e);
}
}
AddAttendThread addAttendThread = new AddAttendThread(hikService, attendanceRecordHikQuery, context);
ThreadPool.getInstance().execute(addAttendThread);
/* AddAttendThread addAttendThread = new AddAttendThread(hikService, attendanceRecordHikQuery, context);
ThreadPool.getInstance().execute(addAttendThread);*/
}
}
......@@ -235,9 +260,9 @@ public class AttendanceLeaveRecordServiceImpl extends AbstractCRUDServiceImpl<At
//以半天4小时为计算单位进行扣分
int multiple = entity.getDuration() / 14400;
if (multiple > 0) {
String redisKey = entity.getLeavePersonId()+"_"+entity.getLeavePerson()+"_"+DateUtils.getDateTimeStr(entity.getStartTime(),"yyyyMMddHHmmss")+"_"+DateUtils.getDateTimeStr(entity.getEndTime(),"yyyyMMddHHmmss");
String redisKey = entity.getLeavePersonId() + "_" + entity.getLeavePerson() + "_" + DateUtils.getDateTimeStr(entity.getStartTime(), "yyyyMMddHHmmss") + "_" + DateUtils.getDateTimeStr(entity.getEndTime(), "yyyyMMddHHmmss");
String leaveKey = cacheService.get(LEAVE_REIDS_KEY + redisKey);
if(StringUtils.isEmpty(leaveKey)) {
if (StringUtils.isEmpty(leaveKey)) {
cacheService.set(LEAVE_REIDS_KEY + redisKey, redisKey, 300); //五分钟内不会重复
PerformAttendRecordEntity recordEntity = conversionLeaveRecord(entity);
recordEntity.setCreateTime(new Date());
......@@ -257,7 +282,7 @@ public class AttendanceLeaveRecordServiceImpl extends AbstractCRUDServiceImpl<At
cacheService.lpush(KEY_CHECK_SUMMARY_CACHE, checkSummaryQuery);
}
} catch (Exception e) {
log.error("创建假期考勤异常",e.getMessage());
log.error("创建假期考勤异常", e.getMessage());
}
}
......
......@@ -46,9 +46,9 @@ POST {{baseUrl}}/attendance/record/hik/addAttendanceRecord
Content-Type: application/json
{
"attendanceDateStart": "2024-08-19",
"attendanceDateEnd": "2024-08-19",
"staffId": 207
"attendanceDateStart": "2024-08-26",
"attendanceDateEnd": "2024-08-26",
"staffId": 346
}
......
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