派生自 projectDept/qhighschool

yn147
2023-11-24 d7963a84282c548fee3595b3343e6ae6ca49bb29
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package com.qxueyou.scc.controller;
 
import com.qxueyou.scc.admin.teacher.service.ITeacherService;
import com.qxueyou.scc.base.model.Result;
import com.qxueyou.scc.base.util.ClientUtils;
import com.qxueyou.scc.base.util.CollectionUtils;
import com.qxueyou.scc.base.util.QBeanUtils;
import com.qxueyou.scc.user.model.User;
import com.qxueyou.scc.user.model.UserRole;
import com.qxueyou.scc.user.model.UserTeacher;
import com.qxueyou.scc.user.service.IUserRoleService;
import com.qxueyou.scc.user.service.IUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.List;
import java.util.Map;
 
/**
 * 角色管理前端控制器
 * 
 * @author chenjunliang
 *
 */
@RestController
@RequestMapping(value = "/p/user")
public class UserController {
    @Autowired
    IUserRoleService userRoleService;
 
    @Autowired
    IUserService userService;
 
    @Autowired
    ITeacherService teacherService;
 
    /**
     * 获取角色列表
     * 
     * @return
     */
    @GetMapping(value = "queryUserRoleLst")
    public Result queryUserRoleLst(String keyword) {
        List<UserRole> userRoleLst = userRoleService.getUserRoleLst(keyword);
        return new Result(true, "success", QBeanUtils.listBean2ListMap(userRoleLst,
                CollectionUtils.newStringMap("name", "userName", "roleId", "roleId")));
    }
 
    /**
     * 获取人员列表
     */
    @GetMapping(value = "getUserLst")
    public Result getUserLstByRoleId(String roleId, Integer pageSize, Integer pageNum, String keyword) {
 
        return userRoleService.getUserLstByRoleId(roleId, pageSize, pageNum, keyword);
    }
 
    /**
     * 删除人员
     * 
     * @param userid
     *            用户id可以多个 ,分隔
     */
    @PostMapping(value = "delete")
    public Result delete(String userId) {
 
        return userRoleService.delete(userId);
    }
 
    /**
     * 新增人员
     */
    @PostMapping(value = "add")
    public Result insertUser(String roleId, String name, String account, String password, String mobilePhone) {
        Result result = new Result(true);
 
        User user = userService.getUserByAccount(account, ClientUtils.getOrgId());
 
        if (null != user) {
            return new Result(false,"重复的用户,不允许添加!");
        }
        
        //如果角色是老师,添加老师信息
        if(roleId.equals(UserRole.ROLE_TEACHER_ID)){
            result= teacherService.add(name, password, mobilePhone, account);
        }else{
            user = userService.insertUser(name, account, mobilePhone, password, true, ClientUtils.getOrgId());
            result= userService.addRole(user.getUserId(), roleId);
        }
        
        return result;
    }
 
    /**
     * 新增教师
     */
    @PostMapping(value = "addTeachers")
    public Result addTeachers(String teacherIds, String roleId) {
        return userRoleService.addTeachers(teacherIds, roleId);
    }
 
    /**
     * 更新
     */
    @PostMapping(value = "update")
    public Result updateUser(String userId, String name, String account, String password, String mobilePhone) {
        Result result = new Result(true);
        
        UserTeacher teacher = ClientUtils.isAdmin() ? null : teacherService.getTeacherByUserId(ClientUtils.getUserId());
        
        //如果用户是老师,更新老师信息
        if(teacher!=null){
            result = teacherService.update(teacher.getTeacherId(), name, account, password, mobilePhone, account);
        }else{
            result = userService.updateUser(userId, name, account, mobilePhone, password, true);
        }
        
        return result;
    }
 
    /**
     * 角色管理 显示角色信息
     */
    @GetMapping(value = "queryRoleDetail")
    public Result queryRoleDetail(String roleId) {
        return userRoleService.queryRoleDetail(roleId);
    }
 
    /**
     * 显示教师列表
     */
    @GetMapping(value = "findTeacherLst")
    public Result findTeacherLst(String keyword, Integer pageSize, Integer pageNum, String roleId) {
        String keyword_ = StringUtils.isBlank(keyword) ? "" : keyword;
        List<Map<String, Object>> teacherLst = teacherService.findLstToRole(keyword_, pageSize, pageNum, roleId);
        int count = teacherService.findLstCountToRole(roleId, keyword_);
        return new Result(true, "success",
                CollectionUtils.newObjectMap("teacherLst", teacherLst, "teacherCount", count));
    }
 
    /**
     * 修改角色信息
     */
    @PostMapping(value = "updateRole")
    public Result updateRole(String roleId, String menuIds, String name) {
        return userRoleService.updateRole(roleId, menuIds, name);
    }
 
    /**
     * 删除角色
     */
    @PostMapping(value = "deleteRole")
    public Result deleteRole(String roleId) {
        return userRoleService.deleteRole(roleId);
    }
 
    /**
     * 获取所有菜单列表
     */
    @GetMapping(value = "findAllMenuLst")
    public Result findMenuLst() {
        List<Map<String, Object>> menuLst = userRoleService.findMenuLst();
        return new Result(true, "success", menuLst);
    }
 
    /**
     * 新增角色
     */
    @PostMapping(value = "addRole")
    public Result addRole(String name,Integer roleType) {
        return userRoleService.addRole(name,String.valueOf(roleType));
    }
 
 
    /**
     * 统计人数
     */
    @GetMapping(value = "countUser")
    public Result countUser() {
        return new Result(true,"cg", CollectionUtils.newObjectMap("sex",userService.countUsersex(),"sex2",userService.countUser()));
    }
}