赵士淞
2023-01-20 d763cd0694bc0d263de311bacbf4ff72ffbea509
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
@@ -20,16 +20,10 @@
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.security.service.OnlineUserService;
import me.zhengjie.modules.security.service.UserCacheManager;
import me.zhengjie.modules.system.domain.SysLevel;
import me.zhengjie.modules.system.domain.SysUserLevelInsurance;
import me.zhengjie.modules.system.domain.SysUserLevelWage;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.modules.system.domain.*;
import me.zhengjie.exception.EntityExistException;
import me.zhengjie.exception.EntityNotFoundException;
import me.zhengjie.modules.system.repository.SysLevelRepository;
import me.zhengjie.modules.system.repository.SysUserLevelInsuranceRepository;
import me.zhengjie.modules.system.repository.SysUserLevelWageRepository;
import me.zhengjie.modules.system.repository.UserRepository;
import me.zhengjie.modules.system.repository.*;
import me.zhengjie.modules.system.service.UserService;
import me.zhengjie.modules.system.service.dto.*;
import me.zhengjie.modules.system.service.mapstruct.SysUserLevelWageMapper;
@@ -70,6 +64,7 @@
    private final SysLevelRepository sysLevelRepository;
    private final SysUserLevelWageRepository sysUserLevelWageRepository;
    private final SysUserLevelInsuranceRepository sysUserLevelInsuranceRepository;
    private final SysUserLevelOtherRepository sysUserLevelOtherRepository;
    @Override
    public Object queryAll(UserQueryCriteria criteria, Pageable pageable) {
@@ -253,15 +248,6 @@
        flushCache(username);
    }
    /**
     * 查询在职员工
     * @return
     */
    @Override
    public List<User> getUsers() {
        List<User> List = userRepository.findAllByEnabled(true);
        return List;
    }
    @Override
    public void download(List<UserDto> queryAll, HttpServletResponse response) throws IOException {
@@ -319,6 +305,8 @@
            createSysUserLevelWage(userId, newLevelId);
            // 创建用户级别保险
            createSysUserLevelInsurance(userId, newLevelId);
            // 创建用户级别其他
            createSysUserLevelOther(userId, newLevelId);
        } else if (oldLevelId != newLevelId) {
            // 旧用户级别工资
            SysUserLevelWage oldSysUserLevelWage = sysUserLevelWageRepository.findLastByUserId(userId);
@@ -374,6 +362,33 @@
            }
            // 创建用户级别保险
            createSysUserLevelInsurance(userId, newLevelId);
            // 旧用户级别其他
            SysUserLevelOther oldSysUserLevelOther = sysUserLevelOtherRepository.findLastByUserId(userId);
            // 判断旧用户级别其他是否为空
            if (oldSysUserLevelOther != null && oldSysUserLevelOther.getId() != null) {
                // 旧日期字符串
                String oldDateString = oldSysUserLevelOther.getStartDate().toString().substring(0,10);
                // 获取当前日期
                Date nowDate = new Date();
                // 创建Calendar实例
                Calendar nowCalendar = Calendar.getInstance();
                // 设置当前时间
                nowCalendar.setTime(nowDate);
                // 新日期字符串
                String nowDateString = new Timestamp(nowCalendar.getTime().getTime()).toString().substring(0,10);
                // 判断新、旧日期字符串
                if (oldDateString.equals(nowDateString)) {
                    throw new BadRequestException("每天只能调整一次级别,请明日再试!");
                }
                // 设置前一天时间
                nowCalendar.add(Calendar.DATE, -1);
                // 旧用户级别保险
                oldSysUserLevelOther.setEndDate(new Timestamp(nowCalendar.getTime().getTime()));
                // 保存
                sysUserLevelOtherRepository.save(oldSysUserLevelOther);
            }
            // 创建用户级别其他
            createSysUserLevelOther(userId, newLevelId);
        } else {
        }
@@ -431,4 +446,23 @@
        // 保存
        sysUserLevelInsuranceRepository.save(sysUserLevelInsurance);
    }
    /**
     * 创建用户级别其他
     * @param userId
     * @param levelId
     */
    private void createSysUserLevelOther(Long userId, Long levelId) {
        // 级别
        SysLevel sysLevel = sysLevelRepository.findById(levelId).orElseGet(SysLevel::new);
        // 用户级别其他
        SysUserLevelOther sysUserLevelOther = new SysUserLevelOther();
        sysUserLevelOther.setUserId(userId);
        sysUserLevelOther.setLevelId(levelId);
        sysUserLevelOther.setStartDate(new Timestamp(new Date().getTime()));
        sysUserLevelOther.setPersonalPerformanceProportion(sysLevel.getPersonalPerformanceProportion());
        sysUserLevelOther.setAnnualLeaveDays(sysLevel.getAnnualLeaveDays());
        // 保存
        sysUserLevelOtherRepository.save(sysUserLevelOther);
    }
}