แก้คำสั่ง

This commit is contained in:
Kittapath 2024-06-24 09:33:18 +07:00
parent 0495d0f647
commit e47eca3235
7 changed files with 20199 additions and 5340 deletions

File diff suppressed because it is too large Load diff

View file

@ -90,13 +90,14 @@ namespace BMA.EHR.Command.Service.Controllers
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
private string? token => _httpContextAccessor.HttpContext.Request.Headers["Authorization"];
private Guid OcId
{
get
{
if (UserId != null || UserId != "")
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), token);
else
return Guid.Empty;
}
@ -4859,6 +4860,7 @@ namespace BMA.EHR.Command.Service.Controllers
FirstName = p.FirstName,
LastName = p.LastName,
OrganizationName = p.OrganizationName,
ReceiveUserId = p.ProfileId.ToString(),
PositionName = p.Position
});
}
@ -5395,11 +5397,22 @@ namespace BMA.EHR.Command.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetCommandOrganizationAsync()
public async Task<ActionResult<ResponseObject>> GetCommandOrganizationAsync([FromHeader] string authorization)
{
try
{
var data = await _repository.GetCommandOrgAsync();
var token = string.Empty;
if (AuthenticationHeaderValue.TryParse(authorization, out var headerValue))
{
// we have a valid AuthenticationHeaderValue that has the following details:
var scheme = headerValue.Scheme;
token = headerValue.Parameter;
// scheme will be "Bearer"
// parmameter will be the token itself.
}
var data = await _repository.GetCommandOrgAsync(token);
return Success(data);
}

View file

@ -253,6 +253,9 @@ namespace BMA.EHR.Domain.Models.Placement
public string? RemarkHorizontal { get; set; }
[Comment("profileId")]
public string? profileId { get; set; }
[Comment("ระดับโครงสร้าง")]
public int? node { get; set; }

View file

@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class updatetableCommandReceiveraddProfile : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "profileId",
table: "PlacementProfiles",
type: "longtext",
nullable: true,
comment: "profileId")
.Annotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "profileId",
table: "PlacementProfiles");
}
}
}

View file

@ -12490,6 +12490,10 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("longtext")
.HasComment("id อัตรากำลัง");
b.Property<string>("profileId")
.HasColumnType("longtext")
.HasComment("profileId");
b.Property<string>("root")
.HasColumnType("longtext")
.HasComment("ชื่อหน่วยงาน root");

View file

