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 { /// /// 内嵌服务项目和货物状态 /// [AllowAnonymous, ApiDescriptionSettings("Application", Name = "EmbedProjectGoodsStatus", Order = 20)] public class EmbedProjectGoodsStatusService: IEmbedProjectGoodsStatusService, IDynamicApiController, ITransient { private readonly ILogger _logger; private readonly IServiceWorkFlowManageService _serviceWorkFlowManageService; private readonly IServiceWorkFlowBaseService _serviceWorkFlowBaseService; /// /// /// /// public EmbedProjectGoodsStatusService(ILogger logger, IServiceWorkFlowManageService serviceWorkFlowManageService, IServiceWorkFlowBaseService serviceWorkFlowBaseService) { _logger = logger; _serviceWorkFlowManageService = serviceWorkFlowManageService; _serviceWorkFlowBaseService = serviceWorkFlowBaseService; } #region 保存服务项目 /// /// 保存服务项目 /// /// 修改服务项目详情 /// 返回回执 [AllowAnonymous, HttpPost("/EmbedProjectGoodsStatus/SaveServiceProject"), ApiUser(ApiCode = "EmbedServiceProjectStatus")] public async Task 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 取消服务项目 /// /// 取消服务项目 /// /// 修改服务项目详情 /// 返回回执 [AllowAnonymous, HttpPost("/EmbedProjectGoodsStatus/CancelServiceProject"), ApiUser(ApiCode = "EmbedServiceProjectStatus")] public async Task 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 获取服务项目列表 /// /// 获取服务项目列表 /// /// 查询服务项目和状态详情 /// 返回回执 [AllowAnonymous, HttpPost("/EmbedProjectGoodsStatus/GetServiceProjectList"), ApiUser(ApiCode = "EmbedServiceProjectStatus")] public async Task 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 获取服务项目下的状态列表 /// /// 获取服务项目下的状态列表 /// /// 查询服务项目和状态详情 /// 返回回执 [AllowAnonymous, HttpPost("/EmbedProjectGoodsStatus/GetServiceStatusList"), ApiUser(ApiCode = "EmbedServiceProjectStatus")] public async Task 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 保存服务状态 /// /// 保存服务状态 /// /// 修改服务状态详情 /// 返回回执 [AllowAnonymous, HttpPost("/EmbedProjectGoodsStatus/SaveServiceStatus"), ApiUser(ApiCode = "EmbedServiceProjectStatus")] public async Task 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(nameof(BookingOrderService)); // await _bookingOrderService.SetBookingGoodsStatus(bookingOrder.Id, true, "手动更新货物状态"); } } catch (Exception ex) { result.succ = false; result.msg = $"服务项目状态推送失败,原因:{ex.Message}"; } return result; } #endregion #region 取消服务状态 /// /// 取消服务状态 /// /// 修改服务状态详情 /// 返回回执 [AllowAnonymous, HttpPost("/EmbedProjectGoodsStatus/CancelServiceStatus"), ApiUser(ApiCode = "EmbedServiceProjectStatus")] public async Task 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 /// /// 获取可用的服务项目字典列表 /// /// 是否重新加载缓存 /// [AllowAnonymous, HttpGet("/EmbedProjectGoodsStatus/GetEnableProjectDictTreeList"), ApiUser(ApiCode = "EmbedServiceProjectStatus")] public async Task> GetEnableProjectDictTreeList([FromQuery] bool isAvoidCache = false) { return await _serviceWorkFlowBaseService.GetEnableProjectDictTreeList(isAvoidCache); } } }