123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using CP.Cache;
- using CP.Dapper;
- using CP.Model;
- using CP.Model.ZiXun;
- using CP.Model.ZiXun.Entity;
- using CP.Model.ZiXun.Query;
- using Dapper;
- namespace CP.Business.ZiXun
- {
- public class NewManager : DbHelper
- {
- /// 缓存
- /// </summary>
- static WMCache cache = WMCache.GetCacheService();
- /// <summary>
- /// 获取新闻,资讯数据
- /// </summary>
- /// <param name="query"></param>
- /// <returns></returns>
- public List<newManagerModels> GetNewManagerList(NewManagerTopQuery query)
- {
- var list = new List<newManagerModels>();
- query.NewsTypeList.ForEach(p =>
- {
- string key = "NewManagerList" + (int)p;
- var data = cache.GetObject<List<newManagerModels>>(key);
- if (data == null)
- {
- var listAll = cache.GetObject<List<newManagerModels>>(CacheKeys.NewManagerListList);
- if (listAll == null)
- {
- listAll = GetAll(query.TopNumber);
- cache.AddObject(CacheKeys.NewManagerListList, listAll, (int)CacheTime.NewManager);
- }
- data = listAll.Where(q => q.menuId == (int)p).ToList().OrderByDescending(q => q.createTime).ToList();
- cache.AddObject(key, data, (int)CacheTime.NewManager);
- }
- list = list.Concat(data).ToList();
- });
- return list;
- }
- private List<newManagerModels> GetAll(int topNumber)
- {
- var sql = string.Empty;
- DynamicParameters Parameters = new DynamicParameters();
- FieldInfo[] enumFields = typeof(NewManagerTypeEnum).GetFields(); //获取字段信息对象集合
- var typeList = new List<int>();
- //遍历集合
- foreach (FieldInfo field in enumFields)
- {
- if (!field.IsSpecialName)
- {
- typeList.Add(Convert.ToInt32(field.GetRawConstantValue()));
- }
- }
- typeList.ForEach(p =>
- {
- sql += $"SELECT * FROM (SELECT TOP {topNumber} * FROM newManagerModels WHERE menuId = @menuId{typeList.IndexOf(p)} ORDER BY createTime DESC ) tem ";
- Parameters.Add("menuId" + typeList.IndexOf(p), p);
- if (typeList.IndexOf(p) != typeList.Count - 1)
- sql += " UNION ";
- });
- return db.FindList<newManagerModels>(sql, Parameters).ToList();
- }
- /// <summary>
- /// 得到公告
- /// </summary>
- /// <returns></returns>
- public NewList GetNewList()
- {
- string key = CacheKeys.NewList;
- var data = cache.GetObject<NewList>(key);
- if (data == null || data.ID <= 0)
- {
- string sql = $"" +
- $"SELECT TOP 1 [ID],[title],[description],[menuId],[createTime],[createUserName] FROM [dbo].[newManagerModels] " +
- $"WHERE menuId = @menuId AND isDelete = 0 ORDER BY createTime DESC ";
- var list = db.FindList<NewList>(sql, new { menuId = 108 }).ToList();
- data = list.Count > 0 ? list[0] : new NewList();
- cache.AddObject(key, data, (int)CacheTime.NewManager);
- }
- return data;
- }
- }
- }
|