Search in sources :

Example 31 with AjaxJson

use of com.cdeledu.common.base.AjaxJson 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;
}
Also used : SysRole(com.cdeledu.model.rbac.SysRole) AjaxJson(com.cdeledu.common.base.AjaxJson) SystemLog(com.cdeledu.core.annotation.SystemLog) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 32 with AjaxJson

use of com.cdeledu.common.base.AjaxJson 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;
}
Also used : SysRole(com.cdeledu.model.rbac.SysRole) AjaxJson(com.cdeledu.common.base.AjaxJson) SystemLog(com.cdeledu.core.annotation.SystemLog) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with AjaxJson

use of com.cdeledu.common.base.AjaxJson in project wechat by dllwh.

the class SysUserOperateController method updateUser.

/**
 * @方法描述: 用户更新
 * @创建者: 皇族灬战狼
 * @创建时间: 2016年9月27日 下午4:51:23
 * @param managerUser
 * @param request
 * @return
 */
@ResponseBody
@RequestMapping(value = "updateUser")
public AjaxJson updateUser(SysUser managerUser) {
    AjaxJson resultMsg = new AjaxJson();
    try {
        if (managerUser != null && managerUser.getId() != null) {
            // 不能更新username
            managerUser.setUserName(null);
            manageruserService.update(managerUser);
            resultMsg.setMsg(MessageConstant.MSG_OPERATION_SUCCESS);
        } else {
            resultMsg.setSuccess(false);
            resultMsg.setResultCode(10017);
            resultMsg.setMsg("缺失必选参数 (%s)");
        }
    } catch (Exception e) {
        resultMsg.setSuccess(false);
        resultMsg.setResultCode(500);
        resultMsg.setMsg(MessageConstant.MSG_OPERATION_FAILED);
    }
    return resultMsg;
}
Also used : AjaxJson(com.cdeledu.common.base.AjaxJson) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 34 with AjaxJson

use of com.cdeledu.common.base.AjaxJson in project wechat by dllwh.

the class SysUserOperateController method updateUserEnable.

@ResponseBody
@RequestMapping("enable")
@SystemLog(desc = " 启用账户", opType = SysOpType.UPDATE, tableName = { "sys_user" })
public AjaxJson updateUserEnable(int userId) {
    AjaxJson resultMsg = new AjaxJson();
    SysUser user = new SysUser();
    user.setId(userId);
    try {
        SysUser sysUser = manageruserService.findOneForJdbc(user);
        // 超级管理员不能操作
        if (sysUser != null && sysUser.getUserType() != -1 && WebUtilHelper.getCurrentUserId() != userId) {
            sysUser.setIfVisible(1);
            manageruserService.update(sysUser);
        }
        resultMsg.setMsg(MessageConstant.MSG_OPERATION_SUCCESS);
    } catch (Exception e) {
        e.printStackTrace();
        resultMsg.setSuccess(false);
        resultMsg.setResultCode(500);
        resultMsg.setMsg(MessageConstant.MSG_OPERATION_FAILED);
    }
    return resultMsg;
}
Also used : SysUser(com.cdeledu.model.rbac.SysUser) AjaxJson(com.cdeledu.common.base.AjaxJson) SystemLog(com.cdeledu.core.annotation.SystemLog) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with AjaxJson

use of com.cdeledu.common.base.AjaxJson in project wechat by dllwh.

the class SysUserOperateController method saveRoleUser.

/**
 * @方法描述: 用户-角色录入
 * @创建者: 皇族灬战狼
 * @创建时间: 2016年9月27日 下午4:51:27
 * @param managerUser
 * @param request
 * @return
 */
@ResponseBody
@RequestMapping(value = "roleAssign", params = "saveRoleUser")
@SystemLog(desc = "用户-角色录入(授权)", opType = SysOpType.INSERT, tableName = "sys_user_role")
public AjaxJson saveRoleUser(@RequestParam(value = "userCode", required = true) int id, @RequestParam(value = "roleID", defaultValue = "1", required = false) int roleID) {
    AjaxJson resultMsg = new AjaxJson();
    SysUser user = new SysUser();
    user.setId(id);
    try {
        if (roleID == 1) {
            // 超级管理员不参与分配
            resultMsg.setSuccess(false);
            resultMsg.setMsg("无法授予权限");
        }
        SysUser tSUser = manageruserService.findOneForJdbc(user);
        if (null == tSUser) {
            resultMsg.setMsg("不存在");
            resultMsg.setSuccess(false);
        } else {
            SysUserRole managerUserRole = new SysUserRole();
            managerUserRole.setUserId(tSUser.getId());
            managerUserRole.setRoleId(roleID);
            manageruserService.saveRoleUser(managerUserRole);
        }
    } catch (Exception e) {
        resultMsg.setResultCode(500);
        resultMsg.setMsg("分配角色时出现异常");
        resultMsg.setSuccess(false);
    }
    return resultMsg;
}
Also used : SysUser(com.cdeledu.model.rbac.SysUser) AjaxJson(com.cdeledu.common.base.AjaxJson) SysUserRole(com.cdeledu.model.rbac.SysUserRole) SystemLog(com.cdeledu.core.annotation.SystemLog) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AjaxJson (com.cdeledu.common.base.AjaxJson)46 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)44 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)33 SystemLog (com.cdeledu.core.annotation.SystemLog)25 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)12 SysUser (com.cdeledu.model.rbac.SysUser)8 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)6 SysRole (com.cdeledu.model.rbac.SysRole)4 SysMenu (com.cdeledu.model.rbac.SysMenu)3 SysUserRole (com.cdeledu.model.rbac.SysUserRole)2 SysIcon (com.cdeledu.model.system.SysIcon)1 Map (java.util.Map)1 HttpSession (javax.servlet.http.HttpSession)1 AuthenticationException (org.apache.shiro.authc.AuthenticationException)1 DisabledAccountException (org.apache.shiro.authc.DisabledAccountException)1 ExcessiveAttemptsException (org.apache.shiro.authc.ExcessiveAttemptsException)1 ExpiredCredentialsException (org.apache.shiro.authc.ExpiredCredentialsException)1 IncorrectCredentialsException (org.apache.shiro.authc.IncorrectCredentialsException)1 LockedAccountException (org.apache.shiro.authc.LockedAccountException)1 UnknownAccountException (org.apache.shiro.authc.UnknownAccountException)1