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));
|
}
|
|
}
|