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.
BookingHeChuan/Myshipping.Application/Service/EmbedProjectGoodsStatus/EmbedProjectGoodsStatusServ...

517 lines
22 KiB
C#

using Furion.ClayObject.Extensions;
using Furion.DependencyInjection;
using Furion.DistributedIDGenerator;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Furion.JsonSerialization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Myshipping.Core;
using Myshipping.Core.Service;
using StackExchange.Profiling.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
/// <summary>
/// 内嵌服务项目和货物状态
/// </summary>
[AllowAnonymous, ApiDescriptionSettings("Application", Name = "EmbedProjectGoodsStatus", Order = 20)]
public class EmbedProjectGoodsStatusService: IEmbedProjectGoodsStatusService, IDynamicApiController, ITransient
{
private readonly ILogger<BookingTruckService> _logger;
private readonly IServiceWorkFlowManageService _serviceWorkFlowManageService;
private readonly IServiceWorkFlowBaseService _serviceWorkFlowBaseService;
/// <summary>
///
/// </summary>
/// <param name="logger"></param>
public EmbedProjectGoodsStatusService(ILogger<BookingTruckService> logger, IServiceWorkFlowManageService serviceWorkFlowManageService, IServiceWorkFlowBaseService serviceWorkFlowBaseService)
{
_logger = logger;
_serviceWorkFlowManageService = serviceWorkFlowManageService;
_serviceWorkFlowBaseService = serviceWorkFlowBaseService;
}
#region 保存服务项目
/// <summary>
/// 保存服务项目
/// </summary>
/// <param name="model">修改服务项目详情</param>
/// <returns>返回回执</returns>
[AllowAnonymous, HttpPost("/EmbedProjectGoodsStatus/SaveServiceProject"), ApiUser(ApiCode = "EmbedServiceProjectStatus")]
public async Task<TaskManageOrderResultDto> SaveServiceProject(EmbedServiceProjectDto model)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
try
{
if (string.IsNullOrWhiteSpace(model.businessId))
throw Oops.Oh($"业务主键不能为空");
_logger.LogInformation("批次={no} 请求保存服务项目 modifyjson={msg}", batchNo, JSON.Serialize(model));
TrackingMessageInfo msgInfo = new TrackingMessageInfo
{
Head = new TrackingMessageHeadInfo
{
GID = IDGen.NextID().ToString(),
MessageType = "PROJECT",
ReceiverId = "ServiceProjectStatus",
ReceiverName = "服务项目和状态",
SenderId = "BookingOrder",
SenderName = "海运订舱",
RequestDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),
Version = "2.0",
RequestAction = "AddOrModify",
},
Main = new TrackingMessageMainInfo
{
BusiId = model.businessId,
BusiSystemCode = "BOOKING_ORDER",
MBlNo = "",
VesselVoyno = "",
OrderNo = "",
PushType = TrackingPushTypeEnum.Project,
OperTenantId = UserManager.TENANT_ID,
OperTenantName = UserManager.TENANT_NAME,
OpertType = model.OpertType,
OperUserId = UserManager.UserId.ToString(),
OperUserName = UserManager.Name,
SourceType = TrackingSourceTypeEnum.MANUAL,
ProjectList = model.ProjectCodes.Select(a => new TrackingMessageMainProjectInfo
{
ServiceProjectCode = a,
}).ToList()
}
};
DateTime bDate = DateTime.Now;
_logger.LogInformation("批次={no} 推送保存服务项目 msg={msg}", batchNo, JSON.Serialize(msgInfo));
var rlt = await _serviceWorkFlowManageService.PushStatus(msgInfo);
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation("批次={no} 请求完成,耗时:{timeDiff}ms. 结果{msg} result={rlt}", batchNo, timeDiff, (rlt.succ ? "成功" : "失败")
, JSON.Serialize(rlt));
if (!rlt.succ)
{
result = rlt;
}
else
{
result.succ = true;
result.msg = "保存成功";
}
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"服务项目保存失败,原因:{ex.Message}";
}
return result;
}
#endregion
#region 取消服务项目
/// <summary>
/// 取消服务项目
/// </summary>
/// <param name="model">修改服务项目详情</param>
/// <returns>返回回执</returns>
[AllowAnonymous, HttpPost("/EmbedProjectGoodsStatus/CancelServiceProject"), ApiUser(ApiCode = "EmbedServiceProjectStatus")]
public async Task<TaskManageOrderResultDto> CancelServiceProject(EmbedServiceProjectDto model)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
try
{
if (string.IsNullOrWhiteSpace(model.businessId))
throw Oops.Oh($"业务主键不能为空");
_logger.LogInformation("批次={no} 请求保存服务项目 modifyjson={msg}", batchNo, JSON.Serialize(model));
TrackingMessageInfo msgInfo = new TrackingMessageInfo
{
Head = new TrackingMessageHeadInfo
{
GID = IDGen.NextID().ToString(),
MessageType = "PROJECT",
ReceiverId = "ServiceProjectStatus",
ReceiverName = "服务项目和状态",
SenderId = "BookingOrder",
SenderName = "海运订舱",
RequestDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),
Version = "2.0",
RequestAction = "AddOrModify",
},
Main = new TrackingMessageMainInfo
{
BusiId = model.businessId,
BusiSystemCode = "BOOKING_ORDER",
MBlNo = "",
VesselVoyno = "",
OrderNo = "",
PushType = TrackingPushTypeEnum.Project,
OperTenantId = UserManager.TENANT_ID,
OperTenantName = UserManager.TENANT_NAME,
OpertType = model.OpertType,
OperUserId = UserManager.UserId.ToString(),
OperUserName = UserManager.Name,
SourceType = TrackingSourceTypeEnum.MANUAL,
ProjectList = model.ProjectCodes.Select(a => new TrackingMessageMainProjectInfo
{
ServiceProjectCode = a,
}).ToList()
}
};
DateTime bDate = DateTime.Now;
_logger.LogInformation("批次={no} 推送取消服务项目 msg={msg}", batchNo, JSON.Serialize(msgInfo));
var rlt = await _serviceWorkFlowManageService.CancelStatus(msgInfo);
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation("批次={no} 请求完成,耗时:{timeDiff}ms. 结果{msg} result={rlt}", batchNo, timeDiff, (rlt.succ ? "成功" : "失败")
, JSON.Serialize(rlt));
if (!rlt.succ)
{
result = rlt;
}
else
{
result.succ = true;
result.msg = "取消成功";
}
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"服务项目取消失败,原因:{ex.Message}";
}
return result;
}
#endregion
#region 获取服务项目列表
/// <summary>
/// 获取服务项目列表
/// </summary>
/// <param name="model">查询服务项目和状态详情</param>
/// <returns>返回回执</returns>
[AllowAnonymous, HttpPost("/EmbedProjectGoodsStatus/GetServiceProjectList"), ApiUser(ApiCode = "EmbedServiceProjectStatus")]
public async Task<TaskManageOrderResultDto> GetServiceProjectList(EmbedQueryServiceProjectWithStatus model)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
try
{
DateTime bDate = DateTime.Now;
EmbedQueryServiceProjectWithStatus queryInfo = new EmbedQueryServiceProjectWithStatus
{
businessId = model.businessId,
QueryType = TrackingQueryTypeEnum.QUERY_SERVICE_PROJECT,
TenantId = UserManager.TENANT_ID
};
result = await _serviceWorkFlowManageService.GetEnableProjectListCommon(queryInfo);
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation("批次={no} id={id} 单票请求服务项目结果 耗时:{timeDiff}ms. ", batchNo, model.businessId, timeDiff);
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"获取服务项目列表失败,原因:{ex.Message}";
}
return result;
}
#endregion
#region 获取服务项目下的状态列表
/// <summary>
/// 获取服务项目下的状态列表
/// </summary>
/// <param name="model">查询服务项目和状态详情</param>
/// <returns>返回回执</returns>
[AllowAnonymous, HttpPost("/EmbedProjectGoodsStatus/GetServiceStatusList"), ApiUser(ApiCode = "EmbedServiceProjectStatus")]
public async Task<TaskManageOrderResultDto> GetServiceStatusList(EmbedQueryServiceProjectWithStatus model)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
try
{
//查询所有服务服务项目和状态时,需要先获取订舱详情
if (model.QueryType == TrackingQueryTypeEnum.QUERY_SERVICE_ALL)
{
DateTime bDate = DateTime.Now;
EmbedQueryServiceProjectWithStatus queryInfo = new EmbedQueryServiceProjectWithStatus
{
businessId = model.businessId,
QueryType = TrackingQueryTypeEnum.QUERY_SERVICE_PROJECT,
TenantId = UserManager.TENANT_ID
};
result = await _serviceWorkFlowManageService.GetEnableStatusListByBusinessCommon(queryInfo);
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation("批次={no} id={id} 单票请求服务状态结果 耗时:{timeDiff}ms. ", batchNo, model.businessId, timeDiff);
}
else
{
if (model.ProjectCodes == null || (model.ProjectCodes != null && model.ProjectCodes.Length == 0))
throw Oops.Oh($"服务项目代码不能为空");
//model.TenantId = UserManager.TENANT_ID;
result = await _serviceWorkFlowManageService.GetEnableStatusListByProject(new QueryServiceProjectWithStatus {
ProjectCodes = model.ProjectCodes,
QueryType = model.QueryType,
TenantId = UserManager.TENANT_ID
});
}
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"获取服务项目下的状态列表失败,原因:{ex.Message}";
}
return result;
}
#endregion
#region 保存服务状态
/// <summary>
/// 保存服务状态
/// </summary>
/// <param name="model">修改服务状态详情</param>
/// <returns>返回回执</returns>
[AllowAnonymous, HttpPost("/EmbedProjectGoodsStatus/SaveServiceStatus"), ApiUser(ApiCode = "EmbedServiceProjectStatus")]
public async Task<TaskManageOrderResultDto> SaveServiceStatus(EmbedServiceProjectStatusDto model)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
try
{
if (string.IsNullOrWhiteSpace(model.businessId))
throw Oops.Oh($"业务主键不能为空");
_logger.LogInformation("批次={no} 请求保存服务项目 modifyjson={msg}", batchNo, JSON.Serialize(model));
TrackingMessageInfo msgInfo = new TrackingMessageInfo
{
Head = new TrackingMessageHeadInfo
{
GID = IDGen.NextID().ToString(),
MessageType = "PROJECT",
ReceiverId = "ServiceProjectStatus",
ReceiverName = "服务项目和状态",
SenderId = "BookingOrder",
SenderName = "海运订舱",
RequestDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),
Version = "2.0",
RequestAction = "AddOrModify",
},
Main = new TrackingMessageMainInfo
{
BusiId = model.businessId,
BusiSystemCode = "BOOKING_ORDER",
MBlNo = "",
VesselVoyno = "",
OrderNo = "",
PushType = TrackingPushTypeEnum.Status,
OperTenantId = UserManager.TENANT_ID,
OperTenantName = UserManager.TENANT_NAME,
OpertType = TrackingOperTypeEnum.MANUAL,
OperUserId = UserManager.UserId.ToString(),
OperUserName = UserManager.Name,
SourceType = model.SourceType,
StatusList = model.StatusCodes.Select(a => new TrackingMessageMainStatusInfo
{
StatusCode = a.StatusCode,
StatusDate = a.SetActDate,
StatusVal = a.SetActVal,
Remark = a.ActRemark
}).ToList()
}
};
DateTime bDate = DateTime.Now;
_logger.LogInformation("批次={no} 推送保存服务项目 msg={msg}", batchNo, JSON.Serialize(msgInfo));
var rlt = await _serviceWorkFlowManageService.PushStatus(msgInfo);
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation("批次={no} 请求完成,耗时:{timeDiff}ms. 结果{msg} result={rlt}", batchNo, timeDiff, (rlt.succ ? "成功" : "失败")
, JSON.Serialize(rlt));
if (!rlt.succ)
{
result = rlt;
}
else
{
result.succ = true;
result.msg = "推送成功";
//这里预留保存完货物状态主动推送东胜
//var _bookingOrderService = _namedBookingOrderServiceProvider.GetService<ITransient>(nameof(BookingOrderService));
// await _bookingOrderService.SetBookingGoodsStatus(bookingOrder.Id, true, "手动更新货物状态");
}
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"服务项目状态推送失败,原因:{ex.Message}";
}
return result;
}
#endregion
#region 取消服务状态
/// <summary>
/// 取消服务状态
/// </summary>
/// <param name="model">修改服务状态详情</param>
/// <returns>返回回执</returns>
[AllowAnonymous, HttpPost("/EmbedProjectGoodsStatus/CancelServiceStatus"), ApiUser(ApiCode = "EmbedServiceProjectStatus")]
public async Task<TaskManageOrderResultDto> CancelServiceStatus(EmbedServiceProjectStatusDto model)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
try
{
_logger.LogInformation("批次={no} 请求保存服务项目 modifyjson={msg}", batchNo, JSON.Serialize(model));
TrackingMessageInfo msgInfo = new TrackingMessageInfo
{
Head = new TrackingMessageHeadInfo
{
GID = IDGen.NextID().ToString(),
MessageType = "PROJECT",
ReceiverId = "ServiceProjectStatus",
ReceiverName = "服务项目和状态",
SenderId = "BookingOrder",
SenderName = "海运订舱",
RequestDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),
Version = "2.0",
RequestAction = "AddOrModify",
},
Main = new TrackingMessageMainInfo
{
BusiId = model.businessId,
BusiSystemCode = "BOOKING_ORDER",
MBlNo = "",
VesselVoyno = "",
OrderNo = "",
PushType = TrackingPushTypeEnum.Status,
OperTenantId = UserManager.TENANT_ID,
OperTenantName = UserManager.TENANT_NAME,
OpertType = TrackingOperTypeEnum.MANUAL,
OperUserId = UserManager.UserId.ToString(),
OperUserName = UserManager.Name,
SourceType = model.SourceType,
StatusList = model.StatusCodes.Select(a => new TrackingMessageMainStatusInfo
{
StatusCode = a.StatusCode,
StatusDate = a.SetActDate,
StatusVal = a.SetActVal,
Remark = a.ActRemark
}).ToList()
}
};
DateTime bDate = DateTime.Now;
_logger.LogInformation("批次={no} 推送保存服务项目 msg={msg}", batchNo, JSON.Serialize(msgInfo));
var rlt = await _serviceWorkFlowManageService.CancelStatus(msgInfo);
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation("批次={no} 请求完成,耗时:{timeDiff}ms. 结果{msg} result={rlt}", batchNo, timeDiff, (rlt.succ ? "成功" : "失败")
, JSON.Serialize(rlt));
if (!rlt.succ)
{
result = rlt;
}
else
{
result.succ = true;
result.msg = "推送成功";
}
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"服务项目状态推送失败,原因:{ex.Message}";
}
return result;
}
#endregion
/// <summary>
/// 获取可用的服务项目字典列表
/// </summary>
/// <param name="isAvoidCache">是否重新加载缓存</param>
/// <returns></returns>
[AllowAnonymous, HttpGet("/EmbedProjectGoodsStatus/GetEnableProjectDictTreeList"), ApiUser(ApiCode = "EmbedServiceProjectStatus")]
public async Task<List<Myshipping.Core.Service.DictTreeOutput>> GetEnableProjectDictTreeList([FromQuery] bool isAvoidCache = false)
{
return await _serviceWorkFlowBaseService.GetEnableStatusDictTreeList(isAvoidCache);
}
}
}