package com.matrix.system.hive.action.util; import com.matrix.core.constance.MatrixConstance; import com.matrix.core.exception.GlobleException; 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; public class QueryUtil { /** * 为查询对象加上当前登录人的门店和公司查询限制 * * @param queryObj */ public static void setQueryLimit(Object queryObj) { SysUsers sysUsers = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); Class objClazz = (Class) queryObj.getClass(); try { 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 objClazz = (Class) queryObj.getClass(); try { 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"); } } }