| | |
| | | package me.zhengjie.modules.attendance.service.impl; |
| | | |
| | | import me.zhengjie.exception.BadRequestException; |
| | | 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.AttendanceBusinessTravelRepository; |
| | | 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.AttendanceLeaveDto; |
| | | 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.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.DictDetailRepository; |
| | | import me.zhengjie.modules.system.repository.SysConfigHolidayRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import me.zhengjie.utils.*; |
| | |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceGoOutDto; |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceGoOutQueryCriteria; |
| | | import me.zhengjie.modules.attendance.service.mapstruct.AttendanceGoOutMapper; |
| | | 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 SysConfigHolidayRepository sysConfigHolidayRepository; |
| | | private final AttendanceLeaveServiceImpl attendanceLeaveService; |
| | | private final OpaiDingTalkService opaiDingTalkService; |
| | | private final AttendanceRepository attendanceRepository; |
| | | private final AttendanceLeaveRepository attendanceLeaveRepository; |
| | | private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository; |
| | | private final DictDetailRepository dictDetailRepository; |
| | | private final DingTalkServiceImpl dingTalkService; |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(AttendanceGoOutQueryCriteria criteria, Pageable pageable){ |
| | |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String goStartTime = df.format(resources.getOutStartTime()); |
| | | String goEndTime = df.format(resources.getOutEndTime()); |
| | | // 查询其他状态的表是否有重复 |
| | | repeatValidation(goStartTime, goEndTime, resources.getUserId() == null ? SecurityUtils.getCurrentUserId() : resources.getUserId()); |
| | | // 验证请假时间是否冲突 |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.checkCreateTime(goStartTime, goEndTime, SecurityUtils.getCurrentUserId()); |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.checkCreateTime(goStartTime, goEndTime, resources.getUserId()); |
| | | if(attendanceGoOutList.size() > 0){ |
| | | AttendanceGoOut errTime = attendanceGoOutList.get(0); |
| | | //LocalDateTime转换为Date |
| | |
| | | + "已经存在外出记录,请调整时间"); |
| | | }else { |
| | | // 获取当前登陆人信息,设置为请假发起人 |
| | | User user = userRepository.getOne(SecurityUtils.getCurrentUserId()); |
| | | User user = userRepository.getOne(resources.getUserId() == null ? SecurityUtils.getCurrentUserId() : 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)); |
| | | } |
| | | } |
| | | // 循环添加开始时间到结束时间的每一天 |
| | |
| | | //查询审批者信息 |
| | | 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 attendanceGoOutMapper.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 goStartTime = df.format(resources.getOutStartTime()); |
| | | String goEndTime = df.format(resources.getOutEndTime()); |
| | | // 查询其他状态的表是否有重复 |
| | | repeatValidation(goStartTime, goEndTime, resources.getUserId()); |
| | | // 验证是否存在时间冲突的请假记录 |
| | | Set<Long> ids = new HashSet<>(); |
| | | ids.add(attendanceGoOut.getId()); |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.checkCreateUpdateTime(goStartTime, goEndTime, SecurityUtils.getCurrentUserId(), ids); |
| | | List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.checkCreateUpdateTime(goStartTime, goEndTime, resources.getUserId(), ids); |
| | | if(attendanceGoOutList.size() > 0){ |
| | | AttendanceGoOut errorSysAskForLeave = attendanceGoOutList.get(0); |
| | | SimpleDateFormat errorFormat = new SimpleDateFormat("yyyy年MM月dd日"); |
| | |
| | | attendanceGoOutRepository.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)); |
| | | } |
| | | } |
| | | // 循环添加开始时间到结束时间的每一天 |
| | |
| | | return attendanceGoOut; |
| | | } |
| | | |
| | | /** |
| | | * 验证其他状态的表是否有重复 |
| | | * @param goStartTime |
| | | * @param goEndTime |
| | | */ |
| | | public void repeatValidation(String goStartTime, String goEndTime, Long userId){ |
| | | // 查询请假表(时单位) |
| | | List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.checkCreateLeaveTime(goStartTime,goEndTime, 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<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.checkCreateTime(goStartTime.substring(0,10),goEndTime.substring(0,10), userId); |
| | | if(attendanceBusinessTravelList.size() > 0){ |
| | | AttendanceBusinessTravel errorSysAskForLeave = attendanceBusinessTravelList.get(0); |
| | | SimpleDateFormat errorFormat = new SimpleDateFormat("yyyy年MM月dd日"); |
| | | throw new BadRequestException("出差时间冲突," + errorFormat.format(errorSysAskForLeave.getTravelStartTime()) + "至" + errorFormat.format(errorSysAskForLeave.getTravelEndTime()) |
| | | + "已经存在出差记录,请调整时间"); |
| | | } |
| | | } |
| | | |
| | | @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(attendanceGoOut.get().getUserId()).equals(SecurityUtils.getCurrentUserId())){ |
| | | throw new BadRequestException("只能删除自己的记录"); |
| | | } |
| | |
| | | public void download(List<AttendanceGoOutDto> all, HttpServletResponse response) throws IOException { |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (AttendanceGoOutDto attendanceGoOut : all) { |
| | | String outOfOfficeType = attendanceGoOut.getOutOfOfficeType() != null ? dictDetailRepository.findByDictNameAndValue(Constant.GOOUT_APPROVE_STATUS, attendanceGoOut.getOutOfOfficeType()).getLabel() : ""; |
| | | String outDurationUnit = attendanceGoOut.getDurationUnit() != null ? dictDetailRepository.findByDictNameAndValue(Constant.LEAVE_TIME_TYPE, attendanceGoOut.getDurationUnit()).getLabel() : ""; |
| | | Map<String,Object> map = new LinkedHashMap<>(); |
| | | map.put("用户id", attendanceGoOut.getUserId()); |
| | | map.put("审批用户id", attendanceGoOut.getApprovalUserId()); |
| | | map.put("外出开始时间", attendanceGoOut.getOutStartTime()); |
| | | map.put("外出结束时间", attendanceGoOut.getOutEndTime()); |
| | | map.put("外出时长", attendanceGoOut.getOutDuration()); |
| | | map.put("时长单位", attendanceGoOut.getDurationUnit()); |
| | | map.put("外出类型", attendanceGoOut.getOutOfOfficeType()); |
| | | map.put("时长单位", outDurationUnit); |
| | | map.put("外出类型", outOfOfficeType); |
| | | map.put("外出原因", attendanceGoOut.getOutReason()); |
| | | map.put("审批状态", attendanceGoOut.getApprovalStatus()); |
| | | map.put("审批说明", attendanceGoOut.getApprovalDescription()); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 审核功能 |
| | | * 审核/撤销功能 |
| | | * @param resources / |
| | | */ |
| | | @Override |
| | | public void updateApprove(AttendanceGoOut resources) { |
| | | public void updateApprove(AttendanceGoOut resources) throws Exception { |
| | | AttendanceGoOut attendanceGoOut = attendanceGoOutRepository.findById(resources.getId()).orElseGet(AttendanceGoOut::new); |
| | | ValidationUtil.isNull( attendanceGoOut.getId(),"AttendanceGoOut","id",resources.getId()); |
| | | attendanceGoOut.copy(resources); |
| | | attendanceGoOutRepository.save(attendanceGoOut); |
| | | // 调用定时任务修改考勤记录 |
| | | List<User> userList = new ArrayList<>(); |
| | | if(ObjectUtils.isNotEmpty(attendanceGoOut.getUserId())){ |
| | | User user = userRepository.findById(attendanceGoOut.getUserId()).orElseGet(User::new); |
| | | userList.add(user); |
| | | } |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String attendanceDate = df.format(attendanceGoOut.getOutStartTime()); |
| | | dingTalkService.getDingTalkAttendanceListOfNoonOrNight(attendanceDate,userList); |
| | | } |
| | | } |