jyy
2021-01-26 ab2879bbcb846256cc182198b9c04e50fbc276c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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 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<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);
            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);
            setCompanyId.invoke(queryObj, sysUsers.getCompanyId());
        } catch (Exception e) {
            LogUtil.error(e.getMessage(), e);
            throw new GlobleException("系统参数错误008");
        }
    }
 
 
 
 
}