diff --git a/src/SJZY.Track.Application/AutoMapper/TrackContentAutoMapperProfile.cs b/src/SJZY.Track.Application/AutoMapper/TrackContentAutoMapperProfile.cs new file mode 100644 index 00000000..cf4453f8 --- /dev/null +++ b/src/SJZY.Track.Application/AutoMapper/TrackContentAutoMapperProfile.cs @@ -0,0 +1,27 @@ +using AutoMapper; +using AutoMapper.Internal.Mappers; +using SJZY.Track.Application.Dtos.TrackContents; +using SJZY.Track.Application.Dtos.TrackTemplates; +using SJZY.Track.Domain.Aggregates.TrackContentAggregate; +using SJZY.Track.Domain.Dtos.TrackContents; +using SJZY.Track.Domain.Dtos.TrackTemplate; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.ObjectMapping; + +namespace SJZY.Track.Application.AutoMapper +{ + public class TrackContentAutoMapperProfile : Profile + { + public TrackContentAutoMapperProfile() + { + CreateMap(MemberList.None); + CreateMap(MemberList.None); + CreateMap(MemberList.None); + + } + } +} diff --git a/src/SJZY.Track.Application/Localization/Resources/en.json b/src/SJZY.Track.Application/Localization/Resources/en.json index 23d14ff9..3fd41b14 100644 --- a/src/SJZY.Track.Application/Localization/Resources/en.json +++ b/src/SJZY.Track.Application/Localization/Resources/en.json @@ -4,7 +4,8 @@ "NotNull1": "{0} is not null", "NotFindData": "No data found under the specified number", "ParameterDemo1": "{0} in {1} to do {2}", - "TemplateExist": "The template code already exists under the currently selected subsystem" + "TemplateExist": "The template code already exists under the currently selected subsystem", + "TrackContentExist": "The trace code or trace content or trace content in the current subsystem is repeated in English" } } \ No newline at end of file diff --git a/src/SJZY.Track.Application/Localization/Resources/zh.json b/src/SJZY.Track.Application/Localization/Resources/zh.json index 1bb47943..4692d323 100644 --- a/src/SJZY.Track.Application/Localization/Resources/zh.json +++ b/src/SJZY.Track.Application/Localization/Resources/zh.json @@ -4,6 +4,7 @@ "NotFindData": "未找到指定编号下的任何数据!", "ParameterDemo": "{0}在{1}地方做了{2}动作", "ParameterDemo1": "{0}在{1}地方做了{2}动作", - "TemplateExist": "模板代码已存在于当前选择的子系统下" + "TemplateExist": "模板代码已存在于当前选择的子系统下", + "TrackContentExist": "当前子系统下轨迹代码或轨迹内容或轨迹内容英文重复" } } \ No newline at end of file diff --git a/src/SJZY.Track.Application/Services/TrackContents/TrackContentService.cs b/src/SJZY.Track.Application/Services/TrackContents/TrackContentService.cs index 86116173..3245d2ce 100644 --- a/src/SJZY.Track.Application/Services/TrackContents/TrackContentService.cs +++ b/src/SJZY.Track.Application/Services/TrackContents/TrackContentService.cs @@ -1,6 +1,8 @@ using Microsoft.AspNetCore.Authorization; +using Microsoft.Extensions.Localization; using SJZY.Track.Application.Dtos.TrackContents; using SJZY.Track.Application.Dtos.TrackStatus; +using SJZY.Track.Application.Localization; using SJZY.Track.Domain.Aggregates.TrackContentAggregate; using SJZY.Track.Domain.Dtos.TrackContents; using SJZY.Track.Domain.Dtos.TrackStatus; @@ -20,12 +22,15 @@ namespace SJZY.Track.Application.Services.TrackContents [Route("/Track/Content")] public class TrackContentService : ApplicationService, ITransientDependency { + private readonly IStringLocalizer _stringLocalizer; private readonly ITrackContentRepository _trackContentRepository; public TrackContentService( + IStringLocalizer stringLocalizer, ITrackContentRepository trackContentRepository ) { + this._stringLocalizer=stringLocalizer; this._trackContentRepository=trackContentRepository; } @@ -83,6 +88,15 @@ namespace SJZY.Track.Application.Services.TrackContents #region 私有方法 private async Task AddAsync(EditTrackContentInput input) { + #region 业务逻辑校验 + var trackContentEntity = await _trackContentRepository.GetFirstAsync(a => a.SubSystemId==input.SubSystemId&&(a.Code==input.Code || + a.Content==input.Content || a.EnContent==input.EnContent)); + if (trackContentEntity != null) + { + throw new BusinessException(message: _stringLocalizer["TrackContentExist"]); + } + #endregion + var entity = ObjectMapper.Map(input); var isTrue = await _trackContentRepository.InsertAsync(entity); @@ -91,6 +105,15 @@ namespace SJZY.Track.Application.Services.TrackContents private async Task UpdateAsync(EditTrackContentInput input) { + #region 业务逻辑校验 + var trackContentEntity = await _trackContentRepository.GetFirstAsync(a => a.Id!=input.Id && a.SubSystemId==input.SubSystemId && (a.Code==input.Code || + a.Content==input.Content || a.EnContent==input.EnContent)); + if (trackContentEntity != null) + { + throw new BusinessException(message: _stringLocalizer["TrackContentExist"]); + } + #endregion + var templateEntity = await _trackContentRepository.GetFirstAsync(a => a.Id == input.Id); ObjectMapper.Map(input, templateEntity); var isTrue = await _trackContentRepository.UpdateAsync(templateEntity); diff --git a/src/SJZY.Track.Application/Validations/TrackContents/EditTrackContentInputValidation.cs b/src/SJZY.Track.Application/Validations/TrackContents/EditTrackContentInputValidation.cs new file mode 100644 index 00000000..75951dc5 --- /dev/null +++ b/src/SJZY.Track.Application/Validations/TrackContents/EditTrackContentInputValidation.cs @@ -0,0 +1,38 @@ +using FluentValidation; +using SJZY.Track.Application.Dtos.TrackContents; +using SJZY.Track.Application.Dtos.TrackTemplates; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SJZY.Track.Application.Validations.TrackContents +{ + public class EditTrackContentInputValidation : AbstractValidator, IValidationEnabled + { + public EditTrackContentInputValidation() + { + //条件分支 + When(x => x.Options == OptionType.修改 || x.Options == OptionType.删除, () => + { + RuleFor(x => x.Id).GreaterThan(0).WithMessage("修改或删除时Id必须大于0!"); + }); + + When(x => x.Options == OptionType.新增, () => + { + RuleFor(x => x.Id).Equal(0).WithMessage("新增时Id必须等于0!"); + }); + + When(x => x.Options == OptionType.修改 || x.Options == OptionType.新增, () => + { + RuleFor(x => x.SubSystemId).GreaterThan(0).WithMessage("子系统的id必须大于0!"); + RuleFor(x => x.TrackStatusId).GreaterThan(0).WithMessage("所属状态的id必须大于0!"); + RuleFor(x => x.Code).NotNull().WithMessage("轨迹代码必填!").NotEmpty().WithMessage("轨迹代码不能为空!"); + RuleFor(x => x.Content).NotNull().WithMessage("轨迹内容必填!").NotEmpty().WithMessage("轨迹内容不能为空!"); + RuleFor(x => x.EnContent).NotNull().WithMessage("轨迹内容英文必填!").NotEmpty().WithMessage("轨迹内容英文不能为空!"); + }); + } + + } +} diff --git a/src/SJZY.Track.Repository/TrackContentRepository.cs b/src/SJZY.Track.Repository/TrackContentRepository.cs index 1671ac80..32ebd92d 100644 --- a/src/SJZY.Track.Repository/TrackContentRepository.cs +++ b/src/SJZY.Track.Repository/TrackContentRepository.cs @@ -1,4 +1,5 @@ using SJZY.Track.Domain.Aggregates.TrackContentAggregate; +using SJZY.Track.Domain.Aggregates.TrackFlagAggregate; using SJZY.Track.Domain.Aggregates.TrackStatusAggregate; using SJZY.Track.Domain.Dtos.TrackContents; using SJZY.Track.Domain.Dtos.TrackStatus; @@ -22,20 +23,22 @@ public class TrackContentRepository : BasicRepository, ITrac public async Task GetDetailAsync(int id) { var detail = await Context.Queryable() - .LeftJoin((a, b) => a.SubSystemId == b.Id) - .Where((a, b) => a.Id == id) - .Select((a, b) => new GetTrackContentDetailVO + .LeftJoin((a, b) => a.TrackStatusId==b.Id) + .LeftJoin((a, b, c) => a.TrackFlagId==c.Id) + .LeftJoin((a, b, c, d) => a.SubSystemId == b.Id) + .Where((a, b, c, d) => a.Id == id) + .Select((a, b, c, d) => new GetTrackContentDetailVO { Id = a.Id, SubSystemId = a.SubSystemId, - SubSystem = b.CnName, + SubSystem = d.CnName, TrackStatusId=a.TrackStatusId, - TrackStatus= "", + TrackStatus= b.Status, Code = a.Code, Content = a.Content, EnContent = a.EnContent, TrackFlagId=a.TrackFlagId, - TrackFlag="" + TrackFlag=c.Name }) .FirstAsync(); return detail; @@ -50,28 +53,32 @@ public class TrackContentRepository : BasicRepository, ITrac { UnifyPageResultDto pagedList = new UnifyPageResultDto(); pagedList = await Context.Queryable() - .LeftJoin((a, b) => a.SubSystemId == b.Id) - .LeftJoin((a, b, c) => a.CreateUserId == c.Id) - .LeftJoin((a, b, c, d) => a.UpdateUserId == d.Id) - .WhereIF(input.SubSystemId > 0, (a, b, c, d) => a.SubSystemId == input.SubSystemId) + .LeftJoin((a, b) => a.TrackStatusId==b.Id) + .LeftJoin((a, b, c) => a.TrackFlagId==c.Id) + .LeftJoin((a, b, c, d) => a.SubSystemId == d.Id) + .LeftJoin((a, b, c, d, e) => a.CreateUserId == e.Id) + .LeftJoin((a, b, c, d, e, f) => a.UpdateUserId == f.Id) + .WhereIF(input.SubSystemId > 0, (a, b, c, d, e, f) => a.SubSystemId == input.SubSystemId) .WhereIF(!input.Keywords.IsNullOrWhiteSpace(), - (a, b, c, d) => a.Code.Contains(input.Keywords) + (a, b, c, d, e, f) => a.Code.Contains(input.Keywords) || a.Content.Contains(input.Keywords) + || a.EnContent.Contains(input.Keywords) ) - .Select((a, b, c, d) => new GetTrackContentListVO + .Select((a, b, c, d, e, f) => new GetTrackContentListVO { Id = a.Id, - SubSystem = b.CnName, + SubSystem = d.CnName, Code = a.Code, Content = a.Content, EnContent = a.EnContent, - TrackStatus= "", - Node = "", - TrackFlag= "", + TrackStatus= b.Status, + Node = SqlFunc.IF(b.Node == 1).Return("揽收").ElseIF(b.Node == 2).Return("干线").ElseIF(b.Node == 3).Return("清关") + .ElseIF(b.Node == 4).Return("中转").ElseIF(b.Node == 5).Return("派送") + .End(""), + TrackFlag= c.Name, CreateTime = a.CreateTime, - CreateUser = c.Name, + CreateUser = e.Name, UpdateTime = a.UpdateTime, - UpdateUser = d.Name, - + UpdateUser = f.Name }) .ToPagedListAsync(input.PageIndex, input.PageSize);