แก้ระบบบรรจุผูกโครงสร้างใหม่
This commit is contained in:
parent
57164f5d45
commit
18d75f4b04
37 changed files with 79295 additions and 3904 deletions
|
|
@ -50,7 +50,7 @@ namespace BMA.EHR.Placement.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"];
|
||||
private string? token => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
|
||||
|
||||
private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
|
||||
|
||||
|
|
@ -67,141 +67,6 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
[HttpGet()]
|
||||
public async Task<ActionResult<ResponseObject>> GetListByAdmin()
|
||||
{
|
||||
|
||||
var placementOfficers = await _context.PlacementOfficers.AsQueryable()
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(p => new
|
||||
{
|
||||
p.Id,
|
||||
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
|
||||
p.Profile.FirstName,
|
||||
p.Profile.LastName,
|
||||
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : (p.Profile.PositionEmployeePosition == null ? null : p.Profile.PositionEmployeePosition.Name),
|
||||
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
|
||||
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : (p.Profile.PositionEmployeeLevel == null ? null : p.Profile.PositionEmployeeLevel.Name),
|
||||
p.CreatedAt,
|
||||
p.Organization,
|
||||
p.Reason,
|
||||
p.Status,
|
||||
p.DateStart,
|
||||
p.DateEnd,
|
||||
salary = p.AmountOld,
|
||||
p.PositionTypeOld,
|
||||
p.PositionLevelOld,
|
||||
p.PositionNumberOld,
|
||||
p.OrganizationPositionOld,
|
||||
p.IsActive,
|
||||
})
|
||||
.ToListAsync();
|
||||
if (PlacementAdmin == true)
|
||||
placementOfficers.Where(x => x.Status.Trim().ToUpper().Contains("APPROVE"));
|
||||
|
||||
return Success(placementOfficers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get รายละเอียดช่วยราชการเจ้าหน้าที่
|
||||
/// </summary>
|
||||
/// <param name="id">Id ช่วยราชการ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetDetailAdmin(Guid id)
|
||||
{
|
||||
var data = await _context.PlacementOfficers.AsQueryable()
|
||||
.Where(x => x.Id == id)
|
||||
.Where(x => x.Profile != null)
|
||||
.Select(p => new
|
||||
{
|
||||
p.Id,
|
||||
PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id,
|
||||
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
|
||||
p.Profile.FirstName,
|
||||
p.Profile.LastName,
|
||||
ProfileId = p.Profile.Id,
|
||||
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : (p.Profile.PositionEmployeePosition == null ? null : p.Profile.PositionEmployeePosition.Name),
|
||||
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
|
||||
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : (p.Profile.PositionEmployeeLevel == null ? null : p.Profile.PositionEmployeeLevel.Name),
|
||||
organizationOrganization = p.Profile.OrganizationOrganization,
|
||||
p.Reason,
|
||||
p.Status,
|
||||
p.Organization,
|
||||
p.DateStart,
|
||||
p.DateEnd,
|
||||
salary = p.AmountOld,
|
||||
p.CreatedAt,
|
||||
p.PositionTypeOld,
|
||||
p.PositionLevelOld,
|
||||
p.PositionNumberOld,
|
||||
p.OrganizationPositionOld,
|
||||
Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id,
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
if (data == null)
|
||||
return Error(GlobalMessages.DataNotFound, 404);
|
||||
var _data = new
|
||||
{
|
||||
data.Id,
|
||||
data.PrefixId,
|
||||
data.Prefix,
|
||||
data.FirstName,
|
||||
data.LastName,
|
||||
data.ProfileId,
|
||||
data.position,
|
||||
data.posNo,
|
||||
data.positionLevel,
|
||||
data.organizationOrganization,
|
||||
data.Reason,
|
||||
data.Status,
|
||||
data.Organization,
|
||||
data.DateStart,
|
||||
data.DateEnd,
|
||||
data.salary,
|
||||
data.CreatedAt,
|
||||
data.PositionTypeOld,
|
||||
data.PositionLevelOld,
|
||||
data.PositionNumberOld,
|
||||
data.OrganizationPositionOld,
|
||||
Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
|
||||
};
|
||||
|
||||
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()]
|
||||
public async Task<ActionResult<ResponseObject>> Post([FromForm] PlacementAddProfileRequest req)
|
||||
{
|
||||
var placementOfficer = new PlacementOfficer
|
||||
{
|
||||
// Profile = profile,
|
||||
Organization = Request.Form.ContainsKey("Organization") ? Request.Form["Organization"] : "",
|
||||
Reason = Request.Form.ContainsKey("Reason") ? Request.Form["Reason"] : "",
|
||||
// Date = req.Date,
|
||||
// AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount,
|
||||
// PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
|
||||
// PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
|
||||
// PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
|
||||
// OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
|
||||
|
||||
Status = "WAITTING",
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
};
|
||||
var rootId = "";
|
||||
var child1Id = "";
|
||||
var child2Id = "";
|
||||
|
|
@ -219,7 +84,142 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
|
||||
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 placementOfficers = await _context.PlacementOfficers.AsQueryable()
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Where(x => PlacementAdmin == true ? true : (rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))))
|
||||
.Select(p => new
|
||||
{
|
||||
p.Id,
|
||||
p.prefix,
|
||||
p.firstName,
|
||||
p.lastName,
|
||||
p.root,
|
||||
p.rootShortName,
|
||||
p.child1,
|
||||
p.child1ShortName,
|
||||
p.child2,
|
||||
p.child2ShortName,
|
||||
p.child3,
|
||||
p.child3ShortName,
|
||||
p.child4,
|
||||
p.child4ShortName,
|
||||
p.posMasterNo,
|
||||
p.position,
|
||||
p.posLevelName,
|
||||
p.posTypeName,
|
||||
p.CreatedAt,
|
||||
p.Reason,
|
||||
p.Status,
|
||||
p.DateStart,
|
||||
p.DateEnd,
|
||||
p.Organization,
|
||||
p.OrganizationPositionOld,
|
||||
p.IsActive,
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return Success(placementOfficers);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get รายละเอียดช่วยราชการเจ้าหน้าที่
|
||||
/// </summary>
|
||||
/// <param name="id">Id ช่วยราชการ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetDetailAdmin(Guid id)
|
||||
{
|
||||
var data = await _context.PlacementOfficers.AsQueryable()
|
||||
.Where(x => x.Id == id)
|
||||
.Select(p => new
|
||||
{
|
||||
p.Id,
|
||||
p.profileId,
|
||||
p.prefix,
|
||||
p.firstName,
|
||||
p.lastName,
|
||||
p.root,
|
||||
p.rootShortName,
|
||||
p.child1,
|
||||
p.child1ShortName,
|
||||
p.child2,
|
||||
p.child2ShortName,
|
||||
p.child3,
|
||||
p.child3ShortName,
|
||||
p.child4,
|
||||
p.child4ShortName,
|
||||
p.posMasterNo,
|
||||
p.position,
|
||||
p.posLevelName,
|
||||
p.posTypeName,
|
||||
p.CreatedAt,
|
||||
p.Reason,
|
||||
p.Status,
|
||||
p.DateStart,
|
||||
p.DateEnd,
|
||||
p.Organization,
|
||||
p.OrganizationPositionOld,
|
||||
p.IsActive,
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
if (data == null)
|
||||
return Error(GlobalMessages.DataNotFound, 404);
|
||||
|
||||
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()]
|
||||
public async Task<ActionResult<ResponseObject>> Post([FromForm] PlacementAddProfileRequest req)
|
||||
{
|
||||
var placementOfficer = new PlacementOfficer
|
||||
{
|
||||
Organization = Request.Form.ContainsKey("Organization") ? Request.Form["Organization"] : "",
|
||||
Reason = Request.Form.ContainsKey("Reason") ? Request.Form["Reason"] : "",
|
||||
Status = "WAITTING",
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
};
|
||||
var apiUrl = $"{_configuration["API"]}org/profile/profileid/position/{req.Id}";
|
||||
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();
|
||||
|
||||
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
|
||||
|
||||
if (org == null || org.result == null)
|
||||
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
|
||||
|
||||
placementOfficer.profileId = org.result.profileId;
|
||||
placementOfficer.prefix = org.result.prefix;
|
||||
placementOfficer.firstName = org.result.firstName;
|
||||
placementOfficer.lastName = org.result.lastName;
|
||||
placementOfficer.citizenId = org.result.citizenId;
|
||||
placementOfficer.root = org.result.root;
|
||||
placementOfficer.rootId = org.result.rootId;
|
||||
placementOfficer.rootShortName = org.result.rootShortName;
|
||||
|
|
@ -235,6 +235,12 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
placementOfficer.child4 = org.result.child4;
|
||||
placementOfficer.child4Id = org.result.child4Id;
|
||||
placementOfficer.child4ShortName = org.result.child4ShortName;
|
||||
placementOfficer.posMasterNo = org.result.posMasterNo;
|
||||
placementOfficer.position = org.result.position;
|
||||
placementOfficer.posTypeId = org.result.posTypeId;
|
||||
placementOfficer.posTypeName = org.result.posTypeName;
|
||||
placementOfficer.posLevelId = org.result.posLevelId;
|
||||
placementOfficer.posLevelName = org.result.posLevelName;
|
||||
}
|
||||
await _context.PlacementOfficers.AddAsync(placementOfficer);
|
||||
await _context.SaveChangesAsync();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue