查询语句优化
This commit is contained in:
parent
3efa40ce08
commit
2705da9b72
@ -184,12 +184,15 @@ public class AppUserService : BaseService<AppUserEntity>, ITransient
|
|||||||
// 身份证/户口本认证时检查身份证号是否重复
|
// 身份证/户口本认证时检查身份证号是否重复
|
||||||
if ((input.AuthType == 1 || input.AuthType == 3) && !string.IsNullOrWhiteSpace(input.IdCardNumber))
|
if ((input.AuthType == 1 || input.AuthType == 3) && !string.IsNullOrWhiteSpace(input.IdCardNumber))
|
||||||
{
|
{
|
||||||
var duplicateIdCard = await _appUserRep.AsQueryable()
|
var q1 = _appUserRep.AsQueryable()
|
||||||
.Where(x => x.IdCardNumber == input.IdCardNumber
|
.Where(x => x.IdCardNumber == input.IdCardNumber
|
||||||
&& x.PersonType == input.PersonType
|
&& x.PersonType == input.PersonType
|
||||||
&& !x.DeleteMark
|
&& !x.DeleteMark);
|
||||||
&& (!input.Id.HasValue || x.Id != input.Id.Value))
|
if (input.Id.HasValue)
|
||||||
.FirstAsync();
|
{
|
||||||
|
q1 = q1.Where(x => x.Id != input.Id.Value);
|
||||||
|
}
|
||||||
|
var duplicateIdCard = await q1.FirstAsync();
|
||||||
|
|
||||||
if (duplicateIdCard != null)
|
if (duplicateIdCard != null)
|
||||||
{
|
{
|
||||||
@ -200,12 +203,15 @@ public class AppUserService : BaseService<AppUserEntity>, ITransient
|
|||||||
// 护照认证时检查护照号是否重复
|
// 护照认证时检查护照号是否重复
|
||||||
if (input.AuthType == 2 && !string.IsNullOrWhiteSpace(input.PassportNumber))
|
if (input.AuthType == 2 && !string.IsNullOrWhiteSpace(input.PassportNumber))
|
||||||
{
|
{
|
||||||
var duplicatePassport = await _appUserRep.AsQueryable()
|
var q2 = _appUserRep.AsQueryable()
|
||||||
.Where(x => x.PassportNumber == input.PassportNumber
|
.Where(x => x.PassportNumber == input.PassportNumber
|
||||||
&& x.PersonType == input.PersonType
|
&& x.PersonType == input.PersonType
|
||||||
&& !x.DeleteMark
|
&& !x.DeleteMark);
|
||||||
&& (!input.Id.HasValue || x.Id != input.Id.Value))
|
if (input.Id.HasValue)
|
||||||
.FirstAsync();
|
{
|
||||||
|
q2 = q2.Where(x => x.Id != input.Id.Value);
|
||||||
|
}
|
||||||
|
var duplicatePassport = await q2.FirstAsync();
|
||||||
|
|
||||||
if (duplicatePassport != null)
|
if (duplicatePassport != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -175,8 +175,9 @@ public class MyController : IDynamicApiController
|
|||||||
if (string.IsNullOrEmpty(input.IdCardBackImageUrl)) throw Oops.Bah("身份证背面图片不能为空");
|
if (string.IsNullOrEmpty(input.IdCardBackImageUrl)) throw Oops.Bah("身份证背面图片不能为空");
|
||||||
|
|
||||||
// 身份证号查重
|
// 身份证号查重
|
||||||
var duplicateIdCard = await _appUserRepository.GetFirstAsync(u =>
|
var duplicateIdCard = await _appUserRepository.AsQueryable()
|
||||||
u.IdCardNumber == input.IdCardNumber && u.Id != userId && !u.DeleteMark);
|
.Where(u => u.IdCardNumber == input.IdCardNumber && u.Id != userId && !u.DeleteMark)
|
||||||
|
.FirstAsync();
|
||||||
if (duplicateIdCard != null) throw Oops.Bah("该身份证号已被其他用户使用");
|
if (duplicateIdCard != null) throw Oops.Bah("该身份证号已被其他用户使用");
|
||||||
}
|
}
|
||||||
else if (input.AuthType == 2)
|
else if (input.AuthType == 2)
|
||||||
@ -187,8 +188,9 @@ public class MyController : IDynamicApiController
|
|||||||
if (!input.BirthDate.HasValue) throw Oops.Bah("出生日期不能为空");
|
if (!input.BirthDate.HasValue) throw Oops.Bah("出生日期不能为空");
|
||||||
|
|
||||||
// 护照号查重
|
// 护照号查重
|
||||||
var duplicatePassport = await _appUserRepository.GetFirstAsync(u =>
|
var duplicatePassport = await _appUserRepository.AsQueryable()
|
||||||
u.PassportNumber == input.PassportNumber && u.Id != userId && !u.DeleteMark);
|
.Where(u => u.PassportNumber == input.PassportNumber && u.Id != userId && !u.DeleteMark)
|
||||||
|
.FirstAsync();
|
||||||
if (duplicatePassport != null) throw Oops.Bah("该护照号码已被其他用户使用");
|
if (duplicatePassport != null) throw Oops.Bah("该护照号码已被其他用户使用");
|
||||||
}
|
}
|
||||||
else if (input.AuthType == 3)
|
else if (input.AuthType == 3)
|
||||||
@ -197,8 +199,9 @@ public class MyController : IDynamicApiController
|
|||||||
if (string.IsNullOrEmpty(input.IdCardNumber)) throw Oops.Bah("身份证号不能为空");
|
if (string.IsNullOrEmpty(input.IdCardNumber)) throw Oops.Bah("身份证号不能为空");
|
||||||
|
|
||||||
// 身份证号查重
|
// 身份证号查重
|
||||||
var duplicateIdCard = await _appUserRepository.GetFirstAsync(u =>
|
var duplicateIdCard = await _appUserRepository.AsQueryable()
|
||||||
u.IdCardNumber == input.IdCardNumber && u.Id != userId && !u.DeleteMark);
|
.Where(u => u.IdCardNumber == input.IdCardNumber && u.Id != userId && !u.DeleteMark)
|
||||||
|
.FirstAsync();
|
||||||
if (duplicateIdCard != null) throw Oops.Bah("该身份证号已被其他用户使用");
|
if (duplicateIdCard != null) throw Oops.Bah("该身份证号已被其他用户使用");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user