| | |
| | | */ |
| | | package me.zhengjie.modules.attendance.service.impl; |
| | | |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.attendance.domain.*; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceBusinessTravelRepository; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceGoOutRepository; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceRepository; |
| | | import me.zhengjie.modules.attendance.repository.*; |
| | | import me.zhengjie.modules.attendance.service.AttendanceLeaveService; |
| | | import me.zhengjie.modules.attendance.service.AttendanceService; |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceDto; |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceLeaveDto; |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceLeaveQueryCriteria; |
| | | import me.zhengjie.modules.attendance.service.mapstruct.AttendanceLeaveMapper; |
| | | 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.repository.SysUserLevelOtherRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import me.zhengjie.utils.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceLeaveRepository; |
| | | import me.zhengjie.modules.attendance.service.AttendanceLeaveService; |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceLeaveDto; |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceLeaveQueryCriteria; |
| | | import me.zhengjie.modules.attendance.service.mapstruct.AttendanceLeaveMapper; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.text.ParseException; |
| | |
| | | import java.time.*; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.io.IOException; |
| | | import java.util.function.Function; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | /** |
| | | * @website https://eladmin.vip |
| | |
| | | private final AttendanceRepository attendanceRepository; |
| | | private final AttendanceGoOutRepository attendanceGoOutRepository; |
| | | private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository; |
| | | private final AttendanceOvertimeRepository attendanceOvertimeRepository; |
| | | private final DingTalkServiceImpl dingTalkService; |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public List<AttendanceLeaveDto> queryAll(AttendanceLeaveQueryCriteria criteria){ |
| | | return attendanceLeaveMapper.toDto(attendanceLeaveRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); |
| | | List<AttendanceLeaveDto> attendanceLeaveDtoList = attendanceLeaveMapper.toDto(attendanceLeaveRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder))); |
| | | attendanceLeaveDtoList.forEach(attendanceLeaveDto -> { |
| | | //查询用户信息 |
| | | User user = userRepository.findById(attendanceLeaveDto.getUserId()).orElseGet(User::new); |
| | | attendanceLeaveDto.setUserName(user.getNickName()); |
| | | //查询审批用户名 |
| | | User appUser = userRepository.findById(attendanceLeaveDto.getApprovalUserId()).orElseGet(User::new); |
| | | attendanceLeaveDto.setAppUserName(appUser.getNickName()); |
| | | }); |
| | | return attendanceLeaveDtoList; |
| | | } |
| | | |
| | | @Override |
| | |
| | | List<DictDetail> dictDetailList = dictDetailRepository.findByDictName("leave_type"); |
| | | List<String> leaveTypes = new ArrayList<>(); |
| | | for(DictDetail dictDetail : dictDetailList){ |
| | | if(dictDetail.getValue().equals(Constant.LEAVE_TYPE_ANNUAL_LEAVE) || dictDetail.getValue().equals(Constant.LEAVE_TYPE_COMPASSIONATE_LEAVE)){ |
| | | if(dictDetail.getValue().equals(Constant.LEAVE_TYPE_ANNUAL_LEAVE) || dictDetail.getValue().equals(Constant.LEAVE_TYPE_REPLACE) || dictDetail.getValue().equals(Constant.LEAVE_TYPE_COMPASSIONATE_LEAVE)){ |
| | | //事假和年假 |
| | | leaveTypes.add(dictDetail.getValue()); |
| | | } |
| | |
| | | * 获取用户年假剩余时长 |
| | | */ |
| | | @Override |
| | | public Double getYearTimeLength(Long userId) throws ParseException { |
| | | // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | // // 获取当前日期 |
| | | // Date date = new Date(); |
| | | // String nowTime = sdf.format(date); |
| | | // Date dateTime = sdf.parse(nowTime); |
| | | // Double surplusYearTime = new Double(0.00); |
| | | // // 查询用户剩余年假时长 |
| | | // 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); |
| | | // } |
| | | // } |
| | | public Double getYearTimeLength(Long userId) { |
| | | //获取年假剩余(新) |
| | | Double surplusYearTime = new Double(0.00); |
| | | // 根据用户查询 |
| | |
| | | |
| | | surplusYearTime = yearTime - (usedYearTime == null ? 0.0 : usedYearTime); |
| | | } |
| | | } |
| | | } |
| | | return surplusYearTime; |
| | | } |
| | | |
| | | /** |
| | | * 获取用户调休假剩余时长 |
| | | */ |
| | | @Override |
| | | public Double getOverTimeLength(Long userId) { |
| | | //获取年假剩余(新) |
| | | Double surplusYearTime = new Double(0.00); |
| | | |
| | | List<AttendanceOvertime> attendanceOvertimeList = attendanceOvertimeRepository.findByUserId(userId); |
| | | if (attendanceOvertimeList.size() > 0) { |
| | | surplusYearTime = attendanceOvertimeList.stream() |
| | | .filter(attendanceOvertime -> attendanceOvertime.getApprovalStatus().equals(Constant.OVERTIME_PASS)) |
| | | .map(attendanceOvertime -> attendanceOvertime.getOvertimeDuration()).reduce(0.0, (o1, o2) -> o1 + o2); |
| | | Double usedTime = attendanceLeaveRepository.sumLeaveDurationByUserIdAndLeaveType(userId, Constant.LEAVE_TYPE_REPLACE); |
| | | if (usedTime != null) { |
| | | surplusYearTime = surplusYearTime - usedTime; |
| | | } |
| | | } |
| | | return surplusYearTime; |
| | |
| | | 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.getUserName()); |
| | | map.put("审批者", attendanceLeave.getAppUserName()); |
| | | map.put("请假类型", leavrType); |
| | | map.put("请假开始时间", attendanceLeave.getLeaveStartTime()); |
| | | map.put("请假结束时间", attendanceLeave.getLeaveEndTime()); |