/// <summary>
/// 输出到控制台
/// </summary>
/// <param name="mkey"></param>
/// <param name="resField"></param>
/// <param name="httpContext"></param>
/// <returns></returns>
public async Task<IActionResult> PageUsed([Required] string mkey, [Required] string resField, JToken jparams, HttpContext httpContext)
{
var pf = new PFGlobalParameter { OwnerId = RequestPFUtil.GetOwnerId(httpContext), SysId = RequestPFUtil.GetSysId(httpContext) };
//await _verifyApiProvider.Verify(pf.OwnerId, pf.SysId, RequestPFUtil.GetVerifyApi(_accessor.HttpContext));
Dictionary<string, object> dictionaryUrl = RequestPFUtil.ConvertHTByReqFormOrParamsD(httpContext);
dictionaryUrl["rmt"] = RequestModuleType.Page.ToString().ToLower();
dictionaryUrl["_rmt"] = RequestModuleType.Page.ToString().ToLower();
dictionaryUrl["_mkey"] = mkey;
dictionaryUrl["_resField"] = resField;
pf.CacheSource = "datapage";
_authProvider.SetAuthParams(pf, dictionaryUrl);
pf.RequestModuleType = RequestModuleType.Page;
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.Page, 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?.Page;
RequestModuleType rmt = RequestModuleType.Page;
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 = new ResultObject<DataTable> { Success = false};// _quDataResultCache.Get<ResultObject<DataTable>>(pf, dictionaryUrl, out cacheKey);
var resultCache = _quDataResultCache.Get<ResultObject<DataTable>>(pf, dictionaryUrl, out cacheKey);
DateTime lastDate = _isubPush.LastDate(pf);
if (resultCache == null || resultCache.Success == false || resultCache.CacheDate <= lastDate)
{
dictionaryUrl = await NodeJsUtil.SetRequestParams(pf, _configurationBuilderService, _nodeServices, dictionaryUrl, httpContext, mkey, resField, RequestModuleType.Page, sqlConfig.ResponseFieldTemp.NjcArgs);
resultCache = PageJson(pf, mkey, resField, dictionaryUrl, out sqlConfig);
resultCache.CacheDate = DateTime.Now;
}
_dbExecuteService.SetViewCount(pf, sqlConfig, RequestModuleType.Page, resultCache.Data, dictionaryUrl, mkey, resField);
if (resultCache != null || resultCache.Success != false)
{
resultCache.CacheDate = DateTime.Now;
_quDataResultCache.Set<ResultObject<DataTable>>(pf, dictionaryUrl, cacheKey, resultCache);
}
return await NodeJsUtil.ResponseRequestResult(pf, _configurationBuilderService, _nodeServices, dictionaryUrl, httpContext, mkey, resField, resultCache, RequestModuleType.Page, sqlConfig.ResponseFieldTemp.NjcResult);
}
}
文档更新时间: 2021-07-04 08:00 作者:admin