赵士淞
2023-01-13 c71ea3a3b1ff125cc5ca916accb50b797cb31d5e
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceCardreplacementServiceImpl.java
@@ -23,8 +23,11 @@
import me.zhengjie.modules.constant.Constant;
import me.zhengjie.modules.quartz.service.OpaiDingTalkService;
import me.zhengjie.modules.system.domain.Job;
import me.zhengjie.modules.system.domain.Role;
import me.zhengjie.modules.system.domain.SysConfigProportion;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.modules.system.repository.RoleRepository;
import me.zhengjie.modules.system.repository.SysConfigProportionRepository;
import me.zhengjie.modules.system.repository.UserRepository;
import me.zhengjie.utils.*;
import lombok.RequiredArgsConstructor;
@@ -61,6 +64,7 @@
    private final OpaiDingTalkService opaiDingTalkService;
    private final RoleRepository roleRepository;
    private final AttendanceRepository attendanceRepository;
    private final SysConfigProportionRepository sysConfigProportionRepository;
    @Override
    public Map<String,Object> queryAll(AttendanceCardreplacementQueryCriteria criteria, Pageable pageable){
@@ -102,6 +106,10 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AttendanceCardreplacementDto create(AttendanceCardreplacement resources) throws Exception {
        //查询补卡次数(每个月5次)
        getCardreplacement(resources.getUserId());
        //查询补卡记录是否存在
        AttendanceCardreplacement attendanceCardreplacement = attendanceCardreplacementRepository.findByUserIdAndCardReplacementTime(resources.getUserId(),resources.getCardReplacementTime());
        if(ObjectUtils.isNotEmpty(attendanceCardreplacement)) {
@@ -116,7 +124,6 @@
        }
        resources.setApprovalStatus(Constant.CARD_APPROVE_STATUS_REVIEWED);
        //查询补卡次数(待加入)?
        //发送给审批者
        List<String> sendList = new ArrayList<>();
@@ -144,11 +151,14 @@
            throw new BadRequestException("考勤记录不存在");
        }
        //查询补卡次数(每个月5次)
        getCardreplacement(resources.getUserId());
        //获取当前登入人信息
        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("只能修改自己的记录");
            }
@@ -159,6 +169,29 @@
        }
        attendanceCardreplacementRepository.save(attendanceCardreplacement);
    }
    /**
     * 查询剩余补卡次数
     */
    public void getCardreplacement(Long userId){
        Calendar calendar = Calendar.getInstance();
        // 获取当前年
        int year = calendar.get(Calendar.YEAR);
        // 获取当前月
        int month = calendar.get(Calendar.MONTH) + 1;
        String mouths = "";
        if(month < 10){
            mouths = "0" + month;
        }
        String baseDate = year + "-" + mouths;
        // 查询当月的补卡记录的条数
        Integer count = attendanceCardreplacementRepository.count(userId, baseDate);
        // 查询配置表的每月补卡次数
        SysConfigProportion sysConfigProportion = sysConfigProportionRepository.findByTitle("每月可补卡次数");
        if(count >= sysConfigProportion.getProportion()){
            throw new BadRequestException("补卡次数用尽,请联系管理员");
        }
    }
    /**
@@ -182,7 +215,6 @@
                attendance.setActualWorkStartTime(resources.getCardReplacementTime());
                attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NORMAL);
                attendance.setStartLocationResults(Constant.LOCATION_RESULTS_NORMAL);
                // 减少补卡次数待加入?
            }else if (resources.getApprovalStatus().equals(Constant.CARD_APPROVE_STATUS_REFUSE)){
                attendance.setStartClockResults(Constant.ATTENDANCE_STATE_NOTSIGNED);
                attendance.setStartLocationResults(Constant.LOCATION_RESULTS_NOTSIGNED);
@@ -194,7 +226,6 @@
                attendance.setActualWorkEndTime(resources.getCardReplacementTime());
                attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NOTSIGNED);
                attendance.setEndLocationResults(Constant.LOCATION_RESULTS_NOTSIGNED);
                // 减少补卡次数待加入?
            }else if (resources.getApprovalStatus().equals(Constant.CARD_APPROVE_STATUS_REFUSE)){
                attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NOTSIGNED);
                attendance.setEndLocationResults(Constant.LOCATION_RESULTS_NOTSIGNED);
@@ -238,11 +269,11 @@
        for (Long id : ids) {
            //获取当前登入人信息
            User user = userRepository.getOne(SecurityUtils.getCurrentUserId());
            Job job = user.getJobs().iterator().next();
            Role role = user.getRoles().iterator().next();
            //根据id查询记录
            Optional<AttendanceCardreplacement> attendanceCardreplacement = attendanceCardreplacementRepository.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(attendanceCardreplacement.get().getUserId()).equals(SecurityUtils.getCurrentUserId())){
                    throw new BadRequestException("只能删除自己的记录");
                }