派生自 projectDept/qhighschool

Administrator
2022-11-29 8c99e2d8b6c1e0d9cde6abbe80b4df75be19f6d1
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
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));
    }
 
}