issue #1291
This commit is contained in:
parent
e345331381
commit
01590c4894
11 changed files with 20571 additions and 11 deletions
|
|
@ -457,6 +457,226 @@ namespace BMA.EHR.Insignia.Service.Controllers
|
|||
return Success(insigniaManage);
|
||||
}
|
||||
|
||||
#region " เรียกคืน "
|
||||
|
||||
/// <summary>
|
||||
/// เรียกคืนเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost("reclaim")]
|
||||
public async Task<ActionResult<ResponseObject>> PostReclaimInsignia([FromBody] InsigniaReclaimRequest req)
|
||||
{
|
||||
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_INSIGNIA_BORROW");
|
||||
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
||||
if (jsonData["status"]?.ToString() != "200")
|
||||
{
|
||||
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
||||
}
|
||||
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.InsigniaNoReclaim);
|
||||
|
||||
await _context.InsigniaReclaimProfiles.AddAsync(
|
||||
new InsigniaReclaimProfile
|
||||
{
|
||||
ReclaimDate = req.ReclaimDate,
|
||||
ReclaimOrganizationId = insigniaNoteProfile.RootId,
|
||||
ReclaimOrganization = insigniaNoteProfile.Root,
|
||||
ReclaimReason = req.ReclaimNote,
|
||||
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>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("reclaim/{insigniaReclaimProfileId:guid}")]
|
||||
public async Task<ActionResult<ResponseObject>> PutReclaimInsignia([FromBody] UpdateInsigniaReclaimRequest req, Guid insigniaReclaimProfileId)
|
||||
{
|
||||
var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_INSIGNIA_BORROW");
|
||||
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
||||
if (jsonData["status"]?.ToString() != "200")
|
||||
{
|
||||
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
||||
}
|
||||
var uppdated = await _context.InsigniaReclaimProfiles.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaReclaimProfileId);
|
||||
if (uppdated == null)
|
||||
return Error(GlobalMessages.InsigniaReclaimNotFound);
|
||||
|
||||
uppdated.ReclaimDate = req.ReclaimDate;
|
||||
uppdated.ReclaimReason = req.ReclaimNote;
|
||||
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
uppdated.LastUpdateUserId = UserId ?? "";
|
||||
uppdated.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>
|
||||
[HttpDelete("reclaim/{insigniaReclaimProfileId:guid}")]
|
||||
public async Task<ActionResult<ResponseObject>> DeleteReclaimInsignia(Guid insigniaReclaimProfileId)
|
||||
{
|
||||
var getPermission = await _permission.GetPermissionAPIAsync("DELETE", "SYS_INSIGNIA_BORROW");
|
||||
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
||||
if (jsonData["status"]?.ToString() != "200")
|
||||
{
|
||||
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
||||
}
|
||||
var deleted = await _context.InsigniaReclaimProfiles.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaReclaimProfileId);
|
||||
if (deleted == null)
|
||||
return Error(GlobalMessages.InsigniaReclaimNotFound);
|
||||
|
||||
_context.InsigniaReclaimProfiles.Remove(deleted);
|
||||
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("reclaim/{year}/{insigniaTypeId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> ListReclaimInsignia(int year, Guid insigniaTypeId)
|
||||
{
|
||||
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_INSIGNIA_BORROW");
|
||||
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
||||
if (jsonData["status"]?.ToString() != "200")
|
||||
{
|
||||
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
||||
}
|
||||
var insigniaType = await _context.InsigniaTypes
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaTypeId);
|
||||
if (insigniaType == null)
|
||||
return Error(GlobalMessages.InsigniaTypeNotFound);
|
||||
|
||||
|
||||
var rawData = await _context.InsigniaReclaimProfiles.AsQueryable()
|
||||
.Where(x => x.InsigniaNoteProfile.RequestInsignia.InsigniaType == insigniaType)
|
||||
.Where(x => year == 0 ? x.Id != null : x.ReclaimDate!.Value.Year == year)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(p => new
|
||||
{
|
||||
Id = p.Id,
|
||||
ReclaimOrganization = p.ReclaimOrganization,
|
||||
ReclaimOrganizationId = p.ReclaimOrganizationId,
|
||||
Profile = p.InsigniaNoteProfile!.ProfileId ?? Guid.Empty,
|
||||
CitizenId = p.InsigniaNoteProfile!.CitizenId ?? string.Empty,
|
||||
Prefix = p.InsigniaNoteProfile!.Prefix ?? string.Empty,
|
||||
FirstName = p.InsigniaNoteProfile!.FirstName ?? string.Empty,
|
||||
LastName = p.InsigniaNoteProfile!.LastName ?? string.Empty,
|
||||
ProfileType = p.InsigniaNoteProfile!.ProfileType ?? string.Empty,
|
||||
Position = p.InsigniaNoteProfile!.Position ?? string.Empty,
|
||||
ReclaimReason = p.ReclaimReason,
|
||||
ReclaimDate = p.ReclaimDate,
|
||||
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,
|
||||
ReclaimOrganizationId = p.ReclaimOrganizationId,
|
||||
ReclaimOrganization = p.ReclaimOrganization,
|
||||
p.ReclaimDate,
|
||||
p.ReclaimReason,
|
||||
p.LastUpdatedAt,
|
||||
p.CreatedAt,
|
||||
p.InsigniaNoteProfileId,
|
||||
CitizenId = p.CitizenId,
|
||||
Prefix = p.Prefix,
|
||||
Position = p.Position,
|
||||
FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
|
||||
ProfileType = p.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();
|
||||
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// ยืมเครื่องราชฯ
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue