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

森中灵 最后提交于9月前 整理为组织方式和替换新的jar
ZmrDeptDao.java4KB
/*
 * 版权所有 (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.dao;

import java.sql.SQLException;
import java.util.List;

import org.zhiqim.httpd.HttpRequest;
import org.zhiqim.kernel.annotation.AnAlias;
import org.zhiqim.kernel.model.tree.Tree;
import org.zhiqim.kernel.model.tree.TreeBuilder;
import org.zhiqim.kernel.util.Arrays;
import org.zhiqim.kernel.util.Validates;
import org.zhiqim.manager.dbo.ZmrDept;
import org.zhiqim.manager.dbo.ZmrOperator;
import org.zhiqim.orm.ORM;
import org.zhiqim.orm.ORMException;
import org.zhiqim.orm.dbo.Selector;
import org.zhiqim.orm.dbo.Updater;

/**
 * 部门数据访问对象
 *
 * @version v1.0.0 @author zouzhigang 2017-8-23 新建与整理
 */
@AnAlias("ZmrDeptDao")
public class ZmrDeptDao
{
    /**
     * 获取组织下部门列表,根据部门级别、部门排序数、部门ID排序
     * 
     * @param orgId         组织编号
     * @return              部门列表
     * @throws ORMException ORM异常
     * @throws SQLException SQL异常
     */
    public static List<ZmrDept> list(long orgId) throws ORMException, SQLException
    {
        return ORM.table().list(ZmrDept.class, new Selector("orgId", orgId).addOrderbyAsc("deptLevel,deptSeq,deptId"));
    }
    
    /**
     * 获取组织下部门树,根据部门级别、部门排序数、部门ID排序
     * 
     * @param orgId         组织编号
     * @return              部门列表
     * @throws ORMException ORM异常
     * @throws SQLException SQL异常
     */
    public static Tree<ZmrDept> tree(long orgId) throws ORMException, SQLException
    {
        return TreeBuilder.newTree(list(orgId), "parentId", "deptId");
    }
    
    /**
     * 通过编号查部门名称
     * @param deptId
     * @return
     */
    public static String getDeptNameById(long deptId)
    {
        try
        {
            ZmrDept dept = ORM.table().item(ZmrDept.class, deptId);
            if (dept != null)
                return dept.getDeptName();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        
        return "";
    }
    
    /**
     * 更新部门负责人所属部门
     * @param request           请求对象
     * @param operatorCodeList  操作员编码列表
     * @param deptId            部门编码
     * @param deptParentAll     部门所有父节点
     * @throws Exception
     */
    public static void doUpdateDeptManeger(HttpRequest request, List<String> operatorCodeList, String deptId, String deptParentAll) throws Exception
    {
        for (String operatorCode : operatorCodeList)
        {
            ZmrOperator operator = ZmrOperatorDao.item(operatorCode);
            if(operator == null)
            {
                request.returnHistory("用户不存在");
                return;
            }
            
            String operatorDept = operator.getOperatorDept();
            if (Validates.isEmptyBlank(operatorDept))
                operatorDept = deptId;
            else
                operatorDept += "," + deptId;
            
            String operatorDeptAll = operator.getOperatorDeptAll();
            if (Validates.isEmptyBlank(operatorDeptAll))
                operatorDeptAll = deptParentAll + "," + deptId;
            else
                operatorDeptAll += "," + deptParentAll + "," + deptId;
            
            //去重
            operatorDept = Arrays.toFilterSameStr(Arrays.toStringArray(operatorDept));
            operatorDeptAll = Arrays.toFilterSameStr(Arrays.toStringArray(operatorDeptAll));
            
            Updater updater = new Updater();
            updater.addMust("operatorCode", operator.getOperatorCode());
            updater.addField("operatorDept", operatorDept);
            updater.addField("operatorDeptAll", operatorDeptAll);
            
            ORM.table().update(ZmrOperator.class, updater);
        }
    }
    
    
}