using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; using Lottomat.Application.Busines.CommonManage; using Lottomat.Application.Cache; using Lottomat.Application.Code; using Lottomat.Application.Entity.CommonEntity; using Lottomat.Application.Entity.InformationManage; using Lottomat.Application.Entity.LotteryNumberManage.Parameter; using Lottomat.Application.Entity.ViewModel; using Lottomat.Cache.Factory; using Lottomat.SOA.API.Caching; using Lottomat.SOA.API.Controllers.Base; using Lottomat.Util; using Lottomat.Util.Extension; namespace Lottomat.SOA.API.Controllers.V1 { /// /// 专题文章 /// public class ThematicArticleController : BaseApiController { #region 实例 /// /// 公共BLL /// private static readonly CommonBLL commonBll = new CommonBLL(); #endregion /// /// 获取专题文章分类 /// /// [HttpPost] public HttpResponseMessage GetThematicArticleClassify(BaseParameterEntity arg) { BaseJson> resultMsg = new BaseJson> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null }; Logger(typeof(ThematicArticleController), arg.TryToJson(), "获取专题文章分类-GetThematicArticleClassify", () => { if (!string.IsNullOrEmpty(arg.t)) { if (arg.t.CheckTimeStamp()) { List res = null; string key = $"GetThematicArticleClassify"; if (webCache.IsExist(key)) { res = webCache.GetObject>(key) as List; } else { //res = Cache.Factory.CacheFactory.Cache().GetCache>("__ThematicArticleClassify"); if (res == null || res.Count == 0) { res = new List(); DataTable data = commonBll.ExcuteSqlDataTable(QueryThematicArticleClassify, DatabaseLinksEnum.CB55128); if (data.IsExistRows()) { List list = data.DataTableToList(); foreach (ZTColumnEntity entity in list) { ZTColumnViewModel model = new ZTColumnViewModel { Name = entity.Name.Trim(), CId = entity.CId, TagId = entity.TagId, Logo = entity.Logo.ToLower(), Lottery = entity.Lottery.Trim(), About = entity.About, hTitle = entity.hTitle, hKeywords = entity.hKeywords, hDescription = entity.hDescription, RewriteUrl = entity.RewriteUrl.Trim() }; res.Add(model); } webCache.AddObject(key, res, (int)CacheTime.Data); //Cache.Factory.CacheFactory.Cache().WriteCache(res, "__ThematicArticleClassify", DateTime.Now.AddHours(12)); } } } resultMsg = new BaseJson> { Status = (int)JsonObjectStatus.Success, Data = res, Message = JsonObjectStatus.Success.GetEnumText(), BackUrl = null }; } else { resultMsg = new BaseJson> { Status = (int)JsonObjectStatus.Fail, Data = null, Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。", BackUrl = null }; } } else { resultMsg = new BaseJson> { Status = (int)JsonObjectStatus.Fail, Data = null, Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。", BackUrl = null }; } }, e => { resultMsg = new BaseJson> { Status = (int)JsonObjectStatus.Exception, Data = null, Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message, BackUrl = null }; }); return resultMsg.TryToJson().ToHttpResponseMessage(); } /// /// 获取专题文章列表 /// /// [HttpPost] public HttpResponseMessage GetThematicArticleList(ThematicArticleListArg arg) { BaseJson4Page resultMsg = new BaseJson4Page { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null }; Logger(typeof(ThematicArticleController), arg.TryToJson(), "获取专题文章列表-GetThematicArticleList", () => { if (!string.IsNullOrEmpty(arg.t)) { if (arg.t.CheckTimeStamp()) { DataTablePagerCache tablePager = null; string key = $"GetThematicArticleList/{arg.CId}/{arg.PageIndex}/{arg.PageSize}"; if (webCache.IsExist(key)) { tablePager = webCache.GetObject>(key); } else { string sql = $"SELECT [Id],[Title],[ShortDetail],[Addtime] FROM [dbo].[ZT_Article] WHERE Cid = {arg.CId}"; DataTable table = commonBll.FindPageDataTable(sql, "Addtime", false, arg.PageSize, arg.PageIndex, out int total, DatabaseLinksEnum.CB55128); tablePager = new DataTablePagerCache() { Total = total, Table = table }; webCache.AddObject(key, tablePager, (int)CacheTime.Data); } DataTable data = null; int recordTotal = 0; if (tablePager != null && tablePager.Table != null) { recordTotal = tablePager.Total; data = tablePager.Table; } else { data = new DataTable(); } if (data.IsExistRows()) { List res = data.DataTableToList(); PageData pageData = new PageData { TotalRow = recordTotal, TotalPage = (int)Math.Floor(recordTotal * 1.0 / arg.PageSize) + 1, PageIndex = arg.PageIndex, Rows = res }; resultMsg = new BaseJson4Page { Status = (int)JsonObjectStatus.Success, Data = pageData, Message = JsonObjectStatus.Success.GetEnumText(), BackUrl = null }; } else { resultMsg = new BaseJson4Page { Status = (int)JsonObjectStatus.Success, Data = null, Message = JsonObjectStatus.Success.GetEnumText(), BackUrl = null }; } } else { resultMsg = new BaseJson4Page { Status = (int)JsonObjectStatus.Fail, Data = null, Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。", BackUrl = null }; } } else { resultMsg = new BaseJson4Page { Status = (int)JsonObjectStatus.Fail, Data = null, Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。", BackUrl = null }; } }, e => { resultMsg = new BaseJson4Page { Status = (int)JsonObjectStatus.Exception, Data = null, Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message, BackUrl = null }; }); return resultMsg.TryToJson().ToHttpResponseMessage(); } /// /// 获取专题文章详细 /// /// [HttpPost] public HttpResponseMessage GetThematicArticleById(ThematicArticleInfoArg arg) { BaseJson resultMsg = new BaseJson { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null }; Logger(typeof(ThematicArticleController), arg.TryToJson(), "获取专题文章详细-GetThematicArticleById", () => { if (!string.IsNullOrEmpty(arg.t)) { if (arg.t.CheckTimeStamp()) { DataTable data = null; string key = $"GetThematicArticleById/{arg.Id}/{arg.CId}"; if (webCache.IsExist(key)) { data = webCache.GetObject(key); } else { //string sql = $"SELECT [Id],[Title],[Detail],[Editor],[Addtime] FROM [dbo].[ZT_ArticleDetail] WHERE Id = {arg.Id}"; string sql = $"SELECT ad.[Id],ad.[Title],ad.[Detail],ad.[Editor],ad.[Addtime],c.[Name] AS TypeName,c.[Lottery] AS EnumCode FROM [dbo].[ZT_ArticleDetail] AS ad JOIN [dbo].[ZT_Column] AS c ON ad.Id = {arg.Id} AND c.CId = {arg.CId}"; data = commonBll.ExcuteSqlDataTable(sql, DatabaseLinksEnum.CB55128); webCache.AddObject(key, data, (int)CacheTime.Data); } if (data.IsExistRows()) { ZTArticleDetailViewModel detail = data.DataTableToObject(); if (detail != null) { detail.Editor = detail.Editor.Trim(); detail.TypeName = detail.TypeName.Trim(); //校正彩种枚举码 switch (detail.EnumCode.Trim()) { case "ssq": detail.EnumCode = SCCLottery.SSQ.ToString(); break; case "p3": detail.EnumCode = SCCLottery.PL3.ToString(); break; case "3d": detail.EnumCode = SCCLottery.FC3D.ToString(); break; case "dlt": detail.EnumCode = SCCLottery.DLT.ToString(); break; } resultMsg = new BaseJson { Status = (int)JsonObjectStatus.Success, Data = detail, Message = JsonObjectStatus.Success.GetEnumText(), BackUrl = null }; } } } else { resultMsg = new BaseJson { Status = (int)JsonObjectStatus.Fail, Data = null, Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。", BackUrl = null }; } } else { resultMsg = new BaseJson { Status = (int)JsonObjectStatus.Fail, Data = null, Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。", BackUrl = null }; } }, e => { resultMsg = new BaseJson { Status = (int)JsonObjectStatus.Exception, Data = null, Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message, BackUrl = null }; }); return resultMsg.TryToJson().ToHttpResponseMessage(); } /// /// 获取系统推荐专题文章列表 /// /// [HttpPost] public HttpResponseMessage GetRecommendThematicArticleList(RecommendThematicArticleArg arg) { BaseJson> resultMsg = new BaseJson> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null }; Logger(typeof(ThematicArticleController), arg.TryToJson(), "获取系统推荐专题文章列表-GetRecommendThematicArticleList", () => { if (!string.IsNullOrEmpty(arg.t)) { if (arg.t.CheckTimeStamp()) { string[] codeArr = { "SSQ", "PL3", "FC3D", "DLT" }; arg.EnumCode = string.IsNullOrEmpty(arg.EnumCode) ? "Default" : codeArr.Contains(arg.EnumCode) ? arg.EnumCode : "Default"; //List list = CacheFactory.Cache().GetCache>("__RecommendThematicArticle_" + arg.TotalRecord + "_" + arg.EnumCode.Trim().ToUpper()); List list = null; string key = $"GetRecommendThematicArticleList/{arg.EnumCode}/{arg.TotalRecord}"; if (webCache.IsExist(key)) { list = webCache.GetObject>(key); } else { if (list == null || list.Count == 0) { list = new List(); //string sql = $"SELECT TOP {arg.TotalRecord} [Id],[Title],[AddTime],[Cid] FROM [dbo].[ZT_Article] ORDER BY Addtime DESC"; string code = String.Empty; //校正彩种编码 switch (arg.EnumCode.Trim()) { case "SSQ": code = "ssq"; break; case "PL3": code = "p3"; break; case "FC3D": code = "3d"; break; case "DLT": code = "dlt"; break; default: code = ""; break; } string sql = ""; if (string.IsNullOrEmpty(code)) { sql = $"SELECT TOP {arg.TotalRecord} [Id],[Title],[AddTime],[Cid] FROM [dbo].[ZT_Article] WHERE Cid IN(SELECT [CId] FROM [dbo].[ZT_Column] WHERE TypeName = 'article') ORDER BY Addtime DESC"; } else { sql = $"SELECT TOP {arg.TotalRecord} [Id],[Title],[AddTime],[Cid] FROM [dbo].[ZT_Article] WHERE Cid IN(SELECT [CId] FROM [dbo].[ZT_Column] WHERE Lottery = '{code}' AND TypeName = 'article') ORDER BY Addtime DESC"; } DataTable data = commonBll.ExcuteSqlDataTable(sql, DatabaseLinksEnum.CB55128); if (data.IsExistRows()) { for (int i = 0; i < data.Rows.Count; i++) { ZTArticleViewModel article = new ZTArticleViewModel { Id = data.Rows[i]["Id"].TryToInt32(), Title = data.Rows[i]["Title"].ToStringEx(), Addtime = data.Rows[i]["AddTime"].TryToDateTime(), Cid = data.Rows[i]["Cid"].TryToInt32() }; list.Add(article); } webCache.AddObject(key, list, (int)CacheTime.Data); //CacheFactory.Cache().WriteCache(list, "__RecommendThematicArticle_" + arg.TotalRecord + "_" + arg.EnumCode.Trim().ToUpper(), DateTime.Now.AddHours(6)); } else { resultMsg = new BaseJson> { Status = (int)JsonObjectStatus.Success, Data = null, Message = JsonObjectStatus.Success.GetEnumText(), BackUrl = null }; } } } resultMsg = new BaseJson> { Status = (int)JsonObjectStatus.Success, Data = list, Message = JsonObjectStatus.Success.GetEnumText(), BackUrl = null }; } else { resultMsg = new BaseJson> { Status = (int)JsonObjectStatus.Fail, Data = null, Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。", BackUrl = null }; } } else { resultMsg = new BaseJson> { Status = (int)JsonObjectStatus.Fail, Data = null, Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。", BackUrl = null }; } }, e => { resultMsg = new BaseJson> { Status = (int)JsonObjectStatus.Exception, Data = null, Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message, BackUrl = null }; }); return resultMsg.TryToJson().ToHttpResponseMessage(); } #region SQL语句 /// /// 查询专题文章分类 /// private string QueryThematicArticleClassify = "SELECT [Id],[Name],[CId],[TagId],[RewriteUrl],[Logo],[Lottery],[TypeName],[Status],[Words],[About],[hTitle],[hKeywords],[hDescription],[Addtime] FROM [dbo].[ZT_Column] WHERE TypeName = 'article'"; #endregion } }