1031 lines
57 KiB
C#
1031 lines
57 KiB
C#
using BMA.EHR.Application.Repositories;
|
|
using BMA.EHR.Application.Repositories.MessageQueue;
|
|
using BMA.EHR.Domain.Common;
|
|
using BMA.EHR.Domain.Extensions;
|
|
using BMA.EHR.Domain.Models.Retirement;
|
|
using BMA.EHR.Domain.Shared;
|
|
using BMA.EHR.Infrastructure.Persistence;
|
|
using BMA.EHR.Retirement.Service.Requests;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
using System.Net.Http.Headers;
|
|
using System.Security.Claims;
|
|
|
|
namespace BMA.EHR.Retirement.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/retirement/other")]
|
|
[ApiVersion("1.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("ระบบอื่นๆ")]
|
|
public class RetirementOtherController : BaseController
|
|
{
|
|
private readonly RetirementRepository _repository;
|
|
private readonly NotificationRepository _repositoryNoti;
|
|
private readonly ApplicationDBContext _context;
|
|
private readonly MinIOService _documentService;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly PermissionRepository _permission;
|
|
|
|
public RetirementOtherController(RetirementRepository repository,
|
|
NotificationRepository repositoryNoti,
|
|
ApplicationDBContext context,
|
|
MinIOService documentService,
|
|
IHttpContextAccessor httpContextAccessor,
|
|
IConfiguration configuration,
|
|
PermissionRepository permission)
|
|
{
|
|
_repository = repository;
|
|
_repositoryNoti = repositoryNoti;
|
|
_context = context;
|
|
_documentService = documentService;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_configuration = configuration;
|
|
_permission = permission;
|
|
}
|
|
|
|
#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"];
|
|
|
|
#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()
|
|
// public async Task<ActionResult<ResponseObject>> GetListByAdmin(int page = 1, int pageSize = 10, string keyword = "")
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_PLACEMENT_OTHER");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var rootId = "";
|
|
var child1Id = "";
|
|
var child2Id = "";
|
|
var child3Id = "";
|
|
var child4Id = "";
|
|
var apiUrl = $"{_configuration["API"]}/org/permission/checkOrg/{UserId}";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
|
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
|
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 retirementOthers = await _context.RetirementOthers.AsQueryable()
|
|
.OrderByDescending(x => x.CreatedAt)
|
|
// .Where(x => rootId == "" ? true : (child1Id == "" ? x.rootOldId == rootId : (child2Id == "" ? x.child1OldId == child1Id : (child3Id == "" ? x.child2OldId == child2Id : (child4Id == "" ? x.child3OldId == child3Id : x.child4OldId == child4Id)))))
|
|
.Select(p => new
|
|
{
|
|
p.Id,
|
|
p.citizenId,
|
|
p.profileId,
|
|
p.prefix,
|
|
p.firstName,
|
|
p.lastName,
|
|
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.PositionOld,
|
|
p.posMasterNoOld,
|
|
p.posTypeOldId,
|
|
p.posTypeNameOld,
|
|
p.posLevelOldId,
|
|
p.posLevelNameOld,
|
|
p.Status,
|
|
p.CreatedAt,
|
|
p.Reason,
|
|
p.MilitaryDate,
|
|
p.EducationOld,
|
|
p.AmountOld,
|
|
p.PositionTypeOld,
|
|
p.PositionLevelOld,
|
|
p.PositionNumberOld,
|
|
p.OrganizationPositionOld,
|
|
p.PositionDate,
|
|
CommandType = p.CommandType == null ? null : p.CommandType.Name,
|
|
})
|
|
.ToListAsync();
|
|
// if (keyword != "")
|
|
// {
|
|
// var data = retirementOthers.Where(x =>
|
|
// (x.prefix != null && x.prefix.Contains(keyword)) ||
|
|
// (x.firstName != null && x.firstName.Contains(keyword)) ||
|
|
// (x.lastName != null && x.lastName.Contains(keyword)) ||
|
|
// (x.rootShortNameOld != null && x.rootShortNameOld.Contains(keyword)) ||
|
|
// (x.posMasterNoOld != null && x.posMasterNoOld.ToString().Contains(keyword)) ||
|
|
// (x.posTypeNameOld != null && x.posTypeNameOld.Contains(keyword)) ||
|
|
// (x.posLevelNameOld != null && x.posLevelNameOld.Contains(keyword)) ||
|
|
// (x.OrganizationPositionOld != null && x.OrganizationPositionOld.Contains(keyword)) ||
|
|
// (x.Reason != null && x.Reason.Contains(keyword)))
|
|
// .OrderByDescending(x => x.CreatedAt)
|
|
// .Skip((page - 1) * pageSize)
|
|
// .Take(pageSize)
|
|
// .ToList();
|
|
|
|
// retirementOthers = data;
|
|
// }
|
|
|
|
return Success(retirementOthers);
|
|
}
|
|
}
|
|
|
|
/// <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 getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(id.ToString(), "SYS_PLACEMENT_OTHER");
|
|
if (getWorkflow == false)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_PLACEMENT_OTHER");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
}
|
|
var data = await _context.RetirementOthers.AsQueryable()
|
|
.Where(x => x.Id == id)
|
|
.Select(p => new
|
|
{
|
|
p.Id,
|
|
p.profileId,
|
|
p.prefix,
|
|
p.firstName,
|
|
p.lastName,
|
|
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,
|
|
p.Status,
|
|
p.CreatedAt,
|
|
p.Reason,
|
|
p.MilitaryDate,
|
|
p.EducationOld,
|
|
p.AmountOld,
|
|
p.PositionTypeOld,
|
|
p.PositionLevelOld,
|
|
p.PositionNumberOld,
|
|
p.OrganizationPositionOld,
|
|
p.PositionOld,
|
|
p.OrganizationOld,
|
|
p.PositionDate,
|
|
// Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id,
|
|
// RetirementOtherDocs = p.RetirementOtherDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
|
|
CommandType = p.CommandType == null ? null : p.CommandType.Name,
|
|
})
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(GlobalMessages.DataNotFound, 404);
|
|
|
|
// var retirementOtherDocs = new List<dynamic>();
|
|
// foreach (var doc in data.RetirementOtherDocs)
|
|
// {
|
|
// var _doc = new
|
|
// {
|
|
// doc.FileName,
|
|
// PathName = await _documentService.ImagesPath(doc.Id)
|
|
// };
|
|
// retirementOtherDocs.Add(_doc);
|
|
// }
|
|
// var _data = new
|
|
// {
|
|
// data.Id,
|
|
// data.ProfileId,
|
|
// data.CitizenId,
|
|
// data.Prefix,
|
|
// data.PrefixId,
|
|
// 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.PosNo,
|
|
// data.Position,
|
|
// data.PositionPathSide,
|
|
// data.PositionType,
|
|
// data.PositionLine,
|
|
// data.PositionLevel,
|
|
// data.OrganizationPositionId,
|
|
// data.CreatedAt,
|
|
// data.Reason,
|
|
// data.MilitaryDate,
|
|
// data.EducationOld,
|
|
// data.AmountOld,
|
|
// data.PositionTypeOld,
|
|
// data.PositionLevelOld,
|
|
// data.PositionNumberOld,
|
|
// data.OrganizationPositionOld,
|
|
// data.PositionDate,
|
|
// // Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
|
|
// // Docs = retirementOtherDocs,
|
|
// data.CommandType,
|
|
// };
|
|
|
|
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] RetirementAddProfileRequest req)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_PLACEMENT_OTHER");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var retirementOther = new RetirementOther
|
|
{
|
|
// Profile = profile,
|
|
// CitizenId = profile.CitizenId,
|
|
// Prefix = profile.Prefix,
|
|
// Firstname = profile.FirstName,
|
|
// Lastname = profile.LastName,
|
|
// DateOfBirth = profile.BirthDate,
|
|
// Gender = profile.Gender,
|
|
// Nationality = profile.Nationality,
|
|
// Race = profile.Race,
|
|
// Religion = await _context.Religions.FindAsync(profile.ReligionId),
|
|
// BloodGroup = await _context.BloodGroups.FindAsync(profile.BloodGroupId),
|
|
// Relationship = await _context.Relationships.FindAsync(profile.RelationshipId),
|
|
// TelephoneNumber = profile.TelephoneNumber,
|
|
// EducationOld = profile.Educations.Count() == 0 ? null : $"{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Degree}-{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Field}",
|
|
// 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}",
|
|
// PositionNumber = profile.PosNo,
|
|
// PositionPath = profile.Position,
|
|
// PositionPathSide = await _context.PositionPathSides.FindAsync(profile.PositionPathSideId),
|
|
// PositionType = profile.PositionType,
|
|
// PositionLine = await _context.PositionLines.FindAsync(profile.PositionLineId),
|
|
// PositionLevel = profile.PositionLevel,
|
|
// OrganizationPositionId = p.OrganizationPosition == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.OrganizationPosition.Id,
|
|
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 ", ""));
|
|
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
|
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);
|
|
|
|
retirementOther.profileId = org.result.profileId;
|
|
retirementOther.prefix = org.result.prefix;
|
|
retirementOther.firstName = org.result.firstName;
|
|
retirementOther.lastName = org.result.lastName;
|
|
retirementOther.citizenId = org.result.citizenId;
|
|
retirementOther.rootOld = org.result.root;
|
|
retirementOther.rootOldId = org.result.rootId;
|
|
retirementOther.rootShortNameOld = org.result.rootShortName;
|
|
retirementOther.child1Old = org.result.child1;
|
|
retirementOther.child1OldId = org.result.child1Id;
|
|
retirementOther.child1ShortNameOld = org.result.child1ShortName;
|
|
retirementOther.child2Old = org.result.child2;
|
|
retirementOther.child2OldId = org.result.child2Id;
|
|
retirementOther.child2ShortNameOld = org.result.child2ShortName;
|
|
retirementOther.child3Old = org.result.child3;
|
|
retirementOther.child3OldId = org.result.child3Id;
|
|
retirementOther.child3ShortNameOld = org.result.child3ShortName;
|
|
retirementOther.child4Old = org.result.child4;
|
|
retirementOther.child4OldId = org.result.child4Id;
|
|
retirementOther.child4ShortNameOld = org.result.child4ShortName;
|
|
retirementOther.posMasterNoOld = org.result.posMasterNo;
|
|
retirementOther.posTypeOldId = org.result.posTypeId;
|
|
retirementOther.posTypeNameOld = org.result.posTypeName;
|
|
retirementOther.posLevelOldId = org.result.posLevelId;
|
|
retirementOther.posLevelNameOld = org.result.posLevelName;
|
|
|
|
retirementOther.LeaveDate = org.result.leaveDate;
|
|
retirementOther.PositionOld = org.result.position;
|
|
retirementOther.PositionLevelOld = org.result.posLevelName;
|
|
retirementOther.PositionTypeOld = org.result.posTypeName;
|
|
retirementOther.PositionNumberOld = org.result.nodeShortName + org.result.posMasterNo;
|
|
retirementOther.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);
|
|
retirementOther.OrganizationPositionOld = org.result.position + "/" + retirementOther.OrganizationOld;
|
|
retirementOther.EducationOld = org.result.education;
|
|
retirementOther.AmountOld = org.result.salary;
|
|
}
|
|
await _context.RetirementOthers.AddAsync(retirementOther);
|
|
await _context.SaveChangesAsync();
|
|
// 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 retirementOtherDoc = new RetirementOtherDoc
|
|
// {
|
|
// RetirementOther = retirementOther,
|
|
// Document = _doc,
|
|
// CreatedFullName = FullName ?? "System Administrator",
|
|
// CreatedUserId = UserId ?? "",
|
|
// CreatedAt = DateTime.Now,
|
|
// LastUpdateFullName = FullName ?? "System Administrator",
|
|
// LastUpdateUserId = UserId ?? "",
|
|
// LastUpdatedAt = DateTime.Now,
|
|
// };
|
|
// await _context.RetirementOtherDocs.AddAsync(retirementOtherDoc);
|
|
|
|
// }
|
|
// }
|
|
// }
|
|
// 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>> UpdatePositionRetirementOther([FromBody] PersonSelectPositionOtherRequest req, Guid id)
|
|
// {
|
|
// var uppdated = await _context.RetirementOthers
|
|
// .FirstOrDefaultAsync(x => x.Id == id);
|
|
// if (uppdated == null)
|
|
// return Error(GlobalMessages.RetirementOtherNotFound, 404);
|
|
// if (req.PosNoId != null)
|
|
// {
|
|
// var save_posNo = await _context.PositionNumbers.FindAsync(req.PosNoId);
|
|
// if (save_posNo == null)
|
|
// return Error(GlobalMessages.PositionPosNoNotFound, 404);
|
|
// uppdated.PositionNumber = save_posNo;
|
|
|
|
// var save_orgPosition = await _context.OrganizationPositions.FirstOrDefaultAsync(x => x.PositionNumber == save_posNo);
|
|
// if (save_orgPosition == null)
|
|
// return Error(GlobalMessages.PositionPosNoNotFound, 404);
|
|
// uppdated.OrganizationPosition = save_orgPosition;
|
|
// }
|
|
|
|
// if (req.PositionId != null)
|
|
// {
|
|
// var save = await _context.PositionPaths.FindAsync(req.PositionId);
|
|
// if (save == null)
|
|
// return Error(GlobalMessages.PositionPathNotFound, 404);
|
|
// uppdated.PositionPath = save;
|
|
// }
|
|
|
|
// if (req.PositionLevelId != null)
|
|
// {
|
|
// var save = await _context.PositionLevels.FindAsync(req.PositionLevelId);
|
|
// if (save == null)
|
|
// return Error(GlobalMessages.PositionLevelNotFound, 404);
|
|
// uppdated.PositionLevel = save;
|
|
// }
|
|
|
|
// if (req.PositionLineId != null)
|
|
// {
|
|
// var save = await _context.PositionLines.FindAsync(req.PositionLineId);
|
|
// if (save == null)
|
|
// return Error(GlobalMessages.PositionLineNotFound, 404);
|
|
// uppdated.PositionLine = save;
|
|
// }
|
|
|
|
// if (req.PositionPathSideId != null)
|
|
// {
|
|
// var save = await _context.PositionPathSides.FindAsync(req.PositionPathSideId);
|
|
// if (save == null)
|
|
// return Error(GlobalMessages.PositionPathSideNotFound, 404);
|
|
// uppdated.PositionPathSide = save;
|
|
// }
|
|
|
|
// if (req.PositionTypeId != null)
|
|
// {
|
|
// var save = await _context.PositionTypes.FindAsync(req.PositionTypeId);
|
|
// if (save == null)
|
|
// return Error(GlobalMessages.PositionTypeNotFound, 404);
|
|
// uppdated.PositionType = save;
|
|
// }
|
|
|
|
// 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] RetirementOtherEditRequest req, Guid id)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_PLACEMENT_OTHER");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var uppdated = await _context.RetirementOthers
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (uppdated == null)
|
|
return Error(GlobalMessages.RetirementOtherNotFound, 404);
|
|
|
|
uppdated.EducationOld = req.EducationOld;
|
|
uppdated.Reason = req.Reason;
|
|
uppdated.MilitaryDate = req.MilitaryDate;
|
|
uppdated.OrganizationPositionOld = req.OrganizationPositionOld;
|
|
uppdated.PositionTypeOld = req.PositionTypeOld;
|
|
uppdated.PositionLevelOld = req.PositionLevelOld;
|
|
uppdated.PositionNumberOld = req.PositionNumberOld;
|
|
uppdated.AmountOld = req.AmountOld;
|
|
uppdated.PositionDate = req.PositionDate;
|
|
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 getPermission = await _permission.GetPermissionAPIAsync("DELETE", "SYS_PLACEMENT_OTHER");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var deleted = await _context.RetirementOthers.AsQueryable()
|
|
.Include(x => x.RetirementOtherDocs)
|
|
.ThenInclude(x => x.Document)
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (deleted == null)
|
|
return NotFound();
|
|
var retirementOtherDocs = new List<dynamic>();
|
|
foreach (var doc in deleted.RetirementOtherDocs)
|
|
{
|
|
if (doc.Document != null)
|
|
retirementOtherDocs.Add(doc.Document.Id);
|
|
}
|
|
_context.RetirementOtherDocs.RemoveRange(deleted.RetirementOtherDocs);
|
|
await _context.SaveChangesAsync();
|
|
_context.RetirementOthers.Remove(deleted);
|
|
foreach (var doc in retirementOtherDocs)
|
|
{
|
|
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>
|
|
[HttpPut("report/{commandTypeId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> PostToReport([FromBody] RetirementProfileRequest req, Guid commandTypeId)
|
|
{
|
|
foreach (var item in req.Id)
|
|
{
|
|
var uppdated = await _context.RetirementOthers
|
|
.FirstOrDefaultAsync(x => x.Id == item);
|
|
if (uppdated == null)
|
|
continue;
|
|
|
|
uppdated.CommandType = await _context.CommandTypes.FindAsync(commandTypeId);
|
|
uppdated.Status = "REPORT";
|
|
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
|
uppdated.LastUpdateUserId = UserId ?? "";
|
|
uppdated.LastUpdatedAt = DateTime.Now;
|
|
}
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ส่งรายชื่อออกคำสั่ง C-PM-08
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("appoint/report")]
|
|
public async Task<ActionResult<ResponseObject>> PostReportAppoint([FromBody] ReportPersonRequest req)
|
|
{
|
|
var placementProfiles = await _context.RetirementOthers
|
|
.Where(x => req.refIds.Contains(x.Id.ToString()))
|
|
.ToListAsync();
|
|
placementProfiles.ForEach(profile => profile.Status = "REPORT");
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ลบรายชื่อออกคำสั่ง C-PM-08
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("appoint/report/delete")]
|
|
public async Task<ActionResult<ResponseObject>> PostReportDeleteAppoint([FromBody] ReportPersonRequest req)
|
|
{
|
|
var placementProfiles = await _context.RetirementOthers
|
|
.Where(x => req.refIds.Contains(x.Id.ToString()))
|
|
// .Where(x => x.Status.ToUpper() == "REPORT")
|
|
.ToListAsync();
|
|
placementProfiles.ForEach(profile => profile.Status = "WAITTING");
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// เอกสารแนบท้าย C-PM-08
|
|
/// </summary>
|
|
/// <param name="id">Record Id ของคำสั่ง</param>
|
|
/// <param name="exportType">pdf, docx หรือ xlsx</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("appoint/report/attachment")]
|
|
[AllowAnonymous]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> PostReportAppointAttachment([FromBody] ReportAttachmentRequest req)
|
|
{
|
|
try
|
|
{
|
|
var report_data = (from p in _context.RetirementOthers
|
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
|
.ToList()
|
|
join r in req.refIds
|
|
on p.Id.ToString() equals r.refId
|
|
orderby r.Sequence
|
|
select new
|
|
{
|
|
No = r.Sequence.ToString().ToThaiNumber(),
|
|
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
|
|
Education = p.EducationOld == null ? "-" : p.EducationOld,
|
|
OldOc = (p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld) + "/" + (p.rootOld == null ? "" : p.rootOld),
|
|
OldPositionType = p.PositionTypeOld == null ? "-" : p.PositionTypeOld,
|
|
OldPositionLevel = p.PositionLevelOld == null ? "-" : p.PositionLevelOld,
|
|
OldPositionNumber = p.PositionNumberOld == null ? "-" : p.PositionNumberOld.ToThaiNumber(),
|
|
OldSalary = p.AmountOld == null ? "-" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
|
|
LeaveDate = p.LeaveDate == null ? "-" : p.LeaveDate.Value.ToThaiShortDate2().ToThaiNumber(),
|
|
NewOc = (p.OrganizationPositionOld == null ? "" : p.OrganizationPositionOld) + "/" + (p.rootOld == null ? "" : p.rootOld),
|
|
NewPositionType = p.PositionTypeOld == null ? "-" : p.PositionTypeOld,
|
|
NewPositionLevel = p.PositionLevelOld == null ? "-" : p.PositionLevelOld,
|
|
NewPositionNumber = p.PositionNumberOld == null ? "-" : p.PositionNumberOld.ToThaiNumber(),
|
|
NewSalary = r.Amount == null ? "-" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
|
|
AppointDate = p.PositionDate == null ? "-" : p.PositionDate.Value.ToThaiShortDate2().ToThaiNumber(),
|
|
CommandExcecuteDate = string.IsNullOrEmpty(r.CommandExcecuteDate.ToString()) ? "-" : r.CommandExcecuteDate.Value.ToThaiShortDate2().ToThaiNumber(),
|
|
RemarkHorizontal = r.RemarkHorizontal,
|
|
RemarkVertical = r.RemarkVertical,
|
|
}).ToList();
|
|
|
|
var result = new List<dynamic>();
|
|
|
|
foreach (var r in report_data)
|
|
{
|
|
result.Add(r);
|
|
string? _null = null;
|
|
if (r.RemarkHorizontal != null && r.RemarkHorizontal != "")
|
|
{
|
|
result.Add(new
|
|
{
|
|
No = _null,
|
|
FullName = r.RemarkHorizontal,
|
|
Education = _null,
|
|
OldOc = _null,
|
|
OldPositionType = _null,
|
|
OldPositionLevel = _null,
|
|
OldPositionNumber = _null,
|
|
OldSalary = _null,
|
|
LeaveDate = _null,
|
|
NewOc = _null,
|
|
NewPositionType = _null,
|
|
NewPositionLevel = _null,
|
|
NewPositionNumber = _null,
|
|
NewSalary = _null,
|
|
AppointDate = _null,
|
|
CommandExcecuteDate = _null,
|
|
RemarkHorizontal = _null,
|
|
RemarkVertical = _null,
|
|
});
|
|
}
|
|
}
|
|
return Success(result);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ออกคำสั่ง C-PM-08 บรรจุและแต่งตั้งข้าราชการกลับเข้ารับราชการ
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("appoint/report/excecute")]
|
|
public async Task<ActionResult<ResponseObject>> PostReportExecuteAppoint([FromBody] ReportExecuteRequest req)
|
|
{
|
|
var data = await _context.RetirementOthers
|
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
|
.ToListAsync();
|
|
string? _null = null;
|
|
var resultData = (from p in data
|
|
join r in req.refIds
|
|
on p.Id.ToString() equals r.refId
|
|
select new
|
|
{
|
|
profileId = p.profileId,
|
|
date = r.commandAffectDate,
|
|
amount = r.amount,
|
|
amountSpecial = r.amountSpecial,
|
|
commandId = r.commandId,
|
|
positionSalaryAmount = r.positionSalaryAmount,
|
|
mouthSalaryAmount = r.mouthSalaryAmount,
|
|
posNo = p.PositionNumberOld,
|
|
position = p.PositionOld,
|
|
positionLine = "",
|
|
positionPathSide = "",
|
|
positionExecutive = "",
|
|
positionType = p.PositionTypeOld,
|
|
positionLevel = p.PositionLevelOld,
|
|
refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}",
|
|
templateDoc = r.templateDoc,
|
|
isLeave = false,
|
|
leaveReason = _null,
|
|
dateLeave = _null,
|
|
isGovernment = true,
|
|
refCommandCode = r.refCommandCode,
|
|
refCommandName = r.refCommandName,
|
|
}).ToList();
|
|
|
|
var baseAPIOrg = _configuration["API"];
|
|
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
|
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
|
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
|
{
|
|
data = resultData,
|
|
});
|
|
var _result = await _res.Content.ReadAsStringAsync();
|
|
if (_res.IsSuccessStatusCode)
|
|
{
|
|
data.ForEach(profile => profile.Status = "DONE");
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
}
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ส่งรายชื่อออกคำสั่ง C-PM-09
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("out/report")]
|
|
public async Task<ActionResult<ResponseObject>> PostReportOut([FromBody] ReportPersonRequest req)
|
|
{
|
|
var placementProfiles = await _context.RetirementOthers
|
|
.Where(x => req.refIds.Contains(x.Id.ToString()))
|
|
.ToListAsync();
|
|
placementProfiles.ForEach(profile => profile.Status = "REPORT");
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ลบรายชื่อออกคำสั่ง C-PM-09
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("out/report/delete")]
|
|
public async Task<ActionResult<ResponseObject>> PostReportDeleteOut([FromBody] ReportPersonRequest req)
|
|
{
|
|
var placementProfiles = await _context.RetirementOthers
|
|
.Where(x => req.refIds.Contains(x.Id.ToString()))
|
|
// .Where(x => x.Status.ToUpper() == "REPORT")
|
|
.ToListAsync();
|
|
placementProfiles.ForEach(profile => profile.Status = "WAITTING");
|
|
await _context.SaveChangesAsync();
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// เอกสารแนบท้าย C-PM-09
|
|
/// </summary>
|
|
/// <param name="id">Record Id ของคำสั่ง</param>
|
|
/// <param name="exportType">pdf, docx หรือ xlsx</param>
|
|
/// <returns></returns>
|
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("out/report/attachment")]
|
|
[AllowAnonymous]
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<ResponseObject>> PostReportOutAttachment([FromBody] ReportAttachmentRequest req)
|
|
{
|
|
try
|
|
{
|
|
var report_data = (from p in _context.RetirementOthers
|
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
|
.ToList()
|
|
join r in req.refIds
|
|
on p.Id.ToString() equals r.refId
|
|
orderby r.Sequence
|
|
select new
|
|
{
|
|
No = r.Sequence.ToString().ToThaiNumber(),
|
|
FullName = $"{r.Prefix}{r.FirstName} {r.LastName}",
|
|
Education = p.EducationOld == null ? "-" : p.EducationOld,
|
|
OldOc = p.rootOld == null ? p.PositionOld == null ? "-" : $"{p.PositionOld}/-" :
|
|
p.child4Old != null
|
|
? p.PositionOld == null ? $"{p.child4Old}/{p.child3Old}/{p.child2Old}/{p.child1Old}/{p.rootOld}" : $"{p.PositionOld}/{p.child4Old}/{p.child3Old}/{p.child2Old}/{p.child1Old}/{p.rootOld}" :
|
|
p.child3Old != null
|
|
? p.PositionOld == null ? $"{p.child3Old}/{p.child2Old}/{p.child1Old}/{p.rootOld}" : $"{p.PositionOld}/{p.child3Old}/{p.child2Old}/{p.child1Old}/{p.rootOld}" :
|
|
p.child2Old != null
|
|
? p.PositionOld == null ? $"{p.child2Old}/{p.child1Old}/{p.rootOld}" : $"{p.PositionOld}/{p.child2Old}/{p.child1Old}/{p.rootOld}" :
|
|
p.child1Old != null
|
|
? p.PositionOld == null ? $"{p.child1Old}/{p.rootOld}" : $"{p.PositionOld}/{p.child1Old}/{p.rootOld}" :
|
|
p.rootOld != null
|
|
? p.PositionOld == null ? $"{p.rootOld}" : $"{p.PositionOld}/{p.rootOld}" : "-",
|
|
OldPositionType = p.PositionTypeOld == null ? "-" : p.PositionTypeOld,
|
|
OldPositionLevel = p.PositionLevelOld == null ? "-" : p.PositionLevelOld,
|
|
OldPositionNumber = p.PositionNumberOld == null ? "-" : p.PositionNumberOld.ToThaiNumber(),
|
|
OldSalary = p.AmountOld == null ? "-" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
|
|
LeaveDate = p.LeaveDate == null ? "-" : p.LeaveDate.Value.ToThaiShortDate2().ToThaiNumber(),
|
|
MilitaryDate = p.MilitaryDate == null ? "-" : p.MilitaryDate.Value.ToThaiShortDate2().ToThaiNumber(),
|
|
NewOc = p.rootOld == null ? p.PositionOld == null ? "-" : $"{p.PositionOld}/-" :
|
|
p.child4Old != null
|
|
? p.PositionOld == null ? $"{p.child4Old}/{p.child3Old}/{p.child2Old}/{p.child1Old}/{p.rootOld}" : $"{p.PositionOld}/{p.child4Old}/{p.child3Old}/{p.child2Old}/{p.child1Old}/{p.rootOld}" :
|
|
p.child3Old != null
|
|
? p.PositionOld == null ? $"{p.child3Old}/{p.child2Old}/{p.child1Old}/{p.rootOld}" : $"{p.PositionOld}/{p.child3Old}/{p.child2Old}/{p.child1Old}/{p.rootOld}" :
|
|
p.child2Old != null
|
|
? p.PositionOld == null ? $"{p.child2Old}/{p.child1Old}/{p.rootOld}" : $"{p.PositionOld}/{p.child2Old}/{p.child1Old}/{p.rootOld}" :
|
|
p.child1Old != null
|
|
? p.PositionOld == null ? $"{p.child1Old}/{p.rootOld}" : $"{p.PositionOld}/{p.child1Old}/{p.rootOld}" :
|
|
p.rootOld != null
|
|
? p.PositionOld == null ? $"{p.rootOld}" : $"{p.PositionOld}/{p.rootOld}" : "-",
|
|
NewPositionType = p.PositionTypeOld == null ? "-" : p.PositionTypeOld,
|
|
NewPositionLevel = p.PositionLevelOld == null ? "-" : p.PositionLevelOld,
|
|
NewPositionNumber = p.PositionNumberOld == null ? "-" : p.PositionNumberOld.ToThaiNumber(),
|
|
NewSalary = r.Amount == null ? "-" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
|
|
AppointDate = p.PositionDate == null ? "-" : p.PositionDate.Value.ToThaiShortDate2().ToThaiNumber(),
|
|
CommandExcecuteDate = string.IsNullOrEmpty(r.CommandExcecuteDate.ToString()) ? "-" : r.CommandExcecuteDate.Value.ToThaiShortDate2().ToThaiNumber(),
|
|
RemarkHorizontal = r.RemarkHorizontal,
|
|
RemarkVertical = r.RemarkVertical,
|
|
}).ToList();
|
|
|
|
var result = new List<dynamic>();
|
|
|
|
foreach (var r in report_data)
|
|
{
|
|
result.Add(r);
|
|
string? _null = null;
|
|
if (r.RemarkHorizontal != null && r.RemarkHorizontal != "")
|
|
{
|
|
result.Add(new
|
|
{
|
|
No = _null,
|
|
FullName = r.RemarkHorizontal,
|
|
Education = _null,
|
|
OldOc = _null,
|
|
OldPositionType = _null,
|
|
OldPositionLevel = _null,
|
|
OldPositionNumber = _null,
|
|
OldSalary = _null,
|
|
LeaveDate = _null,
|
|
MilitaryDate = _null,
|
|
NewOc = _null,
|
|
NewPositionType = _null,
|
|
NewPositionLevel = _null,
|
|
NewPositionNumber = _null,
|
|
NewSalary = _null,
|
|
AppointDate = _null,
|
|
CommandExcecuteDate = _null,
|
|
RemarkHorizontal = _null,
|
|
RemarkVertical = _null,
|
|
});
|
|
}
|
|
}
|
|
return Success(result);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ออกคำสั่ง C-PM-09 คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("out/report/excecute")]
|
|
public async Task<ActionResult<ResponseObject>> PostReportExecuteOut([FromBody] ReportExecuteRequest req)
|
|
{
|
|
var data = await _context.RetirementOthers
|
|
.Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString()))
|
|
.ToListAsync();
|
|
string? _null = null;
|
|
var resultData = (from p in data
|
|
join r in req.refIds
|
|
on p.Id.ToString() equals r.refId
|
|
select new
|
|
{
|
|
profileId = p.profileId,
|
|
date = r.commandAffectDate,
|
|
amount = r.amount,
|
|
amountSpecial = r.amountSpecial,
|
|
commandId = r.commandId,
|
|
positionSalaryAmount = r.positionSalaryAmount,
|
|
mouthSalaryAmount = r.mouthSalaryAmount,
|
|
posNo = p.PositionNumberOld,
|
|
position = p.PositionOld,
|
|
positionLine = "",
|
|
positionPathSide = "",
|
|
positionExecutive = "",
|
|
positionType = p.PositionTypeOld,
|
|
positionLevel = p.PositionLevelOld,
|
|
refCommandNo = $"{r.commandNo}/{r.commandYear.ToThaiYear()}",
|
|
templateDoc = r.templateDoc,
|
|
isLeave = false,
|
|
leaveReason = _null,
|
|
dateLeave = _null,
|
|
isGovernment = true,
|
|
refCommandCode = r.refCommandCode,
|
|
refCommandName = r.refCommandName,
|
|
}).ToList();
|
|
|
|
var baseAPIOrg = _configuration["API"];
|
|
var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-leave";
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
|
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
|
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
|
|
{
|
|
data = resultData,
|
|
});
|
|
var _result = await _res.Content.ReadAsStringAsync();
|
|
if (_res.IsSuccessStatusCode)
|
|
{
|
|
data.ForEach(profile => profile.Status = "DONE");
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
}
|
|
return Success();
|
|
}
|
|
}
|
|
}
|