| | |
| | | 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.treatment.repository.UserLevelWageRepository; |
| | | import me.zhengjie.utils.QueryHelp; |
| | | import me.zhengjie.utils.StringUtils; |
| | | import me.zhengjie.weixin.cp.api.WxCpOaWeDocSmartsheetService; |
| | | import me.zhengjie.weixin.cp.bean.smartsheet.field.*; |
| | | import me.zhengjie.weixin.cp.bean.smartsheet.record.*; |
| | | import me.zhengjie.weixin.cp.bean.smartsheet.sheet.*; |
| | | 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; |
| | |
| | | // 获取企业微信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; |
| | | // 获取企业微信考勤白名单 |
| | |
| | | // 遍历用户列表 |
| | | for (User user : userList) { |
| | | // 考勤记录:根据用户和日期查询 |
| | | Attendance 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) || attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND)) { |
| | | isHoliday = true; |
| | |
| | | // 企业微信ID |
| | | List<String> userWeComList = new ArrayList<>(); |
| | | userWeComList.add(user.getWeComId()); |
| | | System.out.println("开始查询用户" + user.getWeComId() + "的" + strAttendDate + "考勤记录"); |
| | | System.out.println("开始查询用户" + user.getWeComId() + "的" + startAttendDate + "考勤记录"); |
| | | try { |
| | | // 企微打卡数据 |
| | | List<WxCpCheckinData> weComRecordResultList = wxCpService.getOaService().getCheckinData(1, sdf.parse(strAttendDate + " 00:00:00"), sdf.parse(strAttendDate + " 23:59:59"), userWeComList); |
| | | // 企微打卡数据 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) { |
| | | // 无打卡记录 |
| | |
| | | // 早打卡 |
| | | // 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(), strAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOON, attendance); |
| | | cardDatetimeSupplement(attendance.getUserId(), startAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOON, attendance); |
| | | } |
| | | 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))); |
| | | 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); |
| | | } |
| | |
| | | // 晚打卡 |
| | | // 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(), strAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOOFF, attendance); |
| | | 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))); |
| | | 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); |
| | | } |
| | |
| | | } |
| | | } 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); |
| | | } |
| | | } |
| | | |
| | |
| | | // 日期格式化 |
| | | 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; |
| | | // 获取企业微信考勤白名单 |
| | |
| | | // 遍历用户列表 |
| | | for (User user : userList) { |
| | | // 考勤记录:根据用户和日期查询 |
| | | Attendance 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) || attendance.getDateType().equals(Constant.DATE_TYPE_WEEKEND)) { |
| | | isHoliday = true; |
| | |
| | | // 企业微信ID |
| | | List<String> userWeComList = new ArrayList<>(); |
| | | userWeComList.add(user.getWeComId()); |
| | | System.out.println("开始查询用户" + user.getWeComId() + "的" + strAttendDate + "考勤记录"); |
| | | System.out.println("开始查询用户" + user.getWeComId() + "的" + startAttendDate + "考勤记录"); |
| | | try { |
| | | // 企微打卡数据 |
| | | List<WxCpCheckinData> weComRecordResultList = wxCpService.getOaService().getCheckinData(1, sdf.parse(strAttendDate + " 00:00:00"), sdf.parse(strAttendDate + " 23:59:59"), userWeComList); |
| | | // 企微打卡数据 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) { |
| | | // 无打卡记录 |
| | |
| | | // 早打卡 |
| | | // 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(), strAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOON, attendance); |
| | | cardDatetimeSupplement(attendance.getUserId(), startAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOON, attendance); |
| | | } |
| | | 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))); |
| | | 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); |
| | | } |
| | |
| | | // 晚打卡 |
| | | // 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(), strAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOOFF, attendance); |
| | | 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))); |
| | | 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); |
| | | } |
| | |
| | | } |
| | | } 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); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | //调用方法修改考勤打卡状态 |
| | | updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_LEAVE, day, leaveStartDuration, 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); |
| | | } |
| | | } |
| | | |
| | | // // 查询考勤请假表 |
| | |
| | | } else { |
| | | // 上午 |
| | | if (day) { |
| | | // 上午时长 >= 上午排班时间 改打卡状态 否则 缺时 |
| | | if (duration >= result) { |
| | | // 上午时长 >= 上午排班时间 改打卡状态 否则 缺时 TODO:20250805修改 排除休息日情况 |
| | | if (duration >= result || attendance.getStartLocationResults().equals(Constant.LOCATION_RESULTS_REST)) { |
| | | 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.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.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.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; |
| | | } |
| | | } |
| | |
| | | */ |
| | | 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.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.setEndClockResults(type); |
| | | attendance.setEndLocationResults(null); |
| | | } else { |
| | |
| | | */ |
| | | 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.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.setEndClockResults(type); |
| | | attendance.setEndLocationResults(null); |
| | | } else { |
| | |
| | | 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)) { |
| | | // 发送消息 |
| | | WxCpDefaultConfigImpl wxCpDefaultConfig = new WxCpDefaultConfigImpl(); |
| | | wxCpDefaultConfig.setWebhookKey(robotParamMap.get(Constant.REMIND_REPORT_WEBHOOK_KEY)); |
| | | wxCpService.setWxCpConfigStorage(wxCpDefaultConfig); |
| | | wxCpService.getGroupRobotService().sendText(robotParamMap.get(Constant.REMIND_REPORT_MSG), Arrays.asList("@all"), Arrays.asList()); |
| | | } |
| | | } catch (WxErrorException wxErrorException) { |
| | | wxErrorException.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | |
| | | 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)) { |
| | | // 发送周报生成成功消息 |
| | | WxCpDefaultConfigImpl wxCpDefaultConfig = new WxCpDefaultConfigImpl(); |
| | | wxCpDefaultConfig.setWebhookKey(robotParamMap.get(Constant.REMIND_REPORT_WEBHOOK_KEY)); |
| | | wxCpService.setWxCpConfigStorage(wxCpDefaultConfig); |
| | | wxCpService.getGroupRobotService().sendText(robotParamMap.get(Constant.REMIND_REPORT_SUCCESS_MSG), Arrays.asList("@all"), Arrays.asList()); |
| | | } |
| | | } catch (WxErrorException wxErrorException) { |
| | | wxErrorException.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | // 制作项目周报数据 |
| | | 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); |
| | |
| | | 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()); |
| | |
| | | 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("项目周报子表不存在"); |
| | |
| | | } |
| | | } 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(); |
| | | } |
| | |
| | | } |
| | | } 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(); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 提醒考勤异常的人员补充考勤 |
| | | */ |
| | | 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 |