liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
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
package com.basic.x01.system.controller;
 
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
 
import com.basic.x01.base.BaseController;
import com.basic.x01.helper.UserHelper;
import com.basic.x01.system.mapper.SystemMapper;
import com.basic.x01.system.model.TSysRole;
import com.basic.x01.system.model.TSysUser;
 
/**
 * 学校的教职工用户管理
 * 
 * @company 北京贝思科技术有限公司
 * @author liuyajun, 8384503@qq.com
 * @date 2016年1月26日
 * @time 下午9:20:00
 */
@Controller
@Transactional(rollbackFor=Throwable.class)
public class SchoolSystemUser extends BaseController {
 
    public static final String EDIT_ACTION = "schoolSystemUserEdit";
    
    @Resource
    private SystemMapper userMapper;
    
    @RequestMapping(value=EDIT_ACTION)
    public String schoolSystemUserEdit(
            @Param("edit") String edit,
            TSysUser editUser
            ){
        TSysUser user = this.getLoingedUser();
        if(! UserHelper.isSchoolUser(user)){
            throw this.exception("当前用户不是学校用户");
        }
        
        if(! this.isEmpty(edit) && edit.equals("edit")){
            //新增
            if(editUser==null 
                    || this.isEmpty(editUser.getLoginName())
                    || this.isEmpty(editUser.getRealName())
                    || this.isEmpty(editUser.getRoleId())){
                throw this.exception("1");    //
            }
            
            TSysUser sameUser = userMapper.getUserByLoginName(editUser.getLoginName());
            if(this.isEmpty(editUser.getUserId())){
                if(sameUser !=null){
                    throw this.exception("2");    //same user
                }
                
                editUser.setOrgId(user.getOrgId());
                editUser.setUserId(user.getUserId());
                userMapper.createUser(editUser);
            }else{
                if(user.getUserId().equals(editUser.getUserId())){
                    throw this.exception("3");    //不能修改自己
                }
                
                if(sameUser !=null && ! sameUser.getUserId().equals(editUser.getUserId())){
                    throw this.exception("2");    //same user
                }
                userMapper.updateUser(editUser);
            }
            
            
            return this.ajax("ok");
        }
        
        List<TSysRole> roleList = new LinkedList<TSysRole>();
        if(UserHelper.isAdmin(user)){
            //管理员,使用全部该组织的角色
            roleList = userMapper.getRoleListByOrgId(user.getOrgId(), false);
        }else{
            //不是管理员,只使用当前用户的角色
            roleList.add(user.getRole());
        }
        this.getRequest().setAttribute("roleList", roleList);
        
        if(editUser !=null){
            //修改时带出
            editUser = userMapper.getUserByUserId(editUser.getUserId());
            this.getRequest().setAttribute("editUser", editUser);
        }
        
        this.getRequest().setAttribute("editAction", EDIT_ACTION);
        return "system/user-create";
    }
 
    @RequestMapping(value="schoolSystemUser")
    public String school() {
        TSysUser user = this.getLoingedUser();
        if(! UserHelper.isSchoolUser(user)){
            throw this.exception("当前用户不是学校用户");
        }
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("orgId", user.getOrgId());
        map.put("all", true);
        List<TSysUser> userList = userMapper.getUserListByOrgId(this.wrapPageSearchParam(map));
        this.getRequest().setAttribute("userList", userList);
        
        boolean editAccess = this.checkAccess(EDIT_ACTION);
        this.getRequest().setAttribute("editAccess", editAccess?"y":"n");
        this.getRequest().setAttribute("editAction", EDIT_ACTION);
        return "system/school-user";
    }
}