fix Issue : 723

This commit is contained in:
Suphonchai Phoonsawat 2024-11-11 20:46:45 +07:00
parent 4970659f0a
commit ddb541c819
7 changed files with 1362 additions and 3 deletions

View file

@ -397,6 +397,34 @@ namespace BMA.EHR.Application.Repositories
}
}
public GetUserOCIdDto? GetUserOC(Guid keycloakId, string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/user-oc/{keycloakId}";
var apiKey = _configuration["API_KEY"];
var apiResult = GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult.Result != null)
{
var raw = JsonConvert.DeserializeObject<GetUserOCIdDto>(apiResult.Result);
return raw;
//if (raw == null || raw.RootId == null)
// return Guid.Empty;
//return raw.RootId;
}
return null;
}
catch
{
throw;
}
}
public Guid? GetRootOcId(Guid ocId, string? accessToken)
{
try

View file

@ -44,6 +44,16 @@ namespace BMA.EHR.Application.Responses.Profiles
public string? ProfileType { get; set; }
public bool? IsLeave { get; set; }
public string? Root { get; set; }
public string? Child1 { get; set; }
public string? Child2 { get; set; }
public string? Child3 { get; set; }
public string? Child4 { get; set; }
}
public class PosLevel

View file

@ -162,5 +162,16 @@ namespace BMA.EHR.Domain.Models.Leave.Requests
public string? LastName { get; set; }
public string? CitizenId { get; set; }
public string? Root { get; set; }
public string? Child1 { get; set; }
public string? Child2 { get; set; }
public string? Child3 { get; set; }
public string? Child4 { get; set; }
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,73 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
{
/// <inheritdoc />
public partial class addrootinfo : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Child1",
table: "LeaveRequests",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "Child2",
table: "LeaveRequests",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "Child3",
table: "LeaveRequests",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "Child4",
table: "LeaveRequests",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "Root",
table: "LeaveRequests",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Child1",
table: "LeaveRequests");
migrationBuilder.DropColumn(
name: "Child2",
table: "LeaveRequests");
migrationBuilder.DropColumn(
name: "Child3",
table: "LeaveRequests");
migrationBuilder.DropColumn(
name: "Child4",
table: "LeaveRequests");
migrationBuilder.DropColumn(
name: "Root",
table: "LeaveRequests");
}
}
}

View file

@ -217,6 +217,18 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
.HasColumnType("longtext")
.HasComment("เขียนที่ (ขอยกเลิก)");
b.Property<string>("Child1")
.HasColumnType("longtext");
b.Property<string>("Child2")
.HasColumnType("longtext");
b.Property<string>("Child3")
.HasColumnType("longtext");
b.Property<string>("Child4")
.HasColumnType("longtext");
b.Property<string>("CitizenId")
.HasColumnType("longtext");
@ -437,6 +449,9 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
b.Property<double>("RestDayOldTotal")
.HasColumnType("double");
b.Property<string>("Root")
.HasColumnType("longtext");
b.Property<string>("StudyDayCountry")
.IsRequired()
.HasColumnType("longtext");

View file

@ -18,6 +18,7 @@ using Newtonsoft.Json;
using Swashbuckle.AspNetCore.Annotations;
using System.Security.Claims;
using System.Net.Http.Headers;
using BMA.EHR.Domain.Models.MetaData;
namespace BMA.EHR.Leave.Service.Controllers
{
@ -188,6 +189,12 @@ namespace BMA.EHR.Leave.Service.Controllers
FirstName = profile.FirstName,
LastName = profile.LastName,
CitizenId = profile.CitizenId,
Root = profile.Root,
Child1 = profile.Child1,
Child2 = profile.Child2,
Child3 = profile.Child3,
Child4 = profile.Child4,
};
// get leave last
@ -327,7 +334,7 @@ namespace BMA.EHR.Leave.Service.Controllers
leaveRequest.Dear = approver;
leaveRequest.PositionName = profile.Position == null ? "" : profile.Position;
leaveRequest.PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel.PosLevelName;
leaveRequest.OrganizationName = profile.Oc ?? "";
leaveRequest.OrganizationName = profile.Root ?? "";
@ -337,6 +344,42 @@ namespace BMA.EHR.Leave.Service.Controllers
return Success(new { id = leaveRequest.Id });
}
[HttpGet("update-leave-root")]
[AllowAnonymous]
public async Task<IActionResult> UpdateRootForLeaveRequestAsync()
{
var leaves = await _context.Set<LeaveRequest>().ToListAsync();
foreach (var leave in leaves)
{
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(leave.KeycloakUserId, AccessToken);
if (profile != null)
{
leave.Prefix = profile.Prefix;
leave.FirstName = profile.FirstName;
leave.LastName = profile.LastName;
leave.CitizenId = profile.CitizenId;
leave.PositionName = profile.Position == null ? "" : profile.Position;
leave.PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel.PosLevelName;
leave.OrganizationName = profile.Root ?? "";
leave.Root = profile.Root ?? "";
leave.Child1 = profile.Child1 ?? "";
leave.Child2 = profile.Child2 ?? "";
leave.Child3 = profile.Child3 ?? "";
leave.Child4 = profile.Child4 ?? "";
}
}
await _context.SaveChangesAsync();
return Ok("update success");
}
/// <summary>
/// LV2_020 - แก้ไขคำขอการลา
@ -1124,6 +1167,9 @@ namespace BMA.EHR.Leave.Service.Controllers
{
//var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(item.KeycloakUserId, AccessToken);
//var userOc = _userProfileRepository.GetUserOC(item.KeycloakUserId, AccessToken);
// Get Organization
//var org = await _userProfileRepository.GetOrganizationById(profile.OcId ?? Guid.Empty);
@ -1134,6 +1180,11 @@ namespace BMA.EHR.Leave.Service.Controllers
//var gov_agency = await _userProfileRepository.GetOrgGovAgencyById(gov_agency_id);
var agency_name = string.Concat(item.Child1 != string.Empty ? item.Child1 + "/" : "",
item.Child2 != string.Empty ? item.Child2 + "/" : "",
item.Child3 != string.Empty ? item.Child3 + "/" : "",
item.Child4 != string.Empty ? item.Child4 : "")
.Trim();
var res = new GetLeaveRequestForAdminResultDto
{
Id = item.Id,
@ -1147,11 +1198,12 @@ namespace BMA.EHR.Leave.Service.Controllers
LeaveEndDate = item.LeaveEndDate,
Position = item.PositionName ?? "-",
Level = item.PositionLevelName ?? "-",
Agency = "-", //agency == null ? "" : agency.Name,
Org = "-", //gov_agency == null ? "" : gov_agency.Name,
Agency = agency_name,//agency == null ? "" : agency.Name,
Org = item.Root ?? "",//userOc == null ? "-" : userOc.Root,
LeaveRange = item.LeaveRange ?? "ALL",
HajjDayStatus = item.HajjDayStatus,
};
result.Add(res);
}