Zhiqim Master(运营管理台)是在ZhiqimManager基础上改造成用于运营思路的管理系统,增加余额,和组织结构等,开放组织管理员,可以添加组织内的部门和角色和操作员。并增加该管理台上的一些组件,如充值支付等组件。适用于二级代理管理或该大型组织机构
森中灵 最后提交于7月前 替换为8.0.5版本
OrgAction.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 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.kernel.transaction.Transaction;
import org.zhiqim.kernel.transaction.TransactionManager;
import org.zhiqim.kernel.util.Ids;
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.dao.ZmrOrgDao;
import org.zhiqim.manager.dbo.ZmrDept;
import org.zhiqim.manager.dbo.ZmrDeptRule;
import org.zhiqim.manager.dbo.ZmrDeptType;
import org.zhiqim.manager.dbo.ZmrOperator;
import org.zhiqim.manager.dbo.ZmrOrg;
import org.zhiqim.manager.dbo.ZmrRole;
import org.zhiqim.manager.dbo.ZmrRoleRule;
import org.zhiqim.orm.ORM;
import org.zhiqim.orm.dbo.Selector;
import org.zhiqim.orm.dbo.Updater;
/**
* 组织管理
*
* @version v1.0.0 @author zzy 2018-5-30 新建与整理
*/
public class OrgAction extends StdSwitchAction implements ZmrConstants
{
@Override
protected void validateId(HttpRequest request)
{
request.addValidate(new IsInteger("orgId", "请选择一个选项"));
}
@Override
protected void validateForm(HttpRequest request)
{
request.addValidate(new IsLen("orgName", "组织名称不能为空且不能超过32个汉字", 1, 32));
request.addValidate(new IsIntegerValue("orgSeq", "组织排序必须是[0, 999999]范围的非负整数", 0, 999999));
request.addValidate(new IsLen("orgDesc", "组织描述可为空或不能超过100个汉字", 0, 100));
}
@Override
protected void list(HttpRequest request) throws Exception
{
request.setAttribute("list", ZmrOrgDao.list());
}
@Override
protected void add(HttpRequest request) throws Exception
{
ZmrOrg parent = ORM.table().item(ZmrOrg.class, new Selector("orgLevel", 0));
if (parent == null)
{
request.returnHistory("上级组织不存在,请选择正确的组织");
return;
}
request.setAttribute("parent", parent);
}
@Override
protected void modify(HttpRequest request) throws Exception
{
long orgId = request.getParameterLong("orgId");
ZmrOrg org = ORM.table().item(ZmrOrg.class, orgId);
if (org == null)
{
request.returnHistory("组织不存在,请选择正确的组织");
return;
}
request.setAttribute("org", org);
}
@Override
protected void insert(HttpRequest request) throws Exception
{
ZmrOrg org = request.getParameter(ZmrOrg.class);
org.setOrgId(Ids.longId13());
org.setOrgLevel(1);
//插入部门类型
ZmrDeptType type = new ZmrDeptType();
type.setOrgId(org.getOrgId());
type.setDeptType(_ID_13_);
type.setDeptTypeName("通用");
type.setDeptTypeValid(true);
type.setDeptTypeSeq(0);
type.setDeptTypeSys(true);
//插入部门
ZmrDept dept = new ZmrDept();
dept.setOrgId(org.getOrgId());
dept.setParentId(0);
dept.setDeptId(_ID_13_);
dept.setDeptName(org.getOrgName());
dept.setDeptType(_ID_13_);
dept.setDeptValid(true);
dept.setDeptLevel(0);
dept.setDeptParentAll("0");
//插入角色
ZmrRole role = new ZmrRole();
role.setOrgId(org.getOrgId());
role.setRoleId(_ID_13_);
role.setRoleName("管理员");
role.setRoleSys(true);
role.setRoleValid(true);
role.setRoleSeq(0);
Transaction tx = TransactionManager.beginTransaction();
try
{
ORM.table().insert(type);
ORM.table().insert(org);
ORM.table().insert(dept);
ORM.table().insert(role);
tx.commit();
}
catch (Exception e)
{
tx.rollback();
request.returnHistory("保存组织异常:"+ e.getMessage());
return;
}
finally
{
tx.close();
}
//增加操作日志
ZmrOperatorDao.addOperateLog(request, "增加组织", Jsons.toString(org));
}
@Override
protected void update(HttpRequest request) throws Exception
{
long orgId = request.getParameterLong("orgId");
ZmrOrg org = ORM.table().item(ZmrOrg.class, new Selector("orgId", orgId));
String orgName = request.getParameter("orgName");
int orgStatus = request.getParameterInt("orgStatus");
int orgSeq = request.getParameterInt("orgSeq");
String orgManager = request.getParameter("orgManager");
String orgDesc = request.getParameter("orgDesc");
Updater updater = new Updater();
updater.addMust("orgId", orgId);
updater.addField("orgName", orgName);
updater.addField("orgStatus", orgStatus);
updater.addField("orgSeq", orgSeq);
updater.addField("orgManager", orgManager);
updater.addField("orgDesc", orgDesc);
ORM.table().update(ZmrOrg.class, updater);
//将组织负责人的级别提升为管理员
if(Validates.isNotEmpty(orgManager))
{
Updater operatorUpdater = new Updater();
operatorUpdater.addMust("operatorCode", orgManager);
operatorUpdater.addField("operatorType", 1);
ORM.table().update(ZmrOperator.class, operatorUpdater);
}
//更换负责人,将原来负责人的权限降为操作员
String oldOrgManager = org.getOrgManager();
if(Validates.isNotEmpty(oldOrgManager))
{
if(!oldOrgManager.equals(orgManager)){
Updater operatorUpdater = new Updater();
operatorUpdater.addMust("operatorCode", oldOrgManager);
operatorUpdater.addField("operatorType", 2);
ORM.table().update(ZmrOperator.class, operatorUpdater);
}
}
//增加操作日志
ZmrOperatorDao.addOperateLog(request, "修改组织", Jsons.toString("orgId", orgId));
}
@Override
protected void delete(HttpRequest request) throws Exception
{
ZmrSessionUser sessionUser = request.getSessionUser(ZmrSessionUser.class);
long orgId = request.getParameterLong("orgId");
if (sessionUser.getSelectedOrgId() == orgId)
{
request.returnHistory("当前选中组织不能删除,请先切换组织");
return;
}
ZmrOrg org = ORM.table().item(ZmrOrg.class, orgId);
if (org == null)
{
request.returnHistory("组织不存在,请选择正确的组织");
return;
}
if (org.getOrgLevel() == 0)
{
request.returnHistory("顶级组织不能删除,只允许修改");
return;
}
if (ORM.table().count(ZmrDept.class, new Selector("orgId", orgId).addMustNotEqual("deptId", _ID_13_)) > 0)
{
request.returnHistory("该组织已有部门,要先删除部门(根部门除外)才能删除本组织");
return;
}
if (ORM.table().count(ZmrRole.class, new Selector("orgId", orgId).addMustNotEqual("roleId", _ID_13_)) > 0)
{
request.returnHistory("该组织已有角色,要先删除角色才能删除本组织");
return;
}
if (ORM.table().count(ZmrOperator.class, new Selector().addMust("orgId", orgId).addMustThenG("operatorType", 1)) > 0)
{
request.returnHistory("该组织已有操作员,请删除组织成员后再删除本组织");
return;
}
//清除组织部门、角色和操作员
ORM.table().delete(ZmrDept.class, new Selector("orgId", orgId));
ORM.table().delete(ZmrDeptType.class, new Selector("orgId", orgId));
ORM.table().delete(ZmrDeptRule.class, new Selector("orgId", orgId));
ORM.table().delete(ZmrRole.class, new Selector("orgId", orgId));
ORM.table().delete(ZmrRoleRule.class, new Selector("orgId", orgId));
ORM.table().delete(ZmrOperator.class, new Selector("orgId", orgId));
ORM.table().delete(ZmrOrg.class, orgId);
//增加操作日志
ZmrOperatorDao.addOperateLog(request, "删除组织", Jsons.toString("orgId", orgId));
}
}