hrms-api-backend/BMA.EHR.Discipline.Service/Controllers/DisciplineComplaint_AppealController.cs
2024-07-07 10:25:29 +07:00

625 lines
33 KiB
C#

using BMA.EHR.Application.Repositories;
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;
// using BMA.EHR.Placement.Service.Requests;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Swashbuckle.AspNetCore.Annotations;
using System.Net.Http.Headers;
using System.Security.Claims;
namespace BMA.EHR.DisciplineComplaint_Appeal.Service.Controllers
{
[Route("api/v{version:apiVersion}/discipline/complaint_appeal")]
[ApiVersion("1.0")]
[ApiController]
[Produces("application/json")]
[Authorize]
[SwaggerTag("ระบบย่อย อุทธรณ์/ร้องทุกข์")]
public class DisciplineComplaint_AppealController : BaseController
{
private readonly DisciplineDbContext _context;
private readonly ApplicationDBContext _contextMain;
private readonly MinIODisciplineService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly NotificationRepository _repositoryNoti;
private readonly IConfiguration _configuration;
public DisciplineComplaint_AppealController(DisciplineDbContext context,
NotificationRepository repositoryNoti,
ApplicationDBContext contextMain,
MinIODisciplineService documentService,
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration)
{
// _repository = repository;
_context = context;
_contextMain = contextMain;
_repositoryNoti = repositoryNoti;
_documentService = documentService;
_httpContextAccessor = httpContextAccessor;
_configuration = configuration;
}
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private string? token => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
private static string StatusDisciplineComplaintAppeal(string value)
{
switch (value)
{
case "NEW": return "ใหม่";
case "RECEIVE_DOC": return "ได้รับเอกสารแล้ว";
case "RECEIVE_APPEAL": return "รับอุทธรณ์/ร้องทุกข์";
case "NO_RECEIVE_APPEAL": return "ไม่รับอุทธรณ์/ร้องทุกข์";
case "DIAGNOSTIC": return "ตั้งองค์คณะวินิจฉัย";
case "SUMMARY": return "สรุปผลการพิจารณา";
case "DONE": return "ปิดคำร้อง";
default: return "";
}
}
#endregion
/// <summary>
/// List รายการยื่นอุทธรณ์/ร้องทุกข์ (USER)
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("user")]
public async Task<ActionResult<ResponseObject>> GetDisciplineUser(string status = "ALL", string type = "ALL", int year = 0, int page = 1, int pageSize = 25, string keyword = "")
{
var id = "";
var apiUrl = $"{_configuration["API"]}/org/profile/keycloak/position";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<dynamic>(_result);
if (org == null || org.result == null)
return Success(new { data = new List<dynamic>(), total = 0 });
id = org.result.profileId;
if (id == "")
return Success(new { data = new List<dynamic>(), total = 0 });
var data_search = (from x in _context.DisciplineComplaint_Appeals
where x.Title.Contains(keyword) ||
x.Description.Contains(keyword) ||
x.CaseType.Contains(keyword) ||
x.CaseNumber.Contains(keyword) ||
x.Fullname.Contains(keyword) ||
x.CitizenId.Contains(keyword)
where x.ProfileId == id
select x).ToList();
if (status.Trim().ToUpper() != "ALL")
data_search = data_search.Where(x => x.Status == status).ToList();
if (type.Trim().ToUpper() != "ALL")
data_search = data_search.Where(x => x.Type == type).ToList();
if (year != 0)
data_search = data_search.Where(x => x.Year == year).ToList();
var data = data_search
.Select(x => new
{
Id = x.Id,
Title = x.Title,
Description = x.Description,
Status = x.Status,
Type = x.Type,
Year = x.Year,
CaseType = x.CaseType,
CaseNumber = x.CaseNumber,
Fullname = x.Fullname,
CitizenId = x.CitizenId,
ProfileId = x.ProfileId,
LastUpdatedAt = x.LastUpdatedAt,
})
.OrderByDescending(x => x.LastUpdatedAt)
.Skip((page - 1) * pageSize)
.Take(pageSize)
.ToList();
return Success(new { data, total = data_search.Count() });
}
}
/// <summary>
/// รายละเอียดยื่นอุทธรณ์/ร้องทุกข์ (USER/ADMIN)
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("{id:guid}")]
public async Task<ActionResult<ResponseObject>> GetByDiscipline(Guid id)
{
var _data = await _context.DisciplineComplaint_Appeals
.Include(x => x.DisciplineComplaint_Appeal_Docs)
.Include(x => x.DisciplineComplaint_Appeal_Historys)
.Select(x => new
{
Id = x.Id,
Title = x.Title,
Description = x.Description,
Status = x.Status,
Type = x.Type,
Year = x.Year,
CaseType = x.CaseType,
CaseNumber = x.CaseNumber,
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 }),
})
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (_data == null)
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
var disciplineComplaint_Appeal_Docs = new List<dynamic>();
foreach (var doc in _data.DisciplineComplaint_Appeal_Docs)
{
var _doc = new
{
doc.Id,
doc.FileName,
PathName = await _documentService.ImagesPath(doc.Id)
};
disciplineComplaint_Appeal_Docs.Add(_doc);
}
var data = new
{
_data.Id,
_data.Title,
_data.Description,
_data.Status,
_data.Type,
_data.Year,
_data.CaseType,
_data.CaseNumber,
_data.Fullname,
_data.CitizenId,
_data.ProfileId,
_data.Oc,
_data.Position,
_data.LastUpdatedAt,
_data.HistoryStatus,
disciplineComplaint_Appeal_Docs,
};
return Success(data);
}
/// <summary>
/// สร้างรายการยื่นอุทธรณ์/ร้องทุกข์ (USER)
/// </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>> CreateDiscipline([FromForm] DisciplineComplaint_AppealRequest req)
{
var apiUrl = $"{_configuration["API"]}/org/profile/keycloak/position";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var _res = await client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<dynamic>(_result);
if (org == null || org.result == null)
return Success(new { data = new List<dynamic>(), total = 0 });
var id = org.result.profileId;
if (id == "")
return Success(new { data = new List<dynamic>(), total = 0 });
var disciplineComplaint_Appeal = new Domain.Models.Discipline.DisciplineComplaint_Appeal
{
Title = req.Title,
Description = req.Description,
Status = "NEW",
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 = id,
Position = req.Position,
Oc = req.Oc,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
var disciplineComplaint_Appeal_History = new DisciplineComplaint_Appeal_History
{
DisciplineComplaint_Appeal = disciplineComplaint_Appeal,
Status = "NEW",
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
// await _context.DisciplineComplaint_Appeals.AddAsync(disciplineComplaint_Appeal);
await _context.DisciplineComplaint_Appeal_Historys.AddAsync(disciplineComplaint_Appeal_History);
await _context.SaveChangesAsync();
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, file.FileName);
var _doc = await _context.Documents.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == doc.Id);
if (_doc != null)
{
var disciplineComplaint_Appeal_Doc = new DisciplineComplaint_Appeal_Doc
{
DisciplineComplaint_Appeal = disciplineComplaint_Appeal,
Document = _doc,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.DisciplineComplaint_Appeal_Docs.AddAsync(disciplineComplaint_Appeal_Doc);
}
}
}
await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6"),
$"มีคำขอยื่นอุทธรณ์/ร้องทุกข์จาก {req.Fullname}",
$"มีคำขอยื่นอุทธรณ์/ร้องทุกข์จาก {req.Fullname}",
"",
true,
true
);
await _context.SaveChangesAsync();
return Success(disciplineComplaint_Appeal.Id);
}
}
/// <summary>
/// สร้างรายการยื่นอุทธรณ์/ร้องทุกข์ (ADMIN)
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("admin")]
public async Task<ActionResult<ResponseObject>> CreateDisciplineAdmin([FromForm] DisciplineComplaint_AppealRequest req)
{
var disciplineComplaint_Appeal = new Domain.Models.Discipline.DisciplineComplaint_Appeal
{
Title = req.Title,
Description = req.Description,
Status = "NEW",
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,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
var disciplineComplaint_Appeal_History = new DisciplineComplaint_Appeal_History
{
DisciplineComplaint_Appeal = disciplineComplaint_Appeal,
Status = "NEW",
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
// await _context.DisciplineComplaint_Appeals.AddAsync(disciplineComplaint_Appeal);
await _context.DisciplineComplaint_Appeal_Historys.AddAsync(disciplineComplaint_Appeal_History);
await _context.SaveChangesAsync();
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, file.FileName);
var _doc = await _context.Documents.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == doc.Id);
if (_doc != null)
{
var disciplineComplaint_Appeal_Doc = new DisciplineComplaint_Appeal_Doc
{
DisciplineComplaint_Appeal = disciplineComplaint_Appeal,
Document = _doc,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.DisciplineComplaint_Appeal_Docs.AddAsync(disciplineComplaint_Appeal_Doc);
}
}
}
// await _repositoryNoti.PushNotificationAsyncV2(
// req.ProfileId,
// $"เจ้าหน้าที่ได้ทำการสร้างคำร้องอุทธรณ์ร้องทุกข์",
// $"เจ้าหน้าที่ได้ทำการสร้างคำร้องอุทธรณ์ร้องทุกข์",
// "",
// true,
// true
// );
await _context.SaveChangesAsync();
return Success(disciplineComplaint_Appeal.Id);
}
/// <summary>
/// อัพไฟล์เอกสารอุทธรณ์/ร้องทุกข์
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("file/{id:guid}")]
public async Task<ActionResult<ResponseObject>> UploadFileComplaintAppeals([FromForm] DisciplineFileRequest req, Guid id)
{
var data = await _context.DisciplineComplaint_Appeals
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
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, file.FileName);
var _doc = await _context.Documents.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == doc.Id);
if (_doc != null)
{
var disciplineComplaint_Appeal_Doc = new DisciplineComplaint_Appeal_Doc
{
DisciplineComplaint_Appeal = data,
Document = _doc,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.DisciplineComplaint_Appeal_Docs.AddAsync(disciplineComplaint_Appeal_Doc);
}
}
}
data.LastUpdateFullName = FullName ?? "System Administrator";
data.LastUpdateUserId = UserId ?? "";
data.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("file/{id:guid}/{docId:guid}")]
public async Task<ActionResult<ResponseObject>> DeleteFileComplaintAppeals(Guid id, Guid docId)
{
var data = await _context.DisciplineComplaint_Appeals
.Include(x => x.DisciplineComplaint_Appeal_Docs)
.ThenInclude(x => x.Document)
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
var dataDoc = data.DisciplineComplaint_Appeal_Docs.Where(x => x.Document.Id == docId).FirstOrDefault();
if (dataDoc != null)
{
_context.DisciplineComplaint_Appeal_Docs.Remove(dataDoc);
await _context.SaveChangesAsync();
var dataDocComplaint = data.DisciplineComplaint_Appeal_Docs.Where(x => x.Document.Id == docId).FirstOrDefault();
if (dataDocComplaint == null)
{
await _documentService.DeleteFileAsync(docId);
data.LastUpdateFullName = FullName ?? "System Administrator";
data.LastUpdateUserId = UserId ?? "";
data.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync();
}
return Success();
}
else
{
return Error(new Exception("ไม่พบไฟล์นี้ในระบบ"), (int)StatusCodes.Status404NotFound);
}
}
/// <summary>
/// List รายการยื่นอุทธรณ์/ร้องทุกข์ (ADMIN)
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("admin")]
public async Task<ActionResult<ResponseObject>> GetDisciplineAdmin(string status = "ALL", string type = "ALL", int year = 0, int page = 1, int pageSize = 25, string keyword = "")
{
var data_search = (from x in _context.DisciplineComplaint_Appeals
where (x.Title == null ? false : x.Title.Contains(keyword)) ||
(x.Description == null ? false : x.Description.Contains(keyword)) ||
(x.CaseType == null ? false : x.CaseType.Contains(keyword)) ||
(x.CaseNumber == null ? false : x.CaseNumber.Contains(keyword)) ||
(x.Fullname == null ? false : x.Fullname.Contains(keyword)) ||
(x.CitizenId == null ? false : x.CitizenId.Contains(keyword))
select x).ToList();
if (status.Trim().ToUpper() != "ALL")
data_search = data_search.Where(x => x.Status == status).ToList();
if (type.Trim().ToUpper() != "ALL")
data_search = data_search.Where(x => x.Type == type).ToList();
if (year != 0)
data_search = data_search.Where(x => x.Year == year).ToList();
var data = data_search
.Select(x => new
{
Id = x.Id,
Title = x.Title,
Description = x.Description,
Status = x.Status,
Type = x.Type,
Year = x.Year,
CaseType = x.CaseType,
CaseNumber = x.CaseNumber,
Fullname = x.Fullname,
CitizenId = x.CitizenId,
ProfileId = x.ProfileId,
LastUpdatedAt = x.LastUpdatedAt,
})
.OrderByDescending(x => x.LastUpdatedAt)
.Skip((page - 1) * pageSize)
.Take(pageSize)
.ToList();
return Success(new { data, total = data_search.Count() });
}
/// <summary>
/// แก้ไขรายการยื่นอุทธรณ์/ร้องทุกข์ (ADMIN)
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("{id:guid}")]
public async Task<ActionResult<ResponseObject>> UpdateDiscipline(Guid id, [FromBody] DisciplineComplaint_AppealUpdateRequest req)
{
var data = await _context.DisciplineComplaint_Appeals
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (data == null)
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
data.Title = req.Title;
data.Description = req.Description;
if (data.Status != req.Status.Trim().ToUpper())
{
var disciplineComplaint_Appeal_History = new DisciplineComplaint_Appeal_History
{
DisciplineComplaint_Appeal = data,
Status = req.Status.Trim().ToUpper(),
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.DisciplineComplaint_Appeal_Historys.AddAsync(disciplineComplaint_Appeal_History);
// await _repositoryNoti.PushNotificationAsync(
// data.ProfileId,
// $"มีการแก้ไขสถานะคำขออุทธรณ์/ร้องทุกข์จาก {data.Fullname} เป็น {StatusDisciplineComplaintAppeal(req.Status.Trim().ToUpper())}",
// $"มีการแก้ไขสถานะคำขออุทธรณ์/ร้องทุกข์จาก {data.Fullname} เป็น {StatusDisciplineComplaintAppeal(req.Status.Trim().ToUpper())}",
// "",
// true,
// true
// );
}
data.Status = req.Status.Trim().ToUpper();
data.Type = req.Type.Trim().ToUpper();
data.Year = req.Year;
data.CaseType = req.CaseType;
data.CaseNumber = req.CaseNumber;
data.LastUpdateFullName = FullName ?? "System Administrator";
data.LastUpdateUserId = UserId ?? "";
data.LastUpdatedAt = DateTime.Now;
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);
}
}
}