301 lines
16 KiB
C#
301 lines
16 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.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 Swashbuckle.AspNetCore.Annotations;
|
|
using System.Security.Claims;
|
|
|
|
namespace BMA.EHR.DisciplineResult.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/discipline/result")]
|
|
[ApiVersion("1.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("ระบบวินัยเรื่องผลการพิจารณาทางวินัย")]
|
|
public class DisciplineResultController : BaseController
|
|
{
|
|
private readonly DisciplineDbContext _context;
|
|
private readonly MinIODisciplineService _documentService;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
public DisciplineResultController(DisciplineDbContext context,
|
|
MinIODisciplineService documentService,
|
|
IHttpContextAccessor httpContextAccessor)
|
|
{
|
|
// _repository = repository;
|
|
_context = context;
|
|
_documentService = documentService;
|
|
_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>> GetDisciplineResult(int page = 1, int pageSize = 25, string keyword = "")
|
|
{
|
|
var data_search = (from x in _context.DisciplineDisciplinarys
|
|
where x.Title.Contains(keyword)
|
|
// x.DisciplinaryFaultLevel == null ? false : x.DisciplinaryFaultLevel.Contains(keyword) ||
|
|
// x.DisciplinaryCaseFault == null ? false : x.DisciplinaryCaseFault.Contains(keyword) ||
|
|
select x).ToList();
|
|
var data = data_search
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,//id ข้อมูลเรื่องสอบสวน
|
|
Title = x.Title,//ชื่อเรื่อง
|
|
RespondentType = x.RespondentType,//ผู้ถูกสืบสวน
|
|
OffenseDetails = x.OffenseDetails,//ลักษณะความผิด
|
|
DisciplinaryFaultLevel = x.DisciplinaryFaultLevel,//ระดับโทษความผิด
|
|
DisciplinaryCaseFault = x.DisciplinaryCaseFault,//กรณีความผิด
|
|
Status = x.Status,//สถานะหรือผลการสอบสวน
|
|
CreatedAt = x.CreatedAt,//วันที่สร้างเรื่องสอบสวน
|
|
})
|
|
.Where(x => x.Status == "DONE" || x.Status == "REPORT")
|
|
.OrderByDescending(x => x.CreatedAt)
|
|
.Skip((page - 1) * pageSize)
|
|
.Take(pageSize)
|
|
.ToList();
|
|
return Success(new { data, total = data_search.Count() });
|
|
}
|
|
|
|
/// <summary>
|
|
/// get รายการสรุปผลการพิจารณาทางวินัย
|
|
/// </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>> GetByDisciplineResult(Guid id)
|
|
{
|
|
var _data = await _context.DisciplineDisciplinarys
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,//id ข้อมูลเรื่องสอบสวน
|
|
IdInvestigate = x.DisciplineInvestigate.Id,//id ข้อมูลเรื่องสืบสวน
|
|
IdComplaint = x.DisciplineInvestigate.DisciplineComplaint.Id,//id ข้อมูลเรื่องร้องเรียน
|
|
RespondentType = x.RespondentType,//ผู้ถูกสืบสวน
|
|
Persons = x.DisciplineDisciplinary_ProfileComplaintInvestigates.Select(p => new
|
|
{
|
|
Id = p.Id,
|
|
Idcard = p.CitizenId,
|
|
Name = $"{p.Prefix}{p.FirstName} {p.LastName}",
|
|
Prefix = p.Prefix,
|
|
FirstName = p.FirstName,
|
|
LastName = p.LastName,
|
|
Position = p.Position,
|
|
PositionLevel = p.PositionLevel,
|
|
Salary = p.Salary,
|
|
PersonId = p.PersonId,
|
|
PosNo = p.PosNo,
|
|
Organization = p.Organization,
|
|
Status = p.Status,
|
|
StatusDiscard = p.StatusDiscard,
|
|
}),//รายการข้อมูลบุคลผู้ถูกสืบสวน
|
|
OrganizationId = x.Organization,//id หน่วยงานกรณี type เป็นหน่วยงาน
|
|
ResultDescription = x.ResultDescription,//สรุปผลการพิจารณา
|
|
ResultOc = x.ResultOc,//
|
|
ResultDisciplineType = x.ResultDisciplineType,//
|
|
ResultTitleType = x.ResultTitleType,//
|
|
ResultYear = x.ResultYear,//
|
|
Status = x.Status,//สถานะหรือผลการสอบสวน
|
|
DisciplineDisciplinary_DocResults = x.DisciplineDisciplinary_DocResults.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), (int)StatusCodes.Status404NotFound);
|
|
var disciplineDisciplinary_DocResults = new List<dynamic>();
|
|
foreach (var doc in _data.DisciplineDisciplinary_DocResults)
|
|
{
|
|
var _doc = new
|
|
{
|
|
doc.Id,
|
|
doc.FileName,
|
|
PathName = await _documentService.ImagesPath(doc.Id),
|
|
};
|
|
disciplineDisciplinary_DocResults.Add(_doc);
|
|
}
|
|
var data = new
|
|
{
|
|
_data.Id,
|
|
_data.IdInvestigate,
|
|
_data.IdComplaint,
|
|
_data.RespondentType,
|
|
_data.Persons,
|
|
_data.OrganizationId,
|
|
_data.ResultDescription,
|
|
_data.ResultOc,
|
|
_data.ResultDisciplineType,
|
|
_data.ResultTitleType,
|
|
_data.ResultYear,
|
|
_data.Status,
|
|
disciplineDisciplinary_DocResults,
|
|
};
|
|
|
|
return Success(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// แก้ไขรายการสรุปผลการพิจารณาทางวินัย
|
|
/// </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>> UpdateDisciplineResult([FromBody] DisciplineResultRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys.Where(x => x.Id == id).FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
|
|
|
data.ResultDescription = req.resultDescription;
|
|
data.ResultOc = req.oc;
|
|
data.ResultDisciplineType = req.disciplineType;
|
|
data.ResultTitleType = req.titleType;
|
|
data.ResultYear = req.year;
|
|
data.LastUpdateFullName = FullName ?? "System Administrator";
|
|
data.LastUpdateUserId = UserId ?? "";
|
|
data.LastUpdatedAt = DateTime.Now;
|
|
await _context.SaveChangesAsync();
|
|
return Success(data.Id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// สั่งรายชื่อไปออกคำสั่งให้ออกจากราชการไว้ก่อน
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("report/{commandTypeId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> PostToReport([FromBody] DisciplineProfileRequest req, Guid commandTypeId)
|
|
{
|
|
foreach (var item in req.Id)
|
|
{
|
|
var uppdated = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates
|
|
.FirstOrDefaultAsync(x => x.Id == item);
|
|
if (uppdated == null)
|
|
continue;
|
|
|
|
uppdated.CommandTypeId = commandTypeId;
|
|
uppdated.Status = "REPORT";
|
|
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>
|
|
[HttpPut("file/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> UploadFileDisciplineDisciplinaryInvestigate([FromForm] DisciplineFileRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
|
// if (data.Status.Trim().ToUpper() != "NEW")
|
|
// return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
|
|
|
|
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 disciplineDisciplinary_DocResult = new DisciplineDisciplinary_DocResult
|
|
{
|
|
DisciplineDisciplinary = data,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.DisciplineDisciplinary_DocResults.AddAsync(disciplineDisciplinary_DocResult);
|
|
}
|
|
}
|
|
}
|
|
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>> DeleteFileDisciplineDisciplinaryInvestigate(Guid id, Guid docId)
|
|
{
|
|
var data = await _context.DisciplineDisciplinarys
|
|
.Include(x => x.DisciplineDisciplinary_DocResults)
|
|
.ThenInclude(x => x.Document)
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), (int)StatusCodes.Status404NotFound);
|
|
// if (data.Status.Trim().ToUpper() != "NEW")
|
|
// return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), (int)StatusCodes.Status500InternalServerError);
|
|
var dataDoc = data.DisciplineDisciplinary_DocResults.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDoc != null)
|
|
{
|
|
_context.DisciplineDisciplinary_DocResults.Remove(dataDoc);
|
|
await _context.SaveChangesAsync();
|
|
await _documentService.DeleteFileAsync(docId);
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
else
|
|
{
|
|
return Error(new Exception("ไม่พบไฟล์นี้ในระบบ"), (int)StatusCodes.Status404NotFound);
|
|
}
|
|
}
|
|
}
|
|
}
|