字典缓存

booking_auth_dev
wet 2 years ago
parent 8dc390cb8a
commit 300124d65a

@ -29,6 +29,7 @@ using Yitter.IdGenerator;
using Myshipping.Core.Entity;
using Furion.RemoteRequest.Extensions;
using System.Net.Http;
using Myshipping.Core.Service;
namespace Myshipping.Application
{
@ -48,11 +49,13 @@ namespace Myshipping.Application
private readonly SqlSugarRepository<DjyWebsiteAccountConfig> _webconfig;
private readonly SqlSugarRepository<SysDictData> _dicdata;
private readonly ILogger<BookingOrderService> _logger;
private readonly ISysCacheService _cache;
public BookingOrderService(SqlSugarRepository<BookingOrder> rep, SqlSugarRepository<BookingCtn> repCtn, SqlSugarRepository<BookingCtnDetail> ctndetailrep,
SqlSugarRepository<BookingLog> bookinglog, SqlSugarRepository<BookingLogDetail> bookinglogdetail, SqlSugarRepository<BookingRemark> bookingremark,
SqlSugarRepository<BookingFile> bookingfile, SqlSugarRepository<DjyWebsiteAccountConfig> webconfig, SqlSugarRepository<SysDictData> dicdata,
ILogger<BookingOrderService> logger)
ILogger<BookingOrderService> logger, ISysCacheService cache)
{
this._logger = logger;
this._rep = rep;
@ -64,6 +67,7 @@ namespace Myshipping.Application
this._bookingfile = bookingfile;
this._webconfig = webconfig;
this._dicdata = dicdata;
this._cache = cache;
}
/// <summary>
@ -253,7 +257,9 @@ namespace Myshipping.Application
{
_logger.LogInformation("提单号:" + input.MBLNO + " 调用运踪接口");
var key = _webconfig.FirstOrDefault(x => x.TenantId == Convert.ToInt64(UserManager.TENANT_ID) && x.TypeCode == "seae_billtraceurl");
var url = _dicdata.FirstOrDefault(x => x.Code == "seae_billtraceurl");
var url = _cache.GetAllDictData().Result;
BillTraceDto billdto = new BillTraceDto();
List<BillTraceList> billTraceList = new List<BillTraceList>();
billTraceList.Add(new BillTraceList
@ -261,16 +267,16 @@ namespace Myshipping.Application
MBLNO = input.MBLNO,
YARD = input.YARD,
YardCode = input.YARDID,
CARRIER=null,
CARRIERID=null,
isBook=false
CARRIER = null,
CARRIERID = null,
isBook = false
});
billdto.Children = billTraceList;
billdto.Key = key.Account;
billdto.PWD = key.Password;
var json=billdto.ToJsonString();
var html= await url.Value.SetHttpMethod(HttpMethod.Post).SetQueries(new { msg = json }).SetRetryPolicy(3, 5000).SendAsAsync<RespCommon>();
_logger.LogInformation("提单号:" + input.MBLNO + " 调用运踪接口返回"+ html.ToJsonString());
var json = billdto.ToJsonString();
var html = await url.FirstOrDefault(x=>x.TypeCode== "url_set"&&x.Code== "seae_billtraceurl").Value.SetHttpMethod(HttpMethod.Post).SetQueries(new { msg = json }).SetRetryPolicy(3, 5000).SendAsAsync<RespCommon>();
_logger.LogInformation("提单号:" + input.MBLNO + " 调用运踪接口返回" + html.ToJsonString());
}
}
@ -372,13 +378,14 @@ namespace Myshipping.Application
OldValue = _oldvalue,
NewValue = _value,
});
if (descriptor.Name== "YARDID"|| descriptor.Name == "YARD"|| descriptor.Name == "MBLNO") {
if (descriptor.Name == "YARDID" || descriptor.Name == "YARD" || descriptor.Name == "MBLNO")
{
if (!string.IsNullOrWhiteSpace(input.YARDID) && !string.IsNullOrWhiteSpace(input.YARD) && !string.IsNullOrWhiteSpace(input.MBLNO))
{
_logger.LogInformation("提单号:" + input.MBLNO + " 调用运踪接口");
var key = _webconfig.FirstOrDefault(x => x.TenantId == Convert.ToInt64(UserManager.TENANT_ID) && x.TypeCode == "seae_billtraceurl");
var url = _dicdata.FirstOrDefault(x => x.Code == "seae_billtraceurl");
var url = _cache.GetAllDictData().Result;
BillTraceDto billdto = new BillTraceDto();
List<BillTraceList> billTraceList = new List<BillTraceList>();
billTraceList.Add(new BillTraceList
@ -394,7 +401,7 @@ namespace Myshipping.Application
billdto.Key = key.Account;
billdto.PWD = key.Password;
var json = billdto.ToJsonString();
var html = await url.Value.SetHttpMethod(HttpMethod.Post).SetQueries(new { msg = json }).SetRetryPolicy(3, 5000).SendAsAsync<RespCommon>();
var html = await url.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "seae_billtraceurl").Value.SetHttpMethod(HttpMethod.Post).SetQueries(new { msg = json }).SetRetryPolicy(3, 5000).SendAsAsync<RespCommon>();
_logger.LogInformation("提单号:" + input.MBLNO + " 调用运踪接口返回" + html.ToJsonString());
}
}
@ -447,7 +454,6 @@ namespace Myshipping.Application
return list;
}
/// <summary>
/// 获取备注
/// </summary>
@ -473,7 +479,6 @@ namespace Myshipping.Application
await _bookingremark.InsertAsync(entity);
}
/// <summary>
/// 增加订舱附件
/// </summary>
@ -534,8 +539,6 @@ namespace Myshipping.Application
}
/// <summary>
/// 获取附件
/// </summary>

