测试接口
http://localhost:5901/bo/api/v3/db/help/sql/regex?ownerId=bt&_sysId=abcded&ignore=true&a=2
{
"value":"select * from tb where and {s-if:b}bab{e-if:b}{s-if:a}{op-eq:1} bb {op-eq:1}{e-if:a} "
}
空:{s-if:fieldName}value{e-if:fieldName}
不等于:{s-if:fieldName}{op-neq:Value}value{op-eq:Value}{e-if:fieldName}
等于:{s-if:fieldName}{op-eq:Value}value{op-eq:Value}{e-if:fieldName}
大于:{s-if:fieldName}{op-gt:Value}value{op-gt:Value}{e-if:fieldName}
小于:{s-if:fieldName}{op-lt:Value}value{op-lt:Value}{e-if:fieldName}
大于等于:{s-if:fieldName}{op-gte:Value}value{op-gte:Value}{e-if:fieldName}
小于等于:{s-if:fieldName}{op-lte:Value}value{op-lte:Value}{e-if:fieldName}
RegexExtendUtil.cs
if (!sql.Contains(mcOpItem.Value)) continue;
MatchCollection lstMcOpV = Regex.Matches(mcOpItem.Value, RegexConst.FORMAT_WHERE_COMPARE, RegexOptions.IgnoreCase);
string tempValue = null;
if (lstMcOpV.Count > 0)
{
tempValue = lstMcOpV[0].Value.Replace("{op-", "").Trim('}');
}
if (string.IsNullOrEmpty(tempValue))
{
throw new BizException(ErrorCodeConst.MAPPER_25001.ErrorCode, $"【{sql}】配置错误,必须包含其中之一(eq,lt,gt,lte,gte)");
}
string op = tempValue.Split(":")[0];
string val = tempValue.Split(":")[1];
// 如果满足条件,保留表达式里面内容,否则移除表达式和对应的内容
bool isReplaceAll = true;
switch (op)
{
case "eq":
isReplaceAll = paramsValue == val;
break;
case "lt":
isReplaceAll = Convert.ToDouble(paramsValue) < Convert.ToDouble(val);
break;
case "gt":
isReplaceAll = Convert.ToDouble(paramsValue) > Convert.ToDouble(val);
break;
case "lte":
isReplaceAll = Convert.ToDouble(paramsValue) <= Convert.ToDouble(val);
break;
case "gte":
isReplaceAll = Convert.ToDouble(paramsValue) >= Convert.ToDouble(val);
break;
default:
throw new BizException(ErrorCodeConst.MAPPER_25001.ErrorCode, $"【{op}】未配置,必须是其中之一(eq,lt,gt,lte,gte)");
}
string regixS = $"{regixStr_s}{lstMcOpV[0].Value}";
string regixE = $"{lstMcOpV[0].Value}{regixStr_e}";
if (isReplaceAll)
{
sql = Regex.Replace(sql, regixS, string.Empty);
sql = Regex.Replace(sql, regixE, string.Empty);
}
//#endregion 设置默认值 user_id,
"bridgeColumn": "address_id,telephone,real_name,nation,province,city,address,geography,is_enabled",
"auth": false,
"viewCountClosed": false,
//#region 设置主键
"primaryWhere": " {s-if:addressId}{op-neq:0} address_id=@addressId {op-neq:0}{e-if:addressId} {s-if:addressId}{op-eq:0}is_default=1 {op-eq:0}{e-if:addressId} and user_id=@_userId",
//把内部值赋予key,用于解决内部参数,导致的错误
"primaryWhereMapper": [
{
"key": "userId",
"value": "@_userId"
}
]
//#endregion 设置主键
文档更新时间: 2022-05-26 20:54 作者:admin