| | |
| | | package me.zhengjie.modules.quartz.service.impl; |
| | | |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.google.gson.Gson; |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.chanjar.weixin.common.error.WxErrorException; |
| | | import me.chanjar.weixin.cp.api.WxCpService; |
| | | import me.chanjar.weixin.cp.bean.message.WxCpMessage; |
| | | import me.chanjar.weixin.cp.bean.oa.WxCpCheckinData; |
| | | import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl; |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.attendance.domain.*; |
| | | import me.zhengjie.modules.attendance.repository.*; |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceLeaveQueryCriteria; |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceOvertimeQueryCriteria; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.system.domain.SysConfigHoliday; |
| | | import me.zhengjie.modules.system.domain.SysRostering; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import me.zhengjie.modules.project.domain.Project; |
| | | import me.zhengjie.modules.project.domain.ProjectCostOther; |
| | | import me.zhengjie.modules.project.domain.ProjectCostSummary; |
| | | import me.zhengjie.modules.project.domain.ProjectType; |
| | | import me.zhengjie.modules.project.repository.ProjectCostOtherRepository; |
| | | import me.zhengjie.modules.project.repository.ProjectCostRepository; |
| | | import me.zhengjie.modules.project.repository.ProjectRepository; |
| | | import me.zhengjie.modules.project.repository.ProjectTypeRepository; |
| | | import me.zhengjie.modules.project.service.dto.ProjectQueryCriteria; |
| | | import me.zhengjie.modules.system.domain.*; |
| | | import me.zhengjie.modules.system.repository.DictDetailRepository; |
| | | import me.zhengjie.modules.system.repository.SysConfigHolidayRepository; |
| | | import me.zhengjie.modules.system.repository.SysRosteringRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import me.zhengjie.modules.system.service.DeptService; |
| | | import me.zhengjie.modules.system.service.DictDetailService; |
| | | import me.zhengjie.modules.system.service.dto.UserQueryCriteria; |
| | | import me.zhengjie.modules.task.domain.TaskDaliyMongo; |
| | | import me.zhengjie.modules.task.domain.TaskMongo; |
| | | import me.zhengjie.modules.task.domain.TaskUserMongo; |
| | | import me.zhengjie.modules.task.service.dto.TaskDaliyMongoDto; |
| | | import me.zhengjie.modules.treatment.domain.UserInsurance; |
| | | import me.zhengjie.modules.treatment.domain.UserLevelWage; |
| | | import me.zhengjie.modules.treatment.repository.UserInsuranceRepository; |
| | | import me.zhengjie.modules.treatment.repository.UserLevelWageRepository; |
| | | import me.zhengjie.utils.DateUtil; |
| | | import me.zhengjie.utils.QueryHelp; |
| | | import me.zhengjie.utils.StringUtils; |
| | | import me.zhengjie.modules.weixin.cp.api.WxCpOaWeDocSmartsheetService; |
| | | import me.zhengjie.modules.weixin.cp.bean.smartsheet.field.*; |
| | | import me.zhengjie.modules.weixin.cp.bean.smartsheet.record.*; |
| | | import me.zhengjie.modules.weixin.cp.bean.smartsheet.sheet.*; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.apache.commons.lang3.SerializationUtils; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.aggregation.Aggregation; |
| | | import org.springframework.data.mongodb.core.aggregation.AggregationResults; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.Duration; |
| | | import java.time.LocalDateTime; |
| | | import java.time.*; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class WeComServiceImpl { |
| | | private final WxCpService wxCpService; |
| | | private final NewAttendanceRepository attendanceRepository; |
| | | private final AttendanceRepository attendanceRepository; |
| | | private final UserRepository userRepository; |
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository; |
| | | private final SysRosteringRepository sysRosteringRepository; |
| | |
| | | private final AttendanceLeaveRepository attendanceLeaveRepository; |
| | | private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository; |
| | | private final AttendanceGoOutRepository attendanceGoOutRepository; |
| | | private final DictDetailService dictDetailService; |
| | | private final DeptService deptService; |
| | | private final WxCpOaWeDocSmartsheetService wxCpOaWeDocSmartsheetService; |
| | | private final AttendanceOvertimeRepository attendanceOvertimeRepository; |
| | | private final DictDetailRepository dictDetailRepository; |
| | | private final ProjectRepository projectRepository; |
| | | private final ProjectTypeRepository projectTypeRepository; |
| | | private final ProjectCostRepository projectCostRepository; |
| | | private final ProjectCostOtherRepository projectCostOtherRepository; |
| | | private final UserLevelWageRepository sysUserLevelWageRepository; |
| | | private final UserInsuranceRepository sysUserLevelInsuranceRepository; |
| | | private final MongoTemplate mongoTemplate; |
| | | |
| | | /** |
| | | * 凌晨0点执行,新增用户考勤信息 |
| | |
| | | if (ObjectUtils.isEmpty(attendDate) || attendDate.compareTo(Timestamp.valueOf(strTodayDate + " 00:00:00")) <= 0) { |
| | | // 用户列表 |
| | | List<User> userList = new ArrayList<>(); |
| | | // 获取企业微信考勤白名单 |
| | | List<String> excludeList = dictDetailService.getDictByName(Constant.DICT_WECOM_EXCLUDE_LIST).stream().map(i -> i.getValue()).collect(Collectors.toList()); |
| | | // 参数用户不为空(考勤按钮调用) |
| | | if (ObjectUtils.isNotEmpty(attUser)) { |
| | | // 用户列表 |
| | | userList = attUser; |
| | | userList = userList.stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList()); |
| | | userList = userList.stream().filter(i -> StringUtils.isNotBlank(i.getWeComId()) && !excludeList.contains(i.getWeComId())).collect(Collectors.toList()); |
| | | } else { |
| | | // 用户列表:查询状态正常的员工 |
| | | userList = getUserList().stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList()); |
| | | userList = getUserList().stream().filter(i -> StringUtils.isNotBlank(i.getWeComId()) && !excludeList.contains(i.getWeComId())).collect(Collectors.toList()); |
| | | } |
| | | // 参数日期 |
| | | String strAttendDate = ""; |
| | |
| | | // 用户排班 |
| | | SysRostering sysRostering = sysRosteringRepository.findByRosId(user.getSysRostering().getId()); |
| | | // 考勤记录 |
| | | NewAttendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), (ObjectUtils.isEmpty(attendDate) ? strTodayDate : strAttendDate)); |
| | | Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), (ObjectUtils.isEmpty(attendDate) ? strTodayDate : strAttendDate)); |
| | | // 考勤记录为null |
| | | if (ObjectUtil.isEmpty(attendance)) { |
| | | // 新建考勤记录 |
| | | attendance = new NewAttendance(); |
| | | attendance = new Attendance(); |
| | | } |
| | | // 考勤记录 |
| | | attendance.setUserId(user.getId()); |
| | |
| | | attendance.setStartClockResults((ObjectUtil.isNotEmpty(attendance.getStartClockResults()) && attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_NORMAL)) ? attendance.getStartClockResults() : Constant.ATTENDANCE_STATE_WAITFOR); |
| | | attendance.setEndClockResults((ObjectUtil.isNotEmpty(attendance.getEndClockResults()) && attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_NORMAL)) ? attendance.getEndClockResults() : Constant.ATTENDANCE_STATE_WAITFOR); |
| | | // 考勤日期类是否是周末、节假日、工作日 |
| | | if (sysConfigHoliday == null && (calAttendDay.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDay.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)) { |
| | | // 考勤记录:日期类型-双休 |
| | | attendance.setDateType(Constant.DATE_TYPE_WEEKEND); |
| | | } else if (sysConfigHoliday != null && sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) { |
| | | // 考勤记录:日期类型-节假日 |
| | | attendance.setDateType(Constant.DATE_TYPE_LEGAL_HOLIDAYS); |
| | | } else if (sysConfigHoliday != null && sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS)) { |
| | | // 考勤记录:日期类型-法定节假日 |
| | | attendance.setDateType(Constant.DATE_TYPE_HOLIDAYS); |
| | | if (sysConfigHoliday == null) { |
| | | if (calAttendDay.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDay.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { |
| | | // 考勤记录:日期类型-双休 |
| | | attendance.setDateType(Constant.DATE_TYPE_WEEKEND); |
| | | } else { |
| | | // 考勤记录:日期类型-工作日 |
| | | attendance.setDateType(Constant.DATE_TYPE_WEEKDAY); |
| | | } |
| | | } else { |
| | | // 考勤记录:日期类型-工作日 |
| | | attendance.setDateType(Constant.DATE_TYPE_WEEKDAY); |
| | | // 考勤记录:日期类型-节假日 |
| | | attendance.setDateType(sysConfigHoliday.getDateType()); |
| | | } |
| | | // 时间格式化 |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); |
| | |
| | | // 获取企业微信Token |
| | | wxCpService.getAccessToken(); |
| | | |
| | | // 获取参数日期类 |
| | | Calendar calAttendDate = Calendar.getInstance(); |
| | | // 日期格式化 |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | // 参数日期 |
| | | String strAttendDate = ""; |
| | | // 参数日期 TODO:0731修改 企微设置打卡时段为跨天的(当天4:00:00至次日03:59:59) |
| | | String startAttendDate = ""; |
| | | String endAttendDate = ""; |
| | | // 参数日期不为null(考勤按钮调用) |
| | | if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | // 参数日期 |
| | | strAttendDate = attendDate; |
| | | startAttendDate = attendDate; |
| | | } else { |
| | | // 参数日期 |
| | | strAttendDate = df.format(new Date()); |
| | | startAttendDate = df.format(new Date()); |
| | | } |
| | | // 获取参数日期类 |
| | | Calendar calAttendDate = Calendar.getInstance(); |
| | | calAttendDate.setTime(Timestamp.valueOf(strAttendDate + " 00:00:00")); |
| | | // 参数日期 |
| | | calAttendDate.setTime(df.parse(startAttendDate)); |
| | | calAttendDate.add(Calendar.DATE, 1); |
| | | endAttendDate = df.format(calAttendDate.getTime()); |
| | | // 参数日期类 |
| | | calAttendDate.setTime(Timestamp.valueOf(startAttendDate + " 00:00:00")); |
| | | // 用户列表 |
| | | List<User> userList; |
| | | // 获取企业微信考勤白名单 |
| | | List<String> excludeList = dictDetailService.getDictByName(Constant.DICT_WECOM_EXCLUDE_LIST).stream().map(i -> i.getValue()).collect(Collectors.toList()); |
| | | // 参数用户不为空(考勤按钮调用) |
| | | if (ObjectUtils.isNotEmpty(attUser)) { |
| | | // 用户列表 |
| | | userList = attUser; |
| | | userList = userList.stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList()); |
| | | userList = userList.stream().filter(i -> StringUtils.isNotBlank(i.getWeComId()) && !excludeList.contains(i.getWeComId())).collect(Collectors.toList()); |
| | | } else { |
| | | // 用户列表:查询状态正常的员工 |
| | | userList = getUserList().stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList()); |
| | | userList = getUserList().stream().filter(i -> StringUtils.isNotBlank(i.getWeComId()) && !excludeList.contains(i.getWeComId())).collect(Collectors.toList()); |
| | | } |
| | | // 遍历用户列表 |
| | | for (User user : userList) { |
| | | // 考勤记录:根据用户和日期查询 |
| | | NewAttendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), strAttendDate); |
| | | Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), startAttendDate); |
| | | // TODO:20250801修改 当天新建用户没有经过0点的考勤信息创建会空指针,需要创建记录 |
| | | if (attendance == null || attendance.getId().equals(null)) { |
| | | getWeComAttendanceList(Timestamp.valueOf(startAttendDate + " 00:00:00"), Arrays.asList(user)); |
| | | attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), startAttendDate); |
| | | } |
| | | |
| | | Boolean isHoliday = false; |
| | | if (calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS)) { |
| | | // 因存在周六日是工作日的情况,所以不能单纯用周六日作为判断条件 |
| | | if (attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND)) { |
| | | isHoliday = true; |
| | | } |
| | | // 如果是周六或者周日或节假日,打卡状态为等待的话,就改状态为休息(返回结果为空数组的情况下) |
| | | if (ObjectUtils.isNotEmpty(attendance) && (calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS))) { |
| | | if (ObjectUtils.isNotEmpty(attendance) && isHoliday) { |
| | | // 开始打卡结果 |
| | | if (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR)) { |
| | | if (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR) || attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_LACK_OF_TIME)) { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_REST); |
| | | attendance.setStartLocationResults(Constant.LOCATION_RESULTS_REST); |
| | | attendance.setActualWorkStartTime(null); |
| | | } |
| | | // 结束打卡结果 |
| | | if (attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR)) { |
| | | if (attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR) || attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_LACK_OF_TIME)) { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_REST); |
| | | attendance.setEndLocationResults(Constant.LOCATION_RESULTS_REST); |
| | | attendance.setActualWorkEndTime(null); |
| | |
| | | // 企业微信ID |
| | | List<String> userWeComList = new ArrayList<>(); |
| | | userWeComList.add(user.getWeComId()); |
| | | System.out.println("开始查询用户" + user.getWeComId() + "的" + strAttendDate + "考勤记录"); |
| | | // 企微打卡数据 |
| | | List<WxCpCheckinData> weComRecordResultList = wxCpService.getOaService().getCheckinData(1, sdf.parse(strAttendDate + " 00:00:00"), sdf.parse(strAttendDate + " 23:59:59"), userWeComList); |
| | | // 遍历企微打卡数据 |
| | | for (WxCpCheckinData weComRecordResult : weComRecordResultList) { |
| | | // 无打卡记录 |
| | | if (StringUtils.isNotBlank(weComRecordResult.getExceptionType()) && weComRecordResult.getExceptionType().contains("未打卡")) { |
| | | // 企微打卡数据 |
| | | weComRecordResult.setCheckinTime(null); |
| | | } |
| | | Timestamp checkInTime = unixtimeToTimestamp(weComRecordResult.getCheckinTime()); |
| | | // 早打卡 |
| | | if ("上班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getStartClockResults(), attendance.getActualWorkStartTime()); |
| | | // 考勤记录 |
| | | if (!isHoliday) { |
| | | attendance.setStartClockResults(flag == true ? attendance.getStartClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 1))); |
| | | } else { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | System.out.println("开始查询用户" + user.getWeComId() + "的" + startAttendDate + "考勤记录"); |
| | | try { |
| | | // 企微打卡数据 TODO:0731修改 企微设置打卡时段为跨天的(当天4:00:00至次日03:59:59) |
| | | List<WxCpCheckinData> weComRecordResultList = wxCpService.getOaService().getCheckinData(1, sdf.parse(startAttendDate + " 04:00:00"), sdf.parse(endAttendDate + " 03:59:59"), userWeComList); |
| | | // 遍历企微打卡数据 |
| | | for (WxCpCheckinData weComRecordResult : weComRecordResultList) { |
| | | // 无打卡记录 |
| | | if (StringUtils.isNotBlank(weComRecordResult.getExceptionType()) && weComRecordResult.getExceptionType().contains("未打卡")) { |
| | | // 企微打卡数据 |
| | | weComRecordResult.setCheckinTime(null); |
| | | } |
| | | attendance.setStartLocationResults(flag == true ? attendance.getStartLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkStartTime(flag == true ? attendance.getActualWorkStartTime() : checkInTime); |
| | | } |
| | | // 晚打卡 |
| | | if ("下班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getEndClockResults(), attendance.getActualWorkEndTime()); |
| | | // 考勤记录 |
| | | if (!isHoliday) { |
| | | attendance.setEndClockResults(flag == true ? attendance.getEndClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 2))); |
| | | } else { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | Timestamp checkInTime = unixtimeToTimestamp(weComRecordResult.getCheckinTime()); |
| | | // 早打卡 |
| | | // TODO:补充上班补卡记录 |
| | | if (ObjectUtils.isEmpty(attendance.getActualWorkStartTime()) && !isHoliday && (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR) || attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_LACK_OF_TIME))) { |
| | | cardDatetimeSupplement(attendance.getUserId(), startAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOON, attendance); |
| | | } |
| | | attendance.setEndLocationResults(flag == true ? attendance.getEndLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkEndTime(flag == true ? attendance.getActualWorkEndTime() : checkInTime); |
| | | if ("上班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getStartClockResults(), attendance.getActualWorkStartTime()); |
| | | // 考勤记录 |
| | | if (!isHoliday) { |
| | | attendance.setStartClockResults(flag == true ? attendance.getStartClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 1, null))); |
| | | } else { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | } |
| | | attendance.setStartLocationResults(flag == true ? attendance.getStartLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkStartTime(flag == true ? attendance.getActualWorkStartTime() : checkInTime); |
| | | } |
| | | // 晚打卡 |
| | | // TODO:补充下班补卡记录 |
| | | if (ObjectUtils.isEmpty(attendance.getActualWorkEndTime()) && !isHoliday && (attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR) || attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_LACK_OF_TIME))) { |
| | | cardDatetimeSupplement(attendance.getUserId(), startAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOOFF, attendance); |
| | | } |
| | | if ("下班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getEndClockResults(), attendance.getActualWorkEndTime()); |
| | | // 考勤记录 |
| | | if (!isHoliday) { |
| | | attendance.setEndClockResults(flag == true ? attendance.getEndClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 2, LocalDate.parse(startAttendDate)))); |
| | | } else { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | } |
| | | attendance.setEndLocationResults(flag == true ? attendance.getEndLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkEndTime(flag == true ? attendance.getActualWorkEndTime() : checkInTime); |
| | | } |
| | | } |
| | | } |
| | | // 修改考勤打卡状态 |
| | | if (ObjectUtils.isNotEmpty(attendance)) { |
| | | attendance = updateRecord(user, attendance, true, attendDate); |
| | | attendanceRepository.save(attendance); |
| | | // 修改考勤打卡状态 |
| | | if (ObjectUtils.isNotEmpty(attendance)) { |
| | | getMornOrNoon(user,attendance,attendDate,attendance.getRosteringWorkStartTime(),attendance.getRosteringWorkEndTime(), true); |
| | | // attendance = updateRecord(user, attendance, true, attendDate); |
| | | attendanceRepository.save(attendance); |
| | | } |
| | | } catch (WxErrorException wxe) { |
| | | System.out.println(wxe.getMessage()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } catch (WxErrorException wxErrorException) { |
| | | wxErrorException.printStackTrace(); |
| | | sendNotice(Arrays.asList("YueYuHuanXiangQinYuFenDou"), "企微通信异常", String.format("<div class=\"normal\">异常方法:%s</div>" + |
| | | "<div class=\"highlight\">请前往API服务查看LOG。</div>", |
| | | "getWeComAttendanceListOfNoon"), Constant.WECOM_MESSAGE_TYPE_TEXTCARD); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void getWeComAttendanceListOfNight(String attendDate, List attUser) throws Exception { |
| | | // 获取企业微信Token |
| | | wxCpService.getAccessToken(); |
| | | |
| | | try { |
| | | // 获取企业微信Token |
| | | wxCpService.getAccessToken(); |
| | | |
| | | // 获取参数日期类 |
| | | Calendar calAttendDate = Calendar.getInstance(); |
| | | // 日期格式化 |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | // 参数日期 |
| | | String strAttendDate = ""; |
| | | // 参数日期 TODO:0731修改 企微设置打卡时段为跨天的(当天4:00:00至次日03:59:59) |
| | | String startAttendDate = ""; |
| | | String endAttendDate = ""; |
| | | // 参数日期不为null(考勤按钮调用) |
| | | if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | // 参数日期 |
| | | strAttendDate = attendDate; |
| | | startAttendDate = attendDate; |
| | | } else { |
| | | // 参数日期类 |
| | | calAttendDate.add(Calendar.DATE, -1); |
| | | // 参数日期 |
| | | strAttendDate = df.format(calAttendDate.getTime()); |
| | | startAttendDate = df.format(calAttendDate.getTime()); |
| | | } |
| | | // 参数日期 |
| | | calAttendDate.setTime(df.parse(startAttendDate)); |
| | | calAttendDate.add(Calendar.DATE, 1); |
| | | endAttendDate = df.format(calAttendDate.getTime()); |
| | | // 参数日期类 |
| | | calAttendDate.setTime(Timestamp.valueOf(strAttendDate + " 00:00:00")); |
| | | calAttendDate.setTime(Timestamp.valueOf(startAttendDate + " 00:00:00")); |
| | | // 用户列表 |
| | | List<User> userList; |
| | | // 获取企业微信考勤白名单 |
| | | List<String> excludeList = dictDetailService.getDictByName(Constant.DICT_WECOM_EXCLUDE_LIST).stream().map(i -> i.getValue()).collect(Collectors.toList()); |
| | | // 参数用户不为空(考勤按钮调用) |
| | | if (ObjectUtils.isNotEmpty(attUser)) { |
| | | // 用户列表 |
| | | userList = attUser; |
| | | userList = userList.stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList()); |
| | | userList = userList.stream().filter(i -> StringUtils.isNotBlank(i.getWeComId()) && !excludeList.contains(i.getWeComId())).collect(Collectors.toList()); |
| | | } else { |
| | | // 用户列表:查询状态正常的员工 |
| | | userList = getUserList().stream().filter(i -> StringUtils.isNotBlank(i.getWeComId())).collect(Collectors.toList()); |
| | | userList = getUserList().stream().filter(i -> StringUtils.isNotBlank(i.getWeComId()) && !excludeList.contains(i.getWeComId())).collect(Collectors.toList()); |
| | | } |
| | | // 遍历用户列表 |
| | | for (User user : userList) { |
| | | // 考勤记录:根据用户和日期查询 |
| | | NewAttendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), strAttendDate); |
| | | Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), startAttendDate); |
| | | // TODO:20250801修改 当天新建用户没有经过0点的考勤信息创建会空指针,需要创建记录 |
| | | if (attendance == null || attendance.getId().equals(null)) { |
| | | getWeComAttendanceList(Timestamp.valueOf(startAttendDate + " 00:00:00"), Arrays.asList(user)); |
| | | attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(user.getId(), startAttendDate); |
| | | } |
| | | |
| | | Boolean isHoliday = false; |
| | | if (calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS)) { |
| | | // 因存在周六日是工作日的情况,所以不能单纯用周六日作为判断条件 |
| | | if (attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND)) { |
| | | isHoliday = true; |
| | | } |
| | | // 如果是周六或者周日或节假日,打卡状态为等待的话,就改状态为休息(oapiDingTalkRecordResultList为空的情况下) |
| | | if (ObjectUtils.isNotEmpty(attendance) && (calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calAttendDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS) || attendance.getDateType().equals(Constant.DATE_TYPE_HOLIDAYS))) { |
| | | if (ObjectUtils.isNotEmpty(attendance) && isHoliday) { |
| | | // 开始打卡结果 |
| | | if (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR)) { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_REST); |
| | |
| | | // 企业微信ID |
| | | List<String> userWeComList = new ArrayList<>(); |
| | | userWeComList.add(user.getWeComId()); |
| | | System.out.println("开始查询用户" + user.getWeComId() + "的" + strAttendDate + "考勤记录"); |
| | | // 企微打卡数据 |
| | | List<WxCpCheckinData> weComRecordResultList = wxCpService.getOaService().getCheckinData(1, sdf.parse(strAttendDate + " 00:00:00"), sdf.parse(strAttendDate + " 23:59:59"), userWeComList); |
| | | // 遍历企微打卡数据 |
| | | for (WxCpCheckinData weComRecordResult : weComRecordResultList) { |
| | | // 无打卡记录 |
| | | if (StringUtils.isNotBlank(weComRecordResult.getExceptionType()) && weComRecordResult.getExceptionType().contains("未打卡")) { |
| | | // 企微打卡数据 |
| | | weComRecordResult.setCheckinTime(null); |
| | | } |
| | | Timestamp checkInTime = unixtimeToTimestamp(weComRecordResult.getCheckinTime()); |
| | | // 早打卡 |
| | | if ("上班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getStartClockResults(), attendance.getActualWorkStartTime()); |
| | | // 考勤记录 |
| | | if (!isHoliday) { |
| | | attendance.setStartClockResults(flag == true ? attendance.getStartClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 1))); |
| | | } else { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | System.out.println("开始查询用户" + user.getWeComId() + "的" + startAttendDate + "考勤记录"); |
| | | try { |
| | | // 企微打卡数据 TODO:0731修改 企微设置打卡时段为跨天的(当天4:00:00至次日03:59:59) |
| | | List<WxCpCheckinData> weComRecordResultList = wxCpService.getOaService().getCheckinData(1, sdf.parse(startAttendDate + " 04:00:00"), sdf.parse(endAttendDate + " 03:59:59"), userWeComList); |
| | | // 遍历企微打卡数据 |
| | | for (WxCpCheckinData weComRecordResult : weComRecordResultList) { |
| | | // 无打卡记录 |
| | | if (StringUtils.isNotBlank(weComRecordResult.getExceptionType()) && weComRecordResult.getExceptionType().contains("未打卡")) { |
| | | // 企微打卡数据 |
| | | weComRecordResult.setCheckinTime(null); |
| | | } |
| | | attendance.setStartLocationResults(flag == true ? attendance.getStartLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkStartTime(flag == true ? attendance.getActualWorkStartTime() : checkInTime); |
| | | } |
| | | // 晚打卡 |
| | | if ("下班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getEndClockResults(), attendance.getActualWorkEndTime()); |
| | | // 考勤记录 |
| | | if (!isHoliday) { |
| | | attendance.setEndClockResults(flag == true ? attendance.getEndClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 2))); |
| | | } else { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | Timestamp checkInTime = unixtimeToTimestamp(weComRecordResult.getCheckinTime()); |
| | | // 早打卡 |
| | | // TODO:补充上班补卡记录 |
| | | if (ObjectUtils.isEmpty(attendance.getActualWorkStartTime()) && !isHoliday && (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR) || attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_LACK_OF_TIME))) { |
| | | cardDatetimeSupplement(attendance.getUserId(), startAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOON, attendance); |
| | | } |
| | | attendance.setEndLocationResults(flag == true ? attendance.getEndLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkEndTime(flag == true ? attendance.getActualWorkEndTime() : checkInTime); |
| | | if ("上班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getStartClockResults(), attendance.getActualWorkStartTime()); |
| | | // 考勤记录 |
| | | if (!isHoliday) { |
| | | attendance.setStartClockResults(flag == true ? attendance.getStartClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 1, null))); |
| | | } else { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | } |
| | | attendance.setStartLocationResults(flag == true ? attendance.getStartLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkStartTime(flag == true ? attendance.getActualWorkStartTime() : checkInTime); |
| | | } |
| | | // 晚打卡 |
| | | // TODO:补充下班补卡记录 |
| | | if (ObjectUtils.isEmpty(attendance.getActualWorkEndTime()) && !isHoliday && (attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR) || attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_LACK_OF_TIME))) { |
| | | cardDatetimeSupplement(attendance.getUserId(), startAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOOFF, attendance); |
| | | } |
| | | if ("下班打卡".equals(weComRecordResult.getCheckinType())) { |
| | | // 调用验证状态方法 |
| | | Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getEndClockResults(), attendance.getActualWorkEndTime()); |
| | | // 考勤记录 |
| | | if (!isHoliday) { |
| | | attendance.setEndClockResults(flag == true ? attendance.getEndClockResults() : (ObjectUtil.isEmpty(weComRecordResult.getCheckinTime()) ? Constant.ATTENDANCE_STATE_NOTSIGNED : checkResult(user.getSysRostering(), checkInTime, 2, LocalDate.parse(startAttendDate)))); |
| | | } else { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | } |
| | | attendance.setEndLocationResults(flag == true ? attendance.getEndLocationResults() : setLocationResults(weComRecordResult.getExceptionType())); |
| | | attendance.setActualWorkEndTime(flag == true ? attendance.getActualWorkEndTime() : checkInTime); |
| | | } |
| | | } |
| | | } |
| | | // 修改考勤打卡状态 |
| | | if (ObjectUtils.isNotEmpty(attendance)) { |
| | | attendance = updateRecord(user, attendance, false, attendDate); |
| | | attendanceRepository.save(attendance); |
| | | // 修改考勤打卡状态 |
| | | if (ObjectUtils.isNotEmpty(attendance)) { |
| | | getMornOrNoon(user,attendance,attendDate,attendance.getRosteringWorkStartTime(),attendance.getRosteringWorkEndTime(), false); |
| | | // attendance = updateRecord(user, attendance, false, attendDate); |
| | | attendanceRepository.save(attendance); |
| | | } |
| | | } catch (WxErrorException wxe) { |
| | | System.out.println(wxe.getMessage()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } catch (WxErrorException wxErrorException) { |
| | | wxErrorException.printStackTrace(); |
| | | sendNotice(Arrays.asList("YueYuHuanXiangQinYuFenDou"), "企微通信异常", String.format("<div class=\"normal\">异常方法:%s</div>" + |
| | | "<div class=\"highlight\">请前往API服务查看LOG。</div>", |
| | | "getWeComAttendanceListOfNight"), Constant.WECOM_MESSAGE_TYPE_TEXTCARD); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 中午12点30或凌晨02:30执行定时任务 |
| | | * |
| | | * @throws Exception |
| | | */ |
| | | public void getWeComAttendanceListOfNoonOrNight(String attendDate, List attUser) throws Exception { |
| | |
| | | * |
| | | * @param user |
| | | */ |
| | | public NewAttendance updateRecord(User user, NewAttendance attendance, Boolean day, String attendDate) { |
| | | public Attendance updateRecord(User user, Attendance attendance, Boolean day, String attendDate) { |
| | | // 查询考勤请假表 |
| | | List<AttendanceLeave> attendanceLeaveLists = attendanceLeaveRepository.findByUserIdAndDate(user.getId(), attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime()); |
| | | for (AttendanceLeave attendanceLeave : attendanceLeaveLists) { |
| | |
| | | getMornOrNoon(user, attendance, attendDate, attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), day); |
| | | } |
| | | } |
| | | //查询出差表 |
| | | AttendanceBusinessTravel attendanceBusinessTravel = attendanceBusinessTravelRepository.findByUserAndDate(user.getId(), attendance.getAttendanceDate().toLocalDateTime(), attendance.getAttendanceDate().toLocalDateTime()); |
| | | if (ObjectUtils.isNotEmpty(attendanceBusinessTravel)) { |
| | | getMornOrNoon(user, attendance, attendDate, attendanceBusinessTravel.getTravelStartTime(), attendance.getRosteringWorkEndTime(), day); |
| | | // 查询出差表 |
| | | List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(user.getId(), attendance.getAttendanceDate().toLocalDateTime(), attendance.getAttendanceDate().toLocalDateTime()); |
| | | for (AttendanceBusinessTravel attendanceBusinessTravel : attendanceBusinessTravelList) { |
| | | // 上午/下午 |
| | | if (attendanceBusinessTravel.getTravelStartTime().toLocalDateTime().isBefore(attendance.getRosteringLunchStartTime().toLocalDateTime()) && attendanceBusinessTravel.getTravelEndTime().toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) <= 0) { |
| | | getMornOrNoon(user, attendance, attendDate, attendance.getRosteringWorkStartTime(), attendance.getRosteringLunchEndTime(), day); |
| | | } else if (attendanceBusinessTravel.getTravelStartTime().toLocalDateTime().compareTo(attendance.getRosteringLunchEndTime().toLocalDateTime()) >= 0 && attendanceBusinessTravel.getTravelEndTime().toLocalDateTime().compareTo(attendance.getRosteringWorkEndTime().toLocalDateTime()) <= 0) { |
| | | getMornOrNoon(user, attendance, attendDate, attendance.getRosteringLunchStartTime(), attendance.getRosteringWorkEndTime(), day); |
| | | } else { |
| | | getMornOrNoon(user, attendance, attendDate, attendanceBusinessTravel.getTravelStartTime(), attendanceBusinessTravel.getTravelEndTime(), day); |
| | | } |
| | | } |
| | | // 查询外出表 |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(user.getId(), attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime()); |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(user.getId(), DateUtil.parseAttStartTime(attendance.getRosteringWorkStartTime().toLocalDateTime()), DateUtil.parseAttEndTime(attendance.getRosteringWorkEndTime().toLocalDateTime())); |
| | | for (AttendanceGoOut attendanceGoOut : attendanceGoOutList) { |
| | | // 上午/下午 |
| | | if (attendanceGoOut.getOutStartTime().toLocalDateTime().isBefore(attendance.getRosteringLunchStartTime().toLocalDateTime()) && attendanceGoOut.getOutEndTime().toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) <= 0) { |
| | |
| | | return attendance; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 请假优先于出差优先于外出 |
| | | * |
| | |
| | | * @param startDate |
| | | * @param endDate |
| | | */ |
| | | public void getMornOrNoon(User user, NewAttendance attendance, String attendDate, Timestamp startDate, Timestamp endDate, Boolean day) { |
| | | public void getMornOrNoon(User user, Attendance attendance, String attendDate, Timestamp startDate, Timestamp endDate, Boolean day) { |
| | | // 查询考勤请假表 |
| | | List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.findByUserIdAndDate(user.getId(), startDate.toLocalDateTime(), endDate.toLocalDateTime()); |
| | | Double leaveDuration = new Double(0.00);//计算的总时长 |
| | | Double leaveStartDuration = new Double(0.00);//考勤按钮的时长 |
| | | Double leaveEndDuration = new Double(0.00);//考勤按钮的时长 |
| | | // 请假优先于出差优先于外出 |
| | | if (attendanceLeaveList.size() < 1) { |
| | | // 查询考勤出差表 |
| | | AttendanceBusinessTravel attendanceBusinessTravel = attendanceBusinessTravelRepository.findByUserAndDate(user.getId(), attendance.getAttendanceDate().toLocalDateTime(), attendance.getAttendanceDate().toLocalDateTime()); |
| | | Double bussDuration = new Double(0.00); |
| | | Double bussStartDuration = new Double(0.00);//考勤按钮的时长 |
| | | Double bussEndDuration = new Double(0.00);//考勤按钮的时长 |
| | | if (ObjectUtils.isEmpty(attendanceBusinessTravel)) { |
| | | // 查询考勤外出表 |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(user.getId(), attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime()); |
| | | Double outDuration = new Double(0.00); |
| | | Double outStartDuration = new Double(0.00);// 考勤按钮的时长 |
| | | Double outEndDuration = new Double(0.00);// 考勤按钮的时长 |
| | | for (AttendanceGoOut attendanceGoOut : attendanceGoOutList) { |
| | | // attendDate不等于null 说明是考勤信息按钮 |
| | | if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | // 上午时长、下午时长 |
| | | outStartDuration += getStartDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | outEndDuration += getEndDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | // 调用方法修改考勤打卡状态 |
| | | updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_GOOUT, day, outStartDuration, outEndDuration); |
| | | } else { |
| | | // 上午or下午总时长 |
| | | outDuration += getDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance, day); |
| | | updateAttendanceRecord(outDuration, attendance, Constant.ATTENDANCE_STATE_GOOUT, day, null, null); |
| | | } |
| | | } |
| | | } else { |
| | | if (ObjectUtils.isNotEmpty(attendanceBusinessTravel)) { |
| | | // attendDate不等于null 说明是考勤信息按钮 |
| | | if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | // 上午时长、下午时长 |
| | | bussStartDuration += getStartDuration(attendanceBusinessTravel.getTravelStartTime(), attendance.getRosteringWorkEndTime(), attendance); |
| | | bussEndDuration += getEndDuration(attendanceBusinessTravel.getTravelStartTime(), attendance.getRosteringWorkEndTime(), attendance); |
| | | //调用方法修改考勤打卡状态 |
| | | updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_BUSINESS, day, bussStartDuration, bussEndDuration); |
| | | } else { |
| | | // 上午or下午总时长 |
| | | bussDuration += getDuration(attendanceBusinessTravel.getTravelStartTime(), attendance.getRosteringWorkEndTime(), attendance, day); |
| | | updateAttendanceRecord(bussDuration, attendance, Constant.ATTENDANCE_STATE_BUSINESS, day, null, null); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | // 查询考勤外出表 |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(user.getId(), attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime()); |
| | | // 查询考勤出差表 |
| | | List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(user.getId(), attendance.getAttendanceDate().toLocalDateTime().withHour(0).withMinute(0).withSecond(0).withNano(0), attendance.getAttendanceDate().toLocalDateTime().withHour(23).withMinute(59).withSecond(59).withNano(0)); |
| | | // 查询考勤外出表 |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(user.getId(), DateUtil.parseAttStartTime(attendance.getAttendanceDate().toLocalDateTime()), DateUtil.parseAttEndTime(attendance.getAttendanceDate().toLocalDateTime())); |
| | | |
| | | Double outStartDuration = new Double(0.00); // 上午时长 |
| | | Double outEndDuration = new Double(0.00); // 下午时长 |
| | | |
| | | Double bussStartDuration = new Double(0.00); // 上午时长 |
| | | Double bussEndDuration = new Double(0.00); // 下午时长 |
| | | |
| | | Double leaveStartDuration = new Double(0.00); // 上午时长 |
| | | Double leaveEndDuration = new Double(0.00); // 下午时长 |
| | | |
| | | Map<Timestamp, String> startTimeMap = new HashMap<>(); |
| | | Map<Timestamp, String> endTimeMap = new HashMap<>(); |
| | | |
| | | // TODO:统计规则请假优先于出差优先于外出 |
| | | if (attendanceGoOutList.size() > 0) { |
| | | for (AttendanceGoOut attendanceGoOut : attendanceGoOutList) { |
| | | // attendDate不等于null 说明是考勤信息按钮 |
| | | if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | // 上午时长、下午时长 |
| | | leaveStartDuration += getStartDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | leaveEndDuration += getEndDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | } else { |
| | | // 上午or下午总时长 |
| | | leaveDuration += getDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance, day); |
| | | } |
| | | } |
| | | for (AttendanceLeave attendanceLeave : attendanceLeaveList) { |
| | | // attendDate不等于null 说明是考勤信息按钮 |
| | | if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | // 上午总时长、下午总时长 |
| | | leaveStartDuration += getStartDuration(attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), attendance); |
| | | leaveEndDuration += getEndDuration(attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), attendance); |
| | | //调用方法修改考勤打卡状态 |
| | | updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_LEAVE, day, leaveStartDuration, leaveEndDuration); |
| | | } else { |
| | | // 上午or下午总时长 |
| | | leaveDuration += getDuration(attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), attendance, day); |
| | | //调用方法修改考勤打卡状态 |
| | | updateAttendanceRecord(leaveDuration, attendance, Constant.ATTENDANCE_STATE_LEAVE, day, null, null); |
| | | } |
| | | // 上午时长、下午时长 |
| | | outStartDuration += getStartDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | outEndDuration += getEndDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | |
| | | startTimeMap.put(attendanceGoOut.getOutStartTime(), Constant.ATTENDANCE_STATE_GOOUT); |
| | | endTimeMap.put(attendanceGoOut.getOutEndTime(), Constant.ATTENDANCE_STATE_GOOUT); |
| | | } |
| | | } |
| | | if (attendanceBusinessTravelList.size() > 0) { |
| | | for (AttendanceBusinessTravel attendanceBusinessTravel : attendanceBusinessTravelList) { |
| | | // 上午时长、下午时长 |
| | | bussStartDuration += getStartDuration(attendanceBusinessTravel.getTravelStartTime(), attendanceBusinessTravel.getTravelEndTime(), attendance); |
| | | bussEndDuration += getEndDuration(attendanceBusinessTravel.getTravelStartTime(), attendanceBusinessTravel.getTravelEndTime(), attendance); |
| | | |
| | | startTimeMap.put(attendanceBusinessTravel.getTravelStartTime(), Constant.ATTENDANCE_STATE_BUSINESS); |
| | | endTimeMap.put(attendanceBusinessTravel.getTravelEndTime(), Constant.ATTENDANCE_STATE_BUSINESS); |
| | | } |
| | | } |
| | | if (attendanceLeaveList.size() > 0) { |
| | | for (AttendanceLeave attendanceLeave : attendanceLeaveList) { |
| | | // 上午总时长、下午总时长 |
| | | leaveStartDuration += getStartDuration(attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), attendance); |
| | | leaveEndDuration += getEndDuration(attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), attendance); |
| | | |
| | | startTimeMap.put(attendanceLeave.getLeaveStartTime(), Constant.ATTENDANCE_STATE_LEAVE); |
| | | endTimeMap.put(attendanceLeave.getLeaveEndTime(), Constant.ATTENDANCE_STATE_LEAVE); |
| | | } |
| | | } |
| | | // 选出最早的开始时间, 更新考勤记录 |
| | | if (!startTimeMap.isEmpty()) { |
| | | Timestamp startTime = startTimeMap.keySet().stream().sorted(Comparator.comparing(Timestamp::toLocalDateTime)).findFirst().get(); |
| | | |
| | | if (startTimeMap.get(startTime).equals(Constant.ATTENDANCE_STATE_GOOUT)) { |
| | | updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_GOOUT, day, outStartDuration + bussStartDuration + leaveStartDuration, 0.00); |
| | | } else if (startTimeMap.get(startTime).equals(Constant.ATTENDANCE_STATE_BUSINESS)) { |
| | | updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_BUSINESS, day, outStartDuration + bussStartDuration + leaveStartDuration, 0.00); |
| | | } else if (startTimeMap.get(startTime).equals(Constant.ATTENDANCE_STATE_LEAVE)) { |
| | | updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_LEAVE, day, outStartDuration + bussStartDuration + leaveStartDuration, 0.00); |
| | | } |
| | | } |
| | | |
| | | // 选出最晚的结束时间, 更新考勤记录 |
| | | if (!endTimeMap.isEmpty()) { |
| | | Timestamp endTime = endTimeMap.keySet().stream().sorted(Comparator.comparing(Timestamp::toLocalDateTime).reversed()).findFirst().get(); |
| | | |
| | | if (endTimeMap.get(endTime).equals(Constant.ATTENDANCE_STATE_GOOUT)) { |
| | | updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_GOOUT, day, 0.00, outEndDuration + bussEndDuration + leaveEndDuration); |
| | | } else if (endTimeMap.get(endTime).equals(Constant.ATTENDANCE_STATE_BUSINESS)) { |
| | | updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_BUSINESS, day, 0.00, outEndDuration + bussEndDuration + leaveEndDuration); |
| | | } else if (endTimeMap.get(endTime).equals(Constant.ATTENDANCE_STATE_LEAVE)) { |
| | | updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_LEAVE, day, 0.00, outEndDuration + bussEndDuration + leaveEndDuration); |
| | | } |
| | | } |
| | | |
| | | // TODO:20250813修改 增加打卡时间判断,打卡时间需要闭环 |
| | | Boolean actualTimeLoopFlag = ObjectUtils.isNotEmpty(attendance.getActualWorkStartTime()) == ObjectUtils.isNotEmpty(attendance.getActualWorkEndTime()); |
| | | if (!actualTimeLoopFlag) { |
| | | List<String> editStatusList = Arrays.asList(Constant.ATTENDANCE_STATE_GOOUT, Constant.ATTENDANCE_STATE_BUSINESS, Constant.ATTENDANCE_STATE_LEAVE); |
| | | if (ObjectUtils.isEmpty(attendance.getActualWorkStartTime()) && editStatusList.contains(attendance.getStartClockResults())) { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NOTSIGNED); |
| | | attendance.setStartLocationResults(Constant.LOCATION_RESULTS_NOTSIGNED); |
| | | } |
| | | if (ObjectUtils.isEmpty(attendance.getActualWorkEndTime()) && editStatusList.contains(attendance.getEndClockResults())) { |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NOTSIGNED); |
| | | attendance.setEndLocationResults(Constant.LOCATION_RESULTS_NOTSIGNED); |
| | | } |
| | | } |
| | | |
| | | // // 查询考勤请假表 |
| | | // List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.findByUserIdAndDate(user.getId(), startDate.toLocalDateTime(), endDate.toLocalDateTime()); |
| | | // Double leaveDuration = new Double(0.00);//计算的总时长 |
| | | // Double leaveStartDuration = new Double(0.00);//考勤按钮的时长 |
| | | // Double leaveEndDuration = new Double(0.00);//考勤按钮的时长 |
| | | // // 请假优先于出差优先于外出 |
| | | // if (attendanceLeaveList.size() < 1) { |
| | | // // 查询考勤出差表 |
| | | // AttendanceBusinessTravel attendanceBusinessTravel = attendanceBusinessTravelRepository.findByUserAndDate(user.getId(), attendance.getAttendanceDate().toLocalDateTime(), attendance.getAttendanceDate().toLocalDateTime()); |
| | | // Double bussDuration = new Double(0.00); |
| | | // Double bussStartDuration = new Double(0.00);//考勤按钮的时长 |
| | | // Double bussEndDuration = new Double(0.00);//考勤按钮的时长 |
| | | // if (ObjectUtils.isEmpty(attendanceBusinessTravel)) { |
| | | // // 查询考勤外出表 |
| | | // List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(user.getId(), attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime()); |
| | | // Double outDuration = new Double(0.00); |
| | | // Double outStartDuration = new Double(0.00);// 考勤按钮的时长 |
| | | // Double outEndDuration = new Double(0.00);// 考勤按钮的时长 |
| | | // if(ObjectUtils.isNotEmpty(attendDate)){ |
| | | // for(AttendanceGoOut attendanceGoOut : attendanceGoOutList) { |
| | | // // 上午时长、下午时长 |
| | | // outStartDuration += getStartDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | // outEndDuration += getEndDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | // } |
| | | // //调用方法修改考勤打卡状态 |
| | | // updateAttendanceRecord(null,attendance,Constant.ATTENDANCE_STATE_GOOUT,day,outStartDuration,outEndDuration); |
| | | // }else{ |
| | | // for(AttendanceGoOut attendanceGoOut : attendanceGoOutList) { |
| | | // // 上午or下午总时长 |
| | | // outDuration += getDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance, day); |
| | | // } |
| | | // updateAttendanceRecord(outDuration,attendance,Constant.ATTENDANCE_STATE_GOOUT, day,null,null); |
| | | // } |
| | | //// for (AttendanceGoOut attendanceGoOut : attendanceGoOutList) { |
| | | //// // attendDate不等于null 说明是考勤信息按钮 |
| | | //// if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | //// // 上午时长、下午时长 |
| | | //// outStartDuration += getStartDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | //// outEndDuration += getEndDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | //// // 调用方法修改考勤打卡状态 |
| | | //// updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_GOOUT, day, outStartDuration, outEndDuration); |
| | | //// } else { |
| | | //// // 上午or下午总时长 |
| | | //// outDuration += getDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance, day); |
| | | //// updateAttendanceRecord(outDuration, attendance, Constant.ATTENDANCE_STATE_GOOUT, day, null, null); |
| | | //// } |
| | | //// } |
| | | // } else { |
| | | // if (ObjectUtils.isNotEmpty(attendanceBusinessTravel)) { |
| | | // // attendDate不等于null 说明是考勤信息按钮 |
| | | // if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | // // 上午时长、下午时长 |
| | | // bussStartDuration += getStartDuration(attendanceBusinessTravel.getTravelStartTime(), attendanceBusinessTravel.getTravelEndTime(), attendance); |
| | | // bussEndDuration += getEndDuration(attendanceBusinessTravel.getTravelStartTime(), attendanceBusinessTravel.getTravelEndTime(), attendance); |
| | | // //调用方法修改考勤打卡状态 |
| | | // updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_BUSINESS, day, bussStartDuration, bussEndDuration); |
| | | // } else { |
| | | // // 上午or下午总时长 |
| | | // bussDuration += getDuration(attendanceBusinessTravel.getTravelStartTime(), attendanceBusinessTravel.getTravelEndTime(), attendance, day); |
| | | // updateAttendanceRecord(bussDuration, attendance, Constant.ATTENDANCE_STATE_BUSINESS, day, null, null); |
| | | // } |
| | | // } |
| | | // } |
| | | // } else { |
| | | // // 查询考勤外出表 |
| | | // List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(user.getId(), attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime()); |
| | | // AttendanceBusinessTravel attendanceBusinessTravel = attendanceBusinessTravelRepository.findByUserAndDate(user.getId(), attendance.getAttendanceDate().toLocalDateTime(), attendance.getAttendanceDate().toLocalDateTime()); |
| | | // // attendDate不等于null 说明是考勤信息按钮 |
| | | // if(ObjectUtils.isNotEmpty(attendDate)){ |
| | | // Double outStartDuration = new Double(0.00);// 考勤按钮的时长 |
| | | // Double outEndDuration = new Double(0.00);// 考勤按钮的时长 |
| | | // Double bussStartDuration = new Double(0.00);//考勤按钮的时长 |
| | | // Double bussEndDuration = new Double(0.00);//考勤按钮的时长 |
| | | // for(AttendanceGoOut attendanceGoOut : attendanceGoOutList) { |
| | | // // 上午时长、下午时长 |
| | | // outStartDuration += getStartDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | // outEndDuration += getEndDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | // } |
| | | // updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_GOOUT, day, outStartDuration, outEndDuration); |
| | | // if (ObjectUtils.isNotEmpty(attendanceBusinessTravel)) { |
| | | // // 上午时长、下午时长 |
| | | // bussStartDuration += getStartDuration(attendanceBusinessTravel.getTravelStartTime(), attendanceBusinessTravel.getTravelEndTime(), attendance); |
| | | // bussEndDuration += getEndDuration(attendanceBusinessTravel.getTravelStartTime(), attendanceBusinessTravel.getTravelEndTime(), attendance); |
| | | // } |
| | | // updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_BUSINESS, day, bussStartDuration, bussEndDuration); |
| | | // for(AttendanceLeave attendanceLeave : attendanceLeaveList){ |
| | | // // 上午总时长、下午总时长 |
| | | // leaveStartDuration += getStartDuration(attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), attendance); |
| | | // leaveEndDuration += getEndDuration(attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), attendance); |
| | | // } |
| | | // //调用方法修改考勤打卡状态 |
| | | // updateAttendanceRecord(null,attendance,Constant.ATTENDANCE_STATE_LEAVE,day,leaveStartDuration,leaveEndDuration); |
| | | // } else { |
| | | // Double bussDuration = new Double(0.00); |
| | | // Double outDuration = new Double(0.00); |
| | | // for(AttendanceGoOut attendanceGoOut : attendanceGoOutList) { |
| | | // // 上午or下午总时长 |
| | | // outDuration += getDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance, day); |
| | | // } |
| | | // updateAttendanceRecord(outDuration, attendance, Constant.ATTENDANCE_STATE_GOOUT, day, null, null); |
| | | // if (ObjectUtils.isNotEmpty(attendanceBusinessTravel)) { |
| | | // // 上午or下午总时长 |
| | | // bussDuration += getDuration(attendanceBusinessTravel.getTravelStartTime(), attendanceBusinessTravel.getTravelEndTime(), attendance, day); |
| | | // } |
| | | // updateAttendanceRecord(bussDuration, attendance, Constant.ATTENDANCE_STATE_BUSINESS, day, null, null); |
| | | // for(AttendanceLeave attendanceLeave : attendanceLeaveList){ |
| | | // // 上午or下午总时长 |
| | | // leaveDuration += getDuration(attendanceLeave.getLeaveStartTime(),attendanceLeave.getLeaveEndTime(),attendance,day); |
| | | // } |
| | | // // 调用方法修改考勤打卡状态 |
| | | // updateAttendanceRecord(leaveDuration,attendance,Constant.ATTENDANCE_STATE_LEAVE,day,null,null); |
| | | // } |
| | | //// for (AttendanceGoOut attendanceGoOut : attendanceGoOutList) { |
| | | //// // attendDate不等于null 说明是考勤信息按钮 |
| | | //// if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | //// // 上午时长、下午时长 |
| | | //// leaveStartDuration += getStartDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | //// leaveEndDuration += getEndDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance); |
| | | //// } else { |
| | | //// // 上午or下午总时长 |
| | | //// leaveDuration += getDuration(attendanceGoOut.getOutStartTime(), attendanceGoOut.getOutEndTime(), attendance, day); |
| | | //// } |
| | | //// } |
| | | //// for (AttendanceLeave attendanceLeave : attendanceLeaveList) { |
| | | //// // attendDate不等于null 说明是考勤信息按钮 |
| | | //// if (ObjectUtils.isNotEmpty(attendDate)) { |
| | | //// // 上午总时长、下午总时长 |
| | | //// leaveStartDuration += getStartDuration(attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), attendance); |
| | | //// leaveEndDuration += getEndDuration(attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), attendance); |
| | | //// //调用方法修改考勤打卡状态 |
| | | //// updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_LEAVE, day, leaveStartDuration, leaveEndDuration); |
| | | //// } else { |
| | | //// // 上午or下午总时长 |
| | | //// leaveDuration += getDuration(attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), attendance, day); |
| | | //// //调用方法修改考勤打卡状态 |
| | | //// updateAttendanceRecord(leaveDuration, attendance, Constant.ATTENDANCE_STATE_LEAVE, day, null, null); |
| | | //// } |
| | | //// } |
| | | // } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param attendance |
| | | * @param type |
| | | */ |
| | | public void updateAttendanceRecord(Double duration, NewAttendance attendance, String type, Boolean day, Double stDuration, Double enDuration) { |
| | | public void updateAttendanceRecord(Double duration, Attendance attendance, String type, Boolean day, Double stDuration, Double enDuration) { |
| | | // 上午排班开始时间到排班午休开始时间的时长 |
| | | Integer workMorningTime = calculateTimes(attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringLunchStartTime().toLocalDateTime()); |
| | | Double result = Double.valueOf(new BigDecimal((float) workMorningTime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | |
| | | Integer actualTime = calculateTimes(attendance.getRosteringLunchEndTime().toLocalDateTime(), attendance.getActualWorkEndTime().toLocalDateTime()); |
| | | noonResult1 = Double.valueOf(new BigDecimal((float) actualTime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | } |
| | | |
| | | // 没打卡的情况下,修改考勤打卡状态 |
| | | if (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_NOTSIGNED) && attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_NOTSIGNED)) { |
| | | // duration为null说明是考勤信息按钮 |
| | |
| | | } else { |
| | | // 上午 |
| | | if (day) { |
| | | // 上午时长 >= 上午排班时间 改打卡状态 否则 缺时 |
| | | if (duration >= result) { |
| | | // 上午时长 >= 上午排班时间 改打卡状态 否则 缺时 TODO:20250805修改 排除休息日情况(如果打卡了,考勤时间需要闭环) |
| | | if (duration >= result || attendance.getStartLocationResults().equals(Constant.LOCATION_RESULTS_REST) || ((attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) && ((attendance.getActualWorkStartTime() == null) == (attendance.getActualWorkEndTime() == null)))) { |
| | | attendance.setStartClockResults(type); |
| | | attendance.setStartLocationResults(null); |
| | | } else { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_LACK_OF_TIME); |
| | | } |
| | | } else { |
| | | // 下午时长 >= 下午排班时间 改打卡状态 否则 缺时 |
| | | if (duration >= noonResult) { |
| | | // 下午时长 >= 下午排班时间 改打卡状态 否则 缺时 TODO:20250805修改 排除休息日情况(如果打卡了,考勤时间需要闭环) |
| | | if (duration >= noonResult || attendance.getEndLocationResults().equals(Constant.LOCATION_RESULTS_REST) || ((attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) && ((attendance.getActualWorkStartTime() == null) == (attendance.getActualWorkEndTime() == null)))) { |
| | | attendance.setEndClockResults(type); |
| | | attendance.setEndLocationResults(null); |
| | | } else { |
| | |
| | | } else { |
| | | //打卡的情况,修改考勤状态 |
| | | if (day) { |
| | | if ((duration + result1) >= result) { |
| | | // TODO:20250805修改 排除休息日情况(如果打卡了,考勤时间需要闭环) |
| | | if ((duration + result1) >= result || attendance.getStartLocationResults().equals(Constant.LOCATION_RESULTS_REST) || ((attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) && ((attendance.getActualWorkStartTime() == null) == (attendance.getActualWorkEndTime() == null)))) { |
| | | attendance.setStartClockResults(type); |
| | | attendance.setStartLocationResults(null); |
| | | } else { |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_LACK_OF_TIME); |
| | | } |
| | | } else { |
| | | if ((duration + noonResult1) >= noonResult) { |
| | | // TODO:20250805修改 排除休息日情况(如果打卡了,考勤时间需要闭环) |
| | | if ((duration + noonResult1) >= noonResult || attendance.getEndLocationResults().equals(Constant.LOCATION_RESULTS_REST) || ((attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) && ((attendance.getActualWorkStartTime() == null) == (attendance.getActualWorkEndTime() == null)))) { |
| | | attendance.setEndClockResults(type); |
| | | attendance.setEndLocationResults(null); |
| | | } else { |
| | |
| | | * |
| | | * @param sysRostering |
| | | * @param timestamp |
| | | * @param type |
| | | * @param type / 1上班打卡。2下班打卡。 |
| | | * @param attendanceDate / 考勤日期当天(下班打卡使用) |
| | | * @return |
| | | */ |
| | | public String checkResult(SysRostering sysRostering, Timestamp timestamp, Integer type) { |
| | | public String checkResult(SysRostering sysRostering, Timestamp timestamp, Integer type, LocalDate attendanceDate) { |
| | | String result = ObjectUtil.isEmpty(timestamp) ? Constant.ATTENDANCE_STATE_NOTSIGNED : Constant.ATTENDANCE_STATE_NORMAL; |
| | | if (type.equals(1)) { |
| | | // 上班打卡 |
| | | if (timestamp.toLocalDateTime().toLocalTime().isAfter(sysRostering.getWorkStartTime())) { |
| | | result = Constant.ATTENDANCE_START_LATE; |
| | | } |
| | | } else { |
| | | if (timestamp.toLocalDateTime().toLocalTime().isBefore(sysRostering.getWorkEndTime())) { |
| | | // 下班打卡 |
| | | if (timestamp.toLocalDateTime().toLocalTime().isBefore(sysRostering.getWorkEndTime()) && (attendanceDate != null ? !timestamp.toLocalDateTime().toLocalDate().isAfter(attendanceDate) : true)) { |
| | | result = Constant.ATTENDANCE_START_EARLY; |
| | | } |
| | | } |
| | |
| | | */ |
| | | public Boolean getCardSupplement(Long userId, String st, Timestamp checkTime) { |
| | | if (ObjectUtils.isNotEmpty(checkTime)) { |
| | | // 查询补卡记录 |
| | | // 查询补卡记录 TODO:20250805修改 正常考勤状态全部验证通过处理 |
| | | AttendanceCardreplacement attendanceCardreplacement = attendanceCardreplacementRepository.findByUserIdAndTime(userId, checkTime); |
| | | if (ObjectUtils.isNotEmpty(attendanceCardreplacement) && st.equals(Constant.ATTENDANCE_STATE_NORMAL)) { |
| | | if (ObjectUtils.isNotEmpty(attendanceCardreplacement) && (st.equals(Constant.ATTENDANCE_STATE_NORMAL) || st.equals(Constant.ATTENDANCE_STATE_LEAVE) || st.equals(Constant.ATTENDANCE_STATE_BUSINESS)|| st.equals(Constant.ATTENDANCE_STATE_GOOUT))) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 补充补卡记录 |
| | | * |
| | | * @param userId / 用户ID |
| | | * @param checkTime / 补卡日期(yyyy-MM-dd) |
| | | * @param type / 补卡区分 |
| | | * @param attendance / 考勤记录 |
| | | */ |
| | | public void cardDatetimeSupplement(Long userId, String checkTime, String type, Attendance attendance) { |
| | | if (ObjectUtils.isNotEmpty(checkTime) && StringUtils.isNotBlank(type)) { |
| | | // 查询补卡记录 |
| | | AttendanceCardreplacement attendanceCardreplacement = attendanceCardreplacementRepository.findByUserIdAndDateAndType(userId, checkTime, type); |
| | | if (ObjectUtils.isNotEmpty(attendanceCardreplacement)) { |
| | | if (Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOON.equals(type)) { |
| | | attendance.setActualWorkStartTime(attendanceCardreplacement.getCardReplacementTime()); |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | attendance.setStartLocationResults(Constant.LOCATION_RESULTS_NORMAL); |
| | | } else if (Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOOFF.equals(type)) { |
| | | attendance.setActualWorkEndTime(attendanceCardreplacement.getCardReplacementTime()); |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NORMAL); |
| | | attendance.setEndLocationResults(Constant.LOCATION_RESULTS_NORMAL); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param attendance |
| | | * @param type |
| | | */ |
| | | public void setAttendance(Double sDuration, Double eDuration, Double result, Double noonResult, NewAttendance attendance, String type) { |
| | | public void setAttendance(Double sDuration, Double eDuration, Double result, Double noonResult, Attendance attendance, String type) { |
| | | if (ObjectUtils.isEmpty(eDuration) && ObjectUtils.isEmpty(noonResult)) { |
| | | // 上午时长 >= 上午排班时间 改打卡状态 否则 缺时 |
| | | if (sDuration >= result) { |
| | | // 上午时长 >= 上午排班时间 改打卡状态 否则 缺时 TODO:20250805修改 排除休息日情况(如果打卡了,考勤时间需要闭环) |
| | | if (sDuration >= result || attendance.getStartLocationResults().equals(Constant.LOCATION_RESULTS_REST) || ((attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) && ((attendance.getActualWorkStartTime() == null) == (attendance.getActualWorkEndTime() == null)))) { |
| | | attendance.setStartClockResults(type); |
| | | attendance.setStartLocationResults(null); |
| | | } else { |
| | |
| | | } |
| | | } |
| | | if (ObjectUtils.isEmpty(sDuration) && ObjectUtils.isEmpty(result)) { |
| | | // 下午时长 >= 下午排班时间 改打卡状态 否则 缺时 |
| | | if (eDuration >= noonResult) { |
| | | // 下午时长 >= 下午排班时间 改打卡状态 否则 缺时 TODO:20250805修改 排除休息日情况(如果打卡了,考勤时间需要闭环) |
| | | if (eDuration >= noonResult || attendance.getEndLocationResults().equals(Constant.LOCATION_RESULTS_REST) || ((attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) && ((attendance.getActualWorkStartTime() == null) == (attendance.getActualWorkEndTime() == null)))) { |
| | | attendance.setEndClockResults(type); |
| | | attendance.setEndLocationResults(null); |
| | | } else { |
| | |
| | | * @param attendance |
| | | * @param type |
| | | */ |
| | | public void setAttendanceStart(Double sDuration, Double eDuration, Double result1, Double result, Double noonResult, NewAttendance attendance, String type) { |
| | | public void setAttendanceStart(Double sDuration, Double eDuration, Double result1, Double result, Double noonResult, Attendance attendance, String type) { |
| | | if (ObjectUtils.isEmpty(eDuration) && sDuration > 0) { |
| | | if ((sDuration + result1) >= result) { |
| | | // TODO:20250805修改 排除休息日情况(如果打卡了,考勤时间需要闭环) |
| | | if ((sDuration + result1) >= result || attendance.getStartLocationResults().equals(Constant.LOCATION_RESULTS_REST) || ((attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) && ((attendance.getActualWorkStartTime() == null) == (attendance.getActualWorkEndTime() == null)))) { |
| | | attendance.setStartClockResults(type); |
| | | attendance.setStartLocationResults(null); |
| | | } else { |
| | |
| | | } |
| | | } |
| | | if (ObjectUtils.isEmpty(sDuration) && eDuration > 0) { |
| | | if ((eDuration + result1) >= noonResult) { |
| | | // TODO:20250805修改 排除休息日情况(如果打卡了,考勤时间需要闭环) |
| | | if ((eDuration + result1) >= noonResult || attendance.getEndLocationResults().equals(Constant.LOCATION_RESULTS_REST) || ((attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND) || attendance.getDateType().equals(Constant.DATE_TYPE_LEGAL_HOLIDAYS)) && ((attendance.getActualWorkStartTime() == null) == (attendance.getActualWorkEndTime() == null)))) { |
| | | attendance.setEndClockResults(type); |
| | | attendance.setEndLocationResults(null); |
| | | } else { |
| | |
| | | public Integer calculateTimes(LocalDateTime start, LocalDateTime end) { |
| | | Integer time = 0; |
| | | Duration duration = null; |
| | | duration = Duration.between(start, start.toLocalDate().atTime(end.toLocalTime())); |
| | | duration = Duration.between(start, end); |
| | | Long StartSeconds = duration.getSeconds(); |
| | | time += StartSeconds.intValue(); |
| | | return time; |
| | |
| | | * @param attendance |
| | | * @return |
| | | */ |
| | | public Double getDuration(Timestamp startDate, Timestamp endDate, NewAttendance attendance, Boolean day) { |
| | | public Double getDuration(Timestamp startDate, Timestamp endDate, Attendance attendance, Boolean day) { |
| | | Double duration = new Double(0.00); |
| | | // 上午总时长 |
| | | if (day) { |
| | |
| | | return duration; |
| | | } |
| | | |
| | | public Double getStartDuration(Timestamp startDate, Timestamp endDate, NewAttendance attendance) { |
| | | public Double getStartDuration(Timestamp startDate, Timestamp endDate, Attendance attendance) { |
| | | Double duration = new Double(0.00); |
| | | // 上午总时长 |
| | | if (startDate.toLocalDateTime().isBefore(attendance.getRosteringLunchStartTime().toLocalDateTime()) && endDate.toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) <= 0) { |
| | |
| | | return duration; |
| | | } |
| | | |
| | | public Double getEndDuration(Timestamp startDate, Timestamp endDate, NewAttendance attendance) { |
| | | public Double getEndDuration(Timestamp startDate, Timestamp endDate, Attendance attendance) { |
| | | Double duration = new Double(0.00); |
| | | // 下午总时长 |
| | | if (startDate.toLocalDateTime().compareTo(attendance.getRosteringLunchEndTime().toLocalDateTime()) >= 0) { |
| | |
| | | return duration; |
| | | } |
| | | |
| | | /** |
| | | * Unix时间戳转Timestamp |
| | | * |
| | | * @param unixtime Unix时间戳 |
| | | * @return |
| | | */ |
| | | private Timestamp unixtimeToTimestamp(Long unixtime) { |
| | | if (ObjectUtils.isNotEmpty(unixtime)) { |
| | | return new Timestamp(unixtime * 1000); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 发送企微应用消息 |
| | | * |
| | | * @param userWeComIdList 接收消息用户企微ID |
| | | * @param content 消息内容 |
| | | * @param type 消息类型 |
| | | */ |
| | | public void sendNotice(List<String> userWeComIdList, String title, String content, String type) { |
| | | if (userWeComIdList.size() > 0) { |
| | | try { |
| | | // 获取企业微信Token |
| | | wxCpService.getAccessToken(); |
| | | |
| | | // 编辑消息 |
| | | WxCpMessage wxCpMessage = new WxCpMessage(); |
| | | wxCpMessage.setToUser(userWeComIdList.stream().collect(Collectors.joining("|"))); |
| | | if (type.equals(Constant.WECOM_MESSAGE_TYPE_TEXT)) { |
| | | wxCpMessage.setMsgType(Constant.WECOM_MESSAGE_TYPE_TEXT); |
| | | wxCpMessage.setContent(content); |
| | | } else if (type.equals(Constant.WECOM_MESSAGE_TYPE_IMAGE)) { |
| | | wxCpMessage.setMsgType(Constant.WECOM_MESSAGE_TYPE_IMAGE); |
| | | wxCpMessage.setMediaId(content); |
| | | } else if (type.equals(Constant.WECOM_MESSAGE_TYPE_VOICE)) { |
| | | wxCpMessage.setMsgType(Constant.WECOM_MESSAGE_TYPE_VOICE); |
| | | wxCpMessage.setMediaId(content); |
| | | } else if (type.equals(Constant.WECOM_MESSAGE_TYPE_VIDEO)) { |
| | | wxCpMessage.setMsgType(Constant.WECOM_MESSAGE_TYPE_VIDEO); |
| | | wxCpMessage.setMediaId(content); |
| | | wxCpMessage.setTitle(title); |
| | | } else if (type.equals(Constant.WECOM_MESSAGE_TYPE_FILE)) { |
| | | wxCpMessage.setMsgType(Constant.WECOM_MESSAGE_TYPE_FILE); |
| | | wxCpMessage.setMediaId(content); |
| | | } else if (type.equals(Constant.WECOM_MESSAGE_TYPE_TEXTCARD)) { |
| | | wxCpMessage.setMsgType(Constant.WECOM_MESSAGE_TYPE_TEXTCARD); |
| | | wxCpMessage.setTitle(title); |
| | | wxCpMessage.setDescription(content); |
| | | wxCpMessage.setUrl(Constant.WECOM_MESSAGE_URL); |
| | | wxCpMessage.setBtnTxt(Constant.WECOM_MESSAGE_BTNTXT); |
| | | } else { |
| | | wxCpMessage.setMsgType(Constant.WECOM_MESSAGE_TYPE_TEXT); |
| | | wxCpMessage.setContent(content); |
| | | } |
| | | wxCpMessage.setSafe("0"); |
| | | wxCpMessage.setEnableDuplicateCheck(false); |
| | | wxCpMessage.setDuplicateCheckInterval(600); |
| | | |
| | | // 发送消息 |
| | | wxCpService.getMessageService().send(wxCpMessage); |
| | | } catch (WxErrorException wxErrorException) { |
| | | wxErrorException.printStackTrace(); |
| | | // sendNotice(Arrays.asList("YueYuHuanXiangQinYuFenDou"), "企微通信异常", String.format("<div class=\"normal\">异常方法:%s</div>" + |
| | | // "<div class=\"highlight\">请前往API服务查看LOG。</div>", |
| | | // "sendNotice"), Constant.WECOM_MESSAGE_TYPE_TEXTCARD); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 发送企微每周报告 |
| | | */ |
| | | public void remindWeeklyReport() { |
| | | // 校验当天 |
| | | LocalDate todayDate = LocalDate.now(); |
| | | SysConfigHoliday todayHolidayConfig = sysConfigHolidayRepository.findByHolidayDate(todayDate.toString()); |
| | | if (isNonWorkingDay(todayDate, todayHolidayConfig)) { |
| | | return; |
| | | } |
| | | |
| | | // 校验第二天 |
| | | LocalDate tomorrowDate = todayDate.plusDays(1); |
| | | SysConfigHoliday tomorrowHolidayConfig = sysConfigHolidayRepository.findByHolidayDate(tomorrowDate.toString()); |
| | | if (isWorkingDay(tomorrowDate, tomorrowHolidayConfig)) { |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | // 获取企微机器人参数 |
| | | Map<String, String> robotParamMap = dictDetailRepository.findByDictName(Constant.WECOM_ROBOT_PARAM).stream().collect(Collectors.toMap(DictDetail::getLabel, DictDetail::getValue)); |
| | | if (robotParamMap.containsKey(Constant.REMIND_REPORT_WEBHOOK_KEY) && robotParamMap.containsKey(Constant.REMIND_REPORT_MSG)) { |
| | | // 发送消息 |
| | | String webhookUrl = wxCpService.getWxCpConfigStorage().getApiUrl("/cgi-bin/webhook/send?key=") + robotParamMap.get(Constant.REMIND_REPORT_WEBHOOK_KEY); |
| | | wxCpService.getGroupRobotService().sendText(webhookUrl, robotParamMap.get(Constant.REMIND_REPORT_MSG), Arrays.asList("@all"), Arrays.asList()); |
| | | } |
| | | } catch (WxErrorException wxErrorException) { |
| | | wxErrorException.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 发送企微每周报告 |
| | | */ |
| | | public void toWecomSheetPushReport() { |
| | | // 校验当天 |
| | | LocalDate todayDate = LocalDate.now(); |
| | | SysConfigHoliday todayHolidayConfig = sysConfigHolidayRepository.findByHolidayDate(todayDate.toString()); |
| | | if (isNonWorkingDay(todayDate, todayHolidayConfig)) { |
| | | return; |
| | | } |
| | | |
| | | // 校验第二天 |
| | | LocalDate tomorrowDate = todayDate.plusDays(1); |
| | | SysConfigHoliday tomorrowHolidayConfig = sysConfigHolidayRepository.findByHolidayDate(tomorrowDate.toString()); |
| | | if (isWorkingDay(tomorrowDate, tomorrowHolidayConfig)) { |
| | | return; |
| | | } |
| | | |
| | | // 计算统计时间段 |
| | | DateTime startTime = findPreviousHoliday(todayDate); |
| | | DateTime endTime = new DateTime(todayDate); |
| | | |
| | | // 个人报告 |
| | | UserQueryCriteria userQueryCriteria = new UserQueryCriteria(); |
| | | userQueryCriteria.setEnabled(true); |
| | | userQueryCriteria.setLoginEnabled(true); |
| | | userQueryCriteria.setWeComIdNotNull(true); |
| | | userQueryCriteria.getDeptIds().add(7L); |
| | | // 先查找是否存在子节点 |
| | | List<Dept> data = deptService.findByPid(7L); |
| | | // 然后把子节点的ID都加入到集合中 |
| | | userQueryCriteria.getDeptIds().addAll(deptService.getDeptChildren(data)); |
| | | List<Long> userIds = userRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, userQueryCriteria, criteriaBuilder)).stream().map(u -> u.getId()).collect(Collectors.toList()); |
| | | toWecomSheetPushWeeklyReport(userIds, startTime, endTime); |
| | | |
| | | // 项目报告 |
| | | ProjectQueryCriteria projectQueryCriteria = new ProjectQueryCriteria(); |
| | | projectQueryCriteria.setProjectDistinguish(Constant.PROJECT_DISTINGUISH_PRODUCT); |
| | | projectQueryCriteria.setProjectStatusIn(Arrays.asList(Constant.PROJECT_STATUS_NOT_STARTED, Constant.PROJECT_STATUS_UNDER_WAY)); |
| | | List<Long> projectIds = projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, projectQueryCriteria, criteriaBuilder)).stream().map(p -> p.getId()).collect(Collectors.toList()); |
| | | toWeComSheetPushProjectReport(projectIds); |
| | | |
| | | try { |
| | | // 获取企微机器人参数 |
| | | Map<String, String> robotParamMap = dictDetailRepository.findByDictName(Constant.WECOM_ROBOT_PARAM).stream().collect(Collectors.toMap(DictDetail::getLabel, DictDetail::getValue)); |
| | | if (robotParamMap.containsKey(Constant.REMIND_REPORT_WEBHOOK_KEY) && robotParamMap.containsKey(Constant.REMIND_REPORT_SUCCESS_MSG)) { |
| | | // 发送周报生成成功消息 |
| | | String webhookUrl = wxCpService.getWxCpConfigStorage().getApiUrl("/cgi-bin/webhook/send?key=") + robotParamMap.get(Constant.REMIND_REPORT_WEBHOOK_KEY); |
| | | wxCpService.getGroupRobotService().sendText(webhookUrl, robotParamMap.get(Constant.REMIND_REPORT_SUCCESS_MSG), Arrays.asList("@all"), Arrays.asList()); |
| | | } |
| | | } catch (WxErrorException wxErrorException) { |
| | | wxErrorException.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 发送企微周报 |
| | | * |
| | | * @param userIds 周报用户企微ID |
| | | * @param startTime 开始时间 |
| | | * @param endTime 结束时间 |
| | | */ |
| | | public void toWecomSheetPushWeeklyReport(List<Long> userIds, DateTime startTime, DateTime endTime) { |
| | | if (userIds.size() > 0 && ObjectUtils.isNotEmpty(startTime) && ObjectUtils.isNotEmpty(endTime)) { |
| | | Map<Long, Project> projectMap = new HashMap<>(); |
| | | // 计算检索时间 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(startTime); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | Timestamp leaveQueryStartTime = new Timestamp(calendar.getTimeInMillis()); |
| | | Timestamp overtimeQueryStartTime = new Timestamp(calendar.getTimeInMillis()); |
| | | calendar.setTime(endTime); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 23); |
| | | calendar.set(Calendar.MINUTE, 59); |
| | | calendar.set(Calendar.SECOND, 59); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | Timestamp leaveQueryEndTime = new Timestamp(calendar.getTimeInMillis()); |
| | | calendar.add(Calendar.DAY_OF_MONTH, 1); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 4); |
| | | Timestamp overtimeQueryEndTime = new Timestamp(calendar.getTimeInMillis()); |
| | | // 获取企微报告参数 |
| | | Map<String, String> reportParamMap = dictDetailRepository.findByDictName(Constant.WECOM_REPORT_PARAM).stream().collect(Collectors.toMap(DictDetail::getLabel, DictDetail::getValue)); |
| | | |
| | | if (!reportParamMap.containsKey(Constant.WEEKLY_REPORT_DOC_ID)) { |
| | | throw new BadRequestException("周报文件ID未设置"); |
| | | } |
| | | |
| | | try { |
| | | // 获取企业微信Token |
| | | wxCpService.getAccessToken(); |
| | | |
| | | // 查询现有子表信息 |
| | | WxCpSheetQueryRequest sheetQueryRequest = new WxCpSheetQueryRequest(); |
| | | sheetQueryRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | WxCpSheetInfo sheetInfo = wxCpOaWeDocSmartsheetService.sheetInfo(sheetQueryRequest); |
| | | Gson gson = new Gson(); |
| | | // 特殊参数:开发-公共事务、公司-公共事务的项目名称细化到任务详情一级 |
| | | Set<Long> specialProjectType = new HashSet<>(Arrays.asList(46L, 47L)); |
| | | // 应用参数 |
| | | DateTimeFormatter ymdFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | Map<String, String> leaveTypeMap = dictDetailRepository.findByDictName(Constant.LEAVE_TYPE).stream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel)); |
| | | |
| | | for (Long userId : userIds) { |
| | | // 查询用户信息 |
| | | User user = userRepository.findById(userId).orElseGet(User::new); |
| | | // 创建查询条件 |
| | | Criteria criteriaMongo = new Criteria(); |
| | | criteriaMongo.and("userId").is(userId); |
| | | criteriaMongo.andOperator(Criteria.where("fillDate").gte(startTime), Criteria.where("fillDate").lte(endTime)); |
| | | Query query = Query.query(criteriaMongo); |
| | | query.with(Sort.by(Sort.Order.desc("fillDate"))); |
| | | |
| | | // 开始查询 |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(query, TaskDaliyMongo.class); |
| | | // TODO:本段代码Collectors.reducing修改了源数据,需要处理前用map深拷贝对象再操作 |
| | | List<TaskDaliyMongoDto> daliyMongoDtoList = daliyMongoList.stream().map(i -> SerializationUtils.clone(i)).collect( |
| | | Collectors.groupingBy( |
| | | (TaskDaliyMongo taskDaliyMongo) -> { |
| | | Project project; |
| | | if (projectMap.containsKey(taskDaliyMongo.getTaskUserMongo().getTask().getProjectId())) { |
| | | project = projectMap.get(taskDaliyMongo.getTaskUserMongo().getTask().getProjectId()); |
| | | } else { |
| | | project = projectRepository.findById(taskDaliyMongo.getTaskUserMongo().getTask().getProjectId()).orElseGet(Project::new); |
| | | projectMap.put(taskDaliyMongo.getTaskUserMongo().getTask().getProjectId(), project); |
| | | } |
| | | |
| | | if (specialProjectType.contains(project.getProjectTypeId())) { |
| | | return "task_" + taskDaliyMongo.getTaskUserMongo().getTask().getId(); |
| | | } else { |
| | | return "project_" + taskDaliyMongo.getTaskUserMongo().getTask().getProjectId(); |
| | | } |
| | | }, |
| | | Collectors.reducing( |
| | | null, |
| | | (TaskDaliyMongo prev, TaskDaliyMongo cur) -> { |
| | | if (prev == null) { |
| | | return cur; |
| | | } |
| | | // 计算工时 |
| | | prev.setConsumedHours(prev.getConsumedHours() + cur.getConsumedHours()); |
| | | return prev; |
| | | } |
| | | ) |
| | | ) |
| | | ).values().stream().map(taskDaliyMongo -> { |
| | | TaskDaliyMongoDto dto = new TaskDaliyMongoDto(); |
| | | dto.setId(taskDaliyMongo.getId()); |
| | | dto.setFillDate(taskDaliyMongo.getFillDate()); |
| | | dto.setUserId(userId); |
| | | // TODO:暂时用来存储企微ID |
| | | dto.setUserNickName(user.getWeComId()); |
| | | dto.setProjectId(taskDaliyMongo.getTaskUserMongo().getTask().getProjectId()); |
| | | dto.setProjectName(projectMap.get(taskDaliyMongo.getTaskUserMongo().getTask().getProjectId()).getName()); |
| | | dto.setTaskName(taskDaliyMongo.getTaskUserMongo().getTask().getName()); |
| | | dto.setTaskId(taskDaliyMongo.getTaskUserMongo().getTask().getId()); |
| | | dto.setConsumedHours(BigDecimal.valueOf(taskDaliyMongo.getConsumedHours()).setScale(2, RoundingMode.HALF_UP).doubleValue()); |
| | | dto.setTaskProgress(taskDaliyMongo.getTaskProgress()); |
| | | dto.setSettlementStatus(taskDaliyMongo.getSettlementStatus()); |
| | | dto.setRemarks(taskDaliyMongo.getRemarks()); |
| | | dto.setTaskUserMongo(taskDaliyMongo.getTaskUserMongo()); |
| | | return dto; |
| | | }).sorted(Comparator.comparing(TaskDaliyMongoDto::getProjectId)).collect(Collectors.toList()); |
| | | |
| | | // 统计请假信息 |
| | | AttendanceLeaveQueryCriteria leaveQueryCriteria = new AttendanceLeaveQueryCriteria(); |
| | | leaveQueryCriteria.setUserId(userId); |
| | | leaveQueryCriteria.setApprovalStatus(Constant.APPROVAL_STATUS_PASSED); |
| | | leaveQueryCriteria.setLeaveStartTimeGreaterThan(leaveQueryStartTime); |
| | | leaveQueryCriteria.setLeaveEndTimeLessThan(leaveQueryEndTime); |
| | | List<AttendanceLeave> leaveList = attendanceLeaveRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,leaveQueryCriteria,criteriaBuilder)); |
| | | BigDecimal leaveCountHour = leaveList.stream().map(leave -> { |
| | | if (leave.getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_DAY)) { |
| | | return new BigDecimal(8).multiply(new BigDecimal(leave.getLeaveDuration())); |
| | | } else { |
| | | return new BigDecimal(leave.getLeaveDuration()); |
| | | } |
| | | }).reduce(BigDecimal.ZERO, (res, cur) -> res.add(cur)); |
| | | String leaveHourDetail = leaveList.stream().map(leave -> { |
| | | BigDecimal leaveHour = leave.getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_DAY) ? new BigDecimal(8).multiply(new BigDecimal(leave.getLeaveDuration())) : new BigDecimal(leave.getLeaveDuration()); |
| | | return String.format("%s %s %sH", leave.getLeaveStartTime().toLocalDateTime().format(ymdFormatter), leaveTypeMap.get(leave.getLeaveType()), leaveHour.stripTrailingZeros().toPlainString()); |
| | | }).collect(Collectors.joining(";")); |
| | | // 统计换休信息 |
| | | AttendanceOvertimeQueryCriteria overtimeQueryCriteria = new AttendanceOvertimeQueryCriteria(); |
| | | overtimeQueryCriteria.setUserId(userId); |
| | | overtimeQueryCriteria.setApprovalStatus(Constant.OVERTIME_PASS); |
| | | overtimeQueryCriteria.setOvertimeStartTimeGreaterThan(overtimeQueryStartTime); |
| | | overtimeQueryCriteria.setOvertimeEndTimeLessThan(overtimeQueryEndTime); |
| | | List<AttendanceOvertime> overtimeList = attendanceOvertimeRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,overtimeQueryCriteria,criteriaBuilder)); |
| | | BigDecimal overtimeCountHour = overtimeList.stream().map(overtime -> new BigDecimal(overtime.getOvertimeDuration())).reduce(BigDecimal.ZERO, (res, cur) -> res.add(cur)); |
| | | // 统计加班信息 |
| | | BigDecimal workOvertimeCountHour = daliyMongoList.stream().collect(Collectors.groupingBy(TaskDaliyMongo::getFillDate, Collectors.summingDouble(TaskDaliyMongo::getConsumedHours))) |
| | | .values().stream().map(i -> new BigDecimal(i).subtract(new BigDecimal(8)).max(BigDecimal.ZERO)).reduce(BigDecimal.ZERO, (res, cur) -> res.add(cur)); |
| | | |
| | | // 项目周报 |
| | | SheetProperties weeklyReportProjectSheet = sheetInfo.getSheetList().stream().reduce(null, (res, cur) -> cur.getTitle().equals(reportParamMap.get(Constant.WEEKLY_REPORT_PROJECT_SHEET_NAME)) ? cur : res); |
| | | if (ObjectUtils.isNotEmpty(weeklyReportProjectSheet)) { |
| | | // 获取旧记录 |
| | | WxCpRecordQueryRequest recordQueryRequest = new WxCpRecordQueryRequest(); |
| | | recordQueryRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | recordQueryRequest.setSheetId(weeklyReportProjectSheet.getSheetId()); |
| | | recordQueryRequest.setKeyType("CELL_VALUE_KEY_TYPE_FIELD_TITLE"); |
| | | recordQueryRequest.setOffset(0); |
| | | recordQueryRequest.setLimit(1000); |
| | | RecordSort sort = new RecordSort(); |
| | | sort.setFieldTitle("提交日期"); |
| | | sort.setDesc(true); |
| | | recordQueryRequest.setSort(Arrays.asList(sort)); |
| | | WxCpRecordInfo recordInfo = wxCpOaWeDocSmartsheetService.recordInfo(recordQueryRequest); |
| | | |
| | | // 制作项目周报数据 |
| | | Map<String, List<Record>> filterRecordMap = daliyMongoDtoList.stream().map(item -> { |
| | | Record record = recordInfo.getRecords().stream().filter(r -> { |
| | | if (ObjectUtils.isEmpty(r.getValues().get("项目名称")) || StringUtils.isBlank(r.getValues().get("项目名称").toString())) { |
| | | return false; |
| | | } |
| | | LocalDate createDate = Instant.ofEpochMilli(Long.parseLong(r.getValues().get("提交日期").toString())).atZone(ZoneId.systemDefault()).toLocalDate(); |
| | | RecordOption projectNameRecord = ((List<?>) r.getValues().get("项目名称")).stream().map(o -> RecordOption.fromJson(gson.toJson(o))).findFirst().orElseGet(RecordOption::new); |
| | | RecordCellUserValue submitterRecord = ((List<?>) r.getValues().get("提交人")).stream().map(o -> RecordCellUserValue.fromJson(gson.toJson(o))).findFirst().orElseGet(RecordCellUserValue::new); |
| | | String projectName = specialProjectType.contains(projectMap.get(item.getProjectId()).getProjectTypeId()) ? item.getProjectName().concat("-").concat(item.getTaskName()) : item.getProjectName(); |
| | | return createDate.equals(endTime.toLocalDateTime().toLocalDate()) && projectNameRecord.getText().equals(projectName) && submitterRecord.getUserId().equals(item.getUserNickName()); |
| | | }).findFirst().orElseGet(Record::new); |
| | | |
| | | Map<String, Object> values = new HashMap<>(10); |
| | | // 项目名称 |
| | | RecordOption projectName = new RecordOption(); |
| | | if (specialProjectType.contains(projectMap.get(item.getProjectId()).getProjectTypeId())) { |
| | | projectName.setText(item.getProjectName().concat("-").concat(item.getTaskName())); |
| | | } else { |
| | | projectName.setText(item.getProjectName()); |
| | | } |
| | | values.put("项目名称", new Record.TypedValue(Record.DataType.FIELD_TYPE_SELECT, Arrays.asList(projectName)).getValue()); |
| | | // 项目负责人 |
| | | RecordCellUserValue projectLeader = new RecordCellUserValue(); |
| | | projectLeader.setUserId(item.getUserNickName()); |
| | | values.put("项目负责人", new Record.TypedValue(Record.DataType.FIELD_TYPE_USER, Arrays.asList(projectLeader)).getValue()); |
| | | // 项目进度 |
| | | RecordOption projectProgress = new RecordOption(); |
| | | projectProgress.setText("按期"); |
| | | if (ObjectUtils.isNotEmpty(projectMap.get(item.getProjectId()).getPlanEndDate()) && projectMap.get(item.getProjectId()).getPlanEndDate().toLocalDateTime().toLocalDate().compareTo(LocalDate.parse(item.getFillDate())) < 0) { |
| | | projectProgress.setText("延迟"); |
| | | } |
| | | values.put("项目进度", new Record.TypedValue(Record.DataType.FIELD_TYPE_SELECT, Arrays.asList(projectProgress)).getValue()); |
| | | // 预计结束日期 |
| | | if (ObjectUtils.isNotEmpty(projectMap.get(item.getProjectId()).getPlanEndDate())) { |
| | | String endTimestamp = String.valueOf(projectMap.get(item.getProjectId()).getPlanEndDate().getTime()); |
| | | values.put("预计结束日期", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, endTimestamp).getValue()); |
| | | } |
| | | // 本周实际投入 |
| | | values.put("本周实际投入", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, item.getConsumedHours()).getValue()); |
| | | // 提交人 |
| | | RecordCellUserValue submitter = new RecordCellUserValue(); |
| | | submitter.setUserId(item.getUserNickName()); |
| | | values.put("提交人", new Record.TypedValue(Record.DataType.FIELD_TYPE_USER, Arrays.asList(submitter)).getValue()); |
| | | // 提交日期 |
| | | String submitTimestamp = String.valueOf(endTime.getTime()); |
| | | values.put("提交日期", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, submitTimestamp).getValue()); |
| | | record.setValues(values); |
| | | return record; |
| | | }).collect(Collectors.groupingBy(record -> StringUtils.isNotBlank(record.getRecordId()) ? "EDIT" : "CREATE")); |
| | | // 待删除记录 |
| | | List<Record> recordDeleteList = recordInfo.getRecords().stream().filter(r -> ObjectUtils.isEmpty(r.getValues().get("项目名称")) || StringUtils.isBlank(r.getValues().get("项目名称").toString())).collect(Collectors.toList()); |
| | | |
| | | // 创建新纪录 |
| | | List<Record> recordCreateList = filterRecordMap.getOrDefault("CREATE", Collections.emptyList()); |
| | | if (recordCreateList.size() > 0) { |
| | | WxCpRecordCreateRequest recordCreateRequest = new WxCpRecordCreateRequest(); |
| | | recordCreateRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | recordCreateRequest.setSheetId(weeklyReportProjectSheet.getSheetId()); |
| | | recordCreateRequest.setKeyType("CELL_VALUE_KEY_TYPE_FIELD_TITLE"); |
| | | recordCreateRequest.setRecords(recordCreateList); |
| | | // 提交记录 |
| | | wxCpOaWeDocSmartsheetService.recordCreate(recordCreateRequest); |
| | | } |
| | | |
| | | // 编辑记录 |
| | | List<Record> recordEditList = filterRecordMap.getOrDefault("EDIT", Collections.emptyList()); |
| | | if (recordEditList.size() > 0) { |
| | | WxCpRecordEditRequest recordEditRequest = new WxCpRecordEditRequest(); |
| | | recordEditRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | recordEditRequest.setSheetId(weeklyReportProjectSheet.getSheetId()); |
| | | recordEditRequest.setKeyType("CELL_VALUE_KEY_TYPE_FIELD_TITLE"); |
| | | recordEditRequest.setRecords(recordEditList); |
| | | // 提交记录 |
| | | wxCpOaWeDocSmartsheetService.recordEdit(recordEditRequest); |
| | | } |
| | | |
| | | // 删除记录(仅限空数据) |
| | | if (recordDeleteList.size() > 0) { |
| | | List<String> recordIdDeleteList = recordDeleteList.stream().map(r -> r.getRecordId()).collect(Collectors.toList()); |
| | | wxCpOaWeDocSmartsheetService.recordDelete(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID), weeklyReportProjectSheet.getSheetId(), recordIdDeleteList); |
| | | } |
| | | } else { |
| | | System.out.println("项目周报子表不存在"); |
| | | } |
| | | |
| | | // 假勤周报 |
| | | if (!(leaveCountHour.compareTo(BigDecimal.ZERO) == 0) || !(overtimeCountHour.compareTo(BigDecimal.ZERO) == 0) || !(workOvertimeCountHour.compareTo(BigDecimal.ZERO) == 0)) { |
| | | SheetProperties weeklyReportAttendanceSheet = sheetInfo.getSheetList().stream().reduce(null, (res, cur) -> cur.getTitle().equals(reportParamMap.get(Constant.WEEKLY_REPORT_ATTENDANCE_SHEET_NAME)) ? cur : res); |
| | | if (ObjectUtils.isNotEmpty(weeklyReportAttendanceSheet)) { |
| | | // 获取旧记录 |
| | | WxCpRecordQueryRequest recordQueryRequest = new WxCpRecordQueryRequest(); |
| | | recordQueryRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | recordQueryRequest.setSheetId(weeklyReportAttendanceSheet.getSheetId()); |
| | | recordQueryRequest.setKeyType("CELL_VALUE_KEY_TYPE_FIELD_TITLE"); |
| | | recordQueryRequest.setOffset(0); |
| | | recordQueryRequest.setLimit(1000); |
| | | RecordSort sort = new RecordSort(); |
| | | sort.setFieldTitle("提交日期"); |
| | | sort.setDesc(true); |
| | | recordQueryRequest.setSort(Arrays.asList(sort)); |
| | | WxCpRecordInfo recordInfo = wxCpOaWeDocSmartsheetService.recordInfo(recordQueryRequest); |
| | | |
| | | // 制作假勤周报数据 |
| | | Record record = recordInfo.getRecords().stream().filter(r -> { |
| | | LocalDate createDate = Instant.ofEpochMilli(Long.parseLong(r.getValues().get("提交日期").toString())).atZone(ZoneId.systemDefault()).toLocalDate(); |
| | | RecordCellTextValue userNameRecord = ((List<?>) r.getValues().get("人员名称")).stream().map(o -> RecordCellTextValue.fromJson(gson.toJson(o))).findFirst().orElseGet(RecordCellTextValue::new); |
| | | return user.getNickName().equals(userNameRecord.getText()) && createDate.equals(endTime.toLocalDateTime().toLocalDate()); |
| | | }).findFirst().orElseGet(Record::new); |
| | | Map<String, Object> values = new HashMap<>(3); |
| | | // 人员名称 |
| | | RecordCellTextValue userName = new RecordCellTextValue(); |
| | | userName.setType("text"); |
| | | userName.setText(user.getNickName()); |
| | | values.put("人员名称", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(userName)).getValue()); |
| | | // 加班 |
| | | values.put("加班(H)", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, workOvertimeCountHour.doubleValue()).getValue()); |
| | | // 换休 |
| | | values.put("换休(H)", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, overtimeCountHour.doubleValue()).getValue()); |
| | | // 请假 |
| | | values.put("请假(H)", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, leaveCountHour.doubleValue()).getValue()); |
| | | // 提交日期 |
| | | String submitTimestamp = String.valueOf(endTime.getTime()); |
| | | values.put("提交日期", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, submitTimestamp).getValue()); |
| | | record.setValues(values); |
| | | // 请假详细 |
| | | RecordCellTextValue leaveDetail = new RecordCellTextValue(); |
| | | leaveDetail.setType("text"); |
| | | leaveDetail.setText(leaveHourDetail); |
| | | values.put("请假详细", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(leaveDetail)).getValue()); |
| | | |
| | | if (StringUtils.isNotBlank(record.getRecordId())) { |
| | | // 编辑记录 |
| | | WxCpRecordEditRequest recordEditRequest = new WxCpRecordEditRequest(); |
| | | recordEditRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | recordEditRequest.setSheetId(weeklyReportAttendanceSheet.getSheetId()); |
| | | recordEditRequest.setKeyType("CELL_VALUE_KEY_TYPE_FIELD_TITLE"); |
| | | recordEditRequest.setRecords(Arrays.asList(record)); |
| | | // 提交记录 |
| | | wxCpOaWeDocSmartsheetService.recordEdit(recordEditRequest); |
| | | } else { |
| | | // 创建新纪录 |
| | | WxCpRecordCreateRequest recordCreateRequest = new WxCpRecordCreateRequest(); |
| | | recordCreateRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | recordCreateRequest.setSheetId(weeklyReportAttendanceSheet.getSheetId()); |
| | | recordCreateRequest.setKeyType("CELL_VALUE_KEY_TYPE_FIELD_TITLE"); |
| | | recordCreateRequest.setRecords(Arrays.asList(record)); |
| | | // 提交记录 |
| | | wxCpOaWeDocSmartsheetService.recordCreate(recordCreateRequest); |
| | | } |
| | | } else { |
| | | System.out.println("假勤周报子表不存在"); |
| | | } |
| | | } |
| | | } |
| | | } catch (WxErrorException wxErrorException) { |
| | | wxErrorException.printStackTrace(); |
| | | sendNotice(Arrays.asList("YueYuHuanXiangQinYuFenDou"), "企微通信异常", String.format("<div class=\"normal\">异常方法:%s</div>" + |
| | | "<div class=\"highlight\">请前往API服务查看LOG。</div>", |
| | | "toWecomSheetPushWeeklyReport"), Constant.WECOM_MESSAGE_TYPE_TEXTCARD); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } else { |
| | | throw new BadRequestException("企微周报参数缺失"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 发送企微项目WBS及独立报告 |
| | | * |
| | | * @param projectIds 周报用户企微ID |
| | | */ |
| | | public void toWeComSheetPushProjectReport(List<Long> projectIds) { |
| | | if (projectIds.size() > 0) { |
| | | // 查询项目类型 |
| | | Map<Long, ProjectType> projectTypeMap = projectTypeRepository.findAll().stream().collect(Collectors.toMap(ProjectType::getId, i -> i)); |
| | | // 查询项目状态 |
| | | Map<String, String> projectStatusMap = dictDetailRepository.findByDictName(Constant.PROJECT_STATUS).stream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel)); |
| | | // 查询任务状态 |
| | | Map<String, String> taskStatusMap = dictDetailRepository.findByDictName(Constant.TASK_STATUS).stream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel)); |
| | | // 获取企微报告参数 |
| | | Map<String, String> reportParamMap = dictDetailRepository.findByDictName(Constant.WECOM_REPORT_PARAM).stream().collect(Collectors.toMap(DictDetail::getLabel, DictDetail::getValue)); |
| | | |
| | | if (!reportParamMap.containsKey(Constant.WEEKLY_REPORT_DOC_ID)) { |
| | | throw new BadRequestException("周报文件ID未设置"); |
| | | } |
| | | |
| | | try { |
| | | // 获取企业微信Token |
| | | wxCpService.getAccessToken(); |
| | | |
| | | // 查询现有子表信息 |
| | | WxCpSheetQueryRequest sheetQueryRequest = new WxCpSheetQueryRequest(); |
| | | sheetQueryRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | WxCpSheetInfo sheetInfo = wxCpOaWeDocSmartsheetService.sheetInfo(sheetQueryRequest); |
| | | |
| | | for (Long projectId : projectIds) { |
| | | // 获取项目信息 |
| | | Project project = projectRepository.findById(projectId).orElseGet(Project::new); |
| | | // 获取任务信息 |
| | | Query taskQuery = new Query(Criteria.where("projectId").is(projectId)); |
| | | List<TaskMongo> taskMongoList = mongoTemplate.find(taskQuery, TaskMongo.class); |
| | | List<TaskUserMongo> taskUserMongoList = mongoTemplate.find(Query.query(Criteria.where("task").in(taskMongoList)), TaskUserMongo.class); |
| | | |
| | | // 项目WBS信息 |
| | | SheetProperties wbsProjectSheet = sheetInfo.getSheetList().stream().reduce(null, (res, cur) -> cur.getTitle().equals(reportParamMap.get(Constant.PROJECT_REPORT_WBS_SHEET_NAME)) ? cur : res); |
| | | if (ObjectUtils.isNotEmpty(wbsProjectSheet)) { |
| | | Record projectRecord = new Record(); |
| | | Integer queryOffset = 0; |
| | | |
| | | do { |
| | | // 制作查询项目WBS子表记录条件 |
| | | WxCpRecordQueryRequest recordQueryRequest = new WxCpRecordQueryRequest(); |
| | | recordQueryRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | recordQueryRequest.setSheetId(wbsProjectSheet.getSheetId()); |
| | | recordQueryRequest.setKeyType("CELL_VALUE_KEY_TYPE_FIELD_TITLE"); |
| | | recordQueryRequest.setOffset(queryOffset); |
| | | recordQueryRequest.setLimit(1000); |
| | | RecordSort sort = new RecordSort(); |
| | | sort.setFieldTitle("项目ID"); |
| | | sort.setDesc(true); |
| | | recordQueryRequest.setSort(Arrays.asList(sort)); |
| | | |
| | | // 查询项目WBS子表记录 |
| | | WxCpRecordInfo wbsRecordInfo = wxCpOaWeDocSmartsheetService.recordInfo(recordQueryRequest); |
| | | |
| | | // 查找对应项目记录 |
| | | List<Record> filterRecordList = wbsRecordInfo.getRecords().stream().filter(item -> !item.getValues().isEmpty() && item.getValues().containsKey("项目ID") && Double.valueOf(projectId).equals(item.getValues().get("项目ID"))).collect(Collectors.toList()); |
| | | projectRecord = filterRecordList.stream().findFirst().orElseGet(Record::new); |
| | | if (StringUtils.isBlank(projectRecord.getRecordId()) && !wbsRecordInfo.getHasMore()) { |
| | | break; |
| | | } else { |
| | | queryOffset++; |
| | | } |
| | | } while (StringUtils.isBlank(projectRecord.getRecordId())); |
| | | |
| | | // 创建/更新记录 |
| | | Map<String, Object> values = Optional.ofNullable(projectRecord.getValues()).orElse(new HashMap<>()); |
| | | // 项目ID |
| | | if (!values.containsKey("项目ID")) { |
| | | values.put("项目ID", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, projectId.doubleValue()).getValue()); |
| | | } |
| | | // 项目类型 |
| | | if (projectTypeMap.containsKey(project.getProjectTypeId())) { |
| | | RecordOption projectType = new RecordOption(); |
| | | projectType.setText(projectTypeMap.get(project.getProjectTypeId()).getName()); |
| | | values.put("项目类型", new Record.TypedValue(Record.DataType.FIELD_TYPE_SELECT, Arrays.asList(projectType)).getValue()); |
| | | } |
| | | // 项目名称 |
| | | RecordCellTextValue projectName = new RecordCellTextValue(); |
| | | projectName.setType("text"); |
| | | projectName.setText(project.getName()); |
| | | values.put("项目名称", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(projectName)).getValue()); |
| | | // 项目负责人 |
| | | if (StringUtils.isNotBlank(project.getLiableUserId())) { |
| | | RecordCellTextValue projectLeader = new RecordCellTextValue(); |
| | | String leaderName = Arrays.stream(project.getLiableUserId().split(",")).filter(f -> StringUtils.isNotBlank(f)).map(m -> { |
| | | Long userId = Long.parseLong(m.replace("-", "")); |
| | | User user = userRepository.findById(userId).orElseGet(User::new); |
| | | return Optional.ofNullable(user.getNickName()).orElse(""); |
| | | }).collect(Collectors.joining(",")); |
| | | projectLeader.setType("text"); |
| | | projectLeader.setText(leaderName); |
| | | values.put("项目负责人", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(projectLeader)).getValue()); |
| | | } |
| | | // 计划成本 |
| | | ProjectCostSummary projectCostSummary = projectCostRepository.findSummaryByProjectId(projectId); |
| | | List<ProjectCostOther> projectCostOtherList = projectCostOtherRepository.findByProjectId(projectId); |
| | | Double planCost = projectCostSummary.getTotalLaborCost().add(projectCostOtherList.stream().map(ProjectCostOther::getProjectCost).reduce(BigDecimal.ZERO, BigDecimal::add)).doubleValue(); |
| | | values.put("计划成本", new Record.TypedValue(Record.DataType.FIELD_TYPE_CURRENCY, planCost).getValue()); |
| | | // 实际成本 |
| | | Aggregation customerAgg = Aggregation.newAggregation( |
| | | Aggregation.match(Criteria.where("taskUserMongo").in(taskUserMongoList)), |
| | | Aggregation.project("userId", "consumedHours"), |
| | | Aggregation.group("userId").sum("consumedHours").as("consumedHours") |
| | | ); |
| | | AggregationResults<Map> aggregate = mongoTemplate.aggregate(customerAgg, TaskDaliyMongo.class, Map.class); |
| | | BigDecimal actualCost = aggregate.getMappedResults().stream().filter(data -> data.get("_id") != null).map(data -> { |
| | | BigDecimal moneyTotalCost = calcUserCostByHours(Long.parseLong(String.valueOf(data.get("_id"))), Double.valueOf(String.valueOf(data.get("consumedHours")))); |
| | | return moneyTotalCost; |
| | | }).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | values.put("实际成本", new Record.TypedValue(Record.DataType.FIELD_TYPE_CURRENCY, actualCost.doubleValue()).getValue()); |
| | | // 预计开始时间 |
| | | if (ObjectUtils.isNotEmpty(project.getPlanStartDate())) { |
| | | String planStartTimestamp = String.valueOf(project.getPlanStartDate().getTime()); |
| | | values.put("预计开始时间", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, planStartTimestamp).getValue()); |
| | | } |
| | | // 预计结束时间 |
| | | if (ObjectUtils.isNotEmpty(project.getPlanEndDate())) { |
| | | String planEndTimestamp = String.valueOf(project.getPlanEndDate().getTime()); |
| | | values.put("预计结束时间", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, planEndTimestamp).getValue()); |
| | | } |
| | | // 计划投入人月 |
| | | BigDecimal planManMonth = taskUserMongoList.stream().map(p -> new BigDecimal(p.getTaskHours())).reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(160), 2, BigDecimal.ROUND_CEILING); |
| | | values.put("计划投入人月", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, planManMonth.doubleValue()).getValue()); |
| | | // 实际投入人月 |
| | | BigDecimal actualManMonth = taskUserMongoList.stream().map(p -> new BigDecimal(p.getCostHours())).reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(160), 2, BigDecimal.ROUND_CEILING); |
| | | values.put("实际投入人月", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, actualManMonth.doubleValue()).getValue()); |
| | | // 盈余 |
| | | BigDecimal surplus = planManMonth.subtract(actualManMonth).max(BigDecimal.ZERO); |
| | | values.put("盈余", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, surplus.doubleValue()).getValue()); |
| | | // 项目状态 |
| | | RecordOption projectStatus = new RecordOption(); |
| | | projectStatus.setText(projectStatusMap.get(project.getProjectStatus())); |
| | | values.put("项目状态", new Record.TypedValue(Record.DataType.FIELD_TYPE_SELECT, Arrays.asList(projectStatus)).getValue()); |
| | | // 项目描述 |
| | | if (StringUtils.isNotBlank(project.getRequirement())) { |
| | | RecordCellTextValue projectDescription = new RecordCellTextValue(); |
| | | projectDescription.setType("text"); |
| | | projectDescription.setText(project.getRequirement()); |
| | | values.put("项目描述", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(projectDescription)).getValue()); |
| | | } |
| | | // 备注 |
| | | if (StringUtils.isNotBlank(project.getRemarks())) { |
| | | RecordCellTextValue projectRemark = new RecordCellTextValue(); |
| | | projectRemark.setType("text"); |
| | | projectRemark.setText(project.getRemarks()); |
| | | values.put("备注", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(projectRemark)).getValue()); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(projectRecord.getRecordId())) { |
| | | // 更新记录 |
| | | WxCpRecordEditRequest recordEditRequest = new WxCpRecordEditRequest(); |
| | | recordEditRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | recordEditRequest.setSheetId(wbsProjectSheet.getSheetId()); |
| | | recordEditRequest.setKeyType("CELL_VALUE_KEY_TYPE_FIELD_TITLE"); |
| | | projectRecord.setValues(values); |
| | | recordEditRequest.setRecords(Arrays.asList(projectRecord)); |
| | | wxCpOaWeDocSmartsheetService.recordEdit(recordEditRequest); |
| | | } else { |
| | | // 创建记录 |
| | | WxCpRecordCreateRequest recordCreateRequest = new WxCpRecordCreateRequest(); |
| | | recordCreateRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | recordCreateRequest.setSheetId(wbsProjectSheet.getSheetId()); |
| | | recordCreateRequest.setKeyType("CELL_VALUE_KEY_TYPE_FIELD_TITLE"); |
| | | projectRecord.setValues(values); |
| | | recordCreateRequest.setRecords(Arrays.asList(projectRecord)); |
| | | wxCpOaWeDocSmartsheetService.recordCreate(recordCreateRequest); |
| | | } |
| | | } else { |
| | | System.out.println("项目WBS报告子表不存在"); |
| | | } |
| | | |
| | | // 项目独立报告 |
| | | SheetProperties separateProjectSheet = sheetInfo.getSheetList().stream().reduce(null, (res, cur) -> cur.getTitle().equals(project.getName()) ? cur : res); |
| | | if (ObjectUtils.isEmpty(separateProjectSheet)) { |
| | | // 新建项目独立报告Sheet |
| | | WxCpSheetCreateRequest sheetCreateRequest = new WxCpSheetCreateRequest(); |
| | | sheetCreateRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | SheetProperties sheetProperties = new SheetProperties(); |
| | | sheetProperties.setTitle(project.getName()); |
| | | sheetProperties.setIndex(3); |
| | | sheetCreateRequest.setProperties(sheetProperties); |
| | | // 执行新建项目独立报告Sheet |
| | | WxCpSheetCreateData sheetCreateData = wxCpOaWeDocSmartsheetService.sheetCreate(sheetCreateRequest); |
| | | separateProjectSheet = sheetCreateData.getProperties(); |
| | | |
| | | // 查询Sheet字段默认列:因智能表格至少一列的要求,创建Sheet时会有一个默认列 |
| | | WxCpFieldQueryRequest fieldQueryRequest = new WxCpFieldQueryRequest(); |
| | | fieldQueryRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | fieldQueryRequest.setSheetId(separateProjectSheet.getSheetId()); |
| | | fieldQueryRequest.setOffset(0); |
| | | fieldQueryRequest.setLimit(1000); |
| | | WxCpFieldInfo fieldInfo = wxCpOaWeDocSmartsheetService.fieldInfo(fieldQueryRequest); |
| | | |
| | | // 创建项目独立报告Field |
| | | List<Field> fieldList = new ArrayList<>(); |
| | | // 任务ID |
| | | Field taskId = new Field(); |
| | | taskId.setFieldTitle("任务ID"); |
| | | taskId.setFieldType("FIELD_TYPE_TEXT"); |
| | | fieldList.add(taskId); |
| | | // 优先级 |
| | | Field taskLevel = new Field(); |
| | | taskLevel.setFieldTitle("优先级"); |
| | | taskLevel.setFieldType("FIELD_TYPE_SINGLE_SELECT"); |
| | | SingleSelectFieldProperty taskLevelProp = new SingleSelectFieldProperty(); |
| | | taskLevelProp.setIsQuickAdd(false); |
| | | FieldOption highOption = new FieldOption(); |
| | | highOption.setText("高"); |
| | | highOption.setStyle(18); |
| | | FieldOption mediumOption = new FieldOption(); |
| | | mediumOption.setText("中"); |
| | | mediumOption.setStyle(23); |
| | | FieldOption lowOption = new FieldOption(); |
| | | lowOption.setText("低"); |
| | | lowOption.setStyle(14); |
| | | taskLevelProp.setOptions(Arrays.asList(highOption, mediumOption, lowOption)); |
| | | taskLevel.setPropertySingleSelect(taskLevelProp); |
| | | fieldList.add(taskLevel); |
| | | // 备注 |
| | | Field remark = new Field(); |
| | | remark.setFieldTitle("备注"); |
| | | remark.setFieldType("FIELD_TYPE_TEXT"); |
| | | fieldList.add(remark); |
| | | // 完成度 |
| | | Field completePercent = new Field(); |
| | | completePercent.setFieldTitle("完成度"); |
| | | completePercent.setFieldType("FIELD_TYPE_PERCENTAGE"); |
| | | PercentageFieldProperty completePercentProp = new PercentageFieldProperty(); |
| | | completePercentProp.setDecimalPlaces(0); |
| | | completePercentProp.setUseSeparate(false); |
| | | completePercent.setPropertyPercentage(completePercentProp); |
| | | fieldList.add(completePercent); |
| | | // 状态 |
| | | Field taskStatus = new Field(); |
| | | taskStatus.setFieldTitle("状态"); |
| | | taskStatus.setFieldType("FIELD_TYPE_SINGLE_SELECT"); |
| | | SingleSelectFieldProperty taskStatusProp = new SingleSelectFieldProperty(); |
| | | taskStatusProp.setIsQuickAdd(false); |
| | | FieldOption notStartOption = new FieldOption(); |
| | | notStartOption.setText("未开始"); |
| | | notStartOption.setStyle(21); |
| | | FieldOption inHandOption = new FieldOption(); |
| | | inHandOption.setText("进行中"); |
| | | inHandOption.setStyle(23); |
| | | FieldOption toBeTestOption = new FieldOption(); |
| | | toBeTestOption.setText("待测试"); |
| | | toBeTestOption.setStyle(12); |
| | | FieldOption stopOption = new FieldOption(); |
| | | stopOption.setText("已暂停"); |
| | | stopOption.setStyle(18); |
| | | FieldOption toBeAdminOption = new FieldOption(); |
| | | toBeAdminOption.setText("待承认"); |
| | | toBeAdminOption.setStyle(20); |
| | | FieldOption completeOption = new FieldOption(); |
| | | completeOption.setText("已完成"); |
| | | completeOption.setStyle(16); |
| | | taskStatusProp.setOptions(Arrays.asList(notStartOption, inHandOption, toBeTestOption, stopOption, toBeAdminOption, completeOption)); |
| | | taskStatus.setPropertySingleSelect(taskStatusProp); |
| | | fieldList.add(taskStatus); |
| | | // 实际工时 |
| | | Field actualHours = new Field(); |
| | | actualHours.setFieldTitle("实际工时"); |
| | | actualHours.setFieldType("FIELD_TYPE_NUMBER"); |
| | | NumberFieldProperty actualHoursProperty = new NumberFieldProperty(); |
| | | actualHoursProperty.setDecimalPlaces(2); |
| | | actualHoursProperty.setUseSeparate(false); |
| | | actualHours.setPropertyNumber(actualHoursProperty); |
| | | fieldList.add(actualHours); |
| | | // 实际完成时间 |
| | | Field actualEndTime = new Field(); |
| | | actualEndTime.setFieldTitle("实际完成时间"); |
| | | actualEndTime.setFieldType("FIELD_TYPE_DATE_TIME"); |
| | | DateTimeFieldProperty actualEndTimeProp = new DateTimeFieldProperty(); |
| | | actualEndTimeProp.setFormat("yyyy\"年\"m\"月\"d\"日\""); |
| | | actualEndTimeProp.setAutoFill(false); |
| | | actualEndTime.setPropertyDateTime(actualEndTimeProp); |
| | | fieldList.add(actualEndTime); |
| | | // 实际开始时间 |
| | | Field actualStartTime = new Field(); |
| | | actualStartTime.setFieldTitle("实际开始时间"); |
| | | actualStartTime.setFieldType("FIELD_TYPE_DATE_TIME"); |
| | | DateTimeFieldProperty actualStartTimeProp = new DateTimeFieldProperty(); |
| | | actualStartTimeProp.setFormat("yyyy\"年\"m\"月\"d\"日\""); |
| | | actualStartTimeProp.setAutoFill(false); |
| | | actualStartTime.setPropertyDateTime(actualStartTimeProp); |
| | | fieldList.add(actualStartTime); |
| | | // 预计工时 |
| | | Field expectHours = new Field(); |
| | | expectHours.setFieldTitle("预计工时"); |
| | | expectHours.setFieldType("FIELD_TYPE_NUMBER"); |
| | | NumberFieldProperty expectHoursProperty = new NumberFieldProperty(); |
| | | expectHoursProperty.setDecimalPlaces(2); |
| | | expectHoursProperty.setUseSeparate(false); |
| | | expectHours.setPropertyNumber(expectHoursProperty); |
| | | fieldList.add(expectHours); |
| | | // 预计完成时间 |
| | | Field planEndTime = new Field(); |
| | | planEndTime.setFieldTitle("预计完成时间"); |
| | | planEndTime.setFieldType("FIELD_TYPE_DATE_TIME"); |
| | | DateTimeFieldProperty planEndTimeProp = new DateTimeFieldProperty(); |
| | | planEndTimeProp.setFormat("yyyy\"年\"m\"月\"d\"日\""); |
| | | planEndTimeProp.setAutoFill(false); |
| | | planEndTime.setPropertyDateTime(planEndTimeProp); |
| | | fieldList.add(planEndTime); |
| | | // 预计开始时间 |
| | | Field planStartTime = new Field(); |
| | | planStartTime.setFieldTitle("预计开始时间"); |
| | | planStartTime.setFieldType("FIELD_TYPE_DATE_TIME"); |
| | | DateTimeFieldProperty planStartTimeProp = new DateTimeFieldProperty(); |
| | | planStartTimeProp.setFormat("yyyy\"年\"m\"月\"d\"日\""); |
| | | planStartTimeProp.setAutoFill(false); |
| | | planStartTime.setPropertyDateTime(planStartTimeProp); |
| | | fieldList.add(planStartTime); |
| | | // 作成者 |
| | | Field taskAllocCreator = new Field(); |
| | | taskAllocCreator.setFieldTitle("作成者"); |
| | | taskAllocCreator.setFieldType("FIELD_TYPE_TEXT"); |
| | | fieldList.add(taskAllocCreator); |
| | | // 任务分配-名称 |
| | | Field taskAllocName = new Field(); |
| | | taskAllocName.setFieldTitle("任务分配-名称"); |
| | | taskAllocName.setFieldType("FIELD_TYPE_TEXT"); |
| | | fieldList.add(taskAllocName); |
| | | // 任务详情-描述 |
| | | Field taskDetailDescription = new Field(); |
| | | taskDetailDescription.setFieldTitle("任务详情-描述"); |
| | | taskDetailDescription.setFieldType("FIELD_TYPE_TEXT"); |
| | | fieldList.add(taskDetailDescription); |
| | | // 任务详情-任务负责人 |
| | | Field taskDetailLeader = new Field(); |
| | | taskDetailLeader.setFieldTitle("任务详情-任务负责人"); |
| | | taskDetailLeader.setFieldType("FIELD_TYPE_TEXT"); |
| | | fieldList.add(taskDetailLeader); |
| | | // 任务详情-名称 |
| | | Field taskDetailName = new Field(); |
| | | taskDetailName.setFieldTitle("任务详情-名称"); |
| | | taskDetailName.setFieldType("FIELD_TYPE_TEXT"); |
| | | fieldList.add(taskDetailName); |
| | | // 项目负责人 |
| | | Field projectLeader = new Field(); |
| | | projectLeader.setFieldTitle("项目负责人"); |
| | | projectLeader.setFieldType("FIELD_TYPE_TEXT"); |
| | | fieldList.add(projectLeader); |
| | | // 项目名称 |
| | | Field projectName = new Field(); |
| | | projectName.setFieldTitle("项目名称"); |
| | | projectName.setFieldType("FIELD_TYPE_TEXT"); |
| | | fieldList.add(projectName); |
| | | |
| | | // 执行创建项目独立报告Field |
| | | WxCpFieldCreateRequest fieldCreateRequest = new WxCpFieldCreateRequest(); |
| | | fieldCreateRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | fieldCreateRequest.setSheetId(separateProjectSheet.getSheetId()); |
| | | fieldCreateRequest.setFields(fieldList); |
| | | wxCpOaWeDocSmartsheetService.fieldCreate(fieldCreateRequest); |
| | | |
| | | // 删除创建Sheet时的默认列 |
| | | List<String> delFieldIdList = fieldInfo.getFields().stream().map(f -> f.getFieldId()).collect(Collectors.toList()); |
| | | wxCpOaWeDocSmartsheetService.fieldDelete(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID), separateProjectSheet.getSheetId(), delFieldIdList); |
| | | } |
| | | |
| | | // 添加项目独立报告记录 |
| | | List<Record> recordList = new ArrayList<>(); |
| | | Integer queryOffset = 0; |
| | | |
| | | do { |
| | | // 查询项目独立报告记录 |
| | | WxCpRecordQueryRequest recordQueryRequest = new WxCpRecordQueryRequest(); |
| | | recordQueryRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | recordQueryRequest.setSheetId(separateProjectSheet.getSheetId()); |
| | | recordQueryRequest.setKeyType("CELL_VALUE_KEY_TYPE_FIELD_TITLE"); |
| | | RecordSort sort = new RecordSort(); |
| | | sort.setFieldTitle("任务ID"); |
| | | sort.setDesc(true); |
| | | recordQueryRequest.setSort(Arrays.asList(sort)); |
| | | recordQueryRequest.setOffset(queryOffset); |
| | | recordQueryRequest.setLimit(1000); |
| | | |
| | | WxCpRecordInfo recordInfo = wxCpOaWeDocSmartsheetService.recordInfo(recordQueryRequest); |
| | | recordList.addAll(recordInfo.getRecords()); |
| | | if (!recordInfo.getHasMore()) { |
| | | break; |
| | | } else { |
| | | queryOffset++; |
| | | } |
| | | } while (recordList.size() > 0); |
| | | |
| | | // 整理新建及更新数据 |
| | | Map<String, List<Record>> filterRecordMap = taskUserMongoList.stream().map(taskUserMongo -> { |
| | | Record taskRecord = recordList.stream().filter(record -> taskUserMongo.getId().equals(record.getValues().get("任务ID"))).findFirst().orElseGet(Record::new); |
| | | |
| | | // 获取日报信息 |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(Query.query(new Criteria("taskUserMongo").is(taskUserMongo)), TaskDaliyMongo.class); |
| | | |
| | | Map<String, Object> values = new HashMap<>(); |
| | | // 项目名称 |
| | | RecordCellTextValue projectName = new RecordCellTextValue(); |
| | | projectName.setType("text"); |
| | | projectName.setText(project.getName()); |
| | | values.put("项目名称", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(projectName)).getValue()); |
| | | // 项目负责人 |
| | | RecordCellTextValue projectLeader = new RecordCellTextValue(); |
| | | String leaderName = Arrays.stream(project.getLiableUserId().split(",")).filter(f -> StringUtils.isNotBlank(f)).map(m -> { |
| | | Long userId = Long.parseLong(m.replace("-", "")); |
| | | User user = userRepository.findById(userId).orElseGet(User::new); |
| | | return Optional.ofNullable(user.getNickName()).orElse(""); |
| | | }).collect(Collectors.joining(",")); |
| | | projectLeader.setType("text"); |
| | | projectLeader.setText(leaderName); |
| | | values.put("项目负责人", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(projectLeader)).getValue()); |
| | | // 任务详情-名称 |
| | | RecordCellTextValue taskDetailName = new RecordCellTextValue(); |
| | | taskDetailName.setType("text"); |
| | | taskDetailName.setText(taskUserMongo.getTask().getName()); |
| | | values.put("任务详情-名称", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(taskDetailName)).getValue()); |
| | | // 任务详情-任务负责人 |
| | | String taskDetailLeaderName = taskUserMongo.getTask().getUserIdList().stream().map(userId -> { |
| | | User user = userRepository.findById(userId).orElseGet(User::new); |
| | | return Optional.ofNullable(user.getNickName()).orElse(""); |
| | | }).collect(Collectors.joining(",")); |
| | | RecordCellTextValue taskDetailLeader = new RecordCellTextValue(); |
| | | taskDetailLeader.setType("text"); |
| | | taskDetailLeader.setText(taskDetailLeaderName); |
| | | values.put("任务详情-任务负责人", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(taskDetailLeader)).getValue()); |
| | | // 任务详情-描述 |
| | | if (StringUtils.isNotBlank(taskUserMongo.getTask().getDescription())) { |
| | | RecordCellTextValue taskDetailDescription = new RecordCellTextValue(); |
| | | taskDetailDescription.setType("text"); |
| | | taskDetailDescription.setText(taskUserMongo.getTask().getDescription()); |
| | | values.put("任务详情-描述", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(taskDetailDescription)).getValue()); |
| | | } |
| | | // 任务分配-名称 |
| | | RecordCellTextValue taskAllocName = new RecordCellTextValue(); |
| | | taskAllocName.setType("text"); |
| | | taskAllocName.setText(taskUserMongo.getName()); |
| | | values.put("任务分配-名称", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(taskAllocName)).getValue()); |
| | | // 作成者 |
| | | RecordCellTextValue taskAllocCreator = new RecordCellTextValue(); |
| | | taskAllocCreator.setType("text"); |
| | | if (ObjectUtils.isNotEmpty(taskUserMongo.getUserId())) { |
| | | User user = userRepository.findById(taskUserMongo.getUserId()).orElseGet(User::new); |
| | | taskAllocCreator.setText(user.getNickName()); |
| | | } else { |
| | | taskAllocCreator.setText(""); |
| | | } |
| | | values.put("作成者", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(taskAllocCreator)).getValue()); |
| | | // 预计开始时间 |
| | | String planStartTimestamp = String.valueOf(taskUserMongo.getTaskStartDate().getTime()); |
| | | values.put("预计开始时间", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, planStartTimestamp).getValue()); |
| | | // 预计完成时间 |
| | | String planEndTimestamp = String.valueOf(taskUserMongo.getTaskEndDate().getTime()); |
| | | values.put("预计完成时间", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, planEndTimestamp).getValue()); |
| | | // 预计工时 |
| | | values.put("预计工时", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, taskUserMongo.getTaskHours()).getValue()); |
| | | // 实际开始时间 |
| | | if (daliyMongoList.size() > 0) { |
| | | daliyMongoList.sort(((o1, o2) -> o1.getFillDate().compareTo(o2.getFillDate()))); |
| | | String actualStartTimestamp = String.valueOf(daliyMongoList.get(0).getFillDate().getTime()); |
| | | values.put("实际开始时间", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, actualStartTimestamp).getValue()); |
| | | } |
| | | // 实际完成时间 |
| | | if (daliyMongoList.size() > 0 && Constant.TASK_STATUS_COMPLETED.equals(taskUserMongo.getTaskStatus())) { |
| | | daliyMongoList.sort(((o1, o2) -> o2.getFillDate().compareTo(o1.getFillDate()))); |
| | | String actualEndTimestamp = String.valueOf(daliyMongoList.get(0).getFillDate().getTime()); |
| | | values.put("实际完成时间", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, actualEndTimestamp).getValue()); |
| | | } |
| | | // 实际工时 |
| | | values.put("实际工时", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, taskUserMongo.getCostHours()).getValue()); |
| | | // 状态 |
| | | RecordOption taskStatus = new RecordOption(); |
| | | taskStatus.setText(taskStatusMap.get(taskUserMongo.getTaskStatus())); |
| | | values.put("状态", new Record.TypedValue(Record.DataType.FIELD_TYPE_SELECT, Arrays.asList(taskStatus)).getValue()); |
| | | // 完成度 |
| | | Double completePercent = new Double(0); |
| | | if (daliyMongoList.size() > 0) { |
| | | daliyMongoList.sort(((o1, o2) -> o2.getFillDate().compareTo(o1.getFillDate()))); |
| | | completePercent = daliyMongoList.get(0).getTaskProgress(); |
| | | } |
| | | values.put("完成度", new Record.TypedValue(Record.DataType.FIELD_TYPE_PERCENTAGE, completePercent).getValue()); |
| | | // 任务ID |
| | | RecordCellTextValue taskId = new RecordCellTextValue(); |
| | | taskId.setType("text"); |
| | | taskId.setText(taskUserMongo.getId()); |
| | | values.put("任务ID", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(taskId)).getValue()); |
| | | |
| | | taskRecord.setValues(values); |
| | | return taskRecord; |
| | | }).collect(Collectors.groupingBy(record -> StringUtils.isNotBlank(record.getRecordId()) ? "EDIT" : "CREATE")); |
| | | |
| | | // 创建新纪录 |
| | | List<Record> recordCreateList = filterRecordMap.getOrDefault("CREATE", Collections.emptyList()); |
| | | if (recordCreateList.size() > 0) { |
| | | WxCpRecordCreateRequest recordCreateRequest = new WxCpRecordCreateRequest(); |
| | | recordCreateRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | recordCreateRequest.setSheetId(separateProjectSheet.getSheetId()); |
| | | recordCreateRequest.setKeyType("CELL_VALUE_KEY_TYPE_FIELD_TITLE"); |
| | | recordCreateRequest.setRecords(recordCreateList); |
| | | wxCpOaWeDocSmartsheetService.recordCreate(recordCreateRequest); |
| | | } |
| | | |
| | | // 编辑记录 |
| | | List<Record> recordEditList = filterRecordMap.getOrDefault("EDIT", Collections.emptyList()); |
| | | if (recordEditList.size() > 0) { |
| | | WxCpRecordEditRequest recordEditRequest = new WxCpRecordEditRequest(); |
| | | recordEditRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID)); |
| | | recordEditRequest.setSheetId(separateProjectSheet.getSheetId()); |
| | | recordEditRequest.setKeyType("CELL_VALUE_KEY_TYPE_FIELD_TITLE"); |
| | | recordEditRequest.setRecords(recordEditList); |
| | | wxCpOaWeDocSmartsheetService.recordEdit(recordEditRequest); |
| | | } |
| | | |
| | | // 删除记录 |
| | | Set<String> taskUserMongoIdSet = taskUserMongoList.stream().map(TaskUserMongo::getId).collect(Collectors.toSet()); |
| | | List<String> delRecordIdList = recordList.stream() |
| | | .filter(record -> !taskUserMongoIdSet.contains(record.getValues().getOrDefault("任务ID", "").toString())) |
| | | .map(t -> t.getRecordId()).collect(Collectors.toList()); |
| | | if (delRecordIdList.size() > 0) { |
| | | wxCpOaWeDocSmartsheetService.recordDelete(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID), separateProjectSheet.getSheetId(), delRecordIdList); |
| | | } |
| | | } |
| | | } catch (WxErrorException wxErrorException) { |
| | | wxErrorException.printStackTrace(); |
| | | sendNotice(Arrays.asList("YueYuHuanXiangQinYuFenDou"), "企微通信异常", String.format("<div class=\"normal\">异常方法:%s</div>" + |
| | | "<div class=\"highlight\">请前往API服务查看LOG。</div>", |
| | | "toWeComSheetPushProjectReport"), Constant.WECOM_MESSAGE_TYPE_TEXTCARD); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } else { |
| | | throw new BadRequestException("企微项目WBS及独立报告参数缺失"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 提醒考勤异常的人员补充考勤 |
| | | */ |
| | | public void remindAttendanceError() { |
| | | // 获取当前日期 |
| | | LocalDate todayDate = LocalDate.now(); |
| | | // 查询相关用户 |
| | | UserQueryCriteria userQueryCriteria = new UserQueryCriteria(); |
| | | userQueryCriteria.setEnabled(true); |
| | | userQueryCriteria.setWeComIdNotNull(true); |
| | | List<User> userList = userRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, userQueryCriteria, criteriaBuilder)); |
| | | |
| | | // 提醒上月的异常考勤(每月前五天) |
| | | if (todayDate.getDayOfMonth() < 6) { |
| | | // 获取上个月的第一天 |
| | | LocalDate firstDayOfLastMonth = todayDate.minusMonths(1).withDayOfMonth(1); |
| | | // 获取上个月的最后一天 |
| | | LocalDate lastDayOfLastMonth = todayDate.withDayOfMonth(1).minusDays(1); |
| | | |
| | | // 异常状态列表 |
| | | List<String> errorStatusList = Arrays.asList(Constant.ATTENDANCE_STATE_WAITFOR, Constant.ATTENDANCE_STATE_NOTSIGNED, Constant.ATTENDANCE_STATE_LACK_OF_TIME, Constant.ATTENDANCE_START_LATE, Constant.ATTENDANCE_START_EARLY); |
| | | |
| | | for (User user : userList) { |
| | | // 查询考勤记录 |
| | | List<Attendance> attendanceList = attendanceRepository.findAllByUserAndDate(user.getId(), firstDayOfLastMonth.toString(), lastDayOfLastMonth.toString()); |
| | | // 过滤异常记录 |
| | | List<Attendance> errorAttendanceList = attendanceList.stream().filter(a -> errorStatusList.contains(a.getStartClockResults()) || errorStatusList.contains(a.getEndClockResults())).collect(Collectors.toList()); |
| | | |
| | | if (errorAttendanceList.size() > 0) { |
| | | // 异常提醒 |
| | | sendNotice(Arrays.asList(user.getWeComId()), "上月考勤异常提醒", String.format("<div class=\"normal\">异常时间:%s</div>" + |
| | | "<div class=\"highlight\">上月考勤异常,请登录PMS系统查看。</div>", |
| | | errorAttendanceList.stream().map(a -> a.getAttendanceDate().toLocalDateTime().toLocalDate().toString()).collect(Collectors.joining(","))), Constant.WECOM_MESSAGE_TYPE_TEXTCARD); |
| | | } |
| | | // 获取上个月内缺勤记录(20250718 TODO:因业务需求,打卡必须闭环,否则会导致工时计算错误) |
| | | List<Attendance> lackOfAttendanceList = attendanceList.stream().filter(a -> (a.getActualWorkStartTime() != null && a.getActualWorkEndTime() == null) || (a.getActualWorkStartTime() == null && a.getActualWorkEndTime() != null)).collect(Collectors.toList()); |
| | | if (lackOfAttendanceList.size() > 0) { |
| | | // 缺卡异常提醒 |
| | | sendNotice(Arrays.asList(user.getWeComId()), "上月考勤缺勤提醒", String.format("<div class=\"normal\">缺勤时间:%s</div>" + |
| | | "<div class=\"highlight\">上月存在缺勤,请登录PMS系统查看。</div>", |
| | | lackOfAttendanceList.stream().map(a -> a.getAttendanceDate().toLocalDateTime().toLocalDate().toString()).collect(Collectors.joining(","))), Constant.WECOM_MESSAGE_TYPE_TEXTCARD); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 提醒缺卡的异常考勤(三天前至昨天) |
| | | // 获取三天前 |
| | | LocalDate threeDayAgo = todayDate.minusDays(3); |
| | | // 获取昨天 |
| | | LocalDate yesterday = todayDate.minusDays(1); |
| | | |
| | | // 异常状态列表 |
| | | List<String> errorStatusList = Arrays.asList(Constant.ATTENDANCE_STATE_NOTSIGNED, Constant.ATTENDANCE_STATE_LACK_OF_TIME); |
| | | |
| | | for (User user : userList) { |
| | | // 查询考勤记录 |
| | | List<Attendance> attendanceList = attendanceRepository.findAllByUserAndDate(user.getId(), threeDayAgo.toString(), yesterday.toString()); |
| | | // 过滤异常记录 |
| | | List<Attendance> errorAttendanceList = attendanceList.stream().filter(a -> errorStatusList.contains(a.getStartClockResults()) || errorStatusList.contains(a.getEndClockResults())).collect(Collectors.toList()); |
| | | |
| | | if (errorAttendanceList.size() > 0) { |
| | | // 异常提醒 |
| | | sendNotice(Arrays.asList(user.getWeComId()), "打卡考勤异常提醒", String.format("<div class=\"normal\">检测到您打卡考勤存在异常,请及时补卡</div>" + |
| | | "<div class=\"normal\">异常时间:%s</div>" + |
| | | "<div class=\"highlight\">打卡考勤异常,请登录PMS系统查看。</div>", |
| | | errorAttendanceList.stream().map(a -> a.getAttendanceDate().toLocalDateTime().toLocalDate().toString()).collect(Collectors.joining(","))), Constant.WECOM_MESSAGE_TYPE_TEXTCARD); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 计算用户所需成本 |
| | | * |
| | | * @param userId |
| | | * @param timeTotalCost |
| | | * @return |
| | | */ |
| | | private BigDecimal calcUserCostByHours(Long userId, Double timeTotalCost) { |
| | | // 工资 |
| | | BigDecimal wageCost = BigDecimal.valueOf(0); |
| | | |
| | | // 通过id获取用户级别工资 |
| | | List<UserLevelWage> sysUserLevelWages = sysUserLevelWageRepository.findUserLevelWageByUserId(userId); |
| | | if (sysUserLevelWages.size() == 0) { |
| | | return BigDecimal.ZERO; |
| | | } |
| | | // 通过id获取用户级别保险 |
| | | List<UserInsurance> sysUserLevelInsurances = sysUserLevelInsuranceRepository.findByUserId(userId); |
| | | if (sysUserLevelInsurances.size() == 0) { |
| | | return BigDecimal.ZERO; |
| | | } |
| | | |
| | | // 工资 |
| | | UserLevelWage sysUserLevelWage = sysUserLevelWages.get(sysUserLevelWages.size() - 1); |
| | | wageCost = wageCost.add(sysUserLevelWage.getBasicWage().add(sysUserLevelWage.getRankWage()).add(sysUserLevelWage.getPerformanceWage()).multiply(BigDecimal.valueOf(timeTotalCost)).divide(BigDecimal.valueOf(160), 2, BigDecimal.ROUND_CEILING)); |
| | | |
| | | // 五险一金 |
| | | UserInsurance sysUserLevelInsurance = sysUserLevelInsurances.get(sysUserLevelInsurances.size() - 1); |
| | | BigDecimal accumulationRadix = sysUserLevelInsurance.getAccumulationFund().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getAccumulationFundCompany() / 100)); |
| | | BigDecimal pensionRadix = sysUserLevelInsurance.getRetirementInsurance().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getRetirementInsuranceCompany() / 100)); |
| | | BigDecimal medicalRadix = sysUserLevelInsurance.getMedicalInsurance().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getMedicalInsuranceCompany() / 100)); |
| | | BigDecimal unemploymentRadix = sysUserLevelInsurance.getUnemploymentInsurance().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getUnemploymentInsuranceCompany() / 100)); |
| | | BigDecimal maternityRadix = sysUserLevelInsurance.getBirthInsurance().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getBirthInsuranceCompany() / 100)); |
| | | BigDecimal industrialInjuryRadix = sysUserLevelInsurance.getEmploymentInsurance().multiply(BigDecimal.valueOf(sysUserLevelInsurance.getEmploymentInsuranceCompany() / 100)); |
| | | |
| | | wageCost = wageCost.add(accumulationRadix.add(pensionRadix).add(medicalRadix).add(unemploymentRadix).add(maternityRadix).add(industrialInjuryRadix).multiply(BigDecimal.valueOf(timeTotalCost)).divide(BigDecimal.valueOf(160), 2, BigDecimal.ROUND_CEILING)); |
| | | |
| | | return wageCost; |
| | | } |
| | | |
| | | /** |
| | | * 判断是否为非工作日 |
| | | * |
| | | * @param date |
| | | * @param holidayConfig |
| | | * @return |
| | | */ |
| | | private boolean isNonWorkingDay(LocalDate date, SysConfigHoliday holidayConfig) { |
| | | boolean isWeekend = date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY; |
| | | if (holidayConfig != null) { |
| | | String dateType = holidayConfig.getDateType(); |
| | | return (isWeekend && !Constant.DATE_TYPE_WEEKDAY.equals(dateType)) || |
| | | Constant.DATE_TYPE_WEEKEND.equals(dateType) || |
| | | Constant.DATE_TYPE_LEGAL_HOLIDAYS.equals(dateType) || |
| | | Constant.DATE_TYPE_HOLIDAYS.equals(dateType); |
| | | } |
| | | return isWeekend; |
| | | } |
| | | |
| | | /** |
| | | * 判断是否为工作日 |
| | | * |
| | | * @param date |
| | | * @param holidayConfig |
| | | * @return |
| | | */ |
| | | private boolean isWorkingDay(LocalDate date, SysConfigHoliday holidayConfig) { |
| | | boolean isWeekend = date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY; |
| | | if (holidayConfig != null) { |
| | | String dateType = holidayConfig.getDateType(); |
| | | return (isWeekend && Constant.DATE_TYPE_WEEKDAY.equals(dateType)) || |
| | | (!isWeekend && !Constant.DATE_TYPE_WEEKEND.equals(dateType) && !Constant.DATE_TYPE_LEGAL_HOLIDAYS.equals(dateType) && !Constant.DATE_TYPE_HOLIDAYS.equals(dateType)); |
| | | } |
| | | return !isWeekend; |
| | | } |
| | | |
| | | /** |
| | | * 查找第一个工作日 |
| | | * |
| | | * @param todayDate |
| | | * @return |
| | | */ |
| | | private DateTime findPreviousHoliday(LocalDate todayDate) { |
| | | int minusDay = 1; |
| | | while (true) { |
| | | LocalDate beforeDate = todayDate.minusDays(minusDay); |
| | | SysConfigHoliday beforeHolidayConfig = sysConfigHolidayRepository.findByHolidayDate(beforeDate.toString()); |
| | | |
| | | if (isNonWorkingDay(beforeDate, beforeHolidayConfig)) { |
| | | return new DateTime(todayDate.minusDays(minusDay - 1)); |
| | | } |
| | | minusDay++; |
| | | } |
| | | } |
| | | } |