feat 换卡操作
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Basic.Organization.Services;
|
||||
using Dlhis.Basic.Packs;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 档案卡记录
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class GainfoCardsController : ControllerBase
|
||||
{
|
||||
private readonly IGainfoCardService _gainfoCardService;
|
||||
|
||||
public GainfoCardsController(IGainfoCardService gainfoCardService)
|
||||
{
|
||||
_gainfoCardService = gainfoCardService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 换卡
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("change")]
|
||||
[Transactional]
|
||||
public async Task ChangeCardAsync(ChangeCardRequest request)
|
||||
{
|
||||
await _gainfoCardService.ChangeCardAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 换卡记录
|
||||
/// </summary>
|
||||
/// <param name="userNo"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("records")]
|
||||
public async Task<List<ChangeCardResponse>> GetChangeRecordsAsync(string userNo)
|
||||
{
|
||||
return await _gainfoCardService.GetChangeRecordsAsync(userNo);
|
||||
}
|
||||
}
|
||||
17
Src/Dlhis.Basic/Organization/Request/ChangeCardRequest.cs
Normal file
17
Src/Dlhis.Basic/Organization/Request/ChangeCardRequest.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Request;
|
||||
|
||||
public class ChangeCardRequest
|
||||
{
|
||||
[Required]
|
||||
public string UserNo { get; set; }
|
||||
|
||||
[Required]
|
||||
public string CardNo { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Reason { get; set; }
|
||||
|
||||
public string Remark { get; set; }
|
||||
}
|
||||
15
Src/Dlhis.Basic/Organization/Response/ChangeCardResponse.cs
Normal file
15
Src/Dlhis.Basic/Organization/Response/ChangeCardResponse.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace Dlhis.Basic.Organization.Response;
|
||||
|
||||
public class ChangeCardResponse
|
||||
{
|
||||
public string UserNo { get; set; }
|
||||
public string UserCode { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string CardNo { get; set; }
|
||||
|
||||
public string Reason { get; set; }
|
||||
|
||||
public string Remark { get; set; }
|
||||
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
11
Src/Dlhis.Basic/Organization/Services/IGainfoCardService.cs
Normal file
11
Src/Dlhis.Basic/Organization/Services/IGainfoCardService.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Services;
|
||||
|
||||
public interface IGainfoCardService
|
||||
{
|
||||
Task ChangeCardAsync(ChangeCardRequest request);
|
||||
|
||||
Task<List<ChangeCardResponse>> GetChangeRecordsAsync(string userNo);
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace Dlhis.Basic.Organization.Services;
|
||||
/// </summary>
|
||||
public interface IGainfoStore : IScopeDependency
|
||||
{
|
||||
ISugarQueryable<GainfoEntity> Queryable(GainfoStatusEnumType? gainfoStatus);
|
||||
ISugarQueryable<GainfoEntity> Queryable(GainfoStatusEnumType? gainfoStatus = null);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
33
Src/Dlhis.Entity/Basic/Entity/GainfoCardRecordEntity.cs
Normal file
33
Src/Dlhis.Entity/Basic/Entity/GainfoCardRecordEntity.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Kurisu.Core.DataAccess.Entity;
|
||||
using Kurisu.SqlSugar;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Entity.Basic.Entity;
|
||||
|
||||
[SugarTable(TableName = "GainfoCardRecord", TableDescription = "卡记录")]
|
||||
public class GainfoCardRecordEntity : SugarBaseEntity, ITenantId
|
||||
{
|
||||
/// <summary>
|
||||
/// 档案No
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, IndexGroupNameList = new[] { "idx_GainfoCardRecord_userno" })]
|
||||
public string UserNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 卡号
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false)]
|
||||
public string CardNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更换原因
|
||||
/// </summary>
|
||||
public string Reason { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remark { get; set; }
|
||||
|
||||
public string TenantId { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user