| | |
| | | package me.zhengjie.modules.attendance.service.impl; |
| | | |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.attendance.domain.AttendanceBusinessTravel; |
| | | import me.zhengjie.modules.attendance.domain.AttendanceGoOut; |
| | | import me.zhengjie.modules.attendance.domain.AttendanceLeave; |
| | | import me.zhengjie.modules.attendance.domain.Calculate; |
| | | import me.zhengjie.modules.attendance.domain.*; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceGoOutRepository; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceLeaveRepository; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceRepository; |
| | | import me.zhengjie.modules.attendance.service.AttendanceService; |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceGoOutDto; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.quartz.service.OpaiDingTalkService; |
| | | import me.zhengjie.modules.system.domain.Job; |
| | | import me.zhengjie.modules.system.domain.Role; |
| | | import me.zhengjie.modules.system.domain.SysConfigHoliday; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import me.zhengjie.modules.system.repository.SysConfigHolidayRepository; |
| | |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceBusinessTravelDto; |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceBusinessTravelQueryCriteria; |
| | | import me.zhengjie.modules.attendance.service.mapstruct.AttendanceBusinessTravelMapper; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.data.domain.Page; |
| | |
| | | private final AttendanceLeaveServiceImpl attendanceLeaveService; |
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository; |
| | | private final AttendanceService attendanceService; |
| | | private final AttendanceRepository attendanceRepository; |
| | | private final AttendanceLeaveRepository attendanceLeaveRepository; |
| | | private final AttendanceGoOutRepository attendanceGoOutRepository; |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(AttendanceBusinessTravelQueryCriteria criteria, Pageable pageable){ |
| | |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String bussStartTime = df.format(resources.getTravelStartTime()); |
| | | String bussEndTime = df.format(resources.getTravelEndTime()); |
| | | // 验证请假时间是否冲突 |
| | | List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.checkCreateTime(bussStartTime,bussEndTime, SecurityUtils.getCurrentUserId()); |
| | | // 查询其他状态的表是否有重复 |
| | | repeatValidation(bussStartTime, bussEndTime, resources.getUserId()); |
| | | // 验证出差时间是否冲突 |
| | | List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.checkCreateTime(bussStartTime,bussEndTime, resources.getUserId()); |
| | | if(attendanceBusinessTravelList.size() > 0){ |
| | | AttendanceBusinessTravel errorSysAskForLeave = attendanceBusinessTravelList.get(0); |
| | | SimpleDateFormat errorFormat = new SimpleDateFormat("yyyy年MM月dd日"); |
| | |
| | | + "已经存在出差记录,请调整时间"); |
| | | }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(); |
| | |
| | | //查询审批者信息 |
| | | User appUser = userRepository.getOne(resources.getApprovalUserId()); |
| | | sendList.add(appUser.getDingding()); |
| | | opaiDingTalkService.sendNotice(sendList, "审批提醒", "### 审批提示 \n >" + user.getNickName() + " 提交了请假审批,请登录PMS系统处理", "card"); |
| | | opaiDingTalkService.sendNotice(sendList, "审批提醒", "### 审批提示 \n >" + user.getNickName() + " 提交了出差审批,请登录PMS系统处理", "card"); |
| | | } |
| | | return attendanceBusinessTravelMapper.toDto(resources); |
| | | } |
| | |
| | | |
| | | //获取当前登入人信息 |
| | | User user1 = userRepository.getOne(SecurityUtils.getCurrentUserId()); |
| | | Job job = user1.getJobs().iterator().next(); |
| | | Role role = user1.getRoles().iterator().next(); |
| | | //除超管、总经理只能修改自己信息 |
| | | if(!job.getId().equals(Constant.ROLE_LEVEL_SUPER) || !job.getId().equals(Constant.ROLE_LEVEL_GENERAL)){ |
| | | if(role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL){ |
| | | if (!Long.valueOf(resources.getUserId()).equals(SecurityUtils.getCurrentUserId())){ |
| | | throw new BadRequestException("只能修改自己的记录"); |
| | | } |
| | |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String bussStartTime = df.format(resources.getTravelStartTime()); |
| | | String bussEndTime = df.format(resources.getTravelEndTime()); |
| | | // 查询其他状态的表是否有重复 |
| | | repeatValidation(bussStartTime, bussEndTime, resources.getUserId()); |
| | | // 验证是否存在时间冲突的请假记录 |
| | | Set<Long> ids = new HashSet<>(); |
| | | ids.add(attendanceBusinessTravel.getId()); |
| | |
| | | attendanceBusinessTravelRepository.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(); |
| | |
| | | return attendanceBusinessTravel; |
| | | } |
| | | |
| | | /** |
| | | * 验证其他状态的表是否有重复 |
| | | * @param buStartTime |
| | | * @param buEndTime |
| | | */ |
| | | public void repeatValidation(String buStartTime, String buEndTime, Long userId){ |
| | | //查询用户的排班时间 |
| | | User user = userRepository.getOne(userId); |
| | | buStartTime = buStartTime.substring(0,10) + " " + user.getSysRostering().getWorkStartTime().toString() + ":00"; |
| | | buEndTime = buEndTime.substring(0,10) + " " + user.getSysRostering().getWorkEndTime().toString() + ":00"; |
| | | // 查询请假表(时单位) |
| | | List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.checkCreateLeaveTime(buStartTime,buEndTime, userId); |
| | | if(attendanceLeaveList.size() > 0){ |
| | | AttendanceLeave errorSysAskForLeave = attendanceLeaveList.get(0); |
| | | SimpleDateFormat errorFormat = new SimpleDateFormat("yyyy年MM月dd日"); |
| | | throw new BadRequestException("请假时间冲突," + errorFormat.format(errorSysAskForLeave.getLeaveStartTime()) + "至" + errorFormat.format(errorSysAskForLeave.getLeaveEndTime()) |
| | | + "已经存在请假记录,请调整时间"); |
| | | } |
| | | // 查询外出表 |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.checkCreateTime(buStartTime, buEndTime, userId); |
| | | if(attendanceGoOutList.size() > 0){ |
| | | AttendanceGoOut errorSysAskForLeave = attendanceGoOutList.get(0); |
| | | SimpleDateFormat errorFormat = new SimpleDateFormat("yyyy年MM月dd日"); |
| | | throw new BadRequestException("外出时间冲突," + errorFormat.format(errorSysAskForLeave.getOutStartTime()) + "至" + errorFormat.format(errorSysAskForLeave.getOutEndTime()) |
| | | + "已经存在外出记录,请调整时间"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void deleteAll(Long[] ids) { |
| | | for (Long id : ids) { |
| | |
| | | |
| | | //获取当前登入人信息 |
| | | User user = userRepository.getOne(SecurityUtils.getCurrentUserId()); |
| | | Job job = user.getJobs().iterator().next(); |
| | | Role role = user.getRoles().iterator().next(); |
| | | //除超管、总经理只能删除自己信息 |
| | | if(!job.getId().equals(Constant.ROLE_LEVEL_SUPER) || !job.getId().equals(Constant.ROLE_LEVEL_GENERAL)){ |
| | | if(role.getId() != Constant.ROLE_LEVEL_SUPER && role.getId() != Constant.ROLE_LEVEL_GENERAL){ |
| | | if (!Long.valueOf(attendanceBusinessTravel.get().getUserId()).equals(SecurityUtils.getCurrentUserId())){ |
| | | throw new BadRequestException("只能删除自己的记录"); |
| | | } |
| | |
| | | AttendanceBusinessTravel attendanceBusinessTravel = attendanceBusinessTravelRepository.findById(resources.getId()).orElseGet(AttendanceBusinessTravel::new); |
| | | ValidationUtil.isNull( attendanceBusinessTravel.getId(),"AttendanceBusinessTravel","id",resources.getId()); |
| | | attendanceBusinessTravel.copy(resources); |
| | | //审批通过直接改考勤记录的状态 |
| | | if(resources.getApprovalStatus().equals(Constant.BUSSINESS_APPROVE_STATUS_AGREE)){ |
| | | // 查询考勤记录是否存在 |
| | | Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(resources.getUserId(),resources.getTravelStartTime().toLocalDateTime().toString().substring(0,10)); |
| | | if(ObjectUtils.isNotEmpty(attendance)){ |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_BUSINESS); |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_BUSINESS); |
| | | attendanceRepository.save(attendance); |
| | | } |
| | | } |
| | | attendanceBusinessTravelRepository.save(attendanceBusinessTravel); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void updateRevoke(AttendanceBusinessTravel resources) { |
| | | |
| | | AttendanceBusinessTravel attendanceBusinessTravel = attendanceBusinessTravelRepository.findById(resources.getId()).orElseGet(AttendanceBusinessTravel::new); |
| | | ValidationUtil.isNull( attendanceBusinessTravel.getId(),"AttendanceBusinessTravel","id",resources.getId()); |
| | | attendanceBusinessTravel.copy(resources); |
| | | attendanceBusinessTravel.setApprovalStatus(Constant.BUSSINESS_APPROVE_STATUS_REVIEWED); |
| | | // 查询考勤记录是否存在,修改状态为等待 |
| | | Attendance attendance = attendanceRepository.findAllByUserIdAndAttendanceDate(resources.getUserId(),resources.getTravelStartTime().toLocalDateTime().toString().substring(0,10)); |
| | | if(ObjectUtils.isNotEmpty(attendance)){ |
| | | attendance.setStartClockResults(Constant.ATTENDANCE_STATE_WAITFOR); |
| | | attendance.setEndClockResults(Constant.ATTENDANCE_STATE_WAITFOR); |
| | | attendanceRepository.save(attendance); |
| | | } |
| | | attendanceBusinessTravelRepository.save(attendanceBusinessTravel); |
| | | } |
| | | } |