fix: 增加校验外包工号输入
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Dlhis.Basic.Organization.Request;
|
using System.Text.RegularExpressions;
|
||||||
|
using Dlhis.Basic.Organization.Request;
|
||||||
using Dlhis.Basic.Organization.Response;
|
using Dlhis.Basic.Organization.Response;
|
||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Dlhis.Entity.Basic.Enums;
|
using Dlhis.Entity.Basic.Enums;
|
||||||
@@ -35,6 +36,7 @@ public class GainfoOutsourceService : IGainfoOutsourceService
|
|||||||
public async Task SaveAsync(GainfoOutsourceRequest request)
|
public async Task SaveAsync(GainfoOutsourceRequest request)
|
||||||
{
|
{
|
||||||
await CheckDuplicate(request);
|
await CheckDuplicate(request);
|
||||||
|
|
||||||
var sapCodeExists = await _dbContext.Queryable<GainfoEntity>()
|
var sapCodeExists = await _dbContext.Queryable<GainfoEntity>()
|
||||||
.Where(x => x.Code == request.ExternalInfo.SapCode)
|
.Where(x => x.Code == request.ExternalInfo.SapCode)
|
||||||
.AnyAsync();
|
.AnyAsync();
|
||||||
@@ -51,6 +53,12 @@ public class GainfoOutsourceService : IGainfoOutsourceService
|
|||||||
var entity = request.Adapt<GainfoEntity>();
|
var entity = request.Adapt<GainfoEntity>();
|
||||||
entity.No = Guid.NewGuid().ToString();
|
entity.No = Guid.NewGuid().ToString();
|
||||||
entity.Type = GainfoUserTypeEnumType.Outsource;
|
entity.Type = GainfoUserTypeEnumType.Outsource;
|
||||||
|
|
||||||
|
if (request.Code.IsPresent())
|
||||||
|
{
|
||||||
|
IsAlphanumeric(request.Code).ThrowIfFalse("工号只能包含字母和数字");
|
||||||
|
}
|
||||||
|
|
||||||
entity.Code = request.Code.IsPresent()
|
entity.Code = request.Code.IsPresent()
|
||||||
? request.Code
|
? request.Code
|
||||||
: await GetOutSourceCodeAsync();
|
: await GetOutSourceCodeAsync();
|
||||||
@@ -338,4 +346,13 @@ public class GainfoOutsourceService : IGainfoOutsourceService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsAlphanumeric(string input)
|
||||||
|
{
|
||||||
|
// 空字符串可根据需要决定是否允许,此处为 false
|
||||||
|
if (string.IsNullOrEmpty(input)) return false;
|
||||||
|
|
||||||
|
// ^ 表示开头,$ 表示结尾,确保整个字符串都由英文数字组成
|
||||||
|
return Regex.IsMatch(input, @"^[a-zA-Z0-9]+$");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user