|
|
|
@ -1,5 +1,11 @@
|
|
|
|
|
using Furion.DynamicApiController;
|
|
|
|
|
using Furion.DistributedIDGenerator;
|
|
|
|
|
using Furion.DynamicApiController;
|
|
|
|
|
using Furion.FriendlyException;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Myshipping.Application.Entity;
|
|
|
|
|
using Myshipping.Core;
|
|
|
|
|
using Myshipping.Core.Service;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
@ -14,20 +20,162 @@ namespace Myshipping.Application.Service.TaskManagePlat
|
|
|
|
|
[ApiDescriptionSettings("Application", Name = "TaskManageShareLink", Order = 10)]
|
|
|
|
|
public class TaskManageShareLinkService : ITaskManageShareLinkService, IDynamicApiController
|
|
|
|
|
{
|
|
|
|
|
private readonly ISysCacheService _cache;
|
|
|
|
|
private readonly ILogger<TaskManageShareLinkService> _logger;
|
|
|
|
|
private readonly SqlSugarRepository<TaskShareLinkInfo> _taskShareLinkInfoRepository;
|
|
|
|
|
private readonly SqlSugarRepository<TaskShareLinkDynamicDataInfo> _taskShareLinkDynamicDataInfoRepository;
|
|
|
|
|
private readonly SqlSugarRepository<TaskBaseInfo> _taskBaseRepository;
|
|
|
|
|
|
|
|
|
|
private const string SHARE_LINK_CACHE_KEY_TEMPLATE = "ShareLinkKey_";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TaskManageShareLinkService(ISysCacheService cache, ILogger<TaskManageShareLinkService> logger,
|
|
|
|
|
SqlSugarRepository<TaskShareLinkInfo> taskShareLinkInfoRepository,
|
|
|
|
|
SqlSugarRepository<TaskShareLinkDynamicDataInfo> taskShareLinkDynamicDataInfoRepository,
|
|
|
|
|
SqlSugarRepository<TaskBaseInfo> taskBaseRepository)
|
|
|
|
|
{
|
|
|
|
|
_cache = cache;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
|
|
|
|
_taskShareLinkInfoRepository = taskShareLinkInfoRepository;
|
|
|
|
|
_taskShareLinkDynamicDataInfoRepository = taskShareLinkDynamicDataInfoRepository;
|
|
|
|
|
_taskBaseRepository = taskBaseRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 生成访问链接
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生成访问链接
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="businessId">业务ID</param>
|
|
|
|
|
/// <param name="taskType">任务类型</param>
|
|
|
|
|
/// <param name="expireDate">失效时间</param>
|
|
|
|
|
/// <param name="model">创建分享链接请求</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<TaskManageOrderResultDto> CreateShareLink(string businessId, string taskType, DateTime expireDate)
|
|
|
|
|
[HttpPost("/TaskManageShareLink/CreateShareLink")]
|
|
|
|
|
public async Task<TaskManageOrderResultDto> CreateShareLink([FromBody] ShareLinkRequestDto model)
|
|
|
|
|
{
|
|
|
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
1、判断当前businessId是否有STATUS=ACTIVE的记录,如果有记录不允许重复分享。
|
|
|
|
|
2、创建分享记录,并生成动态数据(预甩需要生成免责声明)
|
|
|
|
|
3、判断有效期是否小于等于当前日期,如果是不能生成分享。
|
|
|
|
|
4、创建完记录后,把生成后的SHARE_LINK_KEY写入redis并用expireDate作为失效日期。
|
|
|
|
|
5、返回SHARE_LINK_KEY。
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string shareKey = string.Empty;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.businessId))
|
|
|
|
|
throw Oops.Oh($"业务ID不能为空");
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.taskType))
|
|
|
|
|
throw Oops.Oh($"任务类型不能为空");
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.expireDate))
|
|
|
|
|
throw Oops.Oh($"失效时间不能为空");
|
|
|
|
|
|
|
|
|
|
DateTime expireDateTime = DateTime.MinValue;
|
|
|
|
|
|
|
|
|
|
if(!DateTime.TryParse(model.expireDate, out expireDateTime))
|
|
|
|
|
throw Oops.Oh($"失效时间格式错误,请参考格式yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
if(expireDateTime <= DateTime.Now)
|
|
|
|
|
throw Oops.Oh($"失效时间不能早于或等于当前时间");
|
|
|
|
|
|
|
|
|
|
var taskInfo = _taskBaseRepository.AsQueryable().First(a => a.PK_ID == model.businessId);
|
|
|
|
|
|
|
|
|
|
if (taskInfo == null)
|
|
|
|
|
throw Oops.Oh($"任务ID获取详情失败,已删除或不存在");
|
|
|
|
|
|
|
|
|
|
var shareInfo = _taskShareLinkInfoRepository.AsQueryable()
|
|
|
|
|
.First(a => a.BUSI_ID == model.businessId && a.TASK_TYPE == model.taskType && a.STATUS == "ACTIVE");
|
|
|
|
|
|
|
|
|
|
if (shareInfo != null)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Oh($"已有分享记录不能重复生成");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DateTime nowDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
TaskShareLinkInfo taskShareLinkInfo = new TaskShareLinkInfo {
|
|
|
|
|
EXPIRE_DATE = expireDateTime,
|
|
|
|
|
STATUS = "ACTIVE",
|
|
|
|
|
BUSI_ID = model.businessId,
|
|
|
|
|
IS_MANUAL = false,
|
|
|
|
|
CreatedTime = nowDate,
|
|
|
|
|
UpdatedTime = nowDate,
|
|
|
|
|
CreatedUserId = UserManager.UserId,
|
|
|
|
|
CreatedUserName = UserManager.Name,
|
|
|
|
|
TASK_TYPE = model.taskType,
|
|
|
|
|
IS_USER_FEEDBACK = model.isUserFeedBack,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//写入分享记录
|
|
|
|
|
await _taskShareLinkInfoRepository.InsertAsync(taskShareLinkInfo);
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"写入分享记录表完成,id={taskShareLinkInfo.Id}");
|
|
|
|
|
|
|
|
|
|
//生成分享KEY
|
|
|
|
|
SuperShortLinkHelper codeHelper = new SuperShortLinkHelper();
|
|
|
|
|
shareKey = codeHelper.Confuse(taskShareLinkInfo.Id);
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"生成分享KEY完成,id={taskShareLinkInfo.Id} shareKey={shareKey}");
|
|
|
|
|
|
|
|
|
|
//更新分享表
|
|
|
|
|
var shareEntity = _taskShareLinkInfoRepository.AsQueryable().First(a => a.Id == taskShareLinkInfo.Id);
|
|
|
|
|
|
|
|
|
|
//写入redis缓存
|
|
|
|
|
string cacheVal = $"{taskInfo.TASK_TYPE}_{taskInfo.TASK_NO}_{taskInfo.TenantName}_{model.expireDate}";
|
|
|
|
|
|
|
|
|
|
var expireTimeSpan = new DateTimeOffset(expireDateTime).ToUnixTimeSeconds();
|
|
|
|
|
|
|
|
|
|
if (_cache.Exists(shareKey))
|
|
|
|
|
{
|
|
|
|
|
shareEntity.SHARE_LINK_KEY = shareKey;
|
|
|
|
|
shareEntity.STATUS = "REPEAT_KEY";//REPEAT_KEY-重复KEY被取消
|
|
|
|
|
|
|
|
|
|
await _taskShareLinkInfoRepository.AsUpdateable(shareEntity)
|
|
|
|
|
.UpdateColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.SHARE_LINK_KEY,
|
|
|
|
|
it.STATUS,
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"分享KEY存在重复终止生成分享(cache),id={taskShareLinkInfo.Id} shareKey={shareKey} cache={_cache.Get<string>(shareKey)}");
|
|
|
|
|
|
|
|
|
|
throw Oops.Oh($"已有分享记录不能重复生成");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
shareEntity.SHARE_LINK_KEY = shareKey;
|
|
|
|
|
|
|
|
|
|
await _taskShareLinkInfoRepository.AsUpdateable(shareEntity)
|
|
|
|
|
.UpdateColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.SHARE_LINK_KEY,
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
await _cache.SetTimeoutAsync(shareKey, cacheVal, new TimeSpan(expireTimeSpan));
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"分享KEY写入cache完成,id={taskShareLinkInfo.Id} shareKey={shareKey} cache={cacheVal}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.succ = true;
|
|
|
|
|
result.ext = shareKey;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError($"获取预甩详情异常,原因:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
result.succ = false;
|
|
|
|
|
result.msg = $"获取预甩详情异常,原因:{ex.Message}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 取消访问链接
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 取消访问链接
|
|
|
|
|
/// </summary>
|
|
|
|
@ -39,8 +187,9 @@ namespace Myshipping.Application.Service.TaskManagePlat
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 校验成访问链接
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 校验成访问链接
|
|
|
|
|
/// </summary>
|
|
|
|
@ -52,8 +201,9 @@ namespace Myshipping.Application.Service.TaskManagePlat
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 访问链接
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 访问链接
|
|
|
|
|
/// </summary>
|
|
|
|
@ -65,5 +215,25 @@ namespace Myshipping.Application.Service.TaskManagePlat
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 获取分享详情
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取分享详情
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="shareKey">链接分享KEY</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<TaskManageOrderResultDto> GetInfo(string shareKey)
|
|
|
|
|
{
|
|
|
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
1、先验证shareKey是否在缓存存在,存在继续,不存在返回错误。
|
|
|
|
|
2、获取分享的表记录,根据任务类型调取不同的接口,返回详情数据。
|
|
|
|
|
3、查看是否存在分享的声明内容,如果存在,需要返回。
|
|
|
|
|
*/
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|