yaozc
2023-01-18 e818b1d6d438c2bfd3985d1edba1842fcf4af1d3
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceServiceImpl.java
@@ -22,6 +22,8 @@
import me.zhengjie.modules.attendance.repository.AttendanceLeaveRepository;
import me.zhengjie.modules.attendance.service.dto.*;
import me.zhengjie.modules.constant.Constant;
import me.zhengjie.modules.quartz.service.impl.DingTalkServiceImpl;
import me.zhengjie.modules.quartz.task.OapiDingTalkMethod;
import me.zhengjie.modules.system.domain.*;
import me.zhengjie.modules.system.repository.DictDetailRepository;
import me.zhengjie.modules.system.repository.SysConfigHolidayRepository;
@@ -39,6 +41,7 @@
import org.springframework.data.domain.Pageable;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.temporal.ChronoUnit;
import java.util.*;
@@ -65,6 +68,7 @@
    private final AttendanceLeaveRepository attendanceLeaveRepository;
    private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository;
    private final AttendanceGoOutRepository attendanceGoOutRepository;
    private final DingTalkServiceImpl dingTalkService;
    @Override
    public Map<String,Object> queryAll(AttendanceQueryCriteria criteria, Pageable pageable){
@@ -110,12 +114,11 @@
        Attendance attendance = attendanceRepository.findById(resources.getId()).orElseGet(Attendance::new);
        ValidationUtil.isNull( attendance.getId(),"Attendance","id",resources.getId());
        attendance.copy(resources);
        //获取当前登入人信息
        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(resources.getUserId()).equals(SecurityUtils.getCurrentUserId())){
                throw new BadRequestException("只能修改自己的记录");
            }
@@ -208,7 +211,7 @@
        if (localDateTime.toLocalTime().isBefore(sysRostering.getWorkStartTime())) {
            return localDateTime.toLocalDate().atTime(sysRostering.getWorkStartTime());
        } else if (localDateTime.toLocalTime().isAfter(sysRostering.getLunchStartTime()) && localDateTime.toLocalTime().isBefore(sysRostering.getLunchEndTime())) {
            return localDateTime.toLocalDate().atTime(sysRostering.getWorkEndTime());
            return localDateTime.toLocalDate().atTime(sysRostering.getLunchEndTime());
        } else if (localDateTime.toLocalTime().isAfter(sysRostering.getWorkEndTime())) {
            return localDateTime.toLocalDate().atTime(sysRostering.getWorkEndTime());
        }
@@ -221,11 +224,11 @@
            //获取当前登入人信息
            User user = userRepository.getOne(SecurityUtils.getCurrentUserId());
            Job job = user.getJobs().iterator().next();
            Role role = user.getRoles().iterator().next();
            //根据id查询记录
            Optional<Attendance> attendance = attendanceRepository.findById(id);
            //除超管、总经理只能删除自己信息
            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(attendance.get().getUserId()).equals(SecurityUtils.getCurrentUserId())){
                    throw new BadRequestException("只能删除自己的记录");
                }
@@ -255,13 +258,30 @@
    public void getUserMakeUpCard(String userId) {
        //获取当前登入人信息
        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(userId).equals(SecurityUtils.getCurrentUserId())){
                throw new BadRequestException("只能补自己的卡");
            }
        }
    }
    /**
     * 补充考勤信息
     * @param attendance
     */
    @Override
    public void addAttendanceInfo(Attendance attendance) throws Exception {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String attendanceDate = df.format(attendance.getAttendanceDate());
        List<User> userList = new ArrayList<>();
        if(ObjectUtils.isNotEmpty(attendance.getUserId())){
            User user = userRepository.findById(attendance.getUserId()).orElseGet(User::new);
            userList.add(user);
        }
        // 选择日期和员工更新员工的考勤信息,未选择员工则更新所有人
        dingTalkService.getDingTalkAttendanceListOfNoonOrNight(attendanceDate ,userList);
    }
    @Override
@@ -401,6 +421,8 @@
            if (attendanceDayList.size() > 1) {
                throw new BadRequestException("相同日期存在多条考勤记录!");
            } else if (attendanceDayList.size() == 1) {
                // 本日考勤
                attendanceDay = attendanceDayList.get(0);
                // 判断本日考勤排班信息是否完整
                if (attendanceDay.getRosteringWorkStartTime() == null || "".equals(attendanceDay.getRosteringWorkStartTime()) ||
                        attendanceDay.getRosteringLunchStartTime() == null || "".equals(attendanceDay.getRosteringLunchStartTime()) ||
@@ -408,8 +430,6 @@
                        attendanceDay.getRosteringWorkEndTime() == null || "".equals(attendanceDay.getRosteringWorkEndTime())) {
                    throw new BadRequestException("考勤记录排班信息缺失!");
                }
                // 本日考勤
                attendanceDay = attendanceDayList.get(0);
                // 判断本日考勤是否有实际工作开始时间、实际工作结束时间
                if (attendanceDay.getActualWorkStartTime() != null && !"".equals(attendanceDay.getActualWorkStartTime()) && attendanceDay.getActualWorkEndTime() != null && !"".equals(attendanceDay.getActualWorkEndTime())) {
                    // 获取有效时长