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.Response;
|
||||||
using Dlhis.Basic.Organization.Services;
|
using Dlhis.Basic.Organization.Services;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@@ -36,10 +37,10 @@ public class GainfoFingerprintsController : ControllerBase
|
|||||||
/// 获取人员指纹数据
|
/// 获取人员指纹数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userCode"></param>
|
/// <param name="userCode"></param>
|
||||||
/// <param name="fingerNum"></param>
|
/// <param name="fingerNum">1-10,不传入则获取所有</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("fingerprints")]
|
[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);
|
return await _gainfoFingerprintService.GetFingerprintAsync(userCode, fingerNum);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ public class GainfoFingerprintResponse
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string DepartmentName { get; set; }
|
public string DepartmentName { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public List<FingerprintResponse> Fingerprints { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FingerprintResponse
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 指纹号
|
/// 指纹号
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -6,5 +6,5 @@ public interface IGainfoFingerprintService : IScopeDependency
|
|||||||
{
|
{
|
||||||
Task CollectFingerprintAsync(string userCode, int fingerNum, string fingerprint);
|
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.Basic.Organization.Response;
|
||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||||
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Organization.Services.Implements
|
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)
|
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();
|
var gainfoFingerprint = await _dbContext.Queryable<GainfoFingerprintEntity>().Where(x => x.UserCode == userCode && x.FingerNum == fingerNum).FirstAsync();
|
||||||
if (gainfoFingerprint == null)
|
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>()
|
var gainfo = await _dbContext.Queryable<GainfoEntity>()
|
||||||
.LeftJoin<GainfoEntity>((x, ga) => x.UserCode == ga.Code)
|
.LeftJoin<DepartmentEntity>((x, dept) => x.DepartmentNo == dept.No)
|
||||||
.LeftJoin<DepartmentEntity>((x, ga, dept) => ga.DepartmentNo == dept.No)
|
.Where(x => x.Code == userCode)
|
||||||
.Select((x, ga, dept) => new GainfoFingerprintResponse
|
.Select((x, dept) => new
|
||||||
{
|
{
|
||||||
UserCode = x.UserCode,
|
x.Code,
|
||||||
UserName = ga.Name,
|
x.Name,
|
||||||
DepartmentNo = dept.No,
|
x.DepartmentNo,
|
||||||
DepartmentName = dept.Name,
|
DepartmentName = dept.Name
|
||||||
FingerNum = x.FingerNum,
|
})
|
||||||
Fingerprint = x.Fingerprint
|
.FirstAsync();
|
||||||
})
|
gainfo.ThrowIfNull("人员不存在");
|
||||||
.ToListAsync();
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
FingerNum = x.FingerNum,
|
||||||
|
Fingerprint = x.Fingerprint
|
||||||
|
}).ToList()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user