You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
6.5 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Furion.DependencyInjection;
using Furion.DistributedIDGenerator;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Myshipping.Application.Entity;
using Myshipping.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace Myshipping.Application
{
/// <summary>
/// 任务管理
/// </summary>
[ApiDescriptionSettings("Application", Name = "TaskManage", Order = 10)]
public class TaskManageService : ITaskManageService, IDynamicApiController
{
private readonly SqlSugarRepository<TaskBaseInfo> _taskBaseInfoRepository;
private readonly SqlSugarRepository<TaskSIFeedBackInfo> _taskSIFeedBackInfoRepository;
private readonly SqlSugarRepository<TaskSIFeedBackContaInfo> _taskSIFeedBackContaInfoRepository;
private readonly ILogger<BookingOrderService> _logger;
public TaskManageService(SqlSugarRepository<TaskBaseInfo> taskBaseInfoRepository,
SqlSugarRepository<TaskSIFeedBackInfo> taskSIFeedBackInfoRepository,
SqlSugarRepository<TaskSIFeedBackContaInfo> taskSIFeedBackContaInfoRepository,
ILogger<BookingOrderService> logger)
{
_taskBaseInfoRepository = taskBaseInfoRepository;
_taskSIFeedBackInfoRepository = taskSIFeedBackInfoRepository;
_taskSIFeedBackContaInfoRepository = taskSIFeedBackContaInfoRepository;
_logger = logger;
}
/// <summary>
/// 创建任务
/// </summary>
/// <param name="info">任务详情</param>
/// <returns>返回回执</returns>
[AllowAnonymous,HttpPost("/TaskManage/CreateTaskJob")]
public async Task<TaskManageOrderResultDto> CreateTaskJob(TaskManageOrderMessageInfo info)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
/*
创建任务
1、判断当前任务的主键是否已入库已入库不允许重复返回错误提示。
2、
*/
result = await InitTaskJob(info);
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"请求任务异常,{ex.Message}";
}
return result;
}
/// <summary>
/// 新增任务
/// </summary>
/// <param name="info">任务详情</param>
/// <returns>返回回执</returns>
private async Task<TaskManageOrderResultDto> InitTaskJob(TaskManageOrderMessageInfo info)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.OUT_BUSI_NO == info.Head.GID);
if (taskInfo != null)
throw Oops.Oh($"任务已经存在不能重复提交");
taskInfo = new TaskBaseInfo
{
PK_ID = IDGen.NextID().ToString(),
TASK_NO = info.Head.GID,
STATUS = TaskStatusEnum.Create.ToString(),
IsDeleted = false,
IS_EXCEPT = 0,
IS_COMPLETE = 0,
MBL_NO = info.Main.MBlNo,
TASK_BASE_TYPE = info.Main.TaskType.ToString(),
CARRIER_ID = info.Main.CarrierId?.Trim(),
IS_PUBLIC = string.IsNullOrWhiteSpace(info.Main.TaskUserId) ? 1 : 0,
BOOK_ORDER_NO = info.Main.BookingOrderNo,
OUT_BUSI_NO = info.Head.GID,
TASK_TITLE = info.Main.TaskTitle,
TASK_DESP = info.Main.TaskDesp,
TASK_SOURCE = info.Main.TaskSource.ToString(),
TASK_TYPE = info.Main.TaskType.ToString(),
};
taskInfo.CreatedTime = DateTime.Now;
taskInfo.UpdatedTime = taskInfo.CreatedTime;
if (!string.IsNullOrWhiteSpace(taskInfo.CARRIER_ID)
&& taskInfo.CARRIER_ID == "MSC")
{
if (TaskBaseTypeEnum.BC.ToString() == taskInfo.TASK_BASE_TYPE)
taskInfo.TASK_TYPE = TaskBusiTypeEnum.MSC_BC.ToString();
if(taskInfo.IS_EXCEPT == 1)
taskInfo.TASK_TYPE = TaskBusiTypeEnum.MSC_EXCEPT.ToString();
}
//新增
await _taskBaseInfoRepository.InsertAsync(taskInfo);
//SI反馈入库
if (info.Main.TaskType == TaskBaseTypeEnum.SI_FEEDBACK)
{
if(info.Main.SIFeedBack == null)
throw Oops.Oh($"任务类型={info.Main.TaskType.ToString()} SIFeedBack信息必传");
TaskSIFeedBackInfo taskSIFeedBackInfo = info.Main.SIFeedBack.Adapt<TaskSIFeedBackInfo>();
taskSIFeedBackInfo.PK_ID = IDGen.NextID().ToString();
taskSIFeedBackInfo.TASK_PKID = taskInfo.PK_ID;
taskSIFeedBackInfo.CreatedTime = taskInfo.CreatedTime;
taskSIFeedBackInfo.UpdatedTime = taskInfo.CreatedTime;
await _taskSIFeedBackInfoRepository.InsertAsync(taskSIFeedBackInfo);
//SI反馈箱信息入库
if(info.Main.SIFeedBack.ContaList != null && info.Main.SIFeedBack.ContaList.Count > 0)
{
info.Main.SIFeedBack.ContaList.ForEach( async ctn => {
var contaInfo = ctn.Adapt<TaskSIFeedBackContaInfo>();
contaInfo.PK_ID = IDGen.NextID().ToString();
contaInfo.P_PKID = taskSIFeedBackInfo.PK_ID;
contaInfo.CreatedTime = taskInfo.CreatedTime;
contaInfo.UpdatedTime = taskInfo.CreatedTime;
await _taskSIFeedBackContaInfoRepository.InsertAsync(contaInfo);
});
}
}
result.succ = true;
result.msg = "新增任务成功";
}
catch (Exception ex)
{
throw Oops.Oh($"{ex.Message}");
}
return result;
}
}
}