935090232@qq.com
2021-10-23 13cbb37d5a38ae764fbe78063de4af61511b33e2
zq-erp/src/main/java/com/matrix/system/hive/action/util/QueryUtil.java
@@ -5,6 +5,7 @@
import com.matrix.core.tools.LogUtil;
import com.matrix.core.tools.WebUtil;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.common.constance.AppConstance;
import java.lang.reflect.Method;
@@ -12,40 +13,44 @@
    /**
     * 为查询对象加上当前登录人的门店和公司查询限制
     *
     * @param queryObj
     */
    public static void setQueryLimit(Object queryObj) {
        SysUsers sysUsers = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY);
        Class<Object> objClazz = (Class<Object>) queryObj.getClass();
        try {
            Method setShopId = (Method) objClazz.getMethod("setShopId",Long.class);
            setShopId.invoke(queryObj, sysUsers.getShopId());
            Method setCompanyId = (Method) objClazz.getMethod("setCompanyId",Long.class);
            if (!AppConstance.USER_TYPE_ADMIN.equals(sysUsers.getSuUserType())) {
                Method setShopId = (Method) objClazz.getMethod("setShopId", Long.class);
                setShopId.invoke(queryObj, sysUsers.getShopId());
            }
            Method setCompanyId = (Method) objClazz.getMethod("setCompanyId", Long.class);
            setCompanyId.invoke(queryObj, sysUsers.getCompanyId());
        } catch (Exception e) {
            LogUtil.error(e.getMessage(), e);
            throw new GlobleException("系统参数错误007");
        }
    }
    /**
     * 限制数据公司id
     *
     * @param queryObj
     */
    public static void setQueryLimitCom(Object queryObj) {
        SysUsers sysUsers = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY);
        Class<Object> objClazz = (Class<Object>) queryObj.getClass();
        try {
            Method setCompanyId = (Method) objClazz.getMethod("setCompanyId",Long.class);
            Method setCompanyId = (Method) objClazz.getMethod("setCompanyId", Long.class);
            setCompanyId.invoke(queryObj, sysUsers.getCompanyId());
        } catch (Exception e) {
            LogUtil.error(e.getMessage(), e);
            throw new GlobleException("系统参数错误008");
        }
    }
}