Zhiqim Master(运营管理台)是在ZhiqimManager基础上改造成用于运营思路的管理系统,增加余额,和组织结构等,开放组织管理员,可以添加组织内的部门和角色和操作员。并增加该管理台上的一些组件,如充值支付等组件。适用于二级代理管理或该大型组织机构

森中灵 最后提交于7月前 替换为8.0.5版本
RoleAction.java5KB
/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
 * 
 * https://zhiqim.org/project/zhiqim_components/zhiqim_master.htm
 *
 * Zhiqim Master is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package org.zhiqim.manager.action;

import java.util.List;

import org.zhiqim.httpd.HttpRequest;
import org.zhiqim.httpd.context.extend.StdSwitchAction;
import org.zhiqim.httpd.validate.ones.IsIntegerValue;
import org.zhiqim.httpd.validate.ones.IsLen;
import org.zhiqim.httpd.validate.onex.IsInteger;
import org.zhiqim.kernel.json.Jsons;
import org.zhiqim.manager.ZmrConstants;
import org.zhiqim.manager.ZmrSessionUser;
import org.zhiqim.manager.dao.ZmrOperatorDao;
import org.zhiqim.manager.dbo.ZmrOperator;
import org.zhiqim.manager.dbo.ZmrRole;
import org.zhiqim.orm.ORM;
import org.zhiqim.orm.dbo.Selector;
import org.zhiqim.orm.dbo.Updater;

/**
 * 角色管理
 *
 * @version v1.0.0 @author zouzhigang 2015-5-29 新建与整理
 */
public class RoleAction extends StdSwitchAction implements ZmrConstants
{

    @Override
    protected void validateId(HttpRequest request)
    {
        request.addValidate(new IsInteger("roleId", "请选择一个角色"));
    }

    @Override
    protected void validateForm(HttpRequest request)
    {
        request.addValidate(new IsInteger("roleId", "请选择一个角色"));
        request.addValidate(new IsLen("roleName", "角色名称不能为空且不能超过32个汉字", 1, 32));
        request.addValidate(new IsIntegerValue("roleSeq", "角色排序必须是[0, 999999]范围的非负整数", 0, 999999));
    }

    @Override
    protected void list(HttpRequest request) throws Exception
    {
        ZmrSessionUser sessionUser = request.getSessionUser(ZmrSessionUser.class);
        long orgId = sessionUser.getSelectedOrgId();
        
        List<ZmrRole> list = ORM.table().list(ZmrRole.class, new Selector("orgId", orgId).addOrderbyAsc("roleSeq"));
        request.setAttribute("list", list);
    }

    @Override
    protected void insert(HttpRequest request) throws Exception
    {
        ZmrRole item = request.getParameter(ZmrRole.class);
        item.setOrgId(request.getSessionUser(ZmrSessionUser.class).getSelectedOrgId());
        item.setRoleValid(true);
        item.setRoleSys(false);
        ORM.table().insert(item);
        
        //增加操作日志
        ZmrOperatorDao.addOperateLog(request, "增加操作员角色", Jsons.toString(item));
    }

    @Override
    protected void modify(HttpRequest request) throws Exception
    {
        long orgId = request.getSessionUser(ZmrSessionUser.class).getSelectedOrgId();
        long roleId = request.getParameterLong("roleId");
        ZmrRole item = ORM.table().item(ZmrRole.class, orgId, roleId);
        if (item == null)
        {
            request.returnHistory("角色不存在,请选择正确的角色");
            return;
        }
        
        request.setAttribute("item", item);
    }

    @Override
    protected void update(HttpRequest request) throws Exception
    {
        long orgId = request.getSessionUser(ZmrSessionUser.class).getSelectedOrgId();
        ZmrRole item = request.getParameter(ZmrRole.class);
        
        Updater updater = new Updater();
        updater.addMust("roleId", item.getOrgId());
        updater.addMust("orgId", orgId);
        updater.addField("roleName", item.getRoleName());
        updater.addField("roleValid", item.isRoleValid());
        updater.addField("roleSeq", item.getRoleSeq());
        ORM.table().update(item);
        
        //增加操作日志
        ZmrOperatorDao.addOperateLog(request, "修改操作员角色", Jsons.toString(item));
    }

    @Override
    protected void delete(HttpRequest request) throws Exception
    {
        long roleId = request.getParameterLong("roleId");
        if (roleId == _ID_13_)
        {
            request.returnHistory("管理员角色是系统默认角色,不能删除");
            return;
        }
        
        ZmrSessionUser sessionUser = request.getSessionUser(ZmrSessionUser.class);
        long orgId = sessionUser.getSelectedOrgId();
        
        if (ORM.table().count(ZmrRole.class, orgId, roleId) == 0)
        {
            request.returnHistory("请选择一个有效的角色");
            return;
        }
        
        if (ORM.table().count(ZmrOperator.class, new Selector("orgId", orgId).addMustLike("operatorRole", roleId)) > 0)
        {
            request.returnHistory("该角色已有操作员,请删除角色成员后再删除本角色");
            return;
        }
        
        ORM.table().delete(ZmrRole.class, orgId, roleId);
        
        //增加操作日志
        ZmrOperatorDao.addOperateLog(request, "删除操作员角色", Jsons.toString("roleId", roleId));
    }
}