fix 优化查询和检查
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Basic.Organization.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -36,10 +37,10 @@ public class GainfoFingerprintsController : ControllerBase
|
||||
/// 获取人员指纹数据
|
||||
/// </summary>
|
||||
/// <param name="userCode"></param>
|
||||
/// <param name="fingerNum"></param>
|
||||
/// <param name="fingerNum">1-10,不传入则获取所有</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("fingerprints")]
|
||||
public async Task<List<GainfoFingerprintResponse>> GetFingerprintAsync(string userCode, int fingerNum)
|
||||
public async Task<List<GainfoFingerprintResponse>> GetFingerprintAsync([Required] string userCode, int? fingerNum)
|
||||
{
|
||||
return await _gainfoFingerprintService.GetFingerprintAsync(userCode, fingerNum);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,12 @@ public class GainfoFingerprintResponse
|
||||
/// </summary>
|
||||
public string DepartmentName { get; set; }
|
||||
|
||||
|
||||
public List<FingerprintResponse> Fingerprints { get; set; }
|
||||
}
|
||||
|
||||
public class FingerprintResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 指纹号
|
||||
/// </summary>
|
||||
|
||||
@@ -6,5 +6,5 @@ public interface IGainfoFingerprintService : IScopeDependency
|
||||
{
|
||||
Task CollectFingerprintAsync(string userCode, int fingerNum, string fingerprint);
|
||||
|
||||
Task<List<GainfoFingerprintResponse>> GetFingerprintAsync(string userCode, int fingerNum);
|
||||
Task<GainfoFingerprintResponse> GetFingerprintAsync(string userCode, int? fingerNum);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Services.Implements
|
||||
{
|
||||
@@ -14,6 +15,11 @@ namespace Dlhis.Basic.Organization.Services.Implements
|
||||
}
|
||||
public async Task CollectFingerprintAsync(string userCode, int fingerNum, string fingerprint)
|
||||
{
|
||||
if (!await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == userCode).AnyAsync())
|
||||
{
|
||||
true.ThrowIfTrue("人员不存在");
|
||||
}
|
||||
|
||||
var gainfoFingerprint = await _dbContext.Queryable<GainfoFingerprintEntity>().Where(x => x.UserCode == userCode && x.FingerNum == fingerNum).FirstAsync();
|
||||
if (gainfoFingerprint == null)
|
||||
{
|
||||
@@ -32,21 +38,35 @@ namespace Dlhis.Basic.Organization.Services.Implements
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<GainfoFingerprintResponse>> GetFingerprintAsync(string userCode, int fingerNum)
|
||||
public async Task<GainfoFingerprintResponse> GetFingerprintAsync(string userCode, int? fingerNum)
|
||||
{
|
||||
return await _dbContext.Queryable<GainfoFingerprintEntity>()
|
||||
.LeftJoin<GainfoEntity>((x, ga) => x.UserCode == ga.Code)
|
||||
.LeftJoin<DepartmentEntity>((x, ga, dept) => ga.DepartmentNo == dept.No)
|
||||
.Select((x, ga, dept) => new GainfoFingerprintResponse
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>()
|
||||
.LeftJoin<DepartmentEntity>((x, dept) => x.DepartmentNo == dept.No)
|
||||
.Where(x => x.Code == userCode)
|
||||
.Select((x, dept) => new
|
||||
{
|
||||
x.Code,
|
||||
x.Name,
|
||||
x.DepartmentNo,
|
||||
DepartmentName = dept.Name
|
||||
})
|
||||
.FirstAsync();
|
||||
gainfo.ThrowIfNull("人员不存在");
|
||||
|
||||
var fingerprins = await _dbContext.Queryable<GainfoFingerprintEntity>().Where(x => x.UserCode == userCode).OrderBy(x => x.FingerNum).ToListAsync();
|
||||
|
||||
return new GainfoFingerprintResponse
|
||||
{
|
||||
UserCode = gainfo.Code,
|
||||
UserName = gainfo.Name,
|
||||
DepartmentNo = gainfo.DepartmentNo,
|
||||
DepartmentName = gainfo.DepartmentName,
|
||||
Fingerprints = fingerprins.Select(x => new FingerprintResponse
|
||||
{
|
||||
UserCode = x.UserCode,
|
||||
UserName = ga.Name,
|
||||
DepartmentNo = dept.No,
|
||||
DepartmentName = dept.Name,
|
||||
FingerNum = x.FingerNum,
|
||||
Fingerprint = x.Fingerprint
|
||||
})
|
||||
.ToListAsync();
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user