feat: 限制只能输入英文和英文符号
This commit is contained in:
parent
f9ac2af1ef
commit
8a2fb92900
24
src/SJZY.Track.Application/Helpers/StringHelper.cs
Normal file
24
src/SJZY.Track.Application/Helpers/StringHelper.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SJZY.Track.Application.Helpers
|
||||
{
|
||||
public class StringHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 只能输入英文字符和键盘上常用的符号
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsValidEnglishString(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Regular expression to match only English letters and specified symbols
|
||||
var regex = new Regex(@"^[a-zA-Z\(\)@!#$%^&*_\-+=;:""'/><,.\s]+$");
|
||||
return regex.IsMatch(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,5 @@
|
||||
using SJZY.Expand.ABP.Core;
|
||||
using SJZY.Track.Application.Contract.Services;
|
||||
using SJZY.Track.Domain.Aggregates.KPIAreaAggregate;
|
||||
using SJZY.Track.Domain.Consts;
|
||||
using SJZY.Track.Domain.Dtos.Forewarning;
|
||||
|
||||
namespace SJZY.Track.Application.Services.ForewarningServices;
|
||||
@ -10,8 +8,8 @@ namespace SJZY.Track.Application.Services.ForewarningServices;
|
||||
[Route("/ForewarningService")]
|
||||
public class KpiAreaService : ApplicationService
|
||||
{
|
||||
private readonly IKpiAreaRepository _ruleAreaRepository;
|
||||
private readonly IForewarningCacheService _forewarningCacheService;
|
||||
private readonly IKpiAreaRepository _ruleAreaRepository;
|
||||
|
||||
public KpiAreaService(IKpiAreaRepository ruleAreaRepository, IForewarningCacheService forewarningCacheService)
|
||||
{
|
||||
@ -28,6 +26,12 @@ public class KpiAreaService : ApplicationService
|
||||
public async ValueTask<UnifyResultDto> CreateKpiArea(CreateRuleAreaRequest input)
|
||||
{
|
||||
var ruleAreaEntity = ObjectMapper.Map<CreateRuleAreaRequest, RuleAreaEntity>(input);
|
||||
var hasSameName = await _ruleAreaRepository.IsAnyAsync(val => val.SubSystemId == input.SystemId && val.Name == input.Name);
|
||||
if (hasSameName)
|
||||
{
|
||||
return new UnifyResultDto(false, "分区名称重复,请重新修改提交");
|
||||
}
|
||||
|
||||
var areaId = await _ruleAreaRepository.CreateAreaAsync(ruleAreaEntity);
|
||||
return new UnifyResultDto(true, areaId, "创建成功");
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using SJZY.Track.Application.Contract.Dtos.TrackNode;
|
||||
using SJZY.Track.Application.Contract.Dtos.TrackStatus;
|
||||
using SJZY.Track.Application.Helpers;
|
||||
using SJZY.Track.Domain.Aggregates.TrackNodeAggregate;
|
||||
using SJZY.Track.Domain.Aggregates.TrackStatusAggregate;
|
||||
using SJZY.Track.Domain.Dtos.TrackNode;
|
||||
@ -13,9 +14,9 @@ namespace SJZY.Track.Application.Services.TrackNode
|
||||
[ApiExplorerSettings(GroupName = "轨迹节点")]
|
||||
[Route("/Track/Node")]
|
||||
public class TrackNodeService : ApplicationService, ITransientDependency
|
||||
{
|
||||
private readonly ITrackStatusRepository _trackStatusRepository;
|
||||
{
|
||||
private readonly ITrackNodeRepository _trackNodeRepository;
|
||||
private readonly ITrackStatusRepository _trackStatusRepository;
|
||||
|
||||
public TrackNodeService(
|
||||
ITrackNodeRepository trackNodeRepository, ITrackStatusRepository trackStatusRepository)
|
||||
@ -39,7 +40,7 @@ namespace SJZY.Track.Application.Services.TrackNode
|
||||
_ => throw new BusinessException(message: "当前操作动作不合法")
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取分页轨迹节点
|
||||
/// </summary>
|
||||
@ -52,7 +53,7 @@ namespace SJZY.Track.Application.Services.TrackNode
|
||||
var resultDto = await _trackNodeRepository.GetPageList(queryParam);
|
||||
return resultDto;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取详情
|
||||
/// </summary>
|
||||
@ -62,9 +63,9 @@ namespace SJZY.Track.Application.Services.TrackNode
|
||||
public async Task<UnifyResultDto> GetDetail(int nodeid)
|
||||
{
|
||||
var resultDto = await _trackNodeRepository.GetDetail(nodeid);
|
||||
return new UnifyResultDto(true,resultDto);
|
||||
return new UnifyResultDto(true, resultDto);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取分页轨迹字典,下拉框用的
|
||||
/// </summary>
|
||||
@ -83,13 +84,16 @@ namespace SJZY.Track.Application.Services.TrackNode
|
||||
private async Task<UnifyResultDto> AddAsync(EditTrackNodeInput input)
|
||||
{
|
||||
#region 业务校验
|
||||
if(string.IsNullOrEmpty(input.NodeName)|| string.IsNullOrEmpty(input.NodeEnName) || !input.SubSystemId.HasValue)
|
||||
|
||||
if (string.IsNullOrEmpty(input.NodeName) || string.IsNullOrEmpty(input.NodeEnName) ||
|
||||
!input.SubSystemId.HasValue)
|
||||
{
|
||||
return new UnifyResultDto("200", "NodeName,NodeEnName,SubSystemId 必填", false);
|
||||
}
|
||||
|
||||
|
||||
var trackNodesEntitys = await _trackNodeRepository.GetListAsync(a =>
|
||||
a.SubSystemId == input.SubSystemId && (a.NodeName == input.NodeName || a.NodeEnName == input.NodeEnName));
|
||||
a.SubSystemId == input.SubSystemId &&
|
||||
(a.NodeName == input.NodeName || a.NodeEnName == input.NodeEnName));
|
||||
if (trackNodesEntitys.Any())
|
||||
{
|
||||
var trackNodeName = trackNodesEntitys.FirstOrDefault(a => a.NodeName == input.NodeName);
|
||||
@ -97,14 +101,21 @@ namespace SJZY.Track.Application.Services.TrackNode
|
||||
{
|
||||
throw new BusinessException(message: "该子系统下节点名称已存在");
|
||||
}
|
||||
|
||||
var trackNodeEnName = trackNodesEntitys.FirstOrDefault(a => a.NodeEnName == input.NodeEnName);
|
||||
if (trackNodeEnName != null)
|
||||
{
|
||||
throw new BusinessException(message: "该子系统下节点英文名称已存在");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
if (!StringHelper.IsValidEnglishString(input.NodeEnName))
|
||||
{
|
||||
return new UnifyResultDto("200", "节点英文名称必须是英文和常用英文符号", false);
|
||||
}
|
||||
|
||||
var entity = ObjectMapper.Map<EditTrackNodeInput, TrackNodeEntity>(input);
|
||||
var isTrue = await _trackNodeRepository.InsertAsync(entity);
|
||||
|
||||
@ -114,11 +125,12 @@ namespace SJZY.Track.Application.Services.TrackNode
|
||||
private async Task<UnifyResultDto> UpdateAsync(EditTrackNodeInput input)
|
||||
{
|
||||
#region 业务校验
|
||||
if(string.IsNullOrEmpty(input.NodeName)|| string.IsNullOrEmpty(input.NodeEnName) )
|
||||
|
||||
if (string.IsNullOrEmpty(input.NodeName) || string.IsNullOrEmpty(input.NodeEnName))
|
||||
{
|
||||
return new UnifyResultDto("200", "NodeName,NodeEnName 必填", false);
|
||||
}
|
||||
|
||||
|
||||
var trackNodesEntitys = await _trackNodeRepository.GetFirstAsync(a => a.Id == input.Id);
|
||||
if (trackNodesEntitys == null)
|
||||
{
|
||||
@ -136,19 +148,21 @@ namespace SJZY.Track.Application.Services.TrackNode
|
||||
|
||||
private async Task<UnifyResultDto> DeleteAsync(EditTrackNodeInput input)
|
||||
{
|
||||
if(input.Id <=0 || !input.SubSystemId.HasValue)
|
||||
if (input.Id <= 0 || !input.SubSystemId.HasValue)
|
||||
{
|
||||
return new UnifyResultDto("200", "SubSystemId 必填", false);
|
||||
}
|
||||
|
||||
var trackStatus = await _trackStatusRepository.GetFirstAsync(val => val.Node == input.Id && val.SubSystemId == input.SubSystemId);
|
||||
if(trackStatus!=null)
|
||||
|
||||
var trackStatus =
|
||||
await _trackStatusRepository.GetFirstAsync(val =>
|
||||
val.Node == input.Id && val.SubSystemId == input.SubSystemId);
|
||||
if (trackStatus != null)
|
||||
{
|
||||
return new UnifyResultDto("200", "删除失败,该节点已被使用", false);
|
||||
}
|
||||
|
||||
|
||||
var rows = await _trackNodeRepository.DeleteById(input.Id);
|
||||
return new UnifyResultDto("200", "删除成功", rows>0);
|
||||
return new UnifyResultDto("200", "删除成功", rows > 0);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Loading…
Reference in New Issue
Block a user