From 3505a4dbcc97195d92fa28b342caba48dee538e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9F=B3=E6=96=87=E7=BF=94?= <878130837@qq.com>
Date: Fri, 1 Mar 2024 17:07:11 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20=E8=BD=A8=E8=BF=B9?=
=?UTF-8?q?=E6=8E=A8=E9=80=81=E9=85=8D=E7=BD=AE=E7=BC=96=E8=BE=91=20?=
=?UTF-8?q?=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../TrackPush/EditTrackPushConfigInput.cs | 81 +++++++++++++
.../SJZY.Track.Application.Contract.csproj | 6 +-
.../AutoMapper/TrackPushAutoMapperProfile.cs | 8 ++
.../Services/TrackPush/TrackPushService.cs | 110 +++++++++++++++++-
.../ITrackPushConfigRepository.cs | 2 +
.../GetTrackPushConfigDetailOutputVO.cs | 2 +-
.../Repositories/TrackPushConfigRepository.cs | 9 ++
7 files changed, 211 insertions(+), 7 deletions(-)
create mode 100644 src/SJZY.Track.Application.Contract/Dtos/TrackPush/EditTrackPushConfigInput.cs
diff --git a/src/SJZY.Track.Application.Contract/Dtos/TrackPush/EditTrackPushConfigInput.cs b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/EditTrackPushConfigInput.cs
new file mode 100644
index 00000000..cf3cb8ee
--- /dev/null
+++ b/src/SJZY.Track.Application.Contract/Dtos/TrackPush/EditTrackPushConfigInput.cs
@@ -0,0 +1,81 @@
+namespace SJZY.Track.Application.Contract.Dtos.TrackPush;
+
+public class EditTrackPushConfigInput
+{
+ ///
+ /// 客户id
+ ///
+ public int CustomId { get; set; }
+
+ ///
+ /// 推送扩展字段
+ ///
+ public string ExpandFieldsName { get; set; }
+
+ public int? Id { get; set; }
+
+ ///
+ /// 是否自动推送
+ ///
+ public bool IsAutoPush { get; set; }
+
+ ///
+ /// 操作类型
+ ///
+ public OptionTypeNoNull Options { get; set; }
+
+ ///
+ /// 推送轨迹订单号
+ ///
+ public string OrderNoName { get; set; }
+
+ ///
+ /// 服务商id
+ ///
+ public int ServiceProviderId { get; set; }
+
+ ///
+ /// 子系统id
+ ///
+ public int SubSystemId { get; set; }
+
+ ///
+ /// 推送轨迹时区
+ ///
+ public string TackTimeZoneName { get; set; }
+
+ ///
+ /// 推送轨迹内容代码
+ ///
+ public string TrackContentCodeName { get; set; }
+
+ ///
+ /// 推送轨迹内容
+ ///
+ public string TrackContentName { get; set; }
+
+ ///
+ /// 推送轨迹内容英文
+ ///
+ public string TrackEnContentName { get; set; }
+
+ ///
+ /// 推送轨迹发生地
+ ///
+ public string TrackPlaceName { get; set; }
+
+ ///
+ /// 推送轨迹状态
+ ///
+ public string TrackStatusName { get; set; }
+
+ ///
+ /// 轨迹模板id
+ ///
+ public List TrackTemplateIds { get; set; }
+
+ ///
+ /// 推送轨迹发生时间
+ ///
+ public string TrackTimeName { get; set; }
+}
\ No newline at end of file
diff --git a/src/SJZY.Track.Application.Contract/SJZY.Track.Application.Contract.csproj b/src/SJZY.Track.Application.Contract/SJZY.Track.Application.Contract.csproj
index a7a570d0..de5d1421 100644
--- a/src/SJZY.Track.Application.Contract/SJZY.Track.Application.Contract.csproj
+++ b/src/SJZY.Track.Application.Contract/SJZY.Track.Application.Contract.csproj
@@ -1,14 +1,14 @@
-
+
net7.0
0.0.2
-
-
+
+
diff --git a/src/SJZY.Track.Application/AutoMapper/TrackPushAutoMapperProfile.cs b/src/SJZY.Track.Application/AutoMapper/TrackPushAutoMapperProfile.cs
index 420b0e23..351f5321 100644
--- a/src/SJZY.Track.Application/AutoMapper/TrackPushAutoMapperProfile.cs
+++ b/src/SJZY.Track.Application/AutoMapper/TrackPushAutoMapperProfile.cs
@@ -1,4 +1,8 @@
using AutoMapper;
+using SJZY.Track.Application.Contract.Dtos.TrackPush;
+using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
+using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
+using Volo.Abp.AutoMapper;
namespace SJZY.Track.Application.AutoMapper;
@@ -6,5 +10,9 @@ public class TrackPushAutoMapperProfile : Profile
{
public TrackPushAutoMapperProfile()
{
+ CreateMap(MemberList.None)
+ .ForMember(dest => dest.TrackTemplateId, opt => opt.MapFrom(source => string.Join(',', source.TrackTemplateIds)));
+ CreateMap(MemberList.None).Ignore(dest => dest.Id)
+ .ForMember(dest => dest.IsPush, opt => opt.MapFrom(source => true));
}
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
index a862e224..cd4567f6 100644
--- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
+++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushService.cs
@@ -1,8 +1,15 @@
using Microsoft.Extensions.Localization;
+using SJZY.Expand.ABP.Core.Localization;
+using SJZY.Expand.ABP.Core.PublicMethords;
+using SJZY.Track.Application.Contract.Dtos.TrackPush;
using SJZY.Track.Application.Localization;
+using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
+using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate;
using SJZY.Track.Domain.Dtos.Common;
using SJZY.Track.Domain.Dtos.TrackPush;
+using SqlSugar;
+using System.Linq.Expressions;
using Volo.Abp.DependencyInjection;
namespace SJZY.Track.Application.Services.TrackPush;
@@ -16,13 +23,19 @@ public class TrackPushService : ApplicationService, ITransientDependency
{
private readonly IStringLocalizer _stringLocalizer;
private readonly ITrackPushConfigRepository _trackPushConfigRepository;
+ private readonly ITrackTemplateRepository _trackTemplateRepository;
+ private readonly ITrackPullConfigRepository _trackPullConfigRepository;
public TrackPushService(
IStringLocalizer stringLocalizer,
- ITrackPushConfigRepository trackPushConfigRepository)
+ ITrackPushConfigRepository trackPushConfigRepository,
+ ITrackTemplateRepository trackTemplateRepository,
+ ITrackPullConfigRepository trackPullConfigRepository)
{
_stringLocalizer = stringLocalizer;
_trackPushConfigRepository = trackPushConfigRepository;
+ _trackTemplateRepository = trackTemplateRepository;
+ _trackPullConfigRepository = trackPullConfigRepository;
}
///
@@ -53,9 +66,18 @@ public class TrackPushService : ApplicationService, ITransientDependency
///
///
[HttpGet("GetDetail")]
- public async Task GetDetailAsync(int id)
+ public async Task GetDetailAsync(int id)
{
- return await _trackPushConfigRepository.GetDetailAsync(id);
+ var res = await _trackPushConfigRepository.GetDetailAsync(id);
+ if (res is null) return null;
+
+ List trackTemplateIds = res.TrackTemplateId.Split(',').Select(int.Parse).ToList();
+
+ var trackTemplateEntities = await _trackTemplateRepository.GetListAsync(x => trackTemplateIds.Contains(x.Id));
+
+ trackTemplateEntities.ForEach(item => { (res.TrackTemplate ??= new()).Add(new() { Value = item.Id, Key = item.Name }); });
+
+ return res;
}
///
@@ -68,4 +90,86 @@ public class TrackPushService : ApplicationService, ITransientDependency
{
return await _trackPushConfigRepository.GetContentDetailAsync(id);
}
+
+ ///
+ /// 轨迹推送配置编辑
+ ///
+ ///
+ ///
+ [HttpPost("Edit")]
+ public async Task EditAsync([FromBody] EditTrackPushConfigInput input)
+ {
+ if (input.Options != OptionTypeNoNull.删除)
+ {
+ Expression> isAnyExp = x =>
+ x.SubSystemId == input.SubSystemId && x.CustomId == input.CustomId && x.ServiceProviderId == input.ServiceProviderId;
+ if (input.Options == OptionTypeNoNull.修改) isAnyExp.And(x => x.Id != input.Id);
+
+ var trackTemplateIdExp = Expressionable.Create();
+ foreach (var trackTemplateId in input.TrackTemplateIds) { trackTemplateIdExp.Or(x => SqlFunc.SplitIn(x.TrackTemplateId, trackTemplateId.ToString())); }
+
+ if (await _trackPushConfigRepository.IsAnyAsync(isAnyExp.And(trackTemplateIdExp.ToExpression())))
+ throw new BusinessException(message: _stringLocalizer["IsTrackPushConfigAny"]);
+ }
+
+ switch (input.Options)
+ {
+ case OptionTypeNoNull.新增:
+ {
+ var trackPushEntity = ObjectMapper.Map(input);
+ var trackPushParamsEntity = ObjectMapper.Map(input);
+
+ using (var ts = TransactionScopeHelper.Create())
+ {
+ int id = await _trackPushConfigRepository.InsertReturnIdentityAsync(trackPushEntity);
+
+ trackPushParamsEntity.PullOrPushConfigId = id;
+ await _trackPullConfigRepository.InsertParamsAsync(trackPushParamsEntity);
+
+ ts.Complete();
+ }
+ }
+ break;
+
+ case OptionTypeNoNull.修改:
+ {
+ var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]);
+
+ var oldTrackPushParamsEntity =
+ await _trackPullConfigRepository.GetParamsSingleAsync(x =>
+ x.PullOrPushConfigId == input.Id && x.IsPush);
+
+ ObjectMapper.Map(input, oldTrackPushEntity);
+ ObjectMapper.Map(input, oldTrackPushParamsEntity);
+
+ using (var ts = TransactionScopeHelper.Create())
+ {
+ await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity);
+ await _trackPullConfigRepository.UpdateParamsAsync(oldTrackPushParamsEntity);
+
+ ts.Complete();
+ }
+ }
+ break;
+
+ case OptionTypeNoNull.删除:
+ using (var ts = TransactionScopeHelper.Create())
+ {
+ await _trackPushConfigRepository.SoftDeleteAsync(x => x.Id == input.Id);
+ await _trackPullConfigRepository.SoftDeleteParamsAsync(x =>
+ x.PullOrPushConfigId == input.Id && x.IsPush);
+ await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id);
+
+ ts.Complete();
+ }
+
+ break;
+
+ default:
+ throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum,
+ nameof(EditTrackPushConfigInput.Options)]);
+ }
+
+ return true;
+ }
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Domain/Aggregates/TrackPushAggregate/ITrackPushConfigRepository.cs b/src/SJZY.Track.Domain/Aggregates/TrackPushAggregate/ITrackPushConfigRepository.cs
index 39b19ad2..9c82ef1c 100644
--- a/src/SJZY.Track.Domain/Aggregates/TrackPushAggregate/ITrackPushConfigRepository.cs
+++ b/src/SJZY.Track.Domain/Aggregates/TrackPushAggregate/ITrackPushConfigRepository.cs
@@ -12,4 +12,6 @@ public interface ITrackPushConfigRepository : IBasicRepository GetDetailAsync(int id);
Task GetContentDetailAsync(int id);
+
+ Task SoftDeleteContentAsync(Expression> whereExpression);
}
\ No newline at end of file
diff --git a/src/SJZY.Track.Domain/Dtos/TrackPush/GetTrackPushConfigDetailOutputVO.cs b/src/SJZY.Track.Domain/Dtos/TrackPush/GetTrackPushConfigDetailOutputVO.cs
index 6e9cd961..900c74bc 100644
--- a/src/SJZY.Track.Domain/Dtos/TrackPush/GetTrackPushConfigDetailOutputVO.cs
+++ b/src/SJZY.Track.Domain/Dtos/TrackPush/GetTrackPushConfigDetailOutputVO.cs
@@ -89,7 +89,7 @@ public class GetTrackPushConfigDetailOutputVO
///
/// 轨迹模板id
///
- public int TrackTemplateId { get; set; }
+ public string TrackTemplateId { get; set; }
///
/// 推送轨迹发生时间
diff --git a/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs b/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs
index 999a2732..07cbedc7 100644
--- a/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs
+++ b/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs
@@ -6,6 +6,7 @@ using SJZY.Track.Domain.Dtos.Common;
using SJZY.Track.Domain.Dtos.TrackPush;
using SJZY.Track.Domain.VEntities;
using SJZY.Track.Repository.VData.Entitys;
+using System.Linq.Expressions;
namespace SJZY.Track.Repository.Repositories;
@@ -82,4 +83,12 @@ public class TrackPushConfigRepository : BasicRepository,
}, true)
.SingleAsync();
}
+
+ public async Task SoftDeleteContentAsync(Expression> whereExpression)
+ {
+ return await Context.Updateable()
+ .Where(whereExpression)
+ .SetColumns(nameof(ISoftDeleteBasicEntity.IsDeleted), true)
+ .ExecuteCommandHasChangeAsync();
+ }
}
\ No newline at end of file