public async Task ContentAsync(HttpContext context, IFastRepository IFast) { var urlParam = HttpUtility.UrlDecode(GetUrlParam(context)); var isSuccess = true; var dic = new Dictionary <string, object>(); var stopwatch = new Stopwatch(); stopwatch.Start(); context.Response.ContentType = "application/Json"; var name = context.Request.Path.Value.ToStr().Substring(1, context.Request.Path.Value.ToStr().Length - 1).ToLower(); if (IFast.IsExists(name)) { var data = new List <Dictionary <string, object> >(); var param = new List <DbParameter>(); foreach (var item in IFast.MapParam(name)) { var checkKey = IFast.MapCheckMap(name, item); var existsKey = IFast.MapExistsMap(name, item); var tempParam = DbProviderFactories.GetFactory(IFast.MapDb(name)).CreateParameter(); tempParam.ParameterName = item; tempParam.Value = GetUrlParam(urlParam, item); param.Add(tempParam); if (!string.IsNullOrEmpty(IFast.MapRequired(name, item))) { if (!(IFast.MapRequired(name, item).ToLower() == "true" && !string.IsNullOrEmpty(tempParam.Value.ToStr()))) { dic.Add("error", string.Format("{0}不能为空", item)); param.Remove(tempParam); break; } } if (IFast.MapMaxlength(name, item).ToInt(0) != 0) { if (!(IFast.MapMaxlength(name, item).ToInt(0) >= tempParam.Value.ToStr().Length)) { dic.Add("error", string.Format("{0}:{1},最大长度{2}", item, tempParam.Value.ToStr(), IFast.MapMaxlength(name, item))); param.Remove(tempParam); break; } } if (!string.IsNullOrEmpty(existsKey)) { var existsListParam = new List <DbParameter>(); var existsParam = DbProviderFactories.GetFactory(IFast.MapDb(existsKey)).CreateParameter(); existsParam.ParameterName = item; existsParam.Value = tempParam.Value; existsListParam.Add(existsParam); var checkData = IFast.Query(existsKey, existsListParam.ToArray())?.First() ?? new Dictionary <string, object>(); if (checkData.GetValue("count").ToStr().ToInt(0) >= 1) { dic.Add("error", string.Format("{0}:{1}已存在", item, tempParam.Value)); param.Remove(tempParam); break; } } if (!string.IsNullOrEmpty(checkKey)) { var checkListParam = new List <DbParameter>(); var checkParam = DbProviderFactories.GetFactory(IFast.MapDb(checkKey)).CreateParameter(); checkParam.ParameterName = item; checkParam.Value = GetUrlParam(urlParam, item); checkListParam.Add(checkParam); var checkData = IFast.Query(existsKey, checkListParam.ToArray())?.First() ?? new Dictionary <string, object>(); if (checkData.GetValue("count").ToStr().ToInt(0) < 1) { dic.Add("error", string.Format("{0}:{1}不存在", item, tempParam.Value)); param.Remove(tempParam); break; } } if (IFast.MapDate(name, item).ToLower() == "true") { if (!BaseRegular.IsDate(tempParam.Value.ToStr())) { dic.Add("error", string.Format("{0}:{1},不是日期类型", item, tempParam.Value)); param.Remove(tempParam); break; } tempParam.Value = tempParam.Value.ToDate(); tempParam.DbType = System.Data.DbType.DateTime; } if (tempParam.Value.ToStr() == "") { param.Remove(tempParam); } } if (IFast.MapType(name).ToLower() == AppConfig.PageAll && dic.Count == 0) { var pageSize = GetUrlParam(urlParam, "PageSize"); var pageId = GetUrlParam(urlParam, "PageId"); isSuccess = true; var page = new PageModel(); page.PageSize = pageSize.ToInt(0) == 0 ? 10 : pageSize.ToInt(0); page.PageId = pageId.ToInt(0) == 0 ? 1 : pageId.ToInt(0); var info = IFast.QueryPage(page, name, param.ToArray()); dic.Add("data", info.list); dic.Add("page", info.pModel); } else if (IFast.MapType(name).ToLower() == AppConfig.Page && param.Count > 0) { var pageSize = GetUrlParam(urlParam, "PageSize"); var pageId = GetUrlParam(urlParam, "PageId"); isSuccess = true; var page = new PageModel(); page.PageSize = pageSize.ToInt(0) == 0 ? 10 : pageSize.ToInt(0); page.PageId = pageId.ToInt(0) == 0 ? 1 : pageId.ToInt(0); var info = IFast.QueryPage(page, name, param.ToArray()); dic.Add("data", info.list); dic.Add("page", info.pModel); } else if (IFast.MapType(name).ToLower() == AppConfig.All && dic.Count == 0) { isSuccess = true; data = IFast.Query(name, param.ToArray()); dic.Add("data", data); } else if (IFast.MapType(name).ToLower() == AppConfig.Write && param.Count > 0) { var result = IFast.Write(name, param.ToArray()); if (result.IsSuccess) { isSuccess = true; } else { isSuccess = false; dic.Add("error", result.Message); } } else { if (param.Count > 0) { isSuccess = true; data = IFast.Query(name, param.ToArray()); dic.Add("data", data); } else { isSuccess = false; } } } else { isSuccess = false; dic.Add("error", "接口不存在"); } dic.Add("isSuccess", isSuccess); context.Response.StatusCode = 200; await context.Response.WriteAsync(BaseJson.ModelToJson(dic), Encoding.UTF8).ConfigureAwait(false); }