use of com.cdeledu.model.rbac.SysRole in project wechat by dllwh.
the class RoleOperateController method roleVisibleButton.
@ResponseBody
@RequestMapping("roleVisibleButton")
@SystemLog(desc = "启用、禁用账户", opType = SysOpType.UPDATE, tableName = "sys_role_menu")
public AjaxJson roleVisibleButton(@RequestParam(name = "id", required = true, defaultValue = "") int id, @RequestParam(name = "visible", required = true, defaultValue = "1") int visible) {
AjaxJson resultMsg = new AjaxJson();
SysRole role = new SysRole();
role.setId(id);
role.setIfVisible(visible);
try {
if (!roleService.hasMenuByRole(id) && !roleService.hasUserByRole(id) && id != 1) {
roleService.update(role);
resultMsg.setMsg(MessageConstant.MSG_OPERATION_SUCCESS);
} else {
resultMsg.setSuccess(false);
resultMsg.setMsg("错误提示:该角色下尚有用户未解除!");
}
} catch (Exception e) {
resultMsg.setSuccess(false);
resultMsg.setMsg(MessageConstant.MSG_OPERATION_FAILED);
}
return resultMsg;
}
use of com.cdeledu.model.rbac.SysRole in project wechat by dllwh.
the class RoleOperateController method delRole.
/**
* @方法描述: 删除角色,根据ID,但是删除角色的时候,需要查询是否有赋予给用户,如果有用户在使用,那么就不能删除
* @param role
* @return
*/
@ResponseBody
@RequestMapping(value = "delRole")
@SystemLog(desc = "角色删除", opType = SysOpType.DEL, tableName = "sys_role")
public AjaxJson delRole(@RequestParam(name = "delId", required = true, defaultValue = "-1") int roleId) {
AjaxJson resultMsg = new AjaxJson();
try {
if (roleId != 1) {
SysRole seacherRole = roleService.getRoleById(roleId);
if (seacherRole != null && seacherRole.getAllowDelete() == 1) {
// 角色允许删除
if (roleService.hasMenuByRole(roleId)) {
resultMsg.setSuccess(false);
resultMsg.setResultCode(201);
resultMsg.setMsg("该角色已经含有权限,无法直接删除!");
} else {
if (roleService.hasUserByRole(roleId)) {
resultMsg.setSuccess(false);
resultMsg.setResultCode(201);
resultMsg.setMsg("该角色已被使用,无法直接删除!");
} else {
roleService.delete(roleId);
resultMsg.setSuccess(true);
resultMsg.setResultCode(200);
resultMsg.setMsg(MessageConstant.MSG_OPERATION_SUCCESS);
}
}
} else {
resultMsg.setSuccess(false);
resultMsg.setResultCode(201);
resultMsg.setMsg("该角色不允许删除");
}
} else {
resultMsg.setSuccess(false);
resultMsg.setResultCode(201);
resultMsg.setMsg("无法删除超级管理员");
}
} catch (Exception e) {
resultMsg.setSuccess(false);
resultMsg.setResultCode(500);
resultMsg.setMsg(MessageConstant.MSG_OPERATION_FAILED);
}
return resultMsg;
}
use of com.cdeledu.model.rbac.SysRole in project wechat by dllwh.
the class RoleOperateController method updateRoleUser.
@ResponseBody
@RequestMapping("updateRoleUser")
@SystemLog(desc = "角色用户管理", opType = SysOpType.UPDATE, tableName = "sys_user_role")
public AjaxJson updateRoleUser(SysUserRole sysUserRole, @RequestParam(name = "opType", required = true, defaultValue = "0") int opType) {
AjaxJson resultMsg = new AjaxJson();
int userCode = sysUserRole.getUserId();
boolean result = false;
String msg = "";
SysRole sysRole = new SysRole(sysUserRole.getRoleId());
SysRole sysRole2 = null;
try {
sysRole2 = roleService.findOneForJdbc(sysRole);
} catch (Exception e) {
}
if (sysRole2 != null && sysRole2.getIfVisible() == 1) {
if ((opType == 1 || opType == -1) && (userCode > 0)) {
if (opType == 1) {
if (roleService.saveRoleUser(sysUserRole)) {
result = true;
msg = MessageConstant.MSG_OPERATION_SUCCESS;
} else {
msg = MessageConstant.MSG_OPERATION_FAILED;
}
} else {
if (sysUserRole.getRoleId() == 1 && sysUserRole.getUserId() == 1) {
msg = "错误提示:超级管理员账号不能删除";
} else {
if (roleService.delRoleUser(sysUserRole)) {
result = true;
msg = MessageConstant.MSG_OPERATION_SUCCESS;
} else {
msg = MessageConstant.MSG_OPERATION_FAILED;
}
}
}
}
} else {
msg = "错误提示:该角色尚未使用,无法操作";
}
resultMsg.setSuccess(result);
resultMsg.setMsg(msg);
return resultMsg;
}
use of com.cdeledu.model.rbac.SysRole in project wechat by dllwh.
the class RoleOperateController method saveRole.
@ResponseBody
@RequestMapping(value = "saveRole")
@SystemLog(desc = "角色更新", opType = SysOpType.UPDATE, tableName = "sys_role")
public AjaxJson saveRole(HttpServletRequest request, HttpServletResponse response, SysRole role) {
AjaxJson resultMsg = new AjaxJson();
String msg = "";
try {
if (null != role) {
String roleCode = role.getRoleCode();
SysRole seacherRole = roleService.getRoleById(role.getId());
if (seacherRole != null && seacherRole.getAllowEdit() == 1) {
// 角色允许编辑
if (seacherRole.getRoleCode().equalsIgnoreCase(roleCode)) {
if (seacherRole.getId() == 1) {
// 超级管理员不允许更新角色代码
role.setRoleCode("");
}
roleService.update(role);
} else {
if (roleService.existRoleWithRoleCode(roleCode)) {
resultMsg.setSuccess(false);
msg = MessageConstant.EXISTED;
} else {
roleService.update(role);
}
}
} else {
resultMsg.setSuccess(false);
resultMsg.setResultCode(201);
resultMsg.setMsg("该角色不允许更新");
}
}
} catch (Exception e) {
resultMsg.setSuccess(false);
resultMsg.setResultCode(500);
msg = MessageConstant.MSG_OPERATION_FAILED;
}
resultMsg.setMsg(msg);
return resultMsg;
}
Aggregations