zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
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
52
53
54
55
56
57
58
59
package com.changhong.epc.form.filter;
 
import com.changhong.autoform.core.filter.SelectSqlFilter;
import com.changhong.autoform.core.filter.UpdateSqlFilter;
import com.changhong.epc.config.sqlfilter.BaseParamSqlFilter;
import com.changhong.epc.config.sqlfilter.PowerSqlFilter;
import com.iemsoft.framework.cloud.core.tools.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
@Slf4j
public class MycatFilter {
    
    public static String filter(String sql){
        try{
            sql = sql.replace("MASTER_DEFINE", "epc_master_define_{rule}");
            sql = sql.replace("MASTER_ELEMENT", "epc_master_element_{rule}");
            sql = sql.replace("MASTER_VALUE", "epc_master_value_{rule}");
            sql = SpringUtil.getBean(BaseParamSqlFilter.class).filter(sql);
//            return (sql = String.format("/*!mycat:sql=select id from epc_tenant_info where id = 5*/ %s", sql));
            return sql;
        } finally {
            log.debug("表单客户端执行sql:{}", sql);
        }
    }
    
    @Component
    public static class SelectFilter implements SelectSqlFilter{
 
        @Resource
        private PowerSqlFilter powerSqlFilter;
 
        @Override
        public String filter(String sql) {
            try {
                log.debug("添加表单数据权限前:{}", sql);
                sql = powerSqlFilter.filter(sql);
                log.debug("添加表单数据权限后:{}", sql);
            }catch (Exception e){
                log.error(e.getMessage(), e);
            }
            return MycatFilter.filter(sql);
        }
        
    }
 
    @Component
    public static class UpdateFilter implements UpdateSqlFilter{
 
        @Override
        public String filter(String sql) {
            return MycatFilter.filter(sql);
        }
        
    }
    
}