@ -151,6 +151,7 @@ namespace BMA.EHR.Placement.Service.Controllers
StatusId = x.PlacementStatus,
Draft = x.Draft,
typeCommand = x.typeCommand,
IsOfficer = x.IsOfficer,
posLevelCandidateId = x.PositionLevel == null ? (Guid?)null : x.PositionLevel.Id,
posTypeCandidateId = x.PositionType == null ? (Guid?)null : x.PositionType.Id,
}).OrderBy(x => x.ExamNumber).ToListAsync();
@ -197,7 +198,7 @@ namespace BMA.EHR.Placement.Service.Controllers
p.PositionCandidate,
p.PositionCandidateId,
p.ReportingDate,
BmaOfficer = p.IdCard == null ? null : await _documentService.CheckBmaOfficer(p.IdCard),
BmaOfficer = p.IsOfficer == true ? "OFFICER" : null,
p.StatusId,
p.Draft,
p.typeCommand,
@ -275,6 +276,7 @@ namespace BMA.EHR.Placement.Service.Controllers
StatusId = x.PlacementStatus,
Draft = x.Draft,
typeCommand = x.typeCommand,
IsOfficer = x.IsOfficer,
posLevelCandidateId = x.PositionLevel == null ? (Guid?)null : x.PositionLevel.Id,
posTypeCandidateId = x.PositionType == null ? (Guid?)null : x.PositionType.Id,
}).OrderBy(x => x.ExamNumber).ToListAsync();
@ -321,7 +323,7 @@ namespace BMA.EHR.Placement.Service.Controllers
p.PositionCandidate,
p.PositionCandidateId,
p.ReportingDate,
BmaOfficer = p.IdCard == null ? null : await _documentService.CheckBmaOfficer(p.IdCard),
BmaOfficer = p.IsOfficer == true ? "OFFICER" : null,
p.StatusId,
p.Draft,
p.typeCommand,
@ -448,7 +450,7 @@ namespace BMA.EHR.Placement.Service.Controllers
ExamRound = x.ExamRound,
Pass = x.Pass,
IsProperty = x.IsProperty == null ? null : Newtonsoft.Json.JsonConvert.DeserializeObject<List<PersonPropertyRequest>>(x.IsProperty),
BmaOfficer = "",
BmaOfficer = x.IsOfficer == true ? "OFFICER" : null,
PlacementProfileDocs = x.PlacementProfileDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
}).FirstOrDefaultAsync(x => x.PersonalId == personalId);
@ -525,7 +527,7 @@ namespace BMA.EHR.Placement.Service.Controllers
data.ExamRound,
data.Pass,
data.IsProperty,
BmaOfficer = data.IdCard == null ? null : await _documentService.CheckBmaOfficer(data.IdCard),
BmaOfficer = data.BmaOfficer,
Docs = placementProfileDocs,
};
return Success(_data);
@ -568,24 +570,47 @@ namespace BMA.EHR.Placement.Service.Controllers
}
else
{
var profileOrg = await _context.Profiles.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(UserId ?? "00000000-0000-0000-0000-000000000000"));
if (profileOrg == null)
return Error(GlobalMessages.DataNotFound, 404);
var ocIdList = _documentService.GetAllIdByRoot(profileOrg.OcId);
var placement = await _context.Placements
.Where(x => x.Id == examId)
.Select(x => new
{
Total = x.PlacementProfiles.Where(p => ocIdList.Contains(p.OrganizationPosition.Organization.Id)).Count(),
UnContain = x.PlacementProfiles.Where(p => ocIdList.Contains(p.OrganizationPosition.Organization.Id)).Where(p => p.PlacementStatus.Trim().ToUpper() == "UN-CONTAIN").Count(),
PrepareContain = x.PlacementProfiles.Where(p => ocIdList.Contains(p.OrganizationPosition.Organization.Id)).Where(p => p.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN").Count(),
Contain = x.PlacementProfiles.Where(p => ocIdList.Contains(p.OrganizationPosition.Organization.Id)).Where(p => p.PlacementStatus.Trim().ToUpper() == "CONTAIN").Count(),
Disclaim = x.PlacementProfiles.Where(p => ocIdList.Contains(p.OrganizationPosition.Organization.Id)).Where(p => p.PlacementStatus.Trim().ToUpper() == "DISCLAIM").Count(),
}).FirstOrDefaultAsync();
if (placement == null)
return Error(GlobalMessages.DataNotFound, 404);
var rootId = "";
var child1Id = "";
var child2Id = "";
var child3Id = "";
var child4Id = "";
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();
return Success(placement);
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
rootId = org.result.rootId == null ? "" : org.result.rootId;
child1Id = org.result.child1Id == null ? "" : org.result.child1Id;
child2Id = org.result.child2Id == null ? "" : org.result.child2Id;
child3Id = org.result.child3Id == null ? "" : org.result.child3Id;
child4Id = org.result.child4Id == null ? "" : org.result.child4Id;
// var profileOrg = await _context.Profiles.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(UserId ?? "00000000-0000-0000-0000-000000000000"));
// if (profileOrg == null)
// return Error(GlobalMessages.DataNotFound, 404);
// var ocIdList = _documentService.GetAllIdByRoot(profileOrg.OcId);
var placement = await _context.Placements
.Where(x => x.Id == examId)
.Select(x => new
{
Total = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Count(),
UnContain = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "UN-CONTAIN").Count(),
PrepareContain = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN").Count(),
Contain = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "CONTAIN").Count(),
Disclaim = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "DISCLAIM").Count(),
}).FirstOrDefaultAsync();
if (placement == null)
return Error(GlobalMessages.DataNotFound, 404);
return Success(placement);
}
}
}