GallerMangerApiController.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. using Lottomat.SOA.API.Controllers.Base;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Net.Http;
  7. using System.Web.Http;
  8. using Lottomat.Application.Entity.GalleryManage;
  9. using Lottomat.Application.Entity.CommonEntity;
  10. using Lottomat.Application.Entity.ViewModel.GallerMangerModel;
  11. using Lottomat.Application.Code;
  12. using Lottomat.Util.Extension;
  13. using Lottomat.Application.Busines.GalleryManage;
  14. using System.IO;
  15. using Lottomat.Application.Entity.ViewModel.ConsultationMangerModel;
  16. using Lottomat.Utils.Date;
  17. using Lottomat.Application.Busines.InformationManage;
  18. using Lottomat.Application.Cache;
  19. using Lottomat.Application.Entity.SystemManage;
  20. using Lottomat.Application.Entity.InformationManage;
  21. using Lottomat.Application.Entity.SystemManage.ViewModel;
  22. using Lottomat.SOA.API.Caching;
  23. namespace Lottomat.SOA.API.Controllers.V1
  24. {
  25. public class GallerMangerApiController : BaseApiController
  26. {
  27. /// <summary>
  28. ///
  29. /// </summary>
  30. private static readonly Tk_GalleryDetailBLL tkDetailBll = new Tk_GalleryDetailBLL();
  31. /// <summary>
  32. ///
  33. /// </summary>
  34. private static readonly Tk_GalleryBLL tkBll = new Tk_GalleryBLL();
  35. private static readonly DataItemCache dataItemCache = new DataItemCache();
  36. private DataItemCache itemCache = new DataItemCache();
  37. /// <summary>
  38. /// 查询图库全部页面
  39. ///
  40. /// </summary>
  41. /// <returns></returns>
  42. [HttpPost]
  43. public HttpResponseMessage QuerAll(ArtListParams param)
  44. {
  45. BaseJson4Page<QueryAllDataModel> resultMsg = new BaseJson4Page<QueryAllDataModel> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  46. Logger(typeof(GallerMangerApiController), param.TryToJson(), "GallerMangerApi/QuerAll链接成功", () =>
  47. {
  48. int totalrows = 0, totalpage = 0;
  49. List<QueryAllDataModel> list = TKApiBLL.QueryAll(param.PageIndex == 0 ? 1 : param.PageIndex, param.PageSize == 0 ? 10 : param.PageSize, param.TryToJson(), out totalrows, out totalpage, param.PeriodsNumber);
  50. PageData<QueryAllDataModel> pageData = new PageData<QueryAllDataModel>
  51. {
  52. TotalRow = totalrows,
  53. TotalPage = totalpage,
  54. PageIndex = param.PageIndex,
  55. Rows = list
  56. };
  57. resultMsg = new BaseJson4Page<QueryAllDataModel>
  58. {
  59. Status = (int)JsonObjectStatus.Success,
  60. Data = pageData,
  61. Message = JsonObjectStatus.Success.GetEnumText(),
  62. BackUrl = null
  63. };
  64. }, e =>
  65. {
  66. resultMsg = new BaseJson4Page<QueryAllDataModel>
  67. {
  68. Status = (int)JsonObjectStatus.Exception,
  69. Data = null,
  70. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  71. BackUrl = null
  72. };
  73. });
  74. return resultMsg.TryToJson().ToHttpResponseMessage();
  75. }
  76. /// <summary>
  77. /// 图库文章详细查询(公用)
  78. /// </summary>
  79. /// <returns></returns>
  80. [HttpPost]
  81. public HttpResponseMessage QueryArtInfo(ArtInfoParams artInfoParams)
  82. {
  83. BaseJson<ImageInfoModel> resultMsg = new BaseJson<ImageInfoModel> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  84. Logger(typeof(GallerMangerApiController), artInfoParams.TryToJson(), "GallerMangerApi/QueryArtInfo链接成功", () =>
  85. {
  86. if (string.IsNullOrEmpty(artInfoParams.GalleryId) && string.IsNullOrEmpty(artInfoParams.ID) && string.IsNullOrEmpty(artInfoParams.PeriodsNumber))
  87. {
  88. resultMsg = new BaseJson<ImageInfoModel>
  89. {
  90. Status = (int)JsonObjectStatus.Fail,
  91. Data = null,
  92. Message = JsonObjectStatus.Fail.GetEnumText() + "GallerMangerApi/QueryArtInfo参数错误: ",
  93. BackUrl = null
  94. };
  95. }
  96. ImageInfoModel data = TKApiBLL.QueryArtInfo(artInfoParams);
  97. resultMsg = new BaseJson<ImageInfoModel>
  98. {
  99. Status = (int)JsonObjectStatus.Success,
  100. Data = data,
  101. Message = JsonObjectStatus.Success.GetEnumText(),
  102. BackUrl = null
  103. };
  104. }, e =>
  105. {
  106. resultMsg = new BaseJson<ImageInfoModel>
  107. {
  108. Status = (int)JsonObjectStatus.Exception,
  109. Data = null,
  110. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  111. BackUrl = null
  112. };
  113. });
  114. return resultMsg.TryToJson().ToHttpResponseMessage();
  115. }
  116. /// <summary>
  117. /// 查询热门分类栏目列表
  118. /// </summary>
  119. /// <returns></returns>
  120. [HttpPost]
  121. public HttpResponseMessage QueryArtHotList(ArtHotListParams artHotListParams)
  122. {
  123. BaseJson4Page<ImageMenuInfoModel> resultMsg = new BaseJson4Page<ImageMenuInfoModel> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  124. Logger(typeof(GallerMangerApiController), artHotListParams.TryToJson(), "GallerMangerApi/QueryArtHotList链接成功", () =>
  125. {
  126. int totalrows = 0, totalpage = 0;
  127. if (string.IsNullOrEmpty(artHotListParams.menuName))
  128. {
  129. resultMsg = new BaseJson4Page<ImageMenuInfoModel>
  130. {
  131. Status = (int)JsonObjectStatus.Fail,
  132. Data = null,
  133. Message = JsonObjectStatus.Fail.GetEnumText() + "GallerMangerApi/QueryArtHotList参数错误: ",
  134. BackUrl = null
  135. };
  136. }
  137. List<ImageMenuInfoModel> list = TKApiBLL.QueryHotArtList(artHotListParams.PageIndex == 0 ? 1 : artHotListParams.PageIndex, artHotListParams.PageSize == 0 ? 10 : artHotListParams.PageSize, artHotListParams.menuName, out totalrows, out totalpage, artHotListParams.PeriodsNumber);
  138. PageData<ImageMenuInfoModel> pageData = new PageData<ImageMenuInfoModel>
  139. {
  140. TotalRow = totalrows,
  141. TotalPage = totalpage,
  142. PageIndex = artHotListParams.PageIndex,
  143. Rows = list
  144. };
  145. resultMsg = new BaseJson4Page<ImageMenuInfoModel>
  146. {
  147. Status = (int)JsonObjectStatus.Success,
  148. Data = pageData,
  149. Message = JsonObjectStatus.Success.GetEnumText(),
  150. BackUrl = null
  151. };
  152. }, e =>
  153. {
  154. resultMsg = new BaseJson4Page<ImageMenuInfoModel>
  155. {
  156. Status = (int)JsonObjectStatus.Exception,
  157. Data = null,
  158. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  159. BackUrl = null
  160. };
  161. });
  162. return resultMsg.TryToJson().ToHttpResponseMessage();
  163. }
  164. /// <summary>
  165. /// 热门分类菜单查询
  166. /// </summary>
  167. /// <returns></returns>
  168. public HttpResponseMessage QueryArtHotMenu(ArtHotMenuParams artHotMenuParams)
  169. {
  170. BaseJson<List<HotMenuModel>> resultMsg = new BaseJson<List<HotMenuModel>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  171. Logger(typeof(GallerMangerApiController), artHotMenuParams.TryToJson(), "GallerMangerApi/QueryArtHotMenu链接成功", () =>
  172. {
  173. string[] itemName = { "A", "B", "C" };
  174. if (!string.IsNullOrEmpty(artHotMenuParams.ItemName))
  175. {
  176. itemName = new string[] { artHotMenuParams.ItemName };
  177. }
  178. List<HotMenuModel> list = TKApiBLL.QueryHotMenu(itemName);
  179. resultMsg = new BaseJson<List<HotMenuModel>>
  180. {
  181. Status = (int)JsonObjectStatus.Success,
  182. Data = list,
  183. Message = JsonObjectStatus.Success.GetEnumText(),
  184. BackUrl = null
  185. };
  186. }, e =>
  187. {
  188. resultMsg = new BaseJson<List<HotMenuModel>>
  189. {
  190. Status = (int)JsonObjectStatus.Exception,
  191. Data = null,
  192. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  193. BackUrl = null
  194. };
  195. });
  196. return resultMsg.TryToJson().ToHttpResponseMessage();
  197. }
  198. /// <summary>
  199. /// 图库最新文章查询(分页)
  200. /// </summary>
  201. /// <returns></returns>
  202. ///
  203. [HttpPost]
  204. public HttpResponseMessage QueryNewArtList(ArtNewParams artNewParams)
  205. {
  206. BaseJson4Page<ImageMenuInfoModel> resultMsg = new BaseJson4Page<ImageMenuInfoModel> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  207. Logger(typeof(GallerMangerApiController), artNewParams.TryToJson(), "GallerMangerApi/QueryNewArtList链接成功", () =>
  208. {
  209. int totalrows = 0, totalpage = 0;
  210. List<ImageMenuInfoModel> list;
  211. string key = $"QueryNewArtList/{artNewParams.PeriodsNumber}/{artNewParams.PageIndex}/{artNewParams.PageSize}";
  212. if (webCache.IsExist(key))
  213. {
  214. var data = webCache.GetObject<DataTablePagerCache<List<ImageMenuInfoModel>>>(key) as DataTablePagerCache<List<ImageMenuInfoModel>>;
  215. list = data.Table as List<ImageMenuInfoModel>;
  216. totalpage = data.Total;
  217. }
  218. else
  219. {
  220. list = TKApiBLL.QueryNew(artNewParams.PageIndex == 0 ? 1 : artNewParams.PageIndex, artNewParams.PageSize == 0 ? 10 : artNewParams.PageSize, out totalrows, out totalpage, artNewParams.PeriodsNumber);
  221. var tablePager = new DataTablePagerCache<List<ImageMenuInfoModel>> { Total = totalrows, Table = list };
  222. webCache.AddObject(key, tablePager, (int)CacheTime.Data);
  223. }
  224. PageData<ImageMenuInfoModel> pageData = new PageData<ImageMenuInfoModel>
  225. {
  226. TotalRow = totalrows,
  227. TotalPage = totalpage,
  228. PageIndex = artNewParams.PageIndex,
  229. Rows = list
  230. };
  231. resultMsg = new BaseJson4Page<ImageMenuInfoModel>
  232. {
  233. Status = (int)JsonObjectStatus.Success,
  234. Data = pageData,
  235. Message = JsonObjectStatus.Success.GetEnumText(),
  236. BackUrl = null
  237. };
  238. }, e =>
  239. {
  240. resultMsg = new BaseJson4Page<ImageMenuInfoModel>
  241. {
  242. Status = (int)JsonObjectStatus.Exception,
  243. Data = null,
  244. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  245. BackUrl = null
  246. };
  247. });
  248. return resultMsg.TryToJson().ToHttpResponseMessage();
  249. }
  250. /// <summary>
  251. /// 图库期数列表
  252. /// </summary>
  253. /// <returns></returns>
  254. [HttpPost]
  255. public HttpResponseMessage GetTkPeriodsNumberList()
  256. {
  257. BaseJson<List<GalleryNumberList>> resultMsg = new BaseJson<List<GalleryNumberList>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  258. Logger(typeof(GallerMangerApiController), "", "GetTkPeriodsNumberList - 图库期数列表", () =>
  259. {
  260. #region 第一种方式,不可取
  261. //List<Tk_GalleryDetail> tkGalleries = tkDetailBll.GetList(n => n.IsDelete == false).OrderBy(n => n.PeriodsNumber).ToList();
  262. ////通过分组获取期数
  263. //IEnumerable<IGrouping<string, Tk_GalleryDetail>> group = tkGalleries.GroupBy(t => t.PeriodsNumber);
  264. ////开始遍历
  265. //foreach (IGrouping<string, Tk_GalleryDetail> grouping in group)
  266. //{
  267. // string key = grouping.Key;
  268. // GalleryNumberList preItem = new GalleryNumberList
  269. // {
  270. // PeriodsNumber = key,
  271. // Title = "2017" + key
  272. // };
  273. // newsPreviewItem.Add(preItem);
  274. //}
  275. #endregion
  276. #region 第二种方式
  277. //List<String> tkGalleries = tkDetailBll.GetList(n => n.IsDelete == false).Select(n => n.PeriodsNumber).ToList();
  278. //TODO
  279. //foreach (string s in tkGalleries)
  280. //{
  281. // GalleryNumberList preItem = new GalleryNumberList
  282. // {
  283. // PeriodsNumber = s,
  284. // Title = "2017" + s
  285. // };
  286. // newsPreviewItem.Add(preItem);
  287. //}
  288. #endregion
  289. #region 第三种
  290. //获取缓存
  291. List<GalleryNumberList> newsPreviewItem = Cache.Factory.CacheFactory.Cache().GetCache<List<GalleryNumberList>>("__TK_PERIODS__NUMBER__");
  292. //新获取缓存_zx(2018-9-25)
  293. newsPreviewItem = webCache.GetObject<List<GalleryNumberList>>("__TK_PERIODS__NUMBER__") as List<GalleryNumberList>;
  294. if (newsPreviewItem == null)
  295. {
  296. newsPreviewItem = new List<GalleryNumberList>();
  297. //查询出所有的分类
  298. List<Tk_Gallery> list = tkBll.GetList(t => t.IsDelete == false).ToList();
  299. //取出所有的分类ID
  300. List<string> ids = list.Select(n => n.ID).ToList();
  301. //再从详细里面取出去期数
  302. List<Tk_GalleryDetail> detailList = tkDetailBll.GetList(t => ids.Contains(t.GalleryId)).ToList();
  303. //取出期数
  304. List<string> preNumbers = detailList.Select(n => n.PeriodsNumber).OrderByDescending(n => n).ToList();
  305. //年份
  306. string year = DateTimeHelper.Now.Year.ToString();
  307. //分组
  308. IEnumerable<IGrouping<string, string>> group = preNumbers.GroupBy(p => p);
  309. foreach (IGrouping<string, string> grouping in group)
  310. {
  311. string key = grouping.Key;
  312. GalleryNumberList preItem = new GalleryNumberList
  313. {
  314. PeriodsNumber = key,
  315. Title = year + key
  316. };
  317. newsPreviewItem.Add(preItem);
  318. }
  319. newsPreviewItem = newsPreviewItem.Take(50).ToList();
  320. Cache.Factory.CacheFactory.Cache().WriteCache<List<GalleryNumberList>>(newsPreviewItem, "__TK_PERIODS__NUMBER__", DateTimeHelper.Now.AddHours(12));
  321. //新存入缓存_zx(2018-9-25)
  322. webCache.AddObject("__TK_PERIODS__NUMBER__", newsPreviewItem, (int)CacheTime.Data);
  323. }
  324. #endregion
  325. resultMsg = new BaseJson<List<GalleryNumberList>>
  326. {
  327. Status = (int)JsonObjectStatus.Success,
  328. Data = newsPreviewItem,
  329. Message = JsonObjectStatus.Success.GetEnumText(),
  330. BackUrl = null
  331. };
  332. }, e =>
  333. {
  334. resultMsg = new BaseJson<List<GalleryNumberList>>
  335. {
  336. Status = (int)JsonObjectStatus.Exception,
  337. Data = null,
  338. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  339. BackUrl = null
  340. };
  341. });
  342. return resultMsg.TryToJson().ToHttpResponseMessage();
  343. }
  344. /// <summary>
  345. /// 查询
  346. /// </summary>
  347. /// <returns></returns>
  348. [HttpPost]
  349. public HttpResponseMessage GetTrendChartSRC(TrendChartParams param)
  350. {
  351. BaseJson<TrendChartModel> resultMsg = new BaseJson<TrendChartModel> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  352. Logger(typeof(GallerMangerApiController), param.TryToJson(), "GetTkPeriodsNumberList - 图库期数列表", () =>
  353. {
  354. if (string.IsNullOrEmpty(param.LotteryType))
  355. {
  356. resultMsg = new BaseJson<TrendChartModel>
  357. {
  358. Status = (int)JsonObjectStatus.Exception,
  359. Data = null,
  360. Message = JsonObjectStatus.Exception.GetEnumText() + ",参数有误请确认:",
  361. BackUrl = null
  362. };
  363. }
  364. TrendChartBLL trendChartBLL = new TrendChartBLL();
  365. DataItemModel itemdata = itemCache.GetItemDetailByItemValue(param.LotteryType);//.GetEntityByCode(param.CategoryId);
  366. List<TrendChartEntity> list;
  367. string key = $"GetTrendChartSRC/{itemdata.ItemDetailId}/JBZST";
  368. if (webCache.IsExist(key))
  369. {
  370. list = webCache.GetObject<List<TrendChartEntity>>(key) as List<TrendChartEntity>;
  371. }
  372. else
  373. {
  374. list = trendChartBLL.GetPageList(s => s.CategoryId == itemdata.ItemDetailId && s.Title.Contains("基本走势图")).ToList();
  375. webCache.AddObject(key, list, (int)CacheTime.Data);
  376. }
  377. TrendChartModel data = new TrendChartModel();
  378. if (list.Count == 0)//继续采用走势图匹配
  379. {
  380. key = $"GetTrendChartSRC/{itemdata.ItemDetailId}/ZST";
  381. if (webCache.IsExist(key))
  382. {
  383. list = webCache.GetObject<List<TrendChartEntity>>(key) as List<TrendChartEntity>;
  384. }
  385. else
  386. {
  387. list = trendChartBLL.GetPageList(s => s.CategoryId == itemdata.ItemDetailId && s.Title == "走势图").ToList();
  388. webCache.AddObject(key, list, (int)CacheTime.Data);
  389. }
  390. }
  391. if (list.Count == 0)//继续采用走势图带连线 匹配
  392. {
  393. key = $"GetTrendChartSRC/{itemdata.ItemDetailId}/ZSTDLX";
  394. if (webCache.IsExist(key))
  395. {
  396. list = webCache.GetObject<List<TrendChartEntity>>(key) as List<TrendChartEntity>;
  397. }
  398. else
  399. {
  400. list = trendChartBLL.GetPageList(s => s.CategoryId == itemdata.ItemDetailId && s.Title == "走势图带连线").ToList();
  401. webCache.AddObject(key, list, (int)CacheTime.Data);
  402. }
  403. }
  404. if (list.Count == 0)//还是就返回失败
  405. {
  406. resultMsg = new BaseJson<TrendChartModel>
  407. {
  408. Status = (int)JsonObjectStatus.Fail,
  409. Data = null,
  410. Message = JsonObjectStatus.Exception.GetEnumText() + ",查询不到结果:",
  411. BackUrl = null
  412. };
  413. }
  414. else
  415. {
  416. data = new TrendChartModel()
  417. {
  418. Name = list[0].Title,
  419. Url = list[0].TrendChartUrl
  420. };
  421. }
  422. resultMsg = new BaseJson<TrendChartModel>()
  423. {
  424. Status = (int)JsonObjectStatus.Success,
  425. Data = data,
  426. Message = JsonObjectStatus.Success.GetEnumText(),
  427. BackUrl = null
  428. };
  429. }, e =>
  430. {
  431. resultMsg = new BaseJson<TrendChartModel>
  432. {
  433. Status = (int)JsonObjectStatus.Exception,
  434. Data = null,
  435. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  436. BackUrl = null
  437. };
  438. });
  439. return resultMsg.TryToJson().ToHttpResponseMessage();
  440. }
  441. }
  442. }