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 roleList = new LinkedList(); 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 map = new HashMap(); map.put("orgId", user.getOrgId()); map.put("all", true); List 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"; } }