@ -115,7 +115,11 @@ public class CommonConst
/// </summary>
public const string CACHE_KEY_COMMON_DB_MAPPING_VESSEL = "CommonDbMappingVessel";
/// <summary>
/// 字典映射
/// </summary>
public const string CACHE_KEY_COMMON_DB_DICT_DATA = "DictDataList";
#endregion

@ -1,4 +1,5 @@
using Myshipping.Core.Entity;
using Myshipping.Core.Service.Dict.Dto;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
@ -217,6 +218,16 @@ public interface ISysCacheService
/// </summary>
/// <returns></returns>
Task SetAllTenantParam(List<DjyTenantParamValue> list);
/// <summary>
/// 获取字典
/// </summary>
/// <returns></returns>
Task<List<DictDataDto>> GetAllDictData();
/// <summary>
/// 设置字典
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
Task SetAllDictData(List<DictDataDto> list);
#endregion
}

@ -3,6 +3,7 @@ using Furion.DynamicApiController;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Myshipping.Core.Entity;
using Myshipping.Core.Service.Dict.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
@ -565,7 +566,28 @@ public class SysCacheService : ISysCacheService, IDynamicApiController, ISinglet
/// <returns></returns>
public Task SetAllTenantParam(List<DjyTenantParamValue> list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_TENANT_PARAM_VALUE, list, TimeSpan.FromMinutes(5));
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_TENANT_PARAM_VALUE, list);
}
/// <summary>
/// 获取字典缓存
/// </summary>
/// <returns></returns>
public Task<List<DictDataDto>> GetAllDictData()
{
return _cache.GetAsync<List<DictDataDto>>(CommonConst.CACHE_KEY_COMMON_DB_DICT_DATA);
}
/// <summary>
/// 设置字典参数
/// </summary>
/// <returns></returns>
public Task SetAllDictData(List<DictDataDto> list)
{
return _cache.SetAsync(CommonConst.CACHE_KEY_COMMON_DB_DICT_DATA, list);
}
#endregion

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Core.Service.Dict.Dto
{
public class DictDataDto
{
public long Id { get; set; }
public string TypeName { get; set; }
public string TypeCode { get; set; }
public string Value { get; set; }
public string Code { get; set; }
public int Sort { get; set; }
public string Remark { get; set; }
}
}

