zouyu
7 天以前 e50a43bb067adff10cd1dcc81349b1aafdfda882
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.ruoyi.system.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.User;
import com.ruoyi.common.utils.QueryWrappers;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.vo.UserVo;
import com.ruoyi.system.mapper.UserMapper;
import com.ruoyi.system.service.UserService;
import org.springframework.stereotype.Service;
 
import java.time.LocalDateTime;
import java.util.List;
 
/**
 * 用户信息表
 *
 * @author zhuo
 * @since 2025-02-13
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
 
    /**
     * 根据条件获取用户列表
     * * todo:  type : 1: 获取检测人员信息
     * type : 2: 获取当前登录用户部门下的所有用户
     *
     * @param user         用户
     * @param type         类型
     * @param departmentId 部门ID
     * @return
     */
    @Override
    public List<User> selectUserCondition(User user, String type, Integer departmentId) {
 
        if (!StringUtils.isNotEmpty(type)) {
            return baseMapper.selectUserCondition(QueryWrappers.queryWrappers(user), type);
        }
 
        switch (type) {
 
            case "1":
                // 检测人员
                return baseMapper.selectQualityUserList();
 
            case "2":
                Long currentUserId = SecurityUtils.getUserId();
                boolean isAdmin = SecurityUtils.isAdmin(currentUserId);
 
                //  管理员判断,传入部门ID就查对应的部门否则查询全部
                if (isAdmin) {
                    if (departmentId != null) {
                        return baseMapper.selectUserByDepartmentId(departmentId);
                    }
                    return baseMapper.selectUserCondition(QueryWrappers.queryWrappers(user), type);
                }
                return baseMapper.selectDepartmentLimsUserList(currentUserId.intValue());
        }
 
        return baseMapper.selectUserCondition(QueryWrappers.queryWrappers(user), type);
    }
 
    /**
     * 获取当前登录的客户信息
     * @return
     */
    @Override
    public UserVo getUserNow() {
        return baseMapper.getUserNow(SecurityUtils.getUserId().intValue());
    }
 
    /**
     * 获取当前登录用户部门
     * @return
     */
    @Override
    public String selectUserDepartmentLimsName() {
        return baseMapper.selectUserDepartmentLimsName(SecurityUtils.getUserId().intValue());
    }
 
    /**
     * 修改人员明细所在组织架构
     * @param ids
     * @param id
     * @return
     */
    @Override
    public int upUserDepardLimsId(String ids, String id) {
        List<Integer> userIds = JSON.parseArray(ids, Integer.class);
        return baseMapper.update(null, Wrappers.<User>lambdaUpdate().in(User::getId, userIds).set(User::getDepartLimsId, id).set(User::getUpdateTime, LocalDateTime.now()).set(User::getUpdateBy, SecurityUtils.getLoginUser().getUsername()));
    }
 
    /**
     * 删除人员明细所在组织架构
     * @param id
     * @return
     */
    @Override
    public int delUserDepardLimsId(Integer id) {
        return baseMapper.update(null, Wrappers.<User>lambdaUpdate().eq(User::getId, id).set(User::getDepartLimsId, null).set(User::getUpdateTime, LocalDateTime.now()).set(User::getUpdateBy, SecurityUtils.getUsername()));
    }
}