คำสั่งวินัยบันทึกลงทะเบยีน

This commit is contained in:
Kittapath 2024-06-26 23:28:27 +07:00
parent 6586fe0bab
commit 410db00812
3 changed files with 155 additions and 5 deletions

View file

@ -11,6 +11,8 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Swashbuckle.AspNetCore.Annotations;
using System.Configuration;
using System.Net.Http.Headers;
using System.Security.Claims;
namespace BMA.EHR.DisciplineResult.Service.Controllers
@ -26,15 +28,18 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers
private readonly DisciplineDbContext _context;
private readonly MinIODisciplineService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IConfiguration _configuration;
public DisciplineResultController(DisciplineDbContext context,
MinIODisciplineService documentService,
IHttpContextAccessor httpContextAccessor)
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration)
{
// _repository = repository;
_context = context;
_documentService = documentService;
_httpContextAccessor = httpContextAccessor;
_configuration = configuration;
}
#region " Properties "
@ -42,6 +47,7 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers
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
@ -465,6 +471,7 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers
foreach (var d in req.result)
{
var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates
.Include(x=>x.DisciplineDisciplinary)
.Where(x => x.Status == "REPORT")
.Where(x => x.Id == d.id)
.FirstOrDefaultAsync();
@ -472,6 +479,24 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers
{
data.Status = "NEW";
data.CommandTypeId = null;
var baseAPI = _configuration["API"];
var apiUrlDiscipline = $"{baseAPI}org/profile/discipline";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlDiscipline);
var _res = await client.PostAsJsonAsync(apiUrlDiscipline, new
{
profileId = d.personId,
date = d.commandAffectDate,
detail = data.DisciplineDisciplinary.Title,
level = data.DisciplineDisciplinary.DisciplinaryFaultLevel,
refCommandDate = "",
refCommandNo = $"{d.commandNo}/{d.commandYear}",
unStigma = d.detail,
});
var _result = await _res.Content.ReadAsStringAsync();
}
}
await _context.SaveChangesAsync();
}
@ -492,6 +517,7 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers
foreach (var d in req.result)
{
var data = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates
.Include(x => x.DisciplineDisciplinary)
.Where(x => x.StatusDiscard == "REPORT")
.Where(x => x.Id == d.id)
.FirstOrDefaultAsync();
@ -499,6 +525,24 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers
{
data.StatusDiscard = "NEW";
data.CommandTypeDiscardId = null;
var baseAPI = _configuration["API"];
var apiUrlDiscipline = $"{baseAPI}org/profile/discipline";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlDiscipline);
var _res = await client.PostAsJsonAsync(apiUrlDiscipline, new
{
profileId = d.personId,
date = d.commandAffectDate,
detail = data.DisciplineDisciplinary.Title,
level = data.DisciplineDisciplinary.DisciplinaryFaultLevel,
refCommandDate = "",
refCommandNo = $"{d.commandNo}/{d.commandYear}",
unStigma = d.detail,
});
var _result = await _res.Content.ReadAsStringAsync();
}
}
await _context.SaveChangesAsync();
}
@ -519,17 +563,58 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers
foreach (var d in req.result)
{
var data1 = await _context.DisciplineInvestigate_ProfileComplaints
.Include(x => x.DisciplineInvestigate)
.Where(x => x.IsReport == "REPORT")
.Where(x => x.Id == d.id)
.FirstOrDefaultAsync();
if (data1 != null)
{
data1.IsReport = "NEW";
var baseAPI = _configuration["API"];
var apiUrlDiscipline = $"{baseAPI}org/profile/discipline";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlDiscipline);
var _res = await client.PostAsJsonAsync(apiUrlDiscipline, new
{
profileId = d.personId,
date = d.commandAffectDate,
detail = data1.DisciplineInvestigate.Title,
level = "",
refCommandDate = "",
refCommandNo = $"{d.commandNo}/{d.commandYear}",
unStigma = d.detail,
});
var _result = await _res.Content.ReadAsStringAsync();
}
}
var data2 = await _context.DisciplineDisciplinary_ProfileComplaintInvestigates
.Include(x => x.DisciplineDisciplinary)
.Where(x => x.IsReport == "REPORT")
.Where(x => x.Id == d.id)
.FirstOrDefaultAsync();
if (data2 != null)
data2.IsReport = "NEW";
if (data2 != null) {
data2.IsReport = "NEW";
var baseAPI = _configuration["API"];
var apiUrlDiscipline = $"{baseAPI}org/profile/discipline";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlDiscipline);
var _res = await client.PostAsJsonAsync(apiUrlDiscipline, new
{
profileId = d.personId,
date = d.commandAffectDate,
detail = data2.DisciplineDisciplinary.Title,
level = data2.DisciplineDisciplinary.DisciplinaryFaultLevel,
refCommandDate = "",
refCommandNo = $"{d.commandNo}/{d.commandYear}",
unStigma = d.detail,
});
var _result = await _res.Content.ReadAsStringAsync();
}
}
await _context.SaveChangesAsync();
}
return Success();
@ -549,11 +634,31 @@ namespace BMA.EHR.DisciplineResult.Service.Controllers
foreach (var d in req.result)
{
var data = await _context.DisciplineReport_Profiles
.Include(x => x.DisciplineDisciplinary)
.Where(x => x.Status == "REPORT")
.Where(x => x.Id == d.id)
.FirstOrDefaultAsync();
if (data != null)
if (data != null) {
data.Status = "DONE";
var baseAPI = _configuration["API"];
var apiUrlDiscipline = $"{baseAPI}org/profile/discipline";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlDiscipline);
var _res = await client.PostAsJsonAsync(apiUrlDiscipline, new
{
profileId = d.personId,
date = d.commandAffectDate,
detail = data.DisciplineDisciplinary.Title,
level = data.DisciplineDisciplinary.DisciplinaryFaultLevel,
refCommandDate = "",
refCommandNo = $"{d.commandNo}/{d.commandYear}",
unStigma = d.detail,
});
var _result = await _res.Content.ReadAsStringAsync();
}
}
await _context.SaveChangesAsync();
}
return Success();