72 lines
2.7 KiB
C#
72 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Hg.Core.Domain
|
|
{
|
|
internal class ProductDomain : IProductDomain
|
|
{
|
|
private readonly IBaseRepository<ZxdDbContext> _repository;
|
|
private readonly IHttpClient _httpClient;
|
|
private readonly IMapper _mapper;
|
|
private readonly ICacheDomain _cacheDomain;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly SystemConfig _systemConfig;
|
|
private readonly IRedisManager _redisManager;
|
|
|
|
public ProductDomain(IConfiguration configuration,
|
|
IBaseRepository<ZxdDbContext> repository,
|
|
IHttpClient httpClient,
|
|
IMapper mapper,
|
|
ICacheDomain cacheDomain,
|
|
IRedisManager redisManager
|
|
)
|
|
{
|
|
_systemConfig = configuration.GetSection("SystemConfig").Get<SystemConfig>();
|
|
_configuration = configuration;
|
|
_repository = repository;
|
|
_httpClient = httpClient;
|
|
_mapper = mapper;
|
|
_cacheDomain = cacheDomain;
|
|
_redisManager = redisManager;
|
|
}
|
|
|
|
public async Task<List<WxSzzyProduct>> GetProductList()
|
|
{
|
|
if (!await _redisManager.ExistsAsync(CacheKeys.ProductList))
|
|
{
|
|
var list = await _repository.GetRepository<WxSzzyProduct>().QueryListAsync();
|
|
await _redisManager.SetAsync(CacheKeys.ProductList, list, TimeSpan.FromDays(1));
|
|
return list;
|
|
}
|
|
else
|
|
{
|
|
var data = await _redisManager.GetListAsync<WxSzzyProduct>(CacheKeys.ProductList);
|
|
return data;
|
|
}
|
|
}
|
|
|
|
public async Task<List<WX_SZZYSUBPRODUCT>> GetSubProductListByProductId(int productId, int isValid, int? midprocutid)
|
|
{
|
|
var list = new List<WX_SZZYSUBPRODUCT>();
|
|
if (!await _redisManager.ExistsAsync(CacheKeys.SubProductList))
|
|
{
|
|
list = await _repository.GetRepository<WX_SZZYSUBPRODUCT>().QueryListAsync();
|
|
await _redisManager.SetAsync(CacheKeys.SubProductList, list, TimeSpan.FromDays(1));
|
|
}
|
|
else
|
|
{
|
|
list = await _redisManager.GetListAsync<WX_SZZYSUBPRODUCT>(CacheKeys.SubProductList);
|
|
}
|
|
list = list.If(productId > 0, x => x.Where(m => m.PRODUCTID == productId))
|
|
.If(isValid == 1, x => x.Where(m => m.ISVALID == isValid))
|
|
.If(midprocutid.HasValue, x => x.Where(m => m.MidProductId == midprocutid.Value))
|
|
.OrderBy(p => p.PRODUCTID).ToList();
|
|
|
|
return list;
|
|
}
|
|
}
|
|
}
|