diff --git a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/UpsertOrderInput.cs b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/UpsertOrderInput.cs index 4bd7b0b7..cfdbe0ac 100644 --- a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/UpsertOrderInput.cs +++ b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/UpsertOrderInput.cs @@ -10,6 +10,16 @@ public class UpsertOrderInput : UpdateOrderInput [Required] [Range(1, int.MaxValue)] public int CustomId { get; set; } + + /// + /// 模板code + /// + public List TemplateCodes { get; set; } + + /// + /// 当前操作人 + /// + public int OptionUserId { get; set; } } public class OrderFlightInfo diff --git a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/UpsertTrackInput.cs b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/UpsertTrackInput.cs index b4cf72ae..2ba86e87 100644 --- a/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/UpsertTrackInput.cs +++ b/src/SJZY.Track.Application.Contract/Dtos/ProvideServices/UpsertTrackInput.cs @@ -118,4 +118,9 @@ public class UpsertTrackInput : OrderNoInfo /// [Range(-12, 12)] public float? DestinationTimeZone { get; set; } + + /// + /// 当前操作人 + /// + public int OptionUserId { get; set; } } diff --git a/src/SJZY.Track.Application.Contract/Dtos/TrackContents/GetContentDetailInput.cs b/src/SJZY.Track.Application.Contract/Dtos/TrackContents/GetContentDetailInput.cs new file mode 100644 index 00000000..d61d19bb --- /dev/null +++ b/src/SJZY.Track.Application.Contract/Dtos/TrackContents/GetContentDetailInput.cs @@ -0,0 +1,29 @@ +namespace SJZY.Track.Application.Contract.Dtos.TrackContents; + +public class GetContentDetailInput +{ + /// + /// 子系统编号 + /// + public int SystemId { get; set; } + + /// + /// 订单号 + /// + public string OrderNumber { get; set; } + + /// + /// 订单类型 + /// + public int OrderType { get; set; } + + /// + /// 轨迹code + /// + public string TrackCode { get; set; } + + /// + /// 轨迹发生时间 + /// + public DateTime TrackTime { get; set; } +} diff --git a/src/SJZY.Track.Application.Contract/Dtos/TrackContents/GetContentDetailOutput.cs b/src/SJZY.Track.Application.Contract/Dtos/TrackContents/GetContentDetailOutput.cs new file mode 100644 index 00000000..ea58971c --- /dev/null +++ b/src/SJZY.Track.Application.Contract/Dtos/TrackContents/GetContentDetailOutput.cs @@ -0,0 +1,192 @@ +namespace SJZY.Track.Application.Contract.Dtos.TrackContents; + +public class GetContentDetailOutput +{ + /// + /// 子系统 + /// + public int SubSystemId { get; set; } + + /// + /// 订单Id + /// + public int OrderId { get; set; } + + /// + /// 订单号 + /// + public string OrderNo { get; set; } = null!; + + /// + /// 索引名称 + /// + public string IndexName { get; set; } = null!; + + /// + /// 订单类型(主数据枚举TrackOrderType) + /// + public int OrderType { get; set; } + + /// + /// 轨迹状态 + /// + public string TrackStatus { get; set; } + + /// + /// 轨迹状态code + /// + public string TrackStatusCode { get; set; } + + /// + /// 轨迹内容代码 + /// + public string TrackCode { get; set; } + + /// + /// 轨迹内容 + /// + public string TrackContent { get; set; } + + /// + /// 轨迹内容英文 + /// + public string TrackEnContent { get; set; } + + /// + /// 服务商code + /// + public string ServiceProviderCode { get; set; } + + /// + /// 原轨迹内容 + /// + public string? OriginTrackContent { get; set; } + + /// + /// 原轨迹报文hash(刷新轨迹重复性校验使用) + /// + public string OriginTrackDataHash { get; set; } = null!; + + /// + /// 轨迹发生地 + /// + public string TrackPlace { get; set; } + + /// + /// 轨迹发生时间 + /// + public DateTime TrackTime { get; set; } + + /// + /// 轨迹发生时区 + /// + public float TrackTimeZone { get; set; } + + /// + /// 转化后的轨迹发生时间 + /// + public DateTime ZeroTrackTime { get; set; } + + /// + /// 创建人 + /// + public string CreateUser { get; set; } + + /// + /// 创建时间 + /// + public DateTime CreateTime { get; set; } + + /// + /// 修改人 + /// + public string UpdateUser { get; set; } + + /// + /// 修改时间 + /// + public DateTime? UpdateTime { get; set; } + + /// + /// 客户是否可见 + /// + public bool IsVisibility { get; set; } + + /// + /// 数据来源:1外部服务商创建,2内部系统创建,3人工创建 + /// + public int Source { get; set; } + + /// + /// 备注 + /// + public string? Remarks { get; set; } + + /// + /// 附件集合 + /// + public List? Files { get; set; } + + /// + /// 轨迹发生地(城市) + /// + public string? TrackPlaceCity { get; set; } + + /// + /// 轨迹发生地(城市)Id + /// + public int? TrackPlaceCityId { get; set; } + + /// + /// 轨迹发生地(省/州) + /// + public string? TrackPlaceProvince { get; set; } + + /// + ///轨迹发生地(省/州)Id + /// + public int? TrackPlaceProvinceId { get; set; } + + /// + /// 轨迹发生地(国家/地区) + /// + public string? TrackPlaceNation { get; set; } + + /// + /// 轨迹发生地(国家/地区)Id + /// + public int? TrackPlaceNationId { get; set; } + + /// + /// 轨迹发生地邮编 + /// + public string? TrackPlacePostcode { get; set; } + + /// + /// 预计签收时间 + /// + public DateTime? EstimatedDeliveryDate { get; set; } + + /// + /// 签收地时区 + /// + public float? DestinationTimeZone { get; set; } +} + +public class FileItem +{ + /// + /// 文件osskey + /// + public string OssKey { get; set; } + + /// + /// 文件名称 + /// + public string FileName { get; set; } + + /// + /// 路径 + /// + public string Url { get; set; } +} diff --git a/src/SJZY.Track.Application/AutoMapper/TrackContentAutoMapperProfile.cs b/src/SJZY.Track.Application/AutoMapper/TrackContentAutoMapperProfile.cs index 862447be..a161314e 100644 --- a/src/SJZY.Track.Application/AutoMapper/TrackContentAutoMapperProfile.cs +++ b/src/SJZY.Track.Application/AutoMapper/TrackContentAutoMapperProfile.cs @@ -1,6 +1,7 @@ using AutoMapper; using SJZY.Track.Application.Contract.Dtos.TrackContents; using SJZY.Track.Domain.Aggregates.TrackContentAggregate; +using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate; using SJZY.Track.Domain.Dtos.TrackContents; namespace SJZY.Track.Application.AutoMapper; @@ -16,5 +17,9 @@ public class TrackContentAutoMapperProfile : Profile CreateMap, UnifyPageResultDto>( MemberList.None); CreateMap(MemberList.None); + + CreateMap(MemberList.None).ReverseMap(); + CreateMap< SJZY.Track.Domain.Aggregates.TrackDetailsAggregate.FileItem, SJZY.Track.Application.Contract.Dtos.TrackContents.FileItem>(MemberList.None).ReverseMap(); + } } diff --git a/src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs b/src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs index dea72486..c41d28c2 100644 --- a/src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs +++ b/src/SJZY.Track.Application/Services/ProvideServices/OrderService.cs @@ -57,7 +57,7 @@ public partial class OrderService : ApplicationService, IOrderService { OrderId = order.Id, OrderNo = input.OrderNo, - OptionType = OrderOperationType.修改订单.ToString(), + OptionType = OrderOperationType.修改订单.ToString(), Content = input.ToJson(), CreateUserId = currentUser.UserId, CreateUserName = currentUser.Name, @@ -76,6 +76,7 @@ public partial class OrderService : ApplicationService, IOrderService order.OrderFlights = ObjectMapper.Map, List>(input.FlightInfos); order.OrderPullStatus = BuiltOrderPullStatus(input.PullConfigInfos); order.OrderPlatformNumbers = BuiltOrderPlatformNumbers(input.PullConfigInfos); + order.TemplateCodes = string.Join(',', input.TemplateCodes); var orderId = await _orderRepository.CreateOrderAsync(order); diff --git a/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs b/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs index cec5feae..ab931373 100644 --- a/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs +++ b/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs @@ -108,7 +108,7 @@ public partial class TrackService : ApplicationService, ITrackService throw new BusinessException(message: $"订单:{input.OrderNo},轨迹代码:{input.TrackCode}存在多条记录,不允许修改"); } - var userInfo = await _requestCurrentUserService.Service.GetCurrentUserBasicInfoAsync(); + var userInfo = await _requestCurrentUserService.Service.GetCurrentUserBasicInfoAsync(input.OptionUserId); if (userInfo.Code != GlobalConst.SuccessCode || userInfo.Data is null) { //TODO: log || ex diff --git a/src/SJZY.Track.Application/Services/TrackContents/TrackContentService.cs b/src/SJZY.Track.Application/Services/TrackContents/TrackContentService.cs index c7c69e68..996b2f57 100644 --- a/src/SJZY.Track.Application/Services/TrackContents/TrackContentService.cs +++ b/src/SJZY.Track.Application/Services/TrackContents/TrackContentService.cs @@ -2,6 +2,7 @@ using System.Linq.Expressions; using Microsoft.Extensions.Localization; using SJZY.Expand.ABP.Core.Localization; using SJZY.Expand.ABP.Core.PublicMethords; +using SJZY.Expand.AliyunOSS; using SJZY.Track.Application.Contract.Dtos.ProvideServices; using SJZY.Track.Application.Contract.Dtos.TrackContents; using SJZY.Track.Application.Localization; @@ -10,7 +11,9 @@ using SJZY.Track.Domain.Aggregates.TrackContentAggregate; using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate; using SJZY.Track.Domain.Aggregates.TrackFlagAggregate; using SJZY.Track.Domain.Aggregates.TrackStatusAggregate; +using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate; using SJZY.Track.Domain.Dtos.TrackContents; +using SJZY.Track.Domain.Dtos.TrackTemplate; using SJZY.Track.Domain.Queries; namespace SJZY.Track.Application.Services.TrackContents; @@ -24,6 +27,7 @@ public class TrackContentService : ApplicationService { private readonly IStringLocalizer _stringLocalizer; private readonly ITrackContentRepository _trackContentRepository; + private readonly ITrackTemplateRepository _trackTemplateRepository; private readonly IBasicQuery _trackFlagBasicQuery; private readonly IBasicQuery _trackStatusBasicQuery; private readonly IOrderRepository _orderRepository; @@ -35,7 +39,8 @@ public class TrackContentService : ApplicationService IBasicQuery trackStatusBasicQuery, IBasicQuery trackFlagBasicQuery, IOrderRepository orderRepository, - ITrackDetailsEsRepository trackDetailsEsRepository) + ITrackDetailsEsRepository trackDetailsEsRepository, + ITrackTemplateRepository trackTemplateRepository) { _stringLocalizer = stringLocalizer; _trackContentRepository = trackContentRepository; @@ -43,6 +48,7 @@ public class TrackContentService : ApplicationService _trackFlagBasicQuery = trackFlagBasicQuery; _orderRepository = orderRepository; _trackDetailsEsRepository = trackDetailsEsRepository; + _trackTemplateRepository = trackTemplateRepository; } /// @@ -220,6 +226,50 @@ public class TrackContentService : ApplicationService return res; } + /// + /// 根据子系统id、单号、订单类型、轨迹发生时间、轨迹code获取轨迹内容 + /// + /// + /// + [HttpPost("GetContentDetail")] + public async Task> GetContentDetail([FromBody] GetContentDetailInput input) + { + if (input.SystemId <= 0) + return new UnifyResultDto(false, "子系统Id必须大于等于0"); + + if (string.IsNullOrEmpty(input.TrackCode)) + return new UnifyResultDto(false, "轨迹内容code不能为空"); + + if (string.IsNullOrEmpty(input.OrderNumber)) + return new UnifyResultDto(false, "订单code不能为空"); + + if (input.OrderType <= 0) + return new UnifyResultDto(false, "订单类型不能为空"); + + if (input.TrackTime == default) + return new UnifyResultDto(false, "轨迹发生时间不能为空"); + + var content = await _trackDetailsEsRepository.GetDetailAsync(input.OrderNumber, input.TrackCode, input.OrderType, input.SystemId, input.TrackTime); + if (content == default) + return new UnifyResultDto(false, "在当前子系统中未找到指定code的轨迹内容"); + + var res = new UnifyResultDto(true) + { + Data = ObjectMapper.Map(content) + }; + + + if (res.Data != default && res.Data.Files.Any()) + { + foreach (var item in res.Data.Files) + { + item.Url = OSSHelper.GetUrlByKey(item.OssKey); + } + } + + return res; + } + /// /// 创建轨迹时获取可用的轨迹内容 /// @@ -235,18 +285,25 @@ public class TrackContentService : ApplicationService return new UnifyResultDto>(false, "单号不能为空!"); //获取当前订单下已有的轨迹内容 - var orderId = await _orderRepository.GetFirstAsync(x => x.OrderNo == input.OrderNo && x.SubSystemId == input.SystemId, x => x.Id); - if (orderId == default) + var order = await _orderRepository.GetFirstAsync(x => x.OrderNo == input.OrderNo && x.SubSystemId == input.SystemId); + if (order == default) throw new BusinessException(message: "订单不存在!"); //获取轨迹详情 - var trackDetails = await _trackDetailsEsRepository.GetListAsync(orderId); + var trackDetails = await _trackDetailsEsRepository.GetListAsync(order.Id); //获取当前子系统下所有的轨迹内容 var contentList = await _trackContentRepository.GetListBySystemIdAsync(input.SystemId); if (contentList == null) throw new BusinessException(message: "当前子系统下未找到任何可用的轨迹内容!"); + //如果订单给了获取模板code,则进一步根据模板code进行过滤 + if (!string.IsNullOrEmpty(order.TemplateCodes)) + { + var currentCodes = order.TemplateCodes.Split(","); + var template = await _trackTemplateRepository.GetContentByTemplateCodes(currentCodes, input.SystemId); + contentList = contentList.Where(m => template.Contains(m.Code)).ToList(); + } var res = new UnifyResultDto>(true) { diff --git a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderEntity.cs b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderEntity.cs index b2e3a5ba..762c1324 100644 --- a/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderEntity.cs +++ b/src/SJZY.Track.Domain/Aggregates/OrderAggregate/OrderEntity.cs @@ -180,6 +180,12 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot [SugarColumn(ColumnName = "DestinationTimeZone")] public float? DestinationTimeZone { get; set; } + /// + /// 模板code + /// + [SugarColumn(ColumnName = "TemplateCodes")] + public string? TemplateCodes { get; set; } + [SugarColumn(IsIgnore = true)] public List OrderFlights { get; set; } [SugarColumn(IsIgnore = true)] public List OrderPullStatus { get; set; } diff --git a/src/SJZY.Track.Domain/Aggregates/TrackDetailsAggregate/ITrackDetailsEsRepository.cs b/src/SJZY.Track.Domain/Aggregates/TrackDetailsAggregate/ITrackDetailsEsRepository.cs index a8da5185..482d7142 100644 --- a/src/SJZY.Track.Domain/Aggregates/TrackDetailsAggregate/ITrackDetailsEsRepository.cs +++ b/src/SJZY.Track.Domain/Aggregates/TrackDetailsAggregate/ITrackDetailsEsRepository.cs @@ -29,4 +29,5 @@ public interface ITrackDetailsEsRepository : IElasticsearchClientService> GetDataByIds(string[] ids); + Task GetDetailAsync(string orderNo, string trackCode, int orderType, int subSystemId, DateTime trackTime); } diff --git a/src/SJZY.Track.Domain/Aggregates/TrackTemplateAggregate/ITrackTemplateRepository.cs b/src/SJZY.Track.Domain/Aggregates/TrackTemplateAggregate/ITrackTemplateRepository.cs index 8a104c3c..db202083 100644 --- a/src/SJZY.Track.Domain/Aggregates/TrackTemplateAggregate/ITrackTemplateRepository.cs +++ b/src/SJZY.Track.Domain/Aggregates/TrackTemplateAggregate/ITrackTemplateRepository.cs @@ -45,4 +45,5 @@ public interface ITrackTemplateRepository : IBasicRepository> whereExpression); Task> GetTrackTemplateListAsync(GetTrackTemplateListInputVo input); + Task> GetContentByTemplateCodes(string[] codes, int systemId); } diff --git a/src/SJZY.Track.Repository/Repositories/TrackDetailsEsRepository.cs b/src/SJZY.Track.Repository/Repositories/TrackDetailsEsRepository.cs index 0fee4fc6..cb62b1b1 100644 --- a/src/SJZY.Track.Repository/Repositories/TrackDetailsEsRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/TrackDetailsEsRepository.cs @@ -440,4 +440,39 @@ public class TrackDetailsEsRepository : ElasticSearchContextAbstract GetDetailAsync(string orderNo, string trackCode, int orderType, int subSystemId, DateTime trackTime) + { + var res = await Context.SearchAsync(s => s + .Index("sjzy_track_details") + .Query(q => q + .Bool(b => b + .Must(mu => mu + .Terms(t => t + .Field(f => f.OrderNo.Suffix("keyword")) + .Terms(orderNo)), + mu => mu + .Terms(t => t + .Field(f => f.TrackCode.Suffix("keyword")) + .Terms(trackCode)), + mu => mu + .Terms(t => t + .Field(f => f.OrderType) + .Terms(orderType)), + mu => mu + .Terms(t => t + .Field(f => f.SubSystemId) + .Terms(subSystemId)), + mu => mu + .Terms(t => t + .Field(f => f.TrackTime) + .Terms(trackTime)) // 注意:这里你重复了OrderType的查询,你可能需要移除重复的查询 + ) + ) + ) + ); + + return res.Documents.FirstOrDefault(); + } + } diff --git a/src/SJZY.Track.Repository/Repositories/TrackTemplateRepository.cs b/src/SJZY.Track.Repository/Repositories/TrackTemplateRepository.cs index be08e964..9f28d8fc 100644 --- a/src/SJZY.Track.Repository/Repositories/TrackTemplateRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/TrackTemplateRepository.cs @@ -8,6 +8,7 @@ using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate; using SJZY.Track.Domain.Dtos.TrackTemplate; using SJZY.Track.Domain.Enums; using SJZY.Track.Domain.VEntities; +using SJZY.Expand.ABP.Core.SqlSugar.Tools; namespace SJZY.Track.Repository.Repositories; @@ -225,4 +226,26 @@ public class TrackTemplateRepository : BasicRepository, ITr return templates; } + + public async Task> GetContentByTemplateCodes(string[] codes, int systemId) + { + + var sql = @$" + select + distinct + c.Code + from t_track_template a + left join t_track_template_content b on a.id = b.TrackTemplateId and b.IsDeleted = 0 + left join t_track_content c on b.TrackContentId = c.Id and c.IsDeleted = 0 + where + a.SubSystemId = {systemId} + and a.Code in (@codes) + and a.IsDeleted = 0 + "; + + + var list = Context.Ado.SqlQuery(sql, new {codes = codes}).ToList(); + + return list; + } }