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);
|
}
|
|
}
|
|
}
|