using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Zxd.Domain { public class DeptmentDomain : IDeptmentDomain { private readonly IBaseRepository _repository; private readonly IRedisManager _redisManager; public DeptmentDomain(IBaseRepository repository, IRedisManager redisManager) { _repository = repository; _redisManager = redisManager; } public async Task> GetDeptments() { var key = CacheKeys.DeptmentList; if (await _redisManager.ExistsAsync(key)) { return await _redisManager.GetListAsync(key); } var deptments = await _repository.GetRepository() .QueryIncluding(x => x.DeptmentCampainIds) .Where(x => x.DeleteType == 0) .Where(x => x.Id != 1) .ToListAsync(); var data = new List(); foreach (var deptment in deptments) { var item = new DeptmentDto() { Id = deptment.Id, Title = deptment.Title, DeptmentCampains = new List() }; if (deptment.DeptmentCampainIds == null) { data.Add(item); continue; } foreach (var deptmentCampain in deptment.DeptmentCampainIds) { item.DeptmentCampains.Add(new DeptmentCampainDto { EndCampainId = deptmentCampain.EndCampainId, StartCampainId = deptmentCampain.StartCampainId }); } data.Add(item); } await _redisManager.SetAsync(key, data, TimeSpan.FromDays(1)); Log.Information("ZXD查询Depts了:"+data.ToJson()); return data; } } }