55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using Dlhis.Basic.Organization.Request;
|
|
using Dlhis.Basic.Organization.Response;
|
|
using Dlhis.Entity.Basic.Entity;
|
|
using Kurisu.AspNetCore.Utils.Extensions;
|
|
using Kurisu.SqlSugar.Services;
|
|
|
|
namespace Dlhis.Basic.Organization.Services.Implements;
|
|
|
|
public class GainfoCardService : IGainfoCardService
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
private readonly IGainfoStore _gainfoStore;
|
|
|
|
public GainfoCardService(IDbContext dbContext, IGainfoStore gainfoStore)
|
|
{
|
|
_dbContext = dbContext;
|
|
_gainfoStore = gainfoStore;
|
|
}
|
|
|
|
public async Task ChangeCardAsync(ChangeCardRequest request)
|
|
{
|
|
var gainfo = await _gainfoStore.Queryable().Where(x => x.No == request.UserNo).FirstAsync();
|
|
gainfo.ThrowIfNull("档案不存在");
|
|
|
|
gainfo.CardNo = request.CardNo;
|
|
|
|
await _gainfoStore.UpdateAsync(gainfo);
|
|
await _dbContext.InsertAsync(new GainfoCardRecordEntity
|
|
{
|
|
UserNo = request.UserNo,
|
|
CardNo = request.CardNo,
|
|
Reason = request.Reason,
|
|
Remark = request.Remark,
|
|
});
|
|
}
|
|
|
|
public async Task<List<ChangeCardResponse>> GetChangeRecordsAsync(string userNo)
|
|
{
|
|
return await _dbContext.Queryable<GainfoCardRecordEntity>()
|
|
.LeftJoin<GainfoEntity>((x, ga) => x.UserNo == ga.No)
|
|
.Where(x => x.UserNo == userNo)
|
|
.Select((x, ga) => new ChangeCardResponse
|
|
{
|
|
UserNo = x.UserNo,
|
|
UserCode = ga.Code,
|
|
UserName = ga.Name,
|
|
CardNo = x.CardNo,
|
|
Reason = x.Reason,
|
|
Remark = x.Remark,
|
|
CreateTime = x.CreateTime,
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
}
|