|
|
|
@ -25,14 +25,18 @@ namespace Myshipping.Application.Service.TaskManagePlat
|
|
|
|
|
private readonly SqlSugarRepository<TaskShareLinkInfo> _taskShareLinkInfoRepository;
|
|
|
|
|
private readonly SqlSugarRepository<TaskShareLinkDynamicDataInfo> _taskShareLinkDynamicDataInfoRepository;
|
|
|
|
|
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,
|
|
|
|
|
SqlSugarRepository<TaskShareLinkInfo> taskShareLinkInfoRepository,
|
|
|
|
|
SqlSugarRepository<TaskShareLinkDynamicDataInfo> taskShareLinkDynamicDataInfoRepository,
|
|
|
|
|
SqlSugarRepository<TaskBaseInfo> taskBaseRepository)
|
|
|
|
|
SqlSugarRepository<TaskBaseInfo> taskBaseRepository,
|
|
|
|
|
SqlSugarRepository<TaskRollingNominationInfo> taskRollingNominationInfoRepository,
|
|
|
|
|
SqlSugarRepository<TaskRollingNominationDispatchInfo> taskRollingNominationDispatchInfoRepository)
|
|
|
|
|
{
|
|
|
|
|
_cache = cache;
|
|
|
|
|
_logger = logger;
|
|
|
|
@ -40,6 +44,8 @@ namespace Myshipping.Application.Service.TaskManagePlat
|
|
|
|
|
_taskShareLinkInfoRepository = taskShareLinkInfoRepository;
|
|
|
|
|
_taskShareLinkDynamicDataInfoRepository = taskShareLinkDynamicDataInfoRepository;
|
|
|
|
|
_taskBaseRepository = taskBaseRepository;
|
|
|
|
|
_taskRollingNominationInfoRepository = taskRollingNominationInfoRepository;
|
|
|
|
|
_taskRollingNominationDispatchInfoRepository = taskRollingNominationDispatchInfoRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 生成访问链接
|
|
|
|
@ -71,6 +77,9 @@ namespace Myshipping.Application.Service.TaskManagePlat
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.taskType))
|
|
|
|
|
throw Oops.Oh($"任务类型不能为空");
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.businessType))
|
|
|
|
|
throw Oops.Oh($"业务类型不能为空");
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.expireDate))
|
|
|
|
|
throw Oops.Oh($"失效时间不能为空");
|
|
|
|
|
|
|
|
|
@ -82,10 +91,22 @@ namespace Myshipping.Application.Service.TaskManagePlat
|
|
|
|
|
if(expireDateTime <= DateTime.Now)
|
|
|
|
|
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)
|
|
|
|
|
throw Oops.Oh($"任务ID获取详情失败,已删除或不存在");
|
|
|
|
|
if (nomDispatchList.Count == 0)
|
|
|
|
|
throw Oops.Oh($"预甩调度获取详情失败,已删除或不存在");
|
|
|
|
|
|
|
|
|
|
if (nomDispatchList.Any(a => !string.IsNullOrWhiteSpace(a.Dispatch.USER_OPINION)))
|
|
|
|
|
throw Oops.Oh($"当前预甩调度已有用户反馈,不能创建分享");
|
|
|
|
|
|
|
|
|
|
var shareInfo = _taskShareLinkInfoRepository.AsQueryable()
|
|
|
|
|
.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}");
|
|
|
|
|
|
|
|
|
|
var autoIncrementKey = RedisHelper.IncrBy(SHARE_LINK_CACHE_KEY_TEMPLATE);
|
|
|
|
|
//生成分享KEY
|
|
|
|
|
SuperShortLinkHelper codeHelper = new SuperShortLinkHelper();
|
|
|
|
|
shareKey = codeHelper.Confuse(taskShareLinkInfo.Id);
|
|
|
|
|
shareKey = codeHelper.Confuse(autoIncrementKey);
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"生成分享KEY完成,id={taskShareLinkInfo.Id} shareKey={shareKey}");
|
|
|
|
|
|
|
|
|
|
//更新分享表
|
|
|
|
|
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缓存
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
|
shareEntity.SHARE_LINK_KEY = shareKey;
|
|
|
|
|
shareEntity.STATUS = "REPEAT_KEY";//REPEAT_KEY-重复KEY被取消
|
|
|
|
|
shareEntity.INCREMENT_KEY = autoIncrementKey;
|
|
|
|
|
|
|
|
|
|
await _taskShareLinkInfoRepository.AsUpdateable(shareEntity)
|
|
|
|
|
.UpdateColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.SHARE_LINK_KEY,
|
|
|
|
|
it.STATUS,
|
|
|
|
|
it.INCREMENT_KEY
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"分享KEY存在重复终止生成分享(cache),id={taskShareLinkInfo.Id} shareKey={shareKey} cache={_cache.Get<string>(shareKey)}");
|
|
|
|
@ -148,14 +177,16 @@ namespace Myshipping.Application.Service.TaskManagePlat
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
shareEntity.SHARE_LINK_KEY = shareKey;
|
|
|
|
|
shareEntity.INCREMENT_KEY = autoIncrementKey;
|
|
|
|
|
|
|
|
|
|
await _taskShareLinkInfoRepository.AsUpdateable(shareEntity)
|
|
|
|
|
.UpdateColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.SHARE_LINK_KEY,
|
|
|
|
|
it.INCREMENT_KEY
|
|
|
|
|
}).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}");
|
|
|
|
|
}
|
|
|
|
|