Zhiqim Master(运营管理台)是在ZhiqimManager基础上改造成用于运营思路的管理系统,增加余额,和组织结构等,开放组织管理员,可以添加组织内的部门和角色和操作员。并增加该管理台上的一些组件,如充值支付等组件。适用于二级代理管理或该大型组织机构
森中灵 最后提交于7月前 替换为8.0.5版本
MenuAction.java9KB
/*
* 版权所有 (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.HttpSessionUser;
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.ones.IsNotEmpty;
import org.zhiqim.httpd.validate.onex.IsInteger;
import org.zhiqim.kernel.json.Jsons;
import org.zhiqim.kernel.model.tree.Tree;
import org.zhiqim.kernel.model.tree.TreeBuilder;
import org.zhiqim.kernel.util.Validates;
import org.zhiqim.manager.ZmrConstants;
import org.zhiqim.manager.ZmrSessionUser;
import org.zhiqim.manager.dao.ZmrOperatorDao;
import org.zhiqim.manager.dbo.ZmrMenu;
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-28 新建与整理
*/
public class MenuAction extends StdSwitchAction implements ZmrConstants
{
@Override
protected void validateId(HttpRequest request)
{
request.addValidate(new IsNotEmpty("menuCode", "请选中一个菜单编码"));
}
@Override
protected void validateForm(HttpRequest request)
{
request.addValidate(new IsNotEmpty("menuCode", "菜单编码不能为空,格式为MENU_开头的每3个数字和下划线组成的字符串"));
request.addValidate(new IsNotEmpty("parentCode", "父菜单编码不能为空"));
request.addValidate(new IsLen("menuName", "菜单名称不能为空且不能超过32个汉字", 1, 32));
request.addValidate(new IsIntegerValue("menuStatus", "菜单状态范围为[0, 2]之间", 0, 2));
request.addValidate(new IsIntegerValue("menuType", "菜单类型范围为[1, 2]之间", 1, 2));
request.addValidate(new IsInteger("menuLevel", "菜单级别必须是整数"));
}
@Override
protected void list(HttpRequest request) throws Exception
{
ZmrSessionUser sessionUser = request.getSessionUser(ZmrSessionUser.class);
if (sessionUser.getOperatorOrgId() != _ID_13_)
{
request.returnHistory("该功能不对外开放");
return;
}
List<ZmrMenu> menuList = null;
if (sessionUser.getOperatorType() == 0)
{//1.超级管理员(显示/隐藏/关闭)
menuList = ORM.table().list(ZmrMenu.class, new Selector().addOrderbyAsc("menuLevel, menuCode"));
}
else if (sessionUser.getOperatorType() == 1)
{//2.管理员(显示/隐藏)
menuList = ORM.table().list(ZmrMenu.class, new Selector().addMustThenLE("menuStatus", 1).addOrderbyAsc("menuLevel, menuCode"));
}
else
{//3.操作员(自己有权限的)
menuList = sessionUser.getMenuList();
}
//菜单列表转换为树型菜单
Tree<ZmrMenu> tree = TreeBuilder.newTree(menuList, "parentCode", "menuCode");
request.setAttribute("tree", tree);
}
@Override
protected void add(HttpRequest request) throws Exception
{
String menuCode = request.getParameter("menuCode");
ZmrMenu item = ORM.table().item(ZmrMenu.class, menuCode);
if (item == null)
{// 获取菜单信息
request.returnHistory("您选择的菜单不存在,请选择一个有效的菜单");
return;
}
request.setAttribute("parent", item);
}
@Override
protected void insert(HttpRequest request) throws Exception
{
String menuCode = request.getParameter("menuCode");
String parentCode = request.getParameter("parentCode");
if (!menuCode.startsWith(parentCode+"_"))
{
request.returnHistory("该菜单编号格式不对,没有从父菜单编码中继承");
return;
}
String code = menuCode.substring(parentCode.length()+1);
if (!Validates.isNumericLen(code, 3, 3))
{
request.returnHistory("该菜单编号格式不对,小编码为3位数字组成");
return;
}
if (ORM.table().count(ZmrMenu.class, menuCode) > 0)
{
request.returnHistory("该菜单编号已存在,请重选一个");
return;
}
//插入数据库
ZmrMenu menu = request.getParameter(ZmrMenu.class);
ORM.table().insert(menu);
//更新自己的会话
refreshSelf(request);
//增加操作日志
ZmrOperatorDao.addOperateLog(request, "增加系统菜单", Jsons.toString("menuCode", menuCode));
}
@Override
protected void modify(HttpRequest request) throws Exception
{
String menuCode = request.getParameter("menuCode");
ZmrMenu item = ORM.table().item(ZmrMenu.class, menuCode);
if (item == null)
{// 获取菜单信息
request.returnHistory("您选择的菜单不存在,请选择一个有效的菜单");
return;
}
if (item.getMenuLevel() == 0)
{
request.returnHistory("系统功能根菜单不支持修改");
return;
}
request.setAttribute("item", item);
}
@Override
protected void update(HttpRequest request) throws Exception
{
String menuCode = request.getParameter("menuCode");
if (ORM.table().count(ZmrMenu.class, menuCode) == 0)
{
request.returnHistory("你修改的菜单不存在,请选择有效的菜单进行修改");
return;
}
String menuName = request.getParameter("menuName");
int menuStatus = request.getParameterInt("menuStatus");
String menuNameAbbr = request.getParameter("menuNameAbbr");
int menuType = request.getParameterInt("menuType");
String menuIcon = request.getParameter("menuIcon");
String menuUrl = request.getParameter("menuUrl");
String menuDesc = request.getParameter("menuDesc");
//更新到数据库
Updater updater = new Updater();
updater.addMust("menuCode", menuCode);
updater.addField("menuName", menuName);
updater.addField("menuNameAbbr", menuNameAbbr);
updater.addField("menuStatus", menuStatus);
updater.addField("menuType", menuType);
updater.addField("menuIcon", menuIcon);
updater.addField("menuUrl", menuUrl);
updater.addField("menuDesc", menuDesc);
ORM.table().update(ZmrMenu.class, updater);
//刷新所有在线用户会话
refreshOnline(request);
//增加操作日志
ZmrOperatorDao.addOperateLog(request, "修改系统菜单", Jsons.toString("menuCode", menuCode));
}
@Override
protected void delete(HttpRequest request) throws Exception
{
String menuCode = request.getParameter("menuCode");
if (ORM.table().count(ZmrMenu.class, menuCode) == 0)
{
request.returnHistory("你修改的菜单不存在,请选择有效的菜单进行修改");
return;
}
if (ORM.table().count(ZmrMenu.class, new Selector("parentCode", menuCode)) > 0)
{
request.returnHistory("你修改的菜单有子菜单,请先删除子菜单");
return;
}
ORM.table().delete(ZmrMenu.class, menuCode);
//刷新所有在线用户会话
refreshOnline(request);
//增加操作日志
ZmrOperatorDao.addOperateLog(request, "删除系统菜单", Jsons.toString("menuCode", menuCode));
}
/*******************************************************************************/
//增加时刷新自己会话,修改&删除时所有在线用户会话
/*******************************************************************************/
/** 刷新自己会话 */
private void refreshSelf(HttpRequest request) throws Exception
{
ZmrSessionUser sessionUser = request.getSessionUser(ZmrSessionUser.class);
List<ZmrMenu> menuList = ZmrOperatorDao.getOperatorMenuList(sessionUser.getOperator());
sessionUser.setMenuList(menuList);
}
/** 刷新所有在线用户会话 */
private void refreshOnline(HttpRequest request) throws Exception
{
List<HttpSessionUser> sessionUserList = request.getContext().getSessionManager().getSessionUserList();
for (HttpSessionUser sessionUser : sessionUserList)
{
if (!(sessionUser instanceof ZmrSessionUser))
continue;
ZmrSessionUser sUser = (ZmrSessionUser)sessionUser;
List<ZmrMenu> menuList = ZmrOperatorDao.getOperatorMenuList(sUser.getOperator());
sUser.setMenuList(menuList);
}
}
}