1400 lines
78 KiB
C#
1400 lines
78 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;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using System.Net.Http.Headers;
|
|
|
|
namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/discipline/investigate")]
|
|
[ApiVersion("1.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("ระบบวินัยเรื่องสืบสวน")]
|
|
public class DisciplineInvestigateController : BaseController
|
|
{
|
|
private readonly DisciplineDbContext _context;
|
|
private readonly MinIODisciplineService _documentService;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly NotificationRepository _repositoryNoti;
|
|
private readonly PermissionRepository _permission;
|
|
private readonly IConfiguration _configuration;
|
|
|
|
public DisciplineInvestigateController(DisciplineDbContext context,
|
|
MinIODisciplineService documentService,
|
|
NotificationRepository repositoryNoti,
|
|
IHttpContextAccessor httpContextAccessor,
|
|
IConfiguration configuration,
|
|
PermissionRepository permission)
|
|
{
|
|
// _repository = repository;
|
|
_context = context;
|
|
_documentService = documentService;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_repositoryNoti = repositoryNoti;
|
|
_permission = permission;
|
|
_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"];
|
|
|
|
#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>> GetDisciplineInvestigate(int page = 1, int pageSize = 25, string keyword = "", string status = "")
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_DISCIPLINE_INVESTIGATE");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var data_search = (from x in _context.DisciplineInvestigates
|
|
where x.Title.Contains(keyword)
|
|
select x).ToList();
|
|
if (status.Trim().ToUpper() != "ALL")
|
|
data_search = data_search.Where(x => x.Status.Contains(status.Trim().ToUpper())).ToList();
|
|
var data = data_search
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,//id ข้อมูลเรื่องสืบสวน
|
|
Title = x.Title,//ชื่อเรื่อง
|
|
RespondentType = x.RespondentType,//ผู้ถูกสืบสวน
|
|
OffenseDetails = x.OffenseDetails,//ลักษณะความผิด
|
|
Status = x.Status,//สถานะหรือผลการสืบสวน
|
|
InvestigationDateStart = x.InvestigationDateStart,
|
|
InvestigationDateEnd = x.InvestigationDateEnd,
|
|
CreatedAt = x.CreatedAt,//วันที่สร้างเรื่องสืบสวน
|
|
InvestigationDetail = x.InvestigationDetail,
|
|
InvestigationStatusResult = x.InvestigationStatusResult,
|
|
})
|
|
.OrderByDescending(x => x.InvestigationDateStart)
|
|
.Skip((page - 1) * pageSize)
|
|
.Take(pageSize)
|
|
.ToList();
|
|
return Success(new { data, total = data_search.Count() });
|
|
}
|
|
|
|
/// <summary>
|
|
/// list รายการวินัยเรื่องสืบสวน (ค้นหาขั้นสูง)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("advance-search")]
|
|
public async Task<ActionResult<ResponseObject>> GetAdvanceSearchDisciplineInvestigate([FromBody] DisciplineInvestigateAdvanceSearcRequest req)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_DISCIPLINE_INVESTIGATE");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var page = req.page <= 0 ? 1 : req.page;
|
|
var pageSize = req.pageSize <= 0 ? 25 : req.pageSize;
|
|
var keyword = string.IsNullOrEmpty(req.keyword) ? string.Empty : req.keyword;
|
|
var status = string.IsNullOrEmpty(req.status) ? string.Empty : req.status;
|
|
|
|
var data_search = (from x in _context.DisciplineInvestigates
|
|
where x.Title.Contains(keyword)
|
|
select x).ToList();
|
|
if (status.Trim().ToUpper() != "ALL")
|
|
data_search = data_search.Where(x => x.Status.Contains(status.Trim().ToUpper())).ToList();
|
|
|
|
if (
|
|
(req.investigationDateStart.HasValue && req.investigationDateEnd.HasValue) ||
|
|
(req.dateReceivedStart.HasValue && req.dateReceivedEnd.HasValue) ||
|
|
(!string.IsNullOrEmpty(req.respondentType)) ||
|
|
(!string.IsNullOrEmpty(req.offenseDetails)) ||
|
|
(!string.IsNullOrEmpty(req.investigationDetail)) ||
|
|
(!string.IsNullOrEmpty(req.investigationStatusResult))
|
|
)
|
|
{
|
|
data_search = data_search
|
|
.Where(x =>
|
|
(!req.dateReceivedStart.HasValue || !req.dateReceivedEnd.HasValue ||
|
|
(x.DateReceived.HasValue &&
|
|
x.DateReceived.Value.Date <= req.dateReceivedStart.Value.Date &&
|
|
x.DateReceived.Value.Date >= req.dateReceivedEnd.Value.Date))
|
|
&&
|
|
(!req.investigationDateStart.HasValue || !req.investigationDateEnd.HasValue ||
|
|
(x.InvestigationDateStart.HasValue && x.InvestigationDateEnd.HasValue &&
|
|
x.InvestigationDateStart.Value.Date <= req.investigationDateStart.Value.Date &&
|
|
x.InvestigationDateEnd.Value.Date >= req.investigationDateEnd.Value.Date))
|
|
&&
|
|
(string.IsNullOrEmpty(req.respondentType) || x.RespondentType == req.respondentType)
|
|
&&
|
|
(string.IsNullOrEmpty(req.offenseDetails) || x.OffenseDetails == req.offenseDetails)
|
|
&&
|
|
(string.IsNullOrEmpty(req.investigationDetail) || x.InvestigationDetail == req.investigationDetail)
|
|
&&
|
|
(string.IsNullOrEmpty(req.investigationStatusResult) || x.InvestigationStatusResult == req.investigationStatusResult)
|
|
)
|
|
.ToList();
|
|
}
|
|
|
|
var query = data_search
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,//id ข้อมูลเรื่องสืบสวน
|
|
Title = x.Title,//ชื่อเรื่อง
|
|
RespondentType = x.RespondentType,//ผู้ถูกสืบสวน
|
|
OffenseDetails = x.OffenseDetails,//ลักษณะความผิด
|
|
Status = x.Status,//สถานะหรือผลการสืบสวน
|
|
InvestigationDateStart = x.InvestigationDateStart, //วันที่เริ่มการสืบสวน
|
|
InvestigationDateEnd = x.InvestigationDateEnd, //วันที่สิ้นสุดการสืบสวน
|
|
DateReceived = x.DateReceived, //วันที่รับเรื่อง
|
|
CreatedAt = x.CreatedAt,//วันที่สร้างเรื่องสืบสวน
|
|
InvestigationDetail = x.InvestigationDetail,
|
|
InvestigationStatusResult = x.InvestigationStatusResult,
|
|
});
|
|
|
|
bool desc = req.descending ?? false;
|
|
if (!string.IsNullOrEmpty(req.sortBy))
|
|
{
|
|
switch (req.sortBy)
|
|
{
|
|
case "title":
|
|
query = desc ? query.OrderByDescending(x => x.Title)
|
|
: query.OrderBy(x => x.Title);
|
|
break;
|
|
|
|
case "respondentType":
|
|
query = desc ? query.OrderByDescending(x => x.RespondentType)
|
|
: query.OrderBy(x => x.RespondentType);
|
|
break;
|
|
|
|
case "offenseDetails":
|
|
query = desc ? query.OrderByDescending(x => x.OffenseDetails)
|
|
: query.OrderBy(x => x.OffenseDetails);
|
|
break;
|
|
|
|
case "status":
|
|
query = desc ? query.OrderByDescending(x => x.Status)
|
|
: query.OrderBy(x => x.Status);
|
|
break;
|
|
|
|
case "investigationDateStart":
|
|
query = desc ? query.OrderByDescending(x => x.InvestigationDateStart)
|
|
: query.OrderBy(x => x.InvestigationDateStart);
|
|
break;
|
|
|
|
case "investigationDateEnd":
|
|
query = desc ? query.OrderByDescending(x => x.InvestigationDateEnd)
|
|
: query.OrderBy(x => x.InvestigationDateEnd);
|
|
break;
|
|
|
|
case "dateReceived":
|
|
query = desc ? query.OrderByDescending(x => x.DateReceived)
|
|
: query.OrderBy(x => x.DateReceived);
|
|
break;
|
|
|
|
case "createdAt":
|
|
query = desc ? query.OrderByDescending(x => x.CreatedAt)
|
|
: query.OrderBy(x => x.CreatedAt);
|
|
break;
|
|
|
|
case "investigationDetail":
|
|
query = desc ? query.OrderByDescending(x => x.InvestigationDetail)
|
|
: query.OrderBy(x => x.InvestigationDetail);
|
|
break;
|
|
|
|
case "investigationStatusResult":
|
|
query = desc ? query.OrderByDescending(x => x.InvestigationStatusResult)
|
|
: query.OrderBy(x => x.InvestigationStatusResult);
|
|
break;
|
|
|
|
default:
|
|
query = query.OrderByDescending(x => x.InvestigationDateStart);
|
|
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
var data = query
|
|
.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("complaint/{id:guid}")]
|
|
// public async Task<ActionResult<ResponseObject>> GetByDisciplineInvestigateComplaint(Guid id)
|
|
// {
|
|
// var _data = await _context.DisciplineInvestigates
|
|
// .Select(x => new
|
|
// {
|
|
// Id = x.Id,//id ข้อมูลเรื่องสืบสวน
|
|
// IdComplaint = x.DisciplineComplaint.Id,//id ข้อมูลเรื่องร้องเรียน
|
|
// RespondentType = x.RespondentType,//ผู้ถูกสืบสวน
|
|
// Persons = x.DisciplineInvestigate_ProfileComplaints.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,
|
|
// IsSend = p.IsReport,
|
|
// }),//รายการข้อมูลบุคลผู้ถูกสืบสวน
|
|
// OrganizationId = x.Organization,//id หน่วยงานกรณี type เป็นหน่วยงาน
|
|
// ConsideredAgency = x.ConsideredAgency,//หน่วยงานที่พิจารณา จะเปลี่ยนไปตามผู้ถูกร้องดูรายละเอียดด้านล่าง
|
|
// Title = x.Title,//ชื่อเรื่อง
|
|
// Description = x.Description,//รายละเอียด
|
|
// DateReceived = x.DateReceived,//วันที่รับเรื่อง
|
|
// LevelConsideration = x.LevelConsideration,//ระดับการพัฒนา
|
|
// DateConsideration = x.DateConsideration,//วันที่กำหนดพิจารณา
|
|
// OffenseDetails = x.OffenseDetails,//ลักษณะความผิด
|
|
// DateNotification = x.DateNotification,//วันแจ้งเตือนล่วงหน้า
|
|
// ComplaintFrom = x.ComplaintFrom,//รับเรื่องสืบสวนจาก
|
|
// Appellant = x.Appellant,//ผู้ถูกสืบสวน
|
|
// Result = x.ResultComplaint,//ผลการตรวจสอบ
|
|
// Status = x.Status,//สถานะเรื่องสืบสวน
|
|
// DisciplineInvestigateDocComplaints = x.DisciplineInvestigate_DocComplaints.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 disciplineInvestigateDocComplaints = new List<dynamic>();
|
|
// foreach (var doc in _data.DisciplineInvestigateDocComplaints)
|
|
// {
|
|
// var _doc = new
|
|
// {
|
|
// doc.Id,
|
|
// doc.FileName,
|
|
// PathName = await _documentService.ImagesPath(doc.Id)
|
|
// };
|
|
// disciplineInvestigateDocComplaints.Add(_doc);
|
|
// }
|
|
// var data = new
|
|
// {
|
|
// _data.Id,
|
|
// _data.IdComplaint,
|
|
// _data.RespondentType,
|
|
// _data.Persons,
|
|
// _data.OrganizationId,
|
|
// _data.ConsideredAgency,
|
|
// _data.Title,
|
|
// _data.Description,
|
|
// _data.DateReceived,
|
|
// _data.LevelConsideration,
|
|
// _data.DateConsideration,
|
|
// _data.OffenseDetails,
|
|
// _data.DateNotification,
|
|
// _data.ComplaintFrom,
|
|
// _data.Appellant,
|
|
// _data.Result,
|
|
// _data.Status,
|
|
// disciplineInvestigateDocComplaints,
|
|
// };
|
|
// 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("complaint/{id:guid}")]
|
|
// public async Task<ActionResult<ResponseObject>> UpdateDisciplineInvestigateComplaint([FromBody] DisciplineInvestigateComplaintRequest req, Guid id)
|
|
// {
|
|
// var data = await _context.DisciplineInvestigates.Include(x => x.DisciplineInvestigate_ProfileComplaints).Where(x => x.Id == id).FirstOrDefaultAsync();
|
|
// if (data == null)
|
|
// return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
// if (data.Status.Trim().ToUpper() != "NEW")
|
|
// return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
|
|
|
|
// data.Title = req.title;
|
|
// data.Description = req.description;
|
|
// data.OffenseDetails = req.offenseDetails.Trim().ToUpper();
|
|
// data.LastUpdateFullName = FullName ?? "System Administrator";
|
|
// data.LastUpdateUserId = UserId ?? "";
|
|
// data.LastUpdatedAt = DateTime.Now;
|
|
// var hisprofile = data.DisciplineInvestigate_ProfileComplaints;
|
|
// _context.DisciplineInvestigate_ProfileComplaints.RemoveRange(data.DisciplineInvestigate_ProfileComplaints);
|
|
// if (data.RespondentType.Trim().ToUpper() == "PERSON")
|
|
// {
|
|
// foreach (var item in req.persons)
|
|
// {
|
|
// var isReport = hisprofile.Where(x => x.PersonId == item.personId).FirstOrDefault();
|
|
// data.DisciplineInvestigate_ProfileComplaints.Add(
|
|
// new DisciplineInvestigate_ProfileComplaint
|
|
// {
|
|
// CitizenId = item.idcard,
|
|
// Prefix = item.prefix,
|
|
// FirstName = item.firstName,
|
|
// LastName = item.lastName,
|
|
// Organization = item.organization,
|
|
// Position = item.position,
|
|
// PositionLevel = item.positionLevel,
|
|
// Salary = item.salary,
|
|
// PersonId = item.personId,
|
|
// PosNo = item.posNo,
|
|
// IsReport = isReport == null ? false : isReport.IsReport,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// CreatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// }
|
|
// );
|
|
// }
|
|
// }
|
|
// await _context.SaveChangesAsync();
|
|
// return Success(data.Id);
|
|
// }
|
|
|
|
/// <summary>
|
|
/// get รายการวินัยเรื่องสืบสวน
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("{page}/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> GetByDisciplineInvestigate(string page, Guid id)
|
|
{
|
|
page = page.Trim().ToUpper();
|
|
string getPermission;
|
|
if (page == "MAIN")
|
|
{
|
|
getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_DISCIPLINE_INVESTIGATE");
|
|
}
|
|
else if (page == "DISCIP")
|
|
{
|
|
getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_DISCIPLINE_INTERROGATE");
|
|
}
|
|
else if (page == "RESULT")
|
|
{
|
|
getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_DISCIPLINE_RESULT");
|
|
}
|
|
else
|
|
{
|
|
getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_DISCIPLINE_INVESTIGATE");
|
|
}
|
|
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var _data = await _context.DisciplineInvestigates
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,//id ข้อมูลเรื่องสืบสวน
|
|
IdComplaint = x.DisciplineComplaint.Id,//id ข้อมูลเรื่องร้องเรียน
|
|
InvestigationDetail = x.InvestigationDetail,
|
|
InvestigationDetailOther = x.InvestigationDetailOther,
|
|
InvestigationDateStart = x.InvestigationDateStart,
|
|
InvestigationDateEnd = x.InvestigationDateEnd,
|
|
InvestigationDescription = x.InvestigationDescription,
|
|
InvestigationStatusResult = x.InvestigationStatusResult,
|
|
InvestigationCauseText = x.InvestigationCauseText,
|
|
InvestigationExtendStatus = x.InvestigationExtendStatus,
|
|
InvestigationDaysExtend = x.InvestigationDaysExtend,
|
|
InvestigationExtendHistory = x.DisciplineInvestigateExtends.Select(e => new
|
|
{
|
|
Name = e.Name,
|
|
Num = e.Num,
|
|
DaysExtend = e.DaysExtend,
|
|
DateStart = e.DateStart,
|
|
DateEnd = e.DateEnd,
|
|
}),
|
|
Status = x.Status,//สถานะเรื่องสืบสวน
|
|
Result = x.Result,//ผลการตรวจสอบ
|
|
Director = x.DisciplineInvestigate_Directors.Select(d => new
|
|
{
|
|
DirectorId = d.Id,
|
|
Id = d.DisciplineDirector.Id,
|
|
Prefix = d.DisciplineDirector.Prefix,
|
|
FirstName = d.DisciplineDirector.FirstName,
|
|
LastName = d.DisciplineDirector.LastName,
|
|
Position = d.DisciplineDirector.Position,
|
|
Email = d.DisciplineDirector.Email,
|
|
Duty = d.Duty,
|
|
CommandNo = d.CommandNo,
|
|
Phone = d.DisciplineDirector.Phone,
|
|
// Total = d.DisciplineDirector.DisciplineInvestigate_Directors.Count(),
|
|
}).ToList(),
|
|
RespondentType = x.RespondentType,//ผู้ถูกสืบสวน
|
|
Persons = x.DisciplineInvestigate_ProfileComplaints
|
|
.OrderByDescending(p => p.profileType)
|
|
.ThenByDescending(p => p.CreatedAt)
|
|
.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,
|
|
IsAncestorDNA = p.IsAncestorDNA,
|
|
Salary = p.Salary,
|
|
PersonId = p.PersonId,
|
|
PosNo = p.PosNo,
|
|
Organization = p.Organization,
|
|
|
|
root = p.root,
|
|
rootId = p.rootId,
|
|
rootDnaId = p.rootDnaId,
|
|
rootShortName = p.rootShortName,
|
|
child1 = p.child1,
|
|
child1Id = p.child1Id,
|
|
child1DnaId = p.child1DnaId,
|
|
child1ShortName = p.child1ShortName,
|
|
child2 = p.child2,
|
|
child2Id = p.child2Id,
|
|
child2DnaId = p.child2DnaId,
|
|
child2ShortName = p.child2ShortName,
|
|
child3 = p.child3,
|
|
child3Id = p.child3Id,
|
|
child3DnaId = p.child3DnaId,
|
|
child3ShortName = p.child3ShortName,
|
|
child4 = p.child4,
|
|
child4Id = p.child4Id,
|
|
child4DnaId = p.child4DnaId,
|
|
child4ShortName = p.child4ShortName,
|
|
posMasterNo = p.posMasterNo,
|
|
posTypeId = p.posTypeId,
|
|
posTypeName = p.posTypeName,
|
|
posLevelId = p.posLevelId,
|
|
posLevelName = p.posLevelName,
|
|
|
|
IsSend = p.IsReport,
|
|
DocumentReject = p.DocumentReject,
|
|
disciplineRejectDoc = new List<dynamic>(),
|
|
RemarkReject = p.RemarkReject,
|
|
IsDisciplinary = p.IsDisciplinary,
|
|
profileType = p.profileType,
|
|
CreatedAt = p.CreatedAt,
|
|
}),//รายการข้อมูลบุคลผู้ถูกสืบสวน
|
|
Organization = x.Organization,//id หน่วยงานกรณี type เป็นหน่วยงาน
|
|
OrganizationId = x.OrganizationId,//id หน่วยงานกรณี type เป็นหน่วยงาน
|
|
DisciplineInvestigateDocs = x.DisciplineInvestigate_Docs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
|
|
DisciplineInvestigateRelevantDocs = x.DisciplineInvestigateRelevant_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 disciplineInvestigateDocs = new List<dynamic>();
|
|
foreach (var doc in _data.DisciplineInvestigateDocs)
|
|
{
|
|
var _doc = new
|
|
{
|
|
doc.Id,
|
|
doc.FileName,
|
|
PathName = await _documentService.ImagesPath(doc.Id)
|
|
};
|
|
disciplineInvestigateDocs.Add(_doc);
|
|
}
|
|
|
|
var disciplineInvestigateRelevantDocs = new List<dynamic>();
|
|
foreach (var doc in _data.DisciplineInvestigateRelevantDocs)
|
|
{
|
|
var _doc = new
|
|
{
|
|
doc.Id,
|
|
doc.FileName,
|
|
PathName = await _documentService.ImagesPath(doc.Id)
|
|
};
|
|
disciplineInvestigateRelevantDocs.Add(_doc);
|
|
}
|
|
|
|
var persons = new List<dynamic>();
|
|
foreach (var doc in _data.Persons)
|
|
{
|
|
if (doc.DocumentReject != null)
|
|
{
|
|
var _doc = new
|
|
{
|
|
doc.DocumentReject.Id,
|
|
doc.DocumentReject.FileName,
|
|
PathName = await _documentService.ImagesPath(doc.DocumentReject.Id)
|
|
};
|
|
doc.disciplineRejectDoc.Add(_doc);
|
|
}
|
|
persons.Add(doc);
|
|
}
|
|
|
|
var data = new
|
|
{
|
|
_data.Id,
|
|
_data.IdComplaint,
|
|
_data.InvestigationDetail,
|
|
_data.InvestigationDetailOther,
|
|
_data.InvestigationDateStart,
|
|
_data.InvestigationDateEnd,
|
|
_data.InvestigationDescription,
|
|
_data.InvestigationStatusResult,
|
|
_data.InvestigationCauseText,
|
|
_data.InvestigationExtendStatus,
|
|
_data.InvestigationDaysExtend,
|
|
_data.InvestigationExtendHistory,
|
|
_data.Status,
|
|
_data.Result,
|
|
_data.Director,
|
|
_data.RespondentType,
|
|
persons,
|
|
_data.Organization,
|
|
_data.OrganizationId,
|
|
disciplineInvestigateDocs,
|
|
disciplineInvestigateRelevantDocs,
|
|
};
|
|
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>> UpdateDisciplineInvestigate([FromBody] DisciplineInvestigateRequest req, Guid id)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_DISCIPLINE_INVESTIGATE");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var data = await _context.DisciplineInvestigates
|
|
.Include(x => x.DisciplineInvestigateExtends)
|
|
.Include(x => x.DisciplineInvestigate_ProfileComplaints)
|
|
.Include(x => x.DisciplineInvestigate_Directors)
|
|
.ThenInclude(x => x.DisciplineDirector)
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
|
|
var editExtend = false;
|
|
if (data.InvestigationDateEnd != req.investigationDateEnd) editExtend = true;
|
|
|
|
data.InvestigationDetail = req.investigationDetail == null ? null : req.investigationDetail.Trim().ToUpper();
|
|
data.InvestigationDetailOther = req.investigationDetailOther;
|
|
data.InvestigationDateStart = req.investigationDateStart;
|
|
data.InvestigationDateEnd = req.investigationDateEnd;
|
|
data.InvestigationDescription = req.investigationDescription;
|
|
data.InvestigationStatusResult = req.investigationStatusResult == null ? null : req.investigationStatusResult.Trim().ToUpper();
|
|
data.InvestigationCauseText = req.investigationCauseText;
|
|
data.InvestigationExtendStatus = req.investigationExtendStatus;
|
|
data.InvestigationDaysExtend = req.investigationDaysExtend;
|
|
data.Result = req.result;
|
|
data.LastUpdateFullName = FullName ?? "System Administrator";
|
|
data.LastUpdateUserId = UserId ?? "";
|
|
data.LastUpdatedAt = DateTime.Now;
|
|
if (editExtend == true)
|
|
{
|
|
var sumExtend = data.DisciplineInvestigateExtends.Count();
|
|
data.DisciplineInvestigateExtends.Add(
|
|
new DisciplineInvestigateExtend
|
|
{
|
|
Name = sumExtend > 0 ? "ขยายครั้งที่ " + sumExtend : "วันที่สืบสวน",
|
|
Num = sumExtend,
|
|
DaysExtend = data.InvestigationDaysExtend,
|
|
DateStart = sumExtend > 0 && data.InvestigationDateEnd != null ? data.InvestigationDateEnd.Value.AddDays(data.InvestigationDaysExtend == null ? 0 : -(double)data.InvestigationDaysExtend + 1) : data.InvestigationDateStart,
|
|
DateEnd = data.InvestigationDateEnd,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
}
|
|
var hisDirector = data.DisciplineInvestigate_Directors;
|
|
_context.DisciplineInvestigate_Directors.RemoveRange(data.DisciplineInvestigate_Directors);
|
|
foreach (var item in req.directors)
|
|
{
|
|
var director = await _context.DisciplineDirectors.AsQueryable()
|
|
.FirstOrDefaultAsync(x => x.Id == item);
|
|
if (director != null)
|
|
{
|
|
var isDirector = hisDirector.Where(x => x.DisciplineDirector.Id == director.Id).FirstOrDefault();
|
|
data.DisciplineInvestigate_Directors.Add(
|
|
new DisciplineInvestigate_Director
|
|
{
|
|
DisciplineDirector = director,
|
|
Duty = isDirector == null ? null : isDirector.Duty,
|
|
CommandNo = isDirector == null ? null : isDirector.CommandNo,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
}
|
|
);
|
|
}
|
|
}
|
|
data.Organization = req.organization;
|
|
data.OrganizationId = req.organizationId;
|
|
data.RespondentType = req.respondentType;
|
|
var hisprofile = data.DisciplineInvestigate_ProfileComplaints;
|
|
_context.DisciplineInvestigate_ProfileComplaints.RemoveRange(data.DisciplineInvestigate_ProfileComplaints);
|
|
if (data.RespondentType.Trim().ToUpper() == "PERSON")
|
|
{
|
|
foreach (var item in req.persons)
|
|
{
|
|
var isReport = hisprofile.Where(x => x.PersonId == item.personId).FirstOrDefault();
|
|
data.DisciplineInvestigate_ProfileComplaints.Add(
|
|
new DisciplineInvestigate_ProfileComplaint
|
|
{
|
|
CitizenId = item.idcard,
|
|
Prefix = item.prefix,
|
|
FirstName = item.firstName,
|
|
LastName = item.lastName,
|
|
Organization = item.organization,
|
|
Position = item.position,
|
|
// PositionLevel = item.positionLevel,
|
|
IsAncestorDNA = isReport == null ? false : isReport.IsAncestorDNA,
|
|
Salary = item.salary,
|
|
PersonId = item.personId,
|
|
|
|
root = item.root,
|
|
rootId = item.rootId,
|
|
rootDnaId = item.rootDnaId,
|
|
rootShortName = item.rootShortName,
|
|
child1 = item.child1,
|
|
child1Id = item.child1Id,
|
|
child1DnaId = item.child1DnaId,
|
|
child1ShortName = item.child1ShortName,
|
|
child2 = item.child2,
|
|
child2Id = item.child2Id,
|
|
child2DnaId = item.child2DnaId,
|
|
child2ShortName = item.child2ShortName,
|
|
child3 = item.child3,
|
|
child3Id = item.child3Id,
|
|
child3DnaId = item.child3DnaId,
|
|
child3ShortName = item.child3ShortName,
|
|
child4 = item.child4,
|
|
child4Id = item.child4Id,
|
|
child4DnaId = item.child4DnaId,
|
|
child4ShortName = item.child4ShortName,
|
|
posMasterNo = item.posMasterNo,
|
|
posTypeId = item.posTypeId,
|
|
posTypeName = item.posTypeName,
|
|
posLevelId = item.posLevelId,
|
|
posLevelName = item.posLevelName,
|
|
profileType = item.profileType,
|
|
PosNo = item.posNo,
|
|
IsDisciplinary = isReport == null ? false : isReport.IsDisciplinary,
|
|
IsReport = isReport == null ? "NEW" : isReport.IsReport,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
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>
|
|
[HttpGet("reject/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> RejectDisciplineInvestigate(Guid id)
|
|
{
|
|
var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "SYS_DISCIPLINE_INVESTIGATE");
|
|
if (getWorkflow == false)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_DISCIPLINE_INVESTIGATE");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
}
|
|
var data = await _context.DisciplineInvestigates
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถยุติเรื่องได้"), StatusCodes.Status500InternalServerError);
|
|
if (data.InvestigationStatusResult == null || data.InvestigationStatusResult.Trim().ToUpper() != "NO_CAUSE")
|
|
return Error(new Exception("ไม่สามารถยุติเรื่องได้ จะสามารถยุติเรื่องได้ในกรณีผลการสืบสวนไม่มีมูล"), StatusCodes.Status500InternalServerError);
|
|
data.Status = "STOP";
|
|
|
|
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("approve/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> ApproveDisciplineInvestigate([FromBody] DisciplinePersonIdRequest req, Guid id)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_DISCIPLINE_INVESTIGATE");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var data = await _context.DisciplineInvestigates
|
|
.Include(x => x.DisciplineInvestigate_DocComplaints)
|
|
.ThenInclude(x => x.Document)
|
|
.Include(x => x.DisciplineInvestigate_Docs)
|
|
.ThenInclude(x => x.Document)
|
|
.Include(x => x.DisciplineInvestigateRelevant_Docs)
|
|
.ThenInclude(x => x.Document)
|
|
.Include(x => x.DisciplineInvestigate_ProfileComplaints)
|
|
.Include(x => x.DisciplineInvestigate_Directors)
|
|
.ThenInclude(x => x.DisciplineDirector)
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถส่งต่อไปสอบสวนได้"), (int)StatusCodes.Status500InternalServerError);
|
|
data.Status = "SEND_DISCIPLINARY";
|
|
|
|
var disciplineDisciplinary = new Domain.Models.Discipline.DisciplineDisciplinary
|
|
{
|
|
RespondentType = data.RespondentType.Trim().ToUpper(),
|
|
Organization = data.Organization,
|
|
RootDnaId = data.RootDnaId,
|
|
ConsideredAgency = data.ConsideredAgency,
|
|
OrganizationId = data.OrganizationId,
|
|
ConsideredAgencyId = data.ConsideredAgencyId,
|
|
Title = data.Title,
|
|
Description = data.Description,
|
|
DateReceived = data.DateReceived,
|
|
LevelConsideration = data.LevelConsideration == null ? null : data.LevelConsideration.Trim().ToUpper(),
|
|
DateConsideration = data.DateConsideration,
|
|
OffenseDetails = data.OffenseDetails == null ? null : data.OffenseDetails.Trim().ToUpper(),
|
|
DateNotification = data.DateNotification,
|
|
ComplaintFrom = data.ComplaintFrom,
|
|
Appellant = data.Appellant,
|
|
ResultComplaint = data.ResultComplaint,
|
|
ResultInvestigate = data.Result,
|
|
|
|
InvestigationDetail = data.InvestigationDetail,
|
|
InvestigationDetailOther = data.InvestigationDetailOther,
|
|
InvestigationDateStart = data.InvestigationDateStart,
|
|
InvestigationDateEnd = data.InvestigationDateEnd,
|
|
InvestigationDescription = data.InvestigationDescription,
|
|
InvestigationStatusResult = data.InvestigationStatusResult,
|
|
InvestigationCauseText = data.InvestigationCauseText,
|
|
InvestigationExtendStatus = data.InvestigationExtendStatus,
|
|
InvestigationDaysExtend = data.InvestigationDaysExtend,
|
|
|
|
DisciplinaryExtendStatus = false,
|
|
Status = "NEW",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
var persons = data.DisciplineInvestigate_ProfileComplaints.Where(x => req.persons.Contains(x.Id)).ToList();
|
|
foreach (var item in persons)
|
|
{
|
|
disciplineDisciplinary.DisciplineDisciplinary_ProfileComplaintInvestigates.Add(
|
|
new DisciplineDisciplinary_ProfileComplaintInvestigate
|
|
{
|
|
PersonId = item.PersonId,
|
|
CitizenId = item.CitizenId,
|
|
Prefix = item.Prefix,
|
|
FirstName = item.FirstName,
|
|
LastName = item.LastName,
|
|
Organization = item.Organization,
|
|
|
|
root = item.root,
|
|
rootId = item.rootId,
|
|
rootDnaId = item.rootDnaId,
|
|
rootShortName = item.rootShortName,
|
|
child1 = item.child1,
|
|
child1Id = item.child1Id,
|
|
child1DnaId = item.child1DnaId,
|
|
child1ShortName = item.child1ShortName,
|
|
child2 = item.child2,
|
|
child2Id = item.child2Id,
|
|
child2DnaId = item.child2DnaId,
|
|
child2ShortName = item.child2ShortName,
|
|
child3 = item.child3,
|
|
child3Id = item.child3Id,
|
|
child3DnaId = item.child3DnaId,
|
|
child3ShortName = item.child3ShortName,
|
|
child4 = item.child4,
|
|
child4Id = item.child4Id,
|
|
child4DnaId = item.child4DnaId,
|
|
child4ShortName = item.child4ShortName,
|
|
posMasterNo = item.posMasterNo,
|
|
posTypeId = item.posTypeId,
|
|
posTypeName = item.posTypeName,
|
|
posLevelId = item.posLevelId,
|
|
posLevelName = item.posLevelName,
|
|
profileType = item.profileType,
|
|
Salary = item.Salary,
|
|
PosNo = item.PosNo,
|
|
Position = item.Position,
|
|
// PositionLevel = item.PositionLevel,
|
|
IsAncestorDNA = true,
|
|
Status = "NEW",
|
|
StatusDiscard = "NEW",
|
|
IsReport = "NEW",
|
|
IsSuspend = "NEW",
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
item.IsDisciplinary = true;
|
|
}
|
|
foreach (var item in data.DisciplineInvestigate_DocComplaints)
|
|
{
|
|
disciplineDisciplinary.DisciplineDisciplinary_DocComplaintInvestigates.Add(
|
|
new DisciplineDisciplinary_DocComplaintInvestigate
|
|
{
|
|
Document = item.Document,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
}
|
|
foreach (var item in data.DisciplineInvestigate_Docs)
|
|
{
|
|
disciplineDisciplinary.DisciplineDisciplinary_DocInvestigates.Add(
|
|
new DisciplineDisciplinary_DocInvestigate
|
|
{
|
|
Document = item.Document,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
}
|
|
foreach (var item in data.DisciplineInvestigateRelevant_Docs)
|
|
{
|
|
disciplineDisciplinary.DisciplineDisciplinary_DocInvestigateRelevants.Add(
|
|
new DisciplineDisciplinary_DocInvestigateRelevant
|
|
{
|
|
Document = item.Document,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
});
|
|
}
|
|
var baseAPIOrg = _configuration["API"];
|
|
var apiUrlOrg = $"{baseAPIOrg}/org/workflow/find/director";
|
|
var refId = new List<Guid>();
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
|
client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]);
|
|
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
|
{
|
|
refId = persons.Select(x => x.PersonId),
|
|
});
|
|
var _result = await _res.Content.ReadAsStringAsync();
|
|
var org = JsonConvert.DeserializeObject<DirectorRequest>(_result);
|
|
if (_res.IsSuccessStatusCode)
|
|
{
|
|
refId = org.result.Select(x => Guid.Parse(x.id)).ToList();
|
|
}
|
|
}
|
|
await _repositoryNoti.PushNotificationsAsync(
|
|
refId.ToArray(),
|
|
$"มีคำขอสอบสวนเรื่อง {data.Title}",
|
|
$"มีคำขอสอบสวนเรื่อง {data.Title}",
|
|
"",
|
|
"",
|
|
true,
|
|
true
|
|
);
|
|
|
|
data.DisciplineDisciplinarys.Add(disciplineDisciplinary);
|
|
await _context.SaveChangesAsync();
|
|
return Success(disciplineDisciplinary.Id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// ยกเลิกการยุติเรื่อง
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("resume/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> ResumeDisciplineInvestigate(Guid id)
|
|
{
|
|
var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "SYS_DISCIPLINE_INVESTIGATE");
|
|
if (getWorkflow == false)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_DISCIPLINE_INVESTIGATE");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
}
|
|
var data = await _context.DisciplineInvestigates
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "STOP")
|
|
return Error(new Exception("รายการนี้ยังไม่ถูกยุติเรื่อง"), StatusCodes.Status500InternalServerError);
|
|
data.Status = "NEW";
|
|
|
|
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>> UploadFileDisciplineInvestigate([FromForm] DisciplineFileRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineInvestigates
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), 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 disciplineInvestigate_Doc = new DisciplineInvestigate_Doc
|
|
{
|
|
DisciplineInvestigate = data,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.DisciplineInvestigate_Docs.AddAsync(disciplineInvestigate_Doc);
|
|
}
|
|
}
|
|
}
|
|
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>> DeleteFileDisciplineInvestigate(Guid id, Guid docId)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("DELETE", "SYS_DISCIPLINE_INVESTIGATE");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var data = await _context.DisciplineInvestigates
|
|
.Include(x => x.DisciplineInvestigate_Docs)
|
|
.ThenInclude(x => x.Document)
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
|
|
var dataDoc = data.DisciplineInvestigate_Docs.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDoc != null)
|
|
{
|
|
_context.DisciplineInvestigate_Docs.Remove(dataDoc);
|
|
await _context.SaveChangesAsync();
|
|
await _documentService.DeleteFileAsync(docId);
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
else
|
|
{
|
|
return Error(new Exception("ไม่พบไฟล์นี้ในระบบ"), (int)StatusCodes.Status404NotFound);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// อัพไฟล์เอกสารร้องเรียนวินัย
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("complaint/file/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> UploadFileDisciplineInvestigateComplaint([FromForm] DisciplineFileRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineInvestigates
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), 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 disciplineInvestigate_DocComplaint = new DisciplineInvestigate_DocComplaint
|
|
{
|
|
DisciplineInvestigate = data,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.DisciplineInvestigate_DocComplaints.AddAsync(disciplineInvestigate_DocComplaint);
|
|
}
|
|
}
|
|
}
|
|
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("complaint/file/{id:guid}/{docId:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> DeleteFileDisciplineInvestigateComplaint(Guid id, Guid docId)
|
|
{
|
|
var data = await _context.DisciplineInvestigates
|
|
.Include(x => x.DisciplineInvestigate_DocComplaints)
|
|
.ThenInclude(x => x.Document)
|
|
.Include(x => x.DisciplineComplaint)
|
|
.ThenInclude(x => x.DisciplineComplaint_Docs)
|
|
.ThenInclude(x => x.Document)
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
|
|
var dataDoc = data.DisciplineInvestigate_DocComplaints.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDoc != null)
|
|
{
|
|
_context.DisciplineInvestigate_DocComplaints.Remove(dataDoc);
|
|
await _context.SaveChangesAsync();
|
|
var dataDocComplaint = data.DisciplineComplaint.DisciplineComplaint_Docs.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDocComplaint == null)
|
|
{
|
|
await _documentService.DeleteFileAsync(docId);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
return Success();
|
|
}
|
|
else
|
|
{
|
|
return Error(new Exception("ไม่พบไฟล์นี้ในระบบ"), (int)StatusCodes.Status404NotFound);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// อัพไฟล์เอกสารเกี่ยวข้องสืบสวนวินัย
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("relevant/file/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> UploadFileDisciplineInvestigateRelevant([FromForm] DisciplineFileRequest req, Guid id)
|
|
{
|
|
var data = await _context.DisciplineInvestigates
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), 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 disciplineInvestigateRelevant_Doc = new DisciplineInvestigateRelevant_Doc
|
|
{
|
|
DisciplineInvestigate = data,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.DisciplineInvestigateRelevant_Docs.AddAsync(disciplineInvestigateRelevant_Doc);
|
|
}
|
|
}
|
|
}
|
|
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("relevant/file/{id:guid}/{docId:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> DeleteFileDisciplineInvestigateRelevant(Guid id, Guid docId)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("DELETE", "SYS_DISCIPLINE_INVESTIGATE");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var data = await _context.DisciplineInvestigates
|
|
.Include(x => x.DisciplineInvestigateRelevant_Docs)
|
|
.ThenInclude(x => x.Document)
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
if (data.Status.Trim().ToUpper() != "NEW")
|
|
return Error(new Exception("ไม่สามารถแก้ไขข้อมูลนี้ได้"), StatusCodes.Status500InternalServerError);
|
|
var dataDoc = data.DisciplineInvestigateRelevant_Docs.Where(x => x.Document.Id == docId).FirstOrDefault();
|
|
if (dataDoc != null)
|
|
{
|
|
_context.DisciplineInvestigateRelevant_Docs.Remove(dataDoc);
|
|
await _context.SaveChangesAsync();
|
|
await _documentService.DeleteFileAsync(docId);
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
else
|
|
{
|
|
return Error(new Exception("ไม่พบไฟล์นี้ในระบบ"), (int)StatusCodes.Status404NotFound);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ปฏิทินรายการวินัยเรื่องสืบสวน
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("calendar")]
|
|
public async Task<ActionResult<ResponseObject>> GetCalendarDisciplineInvestigate([FromBody] DisciplineCalendarRequest req)
|
|
{
|
|
var data = await _context.DisciplineInvestigates
|
|
.Where(x => x.InvestigationDateStart != null)
|
|
.Where(x => x.InvestigationDateEnd != null)
|
|
.Where(x => x.InvestigationDateStart.Value.Year == req.year || x.InvestigationDateEnd.Value.Year == req.year || x.InvestigationDateStart.Value.Month == req.month || x.InvestigationDateEnd.Value.Month == req.month)
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,//id ข้อมูลเรื่องสืบสวน
|
|
Title = x.Title,//ชื่อเรื่อง
|
|
InvestigationDateStart = x.InvestigationDateStart,//
|
|
InvestigationDateEnd = x.InvestigationDateEnd,//
|
|
})
|
|
.OrderBy(d => d.InvestigationDateStart.Value.Date)
|
|
.ToListAsync();
|
|
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("report")]
|
|
// [HttpPut("report/{commandTypeId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> PostToReport([FromForm] DisciplineProfileRequest req)
|
|
{
|
|
foreach (var item in req.id)
|
|
{
|
|
var uppdated = await _context.DisciplineInvestigate_ProfileComplaints
|
|
.FirstOrDefaultAsync(x => x.Id == item);
|
|
if (uppdated == null)
|
|
continue;
|
|
|
|
uppdated.IsReport = "DONE";
|
|
uppdated.RemarkReject = req.remark;
|
|
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
|
uppdated.LastUpdateUserId = UserId ?? "";
|
|
uppdated.LastUpdatedAt = DateTime.Now;
|
|
|
|
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)
|
|
{
|
|
uppdated.DocumentReject = _doc;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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("director/{disciplineId:guid}/{id:guid}")]
|
|
public async Task<ActionResult<ResponseObject>> AddDutyDisciplineInvestigate([FromBody] DisciplineDutyRequest req, Guid disciplineId, Guid id)
|
|
{
|
|
var data = await _context.DisciplineInvestigates
|
|
.Include(x => x.DisciplineInvestigate_Directors)
|
|
.Where(x => x.Id == disciplineId)
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
var director = data.DisciplineInvestigate_Directors.FirstOrDefault(x => x.Id == id);
|
|
if (director == null)
|
|
return Error(new Exception(GlobalMessages.DataNotFound), StatusCodes.Status404NotFound);
|
|
director.Duty = req.duty;
|
|
director.CommandNo = req.commandNo;
|
|
director.LastUpdateFullName = FullName ?? "System Administrator";
|
|
director.LastUpdateUserId = UserId ?? "";
|
|
director.LastUpdatedAt = DateTime.Now;
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
}
|
|
}
|