Zxd.Core/code/Zxd.Domain/DeptmentDomain.cs

63 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<DncmsbaseDbContext> _repository;
private readonly IRedisManager _redisManager;
public DeptmentDomain(IBaseRepository<DncmsbaseDbContext> repository,
IRedisManager redisManager)
{
_repository = repository;
_redisManager = redisManager;
}
public async Task<List<DeptmentDto>> GetDeptments()
{
var key = CacheKeys.DeptmentList;
if (await _redisManager.ExistsAsync(key))
{
return await _redisManager.GetListAsync<DeptmentDto>(key);
}
var deptments = await _repository.GetRepository<Deptment>()
.QueryIncluding(x => x.DeptmentCampainIds)
.Where(x => x.DeleteType == 0)
.Where(x => x.Id != 1)
.ToListAsync();
var data = new List<DeptmentDto>();
foreach (var deptment in deptments)
{
var item = new DeptmentDto()
{
Id = deptment.Id,
Title = deptment.Title,
DeptmentCampains = new List<DeptmentCampainDto>()
};
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;
}
}
}