add api add commander and approver ด้วย และเพิ่มประเภทของผู้อนุมัติ
This commit is contained in:
parent
193cffa7c4
commit
ddc3d268be
8 changed files with 1620 additions and 48 deletions
|
|
@ -74,6 +74,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
{
|
{
|
||||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
||||||
//.AsNoTracking()
|
//.AsNoTracking()
|
||||||
|
.Include(x => x.Approvers)
|
||||||
.Include(x => x.LeaveDocument)
|
.Include(x => x.LeaveDocument)
|
||||||
.ThenInclude(x => x.Document)
|
.ThenInclude(x => x.Document)
|
||||||
.Include(x => x.LeaveDraftDocument)
|
.Include(x => x.LeaveDraftDocument)
|
||||||
|
|
@ -88,6 +89,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
||||||
{
|
{
|
||||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
|
.Include(x => x.Approvers)
|
||||||
.Include(x => x.LeaveDocument)
|
.Include(x => x.LeaveDocument)
|
||||||
.ThenInclude(x => x.Document)
|
.ThenInclude(x => x.Document)
|
||||||
.Include(x => x.LeaveDraftDocument)
|
.Include(x => x.LeaveDraftDocument)
|
||||||
|
|
|
||||||
|
|
@ -23,5 +23,7 @@ namespace BMA.EHR.Domain.Models.Leave.Requests
|
||||||
public string ApproveStatus { get; set; } = string.Empty;
|
public string ApproveStatus { get; set; } = string.Empty;
|
||||||
|
|
||||||
public string Comment { get; set; } = string.Empty;
|
public string Comment { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string? ApproveType { get; set; } = string.Empty; // ผู้บังคับบัญชา = commander, ผู้มีอำนาจอนุมัติ = Approver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1481
BMA.EHR.Infrastructure/Migrations/LeaveDb/20250422065634_Add Approver Type.Designer.cs
generated
Normal file
1481
BMA.EHR.Infrastructure/Migrations/LeaveDb/20250422065634_Add Approver Type.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,29 @@
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddApproverType : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "ApproveType",
|
||||||
|
table: "LeaveRequestApprovers",
|
||||||
|
type: "longtext",
|
||||||
|
nullable: true)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "ApproveType",
|
||||||
|
table: "LeaveRequestApprovers");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -625,6 +625,9 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("ApproveType")
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
b.Property<string>("Comment")
|
b.Property<string>("Comment")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("longtext");
|
.HasColumnType("longtext");
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,57 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
|
|
||||||
#region " Methods "
|
#region " Methods "
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// เพิ่มรายชิื่อผู้อนุมัติ หรือ ผู้บังคับบัญชา
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// </returns>
|
||||||
|
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||||
|
[HttpPost("officer/add-approver/{type}/{id:guid}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
public async Task<ActionResult<ResponseObject>> AddApprover(string type, Guid id, [FromBody] List<LeaveRequestApproverDto> req)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var leaveReq = await _leaveRequestRepository.GetByIdAsync(id);
|
||||||
|
if (leaveReq == null)
|
||||||
|
{
|
||||||
|
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
var delete = leaveReq.Approvers.RemoveAll(x => x.ApproveType == type.Trim().ToUpper());
|
||||||
|
|
||||||
|
foreach (var r in req)
|
||||||
|
{
|
||||||
|
leaveReq.Approvers.Add(new LeaveRequestApprover
|
||||||
|
{
|
||||||
|
Seq = r.Seq,
|
||||||
|
Prefix = r.Prefix,
|
||||||
|
FirstName = r.FirstName,
|
||||||
|
LastName = r.LastName,
|
||||||
|
PositionName = r.PositionName,
|
||||||
|
ProfileId = r.ProfileId,
|
||||||
|
KeycloakId = r.KeycloakId,
|
||||||
|
ApproveStatus = "PENDING",
|
||||||
|
ApproveType = type.Trim().ToUpper()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await _leaveRequestRepository.UpdateAsync(leaveReq);
|
||||||
|
|
||||||
|
return Success();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Error(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// LV2_001 - สร้างคำขอการลา (USER)
|
/// LV2_001 - สร้างคำขอการลา (USER)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -370,30 +421,30 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
leaveRequest.PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel;
|
leaveRequest.PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel;
|
||||||
leaveRequest.OrganizationName = userOc;
|
leaveRequest.OrganizationName = userOc;
|
||||||
|
|
||||||
if (req.Approvers != null && req.Approvers != "")
|
//if (req.Approvers != null && req.Approvers != "")
|
||||||
{
|
//{
|
||||||
//var jsonString = System.Text.Json.JsonSerializer.Deserialize<string>(req.Approvers ?? "");
|
// //var jsonString = System.Text.Json.JsonSerializer.Deserialize<string>(req.Approvers ?? "");
|
||||||
//var fixedJson = req.Approvers.Replace("\\\"", "\"");
|
// //var fixedJson = req.Approvers.Replace("\\\"", "\"");
|
||||||
var approvers = JsonConvert.DeserializeObject<List<LeaveRequestApproverDto>>(req.Approvers);
|
// var approvers = JsonConvert.DeserializeObject<List<LeaveRequestApproverDto>>(req.Approvers);
|
||||||
if (approver != null)
|
// if (approver != null)
|
||||||
{
|
// {
|
||||||
foreach (var r in approvers!)
|
// foreach (var r in approvers!)
|
||||||
{
|
// {
|
||||||
leaveRequest.Approvers.Add(new LeaveRequestApprover
|
// leaveRequest.Approvers.Add(new LeaveRequestApprover
|
||||||
{
|
// {
|
||||||
Seq = r.Seq,
|
// Seq = r.Seq,
|
||||||
Prefix = r.Prefix,
|
// Prefix = r.Prefix,
|
||||||
FirstName = r.FirstName,
|
// FirstName = r.FirstName,
|
||||||
LastName = r.LastName,
|
// LastName = r.LastName,
|
||||||
PositionName = r.PositionName,
|
// PositionName = r.PositionName,
|
||||||
ProfileId = r.ProfileId,
|
// ProfileId = r.ProfileId,
|
||||||
KeycloakId = r.KeycloakId,
|
// KeycloakId = r.KeycloakId,
|
||||||
ApproveStatus = "PENDING",
|
// ApproveStatus = "PENDING",
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
// save to database
|
// save to database
|
||||||
|
|
|
||||||
|
|
@ -102,31 +102,7 @@ namespace BMA.EHR.Leave.Service.DTOs.LeaveRequest
|
||||||
public DateTime? CoupleDayEndDateHistory { get; set; }
|
public DateTime? CoupleDayEndDateHistory { get; set; }
|
||||||
|
|
||||||
public string? CoupleDaySumTotalHistory { get; set; }
|
public string? CoupleDaySumTotalHistory { get; set; }
|
||||||
|
|
||||||
public string? Approvers { get; set; } = string.Empty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LeaveRequestApproverDto
|
|
||||||
{
|
|
||||||
[JsonProperty("seq")]
|
|
||||||
public int Seq { get; set; } = 0;
|
|
||||||
|
|
||||||
[JsonProperty("prefix")]
|
|
||||||
public string Prefix { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
[JsonProperty("firstName")]
|
|
||||||
public string FirstName { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
[JsonProperty("lastName")]
|
|
||||||
public string LastName { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
[JsonProperty("positionName")]
|
|
||||||
public string PositionName { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
[JsonProperty("profileId")]
|
|
||||||
public Guid ProfileId { get; set; } = Guid.Empty;
|
|
||||||
|
|
||||||
[JsonProperty("keycloakId")]
|
|
||||||
public Guid KeycloakId { get; set; } = Guid.Empty;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
28
BMA.EHR.Leave/DTOs/LeaveRequest/LeaveRequestApproverDto.cs
Normal file
28
BMA.EHR.Leave/DTOs/LeaveRequest/LeaveRequestApproverDto.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace BMA.EHR.Leave.Service.DTOs.LeaveRequest
|
||||||
|
{
|
||||||
|
public class LeaveRequestApproverDto
|
||||||
|
{
|
||||||
|
[JsonProperty("seq")]
|
||||||
|
public int Seq { get; set; } = 0;
|
||||||
|
|
||||||
|
[JsonProperty("prefix")]
|
||||||
|
public string Prefix { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[JsonProperty("firstName")]
|
||||||
|
public string FirstName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[JsonProperty("lastName")]
|
||||||
|
public string LastName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[JsonProperty("positionName")]
|
||||||
|
public string PositionName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[JsonProperty("profileId")]
|
||||||
|
public Guid ProfileId { get; set; } = Guid.Empty;
|
||||||
|
|
||||||
|
[JsonProperty("keycloakId")]
|
||||||
|
public Guid KeycloakId { get; set; } = Guid.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue