api บันทึกเครื่องราช
This commit is contained in:
parent
9abb9c5422
commit
51bdcf4041
50 changed files with 162548 additions and 111 deletions
|
|
@ -47,17 +47,16 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
/// <summary>
|
||||
/// list รอบเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="type">ประเภทเครื่องราช(insignia=เครื่องราช,coin=เหรียญ)</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("{type}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetList(string type)
|
||||
[HttpGet()]
|
||||
public async Task<ActionResult<ResponseObject>> GetList()
|
||||
{
|
||||
var insigniaPeriods = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Where(x => x.Type == type)
|
||||
// .Where(x => x.Type == type)
|
||||
.OrderByDescending(x => x.Year)
|
||||
.ThenByDescending(x => x.StartDate)
|
||||
.Select(p => new
|
||||
|
|
@ -147,7 +146,6 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
/// <summary>
|
||||
/// สร้างรอบเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="type">ประเภทเครื่องราช(insignia=เครื่องราช,coin=เหรียญ)</param>
|
||||
/// <param name="req.Round">รอบที่</param>
|
||||
/// <param name="req.Name">ชื่อรอบ</param>
|
||||
/// <param name="req.Year">ปีที่เสนอ</param>
|
||||
|
|
@ -160,8 +158,8 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost("{type}")]
|
||||
public async Task<ActionResult<ResponseObject>> Post([FromForm] InsigniaPeriodRequest req, string type)
|
||||
[HttpPost()]
|
||||
public async Task<ActionResult<ResponseObject>> Post([FromForm] InsigniaPeriodRequest req)
|
||||
{
|
||||
var insigniaPeriod = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Where(x => x.Round == req.Round && x.Year == req.Year)
|
||||
|
|
@ -177,7 +175,6 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
StartDate = req.StartDate,
|
||||
EndDate = req.EndDate,
|
||||
Amount = req.Amount,
|
||||
Type = type.Trim().ToUpper(),
|
||||
IsActive = true,
|
||||
CreatedUserId = FullName ?? "",
|
||||
CreatedFullName = UserId ?? "System Administrator",
|
||||
|
|
|
|||
|
|
@ -26,17 +26,20 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly InsigniaPeriodsRepository _repository;
|
||||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
private readonly string Royal_Type = "Royal";
|
||||
|
||||
public InsigniaRequestController(ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
InsigniaPeriodsRepository repository,
|
||||
IWebHostEnvironment hostingEnvironment,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_repository = repository;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
}
|
||||
|
||||
#region " Properties "
|
||||
|
|
@ -282,12 +285,13 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
if (result != null)
|
||||
{
|
||||
Guid period = result.PeriodId;
|
||||
string periodName = result.Name;
|
||||
var periodName = result.Name;
|
||||
string requestStatus = result.RequestStatus;
|
||||
var resend = new InsigniaResults
|
||||
{
|
||||
PeriodId = period,
|
||||
Year = result.Year,
|
||||
Round = result.Round,
|
||||
Name = periodName,
|
||||
RequestStatus = requestStatus,
|
||||
OrganizationName = result.OrganizationName,
|
||||
|
|
@ -453,21 +457,27 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
[HttpGet("{insigniaPeriodId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> UpdateInsignaiRequestBkk(Guid insigniaPeriodId)
|
||||
{
|
||||
var oc = await _context.Organizations.Where(x => x.Parent == null).FirstOrDefaultAsync();
|
||||
if (oc == null)
|
||||
return Error(GlobalMessages.Error);
|
||||
|
||||
var result = await _repository.GetInsigniaRequest(insigniaPeriodId, oc.Id);
|
||||
if (result != null)
|
||||
var organizationType = await _context.OrganizationTypes.Where(x => x.Name == "หน่วยงาน").FirstOrDefaultAsync();
|
||||
if (organizationType == null)
|
||||
return Error(GlobalMessages.OrganizationNotFound);
|
||||
var organizations = await _context.Organizations.Where(x => x.OrganizationType == organizationType).ToListAsync();
|
||||
foreach (var organization in organizations)
|
||||
{
|
||||
Guid period = result.PeriodId;
|
||||
string requestStatus = result.RequestStatus;
|
||||
var candidate = await _repository.GetInsigniaCandidateBKK(insigniaPeriodId, oc.Id);
|
||||
// ตรวจสอบว่ารายการอยู่ใน table insignia_request_new
|
||||
if (requestStatus == null)
|
||||
if (organization == null)
|
||||
continue;
|
||||
|
||||
var result = await _repository.GetInsigniaRequest(insigniaPeriodId, organization.Id);
|
||||
if (result != null)
|
||||
{
|
||||
// บันทึกรายชื่อ
|
||||
await _repository.InsertCandidate(period, oc.Id, candidate);
|
||||
Guid period = result.PeriodId;
|
||||
string requestStatus = result.RequestStatus;
|
||||
var candidate = await _repository.GetInsigniaCandidateBKK(insigniaPeriodId, organization.Id);
|
||||
// ตรวจสอบว่ารายการอยู่ใน table insignia_request_new
|
||||
if (requestStatus == null)
|
||||
{
|
||||
// บันทึกรายชื่อ
|
||||
await _repository.InsertCandidate(period, organization.Id, candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Success();
|
||||
|
|
@ -504,28 +514,99 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
|
||||
// #endregion
|
||||
|
||||
// #region " เปลี่ยน status เป็น st2 รอ ผอ.สำนักรับรอง "
|
||||
/// <summary>
|
||||
/// เปลี่ยน status เป็น st3 การเจ้าหน้าที่อนุมัติ "
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("officer/approve/{ocId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> ApproveChangeStatusToSt2(Guid id, Guid ocId)
|
||||
{
|
||||
await _repository.SaveAprove(id, ocId);
|
||||
var requestId = await _repository.GetRequestId(id, ocId);
|
||||
var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId);
|
||||
if (requestNew != null)
|
||||
{
|
||||
requestNew.RequestStatus = "st3";
|
||||
_context.SaveChanges();
|
||||
return Success();
|
||||
}
|
||||
else
|
||||
return Error(GlobalMessages.InsigniaRequestNotFound);
|
||||
}
|
||||
|
||||
// [HttpPost("status/officer/send/{ocId:length(36)}")]
|
||||
// public async Task<ActionResult<ResponseObject>> ChangeStatusToSt2(Guid id, Guid ocId, InsigniaApproveRequest items)
|
||||
// {
|
||||
// var result = await _repository.GetInsigniaRequest(id, ocId);
|
||||
/// <summary>
|
||||
/// เปลี่ยน status เป็น st2 การเจ้าหน้าที่ไม่อนุมัติ "
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("officer/reject/{ocId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> RejectChangeStatusToSt1(Guid id, Guid ocId)
|
||||
{
|
||||
await _repository.SaveAprove(id, ocId);
|
||||
var requestId = await _repository.GetRequestId(id, ocId);
|
||||
var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId);
|
||||
if (requestNew != null)
|
||||
{
|
||||
requestNew.RequestStatus = "st2";
|
||||
_context.SaveChanges();
|
||||
return Success();
|
||||
}
|
||||
else
|
||||
return Error(GlobalMessages.InsigniaRequestNotFound);
|
||||
}
|
||||
|
||||
// if (items != null)
|
||||
// {
|
||||
// _repository.SaveAprove(result.PeriodId, ocId, items);
|
||||
// }
|
||||
// var requestId = await _repository.GetRequestId(result.PeriodId, ocId);
|
||||
// var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId);
|
||||
// if (requestNew != null)
|
||||
// {
|
||||
// requestNew.RequestStatus = "st2";
|
||||
// _context.SaveChanges();
|
||||
// return Success();
|
||||
// }
|
||||
// else
|
||||
// return Error(GlobalMessages.InsigniaRequestNotFound);
|
||||
// }
|
||||
/// <summary>
|
||||
/// เปลี่ยน status เป็น st5 ผอ.หน่วยอนุมัติ "
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("director/approve/{ocId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> ApproveChangeStatusToSt3(Guid id, Guid ocId)
|
||||
{
|
||||
var requestId = await _repository.GetRequestId(id, ocId);
|
||||
var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId);
|
||||
if (requestNew != null)
|
||||
{
|
||||
requestNew.RequestStatus = "st5";
|
||||
_context.SaveChanges();
|
||||
return Success();
|
||||
}
|
||||
else
|
||||
return Error(GlobalMessages.InsigniaRequestNotFound);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// เปลี่ยน status เป็น st4 ผอ.หน่วยไม่อนุมัติ "
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("director/reject/{ocId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> RejectChangeStatusToSt2(Guid id, Guid ocId)
|
||||
{
|
||||
var requestId = await _repository.GetRequestId(id, ocId);
|
||||
var requestNew = await _context.InsigniaRequests.FirstOrDefaultAsync(i => i.Id == requestId);
|
||||
if (requestNew != null)
|
||||
{
|
||||
requestNew.RequestStatus = "st4";
|
||||
_context.SaveChanges();
|
||||
return Success();
|
||||
}
|
||||
else
|
||||
return Error(GlobalMessages.InsigniaRequestNotFound);
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
|
|
@ -641,24 +722,21 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
var insigniaPeriod = await _context.InsigniaPeriods.FirstOrDefaultAsync(x => x.Id == insigniaPeriodId);
|
||||
if (insigniaPeriod == null)
|
||||
return Error(GlobalMessages.InsigniaRequestNotFound);
|
||||
var orgSendCount = await _context.InsigniaRequests
|
||||
var orgAllCount = await _context.InsigniaRequests
|
||||
.Where(x => x.Period == insigniaPeriod)
|
||||
.CountAsync();
|
||||
.ToListAsync();
|
||||
var allUserUser = await _context.InsigniaRequests
|
||||
.Where(x => x.Period == insigniaPeriod)
|
||||
.Select(x => x.RequestProfiles.Count())
|
||||
.SumAsync();
|
||||
var orgAllCount = await _context.Organizations
|
||||
.Where(x => x.OrganizationType != null)
|
||||
.Where(x => x.OrganizationType.Name == "หน่วยงาน")
|
||||
.CountAsync();
|
||||
|
||||
return Success(new { OrgAllCount = orgAllCount, OrgSendCount = orgSendCount, OrgNoSendCount = orgAllCount - orgSendCount, AllUserUser = allUserUser });
|
||||
return Success(new { OrgAllCount = orgAllCount.Count(), OrgSendCount = orgAllCount.Where(x => x.RequestStatus != "st1" && x.RequestStatus != "st2").Count(), OrgNoSendCount = orgAllCount.Where(x => x.RequestStatus == "st1" && x.RequestStatus == "st2").Count(), AllUserUser = allUserUser });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// หน่วยงานทียังไม่ส่งรายชื่อ
|
||||
/// </summary>
|
||||
/// <param name="insigniaPeriodId">Id รอบการยื่นขอ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
|
|
@ -672,13 +750,14 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
return Error(GlobalMessages.InsigniaRequestNotFound);
|
||||
var orgIdSend = await _context.InsigniaRequests
|
||||
.Where(x => x.Period == insigniaPeriod)
|
||||
.Where(x => x.RequestStatus == "st1")
|
||||
.Select(x => x.Organization.Id)
|
||||
.ToListAsync();
|
||||
var orgAllCount = await _context.Organizations
|
||||
.Where(x => x.OrganizationOrganization != null)
|
||||
.Where(x => x.OrganizationType != null)
|
||||
.Where(x => x.OrganizationType.Name == "หน่วยงาน")
|
||||
.Where(x => !orgIdSend.Contains(x.Id))
|
||||
.Where(x => orgIdSend.Contains(x.Id))
|
||||
.Select(x => new
|
||||
{
|
||||
OrgId = x.Id,
|
||||
|
|
@ -686,7 +765,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
})
|
||||
.ToListAsync();
|
||||
|
||||
return Success();
|
||||
return Success(orgAllCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -716,7 +795,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// เพิ่มราชชื่อผู้ได้รับเครื่องราช
|
||||
/// เพิ่มรายชื่อผู้ได้รับเครื่องราช
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
|
|
@ -787,8 +866,9 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// แก้ไขราชชื่อผู้ได้รับเครื่องราช
|
||||
/// แก้ไขรายชื่อผู้ได้รับเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="insigniaRequestProfileId">Id รายชื่อคนที่ยื่นของในรอบ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
|
|
@ -812,5 +892,354 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// รายชื่อผู้ได้รับเครื่องราชส่งข้อมูลไปบันทึกผลได้รับเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="insigniaPeriodId">Id รอบการยื่นขอ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost("send/note/{insigniaPeriodId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> SendPeriodToNote([FromBody] InsigniaNoteNameRequest req, Guid insigniaPeriodId)
|
||||
{
|
||||
var insigniaPeriod = await _context.InsigniaPeriods
|
||||
.Include(x => x.InsigniaRequests)
|
||||
.Include(x => x.ReliefDoc)
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaPeriodId);
|
||||
if (insigniaPeriod == null)
|
||||
return Error(GlobalMessages.InsigniaRequestNotFound);
|
||||
var insigniaNote = await _context.InsigniaNotes
|
||||
.Include(x => x.InsigniaNoteProfiles)
|
||||
.ThenInclude(x => x.Profile)
|
||||
.Include(x => x.InsigniaNoteProfiles)
|
||||
.ThenInclude(x => x.RequestInsignia)
|
||||
.FirstOrDefaultAsync(x => x.Year == insigniaPeriod.Year);
|
||||
if (insigniaNote == null)
|
||||
{
|
||||
insigniaNote = new InsigniaNote
|
||||
{
|
||||
// Round = insigniaPeriod.Round,
|
||||
Name = req.Name,
|
||||
Year = insigniaPeriod.Year,
|
||||
// StartDate = insigniaPeriod.StartDate,
|
||||
// EndDate = insigniaPeriod.EndDate,
|
||||
// Amount = insigniaPeriod.Amount,
|
||||
// ReliefDoc = insigniaPeriod.ReliefDoc,
|
||||
CreatedUserId = FullName ?? "",
|
||||
CreatedFullName = UserId ?? "System Administrator",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
};
|
||||
await _context.InsigniaNotes.AddAsync(insigniaNote);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
var requestOlds = await _context.InsigniaRequests
|
||||
.Where(p => p.Period == insigniaPeriod)
|
||||
.ToListAsync();
|
||||
foreach (var requestOld in requestOlds)
|
||||
{
|
||||
var profileOlds = await _context.InsigniaRequestProfiles
|
||||
.Include(x => x.Profile)
|
||||
.Include(x => x.RequestInsignia)
|
||||
.Where(p => p.Request == requestOld)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var profileOld in profileOlds)
|
||||
{
|
||||
var noreProfileOld = insigniaNote.InsigniaNoteProfiles
|
||||
.Where(x => x.Profile == profileOld.Profile)
|
||||
.FirstOrDefault();
|
||||
if (noreProfileOld != null)
|
||||
{
|
||||
noreProfileOld.RequestDate = profileOld.RequestDate;
|
||||
noreProfileOld.Salary = profileOld.Salary;
|
||||
noreProfileOld.IsApprove = profileOld.IsApprove;
|
||||
noreProfileOld.Status = profileOld.Status;
|
||||
noreProfileOld.RequestInsignia = profileOld.RequestInsignia;
|
||||
noreProfileOld.CreatedUserId = FullName ?? "";
|
||||
noreProfileOld.CreatedFullName = UserId ?? "System Administrator";
|
||||
noreProfileOld.CreatedAt = DateTime.Now;
|
||||
noreProfileOld.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
noreProfileOld.LastUpdateUserId = UserId ?? "";
|
||||
noreProfileOld.LastUpdatedAt = DateTime.Now;
|
||||
}
|
||||
{
|
||||
await _context.InsigniaNoteProfiles.AddAsync(new InsigniaNoteProfile
|
||||
{
|
||||
RequestDate = profileOld.RequestDate,
|
||||
Salary = profileOld.Salary,
|
||||
IsApprove = profileOld.IsApprove,
|
||||
Status = profileOld.Status,
|
||||
Profile = profileOld.Profile,
|
||||
RequestInsignia = profileOld.RequestInsignia,
|
||||
OrganizationOrganizationSend = await _context.OrganizationOrganizations.FirstOrDefaultAsync(x => x.Id == profileOld.Profile.OrganizationOrganizationId),
|
||||
InsigniaNote = insigniaNote,
|
||||
CreatedUserId = FullName ?? "",
|
||||
CreatedFullName = UserId ?? "System Administrator",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// list รอบบันทึกผลการได้รับพระราชทานเครื่องราชย์อิสริยสภรณ์/การจ่ายใบกำกับ
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("note")]
|
||||
public async Task<ActionResult<ResponseObject>> GetListNote()
|
||||
{
|
||||
var insigniaNotes = await _context.InsigniaNotes.AsQueryable()
|
||||
.OrderByDescending(x => x.Year)
|
||||
// .ThenByDescending(x => x.StartDate)
|
||||
.Select(p => new
|
||||
{
|
||||
Id = p.Id,
|
||||
// Amount = p.Amount,
|
||||
Name = p.Name,
|
||||
// Round = p.Round,
|
||||
// Start = p.StartDate,
|
||||
// End = p.EndDate,
|
||||
Year = p.Year,
|
||||
// Doc = p.ReliefDoc == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.ReliefDoc.Id,
|
||||
})
|
||||
.ToListAsync();
|
||||
// var data = new List<dynamic>();
|
||||
// foreach (var insigniaNote in insigniaNotes)
|
||||
// {
|
||||
// var _data = new
|
||||
// {
|
||||
// Id = insigniaNote.Id,
|
||||
// Amount = insigniaNote.Amount,
|
||||
// Name = insigniaNote.Name,
|
||||
// Round = insigniaNote.Round,
|
||||
// Start = insigniaNote.Start,
|
||||
// End = insigniaNote.End,
|
||||
// Year = insigniaNote.Year,
|
||||
// Doc = insigniaNote.Doc == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(insigniaNote.Doc),
|
||||
// };
|
||||
// data.Add(_data);
|
||||
// }
|
||||
|
||||
return Success(insigniaNotes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// list รายชื่อบันทึกผลการได้รับพระราชทานเครื่องราชย์อิสริยสภรณ์/การจ่ายใบกำกับ
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost("note/search")]
|
||||
public async Task<ActionResult<ResponseObject>> GetListNoteProfile([FromBody] InsigniaNoteSearchRequest req)
|
||||
{
|
||||
var insigniaNote = await _context.InsigniaNotes
|
||||
.FirstOrDefaultAsync(x => x.Id == req.InsigniaNoteId);
|
||||
if (insigniaNote == null)
|
||||
return Error(GlobalMessages.InsigniaRequestNotFound);
|
||||
var insigniaType = await _context.InsigniaTypes
|
||||
.FirstOrDefaultAsync(x => x.Id == req.InsigniaTypeId);
|
||||
if (insigniaType == null)
|
||||
return Error(GlobalMessages.InsigniaTypeNotFound);
|
||||
var insigniaNoteProfiles = await _context.InsigniaNoteProfiles
|
||||
.Where(x => x.InsigniaNote == insigniaNote)
|
||||
.Where(x => x.RequestInsignia.InsigniaType == insigniaType)
|
||||
.Where(x => req.InsigniaId == null ? x.RequestInsignia != null : (x.RequestInsignia.Id == req.InsigniaId))
|
||||
.Select(x => new
|
||||
{
|
||||
FullName = $"{x.Profile.FirstName} {x.Profile.LastName}",
|
||||
RequestInsignia = x.RequestInsignia.Name,
|
||||
RequestInsigniaId = x.RequestInsignia.Id,
|
||||
RequestInsigniaShortName = x.RequestInsignia.ShortName,
|
||||
DateReceive = x.DateReceive,
|
||||
OrganizationOrganizationSend = x.OrganizationOrganizationSend == null ? null : x.OrganizationOrganizationSend.Name,
|
||||
OrganizationOrganizationReceive = x.Profile.OrganizationOrganization,
|
||||
Date = x.Date,
|
||||
VolumeNo = x.VolumeNo,
|
||||
Section = x.Section,
|
||||
Page = x.Page,
|
||||
No = x.No,
|
||||
DatePayment = x.DatePayment,
|
||||
TypePayment = x.TypePayment,
|
||||
Address = x.Address,
|
||||
Salary = x.Salary,
|
||||
}).ToListAsync();
|
||||
|
||||
return Success(insigniaNoteProfiles);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// เพิ่ม/แก้ไขรายชื่อบันทึกผลการได้รับพระราชทานเครื่องราชย์อิสริยสภรณ์/การจ่ายใบกำกับ
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("note/{insigniaNoteId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> AddNoteProfile([FromBody] InsigniaNoteRequest req, Guid insigniaNoteId)
|
||||
{
|
||||
var profile = await _context.Profiles
|
||||
.Include(x => x.Salaries)
|
||||
.FirstOrDefaultAsync(x => x.CitizenId == req.CitizanId);
|
||||
if (profile == null)
|
||||
return Error(GlobalMessages.DataNotFound);
|
||||
var insignia = await _context.Insignias
|
||||
.FirstOrDefaultAsync(x => x.Id == req.InsigniaId);
|
||||
if (insignia == null)
|
||||
return Error(GlobalMessages.InsigniaNotFound);
|
||||
var insigniaNote = await _context.InsigniaNotes
|
||||
.Include(x => x.InsigniaNoteProfiles)
|
||||
.ThenInclude(x => x.Profile)
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaNoteId);
|
||||
if (insigniaNote == null)
|
||||
return Error(GlobalMessages.InsigniaRequestNotFound);
|
||||
|
||||
var profileInsignia = insigniaNote.InsigniaNoteProfiles.FirstOrDefault(x => x.Profile.CitizenId == req.CitizanId);
|
||||
if (profileInsignia == null)
|
||||
{
|
||||
await _context.InsigniaNoteProfiles.AddAsync(new InsigniaNoteProfile
|
||||
{
|
||||
Salary = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount,
|
||||
IsApprove = true,
|
||||
Status = "PENDING",
|
||||
Profile = profile,
|
||||
Issue = req.Issue,
|
||||
Number = req.Number,
|
||||
DateReceive = req.DateReceive,
|
||||
Date = req.Date,
|
||||
VolumeNo = req.VolumeNo,
|
||||
Section = req.Section,
|
||||
Page = req.Page,
|
||||
No = req.No,
|
||||
DatePayment = req.DatePayment,
|
||||
TypePayment = req.TypePayment,
|
||||
Address = req.Address,
|
||||
RequestInsignia = insignia,
|
||||
OrganizationOrganizationSend = await _context.OrganizationOrganizations.FirstOrDefaultAsync(x => x.Id == profile.OrganizationOrganizationId),
|
||||
InsigniaNote = insigniaNote,
|
||||
CreatedUserId = FullName ?? "",
|
||||
CreatedFullName = UserId ?? "System Administrator",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
profileInsignia.Issue = req.Issue;
|
||||
profileInsignia.Number = req.Number;
|
||||
profileInsignia.DateReceive = req.DateReceive;
|
||||
profileInsignia.Date = req.Date;
|
||||
profileInsignia.VolumeNo = req.VolumeNo;
|
||||
profileInsignia.Section = req.Section;
|
||||
profileInsignia.Page = req.Page;
|
||||
profileInsignia.No = req.No;
|
||||
profileInsignia.DatePayment = req.DatePayment;
|
||||
profileInsignia.TypePayment = req.TypePayment;
|
||||
profileInsignia.Address = req.Address;
|
||||
profileInsignia.RequestInsignia = insignia;
|
||||
profileInsignia.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
profileInsignia.LastUpdateUserId = UserId ?? "";
|
||||
profileInsignia.LastUpdatedAt = DateTime.Now;
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// เพิ่มเอกสารบันทึกผลการได้รับพระราชทานเครื่องราชย์อิสริยสภรณ์/การจ่ายใบกำกับ
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("note/doc/{insigniaNoteId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> AddDocumentProfile([FromForm] InsigniaNoteDocRequest req, Guid insigniaNoteId)
|
||||
{
|
||||
var insigniaNote = await _context.InsigniaNotes
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaNoteId);
|
||||
if (insigniaNote == null)
|
||||
return Error(GlobalMessages.InsigniaRequestNotFound);
|
||||
|
||||
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
|
||||
{
|
||||
foreach (var file in Request.Form.Files)
|
||||
{
|
||||
var fileExtension = Path.GetExtension(file.FileName);
|
||||
|
||||
var doc = await _documentService.UploadFileAsync(file, req.Name == null ? file.FileName : req.Name);
|
||||
var _doc = await _context.Documents.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == doc.Id);
|
||||
if (_doc != null)
|
||||
{
|
||||
await _context.InsigniaNoteDocs.AddAsync(new InsigniaNoteDoc
|
||||
{
|
||||
Reason = req.Reason,
|
||||
Document = _doc,
|
||||
InsigniaNote = insigniaNote,
|
||||
CreatedUserId = FullName ?? "",
|
||||
CreatedFullName = UserId ?? "System Administrator",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List เอกสารบันทึกผลการได้รับพระราชทานเครื่องราชย์อิสริยสภรณ์/การจ่ายใบกำกับ
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("note/doc/{insigniaNoteId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetDocumentProfile([FromBody] InsigniaNoteDocRequest req, Guid insigniaNoteId)
|
||||
{
|
||||
var insigniaNote = await _context.InsigniaNotes
|
||||
.Include(x => x.InsigniaNoteDocs)
|
||||
.ThenInclude(x => x.Document)
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaNoteId);
|
||||
if (insigniaNote == null)
|
||||
return Error(GlobalMessages.InsigniaRequestNotFound);
|
||||
var insigniaNoteDocs = new List<dynamic>();
|
||||
foreach (var doc in insigniaNote.InsigniaNoteDocs)
|
||||
{
|
||||
var _doc = new
|
||||
{
|
||||
FileName = doc.Document.FileName,
|
||||
PathName = await _documentService.ImagesPath(doc.Document.Id)
|
||||
};
|
||||
insigniaNoteDocs.Add(_doc);
|
||||
}
|
||||
return Success(insigniaNoteDocs);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue