Merge pull request 'S01-轨迹中台' (#9) from S01-轨迹中台 into dev

Reviewed-on: http://192.168.80.50:3000/Dotnet/SJZY.Track.Api/pulls/9
This commit is contained in:
liuwenxiang 2024-03-01 22:12:14 +08:00
commit 7b9fe50794
7 changed files with 71 additions and 11 deletions

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Localization;
using SJZY.Expand.ABP.Core.Common.Dto;
using SJZY.Expand.ABP.Core.Localization;
using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.Track.Application.Contract.Dtos.TrackContents;
using SJZY.Track.Application.Contract.Dtos.TrackPull;
using SJZY.Track.Application.Localization;
@ -122,8 +123,33 @@ namespace SJZY.Track.Application.Services.TrackContents
//更新的时候需要覆盖内容映射轨迹代码
var templateEntity = await _trackContentRepository.GetFirstAsync(a => a.Id == input.Id);
ObjectMapper.Map(input, templateEntity);
var isTrue = await _trackContentRepository.UpdateAsync(templateEntity);
bool isTrue = false;
using (var ts = TransactionScopeHelper.Create())
{
// 如果轨迹内容的子系统和code发生变化,同步到轨迹映射表
if (templateEntity.SubSystemId != input.SubSystemId || templateEntity.Code != input.Code)
{
await _trackContentRepository.UpdateMapAsync(x => new TrackContentMapEntity
{
SubSystemId = input.SubSystemId,
TrackContentCode = input.Code
}, x => x.TrackContentId == input.Id);
await _trackContentRepository.UpdateMapAsync(x => new TrackContentMapEntity
{
MapSubSystemId = input.SubSystemId,
MapTrackContentCode = input.Code
}, x => x.MapTrackContentId == input.Id);
}
ObjectMapper.Map(input, templateEntity);
isTrue = await _trackContentRepository.UpdateAsync(templateEntity);
ts.Complete();
}
return new UnifyResultDto("200", "修改成功", isTrue);
}

View File

@ -1,8 +1,10 @@
using Microsoft.Extensions.Localization;
using SJZY.Expand.ABP.Core;
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.DemoAggregate;
using SJZY.Track.Domain.Aggregates.TrackPullAggregate;
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate;
@ -66,7 +68,7 @@ public class TrackPushService : ApplicationService, ITransientDependency
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("GetDetail")]
public async Task<GetTrackPushConfigDetailOutputVO?> GetDetailAsync(int id)
public async Task<GetTrackPushConfigDetailOutputVO> GetDetailAsync(int id)
{
var res = await _trackPushConfigRepository.GetDetailAsync(id);
if (res is null) return null;
@ -126,6 +128,8 @@ public class TrackPushService : ApplicationService, ITransientDependency
trackPushParamsEntity.PullOrPushConfigId = id;
await _trackPullConfigRepository.InsertParamsAsync(trackPushParamsEntity);
if (input.IsAutoPush) await RedisHelper.Client.SAddAsync(GlobalConst.AutoPushRosterRedisKey, input.CustomId);
ts.Complete();
}
}
@ -135,6 +139,8 @@ public class TrackPushService : ApplicationService, ITransientDependency
{
var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]);
int oldCustomId = oldTrackPushEntity.CustomId;
var oldTrackPushParamsEntity =
await _trackPullConfigRepository.GetParamsSingleAsync(x =>
x.PullOrPushConfigId == input.Id && x.IsPush);
@ -147,22 +153,30 @@ public class TrackPushService : ApplicationService, ITransientDependency
await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity);
await _trackPullConfigRepository.UpdateParamsAsync(oldTrackPushParamsEntity);
await RedisHelper.Client.SRemAsync(GlobalConst.AutoPushRosterRedisKey, oldCustomId);
if (input.IsAutoPush) await RedisHelper.Client.SAddAsync(GlobalConst.AutoPushRosterRedisKey, input.CustomId);
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);
var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? throw new BusinessException(message: _stringLocalizer["NotFindData"]);
ts.Complete();
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);
await RedisHelper.Client.SRemAsync(GlobalConst.AutoPushRosterRedisKey, oldTrackPushEntity.CustomId);
ts.Complete();
}
}
break;
default:

View File

@ -21,4 +21,6 @@ public interface ITrackContentRepository : IBasicRepository<TrackContentEntity>
Task<bool> UpdateMapAsync(TrackContentMapEntity updateObj);
Task<bool> SoftDeleteMapAsync(Expression<Func<TrackContentMapEntity, bool>> whereExpression);
Task<bool> UpdateMapAsync(Expression<Func<TrackContentMapEntity, TrackContentMapEntity>> columns, Expression<Func<TrackContentMapEntity, bool>> whereExpression);
}

View File

@ -91,6 +91,11 @@ public class GetTrackPushConfigDetailOutputVO
/// </summary>
public string TrackTemplateId { get; set; }
/// <summary>
/// 轨迹模板ids
/// </summary>
public List<int> TrackTemplateIds { get; set; }
/// <summary>
/// 推送轨迹发生时间
/// </summary>

View File

@ -11,4 +11,9 @@ public class GlobalConst
/// 轨迹新增/更新cap订阅名称
/// </summary>
public const string TrackUpsertSubscribe = "SJZY.Track.Upsert";
/// <summary>
/// 自动推送名单RedisKey
/// </summary>
public const string AutoPushRosterRedisKey = "AutoPushRoster";
}

View File

@ -3,6 +3,7 @@ using SJZY.Track.Domain.Aggregates.TrackFlagAggregate;
using SJZY.Track.Domain.Aggregates.TrackStatusAggregate;
using SJZY.Track.Domain.Dtos.TrackContents;
using SJZY.Track.Domain.VEntities;
using System.Linq;
using System.Linq.Expressions;
namespace SJZY.Track.Repository.Repositories;
@ -167,4 +168,10 @@ public class TrackContentRepository : BasicRepository<TrackContentEntity>, ITrac
.SetColumns(nameof(ISoftDeleteBasicEntity.IsDeleted), true)
.ExecuteCommandHasChangeAsync();
}
public async Task<bool> UpdateMapAsync(Expression<Func<TrackContentMapEntity, TrackContentMapEntity>> columns, Expression<Func<TrackContentMapEntity, bool>> whereExpression)
{
return await Context.Updateable<TrackContentMapEntity>().SetColumns(columns).Where(whereExpression)
.ExecuteCommandAsync() > 0;
}
}

View File

@ -68,6 +68,7 @@ public class TrackPushConfigRepository : BasicRepository<TrackPushConfigEntity>,
CustomName = externalSubject.Abbreviation,
ServiceProvider = service.Name,
}, true)
.Mapper(x => { x.TrackTemplateIds = x.TrackTemplateId.Split(',').Select(int.Parse).ToList(); })
.SingleAsync();
}