Zhiqim Account(前端账户管理台)是在ZhiqimManager基础上改造成用于前端注册登录的管理系统,增加组织结构和余额,开放注册组织和组织管理员,可以添加组织内的部门和角色和操作员。并增加该管理台上的一些组件,如充值支付等组件。适用于二级代理管理或该大型组织机构
森中灵 最后提交于8月前 整理为组织方式和替换新的jar
ZmrOrgPresenter.java7KB
/*
* 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙,邂逅框架梦]
*
* https://zhiqim.org/project/zhiqim_components/zhiqim_account.htm
*
* Zhiqim Account 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.presenter;
import org.zhiqim.httpd.HttpRequest;
import org.zhiqim.httpd.context.annotation.AnIntercept;
import org.zhiqim.httpd.validate.ones.IsNotEmpty;
import org.zhiqim.httpd.validate.onex.IsAccountCode;
import org.zhiqim.httpd.validate.onex.IsAccountPass;
import org.zhiqim.httpd.validate.onex.IsIntegerPositive;
import org.zhiqim.httpd.validate.onex.IsMobile11;
import org.zhiqim.kernel.annotation.AnAlias;
import org.zhiqim.kernel.util.Ints;
import org.zhiqim.kernel.util.Randoms;
import org.zhiqim.kernel.util.Sqls;
import org.zhiqim.kernel.util.Validates;
import org.zhiqim.manager.ZmrConstants;
import org.zhiqim.manager.ZmrPassworder;
import org.zhiqim.manager.ZmrSessionUser;
import org.zhiqim.manager.dao.ZmrOperatorDao;
import org.zhiqim.manager.dao.ZmrOrgDao;
import org.zhiqim.manager.dao.ZmrParamDao;
import org.zhiqim.manager.dbo.ZmrOperator;
import org.zhiqim.manager.dbo.ZmrOrg;
import org.zhiqim.orm.ORM;
import org.zhiqim.orm.dbo.Selector;
import org.zhiqim.orm.dbo.Updater;
/**
* 组织控制器
*
* @version v1.0.0 @author liuhu 2018-8-10 新建与整理
*/
@AnAlias("ZmrOrgPresenter")
@AnIntercept("chkZmrLogin")
public class ZmrOrgPresenter implements ZmrConstants
{
/**
* 切换组织
*
* @param request 请求
* @throws Exception 异常
*/
public static void doSelectOrg(HttpRequest request) throws Exception
{
ZmrSessionUser sessionUser = request.getSessionUser(ZmrSessionUser.class);
ZmrOrg rootOrg = ORM.table().item(ZmrOrg.class, sessionUser.getOperatorOrgId());
if (rootOrg == null || rootOrg.getOrgStatus() != 0 || rootOrg.getOrgLevel() != 0)
{
request.setResponseError("您没有选择组织的权限");
return;
}
long orgId = request.getParameterLong("orgId");
if (orgId == -1)
{
request.setResponseError("请选择一个的组织");
return;
}
ZmrOrg org = ORM.table().item(ZmrOrg.class, orgId);
if (org == null || org.getOrgStatus() != 0)
{
request.setResponseError("请选择一个有效的组织");
return;
}
sessionUser.setSelectedOrgId(orgId);
sessionUser.setSelectedDeptId(0);
}
/**
* 添加超级管理员
* @param request
* @throws Exception
*/
public static void doInsertOrgAdmin(HttpRequest request) throws Exception
{
request.addValidate(new IsIntegerPositive("orgId", "请填写组织编号"));
request.addValidate(new IsNotEmpty("orgName", "请填写组织名称"));
request.addValidate(new IsIntegerPositive("orgType", "请选择组织类型"));
request.addValidate(new IsMobile11("operatorMobile", "请填写正确的管理员手机号"));
request.addValidate(new IsAccountCode("operatorCode", "管理员账号不能为空或格式不正确"));
request.addValidate(new IsAccountPass("operatorPass", "管理员密码要求6-16位的大小写字母和.@_#$符号"));
if (!request.chkValidate())
{
request.setResponseError(request.getAlertMsg());
return;
}
long orgId = request.getParameterLong("orgId");
if (orgId < _ID_13_ || orgId > 9999999999999L)
{
request.setResponseError("组织编号必须为13位数字");
return;
}
if (ZmrOrgDao.exists(orgId))
{//验证组织编号唯一性
request.setResponseError("组织编号已被使用,请重填");
return;
}
String orgName = request.getParameter("orgName");
if (ZmrOrgDao.exists(orgName))
{//验证组织名称唯一性
request.setResponseError("组织名称已被使用,请重填");
return;
}
long orgType = request.getParameterLong("orgType");
String operatorMobile = request.getParameter("operatorMobile");
String operatorCode = request.getParameter("operatorCode");
String operatorPass = request.getParameter("operatorPass");
ZmrSessionUser sessionUser = request.getSessionUser(ZmrSessionUser.class);
if (!sessionUser.isSuperAdmin())
{
request.setResponseError("您没有添加组织的权限");
return;
}
if (!Validates.isFileName(operatorCode))
{//验证用户名是否符合目录和文件名定义
request.setResponseError("管理员账号不合法,请重填");
return;
}
if (ZmrOperatorDao.exists(operatorCode))
{//验证用户名唯一性
request.setResponseError("登录账号已被使用,请重新输入");
return;
}
boolean operatorMobileLogin = true;
if (ORM.table().count(ZmrOperator.class, new Selector("operatorMobile", operatorMobile).addMust("operatorMobileLogin", true)) > 0)
{//验证手机号是否可以作为登录名
operatorMobileLogin = false;
}
ZmrOrg org = new ZmrOrg();
org.setOrgId(orgId);
org.setOrgName(orgName);
org.setOrgStatus(0);
org.setOrgLevel(1);
org.setOrgTypes(_EMPTY_ + orgType);
org.setOrgBalance(0);
org.setOrgBalanceGift(0);
org.setOrgVip(ZmrParamDao.getString(ZMR_NAME, ZMR_DEFAULT_VIP));
org.setOrgCreated(Sqls.nowTimestamp());
ZmrOperator operator = new ZmrOperator();
operator.setOrgId(org.getOrgId());
operator.setOperatorCode(operatorCode);
operator.setOperatorPassSalt(Randoms.lettersDigitsSecure(64));
operator.setOperatorPass(ZmrPassworder.encode(operator.getOperatorCode(), operatorPass, operator.getOperatorPassSalt()));
operator.setOperatorType(1);
operator.setOperatorValid(true);
operator.setOperatorName(operator.getOperatorCode());
operator.setOperatorMobile(operatorMobile);
operator.setOperatorMobileLogin(operatorMobileLogin);
operator.setOperatorAvatar(_ID_13_ + Ints.toInt(Randoms.digits(1)));
operator.setOperatorCreated(org.getOrgCreated());
operator.setOperatorModified(org.getOrgCreated());
operator.setOperatorLogined(org.getOrgCreated());
ORM.table().insert(org);
ORM.table().replace(operator);
}
/** 保存默认支付方式 */
public static void doSavePayment(HttpRequest request)throws Exception
{
String paymentCode = request.getParameter("paymentCode");
ZmrSessionUser sessionUser = request.getSessionUser(ZmrSessionUser.class);
long orgId = sessionUser.getOperator().getOrgId();
Updater updater = new Updater();
updater.addMust("orgId", orgId);
updater.addField("orgPayment", paymentCode);
ORM.table().update(ZmrOrg.class, updater);
}
}