public async Task<IActionResult> DetailUsed([Required] string mkey, [Required] string resField, [FromBody] JToken jparams, HttpContext httpContext)
{
var pf = new PFGlobalParameter { OwnerId = RequestPFUtil.GetOwnerId(httpContext), SysId = RequestPFUtil.GetSysId(httpContext) };
Dictionary<string, object> dictionaryUrl = RequestPFUtil.ConvertHTByReqFormOrParamsD(httpContext);
dictionaryUrl["rmt"] = RequestModuleType.Detail.ToString().ToLower();
dictionaryUrl["_rmt"] = RequestModuleType.Detail.ToString().ToLower();
dictionaryUrl["_mkey"] = mkey;
dictionaryUrl["_resField"] = resField;
_authProvider.SetAuthParams(pf, dictionaryUrl);
pf.RequestModuleType = RequestModuleType.Detail;
pf.ModuleKey = mkey;
pf.ReponseField = resField;
//读取文件的配置数据
SqlConfig sqlConfig = _sqlConfigService.BuildUseSqlConfigMapper(true, pf, mkey, resField);
if (sqlConfig.ResponseFieldTemp.DataFromType == DataFromType.Api)
{
return await _nodeApiService.Query(httpContext, dictionaryUrl, mkey, resField, null, RequestModuleType.Detail, sqlConfig.ResponseFieldTemp.NjcResult, sqlConfig.ResponseFieldTemp.NjcArgs);
}
else if (sqlConfig.ResponseFieldTemp.DataFromType == DataFromType.ConfigFile)
{
#region 读取文件的配置数据
JToken resultCache = new JObject();
resultCache["success"] = false;
StringBuilder sb = new StringBuilder();
string detailPath = sqlConfig.ResponseFieldTemp?.Mock?.Detail;
RequestModuleType rmt = RequestModuleType.Detail;
if (!string.IsNullOrEmpty(detailPath))
{
sb.Append(detailPath);
foreach (string key in dictionaryUrl.Keys)
{
if (detailPath.Contains($"{key}"))
{
sb.Replace($"{key}", dictionaryUrl[key]?.ToString());
}
}
}
if (!string.IsNullOrEmpty(detailPath))
{
var str = FileUtil.ReadFileAndContentByVirUrl(sb.ToString());
if (string.IsNullOrEmpty(str))
{
throw new BizException(ErrorCodeConst.FILE_17010.ErrorCode, $"【{sb.ToString()}】未读取到内容");
}
dictionaryUrl = await NodeJsUtil.SetRequestParams(pf, _configurationBuilderService, _nodeServices, dictionaryUrl, httpContext, mkey, resField, rmt, sqlConfig.ResponseFieldTemp.NjcArgs);
resultCache = JsonUtil.Deserialize<JToken>(str);
}
else
{
throw new BizException(ErrorCodeConst.FILE_17010.ErrorCode, $"【responseField:key:mock:{rmt.ToString().ToLower()}】未配置");
}
//end读取文件的配置数据
#endregion
return await NodeJsUtil.ResponseRequestResult(pf, _configurationBuilderService, _nodeServices, dictionaryUrl, httpContext, mkey, resField, resultCache, rmt, sqlConfig.ResponseFieldTemp.NjcResult);
}
else
{
string cacheKey = _quDataResultCache.GetCacheKey(pf, dictionaryUrl);
// string cacheKeyTemp = MD5.MD5Encrypt(JsonUtil.Serialize(dictionaryUrl));
if (!string.IsNullOrEmpty(cacheKey)) dictionaryUrl["_cache"] = cacheKey;
var resultCache = _quDataResultCache.Get<ResultDetail<Dictionary<string, object>>>(pf, dictionaryUrl, out cacheKey);
//SqlConfig sqlConfig = null;
if (resultCache == null || resultCache.Success == false)
{
dictionaryUrl = await NodeJsUtil.SetRequestParams(pf, _configurationBuilderService, _nodeServices, dictionaryUrl, httpContext, mkey, resField, RequestModuleType.Detail, sqlConfig.ResponseFieldTemp.NjcArgs);
resultCache = DetailJson(pf, mkey, resField, dictionaryUrl, out sqlConfig);
}
_dbExecuteService.SetViewCount(pf, sqlConfig, RequestModuleType.Detail, resultCache.Data, dictionaryUrl, mkey, resField);
if (resultCache != null || resultCache.Success != false)
{
_quDataResultCache.Set<ResultDetail<Dictionary<string, object>>>(pf, dictionaryUrl, cacheKey, resultCache);
}
var r = await NodeJsUtil.ResponseRequestResult(pf, _configurationBuilderService, _nodeServices, dictionaryUrl, httpContext, mkey, resField, resultCache, RequestModuleType.Detail, sqlConfig.ResponseFieldTemp.NjcResult);
return r;
}
}
文档更新时间: 2021-07-04 08:00 作者:admin