package com.changhong.epc.config.tool;
|
|
import com.changhong.epc.constter.system.RestParamConst;
|
import com.changhong.ssc.data.autho.base.struct.Condition;
|
import com.changhong.ssc.data.autho.base.struct.DataPermission;
|
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
|
|
import java.util.Collection;
|
|
/**
|
* 获得权限条件数据
|
* @author WangYX
|
*
|
*/
|
@FunctionalInterface
|
public interface PowerParam extends RestParamConst {
|
|
String getValue(String key);
|
|
default String getSql(Collection<Condition> powerDatas, String alias, String tableName){
|
if(ObjectUtil.empty(powerDatas)){
|
return "";
|
}
|
StringBuilder param = new StringBuilder();
|
String sql;
|
for(Condition power : powerDatas){
|
if(param.length() == 0){
|
param.append(getSql(power, alias, tableName));
|
}else{
|
sql = getSql(power, alias, tableName);
|
if(ObjectUtil.notEmpty(sql)){
|
param.append(" AND ")
|
.append(sql);
|
}
|
}
|
}
|
return param.toString();
|
}
|
|
/**
|
* 获得条件sql
|
* @param alias
|
* @return
|
*/
|
default String getSql(DataPermission powerData, String alias, String tableName){
|
if(ObjectUtil.empty(powerData.getConditions())){
|
return "";
|
}
|
StringBuilder param = new StringBuilder();
|
for(Condition con : powerData.getConditions()){
|
if(param.length() == 0){
|
param.append(getSql(con, alias, tableName));
|
}else{
|
param.append(" AND ")
|
.append(getSql(con, alias, tableName));
|
}
|
}
|
return param.toString();
|
}
|
|
default String getSql(Condition con, String alias, String tableName){
|
// Assert.condition(con.getOperator() == null, new IEMRuntimeException().setchildIEMExc("operator == null"));
|
con.setValue(getValue(con.getValue()));
|
return Operator.values()[con.getOperator()].getSql(con, alias, tableName);
|
}
|
}
|