添加项目文件。
This commit is contained in:
21
Atomx.Data/Atomx.Data.csproj
Normal file
21
Atomx.Data/Atomx.Data.csproj
Normal file
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="IdGen" Version="3.0.7" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.0" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Atomx.Common\Atomx.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
63
Atomx.Data/CacheServices/AgencyCacheService.cs
Normal file
63
Atomx.Data/CacheServices/AgencyCacheService.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
//namespace Atomx.Data.CacheServices
|
||||
//{
|
||||
// public partial interface ICacheService
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 获取代理信息
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<Agency> GetAgencyById(long id, bool? reload = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取代理的客服信息
|
||||
// /// </summary>
|
||||
// /// <param name="agencyId"></param>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<CustomerService>> GetCustomerServices(long agencyId, bool? reload = null);
|
||||
// }
|
||||
// public partial class CacheService : ICacheService
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 获取代理信息
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<Agency> GetAgencyById(long id, bool? reload = null)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<Agency>($"{CacheKeys.AgencyPrefix}{id}");
|
||||
|
||||
// if (cacheData == null || reload.HasValue)
|
||||
// {
|
||||
// var data = _dbContext.Agencies.SingleOrDefault(p => p.Id == id);
|
||||
// if (data != null)
|
||||
// {
|
||||
// cacheData = data;
|
||||
// await SetCacheAsync($"{CacheKeys.AgencyPrefix}{id}", cacheData);
|
||||
// }
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// public async Task<List<CustomerService>> GetCustomerServices(long agencyId, bool? reload = null)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<CustomerService>>($"{CacheKeys.CustomerServicePrefix}{agencyId}");
|
||||
|
||||
// if (cacheData == null || reload.HasValue)
|
||||
// {
|
||||
// var data = _dbContext.CustomerServices.Where(p => p.Enabled && p.AgencyId == agencyId).ToList();
|
||||
// if (data != null)
|
||||
// {
|
||||
// cacheData = data;
|
||||
// await SetCacheAsync($"{CacheKeys.CustomerServicePrefix}{agencyId}", cacheData);
|
||||
// }
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
97
Atomx.Data/CacheServices/AreaCacheService.cs
Normal file
97
Atomx.Data/CacheServices/AreaCacheService.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using Atomx.Common.Constant;
|
||||
using Atomx.Common.Entities;
|
||||
|
||||
namespace Atomx.Data.CacheServices
|
||||
{
|
||||
public partial interface ICacheService
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取国家数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<Area>> GetCountry(bool? reload = false);
|
||||
|
||||
/// <summary>
|
||||
/// 通过ID获取国家名称
|
||||
/// </summary>
|
||||
/// <param name="countryId"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> GetCountryName(long countryId);
|
||||
|
||||
/// <summary>
|
||||
/// 根据上级ID获取下级数据
|
||||
/// </summary>
|
||||
/// <param name="parentId"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<Area>> GetAreas(long parentId, bool? reload = false);
|
||||
|
||||
/// <summary>
|
||||
/// 更新调整缓存数据
|
||||
/// </summary>
|
||||
/// <param name="area"></param>
|
||||
/// <returns></returns>
|
||||
Task ResetArea(Area area);
|
||||
}
|
||||
public partial class CacheService : ICacheService
|
||||
{
|
||||
public async Task<List<Area>> GetCountry(bool? reload = false)
|
||||
{
|
||||
bool reloadData = reload.HasValue ? reload.Value : false;
|
||||
|
||||
var cacheData = await GetCacheAsync<List<Area>>(CacheKeys.Country);
|
||||
if(cacheData == null || reloadData)
|
||||
{
|
||||
var countries = (from p in _dbContext.Areas
|
||||
where p.ParentId == 0
|
||||
select p).ToList();
|
||||
await SetCacheAsync(CacheKeys.Country, countries);
|
||||
return countries;
|
||||
|
||||
}
|
||||
return cacheData;
|
||||
}
|
||||
|
||||
public async Task<string> GetCountryName(long countryId)
|
||||
{
|
||||
var cacheData = await GetCountry();
|
||||
var data = cacheData.SingleOrDefault(p => p.Id == countryId);
|
||||
if (data == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return data.Name;
|
||||
}
|
||||
|
||||
public async Task<List<Area>> GetAreas(long parentId, bool? reload = false)
|
||||
{
|
||||
if (parentId == 0)
|
||||
{
|
||||
return await GetCountry();
|
||||
}
|
||||
var cacheData = await GetCacheAsync<List<Area>>($"{CacheKeys.Area}.{parentId}");
|
||||
bool reloadData = reload.HasValue ? reload.Value : false;
|
||||
if (cacheData == null || reloadData)
|
||||
{
|
||||
var data = (from p in _dbContext.Areas
|
||||
where p.ParentId == 0
|
||||
select p).ToList();
|
||||
await SetCacheAsync(CacheKeys.Country, data);
|
||||
return data;
|
||||
|
||||
}
|
||||
return cacheData;
|
||||
}
|
||||
|
||||
public async Task ResetArea(Area area)
|
||||
{
|
||||
var cacheData = await GetAreas(area.ParentId);
|
||||
var data = cacheData.Where(p => p.Id == area.Id).SingleOrDefault();
|
||||
if (data != null)
|
||||
{
|
||||
cacheData.Remove(data);
|
||||
}
|
||||
cacheData.Add(area);
|
||||
await SetCacheAsync($"{CacheKeys.Area}.{area.ParentId}", cacheData);
|
||||
}
|
||||
}
|
||||
}
|
||||
253
Atomx.Data/CacheServices/AttributeCacheService.cs
Normal file
253
Atomx.Data/CacheServices/AttributeCacheService.cs
Normal file
@@ -0,0 +1,253 @@
|
||||
//using Atomx.Common.Entities;
|
||||
|
||||
//namespace Atomx.Data.CacheServices
|
||||
//{
|
||||
// public partial interface ICacheService
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 获取产品属性值缓存列表
|
||||
// /// </summary>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<ProductAttribute>> GetProductAttributes(List<ProductAttribute>? data = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过ID获取或更新缓存
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<ProductAttribute> GetProductAttributeById(long id, ProductAttribute? data = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 从缓存中删除数据
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <returns></returns>
|
||||
// Task RemoveProductAttribute(long id);
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取产品预设值
|
||||
// /// </summary>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<ProductAttributeOption>> GetProductAttributeOptions(long attributeId, List<ProductAttributeOption>? data = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过ID获取或更新缓存
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<ProductAttributeOption> GetProductAttributeOptionById(long attributeId, long id, ProductAttributeOption? data = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 从缓存中删除数据
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <returns></returns>
|
||||
// Task RemoveProductAttributeOption(long attributeId, long id);
|
||||
|
||||
// /// <summary>
|
||||
// /// 根据ID获取属性树结构
|
||||
// /// </summary>
|
||||
// /// <param name="attributeId"></param>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<AttributeTreeModel> GetAttributeTree(long attributeId);
|
||||
|
||||
// }
|
||||
// public partial class CacheService : ICacheService
|
||||
// {
|
||||
// public async Task<List<ProductAttribute>> GetProductAttributes(List<ProductAttribute>? data = null)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<ProductAttribute>>(CacheKeys.ProductAttributes);
|
||||
// if (data != null)
|
||||
// {
|
||||
// cacheData = data;
|
||||
// await SetCacheAsync(CacheKeys.ProductAttributes, cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (cacheData == null)
|
||||
// {
|
||||
// return new List<ProductAttribute>();
|
||||
// }
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// public async Task<ProductAttribute> GetProductAttributeById(long id, ProductAttribute? data = null)
|
||||
// {
|
||||
// var cacheData = await GetProductAttributes();
|
||||
// if (data != null)
|
||||
// {
|
||||
// var attribute = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (attribute != null)
|
||||
// {
|
||||
// cacheData.Remove(attribute);
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync(CacheKeys.ProductAttributes, cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync(CacheKeys.ProductAttributes, cacheData);
|
||||
// }
|
||||
// return data;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var attribute = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (attribute != null)
|
||||
// {
|
||||
// return attribute;
|
||||
// }
|
||||
// return new ProductAttribute();
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// public async Task RemoveProductAttribute(long id)
|
||||
// {
|
||||
// var cacheData = await GetProductAttributes();
|
||||
// if (cacheData != null)
|
||||
// {
|
||||
// var data = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (data != null)
|
||||
// {
|
||||
// cacheData.Remove(data);
|
||||
// await SetCacheAsync(CacheKeys.ProductAttributes, cacheData);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取产品预设值
|
||||
// /// </summary>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<List<ProductAttributeOption>> GetProductAttributeOptions(long attributeId, List<ProductAttributeOption>? data = null)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<ProductAttributeOption>>($"{CacheKeys.ProductAttributeOptionsPrefix}{attributeId}");
|
||||
// if (data != null)
|
||||
// {
|
||||
// cacheData = data;
|
||||
// await SetCacheAsync($"{CacheKeys.ProductAttributeOptionsPrefix}{attributeId}", cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (cacheData == null)
|
||||
// {
|
||||
// return new List<ProductAttributeOption>();
|
||||
// }
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过ID获取或更新缓存
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<ProductAttributeOption> GetProductAttributeOptionById(long attributeId, long id, ProductAttributeOption? data = null)
|
||||
// {
|
||||
// var cacheData = await GetProductAttributeOptions(attributeId);
|
||||
// if (data != null)
|
||||
// {
|
||||
// var attribute = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (attribute != null)
|
||||
// {
|
||||
// cacheData.Remove(attribute);
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync($"{CacheKeys.ProductAttributeOptionsPrefix}{attributeId}", cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync($"{CacheKeys.ProductAttributeOptionsPrefix}{attributeId}", cacheData);
|
||||
// }
|
||||
// return data;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var attribute = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (attribute != null)
|
||||
// {
|
||||
// return attribute;
|
||||
// }
|
||||
// return new ProductAttributeOption();
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 从缓存中删除数据
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task RemoveProductAttributeOption(long attributeId, long id)
|
||||
// {
|
||||
// var cacheData = await GetProductAttributeOptions(attributeId);
|
||||
// if (cacheData != null)
|
||||
// {
|
||||
// var data = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (data != null)
|
||||
// {
|
||||
// cacheData.Remove(data);
|
||||
// await SetCacheAsync($"{CacheKeys.ProductAttributeOptionsPrefix}{attributeId}", cacheData);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取属性结构缓存
|
||||
// /// </summary>
|
||||
// /// <param name="attributeId"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<AttributeTreeModel> GetAttributeTree(long attributeId)
|
||||
// {
|
||||
// var attribute = await GetProductAttributeById(attributeId);
|
||||
// var options = await GetProductAttributeOptions(attributeId);
|
||||
|
||||
// if (attribute.Id ==0)
|
||||
// {
|
||||
// attribute = _dbContext.ProductAttributes.SingleOrDefault(p => p.Id == attributeId);
|
||||
// if (attribute != null)
|
||||
// {
|
||||
// await GetProductAttributeById(attribute.Id, attribute);
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (attribute == null)
|
||||
// {
|
||||
// return new AttributeTreeModel();
|
||||
// }
|
||||
|
||||
// if (!options.Any())
|
||||
// {
|
||||
// options = _dbContext.ProductAttributeOptions.Where(p => p.AttributeId == attributeId).ToList();
|
||||
// if (options.Any())
|
||||
// {
|
||||
// await GetProductAttributeOptions(attribute.Id, options);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// var data = new AttributeTreeModel()
|
||||
// {
|
||||
// Id = attribute.Id,
|
||||
// Name = attribute.Name,
|
||||
// ProductTypeId = attribute.ProductTypeId,
|
||||
// PredefinedValues = options
|
||||
// };
|
||||
// return data;
|
||||
// }
|
||||
|
||||
// }
|
||||
//}
|
||||
46
Atomx.Data/CacheServices/BasicCacheService.cs
Normal file
46
Atomx.Data/CacheServices/BasicCacheService.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
//namespace Atomx.Data.CacheServices
|
||||
//{
|
||||
// public partial interface ICacheService
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 获取行为日志类型,自动初始化
|
||||
// /// </summary>
|
||||
// /// <param name="reload">是否重载</param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<ActionLogType>> GetActionLogTypes(bool reload = false);
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取行为日志类型
|
||||
// /// </summary>
|
||||
// /// <param name="reload">是否重载</param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<ActionLogType>> GetActionLogTypeList(List<ActionLogType>? data = null);
|
||||
// }
|
||||
// public partial class CacheService : ICacheService
|
||||
// {
|
||||
// public async Task<List<ActionLogType>> GetActionLogTypes(bool reload = false)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<ActionLogType>>(CacheKeys.ActionLogType);
|
||||
// if (cacheData == null || reload)
|
||||
// {
|
||||
// cacheData = _dbContext.ActionLogTypes.ToList();
|
||||
// await SetCacheAsync(CacheKeys.ActionLogType, cacheData);
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// public async Task<List<ActionLogType>> GetActionLogTypeList(List<ActionLogType>? data = null)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<ActionLogType>>(CacheKeys.ActionLogType);
|
||||
// if (cacheData == null || data != null)
|
||||
// {
|
||||
// cacheData = data;
|
||||
// await SetCacheAsync(CacheKeys.ActionLogType, cacheData);
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
176
Atomx.Data/CacheServices/CacheService.cs
Normal file
176
Atomx.Data/CacheServices/CacheService.cs
Normal file
@@ -0,0 +1,176 @@
|
||||
using Atomx.Data;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Atomx.Data.CacheServices
|
||||
{
|
||||
public partial interface ICacheService
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置缓存
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="time">缓存时间,默认8小时</param>
|
||||
/// <returns></returns>
|
||||
Task SetCacheAsync<T>(string key, T value, double time = 8);
|
||||
|
||||
/// <summary>
|
||||
/// 根据指定KEY获取数据
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
Task<T?> GetCacheAsync<T>(string key);
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定 key 的缓存List数据
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<T>> GetCacheList<T>(string key);
|
||||
|
||||
/// <summary>
|
||||
/// 清除指定 key 的缓存
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
Task Remove(string key);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public partial class CacheService : ICacheService
|
||||
{
|
||||
readonly DataContext _dbContext;
|
||||
readonly IDistributedCache _cache;
|
||||
|
||||
public CacheService(DataContext dataContext, IDistributedCache distributedCache)
|
||||
{
|
||||
_dbContext = dataContext;
|
||||
_cache = distributedCache;
|
||||
}
|
||||
|
||||
|
||||
public Task Remove(string key)
|
||||
{
|
||||
_cache.Remove(key);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
public T? GetCache<T>(string key)
|
||||
{
|
||||
try
|
||||
{
|
||||
var cacheData = _cache.GetString(key);
|
||||
if (cacheData != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return JsonSerializer.Deserialize<T>(cacheData);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.BackgroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"无法链接缓存服务,读取缓存数据失败,错误信息:{ex.Message}");
|
||||
Console.ResetColor();
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
public async Task<T?> GetCacheAsync<T>(string key)
|
||||
{
|
||||
try
|
||||
{
|
||||
var cacheData = await _cache.GetStringAsync(key);
|
||||
if (cacheData != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return JsonSerializer.Deserialize<T>(cacheData);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.BackgroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"无法链接缓存服务,读取缓存数据失败,错误信息:{ex.Message}");
|
||||
Console.ResetColor();
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
public async Task<List<T>> GetCacheList<T>(string key)
|
||||
{
|
||||
var cacheData = await _cache.GetStringAsync(key);
|
||||
if (cacheData != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = JsonSerializer.Deserialize<List<T>>(cacheData);
|
||||
if (data != null)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new List<T>();
|
||||
}
|
||||
}
|
||||
return new List<T>();
|
||||
}
|
||||
|
||||
public void SetCache<T>(string key, T value, double time = 8)
|
||||
{
|
||||
var options = new DistributedCacheEntryOptions();
|
||||
var minute = time * 60;
|
||||
var timspace = TimeSpan.FromMinutes(minute);
|
||||
options.SetSlidingExpiration(timspace);
|
||||
|
||||
try
|
||||
{
|
||||
_cache.SetString(key, JsonSerializer.Serialize(value), options);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.BackgroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"无法链接缓存服务,写入缓存数据失败,错误信息:{ex.Message}");
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SetCacheAsync<T>(string key, T value, double time = 8)
|
||||
{
|
||||
var options = new DistributedCacheEntryOptions();
|
||||
var minute = time * 60;
|
||||
var timspace = TimeSpan.FromMinutes(minute);
|
||||
options.SetSlidingExpiration(timspace);
|
||||
|
||||
try
|
||||
{
|
||||
await _cache.SetStringAsync(key, JsonSerializer.Serialize(value), options);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.BackgroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"无法链接缓存服务,写入缓存数据失败,错误信息:{ex.Message}");
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
300
Atomx.Data/CacheServices/CategoryCacheService.cs
Normal file
300
Atomx.Data/CacheServices/CategoryCacheService.cs
Normal file
@@ -0,0 +1,300 @@
|
||||
using Atomx.Common.Constant;
|
||||
using Atomx.Common.Entities;
|
||||
using Atomx.Common.Enums;
|
||||
using Atomx.Common.Models;
|
||||
using Atomx.Utils.Extension;
|
||||
using Mapster;
|
||||
|
||||
namespace Atomx.Data.CacheServices
|
||||
{
|
||||
public partial interface ICacheService
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取内容分类列表
|
||||
/// </summary>
|
||||
/// <param name="reload"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<CategoryItemModel>> GetContentCategoryList(bool? reload = false);
|
||||
|
||||
/// <summary>
|
||||
/// 获取产品分类列表
|
||||
/// </summary>
|
||||
/// <param name="reload"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<CategoryItemModel>> GetProductCategoryList(bool? reload = false);
|
||||
|
||||
/// <summary>
|
||||
/// 获取可用的缓存信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<Category>> GetContentCategories(List<Category>? data = null);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 通过ID获取或更新缓存
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
Task<Category> GetContentCategoryById(long id, Category? data = null);
|
||||
|
||||
/// <summary>
|
||||
/// 从缓存中移除分类缓存
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task RemoveContentCategory(long id);
|
||||
|
||||
/// <summary>
|
||||
/// 获取可用的缓存信息
|
||||
/// </summary>
|
||||
/// <param name="reload"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<Category>> GetProductCategories(bool? reload = false);
|
||||
|
||||
/// <summary>
|
||||
/// 通过ID获取或更新缓存
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
Task<Category> GetProductCategoryById(long id, Category? data = null);
|
||||
|
||||
/// <summary>
|
||||
/// 重缓存中移除产品分类
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task RemoveProductCategory(long id);
|
||||
}
|
||||
public partial class CacheService : ICacheService
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取内容分类列表
|
||||
/// </summary>
|
||||
/// <param name="reload"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<CategoryItemModel>> GetContentCategoryList(bool? reload = false)
|
||||
{
|
||||
var cacheData = await GetCacheAsync<List<CategoryItemModel>>(CacheKeys.ContentCategories);
|
||||
bool needReload = reload.HasValue ? reload.Value : false;
|
||||
if (cacheData == null || needReload)
|
||||
{
|
||||
var category = _dbContext.Categories.Where(p => p.Type == (int)CategoryType.Content).ToList();
|
||||
var list = new List<CategoryItemModel>();
|
||||
cacheData = BuildCategoryList(list, category, 0);
|
||||
await SetCacheAsync(CacheKeys.ContentCategories, cacheData);
|
||||
}
|
||||
return cacheData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取产品分类列表
|
||||
/// </summary>
|
||||
/// <param name="reload"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<CategoryItemModel>> GetProductCategoryList(bool? reload = false)
|
||||
{
|
||||
var cacheData = await GetCacheAsync<List<CategoryItemModel>>(CacheKeys.ProductCategories);
|
||||
bool needReload = reload.HasValue ? reload.Value : false;
|
||||
if (cacheData == null || needReload)
|
||||
{
|
||||
var category = _dbContext.Categories.Where(p => p.Type == (int)CategoryType.Product).ToList();
|
||||
var list = new List<CategoryItemModel>();
|
||||
cacheData = BuildCategoryList(list, category, 0);
|
||||
await SetCacheAsync(CacheKeys.ProductCategories, cacheData);
|
||||
}
|
||||
return cacheData;
|
||||
}
|
||||
|
||||
List<CategoryItemModel> BuildCategoryList(List<CategoryItemModel> list, List<Category> data, long parentId)
|
||||
{
|
||||
var categories = data.Where(p => p.ParentId == parentId).OrderBy(p => p.DisplayOrder).ToList();
|
||||
foreach (var item in categories)
|
||||
{
|
||||
var category = item.Adapt<CategoryItemModel>();
|
||||
|
||||
if (!string.IsNullOrEmpty(item.Path))
|
||||
{
|
||||
var ids = item.Path.Split(',').Select(p => p.ToLong()).ToList();
|
||||
var breadcrumbs = string.Empty;
|
||||
foreach (var id in ids)
|
||||
{
|
||||
var name = data.Where(p => p.Id == id).Select(p => p.Name).SingleOrDefault();
|
||||
if (!string.IsNullOrEmpty(breadcrumbs))
|
||||
{
|
||||
breadcrumbs = breadcrumbs + " >> " + name;
|
||||
}
|
||||
else
|
||||
{
|
||||
breadcrumbs = name;
|
||||
}
|
||||
}
|
||||
|
||||
category.Breadcrumbs = breadcrumbs;
|
||||
category.Breadcrumbs = breadcrumbs + " >> " + category.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
category.Breadcrumbs = item.Name;
|
||||
}
|
||||
list.Add(category);
|
||||
if (data.Count(p => p.ParentId == item.Id) > 0)
|
||||
{
|
||||
List<CategoryItemModel> childlist = new List<CategoryItemModel>();
|
||||
childlist = BuildCategoryList(childlist, data, item.Id);
|
||||
list.AddRange(childlist);
|
||||
}
|
||||
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public async Task<Category> GetProductCategoryById(long id, Category? data = null)
|
||||
{
|
||||
var cacheData = await GetProductCategories();
|
||||
if (data != null)
|
||||
{
|
||||
var category = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
if (category != null)
|
||||
{
|
||||
cacheData.Remove(category);
|
||||
cacheData.Add(data);
|
||||
await SetCacheAsync(CacheKeys.ProductCategories, cacheData);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheData.Add(data);
|
||||
await SetCacheAsync(CacheKeys.ProductCategories, cacheData);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
else
|
||||
{
|
||||
var category = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
if (category == null)
|
||||
{
|
||||
category = _dbContext.Categories.SingleOrDefault(p => p.Id == id);
|
||||
if (category != null)
|
||||
{
|
||||
cacheData.Add(category);
|
||||
await SetCacheAsync(CacheKeys.ProductCategories, cacheData);
|
||||
}
|
||||
}
|
||||
return category;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RemoveProductCategory(long id)
|
||||
{
|
||||
var cacheData = await GetProductCategories();
|
||||
if (cacheData != null)
|
||||
{
|
||||
var data = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
if (data != null)
|
||||
{
|
||||
cacheData.Remove(data);
|
||||
await SetCacheAsync(CacheKeys.ProductCategories, cacheData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<Category>> GetContentCategories(List<Category>? data = null)
|
||||
{
|
||||
var cacheData = await GetCacheAsync<List<Category>>(CacheKeys.ContentCategories);
|
||||
if (data != null)
|
||||
{
|
||||
cacheData = data;
|
||||
await SetCacheAsync(CacheKeys.ContentCategories, cacheData);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cacheData == null)
|
||||
{
|
||||
return new List<Category>();
|
||||
}
|
||||
}
|
||||
|
||||
return cacheData;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取可用的缓存信息
|
||||
/// </summary>
|
||||
/// <param name="reload"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<Category>> GetProductCategories(bool? reload = false)
|
||||
{
|
||||
var cacheData = await GetCacheAsync<List<Category>>(CacheKeys.ProductCategories);
|
||||
bool needReload = reload.HasValue ? reload.Value : false;
|
||||
if (cacheData == null || needReload)
|
||||
{
|
||||
var data = _dbContext.Categories.Where(p => p.Type == (int)CategoryType.Product && p.Enabled).ToList();
|
||||
|
||||
cacheData = data;
|
||||
|
||||
await SetCacheAsync(CacheKeys.ProductCategories, cacheData);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cacheData == null)
|
||||
{
|
||||
return new List<Category>();
|
||||
}
|
||||
}
|
||||
|
||||
return cacheData;
|
||||
}
|
||||
|
||||
public async Task<Category> GetContentCategoryById(long id, Category? data = null)
|
||||
{
|
||||
var cacheData = await GetContentCategories();
|
||||
if (data != null)
|
||||
{
|
||||
var category = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
if (category != null)
|
||||
{
|
||||
cacheData.Remove(category);
|
||||
cacheData.Add(data);
|
||||
await SetCacheAsync(CacheKeys.ContentCategories, cacheData);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheData.Add(data);
|
||||
await SetCacheAsync(CacheKeys.ContentCategories, cacheData);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
else
|
||||
{
|
||||
var category = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
if (category == null)
|
||||
{
|
||||
category = _dbContext.Categories.SingleOrDefault(p => p.Id == id);
|
||||
if (category != null)
|
||||
{
|
||||
cacheData.Add(category);
|
||||
await SetCacheAsync(CacheKeys.ContentCategories, cacheData);
|
||||
}
|
||||
}
|
||||
return category;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RemoveContentCategory(long id)
|
||||
{
|
||||
var cacheData = await GetContentCategories();
|
||||
if (cacheData != null)
|
||||
{
|
||||
var data = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
if (data != null)
|
||||
{
|
||||
cacheData.Remove(data);
|
||||
await SetCacheAsync(CacheKeys.ContentCategories, cacheData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
320
Atomx.Data/CacheServices/ConfigCacheService.cs
Normal file
320
Atomx.Data/CacheServices/ConfigCacheService.cs
Normal file
@@ -0,0 +1,320 @@
|
||||
//using Atomx.Common.Entities;
|
||||
|
||||
//namespace Atomx.Data.CacheServices
|
||||
//{
|
||||
// public partial interface ICacheService
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 获取管理员菜单系统
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<PermissionRecord>> GetAdminMenu(List<PermissionRecord>? data = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取角色信息
|
||||
// /// </summary>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<Role>> GetRoles(Role? data = null, bool remove = false);
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取基本配置信息
|
||||
// /// </summary>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<GeneralConfig> GetGeneralConfig(bool? reload = false);
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取系统默认语言ID
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// Task<int> GetDefaultLanguageId();
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取系统默认语言
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// Task<string> GetDefaultLanguage();
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取货币ID
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// Task<int> GetCurrencyId();
|
||||
|
||||
// /// <summary>
|
||||
// /// 货币代码
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// Task<string> GetCurrency();
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取邮件配置
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<EmailConfig> GetEmailConfig(bool? reload = false);
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取忘记交易密码邮件内容模板
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<EmailTemplateConfig> GetForgetTransactionPasswordEmailTemplate(bool? reload = false);
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取忘记交易密码邮件内容模板
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<EmailTemplateConfig> GetForgetPasswordEmailTemplate(bool? reload = false);
|
||||
|
||||
// /// <summary>
|
||||
// /// 账号激活邮件内容模板
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<EmailTemplateConfig> GetRegisterActiveEmailTemplate(bool? reload = false);
|
||||
|
||||
// }
|
||||
// public partial class CacheService : ICacheService
|
||||
// {
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取管理员菜单系统
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<List<PermissionRecord>> GetAdminMenu(List<PermissionRecord>? data = null)
|
||||
// {
|
||||
|
||||
// var cacheData = await GetCacheAsync<List<PermissionRecord>>(CacheKeys.AdminMenu);
|
||||
// if (data != null)
|
||||
// {
|
||||
// await SetCacheAsync(CacheKeys.AdminMenu, data);
|
||||
// cacheData = data;
|
||||
// }
|
||||
// if (cacheData == null)
|
||||
// {
|
||||
// return new List<PermissionRecord>();
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取基础缓存信息
|
||||
// /// </summary>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// /// <exception cref="NotImplementedException"></exception>
|
||||
// public async Task<GeneralConfig> GetGeneralConfig(bool? reload = false)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<GeneralConfig>(CacheKeys.GeneralConfig);
|
||||
// var needReload = reload.Value;
|
||||
|
||||
// if (cacheData == null || needReload)
|
||||
// {
|
||||
// var config = _dbContext.Configs.SingleOrDefault(p => p.Key == ConfigKeys.General);
|
||||
// if (config != null)
|
||||
// {
|
||||
// cacheData = config.Content.FromJson<GeneralConfig>();
|
||||
// await SetCacheAsync(CacheKeys.GeneralConfig, cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return new GeneralConfig();
|
||||
// }
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取角色得信息
|
||||
// /// </summary>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<List<Role>> GetRoles(Role? data = null, bool remove = false)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<Role>>(CacheKeys.Roles);
|
||||
// if (data != null)
|
||||
// {
|
||||
// if (cacheData != null)
|
||||
// {
|
||||
// var role = cacheData.SingleOrDefault(p => p.Id == data.Id);
|
||||
// if (role != null)
|
||||
// {
|
||||
// cacheData.Remove(role);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// cacheData = new List<Role>();
|
||||
|
||||
// }
|
||||
// if (!remove)
|
||||
// {
|
||||
// cacheData.Add(data);
|
||||
// }
|
||||
// await SetCacheAsync(CacheKeys.Roles, cacheData);
|
||||
// }
|
||||
// if (cacheData == null)
|
||||
// {
|
||||
// return new List<Role>();
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取系统默认语言ID
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// public async Task<int> GetDefaultLanguageId()
|
||||
// {
|
||||
// var data = await GetGeneralConfig();
|
||||
// return data.LanguageId;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取系统默认语言
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// public async Task<string> GetDefaultLanguage()
|
||||
// {
|
||||
// var data = await GetGeneralConfig();
|
||||
// return data.Language;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取货币ID
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// public async Task<int> GetCurrencyId()
|
||||
// {
|
||||
// var data = await GetGeneralConfig();
|
||||
// return data.PrimaryCurrencyId;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 货币代码
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// public async Task<string> GetCurrency()
|
||||
// {
|
||||
// var data = await GetGeneralConfig();
|
||||
// return data.PrimaryCurrency;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取邮件服务配置
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<EmailConfig> GetEmailConfig(bool? reload = false)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<EmailConfig>(CacheKeys.EmailConfig);
|
||||
// var needReload = reload.Value;
|
||||
|
||||
// if (cacheData == null || needReload)
|
||||
// {
|
||||
// var config = _dbContext.Configs.SingleOrDefault(p => p.Key == ConfigKeys.EmailServer);
|
||||
// if (config != null)
|
||||
// {
|
||||
// cacheData = config.Content.FromJson<EmailConfig>();
|
||||
// await SetCacheAsync(CacheKeys.EmailConfig, cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return new EmailConfig();
|
||||
// }
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取忘记交易密码邮件内容模板
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<EmailTemplateConfig> GetForgetTransactionPasswordEmailTemplate(bool? reload = false)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<EmailTemplateConfig>(CacheKeys.ForgetTransactionPasswordEmailTemplateConfig);
|
||||
// var needReload = reload.Value;
|
||||
|
||||
// if (cacheData == null || needReload)
|
||||
// {
|
||||
// var config = _dbContext.Configs.SingleOrDefault(p => p.Key == ConfigKeys.ForgetTransactionPasswordEmailTemplate);
|
||||
// if (config != null)
|
||||
// {
|
||||
// cacheData = config.Content.FromJson<EmailTemplateConfig>();
|
||||
// await SetCacheAsync(CacheKeys.ForgetTransactionPasswordEmailTemplateConfig, cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return new EmailTemplateConfig();
|
||||
// }
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取忘记交易密码邮件内容模板
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<EmailTemplateConfig> GetForgetPasswordEmailTemplate(bool? reload = false)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<EmailTemplateConfig>(CacheKeys.ForgetPasswordEmailTemplateConfig);
|
||||
// var needReload = reload.Value;
|
||||
|
||||
// if (cacheData == null || needReload)
|
||||
// {
|
||||
// var config = _dbContext.Configs.SingleOrDefault(p => p.Key == ConfigKeys.ForgetPasswordEmailTemplate);
|
||||
// if (config != null)
|
||||
// {
|
||||
// cacheData = config.Content.FromJson<EmailTemplateConfig>();
|
||||
// await SetCacheAsync(CacheKeys.ForgetPasswordEmailTemplateConfig, cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return new EmailTemplateConfig();
|
||||
// }
|
||||
// }
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取忘记交易密码邮件内容模板
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<EmailTemplateConfig> GetRegisterActiveEmailTemplate(bool? reload = false)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<EmailTemplateConfig>(CacheKeys.RegisterActiveEmailTemplateConfig);
|
||||
// var needReload = reload.Value;
|
||||
|
||||
// if (cacheData == null || needReload)
|
||||
// {
|
||||
// var config = _dbContext.Configs.SingleOrDefault(p => p.Key == ConfigKeys.RegisterEmailActiveTemplate);
|
||||
// if (config != null)
|
||||
// {
|
||||
// cacheData = config.Content.FromJson<EmailTemplateConfig>();
|
||||
// await SetCacheAsync(CacheKeys.RegisterActiveEmailTemplateConfig, cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return new EmailTemplateConfig();
|
||||
// }
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
84
Atomx.Data/CacheServices/ContentCacheService.cs
Normal file
84
Atomx.Data/CacheServices/ContentCacheService.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
//namespace Atomx.Data.CacheServices
|
||||
//{
|
||||
|
||||
// public partial interface ICacheService
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 通过 slug 获取缓存中的页面主题信息
|
||||
// /// </summary>
|
||||
// /// <param name="slug"></param>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<PageContentModel?> GetPage(string slug, PageContentModel? data = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过ID获取缓存
|
||||
// /// </summary>
|
||||
// /// <param name="slug"></param>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<PageContentModel?> GetContent(string slug, bool? reload = null);
|
||||
// }
|
||||
// public partial class CacheService : ICacheService
|
||||
// {
|
||||
// public async Task<PageContentModel?> GetPage(string slug, PageContentModel? data = null)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<PageContentModel>($"{CacheKeys.ContentPrefix}{slug}");
|
||||
// if (data != null)
|
||||
// {
|
||||
// cacheData = data;
|
||||
// await SetCacheAsync($"{CacheKeys.ContentPrefix}{slug}", cacheData);
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过ID获取缓存
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<PageContentModel?> GetContent(string slug, bool? reload = null)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<PageContentModel>($"{CacheKeys.ContentPrefix}{slug}");
|
||||
// if (cacheData == null || reload.HasValue)
|
||||
// {
|
||||
// var content = (from p in _dbContext.Contents
|
||||
// where p.Slug == slug && p.Status == (int)ContentStatus.Publish
|
||||
// select new PageContentModel
|
||||
// {
|
||||
// AllowComment = p.AllowComment,
|
||||
// Status = p.Status,
|
||||
// Body = p.Body,
|
||||
// CategoryId = p.CategoryId,
|
||||
// CreateTime = p.CreateTime,
|
||||
// Description = p.Description,
|
||||
// Id = p.Id,
|
||||
// Localized = new(),
|
||||
// IsTop = p.IsTop,
|
||||
// LanguageId = p.LanguageId,
|
||||
// MetaDescription = p.MetaDescription,
|
||||
// MetaTitle = p.MetaTitle,
|
||||
// PublishTime = p.PublishTime,
|
||||
// Slug = p.Slug,
|
||||
// Title = p.Title,
|
||||
// Type = p.Type,
|
||||
// UpdateTime = p.UpdateTime,
|
||||
// UserId = p.UserId,
|
||||
// }).SingleOrDefault();
|
||||
// if (content != null)
|
||||
// {
|
||||
// var Localization = _dbContext.LocalizedProperties.Where(p => p.EntityId == content.Id).ToList();
|
||||
|
||||
// content.Localized = Localization;
|
||||
|
||||
// cacheData = content;
|
||||
|
||||
// await SetCacheAsync($"{CacheKeys.ContentPrefix}{slug}", cacheData);
|
||||
// }
|
||||
// }
|
||||
// return cacheData;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
189
Atomx.Data/CacheServices/CurrencyCacheService.cs
Normal file
189
Atomx.Data/CacheServices/CurrencyCacheService.cs
Normal file
@@ -0,0 +1,189 @@
|
||||
using Atomx.Common.Constant;
|
||||
using Atomx.Common.Entities;
|
||||
|
||||
namespace Atomx.Data.CacheServices
|
||||
{
|
||||
//public partial interface ICacheService
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// 获取可付款的货币类型和支付通道信息
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<CurrencyChannelModel> GetCurrencyChannel(bool? reload = false);
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取支持充值的货币信息
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// Task<List<Currency>> GetDepositCurrencies();
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取所有可用的货币信息
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<Currency>?> GetCurrencies(bool? reload = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过ID获取或更新缓存
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<Currency> GetCurrenciesById(long id, Currency? data = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 根据代码获取货币信息
|
||||
// /// </summary>
|
||||
// /// <param name="code"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<Currency> GetCurrency(string code);
|
||||
|
||||
// /// <summary>
|
||||
// /// 从缓存中删除数据
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <returns></returns>
|
||||
// Task RemoveCurrencies(long id);
|
||||
|
||||
//}
|
||||
//public partial class CacheService : ICacheService
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// 获取可付款的货币类型和支付通道信息
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<CurrencyChannelModel> GetCurrencyChannel(bool? reload = false)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<CurrencyChannelModel>(CacheKeys.CurrencyChannel);
|
||||
// bool needReload = reload.HasValue ? reload.Value : false;
|
||||
// if (cacheData == null || needReload)
|
||||
// {
|
||||
// cacheData = new CurrencyChannelModel();
|
||||
|
||||
// var relation = _dbContext.CurrencyChannelRelations.ToList();
|
||||
// var currency = _dbContext.Currencies.Where(p => p.EnablePay).ToList();
|
||||
// var channels = _dbContext.PaymentChannels.Where(p => p.Status == (int)PaymentChannelStatus.Enable).ToList();
|
||||
|
||||
// cacheData.Currencies = currency;
|
||||
// foreach (var item in relation)
|
||||
// {
|
||||
// var channel = channels.SingleOrDefault(p => p.Id == item.PayChannelId);
|
||||
// if (channel != null)
|
||||
// {
|
||||
// var data = new CurrencyPaymentChannelModel()
|
||||
// {
|
||||
// Id = channel.Id,
|
||||
// Config = channel.Config,
|
||||
// CreateTime = channel.CreateTime,
|
||||
// Description = channel.Description,
|
||||
// DisplayOrder = channel.DisplayOrder,
|
||||
// EndTime = item.EndTime,
|
||||
// Extended = item.Extended,
|
||||
// Name = channel.Name,
|
||||
// Network = channel.Network,
|
||||
// StartTime = item.StartTime,
|
||||
// Status = channel.Status,
|
||||
// TimeZone = item.TimeZone,
|
||||
// Type = channel.Type,
|
||||
// UpdateTime = channel.UpdateTime,
|
||||
// CurrencyId = item.CurrencyId,
|
||||
// Account = channel.Account,
|
||||
// Title = channel.Title,
|
||||
// };
|
||||
// cacheData.CurrencyPaymentChannels.Add(data);
|
||||
|
||||
// }
|
||||
// }
|
||||
// await SetCacheAsync(CacheKeys.CurrencyChannel, cacheData);
|
||||
// }
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取支持充值的货币信息
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// public async Task<List<Currency>> GetDepositCurrencies()
|
||||
// {
|
||||
// var data = await GetCurrencies();
|
||||
// return data.Where(p => p.EnablePay).ToList();
|
||||
// }
|
||||
|
||||
// public async Task<List<Currency>?> GetCurrencies(bool? reload = null)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<Currency>>(CacheKeys.Currencies);
|
||||
// if (cacheData == null || reload.HasValue)
|
||||
// {
|
||||
// var data = _dbContext.Currencies.Where(p => p.Enabled).ToList();
|
||||
// if (data != null)
|
||||
// {
|
||||
// cacheData = data;
|
||||
// await SetCacheAsync(CacheKeys.Currencies, cacheData);
|
||||
// }
|
||||
// }
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// public async Task<Currency> GetCurrenciesById(long id, Currency? data = null)
|
||||
// {
|
||||
// var cacheData = await GetCurrencies();
|
||||
// if (data != null)
|
||||
// {
|
||||
// var manufacturer = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (manufacturer != null)
|
||||
// {
|
||||
// cacheData.Remove(manufacturer);
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync(CacheKeys.Currencies, cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync(CacheKeys.Currencies, cacheData);
|
||||
// }
|
||||
// return data;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var manufacturer = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (manufacturer != null)
|
||||
// {
|
||||
// return manufacturer;
|
||||
// }
|
||||
// return new Currency();
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 根据代码获取货币信息
|
||||
// /// </summary>
|
||||
// /// <param name="code"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<Currency> GetCurrency(string code)
|
||||
// {
|
||||
// var cacheData = await GetCurrencies();
|
||||
// if (cacheData != null)
|
||||
// {
|
||||
// return cacheData.SingleOrDefault(p => p.CurrencyCode == code);
|
||||
// }
|
||||
// return new Currency();
|
||||
// }
|
||||
|
||||
// public async Task RemoveCurrencies(long id)
|
||||
// {
|
||||
// var cacheData = await GetCurrencies();
|
||||
// if (cacheData != null)
|
||||
// {
|
||||
// var data = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (data != null)
|
||||
// {
|
||||
// cacheData.Remove(data);
|
||||
// await SetCacheAsync(CacheKeys.Currencies, cacheData);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
103
Atomx.Data/CacheServices/LanguageCacheService.cs
Normal file
103
Atomx.Data/CacheServices/LanguageCacheService.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using Atomx.Common.Constant;
|
||||
using Atomx.Common.Entities;
|
||||
|
||||
namespace Atomx.Data.CacheServices
|
||||
{
|
||||
public partial interface ICacheService
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取语言信息
|
||||
/// </summary>
|
||||
/// <param name="reload"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<Language>> GetLanguages(bool? reload = null);
|
||||
|
||||
/// <summary>
|
||||
/// 通过ID获取或更新缓存
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
Task<Language> GetLanguageById(long id, Language? data = null);
|
||||
|
||||
/// <summary>
|
||||
/// 通过代码获取语言
|
||||
/// </summary>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns></returns>
|
||||
Task<Language> GetLanguageByCulture(string culture);
|
||||
}
|
||||
|
||||
|
||||
public partial class CacheService : ICacheService
|
||||
{
|
||||
public async Task<List<Language>> GetLanguages(bool? reload = null)
|
||||
{
|
||||
var cacheData = await GetCacheAsync<List<Language>>(CacheKeys.Languages);
|
||||
if (cacheData == null || reload.HasValue)
|
||||
{
|
||||
var data = _dbContext.Languages.Where(p => p.Enabled).ToList();
|
||||
if (data != null)
|
||||
{
|
||||
cacheData = data;
|
||||
await SetCacheAsync(CacheKeys.Languages, cacheData);
|
||||
}
|
||||
}
|
||||
|
||||
return cacheData;
|
||||
}
|
||||
|
||||
public async Task<Language> GetLanguageById(long id, Language? data = null)
|
||||
{
|
||||
var cacheData = await GetLanguages();
|
||||
if (data != null)
|
||||
{
|
||||
var language = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
if (language != null)
|
||||
{
|
||||
cacheData.Remove(language);
|
||||
cacheData.Add(data);
|
||||
await SetCacheAsync(CacheKeys.Languages, cacheData);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheData.Add(data);
|
||||
await SetCacheAsync(CacheKeys.Languages, cacheData);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
else
|
||||
{
|
||||
var language = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
if (language != null)
|
||||
{
|
||||
return language;
|
||||
}
|
||||
return new Language();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过代码获取语言
|
||||
/// </summary>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Language> GetLanguageByCulture(string culture)
|
||||
{
|
||||
var cacheData = await GetLanguages();
|
||||
|
||||
var language = cacheData.SingleOrDefault(p => p.Culture == culture);
|
||||
if (language == null)
|
||||
{
|
||||
language = _dbContext.Languages.SingleOrDefault(p => p.Culture == culture);
|
||||
if (language != null)
|
||||
{
|
||||
cacheData.Add(language);
|
||||
await SetCacheAsync(CacheKeys.Languages, cacheData);
|
||||
}
|
||||
}
|
||||
return language;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
183
Atomx.Data/CacheServices/LocaleResourceCacheService.cs
Normal file
183
Atomx.Data/CacheServices/LocaleResourceCacheService.cs
Normal file
@@ -0,0 +1,183 @@
|
||||
using Atomx.Common.Constant;
|
||||
using Atomx.Common.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Atomx.Data.CacheServices
|
||||
{
|
||||
public partial interface ICacheService
|
||||
{
|
||||
/// <summary>
|
||||
/// 通过文化名城获取对应的本地化译文
|
||||
/// </summary>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns></returns>
|
||||
Task<Dictionary<string, string>> GetLocaleResourcesAsync(string culture);
|
||||
|
||||
/// <summary>
|
||||
/// 添加或更新文化本地化信息
|
||||
/// </summary>
|
||||
/// <param name="localeResource"></param>
|
||||
/// <returns></returns>
|
||||
Task SetLocaleResources(LocaleResource localeResource);
|
||||
|
||||
/// <summary>
|
||||
/// 删除文化本地化资源信息
|
||||
/// </summary>
|
||||
/// <param name="localeResource"></param>
|
||||
/// <returns></returns>
|
||||
Task DeleteLocaleResources(LocaleResource localeResource);
|
||||
|
||||
/// <summary>
|
||||
/// 重载本地化资源
|
||||
/// </summary>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns></returns>
|
||||
Task ReloadLocaleResources(string culture);
|
||||
|
||||
/// <summary>
|
||||
/// 移除文化本地化资源缓存
|
||||
/// </summary>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns></returns>
|
||||
Task RemoveLocaleResources(string culture);
|
||||
|
||||
/// <summary>
|
||||
/// 指定文化本地化资源获和名城获取译文
|
||||
/// </summary>
|
||||
/// <param name="culture"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> GetLocaleResourcesString(string culture, string name);
|
||||
}
|
||||
public partial class CacheService : ICacheService
|
||||
{
|
||||
/// <summary>
|
||||
/// 通过文化名城获取对应的本地化译文,如果缓存不存在则从数据库加载
|
||||
/// </summary>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Dictionary<string, string>> GetLocaleResourcesAsync(string culture)
|
||||
{
|
||||
var key = $"{CacheKeys.LocaleResourcePrefix}{culture}";
|
||||
var cacheData = GetCache<Dictionary<string, string>>(key);
|
||||
if (cacheData == null)
|
||||
{
|
||||
var language = await GetLanguageByCulture(culture);
|
||||
if (language == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var data = await _dbContext.LocaleResources.Where(p => p.LanguageId == language.Id).ToDictionaryAsync(p => p.Name, p => p.Value);
|
||||
if (data.Any())
|
||||
{
|
||||
cacheData = data;
|
||||
SetCache(key, cacheData);
|
||||
}
|
||||
}
|
||||
return cacheData;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加或更新文化本地化信息
|
||||
/// </summary>
|
||||
/// <param name="localeResource"></param>
|
||||
/// <returns></returns>
|
||||
public async Task SetLocaleResources(LocaleResource localeResource)
|
||||
{
|
||||
var language = await GetLanguageById(localeResource.LanguageId);
|
||||
if (language == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var key = $"{CacheKeys.LocaleResourcePrefix}{language.Culture}";
|
||||
var data = await GetLocaleResourcesAsync(language.Culture);
|
||||
if (data.ContainsKey(localeResource.Name))
|
||||
{
|
||||
data[localeResource.Name] = localeResource.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
data.Add(localeResource.Name, localeResource.Value);
|
||||
}
|
||||
SetCache(key, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除文化本地化资源信息
|
||||
/// </summary>
|
||||
/// <param name="localeResource"></param>
|
||||
/// <returns></returns>
|
||||
public async Task DeleteLocaleResources(LocaleResource localeResource)
|
||||
{
|
||||
var language = await GetLanguageById(localeResource.LanguageId);
|
||||
if (language == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var key = $"{CacheKeys.LocaleResourcePrefix}{language.Culture}";
|
||||
var data = await GetLocaleResourcesAsync(language.Culture);
|
||||
data.Remove(localeResource.Name);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重载本地化资源
|
||||
/// </summary>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns></returns>
|
||||
public async Task ReloadLocaleResources(string culture)
|
||||
{
|
||||
var key = $"{CacheKeys.LocaleResourcePrefix}{culture}";
|
||||
var cacheData = await GetCacheAsync<Dictionary<string, string>>(key);
|
||||
var language = await GetLanguageByCulture(culture);
|
||||
if (language == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var data = await _dbContext.LocaleResources.Where(p => p.LanguageId == language.Id).ToDictionaryAsync(p => p.Name, p => p.Value);
|
||||
|
||||
if (data.Any())
|
||||
{
|
||||
cacheData = data;
|
||||
await SetCacheAsync(key, cacheData);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除文化本地化资源缓存
|
||||
/// </summary>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns></returns>
|
||||
public async Task RemoveLocaleResources(string culture)
|
||||
{
|
||||
var key = $"{CacheKeys.LocaleResourcePrefix}{culture}";
|
||||
await Remove(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 指定文化本地化资源获和名城获取译文
|
||||
/// </summary>
|
||||
/// <param name="culture"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> GetLocaleResourcesString(string culture, string name)
|
||||
{
|
||||
var key = $"{CacheKeys.LocaleResourcePrefix}{culture}";
|
||||
var cacheData = await GetCacheAsync<Dictionary<string, string>>(key);
|
||||
if (cacheData == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
if (cacheData.TryGetValue(name, out string value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
30
Atomx.Data/CacheServices/LocalizationCacheService.cs
Normal file
30
Atomx.Data/CacheServices/LocalizationCacheService.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
//namespace Atomx.Data.CacheServices
|
||||
//{
|
||||
// public partial interface ICacheService
|
||||
// {
|
||||
// Task SetLocalization(string id, LocalizationModel model);
|
||||
|
||||
// LocalizationModel GetLocalization(string id);
|
||||
// }
|
||||
|
||||
// public partial class CacheService : ICacheService
|
||||
// {
|
||||
// public async Task SetLocalization(string id, LocalizationModel model)
|
||||
// {
|
||||
// var key = $"{CacheKeys.LocalizationPrefix}{id}";
|
||||
// await SetCacheAsync(key, model);
|
||||
// }
|
||||
|
||||
// public LocalizationModel GetLocalization(string id)
|
||||
// {
|
||||
// var key = $"{CacheKeys.LocalizationPrefix}{id}";
|
||||
// var cacheData = GetCache<LocalizationModel>(key);
|
||||
// if (cacheData == null)
|
||||
// {
|
||||
// return new LocalizationModel();
|
||||
// }
|
||||
// return cacheData;
|
||||
// }
|
||||
// }
|
||||
|
||||
//}
|
||||
69
Atomx.Data/CacheServices/LocalizedPropertyCacheService.cs
Normal file
69
Atomx.Data/CacheServices/LocalizedPropertyCacheService.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
//using Atomx.Common.Entities;
|
||||
|
||||
//namespace Atomx.Data.CacheServices
|
||||
//{
|
||||
// public partial interface ICacheService
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 通过数据对象实体ID和语言,获取或更新本地化数据
|
||||
// /// </summary>
|
||||
// /// <param name="entityId"></param>
|
||||
// /// <param name="language"></param>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<LocalizedProperty>> GetLocalizedProperty(long entityId, int language, List<LocalizedProperty>? data = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过数据对象实体ID获取本地化数据
|
||||
// /// </summary>
|
||||
// /// <param name="entityId"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<LocalizedProperty>> GetLocalizedPropertyList(long entityId);
|
||||
// }
|
||||
// public partial class CacheService : ICacheService
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 通过数据对象实体ID和语言,获取或更新本地化数据
|
||||
// /// </summary>
|
||||
// /// <param name="entityId"></param>
|
||||
// /// <param name="language"></param>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<List<LocalizedProperty>> GetLocalizedProperty(long entityId, int language, List<LocalizedProperty>? data = null)
|
||||
// {
|
||||
// var cacheData = await GetLocalizedPropertyList(entityId);
|
||||
// if (data != null)
|
||||
// {
|
||||
// var list = cacheData.Where(p => p.LanguageId == language).ToList();
|
||||
// if (list.Any())
|
||||
// {
|
||||
// cacheData.RemoveAll(p => p.LanguageId == language);
|
||||
// }
|
||||
// cacheData.AddRange(data);
|
||||
// await SetCacheAsync($"{CacheKeys.LocalizedPropertyPrefix}{entityId}", cacheData);
|
||||
// return data;
|
||||
// }
|
||||
// return cacheData.Where(p => p.LanguageId == language).ToList();
|
||||
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过数据对象实体ID获取本地化数据
|
||||
// /// </summary>
|
||||
// /// <param name="entityId"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<List<LocalizedProperty>> GetLocalizedPropertyList(long entityId)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<LocalizedProperty>>($"{CacheKeys.LocalizedPropertyPrefix}{entityId}");
|
||||
// if(cacheData == null)
|
||||
// {
|
||||
// cacheData = _dbContext.LocalizedProperties.Where(p=>p.EntityId == entityId).ToList();
|
||||
// if(cacheData == null)
|
||||
// {
|
||||
// await SetCacheAsync($"{CacheKeys.LocalizedPropertyPrefix}{entityId}", cacheData);
|
||||
// }
|
||||
// }
|
||||
// return cacheData;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
107
Atomx.Data/CacheServices/ManufacturerCacheService.cs
Normal file
107
Atomx.Data/CacheServices/ManufacturerCacheService.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
//using Atomx.Common.Entities;
|
||||
|
||||
//namespace Atomx.Data.CacheServices
|
||||
//{
|
||||
// public partial interface ICacheService
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 获取所有可用的制造商品牌信息
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// Task<List<Manufacturer>> GetManufacturers();
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过ID获取或更新缓存
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<Manufacturer> GetManufacturerById(long id, Manufacturer? data = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过名字查询
|
||||
// /// </summary>
|
||||
// /// <param name="name"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<Manufacturer> GetManufacturerByName(string name);
|
||||
|
||||
// /// <summary>
|
||||
// /// 从缓存中删除数据
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <returns></returns>
|
||||
// Task RemoveManufacturer(long id);
|
||||
|
||||
// }
|
||||
// public partial class CacheService : ICacheService
|
||||
// {
|
||||
// public async Task<Manufacturer> GetManufacturerById(long id, Manufacturer? data = null)
|
||||
// {
|
||||
// var cacheData = await GetManufacturers();
|
||||
// if (data != null)
|
||||
// {
|
||||
// var manufacturer = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (manufacturer != null)
|
||||
// {
|
||||
// cacheData.Remove(manufacturer);
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync(CacheKeys.Manufacturers, cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync(CacheKeys.Manufacturers, cacheData);
|
||||
// }
|
||||
// return data;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var manufacturer = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (manufacturer != null)
|
||||
// {
|
||||
// return manufacturer;
|
||||
// }
|
||||
// return new Manufacturer();
|
||||
// }
|
||||
// }
|
||||
|
||||
// public async Task<Manufacturer> GetManufacturerByName(string name)
|
||||
// {
|
||||
// var cacheData = await GetManufacturers();
|
||||
// if (cacheData != null)
|
||||
// {
|
||||
// var data = cacheData.SingleOrDefault(p => p.Name == name);
|
||||
// if (data != null)
|
||||
// {
|
||||
// return data;
|
||||
// }
|
||||
// }
|
||||
// return new Manufacturer();
|
||||
// }
|
||||
|
||||
// public async Task<List<Manufacturer>> GetManufacturers()
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<Manufacturer>>(CacheKeys.Manufacturers);
|
||||
// if (cacheData == null)
|
||||
// {
|
||||
// return new List<Manufacturer>();
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// public async Task RemoveManufacturer(long id)
|
||||
// {
|
||||
// var cacheData = await GetManufacturers();
|
||||
// if (cacheData != null)
|
||||
// {
|
||||
// var data = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (data != null)
|
||||
// {
|
||||
// cacheData.Remove(data);
|
||||
// await SetCacheAsync(CacheKeys.Manufacturers, cacheData);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
89
Atomx.Data/CacheServices/PaymentChannelsCacheService.cs
Normal file
89
Atomx.Data/CacheServices/PaymentChannelsCacheService.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
//namespace Atomx.Data.CacheServices
|
||||
//{
|
||||
// public partial interface ICacheService
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 获取所有可用的支付通道
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// Task<List<PaymentChannel>> GetPaymentChannels(List<PaymentChannel>? languages = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过ID获取或更新缓存
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<PaymentChannel> GetPaymentChannelById(long id, PaymentChannel? data = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过ID 删除
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task RemovePaymentChannelById(long id);
|
||||
// }
|
||||
// public partial class CacheService : ICacheService
|
||||
// {
|
||||
// public async Task<PaymentChannel> GetPaymentChannelById(long id, PaymentChannel? data = null)
|
||||
// {
|
||||
// var cacheData = await GetPaymentChannels();
|
||||
// if (data != null)
|
||||
// {
|
||||
// var language = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (language != null)
|
||||
// {
|
||||
// cacheData.Remove(language);
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync(CacheKeys.PaymentChannels, cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync(CacheKeys.PaymentChannels, cacheData);
|
||||
// }
|
||||
// return data;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var manufacturer = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (manufacturer != null)
|
||||
// {
|
||||
// return manufacturer;
|
||||
// }
|
||||
// return new PaymentChannel();
|
||||
// }
|
||||
// }
|
||||
|
||||
// public async Task<List<PaymentChannel>> GetPaymentChannels(List<PaymentChannel>? languages = null)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<PaymentChannel>>(CacheKeys.PaymentChannels);
|
||||
// if (languages != null)
|
||||
// {
|
||||
// cacheData = languages;
|
||||
// await SetCacheAsync(CacheKeys.PaymentChannels, cacheData);
|
||||
// }
|
||||
// if (cacheData == null)
|
||||
// {
|
||||
// return new List<PaymentChannel>();
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// public async Task RemovePaymentChannelById(long id)
|
||||
// {
|
||||
// var cacheData = await GetPaymentChannels();
|
||||
// if (cacheData != null)
|
||||
// {
|
||||
// var data = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (data != null)
|
||||
// {
|
||||
// cacheData.Remove(data);
|
||||
// await SetCacheAsync(CacheKeys.PaymentChannels, cacheData);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
16
Atomx.Data/CacheServices/ProductAttributeCacheService.cs
Normal file
16
Atomx.Data/CacheServices/ProductAttributeCacheService.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Atomx.Data.CacheServices
|
||||
{
|
||||
public partial interface ICacheService
|
||||
{
|
||||
|
||||
}
|
||||
public partial class CacheService : ICacheService
|
||||
{
|
||||
}
|
||||
}
|
||||
401
Atomx.Data/CacheServices/ProductCacheService.cs
Normal file
401
Atomx.Data/CacheServices/ProductCacheService.cs
Normal file
@@ -0,0 +1,401 @@
|
||||
//using Atomx.Common.Entities;
|
||||
//using Microsoft.EntityFrameworkCore;
|
||||
|
||||
//namespace Atomx.Data.CacheServices
|
||||
//{
|
||||
|
||||
// public partial interface ICacheService
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 获取每日热销产品数据
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<Product>> GetDailyBestSells(bool? reload = false);
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取产品详情
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<ProductDetailCachedModel?> GetProductDetails(long id, bool reload = false);
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取营销产品
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<MarketingProductModel> GetMarketingProducts(long id, MarketingProductModel? data = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 删除活动产品
|
||||
// /// </summary>
|
||||
// /// <param name="productId"></param>
|
||||
// /// <returns></returns>
|
||||
// Task RemoveMarketingProductByProductId(long marketingId, long productId);
|
||||
|
||||
// /// <summary>
|
||||
// /// 删除指定营销活动产品缓存
|
||||
// /// </summary>
|
||||
// /// <param name="marketingId"></param>
|
||||
// /// <returns></returns>
|
||||
// Task RemoveMarketingProductByMarketingId(long marketingId);
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取营销产品
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// Task<List<MarketingProductModel>> GetMarketingProducts();
|
||||
|
||||
// /// <summary>
|
||||
// /// 删除产品缓存
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <returns></returns>
|
||||
// Task RemoveProduct(long id);
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取最新产品
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// Task<List<Product>> GetNewProducts(bool? reload = false);
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取分类下的最新产品
|
||||
// /// </summary>
|
||||
// /// <param name="categoryId"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<Product>> GetNewProductsByCategory(List<long> categoryIds, bool? reload = false);
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取热销产品
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// Task<List<Product>> GetHotProducts(bool? reload = false);
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取分类下热销产品
|
||||
// /// </summary>
|
||||
// /// <param name="categoryId"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<Product>> GetHotProductsByCategory(List<long> categoryIds, bool? reload = false);
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取首页推荐得精选产品
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<Product>> GetIndexFeatured(bool? reload = false);
|
||||
// }
|
||||
|
||||
// public partial class CacheService : ICacheService
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 获取每日热销产品数据
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<List<Product>> GetDailyBestSells(bool? reload = false)
|
||||
// {
|
||||
// var key = $"{CacheKeys.DailyBestSellProductPrefix}{DateTime.UtcNow.Day}";
|
||||
// var cacheData = await GetCacheAsync<List<Product>>(key);
|
||||
// var needReload = reload.HasValue ? reload.Value : false;
|
||||
// if (cacheData == null || needReload)
|
||||
// {
|
||||
// var query = from p in _dbContext.Products
|
||||
// where p.Status == (int)ProductStatus.Publish && p.StoreId == 0
|
||||
// select p;
|
||||
// cacheData = query.OrderByDescending(p => EF.Functions.Random()).Take(100).ToList();
|
||||
// await SetCacheAsync(key, cacheData);
|
||||
// }
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// public async Task<ProductDetailCachedModel?> GetProductDetails(long id, bool reload = false)
|
||||
// {
|
||||
// if (id == 0)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// var productData = await GetCacheAsync<ProductDetailCachedModel>($"{CacheKeys.ProductPrefix}{id}");
|
||||
|
||||
// if (productData == null || reload)
|
||||
// {
|
||||
// productData = (from p in _dbContext.Products
|
||||
// where p.Id == id && p.Status == (int)ProductStatus.Publish
|
||||
// select new ProductDetailCachedModel
|
||||
// {
|
||||
// AllowExchange = p.AllowExchange,
|
||||
// AllowReturn = p.AllowReturn,
|
||||
// AvailableEndTime = p.AvailableEndTime,
|
||||
// AvailableStartTime = p.AvailableStartTime,
|
||||
// Body = p.Body,
|
||||
// CategoryId = p.CategoryId,
|
||||
// CategoryPath = p.CategoryPath,
|
||||
// CreateTime = p.CreateTime,
|
||||
// Deleted = p.Deleted,
|
||||
// Description = p.Description,
|
||||
// DisableCoupons = p.DisableCoupons,
|
||||
// DisplayOrder = p.DisplayOrder,
|
||||
// Feature = p.Feature,
|
||||
// IsFeatured = p.IsFeatured,
|
||||
// Id = p.Id,
|
||||
// Image = p.Image,
|
||||
// InHouse = p.InHouse,
|
||||
// IsWarehouse = p.IsWarehouse,
|
||||
// Localized = new(),
|
||||
// ManufacturerId = p.ManufacturerId,
|
||||
// MarketPrice = p.MarketPrice,
|
||||
// MetaDescription = p.MetaDescription,
|
||||
// MetaTitle = p.MetaTitle,
|
||||
// Photos = p.Photos,
|
||||
// PictureCount = p.PictureCount,
|
||||
// Price = p.Price,
|
||||
// ProductTypeId = p.ProductTypeId,
|
||||
// Remarks = p.Remarks,
|
||||
// ReviewStatus = p.ReviewStatus,
|
||||
// SaleAttribute = new(),
|
||||
// SalesQuantity = p.SalesQuantity,
|
||||
// ShippingId = p.ShippingId,
|
||||
// SingleShip = p.SingleShip,
|
||||
// Sku = p.Sku,
|
||||
// SKUCombinations = new(),
|
||||
// SkuPrices = p.SkuPrices,
|
||||
// Slug = p.Slug,
|
||||
// Specification = p.Specification,
|
||||
// Status = p.Status,
|
||||
// StockQuantity = p.StockQuantity,
|
||||
// StopSales = p.StopSales,
|
||||
// StoreId = p.StoreId,
|
||||
// Tags = p.Tags,
|
||||
// Title = p.Title,
|
||||
// UpdateTime = p.UpdateTime,
|
||||
// UserId = p.UserId,
|
||||
// VendorId = p.VendorId,
|
||||
// ViewsCount = p.ViewsCount,
|
||||
// WarehouseId = p.WarehouseId,
|
||||
// Weight = p.Weight,
|
||||
// FiveStars = p.FiveStars,
|
||||
// FourStars = p.FourStars,
|
||||
// IsBest = p.IsBest,
|
||||
// IsNew = p.IsNew,
|
||||
// OneStars = p.OneStars,
|
||||
// OrderMaximumQuantity = p.OrderMaximumQuantity,
|
||||
// OrderMinimumQuantity = p.OrderMinimumQuantity,
|
||||
// Ratings = p.Ratings,
|
||||
// ReviewsCount = p.ReviewsCount,
|
||||
// ShippingDays = p.ShippingDays,
|
||||
// ThreeStars = p.ThreeStars,
|
||||
// TwoStars = p.TwoStars
|
||||
// }).SingleOrDefault();
|
||||
|
||||
// if (productData == null)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// var productSaleAttributes = (from p in _dbContext.ProductAttributeRelations
|
||||
// join sa in _dbContext.ProductAttributes on p.AttributeId equals sa.Id into table
|
||||
// from a in table.DefaultIfEmpty()
|
||||
// where p.ProductId == id && a.IsSpecification == false
|
||||
// orderby p.DisplayOrder descending
|
||||
// select new ProductSKUAttributeModel
|
||||
// {
|
||||
// AttributeId = p.AttributeId,
|
||||
// AttributeName = a.Name,
|
||||
// Items = new(),
|
||||
// ProductAttributeId = p.Id
|
||||
// }).ToList();
|
||||
// if (productSaleAttributes.Any())
|
||||
// {
|
||||
// var productAttributeIds = productSaleAttributes.Select(p => p.ProductAttributeId).ToList();
|
||||
// var attributeValues = (from p in _dbContext.ProductAttributeValues
|
||||
// where productAttributeIds.Contains(p.ProductAttributeRelationId)
|
||||
// orderby p.DisplayOrder descending
|
||||
// select new ProductSKUAttributeValueModel
|
||||
// {
|
||||
// Id = p.OptionId,
|
||||
// Name = p.Name,
|
||||
// ProductAttributeId = p.ProductAttributeRelationId
|
||||
// }
|
||||
// ).ToList();
|
||||
// foreach (var item in productSaleAttributes)
|
||||
// {
|
||||
// var values = attributeValues.Where(p => p.ProductAttributeId == item.ProductAttributeId).ToList();
|
||||
// item.Items = values;
|
||||
// }
|
||||
|
||||
// productData.SaleAttribute = productSaleAttributes;
|
||||
// var skuCombinations = _dbContext.ProductSKUCombinations.Where(p => p.ProductId == id).ToList();
|
||||
// productData.SKUCombinations = skuCombinations;
|
||||
// }
|
||||
// await SetCacheAsync($"{CacheKeys.ProductPrefix}{id}", productData);
|
||||
// }
|
||||
|
||||
// return productData;
|
||||
// }
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取营销产品
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<MarketingProductModel> GetMarketingProducts(long id, MarketingProductModel? data = null)
|
||||
// {
|
||||
// var cacheData = await GetMarketingProducts();
|
||||
// if (data != null)
|
||||
// {
|
||||
// cacheData.RemoveAll(p => p.Id == id);
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync(CacheKeys.MarketingProduct, cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// data = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// }
|
||||
// return data;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 删除活动产品
|
||||
// /// </summary>
|
||||
// /// <param name="productId"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task RemoveMarketingProductByProductId(long marketingId, long productId)
|
||||
// {
|
||||
// var cacheData = await GetMarketingProducts();
|
||||
// cacheData.RemoveAll(p => p.ProductId == productId && p.MarketingId == marketingId);
|
||||
|
||||
// await SetCacheAsync(CacheKeys.MarketingProduct, cacheData);
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 删除指定营销活动产品缓存
|
||||
// /// </summary>
|
||||
// /// <param name="marketingId"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task RemoveMarketingProductByMarketingId(long marketingId)
|
||||
// {
|
||||
// var cacheData = await GetMarketingProducts();
|
||||
// cacheData.RemoveAll(p => p.MarketingId == marketingId);
|
||||
|
||||
// await SetCacheAsync(CacheKeys.MarketingProduct, cacheData);
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取营销产品
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// public async Task<List<MarketingProductModel>> GetMarketingProducts()
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<MarketingProductModel>>(CacheKeys.MarketingProduct);
|
||||
// if (cacheData == null)
|
||||
// {
|
||||
// return new List<MarketingProductModel>();
|
||||
// }
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// public async Task RemoveProduct(long id)
|
||||
// {
|
||||
// var productData = await GetCacheAsync<ProductDetailCachedModel>($"{CacheKeys.ProductPrefix}{id}");
|
||||
// if (productData == null)
|
||||
// {
|
||||
// await Remove($"{CacheKeys.ProductPrefix}{id}");
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取最新产品
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// public async Task<List<Product>> GetNewProducts(bool? reload = false)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<Product>>(CacheKeys.ProductNewList);
|
||||
// if (cacheData == null || reload.HasValue)
|
||||
// {
|
||||
// var data = _dbContext.Products.OrderByDescending(p => p.CreateTime).Take(100).ToList();
|
||||
// cacheData = data;
|
||||
// await SetCacheAsync(CacheKeys.MarketingProduct, cacheData, 24);
|
||||
// }
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取分类下的最新产品
|
||||
// /// </summary>
|
||||
// /// <param name="categoryId"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<List<Product>> GetNewProductsByCategory(List<long> categoryIds, bool? reload = false)
|
||||
// {
|
||||
// var key = string.Join(",", categoryIds.ToArray()).ToMD5();
|
||||
// var cacheData = await GetCacheAsync<List<Product>>($"{CacheKeys.ProductNewListPrefix}.{key}");
|
||||
// if (cacheData == null || reload.HasValue)
|
||||
// {
|
||||
// var data = _dbContext.Products.Where(p => categoryIds.Contains(p.CategoryId)).OrderByDescending(p => p.CreateTime).Take(100).ToList();
|
||||
// cacheData = data;
|
||||
// await SetCacheAsync($"{CacheKeys.ProductNewListPrefix}.{key}", cacheData, 24);
|
||||
// }
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取热销产品
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// public async Task<List<Product>> GetHotProducts(bool? reload = false)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<Product>>(CacheKeys.ProductHotList);
|
||||
// if (cacheData == null || reload.HasValue)
|
||||
// {
|
||||
// var data = _dbContext.Products.OrderByDescending(p => p.SalesQuantity).Take(100).ToList();
|
||||
// cacheData = data;
|
||||
// await SetCacheAsync(CacheKeys.ProductHotList, cacheData, 24);
|
||||
// }
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取分类下热销产品
|
||||
// /// </summary>
|
||||
// /// <param name="categoryId"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<List<Product>> GetHotProductsByCategory(List<long> categoryIds, bool? reload = false)
|
||||
// {
|
||||
// var key = string.Join(",", categoryIds.ToArray()).ToMD5();
|
||||
// var cacheData = await GetCacheAsync<List<Product>>($"{CacheKeys.ProductHotListPrefix}.{key}");
|
||||
// if (cacheData == null || reload.HasValue)
|
||||
// {
|
||||
// var data = _dbContext.Products.Where(p => categoryIds.Contains(p.CategoryId)).OrderByDescending(p => p.SalesQuantity).Take(100).ToList();
|
||||
// cacheData = data;
|
||||
// await SetCacheAsync($"{CacheKeys.ProductNewListPrefix}.{key}", cacheData, 24);
|
||||
// }
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取首页推荐得精选产品
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<List<Product>> GetIndexFeatured(bool? reload = false)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<Product>>(CacheKeys.ProductFeaturedList);
|
||||
// if (cacheData == null || reload.HasValue)
|
||||
// {
|
||||
// var data = _dbContext.Products.Where(p => p.IsFeatured).OrderByDescending(p => p.UpdateTime).Take(20).ToList();
|
||||
// cacheData = data;
|
||||
// await SetCacheAsync(CacheKeys.ProductFeaturedList, cacheData, 24);
|
||||
// }
|
||||
// return cacheData;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
110
Atomx.Data/CacheServices/RoleCacheService.cs
Normal file
110
Atomx.Data/CacheServices/RoleCacheService.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using Atomx.Common.Constant;
|
||||
using Atomx.Common.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Atomx.Data.CacheServices
|
||||
{
|
||||
public partial interface ICacheService
|
||||
{
|
||||
/// <summary>
|
||||
/// 重新加载角色
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task ReloadRoleAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存
|
||||
/// </summary>
|
||||
/// <param name="reload"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<Role>> GetRolesAsync(bool? reload = false);
|
||||
|
||||
/// <summary>
|
||||
/// 通过ID获取角色
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <param name="reload"></param>
|
||||
/// <returns></returns>
|
||||
Task<Role?> GetRoleById(long roleId, bool? reload = false);
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有的权限点
|
||||
/// </summary>
|
||||
/// <param name="reload"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<Permission>> GetAllPermissions(bool? reload = false);
|
||||
}
|
||||
|
||||
|
||||
public partial class CacheService : ICacheService
|
||||
{
|
||||
/// <summary>
|
||||
/// 重新加载角色
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task ReloadRoleAsync()
|
||||
{
|
||||
|
||||
var data = _dbContext.Roles.Where(p => p.Enabled).ToList();
|
||||
if (data.Any())
|
||||
{
|
||||
await SetCacheAsync(CacheKeys.Roles, data);
|
||||
}
|
||||
}
|
||||
|
||||
// <summary>
|
||||
/// 获取缓存
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<Role>> GetRolesAsync(bool? reload = false)
|
||||
{
|
||||
bool reloadData = reload.HasValue ? reload.Value : false;
|
||||
|
||||
var cacheData = await GetCacheAsync<List<Role>>(CacheKeys.Roles);
|
||||
if (cacheData == null || reloadData)
|
||||
{
|
||||
var roles = (from p in _dbContext.Roles
|
||||
where p.Enabled
|
||||
select p).ToList();
|
||||
await SetCacheAsync(CacheKeys.Roles, roles);
|
||||
return roles;
|
||||
|
||||
}
|
||||
return cacheData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过ID获取角色
|
||||
/// </summary>
|
||||
/// <param name="roleId"></param>
|
||||
/// <param name="reload"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Role?> GetRoleById(long roleId, bool? reload = false)
|
||||
{
|
||||
var cacheData = await GetRolesAsync(reload);
|
||||
return cacheData.Where(p => p.Id == roleId).SingleOrDefault();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有的权限点
|
||||
/// </summary>
|
||||
/// <param name="reload"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<Permission>> GetAllPermissions(bool? reload = false)
|
||||
{
|
||||
bool reloadData = reload.HasValue ? reload.Value : false;
|
||||
|
||||
var cacheData = await GetCacheAsync<List<Permission>>(CacheKeys.Permissions);
|
||||
if (cacheData == null || reloadData)
|
||||
{
|
||||
var permissions = await (from p in _dbContext.Permissions
|
||||
select p).ToListAsync();
|
||||
await SetCacheAsync(CacheKeys.Permissions, permissions);
|
||||
return permissions;
|
||||
|
||||
}
|
||||
return cacheData;
|
||||
}
|
||||
}
|
||||
}
|
||||
66
Atomx.Data/CacheServices/StoreCacheService.cs
Normal file
66
Atomx.Data/CacheServices/StoreCacheService.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
//using Atomx.Common.Entities;
|
||||
|
||||
//namespace Atomx.Data.CacheServices
|
||||
//{
|
||||
// public partial interface ICacheService
|
||||
// {
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过用户ID获取店铺信息
|
||||
// /// </summary>
|
||||
// /// <param name="uid"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<Store?> GetStore(long id);
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取店铺信息
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="store"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<Store> GetStore(long id, Store store);
|
||||
|
||||
// /// <summary>
|
||||
// /// 重载店铺信息
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <returns></returns>
|
||||
// Task ReloadStore(long id);
|
||||
// }
|
||||
// public partial class CacheService : ICacheService
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 通过用户ID获取店铺信息
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<Store?> GetStore(long id)
|
||||
// {
|
||||
// string key = $"{CacheKeys.StorePrefix}.{id}";
|
||||
// var cacheData = await GetCacheAsync<Store>(key);
|
||||
// if (cacheData == null)
|
||||
// {
|
||||
// var store = _dbContext.Stores.SingleOrDefault(p => p.Id == id);
|
||||
// cacheData = store;
|
||||
// await SetCacheAsync(key, cacheData);
|
||||
// }
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// public async Task<Store> GetStore(long id, Store store)
|
||||
// {
|
||||
// string key = $"{CacheKeys.StorePrefix}.{id}";
|
||||
// var cacheData = await GetCacheAsync<Store>(key);
|
||||
// await SetCacheAsync(key, store);
|
||||
// return store;
|
||||
// }
|
||||
|
||||
|
||||
// public async Task ReloadStore(long id)
|
||||
// {
|
||||
// var store = _dbContext.Stores.FirstOrDefault(p => p.Id == id);
|
||||
// string key = $"{CacheKeys.StorePrefix}.{id}";
|
||||
// await SetCacheAsync(key, store);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
101
Atomx.Data/CacheServices/StoreLevelCacheService.cs
Normal file
101
Atomx.Data/CacheServices/StoreLevelCacheService.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
//using Microsoft.EntityFrameworkCore;
|
||||
|
||||
//namespace Atomx.Data.CacheServices
|
||||
//{
|
||||
// public partial interface ICacheService
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 获取店铺等级列表
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<StoreLevel>> GetStoreLevels(bool? reload = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过ID获取或更新缓存
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<StoreLevel> GetStoreLevelById(long id, StoreLevel? data = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过ID获取店铺登记
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<StoreLevel> GetStoreLevel(long id, bool? reload = false);
|
||||
// }
|
||||
// public partial class CacheService : ICacheService
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 获取店铺等级列表
|
||||
// /// </summary>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<List<StoreLevel>> GetStoreLevels(bool? reload = null)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<StoreLevel>>(CacheKeys.StoreLevel);
|
||||
// if (cacheData == null || reload.HasValue)
|
||||
// {
|
||||
// var data = _dbContext.StoreLevels.Where(p => p.Enabled).ToList();
|
||||
// if (data.Any())
|
||||
// {
|
||||
// cacheData = data;
|
||||
// await SetCacheAsync(CacheKeys.StoreLevel, cacheData);
|
||||
// }
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
// public async Task<StoreLevel> GetStoreLevelById(long id, StoreLevel? data = null)
|
||||
// {
|
||||
// var cacheData = await GetStoreLevels();
|
||||
// if (cacheData == null || data != null)
|
||||
// {
|
||||
// var storeLevel = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (storeLevel != null)
|
||||
// {
|
||||
// cacheData.Remove(storeLevel);
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync(CacheKeys.StoreLevel, cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync(CacheKeys.StoreLevel, cacheData);
|
||||
// }
|
||||
// }
|
||||
// var level = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// return level;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过ID获取店铺登记
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<StoreLevel> GetStoreLevel(long id, bool? reload = false)
|
||||
// {
|
||||
// var cacheData = await GetStoreLevels();
|
||||
// var reloadData = reload.HasValue ? reload.Value : false;
|
||||
|
||||
// if (cacheData == null || reload == true)
|
||||
// {
|
||||
// var storeLevel = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (storeLevel != null)
|
||||
// {
|
||||
// cacheData.Remove(storeLevel);
|
||||
// }
|
||||
|
||||
// var level = _dbContext.StoreLevels.SingleOrDefault(p => p.Id == id);
|
||||
// cacheData.Add(level);
|
||||
// await SetCacheAsync(CacheKeys.StoreLevel, cacheData);
|
||||
// }
|
||||
// var data = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// return data;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
57
Atomx.Data/CacheServices/UserCacheService.cs
Normal file
57
Atomx.Data/CacheServices/UserCacheService.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using Atomx.Common.Constant;
|
||||
using Atomx.Common.Entities;
|
||||
|
||||
namespace Atomx.Data.CacheServices
|
||||
{
|
||||
public partial interface ICacheService
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取用户基本信息
|
||||
/// </summary>
|
||||
/// <param name="agencyId"></param>
|
||||
/// <param name="reload"></param>
|
||||
/// <returns></returns>
|
||||
Task<User?> GetUserBaseInfo(long id, bool? reload = null);
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户缓存
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
Task<User> UpdateUserBaseInfo(User user);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public partial class CacheService : ICacheService
|
||||
{
|
||||
public async Task<User?> GetUserBaseInfo(long id, bool? reload = null)
|
||||
{
|
||||
var cacheData = await GetCacheAsync<User>($"{CacheKeys.UserPrefix}{id}");
|
||||
|
||||
if (cacheData == null || reload.HasValue)
|
||||
{
|
||||
var data = _dbContext.Users.Where(p => p.Id == id).SingleOrDefault();
|
||||
if (data != null)
|
||||
{
|
||||
cacheData = data;
|
||||
await SetCacheAsync($"{CacheKeys.UserPrefix}{id}", cacheData, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
return cacheData;
|
||||
}
|
||||
|
||||
|
||||
public async Task<User> UpdateUserBaseInfo(User user)
|
||||
{
|
||||
var cacheData = await GetCacheAsync<User>($"{CacheKeys.UserPrefix}{user.Id}");
|
||||
cacheData = user;
|
||||
await SetCacheAsync($"{CacheKeys.UserPrefix}{user.Id}", cacheData, 0.5);
|
||||
return cacheData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
175
Atomx.Data/DataContext.cs
Normal file
175
Atomx.Data/DataContext.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
using Atomx.Common.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Atomx.Data
|
||||
{
|
||||
public class DataContext : DbContext
|
||||
{
|
||||
//add-migration 0.1 // add-migration 0.1 -Context DataContext
|
||||
//update-database // update-database -Context DataContext
|
||||
//Remove-Migration // Remove-Migration -Context DataContext
|
||||
|
||||
public DataContext(DbContextOptions options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
protected DataContext()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户地址信息
|
||||
/// </summary>
|
||||
public DbSet<Address> Addresses { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Admin 帐号
|
||||
/// </summary>
|
||||
public DbSet<Admin> Admins { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 应用版本记录
|
||||
/// </summary>
|
||||
public DbSet<AppVersion> AppVersions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 国家省市地区
|
||||
/// </summary>
|
||||
public DbSet<Area> Areas { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分类
|
||||
/// </summary>
|
||||
public DbSet<Category> Categories { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 货币信息
|
||||
/// </summary>
|
||||
public DbSet<Currency> Currencies { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 货币与支付通道关联表
|
||||
/// </summary>
|
||||
public DbSet<CurrencyChannelRelation> CurrencyChannelRelations { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 本地化资源数据
|
||||
/// </summary>
|
||||
public DbSet<LocaleResource> LocaleResources { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 多语言数据本地化数据
|
||||
/// </summary>
|
||||
public DbSet<LocalizedProperty> LocalizedProperties { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 支付通道信息
|
||||
/// </summary>
|
||||
public DbSet<PaymentChannel> PaymentChannels { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 权限信息
|
||||
/// </summary>
|
||||
public DbSet<Permission> Permissions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 产品信息
|
||||
/// </summary>
|
||||
public DbSet<Product> Products { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 产品属性组合信息
|
||||
/// </summary>
|
||||
public DbSet<ProductAttributeCombination> ProductAttributeCombinations { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 产品属性值
|
||||
/// </summary>
|
||||
public DbSet<ProductAttributeOption> ProductAttributeOptions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 产品属性值
|
||||
/// </summary>
|
||||
public DbSet<ProductAttributeValue> ProductAttributeValues { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 产品属性关系
|
||||
/// </summary>
|
||||
public DbSet<ProductAttributeRelation> ProductAttributeRelations { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 产品的属性值
|
||||
/// </summary>
|
||||
public DbSet<ProductAttribute> ProductAttributes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 产品库存信息
|
||||
/// </summary>
|
||||
public DbSet<ProductInventory> ProductInventories { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 产品库存记录日志
|
||||
/// </summary>
|
||||
public DbSet<ProductInventoryLog> ProductInventoryLogs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 产品的规格属性
|
||||
/// </summary>
|
||||
public DbSet<SpecificationAttribute> SpecificationAttributes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 规格属性预设值
|
||||
/// </summary>
|
||||
public DbSet<SpecificationAttributeOption> SpecificationAttributeOptions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户角色
|
||||
/// </summary>
|
||||
public DbSet<Role> Roles { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 系统配置
|
||||
/// </summary>
|
||||
public DbSet<Setting> Settings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网站应用
|
||||
/// </summary>
|
||||
public DbSet<SiteApp> SiteApps { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 多语言
|
||||
/// </summary>
|
||||
public DbSet<Language> Languages { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消息模版
|
||||
/// </summary>
|
||||
public DbSet<MessageTemplate> MessageTemplates { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 后台功能菜单
|
||||
/// </summary>
|
||||
public DbSet<Menu> Menus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上传文件
|
||||
/// </summary>
|
||||
public DbSet<UploadFile> UploadFiles { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户基本信息
|
||||
/// </summary>
|
||||
public DbSet<User> Users { get; set; }
|
||||
}
|
||||
}
|
||||
1374
Atomx.Data/Migrations/20251130091101_0.1.Designer.cs
generated
Normal file
1374
Atomx.Data/Migrations/20251130091101_0.1.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
743
Atomx.Data/Migrations/20251130091101_0.1.cs
Normal file
743
Atomx.Data/Migrations/20251130091101_0.1.cs
Normal file
@@ -0,0 +1,743 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Atomx.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class _01 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Addresses",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
UserId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Name = table.Column<string>(type: "varchar(128)", nullable: false),
|
||||
Email = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
Phone = table.Column<string>(type: "varchar(20)", nullable: false),
|
||||
Company = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
CountryId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Country = table.Column<string>(type: "varchar(50)", nullable: false),
|
||||
ProvinceId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Province = table.Column<string>(type: "varchar(100)", nullable: false),
|
||||
CityId = table.Column<long>(type: "bigint", nullable: false),
|
||||
City = table.Column<string>(type: "varchar(100)", nullable: false),
|
||||
RegionId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Region = table.Column<string>(type: "varchar(100)", nullable: false),
|
||||
PostalCode = table.Column<string>(type: "varchar(15)", nullable: false),
|
||||
AddressDetails = table.Column<string>(type: "varchar(256)", nullable: false),
|
||||
FullAddress = table.Column<string>(type: "varchar(1024)", nullable: false),
|
||||
Longitude = table.Column<decimal>(type: "numeric(10,6)", nullable: false),
|
||||
Latitude = table.Column<decimal>(type: "numeric(10,6)", nullable: false),
|
||||
IsVirtual = table.Column<bool>(type: "boolean", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
IsDelete = table.Column<bool>(type: "boolean", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Addresses", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Admins",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
Username = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
Password = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
Email = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
Mobile = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
Avatar = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
RoleId = table.Column<int>(type: "integer", nullable: false),
|
||||
TimeOffset = table.Column<string>(type: "varchar(4)", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
LoginCount = table.Column<int>(type: "integer", nullable: false),
|
||||
LastLogin = table.Column<DateTime>(type: "timestamptz", nullable: true),
|
||||
LastIp = table.Column<string>(type: "varchar(50)", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Admins", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AppVersions",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
SiteId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Platform = table.Column<int>(type: "integer", nullable: false),
|
||||
AppName = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
Title = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
Version = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
VersionX = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
VersionY = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
VersionZ = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
VersionDate = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
VersionState = table.Column<int>(type: "integer", nullable: false),
|
||||
Content = table.Column<string>(type: "text", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AppVersions", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Areas",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
ParentId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Name = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
Initial = table.Column<string>(type: "varchar(1)", nullable: false),
|
||||
TwoLetterISOCode = table.Column<string>(type: "varchar(2)", nullable: false),
|
||||
ThreeLetterISOCode = table.Column<string>(type: "varchar(3)", nullable: false),
|
||||
NumericISOCode = table.Column<int>(type: "integer", nullable: false),
|
||||
AllowShipping = table.Column<bool>(type: "boolean", nullable: false),
|
||||
Enabled = table.Column<bool>(type: "boolean", nullable: false),
|
||||
DisplayOrder = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Areas", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Categories",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
SiteId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Type = table.Column<int>(type: "integer", nullable: false),
|
||||
ParentId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Name = table.Column<string>(type: "varchar(25)", nullable: false),
|
||||
Slug = table.Column<string>(type: "varchar(50)", nullable: false),
|
||||
MetaDescription = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
MetaKeywords = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
FilterAttributes = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
Image = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
Banner = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
IsNode = table.Column<bool>(type: "boolean", nullable: false),
|
||||
Enabled = table.Column<bool>(type: "boolean", nullable: false),
|
||||
Depth = table.Column<int>(type: "integer", nullable: false),
|
||||
Path = table.Column<string>(type: "varchar(100)", nullable: false),
|
||||
DisplayOrder = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Categories", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Currencies",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false),
|
||||
Name = table.Column<string>(type: "varchar(50)", nullable: false),
|
||||
Title = table.Column<string>(type: "varchar(50)", nullable: false),
|
||||
CurrencyCode = table.Column<string>(type: "varchar(10)", nullable: false),
|
||||
DisplayLocale = table.Column<string>(type: "varchar(15)", nullable: false),
|
||||
Symbolic = table.Column<string>(type: "varchar(8)", nullable: false),
|
||||
CustomFormatting = table.Column<string>(type: "varchar(20)", nullable: false),
|
||||
Rate = table.Column<decimal>(type: "numeric(16,4)", nullable: false),
|
||||
DisplayOrder = table.Column<int>(type: "integer", nullable: false),
|
||||
EnableDisplay = table.Column<bool>(type: "boolean", nullable: false),
|
||||
EnablePay = table.Column<bool>(type: "boolean", nullable: false),
|
||||
Enabled = table.Column<bool>(type: "boolean", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Currencies", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "CurrencyChannelRelations",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
Title = table.Column<string>(type: "text", nullable: false),
|
||||
CurrencyId = table.Column<int>(type: "integer", nullable: false),
|
||||
PayChannelId = table.Column<int>(type: "integer", nullable: false),
|
||||
StartTime = table.Column<int>(type: "integer", nullable: false),
|
||||
EndTime = table.Column<int>(type: "integer", nullable: false),
|
||||
TimeZone = table.Column<int>(type: "integer", nullable: false),
|
||||
Rate = table.Column<decimal>(type: "numeric", nullable: false),
|
||||
Extended = table.Column<string>(type: "text", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_CurrencyChannelRelations", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Languages",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "varchar(50)", nullable: false),
|
||||
Title = table.Column<string>(type: "varchar(50)", nullable: false),
|
||||
Culture = table.Column<string>(type: "varchar(25)", nullable: false),
|
||||
FlagImage = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
DisplayOrder = table.Column<int>(type: "integer", nullable: false),
|
||||
Enabled = table.Column<bool>(type: "boolean", nullable: false),
|
||||
ResourceVersion = table.Column<string>(type: "varchar(25)", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Languages", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "LocaleResources",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
LanguageId = table.Column<int>(type: "integer", nullable: false),
|
||||
Name = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
Value = table.Column<string>(type: "varchar(1000)", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_LocaleResources", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "LocalizedProperties",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
LanguageNumber = table.Column<int>(type: "integer", nullable: false),
|
||||
Type = table.Column<int>(type: "integer", nullable: false),
|
||||
EntityId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Key = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
Value = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_LocalizedProperties", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Menus",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
Type = table.Column<int>(type: "integer", nullable: false),
|
||||
ParentId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Name = table.Column<string>(type: "varchar(50)", nullable: false),
|
||||
Icon = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
Key = table.Column<string>(type: "varchar(50)", nullable: false),
|
||||
Url = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
Code = table.Column<string>(type: "varchar(50)", nullable: false),
|
||||
IsLink = table.Column<bool>(type: "boolean", nullable: false),
|
||||
Enabled = table.Column<bool>(type: "boolean", nullable: false),
|
||||
Depth = table.Column<int>(type: "integer", nullable: false),
|
||||
Path = table.Column<string>(type: "varchar(100)", nullable: false),
|
||||
DisplayOrder = table.Column<int>(type: "integer", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Menus", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "MessageTemplates",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
Type = table.Column<int>(type: "integer", nullable: false),
|
||||
Key = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
Name = table.Column<string>(type: "varchar(256)", nullable: false),
|
||||
Title = table.Column<string>(type: "varchar(256)", nullable: false),
|
||||
Body = table.Column<string>(type: "text", nullable: false),
|
||||
Enabled = table.Column<bool>(type: "boolean", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_MessageTemplates", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PaymentChannels",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false),
|
||||
Type = table.Column<int>(type: "integer", nullable: false),
|
||||
Network = table.Column<int>(type: "integer", nullable: false),
|
||||
Name = table.Column<string>(type: "varchar(20)", nullable: false),
|
||||
Title = table.Column<string>(type: "varchar(20)", nullable: false),
|
||||
Description = table.Column<string>(type: "varchar(512)", nullable: false),
|
||||
Account = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
Config = table.Column<string>(type: "text", nullable: false),
|
||||
DisplayOrder = table.Column<int>(type: "integer", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PaymentChannels", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Permissions",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
Name = table.Column<string>(type: "varchar(128)", nullable: false),
|
||||
Description = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
Category = table.Column<string>(type: "varchar(128)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Permissions", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ProductAttributeCombinations",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
ProductId = table.Column<long>(type: "bigint", nullable: false),
|
||||
CorporationId = table.Column<long>(type: "bigint", nullable: false),
|
||||
ManufacturerId = table.Column<long>(type: "bigint", nullable: false),
|
||||
AttributesJson = table.Column<string>(type: "text", nullable: false),
|
||||
StockQuantity = table.Column<int>(type: "integer", nullable: false),
|
||||
SalesQuantity = table.Column<int>(type: "integer", nullable: false),
|
||||
SkuNumber = table.Column<string>(type: "varchar(20)", nullable: false),
|
||||
Weight = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
WeightUnit = table.Column<int>(type: "integer", nullable: false),
|
||||
ProcessCharge = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
ProcessCost = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
Surcharge = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
SurchargeCost = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
MarketPrice = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
Price = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
Mark = table.Column<int>(type: "integer", nullable: false),
|
||||
Note = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
Enabled = table.Column<bool>(type: "boolean", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ProductAttributeCombinations", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ProductAttributeOptions",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
AttributeId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Value = table.Column<string>(type: "varchar(50)", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
DisplayOrder = table.Column<int>(type: "integer", nullable: false),
|
||||
Standard = table.Column<bool>(type: "boolean", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ProductAttributeOptions", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ProductAttributeRelations",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
ProductId = table.Column<long>(type: "bigint", nullable: false),
|
||||
AttributeId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Image = table.Column<bool>(type: "boolean", nullable: false),
|
||||
DisplayOrder = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ProductAttributeRelations", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ProductAttributes",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
CategoryId = table.Column<long>(type: "bigint", nullable: false),
|
||||
ParentId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Name = table.Column<string>(type: "varchar(50)", nullable: false),
|
||||
WeightIsRequired = table.Column<bool>(type: "boolean", nullable: false),
|
||||
WeightUnit = table.Column<int>(type: "integer", nullable: false),
|
||||
ControlType = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
DisplayOrder = table.Column<int>(type: "integer", nullable: false),
|
||||
IsRequired = table.Column<bool>(type: "boolean", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ProductAttributes", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ProductAttributeValues",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
ProductId = table.Column<long>(type: "bigint", nullable: false),
|
||||
OptionId = table.Column<long>(type: "bigint", nullable: false),
|
||||
ProductAttributeRelationId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Name = table.Column<string>(type: "varchar(50)", nullable: false),
|
||||
Image = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
Weight = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
WeightUnit = table.Column<int>(type: "integer", nullable: false),
|
||||
IsAddWeight = table.Column<bool>(type: "boolean", nullable: false),
|
||||
DisplayOrder = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ProductAttributeValues", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ProductInventories",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
CorporationId = table.Column<long>(type: "bigint", nullable: false),
|
||||
ProductId = table.Column<long>(type: "bigint", nullable: false),
|
||||
ProductAttributeCombinationId = table.Column<long>(type: "bigint", nullable: false),
|
||||
WarehouseId = table.Column<long>(type: "bigint", nullable: false),
|
||||
StockQuantity = table.Column<int>(type: "integer", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ProductInventories", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ProductInventoryLogs",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
Operator = table.Column<long>(type: "bigint", nullable: true),
|
||||
Type = table.Column<int>(type: "integer", nullable: true),
|
||||
ProductId = table.Column<long>(type: "bigint", nullable: false),
|
||||
StoreId = table.Column<long>(type: "bigint", nullable: false),
|
||||
CorporationId = table.Column<long>(type: "bigint", nullable: false),
|
||||
ManufacturerId = table.Column<long>(type: "bigint", nullable: false),
|
||||
WarehouseId = table.Column<long>(type: "bigint", nullable: false),
|
||||
ProductAttributeCombinationId = table.Column<long>(type: "bigint", nullable: false),
|
||||
OrderId = table.Column<long>(type: "bigint", nullable: false),
|
||||
ChangeAmount = table.Column<int>(type: "integer", nullable: false),
|
||||
Weight = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
BeforeStock = table.Column<int>(type: "integer", nullable: false),
|
||||
AfterStock = table.Column<int>(type: "integer", nullable: false),
|
||||
Note = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ProductInventoryLogs", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Products",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
CorporationStaffId = table.Column<long>(type: "bigint", nullable: false),
|
||||
CorporationId = table.Column<long>(type: "bigint", nullable: false),
|
||||
StoreId = table.Column<long>(type: "bigint", nullable: false),
|
||||
ProductTypeId = table.Column<long>(type: "bigint", nullable: false),
|
||||
CategoryPath = table.Column<string>(type: "varchar(200)", nullable: true),
|
||||
CategoryId = table.Column<long>(type: "bigint", nullable: false),
|
||||
ManufacturerId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Title = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
SIN = table.Column<string>(type: "varchar(20)", nullable: true),
|
||||
Image = table.Column<string>(type: "varchar(256)", nullable: true),
|
||||
Photos = table.Column<string>(type: "text", nullable: true),
|
||||
Feature = table.Column<string>(type: "varchar(255)", nullable: true),
|
||||
Description = table.Column<string>(type: "varchar(255)", nullable: true),
|
||||
SpecificationJson = table.Column<string>(type: "text", nullable: true),
|
||||
Weight = table.Column<decimal>(type: "numeric(6,2)", nullable: true),
|
||||
MinWeight = table.Column<decimal>(type: "numeric(6,2)", nullable: true),
|
||||
MaxWeight = table.Column<decimal>(type: "numeric(6,2)", nullable: true),
|
||||
MarketPrice = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
Price = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
|
||||
SkuPrices = table.Column<string>(type: "text", nullable: true),
|
||||
Extended = table.Column<string>(type: "text", nullable: false),
|
||||
DisplayOrder = table.Column<int>(type: "integer", nullable: false),
|
||||
ReviewStatus = table.Column<int>(type: "integer", nullable: false),
|
||||
InventoryMethod = table.Column<int>(type: "integer", nullable: false),
|
||||
StockQuantity = table.Column<int>(type: "integer", nullable: false),
|
||||
SalesQuantity = table.Column<int>(type: "integer", nullable: false),
|
||||
PictureCount = table.Column<int>(type: "integer", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
Deleted = table.Column<bool>(type: "boolean", nullable: false),
|
||||
DeletedTime = table.Column<DateTime>(type: "timestamptz", nullable: true),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Products", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Roles",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Type = table.Column<int>(type: "integer", nullable: false),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Description = table.Column<string>(type: "varchar(255)", nullable: false),
|
||||
Permission = table.Column<string>(type: "text", nullable: false),
|
||||
IsSystemRole = table.Column<bool>(type: "boolean", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
Enabled = table.Column<bool>(type: "boolean", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Roles", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Settings",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
SiteId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Key = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
Type = table.Column<int>(type: "integer", nullable: false),
|
||||
Name = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
Content = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Settings", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "SiteApps",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
Type = table.Column<int>(type: "integer", nullable: false),
|
||||
Name = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
Enabled = table.Column<bool>(type: "boolean", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_SiteApps", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "SpecificationAttributeOptions",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
SpecificationId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Value = table.Column<string>(type: "varchar(50)", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
DisplayOrder = table.Column<int>(type: "integer", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_SpecificationAttributeOptions", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "SpecificationAttributes",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
CategoryId = table.Column<long>(type: "bigint", nullable: false),
|
||||
ParentId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Name = table.Column<string>(type: "varchar(50)", nullable: false),
|
||||
ControlType = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
DisplayOrder = table.Column<int>(type: "integer", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_SpecificationAttributes", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "UploadFiles",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
SiteId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Type = table.Column<int>(type: "integer", nullable: false),
|
||||
Name = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
Path = table.Column<string>(type: "varchar(128)", nullable: false),
|
||||
Extension = table.Column<string>(type: "varchar(12)", nullable: false),
|
||||
ContentType = table.Column<string>(type: "varchar(32)", nullable: false),
|
||||
SHA256Hash = table.Column<string>(type: "varchar(128)", nullable: false),
|
||||
Size = table.Column<int>(type: "integer", nullable: false),
|
||||
CreateUid = table.Column<long>(type: "bigint", nullable: false),
|
||||
CreateBy = table.Column<string>(type: "varchar(32)", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_UploadFiles", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Users",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<long>(type: "bigint", nullable: false),
|
||||
Name = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
Email = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
Mobile = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
Avatar = table.Column<string>(type: "varchar(64)", nullable: false),
|
||||
Password = table.Column<string>(type: "varchar(32)", nullable: false),
|
||||
CreateTime = table.Column<DateTime>(type: "timestamptz", nullable: false),
|
||||
UpdateTime = table.Column<DateTime>(type: "timestamptz", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Users", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Addresses");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Admins");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "AppVersions");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Areas");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Categories");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Currencies");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "CurrencyChannelRelations");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Languages");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "LocaleResources");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "LocalizedProperties");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Menus");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "MessageTemplates");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "PaymentChannels");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Permissions");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ProductAttributeCombinations");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ProductAttributeOptions");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ProductAttributeRelations");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ProductAttributes");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ProductAttributeValues");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ProductInventories");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ProductInventoryLogs");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Products");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Roles");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Settings");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "SiteApps");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "SpecificationAttributeOptions");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "SpecificationAttributes");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "UploadFiles");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Users");
|
||||
}
|
||||
}
|
||||
}
|
||||
1371
Atomx.Data/Migrations/DataContextModelSnapshot.cs
Normal file
1371
Atomx.Data/Migrations/DataContextModelSnapshot.cs
Normal file
File diff suppressed because it is too large
Load Diff
47
Atomx.Data/Services/IdCreatorService.cs
Normal file
47
Atomx.Data/Services/IdCreatorService.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using IdGen;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Atomx.Data.Services
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public interface IIdCreatorService
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
long NewId();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class IdCreatorService : IIdCreatorService
|
||||
{
|
||||
|
||||
private IdGenerator IdCreator { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
public IdCreatorService(IConfiguration configuration)
|
||||
{
|
||||
DateTime epoch = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
var structure = new IdStructure(45, 2, 16);
|
||||
var options = new IdGeneratorOptions(structure, new DefaultTimeSource(epoch));
|
||||
var workId = int.Parse(configuration.GetSection("IdWorkId").Value ?? "0");
|
||||
IdCreator = new IdGenerator(workId, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public long NewId()
|
||||
{
|
||||
return IdCreator.CreateId();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user