yaozc
2023-01-19 2788367c1af81bb1f81e40232fcd708a02db08d6
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceLeaveServiceImpl.java
@@ -24,6 +24,7 @@
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;
@@ -74,6 +75,7 @@
    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){
@@ -455,25 +457,20 @@
     * @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)){
                if (!attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_LEAVE) && resources.getLeaveStartTime().toLocalDateTime().compareTo(attendance.getRosteringWorkStartTime().toLocalDateTime()) <= 0) {
                    attendance.setStartClockResults(Constant.ATTENDANCE_STATE_LEAVE);
                }
                if (!attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_LEAVE) &&resources.getLeaveEndTime().toLocalDateTime().compareTo(attendance.getRosteringWorkEndTime().toLocalDateTime()) >= 0) {
                    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
@@ -505,15 +502,17 @@
    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());