public ResultObject<object> AddCopy(PFGlobalParameter pf, [RequiredStringPF("mkey")] string mkey, [RequiredStringPF("resField")] string resField, Dictionary<string, object> dictionaryUrl, out SqlConfig sqlConfig, JObject jObject)
{
sqlConfig = _sqlConfigService.BuildUseSqlConfigMapper(true, pf, mkey, resField);
if (sqlConfig.ResponseFieldTemp.Copy == null)
{
throw new BizException(ErrorCodeConst.MENU_21801.ErrorCode, $"responseField:copy未配置");
}
if (string.IsNullOrEmpty(sqlConfig.ResponseFieldTemp.Copy.ConnName))
{
throw new BizException(ErrorCodeConst.MENU_21801.ErrorCode, $"responseField:copy:connName未配置");
}
if (sqlConfig.ResponseFieldTemp.Copy.Sql == null || !sqlConfig.ResponseFieldTemp.Copy.Sql.Any())
{
throw new BizException(ErrorCodeConst.MENU_21801.ErrorCode, $"responseField:copy:sql未配置");
}
if (sqlConfig.ResponseFieldTemp.Auth == true)
{
_popedomProvider.ValidatePopedomByCurrentUser(new PFGlobalParameter { ModuleKey = mkey, ReponseField = resField, OwnerId = pf.OwnerId, SysId = pf.SysId }, dictionaryUrl, RequestModuleType.Add);
}
Dictionary<string, object> dicPK = new Dictionary<string, object>();
JTokenUtil.ConvertJObjectToDictionary(jObject, dicPK, dictionaryUrl);
dicPK = DictionaryUtil.ConvertDictionaryRemoveJObject(dicPK);
//执行 LambdaParser 条件验证
if (sqlConfig.ResponseFieldTemp.Copy.Rules != null && sqlConfig.ResponseFieldTemp.Copy.Rules.Any())
{
foreach (var rule in sqlConfig.ResponseFieldTemp.Copy.Rules.OrderBy(temp => temp.SortId))
{
if (ValidateUtil.IsNullOrEmptyOrDbNull(rule.Regex)) continue;
var lambdaParser = new LambdaParser();
bool catchT = false;
var ruleT = false;
try
{
//"null == nullVar" 只支持简单验证
ruleT = (bool)lambdaParser.Eval(rule.Regex, dicPK);
//转换时间
if (!ruleT && !string.IsNullOrEmpty(rule.DateField))
{
foreach (var item in rule.DateField.Split(','))
{
dicPK[$"{item}D"] = Convert.ToDateTime(dicPK[$"{item}"]);
}
}
}
catch (Exception ex)
{
catchT = true;
throw new BizException(ErrorCodeConst.MENU_21801.ErrorCode, ex.Message + rule.Message);
}
if (!catchT && ruleT)
{
throw new BizException(ErrorCodeConst.MENU_21801.ErrorCode, rule.Message);
}
}
}
int doResult = _db.Execute(pf, sqlConfig.ResponseFieldTemp.Copy.ConnName, sqlConfig.ResponseFieldTemp.Copy.SqlV, dicPK);
SqlOpSave sos = new SqlOpSave();
sos.Result = new SqlOpResult();
if (doResult > 0)
{
sos.Result.InsertSuccess = doResult;
}
else
{
sos.Result.InsertError = doResult;
}
if (sos.Result.DoResult)
{
_quDataResultCache.RemoveAll(pf);
#region 订阅信息
var pfTemp = new PFGlobalParameter
{
ModuleKey = mkey,
ReponseField = resField,
OwnerId = pf.OwnerId,
SysId = pf.SysId,
RequestModuleType = RequestModuleType.Copy
};
_subPush.Sub<ResultOps<object>>(new ResultOps<object>
{
Data = sos.Data,
Params = pfTemp,
PrimaryColumn = new List<SqlPrimary>()// sqlConfig.SaveSqlPrimary.PrimaryColumn
}, pfTemp);
#endregion 订阅信息
//result = new
return new ResultObject<object>
{
Success = true,
Message = sos.Message,
Data = sos.Data
};
}
else
{
//result = new
return new ResultObject<object>
{
Success = false,
Error = new Error { ErrorText = sos.Message }
};
}
}
文档更新时间: 2021-06-26 08:00 作者:admin