@ -12,6 +12,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Myshipping.Core.Service.Dict.Dto;
namespace Myshipping.Core.Service;
@ -23,9 +24,12 @@ public class SysDictDataService : ISysDictDataService, IDynamicApiController, IT
{
private readonly SqlSugarRepository<SysDictData> _sysDictDataRep; // 字典类型表仓储
public SysDictDataService(SqlSugarRepository<SysDictData> sysDictDataRep)
private readonly ISysCacheService _cache;
public SysDictDataService(SqlSugarRepository<SysDictData> sysDictDataRep, ISysCacheService cache)
{
_sysDictDataRep = sysDictDataRep;
_cache = cache;
}
/// <summary>
@ -73,6 +77,23 @@ public class SysDictDataService : ISysDictDataService, IDynamicApiController, IT
var dictData = input.Adapt<SysDictData>();
await _sysDictDataRep.InsertAsync(dictData);
////设置缓存
await _cache.DelAsync(CommonConst.CACHE_KEY_COMMON_DB_DICT_DATA);
var list = await _sysDictDataRep.AsQueryable().InnerJoin<SysDictType>((d, t) => d.TypeId == t.Id).Where((d, t) => t.Status == CommonStatus.ENABLE && d.Status == CommonStatus.ENABLE).Select((d, t) => new DictDataDto
{
Id = d.Id,
TypeName = t.Name,
TypeCode = t.Code,
Value = d.Value,
Code = d.Code,
Sort = d.Sort,
Remark = d.Remark
}).ToListAsync();
await _cache.SetAllDictData(list);
}
/// <summary>
@ -87,6 +108,21 @@ public class SysDictDataService : ISysDictDataService, IDynamicApiController, IT
if (dictData == null) throw Oops.Oh(ErrorCode.D3004);
await _sysDictDataRep.DeleteAsync(dictData);
////设置缓存
await _cache.DelAsync(CommonConst.CACHE_KEY_COMMON_DB_DICT_DATA);
var list = await _sysDictDataRep.AsQueryable().InnerJoin<SysDictType>((d, t) => d.TypeId == t.Id).Where((d, t) => t.Status == CommonStatus.ENABLE && d.Status == CommonStatus.ENABLE).Select((d, t) => new DictDataDto
{
Id = d.Id,
TypeName = t.Name,
TypeCode = t.Code,
Value = d.Value,
Code = d.Code,
Sort = d.Sort,
Remark = d.Remark
}).ToListAsync();
await _cache.SetAllDictData(list);
}
/// <summary>
@ -106,6 +142,21 @@ public class SysDictDataService : ISysDictDataService, IDynamicApiController, IT
var dictData = input.Adapt<SysDictData>();
await _sysDictDataRep.AsUpdateable(dictData).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
////设置缓存
await _cache.DelAsync(CommonConst.CACHE_KEY_COMMON_DB_DICT_DATA);
var list = await _sysDictDataRep.AsQueryable().InnerJoin<SysDictType>((d, t) => d.TypeId == t.Id).Where((d, t) => t.Status == CommonStatus.ENABLE && d.Status == CommonStatus.ENABLE).Select((d, t) => new DictDataDto
{
Id = d.Id,
TypeName = t.Name,
TypeCode = t.Code,
Value = d.Value,
Code = d.Code,
Sort = d.Sort,
Remark = d.Remark
}).ToListAsync();
await _cache.SetAllDictData(list);
}
/// <summary>
@ -133,6 +184,20 @@ public class SysDictDataService : ISysDictDataService, IDynamicApiController, IT
if (!Enum.IsDefined(typeof(CommonStatus), input.Status))
throw Oops.Oh(ErrorCode.D3005);
dictData.Status = input.Status;
////设置缓存
await _cache.DelAsync(CommonConst.CACHE_KEY_COMMON_DB_DICT_DATA);
var list = await _sysDictDataRep.AsQueryable().InnerJoin<SysDictType>((d, t) => d.TypeId == t.Id).Where((d, t) => t.Status == CommonStatus.ENABLE && d.Status == CommonStatus.ENABLE).Select((d, t) => new DictDataDto
{
Id = d.Id,
TypeName = t.Name,
TypeCode = t.Code,
Value = d.Value,
Code = d.Code,
Sort = d.Sort,
Remark = d.Remark
}).ToListAsync();
await _cache.SetAllDictData(list);
}
/// <summary>
@ -160,6 +225,20 @@ public class SysDictDataService : ISysDictDataService, IDynamicApiController, IT
public async Task DeleteByTypeId(long dictTypeId)
{
await _sysDictDataRep.DeleteAsync(u => u.TypeId == dictTypeId);
////设置缓存
await _cache.DelAsync(CommonConst.CACHE_KEY_COMMON_DB_DICT_DATA);
var list = await _sysDictDataRep.AsQueryable().InnerJoin<SysDictType>((d, t) => d.TypeId == t.Id).Where((d, t) => t.Status == CommonStatus.ENABLE && d.Status == CommonStatus.ENABLE).Select((d, t) => new DictDataDto
{
Id = d.Id,
TypeName = t.Name,
TypeCode = t.Code,
Value = d.Value,
Code = d.Code,
Sort = d.Sort,
Remark = d.Remark
}).ToListAsync();
await _cache.SetAllDictData(list);
}

@ -110,6 +110,8 @@ public class Startup : AppStartup
// 注册 Log 日志订阅者
builder.AddSubscriber<LogEventSubscriber>();
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

Loading…
Cancel
Save