private async Task<IActionResult> ResponseBridgeResult(string mkey, string resField, RequestModuleType rmt)
        {
            PFGlobalParameter pf = new PFGlobalParameter
            {
                OwnerId = RequestPFUtil.GetOwnerId(this.HttpContext),
                SysId = RequestPFUtil.GetSysId(this.HttpContext),
                ModuleKey = mkey,
                SubBeforeKey = "bridge",
                UserId = RequestPFUtil.GetUserIdByHeader(this.HttpContext)
            };
            Dictionary<string, object> dictionaryUrl = RequestPFUtil.ConvertHTByReqFormOrParamsD(this.HttpContext);


            dictionaryUrl["rmt"] = rmt.ToString().ToLower();
            _authProvider.SetAuthParams(pf, dictionaryUrl);
            pf.RequestModuleType = rmt;
            pf.ModuleKey = mkey;
            pf.ReponseField = resField;

            string cacheKey = MD5.MD5Encrypt($"bridge-{pf.OwnerId}${pf.SysId}${mkey}${resField}${rmt}");
            dictionaryUrl["_cache"] = cacheKey;

            var resultCache = _quDataResultCache.Get<ResultDetail<BridgeConfig>>(pf, dictionaryUrl, out cacheKey);

            string scriptDirectory = _configuration?.GetValue<string>("configDirectory") ?? "~/Config";

            string path = $"{scriptDirectory}/BridgeUsed/{pf.OwnerId}/bridge_{pf.ModuleKey}.json";
            //string pathBack = $"{scriptDirectory}/Bridge/{pf.OwnerId}/backstage/bridge_{pf.ModuleKey}.json";
            //string pathBasis = $"{scriptDirectory}/Bridge/basis/bridge_{pf.ModuleKey}.json";

            DateTime pathModifyDate = FileUtil.ReadLastWriteTimeByVirUrl(path);
            //DateTime pathBackModifyDate = FileUtil.ReadLastWriteTimeByVirUrl(pathBack);
            //DateTime pathBasisModifyDate = FileUtil.ReadLastWriteTimeByVirUrl(pathBasis);


            #region 生产 和 开发 直接读文件  解决更新后不能即时显示问题
            if ((resultCache != null && resultCache.Success != false) && pathModifyDate != DateTime.MinValue && pathModifyDate >= resultCache.CacheDate)
            {
                resultCache = null;
            }
            //else if ((resultCache != null && resultCache.Success != false) && pathBackModifyDate != DateTime.MinValue && pathBackModifyDate >= resultCache.CacheDate)
            //{
            //    resultCache = null;
            //}
            //else if ((resultCache != null && resultCache.Success != false) && pathBasisModifyDate != DateTime.MinValue && pathBasisModifyDate >= resultCache.CacheDate)
            //{
            //    resultCache = null;
            //}
            #endregion


            SqlConfig sqlConfig = null;
            BridgeConfig bridgeConfig = resultCache?.Data;



            if (resultCache == null || resultCache.Success == false)
            {
                dictionaryUrl = await NodeJsUtil.SetRequestParams(pf, _configurationBuilderService, _nodeServices, dictionaryUrl, this.HttpContext, mkey, resField, pf.RequestModuleType);
                bridgeConfig = _bridgeService.ResponseBridgeConfig(pf, dictionaryUrl, ref sqlConfig, pf.RequestModuleType);
                resultCache = new ResultDetail<BridgeConfig> { Success = true, Data = bridgeConfig, Auth = sqlConfig.ResponseFieldTemp.Auth };
                resultCache.CacheKey = cacheKey;
                resultCache.CacheDate = DateTime.Now;
                _quDataResultCache.Set<ResultDetail<BridgeConfig>>(pf, dictionaryUrl, cacheKey, resultCache);
            }
            //if (resultCache != null || resultCache.Success != false)
            //{
            //    _quDataResultCache.Set<ResultDetail<BridgeConfig>>(pf, dictionaryUrl, cacheKey, resultCache);
            //}

            ResponseField rf = null;
            if (bridgeConfig.SqlConfig != null && bridgeConfig.SqlConfig.ResponseField != null && bridgeConfig.SqlConfig.ResponseField.Count > 0)
            {
                rf = bridgeConfig.SqlConfig.ResponseField[pf.ReponseField];
            }
            else
            {
                rf = _sqlConfigServe.GetResponseFieldExtand(pf);
            }

            //根据权限设置
            if (bridgeConfig != null && rf != null && rf.Auth == true)
            {
                TokenUser tu = _authProvider.GetCurrentToken(RequestPFUtil.GetTokenAuthorization(this.HttpContext), null, pf.OwnerId, pf.SysId);
                if (tu == null || !ValidateUtil.ValidateExistsValue(tu.UserId))
                {
                    throw new BizException(ErrorCodeConst.USER_21005.ErrorCode, "未登录或无功能权限。");
                }
                if (!dictionaryUrl.ContainsKey("_menuId") || !ValidateUtil.ValidateExistsValue(dictionaryUrl["_menuId"]))
                {
                    throw new BizException(ErrorCodeConst.USER_21005.ErrorCode, "_menuId参数未传递。");
                }

                pf.UserId = tu.UserId;
                pf.MenuId = dictionaryUrl["_menuId"].ToString();

                _bridgeService.ResponseBridgeConfigPopedom(pf, dictionaryUrl, pf.RequestModuleType, sqlConfig, bridgeConfig);

                //if (bridgeConfig.Actions==null||bridgeConfig.Actions.Action.Count()==0)
                //{
                //    throw new BizException(ErrorCodeConst.USER_21005.ErrorCode, "未获取到功能权限。");
                //}
            }

            //对结果进行二次处理
            if (resultCache != null && resultCache.Data != null && resultCache.Data.Form != null && resultCache.Data.Form.Columns != null)
            {
                foreach (string field in resultCache.Data.Form.Columns.Keys)
                {
                    var item = resultCache.Data.Form.Columns[field];
                    if (item.Meta.Component == "bo-switch")
                    {
                        item.Attrs["data-custorm"] = true;
                    }
                }
            }

            ////权限认证  如果MenuFunc 不存在,使用所有的功能
            //if (resultCache.Data?.MenuFunc?.Auth == true)
            //{
            //    resultCache.Data.MenuFunc = new BridgeMenuFunc
            //    {
            //        Auth = true,
            //        Actions = _popedomProvider.QueryBoPopedomMF(pf, pf.MenuId, pf.UserId, PopedomObjectType.CurrentUser).Select(t => t.FuncId).ToList()
            //    };
            //}
            //处理类型转换问题
            resultCache = HttpContextUtil.DoConvertResponse<ResultDetail<BridgeConfig>>(resultCache);

            //订阅信息,便于前端推送
            await _isubPush.SubInit<SubResult>(new SubResult { }, new PFGlobalParameter
            {
                OwnerId = pf.OwnerId,
                ModuleKey = mkey,
                UserId = pf.UserId,
                SubBeforeKey = "bridge"
            }); ;
            await _isubPush.SubInit<SubResult>(new SubResult { }, new PFGlobalParameter
            {
                OwnerId = pf.OwnerId,
                ModuleKey = mkey,
                UserId = pf.UserId,
                SubBeforeKey = "mapper"
            });
            //mappper信息不输入到前端
            bridgeConfig.SqlConfig = null;
            return await NodeJsUtil.ResponseRequestResult(pf, _configurationBuilderService, _nodeServices, dictionaryUrl, this.HttpContext, mkey, resField, resultCache, pf.RequestModuleType);


        }
文档更新时间: 2021-10-17 20:12   作者:admin