Search in sources :

Example 6 with AjaxJson

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

the class MenuOperateController method delMenu.

/**
 * @方法描述: 删除菜单,根据ID,但是删除权限的时候,需要查询是否有赋予给角色,如果有角色在使用,那么就不能删除。
 * @param menu
 * @return
 */
@ResponseBody
@RequestMapping(value = "del")
@SystemLog(desc = "删除权限菜单", opType = SysOpType.DEL, tableName = "sys_menu,sys_role_menu")
public AjaxJson delMenu(SysMenu sysMenu) {
    AjaxJson ajaxJson = new AjaxJson();
    try {
        Integer id = sysMenu.getId();
        SysMenu menu = sysMenuService.findOneById(id);
        if (menu != null && menu.getAllowDelete() == 1) {
            // 删除权限菜单时先删除权限菜单与角色之间关联表信息
            if (sysMenuService.hasRole(id)) {
                ajaxJson.setSuccess(false);
                ajaxJson.setMsg(MessageConstant.MSG_HAS_CHILD);
            } else {
                if (sysMenuService.hasChildren(id)) {
                    // 子节点
                    ajaxJson.setSuccess(false);
                    ajaxJson.setMsg(MessageConstant.MSG_HAS_CHILD);
                } else {
                    sysMenuService.delete(id);
                    ajaxJson.setMsg(MessageConstant.SUCCESS_DELETE_MESSAGE);
                }
            }
        } else {
            ajaxJson.setSuccess(false);
            ajaxJson.setMsg(MessageConstant.SUCCESS_DELETE_MESSAGE);
        }
    } catch (Exception e) {
        ajaxJson.setSuccess(false);
        ajaxJson.setResultCode(500);
        ajaxJson.setMsg(MessageConstant.FAILURE_DELETE_MESSAGE);
    }
    return ajaxJson;
}
Also used : SysMenu(com.cdeledu.model.rbac.SysMenu) 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 7 with AjaxJson

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

the class RoleOperateController method addRole.

/**
 * ----------------------------------------------------- Fields end
 */
/**
 * @方法描述 : 角色创建的时候,必须要自动添加到管理员下,保证管理员的权限是最大最全的
 * @param role
 * @return
 */
@ResponseBody
@RequestMapping(value = "addRole", method = RequestMethod.POST)
@SystemLog(desc = "角色添加", opType = SysOpType.INSERT, tableName = "sys_role")
public AjaxJson addRole(SysRole role) {
    AjaxJson resultMsg = new AjaxJson();
    try {
        if (roleService.existRoleWithRoleCode(role.getRoleCode())) {
            resultMsg.setSuccess(false);
            resultMsg.setMsg(MessageConstant.EXISTED);
            resultMsg.setResultCode(201);
        } else {
            roleService.insert(role);
        }
    } catch (Exception e) {
        e.printStackTrace();
        resultMsg.setSuccess(false);
        resultMsg.setMsg(MessageConstant.FAILURE_SAVE_MESSAGE);
        resultMsg.setResultCode(500);
    }
    return resultMsg;
}
Also used : 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 8 with AjaxJson

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

the class RoleOperateController method updateMenuByRole.

@ResponseBody
@RequestMapping(value = "updateMenuByRole")
@SystemLog(desc = "更新角色的权限", opType = SysOpType.UPDATE, tableName = "sys_role_menu")
public AjaxJson updateMenuByRole(Integer roleId, String ids) {
    AjaxJson ajaxJson = new AjaxJson();
    if (roleId != null && StringUtils.isNoneBlank(ids)) {
        if (roleId != 1) {
            roleService.delRoleAccess(roleId);
            String[] str = ids.split(",");
            for (int i = 0; i < str.length; i++) {
                try {
                    roleService.saveRoleAccess(roleId, Integer.parseInt(str[i]));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else {
            ajaxJson.setSuccess(false);
            ajaxJson.setResultCode(10005);
            ajaxJson.setMsg("该资源需要appkey拥有授权");
        }
    } else {
        ajaxJson.setSuccess(false);
        ajaxJson.setResultCode(10006);
        ajaxJson.setMsg("缺少source (appkey) 参数");
    }
    return ajaxJson;
}
Also used : 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 9 with AjaxJson

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

the class SysUserOperateController method delUser.

/**
 * @方法描述: 用户删除
 * @创建者: 皇族灬战狼
 * @创建时间: 2016年9月27日 下午4:51:19
 * @param managerUser
 * @param request
 * @return
 */
@ResponseBody
@RequestMapping(value = "deleteUser")
public AjaxJson delUser(@RequestParam(value = "id", required = true, defaultValue = "-1") Integer id) {
    AjaxJson resultMsg = new AjaxJson();
    try {
        if (id != 1) {
            SysUser sysUser = new SysUser();
            sysUser.setId(id);
            List<SysUserRole> userRoleList = manageruserService.getUserRole(sysUser);
            if (userRoleList == null || userRoleList.isEmpty() || userRoleList.size() == 0) {
                manageruserService.delete(id);
                resultMsg.setMsg(MessageConstant.MSG_OPERATION_SUCCESS);
            } else {
                resultMsg.setSuccess(false);
                resultMsg.setMsg("删除失败,该用户已分配角色");
            }
        } else {
            resultMsg.setSuccess(false);
            resultMsg.setResultCode(403);
            resultMsg.setMsg("无法删除超级管理员账号");
        }
    } catch (Exception e) {
        resultMsg.setSuccess(false);
        resultMsg.setResultCode(10001);
        resultMsg.setMsg(MessageConstant.MSG_OPERATION_SUCCESS);
    }
    return resultMsg;
}
Also used : SysUser(com.cdeledu.model.rbac.SysUser) AjaxJson(com.cdeledu.common.base.AjaxJson) SysUserRole(com.cdeledu.model.rbac.SysUserRole) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with AjaxJson

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

the class SysUserOperateController method updateUserDisable.

@ResponseBody
@RequestMapping("disable")
@SystemLog(desc = " 禁用账户", opType = SysOpType.UPDATE, tableName = { "sys_user" })
public AjaxJson updateUserDisable(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(0);
            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)

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