weicd
2023-10-20 698e84a1cd088c9d8f0108ae933e205fc14d2741
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
@@ -150,6 +150,7 @@
        String calendarStr = sdf.format(calendar.getTime());
        TaskMongo taskMongo = mongoTemplate.findById(taskId, TaskMongo.class);
        List<Long> containUserList = taskMongo.getContainUserList();
        List<User> userList = new ArrayList<>();
        if (containUserList.size() != 0) {
@@ -173,6 +174,60 @@
            }
        }
        return userDto;
    }
    @Override
    public List<UserDto> getAllUserByTaskId(String taskId) {
        // 日历类
        Calendar calendar = Calendar.getInstance();
        // 日期格式化
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        // 日历字符串
        String calendarStr = sdf.format(calendar.getTime());
        TaskMongo taskMongo = mongoTemplate.findById(taskId, TaskMongo.class);
        List<Long> containUserList = taskMongo.getContainUserList();
        //递归添加
        addSubTaskUserList(taskMongo, containUserList);
        containUserList = containUserList.stream().distinct().collect(Collectors.toList());
        List<User> userList = new ArrayList<>();
        if (containUserList.size() != 0) {
            for (Long userId : containUserList) {
                userList.add(userRepository.findById(userId).get());
            }
        }
        List<UserDto> userDto = userMapper.toDto(userList);
        for (int i = 0; i < userDto.size(); i++) {
            // 根据用户ID、指定年月查询用户级别工资
            SysUserLevelWage sysUserLevelWage = sysUserLevelWageRepository.findTargetYearMonth(userDto.get(i).getId(), calendarStr);
            // 判断用户级别工资是否为空
            if (sysUserLevelWage != null) {
                // 根据ID查询用户级别
                SysLevel sysLevel = sysLevelRepository.findById(sysUserLevelWage.getLevelId()).orElseGet(SysLevel::new);
                // 用户
                userDto.get(i).setLevelName(sysLevel.getName());
            } else {
                // 用户
                userDto.get(i).setLevelName(null);
            }
        }
        return userDto;
    }
    /**
     * 任务下的所有子级
     * @param taskMongo
     * @param containUserList
     */
    public void addSubTaskUserList(TaskMongo taskMongo, List<Long> containUserList) {
        List<TaskMongo> subTasks = mongoTemplate.find(Query.query(Criteria.where("pid").is(taskMongo.getOld_id())), TaskMongo.class);
        for (TaskMongo subTask : subTasks) {
            containUserList.addAll(subTask.getContainUserList());
            addSubTaskUserList(subTask, containUserList);
        }
    }
    @Override
@@ -312,17 +367,48 @@
        List<Map> resultList = new ArrayList<>();
        for (TaskDaliyMongo taskDaliyMongo : daliyMongoList) {
            String taskName = taskDaliyMongo.getTaskUserMongo().getTask().getName();
            Double taskConsumeHours = taskDaliyMongo.getConsumedHours();
            if (resultList.isEmpty()) {
                Map map = new HashMap();
                map.put("name", taskName);
                map.put("value", taskConsumeHours);
                if (taskDaliyMongo.getTaskUserMongo().getPerformanceType().equals("1")){
                    map.put("value", taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours() ? taskDaliyMongo.getTaskUserMongo().getPerformanceHours() : taskDaliyMongo.getConsumedHours());
                }else {
                    map.put("value", taskDaliyMongo.getConsumedHours());
                }
                map.put(taskDaliyMongo.getTaskUserMongo().getName(),taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours() ? taskDaliyMongo.getTaskUserMongo().getPerformanceHours() : taskDaliyMongo.getConsumedHours());
                resultList.add(map);
                continue;
            }
            findList(resultList, taskName, taskConsumeHours);
            findList(resultList, taskDaliyMongo);
        }
        for (Map map : resultList) {
            ArrayList<Map> list = new ArrayList<>();
            for (Object key : map.keySet()) {
                if (!key.equals("name") && !key.equals("value")){
                    Map innerMap = new HashMap();
                    innerMap.put(key,map.get(key));
                    list.add(innerMap);
                }
            }
            map.put("list",list);
        }
        return resultList;
    }
    @Override
    public List<User> getUserInfose() {
        List<User> userList = new ArrayList<>();
        //获取当前登入人信息
        User user1 = userRepository.getOne(SecurityUtils.getCurrentUserId());
        Role role = user1.getRoles().iterator().next();
        //超管、总经理,痛苦哦经理查看全部
        if(Long.valueOf(role.getLevel()) == Constant.ROLE_LEVEL_SUPER || Long.valueOf(role.getLevel()) == Constant.ROLE_LEVEL_GENERAL){
            userList = userRepository.findAllByEnabled(true);
        } else {
            userList = userRepository.findByUserId(user1.getId());
        }
        return userList;
    }
    /*
@@ -330,22 +416,30 @@
    遍历resultList 集合将集合中的元素逐个遍历,如果有元素与当前任务的任务名称相等
    如果任务名称相等,取出当前元素并且将当前任务的消耗工时添加进元素中
     */
    private static void findList(List<Map> resultList, String taskName, Double taskConsumeHours) {
    private static void findList(List<Map> resultList, TaskDaliyMongo taskDaliyMongo) {
        boolean flag = false;
        for (Map map : resultList) {
            if (map.get("name").equals(taskName)) {
            if (map.get("name").equals(taskDaliyMongo.getTaskUserMongo().getTask().getName())) {
                // 有
                Double value = (Double) map.get("value");
                value += taskConsumeHours;
                value += taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours() ? taskDaliyMongo.getTaskUserMongo().getPerformanceHours() : taskDaliyMongo.getConsumedHours();
                map.put("value", value);
                map.put(taskDaliyMongo.getTaskUserMongo().getName(),taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours() ? taskDaliyMongo.getTaskUserMongo().getPerformanceHours() : taskDaliyMongo.getConsumedHours());
                flag = true;
            }
        }
        // 无
        if (!flag) {
            Map newMap = new HashMap();
            newMap.put("name", taskName);
            newMap.put("value", taskConsumeHours);
            if (taskDaliyMongo.getTaskUserMongo().getPerformanceType().equals("1")){
                newMap.put("name", taskDaliyMongo.getTaskUserMongo().getTask().getName());
                newMap.put("value", taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours() ? taskDaliyMongo.getTaskUserMongo().getPerformanceHours() : taskDaliyMongo.getConsumedHours());
                newMap.put(taskDaliyMongo.getTaskUserMongo().getName(),taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours() ? taskDaliyMongo.getTaskUserMongo().getPerformanceHours() : taskDaliyMongo.getConsumedHours());
            }else {
                newMap.put("name", taskDaliyMongo.getTaskUserMongo().getTask().getName());
                newMap.put("value", taskDaliyMongo.getConsumedHours());
                newMap.put(taskDaliyMongo.getTaskUserMongo().getName(),taskDaliyMongo.getConsumedHours() > taskDaliyMongo.getTaskUserMongo().getPerformanceHours() ? taskDaliyMongo.getTaskUserMongo().getPerformanceHours() : taskDaliyMongo.getConsumedHours());
            }
            resultList.add(newMap);
        }
    }