query report อุทธรณ์

This commit is contained in:
Kittapath 2023-12-19 08:33:09 +07:00
parent f11f927f7e
commit 52af68a9a9
6 changed files with 11826 additions and 4 deletions

View file

@ -2,6 +2,7 @@
using BMA.EHR.Application.Repositories.MessageQueue;
using BMA.EHR.Discipline.Service.Requests;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Discipline;
using BMA.EHR.Domain.Shared;
using BMA.EHR.Infrastructure.Persistence;
@ -120,11 +121,14 @@ namespace BMA.EHR.DisciplineComplaint_Appeal.Service.Controllers
Fullname = x.Fullname,
CitizenId = x.CitizenId,
ProfileId = x.ProfileId,
Oc = x.Oc,
Position = x.Position,
LastUpdatedAt = x.LastUpdatedAt,
HistoryStatus = x.DisciplineComplaint_Appeal_Historys.Select(p => new
{
Status = p.Status,
CreatedAt = p.CreatedAt,
CreatedFullName = p.CreatedFullName,
}),
DisciplineComplaint_Appeal_Docs = x.DisciplineComplaint_Appeal_Docs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
})
@ -156,6 +160,8 @@ namespace BMA.EHR.DisciplineComplaint_Appeal.Service.Controllers
_data.Fullname,
_data.CitizenId,
_data.ProfileId,
_data.Oc,
_data.Position,
_data.LastUpdatedAt,
_data.HistoryStatus,
disciplineComplaint_Appeal_Docs,
@ -179,13 +185,15 @@ namespace BMA.EHR.DisciplineComplaint_Appeal.Service.Controllers
Title = req.Title,
Description = req.Description,
Status = "NEW",
Type = req.Type,
Year = req.Year,
Type = req.Type.Trim().ToUpper(),
Year = req.Year == null ? DateTime.Now.Year : req.Year,
CaseType = req.CaseType,
CaseNumber = req.CaseNumber,
Fullname = req.Fullname,
CitizenId = req.CitizenId,
ProfileId = req.ProfileId,
Position = req.Position,
Oc = req.Oc,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
@ -233,7 +241,7 @@ namespace BMA.EHR.DisciplineComplaint_Appeal.Service.Controllers
}
}
await _context.SaveChangesAsync();
return Success();
return Success(disciplineComplaint_Appeal.Id);
}
/// <summary>
@ -408,7 +416,7 @@ namespace BMA.EHR.DisciplineComplaint_Appeal.Service.Controllers
await _context.DisciplineComplaint_Appeal_Historys.AddAsync(disciplineComplaint_Appeal_History);
}
data.Status = req.Status.Trim().ToUpper();
data.Type = req.Type;
data.Type = req.Type.Trim().ToUpper();
data.Year = req.Year;
data.CaseType = req.CaseType;
data.CaseNumber = req.CaseNumber;
@ -418,5 +426,39 @@ namespace BMA.EHR.DisciplineComplaint_Appeal.Service.Controllers
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// Export Report อุทธรณ์/ร้องทุกข์
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("report/{id:guid}")]
public async Task<ActionResult<ResponseObject>> ReportDiscipline(Guid id)
{
var data = await _context.DisciplineComplaint_Appeals
.Where(x => x.Id == id)
.Select(x => new
{
template = x.Type.Contains("APPEAL") ? "อุทธรณ์" : "ร้องทุกข์",
reportName = "docx-report",
data = new
{
Oc = x.Oc,
Position = x.Position,
Fullname = x.Fullname,
Title = x.Title,
Description = x.Description,
Date = DateTime.Now.ToThaiFullDate2(),
}
})
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
return Success(data);
}
}
}