zhangxiaofeng 9 months ago
commit 1052ce0063

@ -57,5 +57,10 @@ namespace Myshipping.Application
/// 是否手工设定 true-是false-否 /// 是否手工设定 true-是false-否
/// </summary> /// </summary>
public bool IS_MANUAL { get; set; } public bool IS_MANUAL { get; set; }
/// <summary>
/// 自增KEY计数
/// </summary>
public Nullable<long> INCREMENT_KEY { get; set; }
} }
} }

@ -32,12 +32,12 @@ namespace Myshipping.Application
/// <summary> /// <summary>
/// Code长度位数下能达到的最大值 /// Code长度位数下能达到的最大值
/// </summary> /// </summary>
private long MaxValue public long MaxValue
{ {
get get
{ {
var max = (long)Math.Pow(_powMax, _codeLength) - 1; var max = (long)Math.Pow(_powMax, _codeLength) - 1;
return (long)Math.Pow(15, max.ToString().Length - 1) - 1; return (long)Math.Pow(10, max.ToString().Length - 1) - 1;
} }
} }

@ -16,6 +16,11 @@ namespace Myshipping.Application
/// </summary> /// </summary>
public string businessId { get; set; } public string businessId { get; set; }
/// <summary>
/// 业务类型NOMI_DISPATCH-预甩调度BUSI对应的预甩的调度主键
/// </summary>
public string businessType { get; set; } = "NOMI_DISPATCH";
/// <summary> /// <summary>
/// 任务类型 /// 任务类型
/// </summary> /// </summary>

@ -25,14 +25,18 @@ namespace Myshipping.Application.Service.TaskManagePlat
private readonly SqlSugarRepository<TaskShareLinkInfo> _taskShareLinkInfoRepository; private readonly SqlSugarRepository<TaskShareLinkInfo> _taskShareLinkInfoRepository;
private readonly SqlSugarRepository<TaskShareLinkDynamicDataInfo> _taskShareLinkDynamicDataInfoRepository; private readonly SqlSugarRepository<TaskShareLinkDynamicDataInfo> _taskShareLinkDynamicDataInfoRepository;
private readonly SqlSugarRepository<TaskBaseInfo> _taskBaseRepository; private readonly SqlSugarRepository<TaskBaseInfo> _taskBaseRepository;
private readonly SqlSugarRepository<TaskRollingNominationInfo> _taskRollingNominationInfoRepository;
private readonly SqlSugarRepository<TaskRollingNominationDispatchInfo> _taskRollingNominationDispatchInfoRepository;
private const string SHARE_LINK_CACHE_KEY_TEMPLATE = "ShareLinkKey_"; private const string SHARE_LINK_CACHE_KEY_TEMPLATE = "ShareLinkKeyIncrement";
public TaskManageShareLinkService(ISysCacheService cache, ILogger<TaskManageShareLinkService> logger, public TaskManageShareLinkService(ISysCacheService cache, ILogger<TaskManageShareLinkService> logger,
SqlSugarRepository<TaskShareLinkInfo> taskShareLinkInfoRepository, SqlSugarRepository<TaskShareLinkInfo> taskShareLinkInfoRepository,
SqlSugarRepository<TaskShareLinkDynamicDataInfo> taskShareLinkDynamicDataInfoRepository, SqlSugarRepository<TaskShareLinkDynamicDataInfo> taskShareLinkDynamicDataInfoRepository,
SqlSugarRepository<TaskBaseInfo> taskBaseRepository) SqlSugarRepository<TaskBaseInfo> taskBaseRepository,
SqlSugarRepository<TaskRollingNominationInfo> taskRollingNominationInfoRepository,
SqlSugarRepository<TaskRollingNominationDispatchInfo> taskRollingNominationDispatchInfoRepository)
{ {
_cache = cache; _cache = cache;
_logger = logger; _logger = logger;
@ -40,6 +44,8 @@ namespace Myshipping.Application.Service.TaskManagePlat
_taskShareLinkInfoRepository = taskShareLinkInfoRepository; _taskShareLinkInfoRepository = taskShareLinkInfoRepository;
_taskShareLinkDynamicDataInfoRepository = taskShareLinkDynamicDataInfoRepository; _taskShareLinkDynamicDataInfoRepository = taskShareLinkDynamicDataInfoRepository;
_taskBaseRepository = taskBaseRepository; _taskBaseRepository = taskBaseRepository;
_taskRollingNominationInfoRepository = taskRollingNominationInfoRepository;
_taskRollingNominationDispatchInfoRepository = taskRollingNominationDispatchInfoRepository;
} }
#region 生成访问链接 #region 生成访问链接
@ -71,6 +77,9 @@ namespace Myshipping.Application.Service.TaskManagePlat
if (string.IsNullOrWhiteSpace(model.taskType)) if (string.IsNullOrWhiteSpace(model.taskType))
throw Oops.Oh($"任务类型不能为空"); throw Oops.Oh($"任务类型不能为空");
if (string.IsNullOrWhiteSpace(model.businessType))
throw Oops.Oh($"业务类型不能为空");
if (string.IsNullOrWhiteSpace(model.expireDate)) if (string.IsNullOrWhiteSpace(model.expireDate))
throw Oops.Oh($"失效时间不能为空"); throw Oops.Oh($"失效时间不能为空");
@ -82,10 +91,22 @@ namespace Myshipping.Application.Service.TaskManagePlat
if(expireDateTime <= DateTime.Now) if(expireDateTime <= DateTime.Now)
throw Oops.Oh($"失效时间不能早于或等于当前时间"); throw Oops.Oh($"失效时间不能早于或等于当前时间");
var taskInfo = _taskBaseRepository.AsQueryable().First(a => a.PK_ID == model.businessId); if (!model.businessType.Equals("NOMI_DISPATCH", StringComparison.OrdinalIgnoreCase))
{
throw Oops.Oh($"当前只支持预甩调度分享");
}
var nomDispatchList = _taskRollingNominationDispatchInfoRepository.AsQueryable().Filter(null, true)
.InnerJoin<TaskRollingNominationDetailInfo>((dispatch,detail) => dispatch.DETAIL_ID == detail.PK_ID)
.Where((dispatch,detail) => dispatch.BATCH_ID == model.businessId
&& detail.IsDeleted == false && dispatch.IsDeleted == false)
.Select((dispatch, detail) => new { Detail = detail, Dispatch = dispatch }).ToList();
if (taskInfo == null) if (nomDispatchList.Count == 0)
throw Oops.Oh($"任务ID获取详情失败已删除或不存在"); throw Oops.Oh($"预甩调度获取详情失败,已删除或不存在");
if (nomDispatchList.Any(a => !string.IsNullOrWhiteSpace(a.Dispatch.USER_OPINION)))
throw Oops.Oh($"当前预甩调度已有用户反馈,不能创建分享");
var shareInfo = _taskShareLinkInfoRepository.AsQueryable() var shareInfo = _taskShareLinkInfoRepository.AsQueryable()
.First(a => a.BUSI_ID == model.businessId && a.TASK_TYPE == model.taskType && a.STATUS == "ACTIVE"); .First(a => a.BUSI_ID == model.businessId && a.TASK_TYPE == model.taskType && a.STATUS == "ACTIVE");
@ -115,30 +136,38 @@ namespace Myshipping.Application.Service.TaskManagePlat
_logger.LogInformation($"写入分享记录表完成id={taskShareLinkInfo.Id}"); _logger.LogInformation($"写入分享记录表完成id={taskShareLinkInfo.Id}");
var autoIncrementKey = RedisHelper.IncrBy(SHARE_LINK_CACHE_KEY_TEMPLATE);
//生成分享KEY //生成分享KEY
SuperShortLinkHelper codeHelper = new SuperShortLinkHelper(); SuperShortLinkHelper codeHelper = new SuperShortLinkHelper();
shareKey = codeHelper.Confuse(taskShareLinkInfo.Id); shareKey = codeHelper.Confuse(autoIncrementKey);
_logger.LogInformation($"生成分享KEY完成id={taskShareLinkInfo.Id} shareKey={shareKey}"); _logger.LogInformation($"生成分享KEY完成id={taskShareLinkInfo.Id} shareKey={shareKey}");
//更新分享表 //更新分享表
var shareEntity = _taskShareLinkInfoRepository.AsQueryable().First(a => a.Id == taskShareLinkInfo.Id); var shareEntity = _taskShareLinkInfoRepository.AsQueryable().First(a => a.Id == taskShareLinkInfo.Id);
string taskId = nomDispatchList.FirstOrDefault().Dispatch.TASK_ID;
var taskInfo = _taskBaseRepository.AsQueryable().First(a => a.PK_ID == taskId);
//写入redis缓存 //写入redis缓存
string cacheVal = $"{taskInfo.TASK_TYPE}_{taskInfo.TASK_NO}_{taskInfo.TenantName}_{model.expireDate}"; string cacheVal = $"{taskInfo.TASK_TYPE}_{taskInfo.TASK_NO}_{nomDispatchList.FirstOrDefault().Detail.SHIPMENT}_{taskInfo.TenantName}_{model.expireDate}";
var expireTimeSpan = new DateTimeOffset(expireDateTime).ToUnixTimeSeconds(); var expireTimeSpan = expireDateTime.Subtract(nowDate).Duration();
//new DateTimeOffset(expireDateTime).ToUnixTimeSeconds();
if (_cache.Exists(shareKey)) if (_cache.Exists(shareKey))
{ {
shareEntity.SHARE_LINK_KEY = shareKey; shareEntity.SHARE_LINK_KEY = shareKey;
shareEntity.STATUS = "REPEAT_KEY";//REPEAT_KEY-重复KEY被取消 shareEntity.STATUS = "REPEAT_KEY";//REPEAT_KEY-重复KEY被取消
shareEntity.INCREMENT_KEY = autoIncrementKey;
await _taskShareLinkInfoRepository.AsUpdateable(shareEntity) await _taskShareLinkInfoRepository.AsUpdateable(shareEntity)
.UpdateColumns(it => new .UpdateColumns(it => new
{ {
it.SHARE_LINK_KEY, it.SHARE_LINK_KEY,
it.STATUS, it.STATUS,
it.INCREMENT_KEY
}).ExecuteCommandAsync(); }).ExecuteCommandAsync();
_logger.LogInformation($"分享KEY存在重复终止生成分享(cache)id={taskShareLinkInfo.Id} shareKey={shareKey} cache={_cache.Get<string>(shareKey)}"); _logger.LogInformation($"分享KEY存在重复终止生成分享(cache)id={taskShareLinkInfo.Id} shareKey={shareKey} cache={_cache.Get<string>(shareKey)}");
@ -148,14 +177,16 @@ namespace Myshipping.Application.Service.TaskManagePlat
else else
{ {
shareEntity.SHARE_LINK_KEY = shareKey; shareEntity.SHARE_LINK_KEY = shareKey;
shareEntity.INCREMENT_KEY = autoIncrementKey;
await _taskShareLinkInfoRepository.AsUpdateable(shareEntity) await _taskShareLinkInfoRepository.AsUpdateable(shareEntity)
.UpdateColumns(it => new .UpdateColumns(it => new
{ {
it.SHARE_LINK_KEY, it.SHARE_LINK_KEY,
it.INCREMENT_KEY
}).ExecuteCommandAsync(); }).ExecuteCommandAsync();
await _cache.SetTimeoutAsync(shareKey, cacheVal, new TimeSpan(expireTimeSpan)); await _cache.SetTimeoutAsync(shareKey, cacheVal, expireTimeSpan);
_logger.LogInformation($"分享KEY写入cache完成id={taskShareLinkInfo.Id} shareKey={shareKey} cache={cacheVal}"); _logger.LogInformation($"分享KEY写入cache完成id={taskShareLinkInfo.Id} shareKey={shareKey} cache={cacheVal}");
} }

Loading…
Cancel
Save