fix : เปลี่ยนชื่อ Folder + Project เอาคำว่า Service ออก เพื่อให้สามารถ run บน macOS Sonoma ได้ (ไม่เปลี่ยนจะไม่สามารถ run ได้ เนื่องจาก macOS จะมองว่าเป็น application ของ mac)
This commit is contained in:
parent
9d90c98800
commit
59340500b7
42 changed files with 21614 additions and 3532 deletions
721
BMA.EHR.Insignia/Controllers/InsigniaManageController.cs
Normal file
721
BMA.EHR.Insignia/Controllers/InsigniaManageController.cs
Normal file
|
|
@ -0,0 +1,721 @@
|
|||
using System.Security.Claims;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Repositories.MessageQueue;
|
||||
using BMA.EHR.Application.Requests;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Models.Insignias;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
|
||||
using Newtonsoft.Json;
|
||||
using OfficeOpenXml.Export.ToDataTable;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/insignia/manage")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
[SwaggerTag("จัดสรรเครื่องราชฯ")]
|
||||
public class InsigniaManageController : BaseController
|
||||
{
|
||||
private readonly ApplicationDBContext _context;
|
||||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly InsigniaPeriodsRepository _repository;
|
||||
private readonly NotificationRepository _repositoryNoti;
|
||||
private readonly UserProfileRepository _userProfileRepository;
|
||||
|
||||
public InsigniaManageController(ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
InsigniaPeriodsRepository repository,
|
||||
NotificationRepository repositoryNoti,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
UserProfileRepository userProfileRepository)
|
||||
{
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_repository = repository;
|
||||
_repositoryNoti = repositoryNoti;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_userProfileRepository = userProfileRepository;
|
||||
}
|
||||
|
||||
#region " Properties "
|
||||
|
||||
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
||||
|
||||
private string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// list จัดสรรเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <param name="year">ปีการจัดสรร</param>
|
||||
/// <param name="insigniaTypeId">Id ประเภทเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("type/{year}/{insigniaTypeId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetList(int year, Guid insigniaTypeId)
|
||||
{
|
||||
var insigniaType = await _context.InsigniaTypes
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaTypeId);
|
||||
if (insigniaType == null)
|
||||
return Error(GlobalMessages.InsigniaTypeNotFound);
|
||||
var data = await _context.InsigniaManages.AsQueryable()
|
||||
.Where(x => x.Insignia.InsigniaType == insigniaType)
|
||||
.Where(x => x.Year == year)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(p => new
|
||||
{
|
||||
Id = p.Id,
|
||||
Insignia = p.Insignia.Name,
|
||||
InsigniaId = p.Insignia.Id,
|
||||
Year = p.Year,
|
||||
Total = p.Total,
|
||||
Allocate = p.InsigniaManageOrganiations.Sum(x => x.Total),
|
||||
Remain = p.Total - p.InsigniaManageOrganiations.Sum(x => x.Total),
|
||||
LastUpdatedAt = p.LastUpdatedAt,
|
||||
CreatedAt = p.CreatedAt,
|
||||
})
|
||||
.ToListAsync();
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get รายละเอียดจัดสรรเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageId">Id จัดสรรเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("{insigniaManageId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetById(Guid insigniaManageId)
|
||||
{
|
||||
var data = await _context.InsigniaManages.AsQueryable()
|
||||
.Where(x => x.Id == insigniaManageId)
|
||||
.Select(p => new
|
||||
{
|
||||
Id = p.Id,
|
||||
Insignia = p.Insignia.Name,
|
||||
InsigniaId = p.Insignia.Id,
|
||||
Year = p.Year,
|
||||
Total = p.Total,
|
||||
LastUpdatedAt = p.LastUpdatedAt,
|
||||
CreatedAt = p.CreatedAt,
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
if (data == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound, 404);
|
||||
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// สร้างจัดสรรเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost()]
|
||||
public async Task<ActionResult<ResponseObject>> Post([FromBody] InsigniaManageRequest req)
|
||||
{
|
||||
var insignia = await _context.Insignias.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == req.Insignia);
|
||||
if (insignia == null)
|
||||
return Error(GlobalMessages.InsigniaNotFound);
|
||||
|
||||
var insigniaManage = await _context.InsigniaManages.AsQueryable()
|
||||
.Where(x => x.Insignia == insignia && x.Year == req.Year)
|
||||
.FirstOrDefaultAsync();
|
||||
if (insigniaManage != null)
|
||||
return Error(GlobalMessages.InsigniaManageDupicate);
|
||||
|
||||
await _context.InsigniaManages.AddAsync(
|
||||
new InsigniaManage
|
||||
{
|
||||
Insignia = insignia,
|
||||
Year = req.Year,
|
||||
Total = req.Total,
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ลบจัดสรรเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageId">Id จัดสรรเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpDelete("{insigniaManageId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> Delete(Guid insigniaManageId)
|
||||
{
|
||||
var deleted = await _context.InsigniaManages.AsQueryable()
|
||||
.Where(x => x.Id == insigniaManageId)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (deleted == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
_context.InsigniaManages.Remove(deleted);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// แก้ไขจัดสรรเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageId">Id จัดสรรเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("{insigniaManageId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> Put([FromBody] InsigniaManageRequest req, Guid insigniaManageId)
|
||||
{
|
||||
var insignia = await _context.Insignias.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == req.Insignia);
|
||||
if (insignia == null)
|
||||
return Error(GlobalMessages.InsigniaNotFound);
|
||||
|
||||
var insigniaManage = await _context.InsigniaManages.AsQueryable()
|
||||
.Where(x => x.Insignia == insignia && x.Year == req.Year && x.Id != insigniaManageId)
|
||||
.FirstOrDefaultAsync();
|
||||
if (insigniaManage != null)
|
||||
return Error(GlobalMessages.InsigniaManageDupicate);
|
||||
|
||||
var uppdated = await _context.InsigniaManages.AsQueryable()
|
||||
.Include(x => x.Insignia)
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaManageId);
|
||||
if (uppdated == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
|
||||
uppdated.Insignia = insignia;
|
||||
// uppdated.Year = req.Year;
|
||||
uppdated.Total = req.Total;
|
||||
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
uppdated.LastUpdateUserId = UserId ?? "";
|
||||
uppdated.LastUpdatedAt = DateTime.Now;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// list หน่วยงานจัดสรรเครื่องราชอิสริยาภรณ์
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageId">Id จัดสรรเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("org/{insigniaManageId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetListOrganization(Guid insigniaManageId)
|
||||
{
|
||||
var insigniaManage = await _context.InsigniaManages.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaManageId);
|
||||
if (insigniaManage == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
|
||||
var insigniaManageOrg = await _context.InsigniaManageOrganiations.AsQueryable()
|
||||
.Where(x => x.InsigniaManage == insigniaManage)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(p => new
|
||||
{
|
||||
Id = p.Id,
|
||||
OrganizationOrganization = _userProfileRepository.GetOc(p.OrganizationId, 0, AccessToken) == null ? "" : _userProfileRepository.GetOc(p.OrganizationId, 0, AccessToken)!.Root,
|
||||
Total = p.Total,
|
||||
Allocate = p.InsigniaManageProfiles.Where(x => x.Status == false).Count(),
|
||||
Remain = p.Total - p.InsigniaManageProfiles.Where(x => x.Status == false).Count(),
|
||||
LastUpdatedAt = p.LastUpdatedAt,
|
||||
CreatedAt = p.CreatedAt,
|
||||
})
|
||||
.ToListAsync();
|
||||
return Success(insigniaManageOrg);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// สร้างหน่วยงานจัดสรรเครื่องราชอิสริยาภรณ์
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost("org")]
|
||||
public async Task<ActionResult<ResponseObject>> PostOrganization([FromBody] InsigniaManageOrganizationRequest req)
|
||||
{
|
||||
|
||||
var organization = _userProfileRepository.GetOc(req.OrganizationOrganizationId, 0, AccessToken);
|
||||
|
||||
//var organization = await _context.Organizations.AsQueryable()
|
||||
// .Include(x => x.OrganizationOrganization)
|
||||
// .FirstOrDefaultAsync(x => x.Id == req.OrganizationOrganizationId);
|
||||
if (organization == null)
|
||||
return Error(GlobalMessages.OrganizationNotFound);
|
||||
//if (organization.OrganizationOrganization == null)
|
||||
// return Error(GlobalMessages.OrganizationNotFound);
|
||||
|
||||
var insigniaManage = await _context.InsigniaManages.AsQueryable()
|
||||
.Include(x => x.InsigniaManageOrganiations)
|
||||
//.ThenInclude(x => x.OrganizationOrganization)
|
||||
.FirstOrDefaultAsync(x => x.Id == req.insigniaManageId);
|
||||
if (insigniaManage == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
|
||||
var insigniaManageOrganiation = await _context.InsigniaManageOrganiations.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.OrganizationId == organization.RootId && x.InsigniaManage == insigniaManage);
|
||||
if (insigniaManageOrganiation != null)
|
||||
return Error(GlobalMessages.InsigniaManageOrgDupicate);
|
||||
|
||||
var total = insigniaManage.InsigniaManageOrganiations.Where(x => x.OrganizationId != organization.RootId).Sum(x => x.Total);
|
||||
if (req.Total + total > insigniaManage.Total)
|
||||
return Error(GlobalMessages.InsigniaManageOrgLimit);
|
||||
await _context.InsigniaManageOrganiations.AddAsync(
|
||||
new InsigniaManageOrganiation
|
||||
{
|
||||
//OrganizationOrganization = organization.OrganizationOrganization,
|
||||
OrganizationId = organization.RootId ?? Guid.Empty,
|
||||
Total = req.Total,
|
||||
InsigniaManage = insigniaManage,
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ลบหน่วยงานจัดสรรเครื่องราชอิสริยาภรณ์
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageOrgId">Id หน่วยงานจัดสรรเครื่องราชอิสริยาภรณ์</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpDelete("org/{insigniaManageOrgId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> DeleteOrganization(Guid insigniaManageOrgId)
|
||||
{
|
||||
var deleted = await _context.InsigniaManageOrganiations.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaManageOrgId);
|
||||
|
||||
if (deleted == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
_context.InsigniaManageOrganiations.Remove(deleted);
|
||||
await _context.SaveChangesAsync();
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// แก้ไขหน่วยงานจัดสรรเครื่องราชอิสริยาภรณ์
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageOrgId">Id หน่วยงานจัดสรรเครื่องราชอิสริยาภรณ์</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("org/{insigniaManageOrgId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> PutOrganization([FromBody] InsigniaManageOrganizationUpdateRequest req, Guid insigniaManageOrgId)
|
||||
{
|
||||
var uppdated = await _context.InsigniaManageOrganiations.AsQueryable()
|
||||
//.Include(x => x.OrganizationOrganization)
|
||||
.Include(x => x.InsigniaManage)
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaManageOrgId);
|
||||
if (uppdated == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
|
||||
var insigniaManage = await _context.InsigniaManages.AsQueryable()
|
||||
.Include(x => x.InsigniaManageOrganiations)
|
||||
//.ThenInclude(x => x.OrganizationOrganization)
|
||||
.FirstOrDefaultAsync(x => x.Id == uppdated.InsigniaManage.Id);
|
||||
if (insigniaManage == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
var total = insigniaManage.InsigniaManageOrganiations.Where(x => x.Id != insigniaManageOrgId).Sum(x => x.Total);
|
||||
if (req.Total + total > insigniaManage.Total)
|
||||
return Error(GlobalMessages.InsigniaManageOrgLimit);
|
||||
|
||||
uppdated.Total = req.Total;
|
||||
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
uppdated.LastUpdateUserId = UserId ?? "";
|
||||
uppdated.LastUpdatedAt = DateTime.Now;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// list dashboard หน่วยงานจัดสรรเครื่องราชอิสริยาภรณ์
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageId">Id จัดสรรเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("org/dashboard/{insigniaManageId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetListDashboardOrganization(Guid insigniaManageId)
|
||||
{
|
||||
var insigniaManage = await _context.InsigniaManages.AsQueryable()
|
||||
.Include(x => x.InsigniaManageOrganiations)
|
||||
.Select(p => new
|
||||
{
|
||||
Id = p.Id,
|
||||
Insignia = p.Insignia.Name,
|
||||
InsigniaId = p.Insignia.Id,
|
||||
Year = p.Year,
|
||||
Total = p.Total,
|
||||
Allocate = p.InsigniaManageOrganiations.Sum(x => x.Total),
|
||||
Remain = p.Total - p.InsigniaManageOrganiations.Sum(x => x.Total),
|
||||
LastUpdatedAt = p.LastUpdatedAt,
|
||||
CreatedAt = p.CreatedAt,
|
||||
})
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaManageId);
|
||||
if (insigniaManage == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
|
||||
return Success(insigniaManage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ยืมเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost("borrow")]
|
||||
public async Task<ActionResult<ResponseObject>> PostBorrowInsignia([FromBody] InsigniaBorrowRequest req)
|
||||
{
|
||||
|
||||
var insigniaNoteProfile = await _context.InsigniaNoteProfiles.AsQueryable()
|
||||
.Include(x => x.RequestInsignia)
|
||||
.Include(x => x.InsigniaNote)
|
||||
//.Include(x => x.Profile)
|
||||
.FirstOrDefaultAsync(x => x.Id == req.InsigniaNoteProfileId);
|
||||
if (insigniaNoteProfile == null)
|
||||
return Error(GlobalMessages.InsigniaRequestProfileNotFound);
|
||||
if (insigniaNoteProfile.Status != "DONE")
|
||||
return Error(GlobalMessages.InsigniaNoBorrow);
|
||||
|
||||
//var _organization = await _context.Organizations.AsQueryable()
|
||||
// .FirstOrDefaultAsync(x => x.Id == insigniaNoteProfile.Profile.OcId);
|
||||
|
||||
//TODO : Hardcode OCId
|
||||
if (req.BorrowOrganizationId == null) req.BorrowOrganizationId = Guid.Parse("e8493cd1-d371-402e-add6-566e68d5d1b3");
|
||||
|
||||
var organization = _userProfileRepository.GetOc(req.BorrowOrganizationId.Value, 0, AccessToken);
|
||||
//if (organization == null)
|
||||
// return Error(GlobalMessages.OrganizationNotFound);
|
||||
|
||||
//var organization = await _context.Organizations.AsQueryable()
|
||||
// .Include(x => x.OrganizationOrganization)
|
||||
// .FirstOrDefaultAsync(x => x.Id == _organization.OrganizationAgencyId);
|
||||
//if (organization == null)
|
||||
// return Error(GlobalMessages.OrganizationNotFound);
|
||||
|
||||
var insigniaManage = await _context.InsigniaManages.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Year == insigniaNoteProfile.InsigniaNote.Year && x.Insignia == insigniaNoteProfile.RequestInsignia);
|
||||
if (insigniaManage == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
|
||||
var insigniaManageOrganiation = await _context.InsigniaManageOrganiations.AsQueryable()
|
||||
.Include(x => x.InsigniaManageProfiles)
|
||||
.FirstOrDefaultAsync(x => x.OrganizationId == organization.RootId && x.InsigniaManage == insigniaManage);
|
||||
if (insigniaManageOrganiation == null)
|
||||
return Error(GlobalMessages.InsigniaManageOrgNotFound);
|
||||
|
||||
var insigniaManageProfile = await _context.InsigniaManageProfiles.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.InsigniaNoteProfile == insigniaNoteProfile && x.Status == false);
|
||||
if (insigniaManageProfile != null)
|
||||
return Error(GlobalMessages.InsigniaNotReturn);
|
||||
|
||||
if (insigniaManageOrganiation.Total <= insigniaManageOrganiation.InsigniaManageProfiles.Count())
|
||||
return Error(GlobalMessages.InsigniaBorrowOrgLimit);
|
||||
|
||||
await _context.InsigniaManageProfiles.AddAsync(
|
||||
new InsigniaManageProfile
|
||||
{
|
||||
Status = false,
|
||||
InsigniaManageOrganiation = insigniaManageOrganiation,
|
||||
BorrowOrganizationId = organization.RootId,
|
||||
BorrowDate = req.BorrowDate,
|
||||
InsigniaNoteProfile = insigniaNoteProfile,
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// คืนเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageProfileId">Id ยืมเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("return/{insigniaManageProfileId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> PutReturnInsignia([FromBody] InsigniaReturnRequest req, Guid insigniaManageProfileId)
|
||||
{
|
||||
|
||||
var uppdated = await _context.InsigniaManageProfiles.AsQueryable()
|
||||
//.Include(x => x.BorrowOrganization)
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaManageProfileId);
|
||||
if (uppdated == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
|
||||
uppdated.Status = true;
|
||||
uppdated.ReturnDate = req.ReturnDate;
|
||||
// if (req.ReturnOrganizationId == Guid.Parse("00000000-0000-0000-0000-000000000000"))
|
||||
// {
|
||||
uppdated.ReturnOrganizationId = uppdated.BorrowOrganizationId;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var organization = await _context.Organizations.AsQueryable()
|
||||
// .Include(x => x.OrganizationOrganization)
|
||||
// .FirstOrDefaultAsync(x => x.Id == req.ReturnOrganizationId);
|
||||
// if (organization == null)
|
||||
// return Error(GlobalMessages.OrganizationNotFound);
|
||||
// uppdated.ReturnOrganization = organization.OrganizationOrganization;
|
||||
// }
|
||||
uppdated.ReturnReason = req.ReturnReason;
|
||||
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
uppdated.LastUpdateUserId = UserId ?? "";
|
||||
uppdated.LastUpdatedAt = DateTime.Now;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// list รายการยืม/คืนเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <param name="year">ปียืมขอ</param>
|
||||
/// <param name="insigniaTypeId">Id ประเภทเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("borrow/{year}/{insigniaTypeId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> ListBorrowReturnInsignia(int year, Guid insigniaTypeId)
|
||||
{
|
||||
var insigniaType = await _context.InsigniaTypes
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaTypeId);
|
||||
if (insigniaType == null)
|
||||
return Error(GlobalMessages.InsigniaTypeNotFound);
|
||||
|
||||
|
||||
var rawData = await _context.InsigniaManageProfiles.AsQueryable()
|
||||
.Where(x => x.InsigniaNoteProfile.RequestInsignia.InsigniaType == insigniaType)
|
||||
.Where(x => year == 0 ? x.Id != null : x.InsigniaManageOrganiation.InsigniaManage.Year == year)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(p => new
|
||||
{
|
||||
Id = p.Id,
|
||||
BorrowOrganization = p.BorrowOrganizationId == null ? null : _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken),
|
||||
ReturnOrganization = p.ReturnOrganizationId == null ? null : _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken),
|
||||
Profile = p.InsigniaNoteProfile.ProfileId == null ? null : _userProfileRepository.GetOfficerProfileById(p.InsigniaNoteProfile.ProfileId.Value, AccessToken),
|
||||
|
||||
Status = p.Status,
|
||||
BorrowDate = p.BorrowDate,
|
||||
ReturnDate = p.ReturnDate,
|
||||
ReturnReason = p.ReturnReason,
|
||||
LastUpdatedAt = p.LastUpdatedAt,
|
||||
CreatedAt = p.CreatedAt,
|
||||
|
||||
InsigniaNoteProfileId = p.InsigniaNoteProfile.Id,
|
||||
RequestInsignia = p.InsigniaNoteProfile.RequestInsignia == null ? null : p.InsigniaNoteProfile.RequestInsignia.Name,
|
||||
RequestInsigniaId = p.InsigniaNoteProfile.RequestInsignia == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.InsigniaNoteProfile.RequestInsignia.Id,
|
||||
RequestInsigniaShortName = p.InsigniaNoteProfile.RequestInsignia == null ? null : p.InsigniaNoteProfile.RequestInsignia.ShortName,
|
||||
p.InsigniaNoteProfile.DateReceive,
|
||||
p.InsigniaNoteProfile.OrganizationOrganizationSend,
|
||||
p.InsigniaNoteProfile.OrganizationOrganizationReceive,
|
||||
InsigniaNoteProfileStatus = p.InsigniaNoteProfile.Status,
|
||||
p.InsigniaNoteProfile.Issue,
|
||||
p.InsigniaNoteProfile.Date,
|
||||
p.InsigniaNoteProfile.VolumeNo,
|
||||
p.InsigniaNoteProfile.Section,
|
||||
p.InsigniaNoteProfile.Page,
|
||||
p.InsigniaNoteProfile.No,
|
||||
p.InsigniaNoteProfile.DatePayment,
|
||||
p.InsigniaNoteProfile.TypePayment,
|
||||
p.InsigniaNoteProfile.Address,
|
||||
p.InsigniaNoteProfile.Number,
|
||||
p.InsigniaNoteProfile.Salary,
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var data = rawData
|
||||
.Select(p => new
|
||||
{
|
||||
p.Id,
|
||||
p.Status,
|
||||
BorrowOrganization = p.BorrowOrganization == null ? "" : p.BorrowOrganization.Root,
|
||||
BorrowOrganizationId = p.BorrowOrganization == null ? Guid.Empty : p.BorrowOrganization.RootId,
|
||||
p.BorrowDate,
|
||||
p.ReturnDate,
|
||||
ReturnOrganization = p.ReturnOrganization == null ? "" : p.ReturnOrganization.Root,
|
||||
ReturnOrganizationId = p.ReturnOrganization == null ? Guid.Empty : p.ReturnOrganization.RootId,
|
||||
p.ReturnReason,
|
||||
p.LastUpdatedAt,
|
||||
p.CreatedAt,
|
||||
p.InsigniaNoteProfileId,
|
||||
CitizenId = p.Profile == null ? "" : p.Profile.CitizenId,
|
||||
Prefix = p.Profile == null ? "" : p.Profile.Prefix,
|
||||
Position = p.Profile == null ? "" : p.Profile.Position,
|
||||
FullName = p.Profile == null ? "" : $"{p.Profile.Prefix}{p.Profile.FirstName} {p.Profile.LastName}",
|
||||
ProfileType = p.Profile == null ? "" : p.Profile.ProfileType,
|
||||
p.RequestInsignia,
|
||||
p.RequestInsigniaId,
|
||||
p.RequestInsigniaShortName,
|
||||
p.DateReceive,
|
||||
p.OrganizationOrganizationSend,
|
||||
p.OrganizationOrganizationReceive,
|
||||
p.InsigniaNoteProfileStatus,
|
||||
p.Issue,
|
||||
p.Date,
|
||||
p.VolumeNo,
|
||||
p.Section,
|
||||
p.Page,
|
||||
p.No,
|
||||
p.DatePayment,
|
||||
p.TypePayment,
|
||||
p.Address,
|
||||
p.Number,
|
||||
p.Salary,
|
||||
|
||||
})
|
||||
.ToList();
|
||||
|
||||
//var data = await _context.InsigniaManageProfiles.AsQueryable()
|
||||
// .Where(x => x.InsigniaNoteProfile.RequestInsignia.InsigniaType == insigniaType)
|
||||
// .Where(x => year == 0 ? x.Id != null : x.InsigniaManageOrganiation.InsigniaManage.Year == year)
|
||||
// .OrderByDescending(x => x.CreatedAt)
|
||||
// .Select(p => new
|
||||
// {
|
||||
// Id = p.Id,
|
||||
// Status = p.Status,
|
||||
// BorrowOrganization = _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken) == null ? null : _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken).Root,
|
||||
// BorrowOrganizationId = _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken) == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken).RootId,
|
||||
// BorrowDate = p.BorrowDate,
|
||||
// ReturnDate = p.ReturnDate,
|
||||
// ReturnOrganization = _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken) == null ? null : _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken).Root,
|
||||
// ReturnOrganizationId = _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken) == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken).RootId,
|
||||
// ReturnReason = p.ReturnReason,
|
||||
// LastUpdatedAt = p.LastUpdatedAt,
|
||||
// CreatedAt = p.CreatedAt,
|
||||
|
||||
// InsigniaNoteProfileId = p.InsigniaNoteProfile.Id,
|
||||
// Prefix = _userProfileRepository.GetOfficerProfileById(p.InsigniaNoteProfile.ProfileId.Value, AccessToken).Prefix,
|
||||
// Position = _userProfileRepository.GetOfficerProfileById(p.InsigniaNoteProfile.ProfileId.Value, AccessToken).Position,
|
||||
// _userProfileRepository.GetOfficerProfileById(p.InsigniaNoteProfile.ProfileId.Value, AccessToken).CitizenId,
|
||||
// _userProfileRepository.GetOfficerProfileById(p.InsigniaNoteProfile.ProfileId.Value, AccessToken).ProfileType,
|
||||
// FullName = $"{_userProfileRepository.GetOfficerProfileById(p.InsigniaNoteProfile.ProfileId.Value, AccessToken).Prefix}{_userProfileRepository.GetOfficerProfileById(p.InsigniaNoteProfile.ProfileId.Value, AccessToken).FirstName} {_userProfileRepository.GetOfficerProfileById(p.InsigniaNoteProfile.ProfileId.Value, AccessToken).LastName}",
|
||||
// RequestInsignia = p.InsigniaNoteProfile.RequestInsignia == null ? null : p.InsigniaNoteProfile.RequestInsignia.Name,
|
||||
// RequestInsigniaId = p.InsigniaNoteProfile.RequestInsignia == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.InsigniaNoteProfile.RequestInsignia.Id,
|
||||
// RequestInsigniaShortName = p.InsigniaNoteProfile.RequestInsignia == null ? null : p.InsigniaNoteProfile.RequestInsignia.ShortName,
|
||||
// p.InsigniaNoteProfile.DateReceive,
|
||||
// p.InsigniaNoteProfile.OrganizationOrganizationSend,
|
||||
// p.InsigniaNoteProfile.OrganizationOrganizationReceive,
|
||||
// InsigniaNoteProfileStatus = p.InsigniaNoteProfile.Status,
|
||||
// p.InsigniaNoteProfile.Issue,
|
||||
// p.InsigniaNoteProfile.Date,
|
||||
// p.InsigniaNoteProfile.VolumeNo,
|
||||
// p.InsigniaNoteProfile.Section,
|
||||
// p.InsigniaNoteProfile.Page,
|
||||
// p.InsigniaNoteProfile.No,
|
||||
// p.InsigniaNoteProfile.DatePayment,
|
||||
// p.InsigniaNoteProfile.TypePayment,
|
||||
// p.InsigniaNoteProfile.Address,
|
||||
// p.InsigniaNoteProfile.Number,
|
||||
// p.InsigniaNoteProfile.Salary,
|
||||
// })
|
||||
// .ToListAsync();
|
||||
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get รายการยืม/คืนเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageProfileId">Id ประเภทเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("borrow/{insigniaManageProfileId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetBorrowReturnInsignia(Guid insigniaManageProfileId)
|
||||
{
|
||||
var data = await _context.InsigniaManageProfiles.AsQueryable()
|
||||
.Where(x => x.Id == insigniaManageProfileId)
|
||||
.Select(p => new
|
||||
{
|
||||
Id = p.Id,
|
||||
Status = p.Status,
|
||||
BorrowOrganization = _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken) == null ? null : _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken).Root,
|
||||
BorrowOrganizationId = _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken) == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken).RootId,
|
||||
BorrowDate = p.BorrowDate,
|
||||
ReturnDate = p.ReturnDate,
|
||||
ReturnOrganization = _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken) == null ? null : _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken).Root,
|
||||
ReturnOrganizationId = _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken) == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken).RootId,
|
||||
ReturnReason = p.ReturnReason,
|
||||
LastUpdatedAt = p.LastUpdatedAt,
|
||||
CreatedAt = p.CreatedAt,
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
if (data == null)
|
||||
return Error(GlobalMessages.InsigniaBorrowNotFound);
|
||||
return Success(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
294
BMA.EHR.Insignia/Controllers/InsigniaPeriodController.cs
Normal file
294
BMA.EHR.Insignia/Controllers/InsigniaPeriodController.cs
Normal file
|
|
@ -0,0 +1,294 @@
|
|||
using System.Security.Claims;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Repositories.MessageQueue;
|
||||
using BMA.EHR.Application.Requests;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Models.Insignias;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/insignia/period")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
[SwaggerTag("รอบเครื่องราชฯ")]
|
||||
public class InsigniaPeriodController : BaseController
|
||||
{
|
||||
private readonly ApplicationDBContext _context;
|
||||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly InsigniaPeriodsRepository _repository;
|
||||
private readonly NotificationRepository _repositoryNoti;
|
||||
|
||||
public InsigniaPeriodController(ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
InsigniaPeriodsRepository repository,
|
||||
NotificationRepository repositoryNoti,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_repository = repository;
|
||||
_repositoryNoti = repositoryNoti;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
#region " Properties "
|
||||
|
||||
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// list รอบเครื่องราช
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet()]
|
||||
public async Task<ActionResult<ResponseObject>> GetList()
|
||||
{
|
||||
var insigniaPeriods = await _context.InsigniaPeriods.AsQueryable()
|
||||
// .Where(x => x.Type == type)
|
||||
.OrderByDescending(x => x.Year)
|
||||
.ThenByDescending(x => x.StartDate)
|
||||
.Select(p => new
|
||||
{
|
||||
period_id = p.Id,
|
||||
period_amount = p.Amount,
|
||||
period_name = p.Name,
|
||||
period_round = p.Round,
|
||||
period_start = p.StartDate,
|
||||
period_end = p.EndDate,
|
||||
period_status = p.IsLock == true ? "DONE" : (p.InsigniaRequests.Count() == 0 ? "WAITTING" : "PENDING"),
|
||||
period_year = p.Year,
|
||||
period_isActive = p.IsActive,
|
||||
period_doc = p.ReliefDoc == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.ReliefDoc.Id,
|
||||
})
|
||||
.ToListAsync();
|
||||
var data = new List<dynamic>();
|
||||
foreach (var insigniaPeriod in insigniaPeriods)
|
||||
{
|
||||
var _data = new
|
||||
{
|
||||
period_id = insigniaPeriod.period_id,
|
||||
period_amount = insigniaPeriod.period_amount,
|
||||
period_name = insigniaPeriod.period_name,
|
||||
period_round = insigniaPeriod.period_round,
|
||||
period_start = insigniaPeriod.period_start,
|
||||
period_end = insigniaPeriod.period_end,
|
||||
period_status = insigniaPeriod.period_status,
|
||||
period_year = insigniaPeriod.period_year,
|
||||
period_isActive = insigniaPeriod.period_isActive,
|
||||
period_doc = insigniaPeriod.period_doc == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(insigniaPeriod.period_doc),
|
||||
};
|
||||
data.Add(_data);
|
||||
}
|
||||
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get รายละเอียดรอบเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="id">Id เครื่องราช</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetById(Guid id)
|
||||
{
|
||||
var data = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Where(x => x.Id == id)
|
||||
.Select(p => new
|
||||
{
|
||||
period_id = p.Id,
|
||||
period_amount = p.Amount,
|
||||
period_name = p.Name,
|
||||
period_round = p.Round,
|
||||
period_start = p.StartDate,
|
||||
period_end = p.EndDate,
|
||||
period_status = p.IsLock == true ? "DONE" : (p.InsigniaRequests.Count() == 0 ? "WAITTING" : "PENDING"),
|
||||
period_year = p.Year,
|
||||
period_isActive = p.IsActive,
|
||||
period_doc = p.ReliefDoc == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.ReliefDoc.Id,
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
if (data == null)
|
||||
return Error(GlobalMessages.DataNotFound, 404);
|
||||
|
||||
var _data = new
|
||||
{
|
||||
period_id = data.period_id,
|
||||
period_amount = data.period_amount,
|
||||
period_name = data.period_name,
|
||||
period_round = data.period_round,
|
||||
period_start = data.period_start,
|
||||
period_end = data.period_end,
|
||||
period_status = data.period_status,
|
||||
period_year = data.period_year,
|
||||
period_isActive = data.period_isActive,
|
||||
period_doc = data.period_doc == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.period_doc),
|
||||
};
|
||||
|
||||
return Success(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// สร้างรอบเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="req.Round">รอบที่</param>
|
||||
/// <param name="req.Name">ชื่อรอบ</param>
|
||||
/// <param name="req.Year">ปีที่เสนอ</param>
|
||||
/// <param name="req.StartDate">วันที่เริ่มต้น</param>
|
||||
/// <param name="req.EndDate">วันที่สิ้นสุด</param>
|
||||
/// <param name="req.Amount">จำนวนวันแจ้งเตือน</param>
|
||||
/// <param name="req.File">เอกสารประกอบ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[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)
|
||||
.FirstOrDefaultAsync();
|
||||
if (insigniaPeriod != null)
|
||||
return Error(GlobalMessages.InsigniaDupicate);
|
||||
|
||||
var period = new InsigniaPeriod
|
||||
{
|
||||
Round = req.Round,
|
||||
Name = req.Name,
|
||||
Year = req.Year,
|
||||
StartDate = req.StartDate,
|
||||
EndDate = req.EndDate,
|
||||
Amount = req.Amount,
|
||||
IsActive = true,
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
};
|
||||
await _context.InsigniaPeriods.AddAsync(period);
|
||||
await _context.SaveChangesAsync();
|
||||
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
|
||||
{
|
||||
var file = Request.Form.Files[0];
|
||||
var fileExtension = Path.GetExtension(file.FileName);
|
||||
|
||||
var doc = await _documentService.UploadFileAsync(file, file.FileName);
|
||||
period.ReliefDoc = doc;
|
||||
}
|
||||
|
||||
// await _context.InsigniaPeriods.AddAsync(period);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ลบรอบเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="id">Id เครื่องราช</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpDelete("{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> Delete(Guid id)
|
||||
{
|
||||
var deleted = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Include(x => x.ReliefDoc)
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
if (deleted == null)
|
||||
return NotFound();
|
||||
_context.InsigniaPeriods.Remove(deleted);
|
||||
await _context.SaveChangesAsync();
|
||||
if (deleted.ReliefDoc != null)
|
||||
await _documentService.DeleteFileAsync(deleted.ReliefDoc.Id);
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// แก้ไขรอบเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="id">Id เครื่องราช</param>
|
||||
/// <param name="req.Round">รอบที่</param>
|
||||
/// <param name="req.Name">ชื่อรอบ</param>
|
||||
/// <param name="req.Year">ปีที่เสนอ</param>
|
||||
/// <param name="req.StartDate">วันที่เริ่มต้น</param>
|
||||
/// <param name="req.EndDate">วันที่สิ้นสุด</param>
|
||||
/// <param name="req.Amount">จำนวนวันแจ้งเตือน</param>
|
||||
/// <param name="req.File">เอกสารประกอบ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> Put([FromForm] InsigniaPeriodRequest req, Guid id)
|
||||
{
|
||||
if (req == null)
|
||||
return BadRequest();
|
||||
|
||||
var insigniaPeriod = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Where(x => x.Round == req.Round && x.Year == req.Year && x.Id != id)
|
||||
.FirstOrDefaultAsync();
|
||||
if (insigniaPeriod != null)
|
||||
return Error(GlobalMessages.InsigniaDupicate);
|
||||
|
||||
var uppdated = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Include(x => x.ReliefDoc)
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
if (uppdated == null)
|
||||
return NotFound();
|
||||
|
||||
uppdated.Round = req.Round;
|
||||
uppdated.Name = req.Name;
|
||||
uppdated.Year = req.Year;
|
||||
uppdated.StartDate = req.StartDate;
|
||||
uppdated.EndDate = req.EndDate;
|
||||
uppdated.Amount = req.Amount;
|
||||
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
uppdated.LastUpdateUserId = UserId ?? "";
|
||||
uppdated.LastUpdatedAt = DateTime.Now;
|
||||
|
||||
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
|
||||
{
|
||||
if (uppdated.ReliefDoc != null)
|
||||
await _documentService.DeleteFileAsync(uppdated.ReliefDoc.Id);
|
||||
var file = Request.Form.Files[0];
|
||||
var fileExtension = Path.GetExtension(file.FileName);
|
||||
|
||||
var doc = await _documentService.UploadFileAsync(file, file.FileName);
|
||||
uppdated.ReliefDoc = doc;
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
}
|
||||
}
|
||||
248
BMA.EHR.Insignia/Controllers/InsigniaReceiveController.cs
Normal file
248
BMA.EHR.Insignia/Controllers/InsigniaReceiveController.cs
Normal file
|
|
@ -0,0 +1,248 @@
|
|||
using System.Security.Claims;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Repositories.MessageQueue;
|
||||
using BMA.EHR.Application.Requests;
|
||||
using BMA.EHR.Application.Responses.Insignias;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Models.Insignias;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/insignia/receive")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
[SwaggerTag("เครื่องราช")]
|
||||
public class InsigniaReceiveController : BaseController
|
||||
{
|
||||
private readonly ApplicationDBContext _context;
|
||||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly InsigniaPeriodsRepository _repository;
|
||||
private readonly NotificationRepository _repositoryNoti;
|
||||
|
||||
private readonly UserProfileRepository _userProfileRepository;
|
||||
|
||||
public InsigniaReceiveController(ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
InsigniaPeriodsRepository repository,
|
||||
NotificationRepository repositoryNoti,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
UserProfileRepository userProfileRepository)
|
||||
{
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_repository = repository;
|
||||
_repositoryNoti = repositoryNoti;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_userProfileRepository = userProfileRepository;
|
||||
}
|
||||
|
||||
private string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
|
||||
|
||||
[HttpGet("{type}/{ocId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetInsigniaList(string type, Guid id, Guid ocId)
|
||||
{
|
||||
var result = _repository.GetInsigniaRequest(id, ocId);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
// var request = _context.InsigniaRequestProfiles
|
||||
// .Include(x => x.Request)
|
||||
// .ThenInclude(x => x.Period)
|
||||
// .Include(x => x.RequestInsignia)
|
||||
// .ThenInclude(x => x.InsigniaType)
|
||||
// .Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.AcademicStanding)
|
||||
// .Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.Position)
|
||||
// .Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.Insignias)
|
||||
// .ThenInclude(x => x.Insignia)
|
||||
// .ThenInclude(x => x.InsigniaType)
|
||||
// .Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.PositionNumber)
|
||||
// .Where(x => x.Request.Period.Id == result.PeriodId)
|
||||
// .Where(x => x.Request.RequestStatus == "st5p")
|
||||
// .Where(x => x.IsApprove)
|
||||
// .Select(p => new
|
||||
// {
|
||||
// Profile = p.Profile.Id,
|
||||
// Name = $"{p.Profile.Prefix} {p.Profile.FirstName} {p.Profile.LastName}",
|
||||
// Insignia = p.RequestInsignia,
|
||||
// Type = p.RequestInsignia.InsigniaType,
|
||||
// IsApprove = p.IsApprove,
|
||||
// InsigniaId = p.RequestInsignia.Id,
|
||||
// Year = p.Request.Period.Year,
|
||||
// Special = p.Special,
|
||||
// LastInsignia = p.Profile.Insignias.AsQueryable()
|
||||
// .Include(x => x.Insignia)
|
||||
// .Where(x => x.Insignia.Id == p.RequestInsignia.Id)
|
||||
// .Where(x => x.Year == p.Request.Period.Year)
|
||||
// .FirstOrDefault()
|
||||
// })
|
||||
// .ToList()
|
||||
// .Select(r => new InsigniaReceiveResponse
|
||||
// {
|
||||
// Profile = r.Profile,
|
||||
// Name = r.Name,
|
||||
// Insignia = r.Insignia.Name,
|
||||
// TypeId = r.Type == null ? null : r.Type.Id,
|
||||
// TypeName = r.Type == null ? "" : r.Type.Description,
|
||||
// IsApprove = r.IsApprove,
|
||||
// InsigniaId = r.InsigniaId,
|
||||
// InsigniaPage = r.LastInsignia == null ? "" : r.LastInsignia.Page,
|
||||
// InsigniaNo = r.LastInsignia == null ? "" : r.LastInsignia.No,
|
||||
// InsigniaIssue = r.LastInsignia == null ? "" : r.LastInsignia.Issue,
|
||||
// InsigniaVolumeno = r.LastInsignia == null ? "" : r.LastInsignia.VolumeNo,
|
||||
// InsigniaVolume = r.LastInsignia == null ? "" : r.LastInsignia.Volume,
|
||||
// InsigniaSection = r.LastInsignia == null ? "" : r.LastInsignia.Section,
|
||||
// InsigniaDatereceive = r.LastInsignia == null ? null : r.LastInsignia.DateReceive,
|
||||
// InsigniaDateannounce = r.LastInsignia == null ? null : r.LastInsignia.DateAnnounce,
|
||||
// Special = r.Special
|
||||
// })
|
||||
// .ToList()
|
||||
// .GroupBy(r => new { r.TypeId, r.TypeName })
|
||||
// .Select(r => new
|
||||
// {
|
||||
// TypeId = r.Key.TypeId,
|
||||
// InsigniaIssue = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaIssue : "",
|
||||
// InsigniaVolumeno = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaVolumeno : null,
|
||||
// InsigniaVolume = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaVolume : "",
|
||||
// InsigniaSection = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaSection : "",
|
||||
// InsigniaDatereceive = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaDatereceive : null,
|
||||
// InsigniaDateannounce = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaDateannounce : null,
|
||||
// TypeName = r.Key.TypeName,
|
||||
// Profile = r.Select(r => new
|
||||
// {
|
||||
// Profile = r.Profile,
|
||||
// Name = r.Name,
|
||||
// Insignia = r.Insignia,
|
||||
// InsigniaId = r.InsigniaId,
|
||||
// InsigniaPage = r.InsigniaPage,
|
||||
// InsigniaNo = r.InsigniaNo,
|
||||
// //Special = bool.Parse(r.Special)
|
||||
// }).ToList(),
|
||||
// Docs = new List<dynamic>()
|
||||
// });
|
||||
|
||||
return Success();
|
||||
// return Success(request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("{type}")]
|
||||
public async Task<ActionResult<ResponseObject>> SaveToProfile([FromBody] SaveToProfileRequest items, string type)
|
||||
{
|
||||
var item = new Kp7Item
|
||||
{
|
||||
InsigniaDatereceive = items.InsigniaDatereceive,
|
||||
InsigniaLevel = items.InsigniaLevel,
|
||||
InsigniaIssue = items.InsigniaIssue,
|
||||
InsigniaVolumeno = items.InsigniaVolumeno,
|
||||
InsigniaVolume = items.InsigniaVolume,
|
||||
InsigniaSection = items.InsigniaSection,
|
||||
InsigniaDateannounce = items.InsigniaDateannounce
|
||||
};
|
||||
|
||||
if (items.Profile.Count() != 0)
|
||||
{
|
||||
foreach(var p in items.Profile)
|
||||
{
|
||||
await _userProfileRepository.PostProfileInsigniaAsync(new PostProfileInsigniaDto
|
||||
{
|
||||
profileId = Guid.Parse(p.FkProfileId),
|
||||
year = item.InsigniaDateannounce.Value.Year,
|
||||
no = p.InsigniaNo,
|
||||
volume = item.InsigniaVolume,
|
||||
section = item.InsigniaSection,
|
||||
page = p.InsigniaPage,
|
||||
receiveDate = item.InsigniaDatereceive.Value,
|
||||
insigniaId = p.Kp7InsigniaId,
|
||||
dateAnnounce = item.InsigniaDateannounce.Value,
|
||||
issue = item.InsigniaIssue,
|
||||
volumeNo = item.InsigniaVolumeno.Value.ToString(),
|
||||
note = "",
|
||||
refCommandDate = null,
|
||||
refCommandNo = "",
|
||||
|
||||
}, AccessToken);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// foreach (var i in items.Profile)
|
||||
// {
|
||||
// var profile = _context.Profiles.AsQueryable()
|
||||
// .Include(x => x.Insignias)
|
||||
// .ThenInclude(x => x.Insignia)
|
||||
// .Where(x => x.Id == i.FkProfileId)
|
||||
// .FirstOrDefault();
|
||||
// if (profile != null)
|
||||
// {
|
||||
// var kp7 = profile.Insignias.AsQueryable()
|
||||
// .Where(x => x.Insignia.Id == i.Kp7InsigniaId)
|
||||
// .FirstOrDefault();
|
||||
|
||||
// if (kp7 != null)
|
||||
// {
|
||||
// // exit item update to database
|
||||
// kp7.DateReceive = items.InsigniaDatereceive.Value;
|
||||
// kp7.Level = items.InsigniaLevel;
|
||||
// kp7.Issue = items.InsigniaIssue;
|
||||
// kp7.VolumeNo = items.InsigniaVolumeno.Value.ToString();
|
||||
// kp7.Volume = items.InsigniaVolume;
|
||||
// kp7.Section = items.InsigniaSection;
|
||||
// kp7.DateAnnounce = items.InsigniaDateannounce.Value;
|
||||
// kp7.Page = i.InsigniaPage;
|
||||
// kp7.No = i.InsigniaNo;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // insert new item to kp7
|
||||
// var insignia_item = _context.Insignias.FirstOrDefault(x => x.Id == i.Kp7InsigniaId);
|
||||
// var result = _repository.GetInsigniaRequest(type, items.OCId);
|
||||
|
||||
// var period = _context.InsigniaPeriods.FirstOrDefault(x => x.Id == result.PeriodId);
|
||||
|
||||
// kp7 = new Models.HR.ProfileInsignia
|
||||
// {
|
||||
// Order = profile.Insignias.ToList().Count + 1,
|
||||
// Year = period.Year,
|
||||
// Insignia = insignia_item,
|
||||
// DateReceive = items.InsigniaDatereceive.Value,
|
||||
// DateStamp = DateTime.Now,
|
||||
// Level = items.InsigniaLevel,
|
||||
// Issue = items.InsigniaIssue,
|
||||
// VolumeNo = items.InsigniaVolumeno.Value.ToString(),
|
||||
// Volume = items.InsigniaVolume,
|
||||
// Section = items.InsigniaSection,
|
||||
// DateAnnounce = items.InsigniaDateannounce.Value,
|
||||
// Page = i.InsigniaPage,
|
||||
// No = i.InsigniaNo,
|
||||
// };
|
||||
// profile.Insignias.Add(kp7);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// return NotFound("Profile not found!!!");
|
||||
// }
|
||||
}
|
||||
//_context.SaveChanges();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
2524
BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs
Normal file
2524
BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue