| | |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceDto; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.quartz.service.OpaiDingTalkService; |
| | | import me.zhengjie.modules.quartz.service.impl.DingTalkServiceImpl; |
| | | import me.zhengjie.modules.system.domain.*; |
| | | import me.zhengjie.modules.system.repository.DictDetailRepository; |
| | | import me.zhengjie.modules.system.repository.SysConfigHolidayRepository; |
| | |
| | | private final AttendanceRepository attendanceRepository; |
| | | private final AttendanceGoOutRepository attendanceGoOutRepository; |
| | | private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository; |
| | | private final DingTalkServiceImpl dingTalkService; |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(AttendanceLeaveQueryCriteria criteria, Pageable pageable){ |
| | |
| | | // 如果按天为单位请假拼接请假时间的时分秒,取上下班基准时间 |
| | | if(resources.getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_DAY)){ |
| | | //查询用户的排班时间 |
| | | User user = userRepository.getOne(SecurityUtils.getCurrentUserId()); |
| | | User user = userRepository.getOne(resources.getUserId()); |
| | | LeaStartTime = LeaStartTime.substring(0,10) + " " + user.getSysRostering().getWorkStartTime().toString() + ":00"; |
| | | LeaEndTime = LeaEndTime.substring(0,10) + " " + user.getSysRostering().getWorkEndTime().toString() + ":00"; |
| | | } |
| | | // 查询其他状态的表是否有重复 |
| | | repeatValidation(LeaStartTime, LeaEndTime); |
| | | repeatValidation(LeaStartTime, LeaEndTime, resources.getUserId()); |
| | | // 验证请假时间是否冲突 |
| | | List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.checkCreateLeaveTime(LeaStartTime,LeaEndTime, SecurityUtils.getCurrentUserId()); |
| | | List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.checkCreateLeaveTime(LeaStartTime,LeaEndTime, resources.getUserId()); |
| | | if(attendanceLeaveList.size() > 0){ |
| | | AttendanceLeave errTime = attendanceLeaveList.get(0); |
| | | //LocalDateTime转换为Date |
| | |
| | | + "已经存在请假记录,请调整时间"); |
| | | }else { |
| | | // 获取当前登陆人信息,设置为请假发起人 |
| | | User user = userRepository.getOne(SecurityUtils.getCurrentUserId()); |
| | | User user = userRepository.getOne(resources.getUserId()); |
| | | List<String> holiday = new ArrayList<>(), isWork = new ArrayList<>(); |
| | | // 查询节假日 |
| | | List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findAll(); |
| | | for(SysConfigHoliday sysConfigHoliday : sysConfigHolidayList){ |
| | | if(sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)){ |
| | | //工作日 |
| | | isWork.add(sysConfigHoliday.getHolidayDate().toString()); |
| | | isWork.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10)); |
| | | }else{ |
| | | holiday.add(sysConfigHoliday.getHolidayDate().toString()); |
| | | holiday.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10)); |
| | | } |
| | | } |
| | | // 循环添加开始时间到结束时间的每一天 |
| | |
| | | // 如果按天为单位请假拼接请假时间的时分秒,取上下班基准时间 |
| | | if(resources.getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_DAY)){ |
| | | //查询用户的排班时间 |
| | | User user = userRepository.getOne(SecurityUtils.getCurrentUserId()); |
| | | User user = userRepository.getOne(resources.getUserId()); |
| | | LeaStartTime = LeaStartTime.substring(0,10) + " " + user.getSysRostering().getWorkStartTime().toString() + ":00"; |
| | | LeaEndTime = LeaEndTime.substring(0,10) + " " + user.getSysRostering().getWorkEndTime().toString() + ":00"; |
| | | } |
| | | // 查询其他状态的表是否有重复 |
| | | repeatValidation(LeaStartTime, LeaEndTime); |
| | | repeatValidation(LeaStartTime, LeaEndTime, resources.getUserId()); |
| | | // 验证是否存在时间冲突的请假记录 |
| | | Set<Long> ids = new HashSet<>(); |
| | | ids.add(attendanceLeave.getId()); |
| | |
| | | attendanceLeaveRepository.deleteById(id); |
| | | } |
| | | // 获取当前登陆人信息,设置为请假发起人 |
| | | User user = userRepository.getOne(SecurityUtils.getCurrentUserId()); |
| | | User user = userRepository.getOne(resources.getUserId()); |
| | | List<String> holiday = new ArrayList<>(), isWork = new ArrayList<>(); |
| | | // 查询节假日 |
| | | List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findAll(); |
| | | for(SysConfigHoliday sysConfigHoliday : sysConfigHolidayList){ |
| | | if(sysConfigHoliday.getDateType().equals(Constant.DATE_TYPE_WEEKDAY)){ |
| | | //工作日 |
| | | isWork.add(sysConfigHoliday.getHolidayDate().toString()); |
| | | isWork.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10)); |
| | | }else{ |
| | | holiday.add(sysConfigHoliday.getHolidayDate().toString()); |
| | | holiday.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10)); |
| | | } |
| | | } |
| | | // 循环添加开始时间到结束时间的每一天 |
| | |
| | | * 验证其他状态的表是否有重复 |
| | | * @param startTime |
| | | * @param endTime |
| | | * @param userId |
| | | */ |
| | | public void repeatValidation(String startTime, String endTime){ |
| | | public void repeatValidation(String startTime, String endTime, Long userId){ |
| | | // 查询外出表 |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.checkCreateTime(startTime, endTime, SecurityUtils.getCurrentUserId()); |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.checkCreateTime(startTime, endTime, userId); |
| | | if(attendanceGoOutList.size() > 0){ |
| | | AttendanceGoOut errorSysAskForLeave = attendanceGoOutList.get(0); |
| | | SimpleDateFormat errorFormat = new SimpleDateFormat("yyyy年MM月dd日"); |
| | |
| | | + "已经存在外出记录,请调整时间"); |
| | | } |
| | | // 查询出差表 |
| | | List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.checkCreateTime(startTime.substring(0,10),endTime.substring(0,10), SecurityUtils.getCurrentUserId()); |
| | | List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.checkCreateTime(startTime.substring(0,10),endTime.substring(0,10), userId); |
| | | if(attendanceBusinessTravelList.size() > 0){ |
| | | AttendanceBusinessTravel errorSysAskForLeave = attendanceBusinessTravelList.get(0); |
| | | SimpleDateFormat errorFormat = new SimpleDateFormat("yyyy年MM月dd日"); |
| | |
| | | * 获取用户年假剩余时长 |
| | | */ |
| | | @Override |
| | | public Double getYearTimeLength() throws ParseException { |
| | | public Double getYearTimeLength(Long userId) throws ParseException { |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | // 获取当前日期 |
| | | Date date = new Date(); |
| | |
| | | Date dateTime = sdf.parse(nowTime); |
| | | Double surplusYearTime = new Double(0.00); |
| | | // 查询用户剩余年假时长 |
| | | List<SysUserLevelOther> sysUserLevelOtherList = sysUserLevelOtherRepository.findByUserId(SecurityUtils.getCurrentUserId()); |
| | | for(SysUserLevelOther sysUserLevelOther : sysUserLevelOtherList){ |
| | | if(ObjectUtils.isNotEmpty(sysUserLevelOther.getStartDate()) && ObjectUtils.isNotEmpty(sysUserLevelOther.getEndDate())){ |
| | | Date dateStart = new Date(sysUserLevelOther.getStartDate().getTime()); |
| | | Date dateEnd = new Date(sysUserLevelOther.getEndDate().getTime()); |
| | | //取当前日期在数据中开始日期与结束日期之间的数据 |
| | | if(dateTime.compareTo(dateStart) >= 0 && dateTime.compareTo(dateEnd) <= 0){ |
| | | //年假总时长 |
| | | Double yearTime = Double.valueOf(sysUserLevelOther.getAnnualLeaveDays() == null ? 0 : sysUserLevelOther.getAnnualLeaveDays() * 8); |
| | | //已使用年假时长 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | int year = calendar.get(Calendar.YEAR); |
| | | String startTime = year + "-01-01 00:00:00"; |
| | | String endTime = year + "-12-31 23:59:59"; |
| | | Double usedYearTime = attendanceLeaveRepository.getSurplusYearTime(sysUserLevelOther.getUserId(),startTime,endTime); |
| | | //剩余年假 |
| | | surplusYearTime = yearTime - (usedYearTime == null ? 0.0 : usedYearTime); |
| | | } |
| | | List<SysUserLevelOther> sysUserLevelOtherList = sysUserLevelOtherRepository.findByUserId(userId); |
| | | for(SysUserLevelOther sysUserLevelOther : sysUserLevelOtherList) { |
| | | Date dateStart = new Date(sysUserLevelOther.getStartDate().getTime()); |
| | | Date dateEnd = new Date(); |
| | | if (ObjectUtils.isNotEmpty(sysUserLevelOther.getStartDate()) && ObjectUtils.isNotEmpty(sysUserLevelOther.getEndDate())) { |
| | | dateEnd = new Date(sysUserLevelOther.getEndDate().getTime()); |
| | | } |
| | | //取当前日期在数据中开始日期与结束日期之间的数据 |
| | | if (dateTime.compareTo(dateStart) >= 0 && dateTime.compareTo(dateEnd) <= 0 || dateTime.compareTo(dateStart) >= 0 && sysUserLevelOther.getEndDate() == null) { |
| | | //年假总时长 |
| | | Double yearTime = Double.valueOf(sysUserLevelOther.getAnnualLeaveDays() == null ? 0 : sysUserLevelOther.getAnnualLeaveDays() * 8); |
| | | //已使用年假时长 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | int year = calendar.get(Calendar.YEAR); |
| | | String startTime = year + "-01-01 00:00:00"; |
| | | String endTime = year + "-12-31 23:59:59"; |
| | | Double usedYearTime = attendanceLeaveRepository.getSurplusYearTime(sysUserLevelOther.getUserId(), startTime, endTime); |
| | | //剩余年假 |
| | | surplusYearTime = yearTime - (usedYearTime == null ? 0.0 : usedYearTime); |
| | | } |
| | | } |
| | | return surplusYearTime; |
| | |
| | | * @param resources / |
| | | */ |
| | | @Override |
| | | public void updateApprove(AttendanceLeave resources) { |
| | | public void updateApprove(AttendanceLeave resources) throws Exception { |
| | | AttendanceLeave attendanceLeave = attendanceLeaveRepository.findById(resources.getId()).orElseGet(AttendanceLeave::new); |
| | | ValidationUtil.isNull( attendanceLeave.getId(),"AttendanceLeave","id",resources.getId()); |
| | | attendanceLeave.copy(resources); |
| | | //审批通过直接改考勤记录的状态 |
| | | if(resources.getApprovalStatus().equals(Constant.APPROVAL_STATUS_PASSED)){ |
| | | // 查询考勤记录是否存在 |
| | | Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(resources.getUserId(),resources.getLeaveStartTime().toLocalDateTime().toString().substring(0,10)); |
| | | if(ObjectUtils.isNotEmpty(attendance)){ |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_LEAVE); |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_LEAVE); |
| | | attendanceRepository.save(attendance); |
| | | } |
| | | } |
| | | attendanceLeaveRepository.save(attendanceLeave); |
| | | // 调用定时任务修改考勤记录 |
| | | List<User> userList = new ArrayList<>(); |
| | | if(ObjectUtils.isNotEmpty(attendanceLeave.getUserId())){ |
| | | User user = userRepository.findById(attendanceLeave.getUserId()).orElseGet(User::new); |
| | | userList.add(user); |
| | | } |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String attendanceDate = df.format(attendanceLeave.getLeaveStartTime()); |
| | | dingTalkService.getDingTalkAttendanceListOfNoonOrNight(attendanceDate,userList); |
| | | } |
| | | |
| | | @Override |
| | |
| | | public void download(List<AttendanceLeaveDto> all, HttpServletResponse response) throws IOException { |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (AttendanceLeaveDto attendanceLeave : all) { |
| | | String leavrType = attendanceLeave.getLeaveType() != null ? dictDetailRepository.findByDictNameAndValue(Constant.LEAVE_TYPE, attendanceLeave.getLeaveType()).getLabel() : ""; |
| | | String leaveStatus = attendanceLeave.getApprovalStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.APPROVAL_STATUS, attendanceLeave.getApprovalStatus()).getLabel() : ""; |
| | | Map<String,Object> map = new LinkedHashMap<>(); |
| | | map.put("用户ID", attendanceLeave.getUserId()); |
| | | map.put("审批用户ID", attendanceLeave.getApprovalUserId()); |
| | | map.put("请假类型", attendanceLeave.getLeaveType()); |
| | | map.put("请假类型", leavrType); |
| | | map.put("请假开始时间", attendanceLeave.getLeaveStartTime()); |
| | | map.put("请假结束时间", attendanceLeave.getLeaveEndTime()); |
| | | map.put("请假时长", attendanceLeave.getLeaveDuration()); |
| | | map.put("请假原因", attendanceLeave.getLeaveReason()); |
| | | map.put("审批状态", attendanceLeave.getApprovalStatus()); |
| | | map.put("审批状态", leaveStatus); |
| | | map.put("审批说明", attendanceLeave.getApprovalDescription()); |
| | | map.put("备注", attendanceLeave.getRemarks()); |
| | | map.put("创建者", attendanceLeave.getCreateBy()); |