| | |
| | | |
| | | import me.zhengjie.exception.BadRequestException; |
| | | 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.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 java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.io.IOException; |
| | | import javax.servlet.http.HttpServletResponse; |
| | |
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository; |
| | | private final AttendanceService attendanceService; |
| | | private final AttendanceRepository attendanceRepository; |
| | | private final AttendanceLeaveRepository attendanceLeaveRepository; |
| | | private final AttendanceGoOutRepository attendanceGoOutRepository; |
| | | private final DictDetailRepository dictDetailRepository; |
| | | private final DingTalkServiceImpl dingTalkService; |
| | | |
| | | @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() == null ? SecurityUtils.getCurrentUserId() : 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()); |
| | | 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()); |
| | | }else{ |
| | | holiday.add(sysConfigHoliday.getHolidayDate().toString()); |
| | | } |
| | | } |
| | | 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().substring(0,10)); |
| | | // }else{ |
| | | // holiday.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10)); |
| | | // } |
| | | // } |
| | | // 循环添加开始时间到结束时间的每一天 |
| | | List<String> dateList = attendanceLeaveService.getBetweenDate(resources.getTravelStartTime().toLocalDateTime().toString(),resources.getTravelEndTime().toLocalDateTime().toString()); |
| | | int i = 0; |
| | | for(String date : dateList){ |
| | | LocalDate localDate = LocalDate.parse(date); |
| | | Boolean isWeekend = localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY; |
| | | // 不是周末并且节假日表中不存在在创建 |
| | | if((!isWeekend && !holiday.contains(date)) || (isWeekend && isWork.contains(date))){ |
| | | // LocalDate localDate = LocalDate.parse(date); |
| | | // Boolean isWeekend = localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY; |
| | | // // 不是周末并且节假日表中不存在在创建 |
| | | // if((!isWeekend && !holiday.contains(date)) || (isWeekend && isWork.contains(date))){ |
| | | AttendanceBusinessTravel attendanceBusinessTravel = getAttendanceBuss(resources,date,user,i,bussStartTime,bussEndTime,null); |
| | | i++; |
| | | attendanceBusinessTravelRepository.save(attendanceBusinessTravel); |
| | | } |
| | | // } |
| | | } |
| | | //发送钉钉给审批人 |
| | | List<String> sendList = new ArrayList<>(); |
| | |
| | | |
| | | //获取当前登入人信息 |
| | | 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()); |
| | | 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()); |
| | | }else{ |
| | | holiday.add(sysConfigHoliday.getHolidayDate().toString()); |
| | | } |
| | | } |
| | | 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().substring(0,10)); |
| | | // }else{ |
| | | // holiday.add(sysConfigHoliday.getHolidayDate().toString().substring(0,10)); |
| | | // } |
| | | // } |
| | | // 循环添加开始时间到结束时间的每一天 |
| | | List<String> dateList = attendanceLeaveService.getBetweenDate(resources.getTravelStartTime().toLocalDateTime().toString(),resources.getTravelEndTime().toLocalDateTime().toString()); |
| | | int i = 0; |
| | | for(String date : dateList){ |
| | | LocalDate localDate = LocalDate.parse(date); |
| | | Boolean isWeekend = localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY; |
| | | // 不是周末并且节假日表中不存在在创建 |
| | | if((!isWeekend && !holiday.contains(date)) || (isWeekend && isWork.contains(date))){ |
| | | // LocalDate localDate = LocalDate.parse(date); |
| | | // Boolean isWeekend = localDate.getDayOfWeek() == DayOfWeek.SATURDAY || localDate.getDayOfWeek() == DayOfWeek.SUNDAY; |
| | | // // 不是周末并且节假日表中不存在在创建 |
| | | // if((!isWeekend && !holiday.contains(date)) || (isWeekend && isWork.contains(date))){ |
| | | AttendanceBusinessTravel attendanceBusinessTravel1 = getAttendanceBuss(resources,date,user,i,bussStartTime,bussEndTime,resUserId); |
| | | i++; |
| | | attendanceBusinessTravelRepository.save(attendanceBusinessTravel1); |
| | | } |
| | | // } |
| | | } |
| | | } |
| | | } |
| | |
| | | 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("只能删除自己的记录"); |
| | | } |
| | |
| | | public void download(List<AttendanceBusinessTravelDto> all, HttpServletResponse response) throws IOException { |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (AttendanceBusinessTravelDto attendanceBusinessTravel : all) { |
| | | String bussDurationUnit = attendanceBusinessTravel.getDurationUnit() != null ? dictDetailRepository.findByDictNameAndValue(Constant.CARD_APPROVE_STATUS, attendanceBusinessTravel.getDurationUnit()).getLabel() : ""; |
| | | String bussStatus = attendanceBusinessTravel.getApprovalStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.BUSSINESS_APPROVE_STATUS, attendanceBusinessTravel.getApprovalStatus()).getLabel() : ""; |
| | | Map<String,Object> map = new LinkedHashMap<>(); |
| | | map.put("用户id", attendanceBusinessTravel.getUserId()); |
| | | map.put("审批用户id", attendanceBusinessTravel.getApprovalUserId()); |
| | | map.put("出差开始时间", attendanceBusinessTravel.getTravelStartTime()); |
| | | map.put("出差结束时间", attendanceBusinessTravel.getTravelEndTime()); |
| | | map.put("出差时长", attendanceBusinessTravel.getTravelDuration()); |
| | | map.put("时长单位", attendanceBusinessTravel.getDurationUnit()); |
| | | map.put("时长单位", bussDurationUnit); |
| | | map.put("出差原因", attendanceBusinessTravel.getTravelReason()); |
| | | map.put("出发城市", attendanceBusinessTravel.getDepartureCity()); |
| | | map.put("到达城市", attendanceBusinessTravel.getArrivalCity()); |
| | | map.put("审批状态", attendanceBusinessTravel.getApprovalStatus()); |
| | | map.put("审批状态", bussStatus); |
| | | map.put("审批说明", attendanceBusinessTravel.getApprovalDescription()); |
| | | map.put("备注", attendanceBusinessTravel.getRemarks()); |
| | | map.put("创建者", attendanceBusinessTravel.getCreateBy()); |
| | |
| | | calculate.setStart(attendanceBusinessTravel.getTravelStartTime().toLocalDateTime()); |
| | | calculate.setEnd(attendanceBusinessTravel.getTravelEndTime().toLocalDateTime()); |
| | | Double result = new Double(0.00); |
| | | Integer days = attendanceService.calculateDays(calculate); |
| | | Long days = ChronoUnit.DAYS.between(calculate.getStart().toLocalDate(), calculate.getEnd().toLocalDate()) + 1; |
| | | result = Double.valueOf(new BigDecimal(days).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 审核功能 |
| | | * 审核/撤销功能 |
| | | * @param resources / |
| | | */ |
| | | @Override |
| | | public void updateApprove(AttendanceBusinessTravel resources) { |
| | | public void updateApprove(AttendanceBusinessTravel resources) throws Exception { |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 审核撤销 |
| | | * @param resources |
| | | */ |
| | | @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); |
| | | // 调用定时任务修改考勤记录 |
| | | List<User> userList = new ArrayList<>(); |
| | | if(ObjectUtils.isNotEmpty(attendanceBusinessTravel.getUserId())){ |
| | | User user = userRepository.findById(attendanceBusinessTravel.getUserId()).orElseGet(User::new); |
| | | userList.add(user); |
| | | } |
| | | attendanceBusinessTravelRepository.save(attendanceBusinessTravel); |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String attendanceDate = df.format(attendanceBusinessTravel.getTravelStartTime()); |
| | | dingTalkService.getDingTalkAttendanceListOfNoonOrNight(attendanceDate,userList); |
| | | } |
| | | } |