766 lines
37 KiB
C#
766 lines
37 KiB
C#
using BMA.EHR.Application.Repositories;
|
|
using BMA.EHR.Application.Repositories.MessageQueue;
|
|
using BMA.EHR.Domain.Common;
|
|
using BMA.EHR.Domain.Models.Placement;
|
|
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 Newtonsoft.Json;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
using System.Net.Http.Headers;
|
|
using System.Security.Claims;
|
|
|
|
namespace BMA.EHR.Placement.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/placement/Receive")]
|
|
[ApiVersion("1.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("ระบบรับโอน")]
|
|
public class PlacementReceiveController : BaseController
|
|
{
|
|
private readonly PlacementRepository _repository;
|
|
private readonly NotificationRepository _repositoryNoti;
|
|
private readonly ApplicationDBContext _context;
|
|
private readonly MinIOService _documentService;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly IConfiguration _configuration;
|
|
|
|
public PlacementReceiveController(PlacementRepository repository,
|
|
NotificationRepository repositoryNoti,
|
|
ApplicationDBContext context,
|
|
MinIOService documentService,
|
|
IHttpContextAccessor httpContextAccessor,
|
|
IConfiguration configuration)
|
|
{
|
|
_repository = repository;
|
|
_repositoryNoti = repositoryNoti;
|
|
_context = context;
|
|
_documentService = documentService;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_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"];
|
|
|
|
private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
|
|
|
|
#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>> GetListByAdmin()
|
|
{
|
|
// 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();
|
|
|
|
// 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 placementReceives = await _context.PlacementReceives.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.citizenId,
|
|
p.Status,
|
|
p.RecruitDate,
|
|
p.root,
|
|
p.rootId,
|
|
p.rootShortName,
|
|
p.child1,
|
|
p.child1Id,
|
|
p.child1ShortName,
|
|
p.child2,
|
|
p.child2Id,
|
|
p.child2ShortName,
|
|
p.child3,
|
|
p.child3Id,
|
|
p.child3ShortName,
|
|
p.child4,
|
|
p.child4Id,
|
|
p.child4ShortName,
|
|
p.orgRevisionId,
|
|
p.positionId,
|
|
p.posMasterNo,
|
|
p.position,
|
|
p.positionField,
|
|
p.posTypeId,
|
|
p.posTypeName,
|
|
p.posLevelId,
|
|
p.posLevelName,
|
|
|
|
p.IsActive,
|
|
p.Reason,
|
|
p.EducationOld,
|
|
p.AmountOld,
|
|
p.PositionTypeOld,
|
|
p.PositionLevelOld,
|
|
p.PositionNumberOld,
|
|
p.OrganizationPositionOld,
|
|
p.OrganizationOld,
|
|
|
|
p.rootOld,
|
|
p.rootOldId,
|
|
p.rootShortNameOld,
|
|
p.child1Old,
|
|
p.child1OldId,
|
|
p.child1ShortNameOld,
|
|
p.child2Old,
|
|
p.child2OldId,
|
|
p.child2ShortNameOld,
|
|
p.child3Old,
|
|
p.child3OldId,
|
|
p.child3ShortNameOld,
|
|
p.child4Old,
|
|
p.child4OldId,
|
|
p.child4ShortNameOld,
|
|
p.posMasterNoOld,
|
|
p.positionOld,
|
|
p.posTypeOldId,
|
|
p.posTypeNameOld,
|
|
p.posLevelOldId,
|
|
p.posLevelNameOld,
|
|
p.CreatedAt,
|
|
})
|
|
.ToListAsync();
|
|
// if (PlacementAdmin == true)
|
|
// placementReceives.Where(x => x.Status.Trim().ToUpper().Contains("PENDING"));
|
|
|
|
return Success(placementReceives);
|
|
// }
|
|
}
|
|
|
|
/// <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>> GetDetailByUser(Guid id)
|
|
{
|
|
var data = await _context.PlacementReceives.AsQueryable()
|
|
.Where(x => x.Id == id)
|
|
.Select(p => new
|
|
{
|
|
p.Id,
|
|
// ProfileId = p.Profile.Id,
|
|
p.citizenId,
|
|
p.prefix,
|
|
p.firstName,
|
|
p.lastName,
|
|
p.DateOfBirth,
|
|
Gender = p.Gender == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Gender.Id,
|
|
p.Nationality,
|
|
p.Race,
|
|
Religion = p.Religion == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Religion.Id,
|
|
BloodGroup = p.BloodGroup == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.BloodGroup.Id,
|
|
Relationship = p.Relationship == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Relationship.Id,
|
|
p.TelephoneNumber,
|
|
p.Status,
|
|
p.Amount,
|
|
p.RecruitDate,
|
|
p.root,
|
|
p.rootId,
|
|
p.rootShortName,
|
|
p.child1,
|
|
p.child1Id,
|
|
p.child1ShortName,
|
|
p.child2,
|
|
p.child2Id,
|
|
p.child2ShortName,
|
|
p.child3,
|
|
p.child3Id,
|
|
p.child3ShortName,
|
|
p.child4,
|
|
p.child4Id,
|
|
p.child4ShortName,
|
|
p.orgRevisionId,
|
|
p.positionId,
|
|
p.posMasterNo,
|
|
p.position,
|
|
p.positionField,
|
|
p.posTypeId,
|
|
p.posTypeName,
|
|
p.posLevelId,
|
|
p.posLevelName,
|
|
|
|
p.CreatedAt,
|
|
p.Reason,
|
|
p.EducationOld,
|
|
p.AmountOld,
|
|
p.PositionOld,
|
|
p.OrganizationOld,
|
|
p.PositionTypeOld,
|
|
p.PositionLevelOld,
|
|
p.PositionNumberOld,
|
|
p.OrganizationPositionOld,
|
|
p.IsActive,
|
|
|
|
p.rootOld,
|
|
p.rootOldId,
|
|
p.rootShortNameOld,
|
|
p.child1Old,
|
|
p.child1OldId,
|
|
p.child1ShortNameOld,
|
|
p.child2Old,
|
|
p.child2OldId,
|
|
p.child2ShortNameOld,
|
|
p.child3Old,
|
|
p.child3OldId,
|
|
p.child3ShortNameOld,
|
|
p.child4Old,
|
|
p.child4OldId,
|
|
p.child4ShortNameOld,
|
|
p.posMasterNoOld,
|
|
p.posTypeOldId,
|
|
p.posTypeNameOld,
|
|
p.posLevelOldId,
|
|
p.posLevelNameOld,
|
|
|
|
// Avatar = p.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Avatar.Id,
|
|
PlacementReceiveDocs = p.PlacementReceiveDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
|
|
})
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(GlobalMessages.DataNotFound, 404);
|
|
|
|
var placementReceiveDocs = new List<dynamic>();
|
|
foreach (var doc in data.PlacementReceiveDocs)
|
|
{
|
|
var _doc = new
|
|
{
|
|
doc.FileName,
|
|
PathName = await _documentService.ImagesPath(doc.Id)
|
|
};
|
|
placementReceiveDocs.Add(_doc);
|
|
}
|
|
var _data = new
|
|
{
|
|
data.Id,
|
|
// data.ProfileId,
|
|
data.citizenId,
|
|
data.prefix,
|
|
data.firstName,
|
|
data.lastName,
|
|
data.DateOfBirth,
|
|
data.Gender,
|
|
data.Nationality,
|
|
data.Race,
|
|
data.Religion,
|
|
data.BloodGroup,
|
|
data.Relationship,
|
|
data.TelephoneNumber,
|
|
data.Status,
|
|
data.Amount,
|
|
data.RecruitDate,
|
|
data.root,
|
|
data.rootId,
|
|
data.rootShortName,
|
|
data.child1,
|
|
data.child1Id,
|
|
data.child1ShortName,
|
|
data.child2,
|
|
data.child2Id,
|
|
data.child2ShortName,
|
|
data.child3,
|
|
data.child3Id,
|
|
data.child3ShortName,
|
|
data.child4,
|
|
data.child4Id,
|
|
data.child4ShortName,
|
|
node = data.root == null ? (int?)null : (data.child1 == null ? 0 : (data.child2 == null ? 1 : (data.child3 == null ? 2 : (data.child4 == null ? 3 : 4)))),
|
|
nodeName = data.root == null ? null : (data.child1 == null ? data.root : (data.child2 == null ? data.child1 : (data.child3 == null ? data.child2 : (data.child4 == null ? data.child3 : data.child4)))),
|
|
nodeId = data.rootId == null ? null : (data.child1Id == null ? data.rootId : (data.child2Id == null ? data.child1Id : (data.child3Id == null ? data.child2Id : (data.child4Id == null ? data.child3Id : data.child4Id)))),
|
|
nodeShortName = data.rootShortName == null ? null : (data.child1ShortName == null ? data.rootShortName : (data.child2ShortName == null ? data.child1ShortName : (data.child3ShortName == null ? data.child2ShortName : (data.child4ShortName == null ? data.child3ShortName : data.child4ShortName)))),
|
|
data.orgRevisionId,
|
|
data.positionId,
|
|
data.posMasterNo,
|
|
data.position,
|
|
data.positionField,
|
|
data.posTypeId,
|
|
data.posTypeName,
|
|
data.posLevelId,
|
|
data.posLevelName,
|
|
|
|
data.CreatedAt,
|
|
data.Reason,
|
|
data.EducationOld,
|
|
data.AmountOld,
|
|
data.PositionOld,
|
|
data.OrganizationOld,
|
|
data.PositionTypeOld,
|
|
data.PositionLevelOld,
|
|
data.PositionNumberOld,
|
|
data.OrganizationPositionOld,
|
|
data.IsActive,
|
|
|
|
data.rootOld,
|
|
data.rootOldId,
|
|
data.rootShortNameOld,
|
|
data.child1Old,
|
|
data.child1OldId,
|
|
data.child1ShortNameOld,
|
|
data.child2Old,
|
|
data.child2OldId,
|
|
data.child2ShortNameOld,
|
|
data.child3Old,
|
|
data.child3OldId,
|
|
data.child3ShortNameOld,
|
|
data.child4Old,
|
|
data.child4OldId,
|
|
data.child4ShortNameOld,
|
|
data.posMasterNoOld,
|
|
data.posTypeOldId,
|
|
data.posTypeNameOld,
|
|
data.posLevelOldId,
|
|
data.posLevelNameOld,
|
|
|
|
// Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
|
|
Docs = placementReceiveDocs,
|
|
};
|
|
|
|
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] PlacementReceiveRequest req)
|
|
{
|
|
var placementReceive = new PlacementReceive
|
|
{
|
|
// Profile = profile,
|
|
citizenId = req.citizenId,
|
|
prefix = req.prefix,
|
|
firstName = req.firstName,
|
|
lastName = req.lastName,
|
|
DateOfBirth = req.BirthDate,
|
|
Gender = await _context.Genders.FindAsync(req.GenderId),
|
|
Nationality = req.Nationality,
|
|
Race = req.Race,
|
|
Religion = await _context.Religions.FindAsync(req.ReligionId),
|
|
BloodGroup = await _context.BloodGroups.FindAsync(req.BloodGroupId),
|
|
Relationship = await _context.Relationships.FindAsync(req.RelationshipId),
|
|
TelephoneNumber = req.TelephoneNumber,
|
|
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/citizenid/position/{req.citizenId}";
|
|
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)
|
|
{
|
|
placementReceive.profileId = org.result.profileId;
|
|
placementReceive.prefix = org.result.prefix;
|
|
placementReceive.firstName = org.result.firstName;
|
|
placementReceive.lastName = org.result.lastName;
|
|
placementReceive.citizenId = org.result.citizenId;
|
|
placementReceive.rootOld = org.result.root;
|
|
placementReceive.rootOldId = org.result.rootId;
|
|
placementReceive.rootShortNameOld = org.result.rootShortName;
|
|
placementReceive.child1Old = org.result.child1;
|
|
placementReceive.child1OldId = org.result.child1Id;
|
|
placementReceive.child1ShortNameOld = org.result.child1ShortName;
|
|
placementReceive.child2Old = org.result.child2;
|
|
placementReceive.child2OldId = org.result.child2Id;
|
|
placementReceive.child2ShortNameOld = org.result.child2ShortName;
|
|
placementReceive.child3Old = org.result.child3;
|
|
placementReceive.child3OldId = org.result.child3Id;
|
|
placementReceive.child3ShortNameOld = org.result.child3ShortName;
|
|
placementReceive.child4Old = org.result.child4;
|
|
placementReceive.child4OldId = org.result.child4Id;
|
|
placementReceive.child4ShortNameOld = org.result.child4ShortName;
|
|
placementReceive.posMasterNoOld = org.result.posMasterNo;
|
|
placementReceive.posTypeOldId = org.result.posTypeId;
|
|
placementReceive.posTypeNameOld = org.result.posTypeName;
|
|
placementReceive.posLevelOldId = org.result.posLevelId;
|
|
placementReceive.posLevelNameOld = org.result.posLevelName;
|
|
|
|
// placementReceive.EducationOld = profile.Educations.Count() == 0 ? null : $"{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Degree}-{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Field}";
|
|
// placementReceive.AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount;
|
|
|
|
placementReceive.PositionOld = org.result.position;
|
|
placementReceive.PositionLevelOld = org.result.posLevelName;
|
|
placementReceive.PositionTypeOld = org.result.posTypeName;
|
|
placementReceive.PositionNumberOld = org.result.nodeShortName + org.result.posMasterNo;
|
|
placementReceive.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "/") +
|
|
(org.result.child3 == null ? "" : org.result.child3 + "/") +
|
|
(org.result.child2 == null ? "" : org.result.child2 + "/") +
|
|
(org.result.child1 == null ? "" : org.result.child1 + "/") +
|
|
(org.result.root == null ? "" : org.result.root + "/");
|
|
placementReceive.OrganizationPositionOld = org.result.position + "-" + placementReceive.OrganizationOld;
|
|
}
|
|
}
|
|
await _context.PlacementReceives.AddAsync(placementReceive);
|
|
await _context.SaveChangesAsync();
|
|
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
|
|
{
|
|
var file = Request.Form.Files[0];
|
|
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)
|
|
{
|
|
placementReceive.Avatar = _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("upload/{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> PostFile([FromForm] PlacementFileRequest req, Guid id)
|
|
{
|
|
var uppdated = await _context.PlacementReceives
|
|
.Include(x => x.PlacementReceiveDocs)
|
|
.ThenInclude(x => x.Document)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (uppdated == null)
|
|
return Error(GlobalMessages.PlacementReceiveNotFound, 404);
|
|
|
|
var placementReceiveDocs = new List<dynamic>();
|
|
foreach (var doc in uppdated.PlacementReceiveDocs)
|
|
{
|
|
if (doc.Document != null)
|
|
placementReceiveDocs.Add(doc.Document.Id);
|
|
}
|
|
_context.PlacementReceiveDocs.RemoveRange(uppdated.PlacementReceiveDocs);
|
|
await _context.SaveChangesAsync();
|
|
foreach (var doc in placementReceiveDocs)
|
|
{
|
|
if (doc != null)
|
|
await _documentService.DeleteFileAsync(doc);
|
|
}
|
|
|
|
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 placementReceiveDoc = new PlacementReceiveDoc
|
|
{
|
|
PlacementReceive = uppdated,
|
|
Document = _doc,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.PlacementReceiveDocs.AddAsync(placementReceiveDoc);
|
|
}
|
|
}
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// เลือกหน่วยงาน
|
|
/// </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>
|
|
[HttpPut("position/{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> UpdatePositionPlacementReceive([FromBody] PersonSelectPositionReceiveRequest req, Guid id)
|
|
{
|
|
var uppdated = await _context.PlacementReceives
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (uppdated == null)
|
|
return Error(GlobalMessages.PlacementReceiveNotFound, 404);
|
|
|
|
var apiUrl = $"{_configuration["API"]}org/find/all";
|
|
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
|
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
|
|
var _res = await client.PostAsJsonAsync(apiUrl, new
|
|
{
|
|
node = req.node,
|
|
nodeId = req.nodeId,
|
|
});
|
|
var _result = await _res.Content.ReadAsStringAsync();
|
|
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
|
|
|
|
if (org == null || org.result == null)
|
|
return Error("ไม่พบหน่วยงานนี้ในระบบ", 404);
|
|
|
|
uppdated.root = org.result.root;
|
|
uppdated.rootId = org.result.rootId;
|
|
uppdated.rootShortName = org.result.rootShortName;
|
|
uppdated.child1 = req.node <= 0 ? null : org.result.child1;
|
|
uppdated.child1Id = req.node <= 0 ? null : org.result.child1Id;
|
|
uppdated.child1ShortName = req.node <= 0 ? null : org.result.child1ShortName;
|
|
uppdated.child2 = req.node <= 1 ? null : org.result.child2;
|
|
uppdated.child2Id = req.node <= 1 ? null : org.result.child2Id;
|
|
uppdated.child2ShortName = req.node <= 1 ? null : org.result.child2ShortName;
|
|
uppdated.child3 = req.node <= 2 ? null : org.result.child3;
|
|
uppdated.child3Id = req.node <= 2 ? null : org.result.child3Id;
|
|
uppdated.child3ShortName = req.node <= 2 ? null : org.result.child3ShortName;
|
|
uppdated.child4 = req.node <= 3 ? null : org.result.child4;
|
|
uppdated.child4Id = req.node <= 3 ? null : org.result.child4Id;
|
|
uppdated.child4ShortName = req.node <= 3 ? null : org.result.child4ShortName;
|
|
}
|
|
|
|
uppdated.posmasterId = req.posmasterId;
|
|
uppdated.node = req.node;
|
|
uppdated.nodeId = req.nodeId;
|
|
uppdated.orgRevisionId = req.orgRevisionId;
|
|
uppdated.positionId = req.positionId;
|
|
uppdated.posMasterNo = req.posMasterNo;
|
|
uppdated.position = req.position;
|
|
uppdated.positionField = req.positionField;
|
|
uppdated.posTypeId = req.posTypeId;
|
|
uppdated.posTypeName = req.posTypeName;
|
|
uppdated.posLevelId = req.posLevelId;
|
|
uppdated.posLevelName = req.posLevelName;
|
|
uppdated.Amount = req.Amount;
|
|
uppdated.RecruitDate = req.RecruitDate;
|
|
uppdated.Status = "PENDING";
|
|
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
|
uppdated.LastUpdateUserId = UserId ?? "";
|
|
uppdated.LastUpdatedAt = DateTime.Now;
|
|
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("{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> Put([FromBody] PlacementReceiveEditRequest req, Guid id)
|
|
{
|
|
var uppdated = await _context.PlacementReceives
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (uppdated == null)
|
|
return Error(GlobalMessages.PlacementReceiveNotFound, 404);
|
|
|
|
if (req.RelationshipId != null)
|
|
{
|
|
var save = await _context.Relationships.FindAsync(req.RelationshipId);
|
|
if (save == null)
|
|
return Error(GlobalMessages.RelationshipNotFound, 404);
|
|
uppdated.Relationship = save;
|
|
}
|
|
|
|
if (req.ReligionId != null)
|
|
{
|
|
var save = await _context.Religions.FindAsync(req.ReligionId);
|
|
if (save == null)
|
|
return Error(GlobalMessages.ReligionNotFound, 404);
|
|
uppdated.Religion = save;
|
|
}
|
|
|
|
if (req.BloodGroupId != null)
|
|
{
|
|
var save = await _context.BloodGroups.FindAsync(req.BloodGroupId);
|
|
if (save == null)
|
|
return Error(GlobalMessages.BloodGroupNotFound, 404);
|
|
uppdated.BloodGroup = save;
|
|
}
|
|
|
|
if (req.GenderId != null)
|
|
{
|
|
var save = await _context.Genders.FindAsync(req.GenderId);
|
|
if (save == null)
|
|
return Error(GlobalMessages.GenderNotFound, 404);
|
|
uppdated.Gender = save;
|
|
}
|
|
uppdated.citizenId = req.citizenId;
|
|
uppdated.prefix = req.prefix;
|
|
uppdated.firstName = req.firstName;
|
|
uppdated.lastName = req.lastName;
|
|
uppdated.DateOfBirth = req.DateOfBirth;
|
|
uppdated.Nationality = req.Nationality;
|
|
uppdated.Race = req.Race;
|
|
uppdated.TelephoneNumber = req.TelephoneNumber;
|
|
uppdated.EducationOld = req.EducationOld;
|
|
uppdated.Reason = req.Reason;
|
|
uppdated.OrganizationPositionOld = req.OrganizationPositionOld;
|
|
uppdated.PositionTypeOld = req.PositionTypeOld;
|
|
uppdated.PositionLevelOld = req.PositionLevelOld;
|
|
uppdated.PositionNumberOld = req.PositionNumberOld;
|
|
uppdated.Amount = req.Amount;
|
|
uppdated.AmountOld = req.AmountOld;
|
|
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
|
uppdated.LastUpdateUserId = UserId ?? "";
|
|
uppdated.LastUpdatedAt = DateTime.Now;
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ลบรับโอน
|
|
/// </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>
|
|
[HttpDelete("{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> Delete(Guid id)
|
|
{
|
|
var deleted = await _context.PlacementReceives.AsQueryable()
|
|
.Include(x => x.PlacementReceiveDocs)
|
|
.ThenInclude(x => x.Document)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (deleted == null)
|
|
return NotFound();
|
|
var placementReceiveDocs = new List<dynamic>();
|
|
foreach (var doc in deleted.PlacementReceiveDocs)
|
|
{
|
|
if (doc.Document != null)
|
|
placementReceiveDocs.Add(doc.Document.Id);
|
|
}
|
|
_context.PlacementReceiveDocs.RemoveRange(deleted.PlacementReceiveDocs);
|
|
await _context.SaveChangesAsync();
|
|
_context.PlacementReceives.Remove(deleted);
|
|
foreach (var doc in placementReceiveDocs)
|
|
{
|
|
if (doc != null)
|
|
await _documentService.DeleteFileAsync(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>
|
|
[HttpPost("report")]
|
|
public async Task<ActionResult<ResponseObject>> PostToReport([FromBody] PlacementProfileRequest req)
|
|
{
|
|
foreach (var item in req.Id)
|
|
{
|
|
var uppdated = await _context.PlacementReceives
|
|
.FirstOrDefaultAsync(x => x.Id == item);
|
|
if (uppdated == null)
|
|
continue;
|
|
uppdated.Status = "REPORT";
|
|
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
|
uppdated.LastUpdateUserId = UserId ?? "";
|
|
uppdated.LastUpdatedAt = DateTime.Now;
|
|
}
|
|
|
|
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>
|
|
// [HttpGet("use")]
|
|
// public async Task<ActionResult<ResponseObject>> GetReceiveUse()
|
|
// {
|
|
// var receives = await _context.PlacementReceives
|
|
// .Where(x => x.PositionNumber != null)
|
|
// .Select(x => x.PositionNumber.Id)
|
|
// .ToListAsync();
|
|
|
|
// return Success(receives);
|
|
// }
|
|
}
|
|
}
|