yaozc
2023-01-31 aa102c7ba6977ff40f3e02eba32a00a168fb3564
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceCardreplacementServiceImpl.java
@@ -23,8 +23,12 @@
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.DictDetailRepository;
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 +65,8 @@
    private final OpaiDingTalkService opaiDingTalkService;
    private final RoleRepository roleRepository;
    private final AttendanceRepository attendanceRepository;
    private final SysConfigProportionRepository sysConfigProportionRepository;
    private final DictDetailRepository dictDetailRepository;
    @Override
    public Map<String,Object> queryAll(AttendanceCardreplacementQueryCriteria criteria, Pageable pageable){
@@ -102,6 +108,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 +126,6 @@
        }
        resources.setApprovalStatus(Constant.CARD_APPROVE_STATUS_REVIEWED);
        //查询补卡次数(待加入)?
        //发送给审批者
        List<String> sendList = new ArrayList<>();
@@ -144,11 +153,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 +171,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 +217,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);
@@ -192,9 +226,8 @@
            if (resources.getApprovalStatus().equals(Constant.CARD_APPROVE_STATUS_AGREE)) {
                // set考勤打卡时间和打卡状态
                attendance.setActualWorkEndTime(resources.getCardReplacementTime());
                attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NOTSIGNED);
                attendance.setEndLocationResults(Constant.LOCATION_RESULTS_NOTSIGNED);
                // 减少补卡次数待加入?
                attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NORMAL);
                attendance.setEndLocationResults(Constant.LOCATION_RESULTS_NORMAL);
            }else if (resources.getApprovalStatus().equals(Constant.CARD_APPROVE_STATUS_REFUSE)){
                attendance.setEndClockResults(Constant.ATTENDANCE_STATE_NOTSIGNED);
                attendance.setEndLocationResults(Constant.LOCATION_RESULTS_NOTSIGNED);
@@ -238,11 +271,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("只能删除自己的记录");
                }
@@ -259,14 +292,16 @@
    public void download(List<AttendanceCardreplacementDto> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (AttendanceCardreplacementDto attendanceCardreplacement : all) {
            String attCardreplacementType = attendanceCardreplacement.getApprovalStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.CARD_APPROVE_STATUS, attendanceCardreplacement.getApprovalStatus()).getLabel() : "";
            String attCardReplacementDistinguish = attendanceCardreplacement.getCardReplacementDistinguish() != null ? dictDetailRepository.findByDictNameAndValue(Constant.CARD_REPLACEMENT_DIFFERENTIATION, attendanceCardreplacement.getCardReplacementDistinguish()).getLabel() : "";
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("用户id", attendanceCardreplacement.getUserId());
            map.put("审批用户id", attendanceCardreplacement.getApprovalUserId());
            map.put("补卡时间", attendanceCardreplacement.getCardReplacementTime());
            map.put("补卡原因", attendanceCardreplacement.getCardReplacementReason());
            map.put("审批状态", attendanceCardreplacement.getApprovalStatus());
            map.put("审批状态", attCardreplacementType);
            map.put("审批说明", attendanceCardreplacement.getApprovalDescription());
            map.put("补卡区分", attendanceCardreplacement.getCardReplacementDistinguish());
            map.put("补卡区分", attCardReplacementDistinguish);
            map.put("备注", attendanceCardreplacement.getRemarks());
            map.put("创建者", attendanceCardreplacement.getCreateBy());
            map.put("创建时间", attendanceCardreplacement.getCreateTime());