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(null,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()));
|
}
|
}
|