2192 lines
126 KiB
C#
2192 lines
126 KiB
C#
using BMA.EHR.Application.Repositories;
|
|
using BMA.EHR.Application.Repositories.MessageQueue;
|
|
using BMA.EHR.Application.Repositories.Reports;
|
|
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;
|
|
using System.Text;
|
|
|
|
namespace BMA.EHR.Retirement.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/retirement")]
|
|
[ApiVersion("1.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("ระบบพ้นราชการ")]
|
|
public class RetirementController : BaseController
|
|
{
|
|
private readonly RetirementRepository _repository;
|
|
private readonly NotificationRepository _repositoryNoti;
|
|
private readonly ApplicationDBContext _context;
|
|
private readonly MinIOService _documentService;
|
|
private readonly OrganizationCommonRepository _organizationCommonRepository;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly PermissionRepository _permission;
|
|
private readonly DisciplineDbContext _contextDiscipline;
|
|
private readonly RetireReportRepository _service;
|
|
public RetirementController(RetirementRepository repository,
|
|
NotificationRepository repositoryNoti,
|
|
ApplicationDBContext context,
|
|
MinIOService documentService,
|
|
IConfiguration configuration,
|
|
OrganizationCommonRepository organizationCommonRepository,
|
|
IHttpContextAccessor httpContextAccessor,
|
|
PermissionRepository permission,
|
|
DisciplineDbContext contextDiscipline,
|
|
RetireReportRepository service)
|
|
{
|
|
_repository = repository;
|
|
_repositoryNoti = repositoryNoti;
|
|
_context = context;
|
|
_documentService = documentService;
|
|
_organizationCommonRepository = organizationCommonRepository;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_configuration = configuration;
|
|
_permission = permission;
|
|
_contextDiscipline = contextDiscipline;
|
|
_service = service;
|
|
}
|
|
|
|
#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
|
|
|
|
#region " จัดลำดับเกษียณ "
|
|
private class ObjectOrderRetire
|
|
{
|
|
public int Order { get; set; }
|
|
public int? Order1 { get; set; }
|
|
public int? Order2 { get; set; }
|
|
public int? Order3 { get; set; }
|
|
public string LastUpdateFullName { get; set; }
|
|
public string LastUpdateUserId { get; set; }
|
|
public DateTime? LastUpdatedAt { get; set; }
|
|
public Guid? Id { get; set; }
|
|
}
|
|
private async Task GenOrderByYear(Guid id)
|
|
{
|
|
var Org = await _context.Organizations.FirstOrDefaultAsync(x => x.OrganizationOrder == null);
|
|
var ocIdList = await _context.Organizations.Select(x => x.Id).ToListAsync();
|
|
if (Org != null)
|
|
ocIdList = _documentService.GetAllIdByRoot(Org.Id);
|
|
var retire = await _context.RetirementPeriods
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (retire == null)
|
|
return;
|
|
var _retireProfile = await _context.RetirementProfiles
|
|
.Where(x => x.RetirementPeriod == retire)
|
|
.ToListAsync();
|
|
var profiles = new List<ObjectOrderRetire>();
|
|
if (retire.Type.Trim().ToUpper().Contains("OFFICER"))
|
|
{
|
|
profiles = await (from x in _context.RetirementProfiles
|
|
where x.RetirementPeriod == retire
|
|
select new ObjectOrderRetire
|
|
{
|
|
Id = x.Id,
|
|
Order = x.Order,
|
|
Order1 = x.Order,
|
|
// Order1 = x.Order == null ? 999999999 : x.Order,
|
|
Order2 = x.posTypeRank,
|
|
Order3 = x.posLevelRank,
|
|
LastUpdateFullName = x.LastUpdateFullName,
|
|
LastUpdateUserId = x.LastUpdateUserId,
|
|
LastUpdatedAt = x.LastUpdatedAt,
|
|
}).ToListAsync();
|
|
}
|
|
if (retire.Type.Trim().ToUpper().Contains("EMPLOYEE"))
|
|
{
|
|
profiles = await (from x in _context.RetirementProfiles
|
|
where x.RetirementPeriod == retire
|
|
// x.Profile.PositionEmployeeLevelId == null ? null : x.Profile.PositionEmployeeLevelId.Order
|
|
select new ObjectOrderRetire
|
|
{
|
|
Id = x.Id,
|
|
Order = x.Order,
|
|
Order1 = x.Order,
|
|
// Order1 = x.Order == null ? 999999999 : x.Order,
|
|
LastUpdateFullName = x.LastUpdateFullName,
|
|
LastUpdateUserId = x.LastUpdateUserId,
|
|
LastUpdatedAt = x.LastUpdatedAt,
|
|
}).ToListAsync();
|
|
}
|
|
var _profiles = profiles.AsQueryable().OrderBy(x => x.Order1).ThenBy(x => x.Order2).ThenBy(x => x.Order3).ToList();
|
|
var order = 1;
|
|
foreach (var profile in _profiles)
|
|
{
|
|
var retireProfile = _retireProfile.Find(x => x.Id == profile.Id);
|
|
retireProfile.Order = order;
|
|
retireProfile.LastUpdateFullName = FullName ?? "System Administrator";
|
|
retireProfile.LastUpdateUserId = UserId ?? "";
|
|
retireProfile.LastUpdatedAt = DateTime.Now;
|
|
order++;
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
private int SortOrg(Guid? ocId)
|
|
{
|
|
if (ocId == null)
|
|
return 999999999;
|
|
var Org = _context.Organizations.Include(x => x.OrganizationOrganization).FirstOrDefault(x => x.OrganizationOrder == null);
|
|
if (Org != null && Org.OrganizationOrganization != null && Org.OrganizationOrganization.Name.Contains("ปลัด"))
|
|
return -1;
|
|
var ocIdList = _context.Organizations.Select(x => x.Id).ToList();
|
|
if (Org != null)
|
|
ocIdList = _documentService.GetAllIdByRoot(Org.Id);
|
|
int index = ocIdList.IndexOf((Guid)ocId);
|
|
if (index == -1)
|
|
return 999999999;
|
|
return index;
|
|
}
|
|
|
|
private async Task<string> GetAgency(Guid profileId)
|
|
{
|
|
var organizationAgency = "-";
|
|
var _profile = await _context.Profiles
|
|
.Where(x => x.Id == profileId)
|
|
.FirstOrDefaultAsync();
|
|
if (_profile != null)
|
|
{
|
|
if (_profile.ProfileType == "officer")
|
|
{
|
|
var organization = await _context.Organizations
|
|
.Where(x => x.Id == _profile.OcId)
|
|
.FirstOrDefaultAsync();
|
|
if (organization != null)
|
|
{
|
|
var _organizationAgency = await _context.Organizations
|
|
.Include(x => x.OrganizationOrganization)
|
|
.Where(x => x.Id == organization.OrganizationAgencyId)
|
|
.FirstOrDefaultAsync();
|
|
if (_organizationAgency != null && _organizationAgency.OrganizationOrganization != null)
|
|
{
|
|
organizationAgency = _organizationAgency.OrganizationOrganization.Name;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var profilePosition = await _context.OrganizationEmployees
|
|
.Include(x => x.OrganizationAgency)
|
|
.ThenInclude(x => x.OrganizationOrganization)
|
|
.Where(x => x.Organization != null)
|
|
.Where(x => x.OrganizationAgency != null)
|
|
.Where(x => x.OrganizationAgency.OrganizationOrganization != null)
|
|
.Where(x => x.OrganizationAgency.OrganizationOrganization.Name != null)
|
|
.Where(x => x.Organization.Id == _profile.OcId)
|
|
.FirstOrDefaultAsync();
|
|
if (profilePosition != null)
|
|
{
|
|
organizationAgency = profilePosition.OrganizationAgency.OrganizationOrganization.Name;
|
|
}
|
|
}
|
|
}
|
|
return organizationAgency;
|
|
}
|
|
|
|
private async Task<string> GetGovermentAgency(Guid profileId)
|
|
{
|
|
var organizationGovernmentAgency = "-";
|
|
var _profile = await _context.Profiles
|
|
.Where(x => x.Id == profileId)
|
|
.FirstOrDefaultAsync();
|
|
if (_profile != null)
|
|
{
|
|
if (_profile.ProfileType == "officer")
|
|
{
|
|
var organization = await _context.Organizations
|
|
.Where(x => x.Id == _profile.OcId)
|
|
.FirstOrDefaultAsync();
|
|
if (organization != null)
|
|
{
|
|
var _organizationGovernmentAgency = await _context.Organizations
|
|
.Include(x => x.OrganizationOrganization)
|
|
.Where(x => x.Id == organization.OrganizationGovernmentAgencyId)
|
|
.FirstOrDefaultAsync();
|
|
if (_organizationGovernmentAgency != null && _organizationGovernmentAgency.OrganizationOrganization != null)
|
|
{
|
|
organizationGovernmentAgency = _organizationGovernmentAgency.OrganizationOrganization.Name;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var profilePosition = await _context.OrganizationEmployees
|
|
.Include(x => x.OrganizationGovernmentAgency)
|
|
.ThenInclude(x => x.OrganizationOrganization)
|
|
.Where(x => x.Organization != null)
|
|
.Where(x => x.OrganizationGovernmentAgency != null)
|
|
.Where(x => x.OrganizationGovernmentAgency.OrganizationOrganization != null)
|
|
.Where(x => x.OrganizationGovernmentAgency.OrganizationOrganization.Name != null)
|
|
.Where(x => x.Organization.Id == _profile.OcId)
|
|
.FirstOrDefaultAsync();
|
|
if (profilePosition != null)
|
|
{
|
|
organizationGovernmentAgency = profilePosition.OrganizationGovernmentAgency.OrganizationOrganization.Name;
|
|
}
|
|
}
|
|
}
|
|
return organizationGovernmentAgency;
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// list ประกาศเกษียณอายุราชการ
|
|
/// </summary>
|
|
/// <param name="type">ประเภทUser(officer,employee)(ตัวใหญ่หรือเล็กก็ได้)</param>
|
|
/// <param name="year">ปีงบประมาณ(ค.ศ.)</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("{type}/{year}")]
|
|
public async Task<ActionResult<ResponseObject>> GetRetirement(string type, int year)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_RETIREMENT");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
if (type.Trim().ToUpper().Contains("OFFICER") || type.Trim().ToUpper().Contains("EMPLOYEE"))
|
|
{
|
|
var retire_old = await _context.RetirementPeriodHistorys
|
|
.Where(x => x.Year == year)
|
|
.Where(x => x.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
|
|
.OrderByDescending(x => x.Round)
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,
|
|
CreatedAt = x.CreatedAt,
|
|
Year = x.Year,
|
|
Round = x.Round,
|
|
Total = x.Total,
|
|
TypeReport = x.TypeReport,
|
|
SignDate = x.SignDate,
|
|
Detail = x.Detail,
|
|
Json = true,
|
|
Document = x.Document == null ? false : true,
|
|
})
|
|
.ToListAsync();
|
|
|
|
var retire = await _context.RetirementPeriods
|
|
.Include(x => x.RetirementProfiles)
|
|
.Include(x => x.Document)
|
|
.Where(x => x.Year == year)
|
|
.Where(x => x.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
|
|
.FirstOrDefaultAsync();
|
|
if (retire != null)
|
|
{
|
|
retire_old.Add(new
|
|
{
|
|
Id = retire.Id,
|
|
CreatedAt = retire.CreatedAt,
|
|
Year = retire.Year,
|
|
Round = retire.Round,
|
|
Total = retire.RetirementProfiles.Count(),
|
|
TypeReport = retire.TypeReport,
|
|
SignDate = retire.SignDate,
|
|
Detail = retire.Detail,
|
|
Json = false,
|
|
Document = retire.Document == null ? false : true,
|
|
});
|
|
}
|
|
|
|
return Success(retire_old);
|
|
}
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// สร้างประกาศเกษียณใหม่
|
|
/// </summary>
|
|
/// <param name="RetireHistoryId">Id ประวัติรอบพ้นราชการ</param>
|
|
/// <param name="Option">ประเภทประกาศ</param>
|
|
/// <param name="Type">ประเภทUser(officer,employee)(ตัวใหญ่หรือเล็กก็ได้)</param>
|
|
/// <param name="Year">ปีงบประมาณ(ค.ศ.)</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("profile")]
|
|
public async Task<ActionResult<ResponseObject>> CreateProfileRetirement([FromBody] PeriodRequest req)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_RETIREMENT");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
if (!req.Type.Trim().ToUpper().Contains("EMPLOYEE") && !req.Type.Trim().ToUpper().Contains("OFFICER"))
|
|
return Error("ประเภทพ้นราชการไม่ถูกต้อง");
|
|
if (req.Year == 0)
|
|
{
|
|
req.Year = DateTime.Now.Year;
|
|
if (req.Year > 2500)
|
|
req.Year = req.Year - 543;
|
|
}
|
|
|
|
var round = 1;
|
|
var retire = await _context.RetirementPeriods
|
|
.Include(x => x.Document)
|
|
.Include(x => x.RetirementPeriodHistorys)
|
|
.Include(x => x.RetirementProfiles)
|
|
.Where(x => x.Year == req.Year)
|
|
.Where(x => x.Type.Trim().ToUpper().Contains(req.Type.Trim().ToUpper()))
|
|
.FirstOrDefaultAsync();
|
|
if (retire == null)
|
|
{
|
|
retire = new RetirementPeriod
|
|
{
|
|
Round = round,
|
|
TypeReport = null,
|
|
Detail = "มาตรา ๑๖ และมาตรา ๒๑ แห่งพระราชบัญญัติบำเหน็จบำนาญข้าราชการส่วนท้องถิ่น พ.ศ.๒๕๗๗ มาตรา ๘ แห่งพระราชบัญญัติบำเหน็จบำนาญข้าราชการกรุงเทพมหานคร พ.ศ.๒๕๕๔ ประกอบกับมติ ก.ก. ครั้งที่๑๑/๒๕๕๕ เมื่อวันที่ ๑๕ พฤศจิกายน ๒๕๕๕และมติ อ.ก.ก. สามัญข้ารายการสามัญครั้งที่ ๑/๒๕๖๕ เมื่อวันที่ ๒๑ กุมภาพันธ์ ๒๕๖๕",
|
|
Type = req.Type.Trim().ToUpper(),
|
|
Year = req.Year,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.RetirementPeriods.AddAsync(retire);
|
|
var profiles = new List<OrgRequestArrayData>();
|
|
if (req.Type.Trim().ToUpper().Contains("OFFICER"))
|
|
{
|
|
var apiUrl = $"{_configuration["API"]}/org/profile/profileid/retire/{req.Year}";
|
|
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<OrgRequestArray>(_result);
|
|
|
|
if (org != null && org.result != null)
|
|
profiles = org.result;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var apiUrl = $"{_configuration["API"]}/org/profile-employee/profileid/retire/{req.Year}";
|
|
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<OrgRequestArray>(_result);
|
|
|
|
if (org != null && org.result != null)
|
|
profiles = org.result;
|
|
}
|
|
}
|
|
|
|
var order = 1;
|
|
foreach (var profile in profiles)
|
|
{
|
|
var data = new RetirementProfile
|
|
{
|
|
Order = order,
|
|
Remove = "PENDING",
|
|
RetirementPeriod = retire,
|
|
profileId = profile.profileId,
|
|
prefix = profile.prefix,
|
|
firstName = profile.firstName,
|
|
lastName = profile.lastName,
|
|
citizenId = profile.citizenId,
|
|
root = profile.root,
|
|
rootId = profile.rootId,
|
|
rootShortName = profile.rootShortName,
|
|
child1 = profile.child1,
|
|
child1Id = profile.child1Id,
|
|
child1ShortName = profile.child1ShortName,
|
|
child2 = profile.child2,
|
|
child2Id = profile.child2Id,
|
|
child2ShortName = profile.child2ShortName,
|
|
child3 = profile.child3,
|
|
child3Id = profile.child3Id,
|
|
child3ShortName = profile.child3ShortName,
|
|
child4 = profile.child4,
|
|
child4Id = profile.child4Id,
|
|
child4ShortName = profile.child4ShortName,
|
|
posMasterNo = profile.posMasterNo,
|
|
position = profile.position,
|
|
posTypeId = profile.posTypeId,
|
|
posTypeName = profile.posTypeName,
|
|
posTypeRank = profile.posTypeRank,
|
|
posLevelId = profile.posLevelId,
|
|
posLevelName = profile.posLevelName,
|
|
posLevelRank = profile.posLevelRank,
|
|
posExecutiveId = profile.posExecutiveId,
|
|
posExecutiveName = profile.posExecutiveName,
|
|
posNo = profile.posNo,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
var dataRaw = new RetirementRawProfile
|
|
{
|
|
Order = order,
|
|
Remove = "PENDING",
|
|
RetirementPeriod = retire,
|
|
profileId = profile.profileId,
|
|
prefix = profile.prefix,
|
|
firstName = profile.firstName,
|
|
lastName = profile.lastName,
|
|
citizenId = profile.citizenId,
|
|
root = profile.root,
|
|
rootId = profile.rootId,
|
|
rootShortName = profile.rootShortName,
|
|
child1 = profile.child1,
|
|
child1Id = profile.child1Id,
|
|
child1ShortName = profile.child1ShortName,
|
|
child2 = profile.child2,
|
|
child2Id = profile.child2Id,
|
|
child2ShortName = profile.child2ShortName,
|
|
child3 = profile.child3,
|
|
child3Id = profile.child3Id,
|
|
child3ShortName = profile.child3ShortName,
|
|
child4 = profile.child4,
|
|
child4Id = profile.child4Id,
|
|
child4ShortName = profile.child4ShortName,
|
|
posMasterNo = profile.posMasterNo,
|
|
position = profile.position,
|
|
posTypeId = profile.posTypeId,
|
|
posTypeName = profile.posTypeName,
|
|
posTypeRank = profile.posTypeRank,
|
|
posLevelId = profile.posLevelId,
|
|
posLevelName = profile.posLevelName,
|
|
posLevelRank = profile.posLevelRank,
|
|
posExecutiveId = profile.posExecutiveId,
|
|
posExecutiveName = profile.posExecutiveName,
|
|
posNo = profile.posNo,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.RetirementProfiles.AddAsync(data);
|
|
await _context.RetirementRawProfiles.AddAsync(dataRaw);
|
|
order++;
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
await GenOrderByYear(retire.Id);
|
|
}
|
|
else
|
|
{
|
|
if (retire.Document == null)
|
|
return Error(GlobalMessages.RetirementNotCreated);
|
|
if (req.Option == null)
|
|
req.Option = "EDIT";
|
|
var profile_old = await _context.RetirementProfiles
|
|
.Where(x => x.RetirementPeriod == retire)
|
|
.Select(x => new
|
|
{
|
|
order = x.Order,
|
|
id = x.Id,
|
|
reason = x.Reason,
|
|
remove = x.Remove,
|
|
profileId = x.profileId,
|
|
prefix = x.prefix,
|
|
firstName = x.firstName,
|
|
lastName = x.lastName,
|
|
citizenId = x.citizenId,
|
|
root = x.root,
|
|
rootId = x.rootId,
|
|
rootShortName = x.rootShortName,
|
|
child1 = x.child1,
|
|
child1Id = x.child1Id,
|
|
child1ShortName = x.child1ShortName,
|
|
child2 = x.child2,
|
|
child2Id = x.child2Id,
|
|
child2ShortName = x.child2ShortName,
|
|
child3 = x.child3,
|
|
child3Id = x.child3Id,
|
|
child3ShortName = x.child3ShortName,
|
|
child4 = x.child4,
|
|
child4Id = x.child4Id,
|
|
child4ShortName = x.child4ShortName,
|
|
posMasterNo = x.posMasterNo,
|
|
position = x.position,
|
|
posTypeId = x.posTypeId,
|
|
posTypeName = x.posTypeName,
|
|
posTypeRank = x.posTypeRank,
|
|
posLevelId = x.posLevelId,
|
|
posLevelName = x.posLevelName,
|
|
posLevelRank = x.posLevelRank,
|
|
posExecutiveId = x.posExecutiveId,
|
|
posExecutiveName = x.posExecutiveName,
|
|
posNo = x.posNo,
|
|
})
|
|
.ToListAsync();
|
|
var file_name = $"retire_tmp_{DateTime.Now.ToString("yyyyMMddTHHmmss")}";
|
|
var profile = Newtonsoft.Json.JsonConvert.SerializeObject(profile_old);
|
|
await _documentService.GenerateJsonFile(profile, "/retire", file_name);
|
|
var history = new RetirementPeriodHistory
|
|
{
|
|
RetirementPeriod = retire,
|
|
Round = retire.Round,
|
|
TypeReport = retire.TypeReport,
|
|
SignDate = retire.SignDate,
|
|
Detail = retire.Detail,
|
|
Year = retire.Year,
|
|
Type = retire.Type,
|
|
Document = retire.Document,
|
|
Total = retire.RetirementProfiles.Count(),
|
|
ProfileFile = file_name,
|
|
CreatedUserId = retire.CreatedUserId,
|
|
CreatedFullName = retire.CreatedFullName,
|
|
CreatedAt = retire.CreatedAt,
|
|
LastUpdateFullName = retire.LastUpdateFullName,
|
|
LastUpdateUserId = retire.LastUpdateUserId,
|
|
LastUpdatedAt = retire.LastUpdatedAt,
|
|
};
|
|
await _context.RetirementPeriodHistorys.AddAsync(history);
|
|
// await _context.SaveChangesAsync();
|
|
|
|
retire.Document = null;
|
|
retire.Round = retire.Round + 1;
|
|
retire.TypeReport = req.Option.Trim().ToUpper();
|
|
retire.SignDate = null;
|
|
retire.CreatedFullName = FullName ?? "System Administrator";
|
|
retire.CreatedUserId = UserId ?? "";
|
|
retire.CreatedAt = DateTime.Now;
|
|
retire.LastUpdateFullName = FullName ?? "System Administrator";
|
|
retire.LastUpdateUserId = UserId ?? "";
|
|
retire.LastUpdatedAt = DateTime.Now;
|
|
_context.RetirementProfiles.RemoveRange(retire.RetirementProfiles);
|
|
|
|
if (!req.Option.Trim().ToUpper().Contains("ADD"))
|
|
{
|
|
var profileHistorys = await _context.RetirementPeriodHistorys.AsQueryable()
|
|
.FirstOrDefaultAsync(x => x.Id == req.RetireHistoryId);
|
|
|
|
// var profileOlds = new List<dynamic>();
|
|
if (profileHistorys != null)
|
|
{
|
|
using (var client = new HttpClient())
|
|
{
|
|
// var url = $"https://s3cluster.frappet.com/bma-ehr-fpt/{profileHistorys.ProfileFile}.json";
|
|
var url = await _documentService.ImagesPathByName($"{profileHistorys.ProfileFile}.json");
|
|
var responseTask = client.GetAsync(url);
|
|
var results = responseTask.Result;
|
|
var profileOlds = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ProfileJsonRequest>>(results.Content.ReadAsStringAsync().Result);
|
|
if (profileOlds != null)
|
|
{
|
|
profileOlds = profileOlds.Where(x => !x.remove.Trim().ToUpper().Contains("REMOVE")).ToList();
|
|
foreach (var profileOld in profileOlds)
|
|
{
|
|
var data = new RetirementProfile
|
|
{
|
|
Order = profileOld.order,
|
|
Remove = "PENDING",
|
|
RetirementPeriod = retire,
|
|
profileId = profileOld.profileId,
|
|
prefix = profileOld.prefix,
|
|
firstName = profileOld.firstName,
|
|
lastName = profileOld.lastName,
|
|
citizenId = profileOld.citizenId,
|
|
root = profileOld.root,
|
|
rootId = profileOld.rootId,
|
|
rootShortName = profileOld.rootShortName,
|
|
child1 = profileOld.child1,
|
|
child1Id = profileOld.child1Id,
|
|
child1ShortName = profileOld.child1ShortName,
|
|
child2 = profileOld.child2,
|
|
child2Id = profileOld.child2Id,
|
|
child2ShortName = profileOld.child2ShortName,
|
|
child3 = profileOld.child3,
|
|
child3Id = profileOld.child3Id,
|
|
child3ShortName = profileOld.child3ShortName,
|
|
child4 = profileOld.child4,
|
|
child4Id = profileOld.child4Id,
|
|
child4ShortName = profileOld.child4ShortName,
|
|
posMasterNo = profileOld.posMasterNo,
|
|
position = profileOld.position,
|
|
posTypeId = profileOld.posTypeId,
|
|
posTypeName = profileOld.posTypeName,
|
|
posTypeRank = profileOld.posTypeRank,
|
|
posLevelId = profileOld.posLevelId,
|
|
posLevelName = profileOld.posLevelName,
|
|
posLevelRank = profileOld.posLevelRank,
|
|
posExecutiveId = profileOld.posExecutiveId,
|
|
posExecutiveName = profileOld.posExecutiveName,
|
|
posNo = profileOld.posNo,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
retire.RetirementProfiles.Add(data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var retireOld = await _context.RetirementPeriods
|
|
.FirstOrDefaultAsync(x => x.Id == req.RetireHistoryId);
|
|
if (retireOld == null)
|
|
return Error(GlobalMessages.RetirementNotFound, 404);
|
|
var profileOlds = await _context.RetirementProfiles.AsQueryable()
|
|
.Where(x => x.RetirementPeriod == retireOld)
|
|
.ToListAsync();
|
|
if (profileOlds != null)
|
|
{
|
|
profileOlds = profileOlds.Where(x => !x.Remove.Trim().ToUpper().Contains("REMOVE")).ToList();
|
|
foreach (var profileOld in profileOlds)
|
|
{
|
|
var data = new RetirementProfile
|
|
{
|
|
Order = profileOld.Order,
|
|
Remove = "PENDING",
|
|
RetirementPeriod = retire,
|
|
profileId = profileOld.profileId,
|
|
prefix = profileOld.prefix,
|
|
firstName = profileOld.firstName,
|
|
lastName = profileOld.lastName,
|
|
citizenId = profileOld.citizenId,
|
|
root = profileOld.root,
|
|
rootId = profileOld.rootId,
|
|
rootShortName = profileOld.rootShortName,
|
|
child1 = profileOld.child1,
|
|
child1Id = profileOld.child1Id,
|
|
child1ShortName = profileOld.child1ShortName,
|
|
child2 = profileOld.child2,
|
|
child2Id = profileOld.child2Id,
|
|
child2ShortName = profileOld.child2ShortName,
|
|
child3 = profileOld.child3,
|
|
child3Id = profileOld.child3Id,
|
|
child3ShortName = profileOld.child3ShortName,
|
|
child4 = profileOld.child4,
|
|
child4Id = profileOld.child4Id,
|
|
child4ShortName = profileOld.child4ShortName,
|
|
posMasterNo = profileOld.posMasterNo,
|
|
position = profileOld.position,
|
|
posTypeId = profileOld.posTypeId,
|
|
posTypeName = profileOld.posTypeName,
|
|
posTypeRank = profileOld.posTypeRank,
|
|
posLevelId = profileOld.posLevelId,
|
|
posLevelName = profileOld.posLevelName,
|
|
posLevelRank = profileOld.posLevelRank,
|
|
posExecutiveId = profileOld.posExecutiveId,
|
|
posExecutiveName = profileOld.posExecutiveName,
|
|
posNo = profileOld.posNo,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
retire.RetirementProfiles.Add(data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
// await _context.SaveChangesAsync();
|
|
var profile_new = await _context.RetirementProfiles
|
|
.Where(x => x.RetirementPeriod == retire)
|
|
.Select(x => new
|
|
{
|
|
order = x.Order,
|
|
id = x.Id,
|
|
reason = x.Reason,
|
|
remove = x.Remove,
|
|
profileId = x.profileId,
|
|
citizenId = x.citizenId,
|
|
prefix = x.prefix,
|
|
firstName = x.firstName,
|
|
lastName = x.lastName,
|
|
fullName = $"{x.prefix}{x.firstName} {x.lastName}",
|
|
root = x.root,
|
|
rootId = x.rootId,
|
|
child1 = x.child1,
|
|
child1Id = x.child1Id,
|
|
child2 = x.child2,
|
|
child2Id = x.child2Id,
|
|
child3 = x.child3,
|
|
child3Id = x.child3Id,
|
|
child4 = x.child4,
|
|
child4Id = x.child4Id,
|
|
position = x.position,
|
|
positionType = x.posTypeName,
|
|
positionLevel = x.posLevelName,
|
|
positionExecutive = x.posExecutiveName,
|
|
posNo = x.posNo,
|
|
})
|
|
.ToListAsync();
|
|
// var profile_news = new List<ProfileJsonRequest>();
|
|
// foreach (var r in profile_new)
|
|
// {
|
|
// var organizationAgency = await GetAgency(r.profileId);
|
|
// var organizationGovernmentAgency = await GetGovermentAgency(r.profileId);
|
|
|
|
// var data = new ProfileJsonRequest
|
|
// {
|
|
// order = r.order,
|
|
// id = r.id,
|
|
// reason = r.reason,
|
|
// remove = r.remove,
|
|
// profileId = r.profileId,
|
|
// citizenId = r.citizenId,
|
|
// prefix = r.prefix,
|
|
// fullName = r.fullName,
|
|
// organizationOrganization = r.organizationOrganization,
|
|
// oc = r.ocId == null ? null : _organizationCommonRepository.GetOrganizationNameFullPath(r.ocId.Value),
|
|
// position = r.position,
|
|
// positionType = r.positionType,
|
|
// positionExecutive = r.positionExecutive,
|
|
// posNo = r.posNo,
|
|
// positionEmployeePosition = r.positionEmployeePosition,
|
|
// positionEmployeeLevel = r.positionEmployeeLevel,
|
|
// positionEmployeeGroup = r.positionEmployeeGroup,
|
|
// posNoEmployee = r.posNoEmployee,
|
|
// organizationAgency = organizationAgency,//หน่วยงานต้นสังกัด
|
|
// organizationGovernmentAgency = organizationGovernmentAgency,//ส่วนราชการต้นสังกัด
|
|
// };
|
|
// profile_news.Add(data);
|
|
// }
|
|
return Success(new { retire.Id, retire.CreatedAt, retire.Year, retire.Round, retire.Type, retire.TypeReport, retire.SignDate, retire.Detail, profile = profile_new });
|
|
}
|
|
|
|
/// <summary>
|
|
/// View รายชื่อผู้เกษียณอายุราชการในประกาศ
|
|
/// </summary>
|
|
/// <param name="retireId">Id ประกาศ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("{retireId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> GetProfileRetirement(Guid retireId)
|
|
{
|
|
var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(retireId.ToString(), "SYS_RETIREMENT");
|
|
if (getWorkflow == false)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_RETIREMENT");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
}
|
|
var retire = await _context.RetirementPeriods
|
|
.Include(x => x.RetirementProfiles)
|
|
.Include(x => x.Document)
|
|
.FirstOrDefaultAsync(x => x.Id == retireId);
|
|
if (retire == null)
|
|
{
|
|
var profileHistorys = await _context.RetirementPeriodHistorys.AsQueryable()
|
|
.Include(x => x.Document)
|
|
.FirstOrDefaultAsync(x => x.Id == retireId);
|
|
if (profileHistorys == null)
|
|
return Error(GlobalMessages.RetirementHistoryNotFound, 404);
|
|
using (var client = new HttpClient())
|
|
{
|
|
// var Endpoint = _configuration["MinIO:Endpoint"];
|
|
// var BucketName = _configuration["MinIO:BucketName"];
|
|
var url = await _documentService.ImagesPathByName($"{profileHistorys.ProfileFile}.json");
|
|
// var url = $"{Endpoint}{BucketName}/{profileHistorys.ProfileFile}.json";
|
|
var responseTask = client.GetAsync(url);
|
|
var results = responseTask.Result;
|
|
var filehis = profileHistorys.Document == null ? null : await _documentService.ImagesPath(profileHistorys.Document.Id);
|
|
return Success(new { Json = true, profileHistorys.Id, profileHistorys.CreatedAt, profileHistorys.Year, profileHistorys.Round, profileHistorys.Type, profileHistorys.TypeReport, profileHistorys.SignDate, profileHistorys.Detail, profile = results.IsSuccessStatusCode ? Newtonsoft.Json.JsonConvert.DeserializeObject<List<ProfileJsonRequest>>(results.Content.ReadAsStringAsync().Result) : null, File = filehis });
|
|
}
|
|
}
|
|
var profile_new = await _context.RetirementProfiles
|
|
.Where(x => x.RetirementPeriod == retire)
|
|
.Select(x => new
|
|
{
|
|
order = x.Order,
|
|
id = x.Id,
|
|
reason = x.Reason,
|
|
remove = x.Remove,
|
|
profileId = x.profileId,
|
|
citizenId = x.citizenId,
|
|
prefix = x.prefix,
|
|
firstName = x.firstName,
|
|
lastName = x.lastName,
|
|
fullName = $"{x.prefix}{x.firstName} {x.lastName}",
|
|
root = x.root,
|
|
rootId = x.rootId,
|
|
child1 = x.child1,
|
|
child1Id = x.child1Id,
|
|
child2 = x.child2,
|
|
child2Id = x.child2Id,
|
|
child3 = x.child3,
|
|
child3Id = x.child3Id,
|
|
child4 = x.child4,
|
|
child4Id = x.child4Id,
|
|
position = x.position,
|
|
posTypeName = x.posTypeName,
|
|
posLevelName = x.posLevelName,
|
|
posExecutiveName = x.posExecutiveName,
|
|
posNo = x.posNo,
|
|
// positionEmployeePosition = x.Profile.PositionEmployeePosition == null ? null : x.Profile.PositionEmployeePosition.Name,
|
|
// positionEmployeeLevel = x.Profile.PositionEmployeeLevel == null ? null : x.Profile.PositionEmployeeLevel.Name,
|
|
// positionEmployeeGroup = x.Profile.PositionEmployeeGroup == null ? null : x.Profile.PositionEmployeeGroup.Name,
|
|
// posNoEmployee = x.Profile.PosNoEmployee,
|
|
})
|
|
.ToListAsync();
|
|
// var profile_news = new List<ProfileJsonRequest>();
|
|
// foreach (var r in profile_new)
|
|
// {
|
|
// var organizationAgency = await GetAgency(r.profileId);
|
|
// var organizationGovernmentAgency = await GetGovermentAgency(r.profileId);
|
|
|
|
// var data = new ProfileJsonRequest
|
|
// {
|
|
// order = r.order,
|
|
// id = r.id,
|
|
// reason = r.reason,
|
|
// remove = r.remove,
|
|
// profileId = r.profileId,
|
|
// citizenId = r.citizenId,
|
|
// prefix = r.prefix,
|
|
// fullName = r.fullName,
|
|
// organizationOrganization = r.organizationOrganization,
|
|
// oc = r.ocId == null ? null : _organizationCommonRepository.GetOrganizationNameFullPath(r.ocId.Value),
|
|
// position = r.position,
|
|
// positionType = r.positionType,
|
|
// positionExecutive = r.positionExecutive,
|
|
// posNo = r.posNo,
|
|
// positionEmployeePosition = r.positionEmployeePosition,
|
|
// positionEmployeeLevel = r.positionEmployeeLevel,
|
|
// positionEmployeeGroup = r.positionEmployeeGroup,
|
|
// posNoEmployee = r.posNoEmployee,
|
|
// organizationAgency = organizationAgency,//หน่วยงานต้นสังกัด
|
|
// organizationGovernmentAgency = organizationGovernmentAgency,//ส่วนราชการต้นสังกัด
|
|
// };
|
|
// profile_news.Add(data);
|
|
// }
|
|
|
|
var file = retire.Document == null ? null : await _documentService.ImagesPath(retire.Document.Id);
|
|
return Success(new { Json = false, retire.Id, retire.CreatedAt, retire.Year, retire.Round, retire.Type, retire.TypeReport, retire.SignDate, retire.Detail, profile = profile_new, File = file });
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delete รายชื่อผู้เกษียณอายุราชการในประกาศ
|
|
/// </summary>
|
|
/// <param name="retireProfileId">Id ผู้ใช้งานในประกาศ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
// [HttpDelete("profile/{retireProfileId:length(36)}")]
|
|
// public async Task<ActionResult<ResponseObject>> DeleteProfileRetirement(Guid retireProfileId)
|
|
// {
|
|
// var profile = await _context.RetirementProfiles
|
|
// .FirstOrDefaultAsync(x => x.Id == retireProfileId);
|
|
// if (profile == null)
|
|
// return Error(GlobalMessages.DataNotFound, 404);
|
|
|
|
// _context.RetirementProfiles.Remove(profile);
|
|
// _context.SaveChanges();
|
|
|
|
// return Success();
|
|
// }
|
|
|
|
/// <summary>
|
|
/// Add รายชื่อผู้เกษียณอายุราชการในประกาศ
|
|
/// </summary>
|
|
/// <param name="retireId">Id ประกาศ</param>
|
|
/// <param name="profileId">Id ผู้ใช้งาน</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("profile/{retireId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> AddProfileRetirement([FromBody] ProfileRequest req, Guid retireId)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_RETIREMENT");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
|
|
// var profile = await _context.Profiles
|
|
// .FirstOrDefaultAsync(x => x.Id == req.ProfileId);
|
|
// if (profile == null)
|
|
// return Error(GlobalMessages.DataNotFound, 404);
|
|
|
|
var retire = await _context.RetirementPeriods
|
|
.Include(x => x.RetirementPeriodHistorys)
|
|
.Include(x => x.RetirementProfiles)
|
|
// .ThenInclude(x => x.Profile)
|
|
.FirstOrDefaultAsync(x => x.Id == retireId);
|
|
if (retire == null)
|
|
return Error(GlobalMessages.RetirementNotFound, 404);
|
|
if (retire.RetirementProfiles.Where(x => x.profileId == req.ProfileId).Count() > 0)
|
|
return Error("บุคคลนี้ได้ทำการเลือกไว้อยู่แล้ว");
|
|
foreach (var retire_profile in retire.RetirementProfiles)
|
|
{
|
|
retire_profile.Order++;
|
|
retire_profile.LastUpdateFullName = FullName ?? "System Administrator";
|
|
retire_profile.LastUpdateUserId = UserId ?? "";
|
|
retire_profile.LastUpdatedAt = DateTime.Now;
|
|
}
|
|
var num = 1;
|
|
|
|
var profileRawCount = await _context.RetirementRawProfiles
|
|
.CountAsync(x => x.RetirementPeriod.Id == retireId);
|
|
|
|
// var old_retire = retire.RetirementProfiles.OrderByDescending(x => x.Order).FirstOrDefault();
|
|
// if (old_retire != null)
|
|
// num = old_retire.Order + 1;
|
|
|
|
if (retire.Type == "OFFICER")
|
|
{
|
|
var apiUrl = $"{_configuration["API"]}/org/profile/profileid/position/{req.ProfileId}";
|
|
using (var client = new HttpClient())
|
|
{
|
|
var data = new RetirementProfile
|
|
{
|
|
Order = num,
|
|
Remove = "ADD",
|
|
RetirementPeriod = retire,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
var dataRaw = new RetirementRawProfile
|
|
{
|
|
Order = profileRawCount + 1,
|
|
Remove = "ADD",
|
|
RetirementPeriod = retire,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
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);
|
|
|
|
data.profileId = org.result.profileId;
|
|
data.prefix = org.result.prefix;
|
|
data.firstName = org.result.firstName;
|
|
data.lastName = org.result.lastName;
|
|
data.citizenId = org.result.citizenId;
|
|
data.root = org.result.root;
|
|
data.rootId = org.result.rootId;
|
|
data.rootShortName = org.result.rootShortName;
|
|
data.child1 = org.result.child1;
|
|
data.child1Id = org.result.child1Id;
|
|
data.child1ShortName = org.result.child1ShortName;
|
|
data.child2 = org.result.child2;
|
|
data.child2Id = org.result.child2Id;
|
|
data.child2ShortName = org.result.child2ShortName;
|
|
data.child3 = org.result.child3;
|
|
data.child3Id = org.result.child3Id;
|
|
data.child3ShortName = org.result.child3ShortName;
|
|
data.child4 = org.result.child4;
|
|
data.child4Id = org.result.child4Id;
|
|
data.child4ShortName = org.result.child4ShortName;
|
|
data.posMasterNo = org.result.posMasterNo;
|
|
data.position = org.result.position;
|
|
data.posTypeId = org.result.posTypeId;
|
|
data.posTypeName = org.result.posTypeName;
|
|
data.posTypeRank = org.result.posTypeRank;
|
|
data.posLevelId = org.result.posLevelId;
|
|
data.posLevelName = org.result.posLevelName;
|
|
data.posLevelRank = org.result.posLevelRank;
|
|
data.posExecutiveId = org.result.posExecutiveId;
|
|
data.posExecutiveName = org.result.posExecutiveName;
|
|
data.posNo = org.result.posNo;
|
|
|
|
dataRaw.profileId = org.result.profileId;
|
|
dataRaw.prefix = org.result.prefix;
|
|
dataRaw.firstName = org.result.firstName;
|
|
dataRaw.lastName = org.result.lastName;
|
|
dataRaw.citizenId = org.result.citizenId;
|
|
dataRaw.root = org.result.root;
|
|
dataRaw.rootId = org.result.rootId;
|
|
dataRaw.rootShortName = org.result.rootShortName;
|
|
dataRaw.child1 = org.result.child1;
|
|
dataRaw.child1Id = org.result.child1Id;
|
|
dataRaw.child1ShortName = org.result.child1ShortName;
|
|
dataRaw.child2 = org.result.child2;
|
|
dataRaw.child2Id = org.result.child2Id;
|
|
dataRaw.child2ShortName = org.result.child2ShortName;
|
|
dataRaw.child3 = org.result.child3;
|
|
dataRaw.child3Id = org.result.child3Id;
|
|
dataRaw.child3ShortName = org.result.child3ShortName;
|
|
dataRaw.child4 = org.result.child4;
|
|
dataRaw.child4Id = org.result.child4Id;
|
|
dataRaw.child4ShortName = org.result.child4ShortName;
|
|
dataRaw.posMasterNo = org.result.posMasterNo;
|
|
dataRaw.position = org.result.position;
|
|
dataRaw.posTypeId = org.result.posTypeId;
|
|
dataRaw.posTypeName = org.result.posTypeName;
|
|
dataRaw.posTypeRank = org.result.posTypeRank;
|
|
dataRaw.posLevelId = org.result.posLevelId;
|
|
dataRaw.posLevelName = org.result.posLevelName;
|
|
dataRaw.posLevelRank = org.result.posLevelRank;
|
|
dataRaw.posExecutiveId = org.result.posExecutiveId;
|
|
dataRaw.posExecutiveName = org.result.posExecutiveName;
|
|
dataRaw.posNo = org.result.posNo;
|
|
|
|
_context.RetirementProfiles.Add(data);
|
|
_context.RetirementRawProfiles.Add(dataRaw);
|
|
await _context.SaveChangesAsync();
|
|
if (retire.RetirementPeriodHistorys.Count() == 0)
|
|
{
|
|
await GenOrderByYear(retire.Id);
|
|
}
|
|
return Success();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var apiUrl = $"{_configuration["API"]}/org/profile-employee/profileid/position/{req.ProfileId}";
|
|
using (var client = new HttpClient())
|
|
{
|
|
var data = new RetirementProfile
|
|
{
|
|
Order = num,
|
|
Remove = "ADD",
|
|
RetirementPeriod = retire,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
var dataRaw = new RetirementRawProfile
|
|
{
|
|
Order = profileRawCount + 1,
|
|
Remove = "ADD",
|
|
RetirementPeriod = retire,
|
|
CreatedFullName = FullName ?? "System Administrator",
|
|
CreatedUserId = UserId ?? "",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
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);
|
|
|
|
data.profileId = org.result.profileId;
|
|
data.prefix = org.result.prefix;
|
|
data.firstName = org.result.firstName;
|
|
data.lastName = org.result.lastName;
|
|
data.citizenId = org.result.citizenId;
|
|
data.root = org.result.root;
|
|
data.rootId = org.result.rootId;
|
|
data.rootShortName = org.result.rootShortName;
|
|
data.child1 = org.result.child1;
|
|
data.child1Id = org.result.child1Id;
|
|
data.child1ShortName = org.result.child1ShortName;
|
|
data.child2 = org.result.child2;
|
|
data.child2Id = org.result.child2Id;
|
|
data.child2ShortName = org.result.child2ShortName;
|
|
data.child3 = org.result.child3;
|
|
data.child3Id = org.result.child3Id;
|
|
data.child3ShortName = org.result.child3ShortName;
|
|
data.child4 = org.result.child4;
|
|
data.child4Id = org.result.child4Id;
|
|
data.child4ShortName = org.result.child4ShortName;
|
|
data.posMasterNo = org.result.posMasterNo;
|
|
data.position = org.result.position;
|
|
data.posTypeId = org.result.posTypeId;
|
|
data.posTypeName = org.result.posTypeName;
|
|
data.posTypeRank = org.result.posTypeRank;
|
|
data.posLevelId = org.result.posLevelId;
|
|
data.posLevelName = org.result.posLevelName;
|
|
data.posLevelRank = org.result.posLevelRank;
|
|
//data.posExecutiveId = org.result.posExecutiveId;
|
|
//data.posExecutiveName = org.result.posExecutiveName;
|
|
data.posNo = org.result.posNo;
|
|
|
|
dataRaw.profileId = org.result.profileId;
|
|
dataRaw.prefix = org.result.prefix;
|
|
dataRaw.firstName = org.result.firstName;
|
|
dataRaw.lastName = org.result.lastName;
|
|
dataRaw.citizenId = org.result.citizenId;
|
|
dataRaw.root = org.result.root;
|
|
dataRaw.rootId = org.result.rootId;
|
|
dataRaw.rootShortName = org.result.rootShortName;
|
|
dataRaw.child1 = org.result.child1;
|
|
dataRaw.child1Id = org.result.child1Id;
|
|
dataRaw.child1ShortName = org.result.child1ShortName;
|
|
dataRaw.child2 = org.result.child2;
|
|
dataRaw.child2Id = org.result.child2Id;
|
|
dataRaw.child2ShortName = org.result.child2ShortName;
|
|
dataRaw.child3 = org.result.child3;
|
|
dataRaw.child3Id = org.result.child3Id;
|
|
dataRaw.child3ShortName = org.result.child3ShortName;
|
|
dataRaw.child4 = org.result.child4;
|
|
dataRaw.child4Id = org.result.child4Id;
|
|
dataRaw.child4ShortName = org.result.child4ShortName;
|
|
dataRaw.posMasterNo = org.result.posMasterNo;
|
|
dataRaw.position = org.result.position;
|
|
dataRaw.posTypeId = org.result.posTypeId;
|
|
dataRaw.posTypeName = org.result.posTypeName;
|
|
dataRaw.posTypeRank = org.result.posTypeRank;
|
|
dataRaw.posLevelId = org.result.posLevelId;
|
|
dataRaw.posLevelName = org.result.posLevelName;
|
|
dataRaw.posLevelRank = org.result.posLevelRank;
|
|
dataRaw.posNo = org.result.posNo;
|
|
|
|
_context.RetirementProfiles.Add(data);
|
|
_context.RetirementRawProfiles.Add(dataRaw);
|
|
await _context.SaveChangesAsync();
|
|
if (retire.RetirementPeriodHistorys.Count() == 0)
|
|
{
|
|
await GenOrderByYear(retire.Id);
|
|
}
|
|
return Success();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// แก้ไขข้อมูลบุคคล
|
|
/// </summary>
|
|
/// <param name="retireProfileId">Id ผู้ใช้งานในประกาศ</param>
|
|
/// <param name="reason">เหตุผล</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("edit")]
|
|
public async Task<ActionResult<ResponseObject>> EditReasonProfileRetirement([FromBody] ProfileRetireRequest req)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_RETIREMENT");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var profile = await _context.RetirementProfiles
|
|
.FirstOrDefaultAsync(x => x.Id == req.RetireProfileId);
|
|
if (profile == null)
|
|
return Error(GlobalMessages.DataNotFound, 404);
|
|
|
|
var profileRaw = await _context.RetirementRawProfiles
|
|
.FirstOrDefaultAsync(x => x.profileId == profile.profileId);
|
|
if (profileRaw == null)
|
|
return Error(GlobalMessages.DataNotFound, 404);
|
|
|
|
profile.Remove = "EDIT";
|
|
profile.Reason = req.Reason;
|
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
|
profile.LastUpdateUserId = UserId ?? "";
|
|
profile.LastUpdatedAt = DateTime.Now;
|
|
|
|
profileRaw.Remove = "EDIT";
|
|
profileRaw.Reason = req.Reason;
|
|
profileRaw.LastUpdateFullName = FullName ?? "System Administrator";
|
|
profileRaw.LastUpdateUserId = UserId ?? "";
|
|
profileRaw.LastUpdatedAt = DateTime.Now;
|
|
_context.SaveChanges();
|
|
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ลบข้อมูลบุคคล
|
|
/// </summary>
|
|
/// <param name="retireProfileId">Id ผู้ใช้งานในประกาศ</param>
|
|
/// <param name="reason">เหตุผล</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("remove")]
|
|
public async Task<ActionResult<ResponseObject>> RemoveReasonProfileRetirement([FromBody] ProfileRetireRequest req)
|
|
{
|
|
var profile = await _context.RetirementProfiles
|
|
.Include(x => x.RetirementPeriod)
|
|
.ThenInclude(x => x.RetirementPeriodHistorys)
|
|
.FirstOrDefaultAsync(x => x.Id == req.RetireProfileId);
|
|
if (profile == null)
|
|
return Error(GlobalMessages.DataNotFound, 404);
|
|
|
|
var profileRaw = await _context.RetirementRawProfiles
|
|
.FirstOrDefaultAsync(x => x.profileId == profile.profileId);
|
|
if (profileRaw == null)
|
|
return Error(GlobalMessages.DataNotFound, 404);
|
|
|
|
if (profile.RetirementPeriod.RetirementPeriodHistorys.Count() == 0)
|
|
{
|
|
_context.RetirementProfiles.Remove(profile);
|
|
_context.SaveChanges();
|
|
await GenOrderByYear(profile.RetirementPeriod.Id);
|
|
}
|
|
else
|
|
{
|
|
profile.Remove = "REMOVE";
|
|
profile.Reason = req.Reason;
|
|
profile.LastUpdateFullName = FullName ?? "System Administrator";
|
|
profile.LastUpdateUserId = UserId ?? "";
|
|
profile.LastUpdatedAt = DateTime.Now;
|
|
}
|
|
profileRaw.Remove = "REMOVE";
|
|
profileRaw.Reason = req.Reason;
|
|
profileRaw.LastUpdateFullName = FullName ?? "System Administrator";
|
|
profileRaw.LastUpdateUserId = UserId ?? "";
|
|
profileRaw.LastUpdatedAt = DateTime.Now;
|
|
_context.SaveChanges();
|
|
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// View เหตุผลแก้ไขข้อมูลบุคคล
|
|
/// </summary>
|
|
/// <param name="retireProfileId">Id ผู้ใช้งานในประกาศ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("reason/{retireProfileId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> ViewReasonProfileRetirement(Guid retireProfileId)
|
|
{
|
|
var profile = await _context.RetirementProfiles
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,
|
|
Reason = x.Reason,
|
|
})
|
|
.FirstOrDefaultAsync(x => x.Id == retireProfileId);
|
|
if (profile == null)
|
|
return Error(GlobalMessages.DataNotFound, 404);
|
|
|
|
return Success(profile);
|
|
}
|
|
|
|
/// <summary>
|
|
/// จัดอันดับเกษียณ
|
|
/// </summary>
|
|
/// <param name="retireId">Id ประกาศ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPost("{retireId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> UpdateProfileRetirement(Guid retireId)
|
|
{
|
|
var retire = await _context.RetirementPeriods
|
|
.FirstOrDefaultAsync(x => x.Id == retireId);
|
|
if (retire == null)
|
|
return Error(GlobalMessages.RetirementNotFound, 404);
|
|
|
|
await GenOrderByYear(retire.Id);
|
|
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// อัพเอกสารเกษียณอายุราชการ
|
|
/// </summary>
|
|
/// <param name="retireId">Id ประกาศ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("upload/{retireId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> UploadRetirement([FromForm] RetirementFileRequest req, Guid retireId)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_RETIREMENT");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var retire = await _context.RetirementPeriods
|
|
.FirstOrDefaultAsync(x => x.Id == retireId);
|
|
if (retire == null)
|
|
return Error(GlobalMessages.RetirementNotFound, 404);
|
|
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);
|
|
retire.SignDate = req.signDate;
|
|
retire.Document = _doc;
|
|
retire.LastUpdateFullName = FullName ?? "System Administrator";
|
|
retire.LastUpdateUserId = UserId ?? "";
|
|
retire.LastUpdatedAt = DateTime.Now;
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ตรวจสอบการอัพเอกสารเกษียญ false=ยังไม่อัพโหลด true=อัพโหลดเอกสารแล้ว
|
|
/// </summary>
|
|
/// <param name="retireId">Id ประกาศ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("upload/check/{retireId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> CheckUploadRetirement(Guid retireId)
|
|
{
|
|
var retire = await _context.RetirementPeriods
|
|
.Include(x => x.Document)
|
|
.FirstOrDefaultAsync(x => x.Id == retireId);
|
|
if (retire == null)
|
|
return Error(GlobalMessages.RetirementNotFound, 404);
|
|
if (retire.Document == null)
|
|
return Success(false);
|
|
return Success(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// แก้ไขข้อความมติ อ.ก.ก.
|
|
/// </summary>
|
|
/// <param name="retireId">Id ประกาศ</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpPut("detail/{retireId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> UpdateDetailRetirement([FromForm] RetirementDetailRequest req, Guid retireId)
|
|
{
|
|
var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_RETIREMENT");
|
|
var jsonData = JsonConvert.DeserializeObject<JObject>(getPermission);
|
|
if (jsonData["status"]?.ToString() != "200")
|
|
{
|
|
return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden);
|
|
}
|
|
var retire = await _context.RetirementPeriods
|
|
.FirstOrDefaultAsync(x => x.Id == retireId);
|
|
if (retire == null)
|
|
{
|
|
var retireHistory = await _context.RetirementPeriodHistorys
|
|
.FirstOrDefaultAsync(x => x.Id == retireId);
|
|
if (retireHistory == null)
|
|
return Error(GlobalMessages.RetirementNotFound, 404);
|
|
retireHistory.Detail = req.Detail;
|
|
}
|
|
else
|
|
{
|
|
retire.Detail = req.Detail;
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
return Success(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// report1
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("report1")]
|
|
public async Task<ActionResult<ResponseObject>> report1(string nodeId = "", int? node = null, DateTime? startDate = null, DateTime? endDate = null)
|
|
{
|
|
|
|
var apiUrl = $"{_configuration["API"]}/org/find/node-all";
|
|
var data = new object();
|
|
var data1 = new List<dynamic>();
|
|
var data2 = new List<dynamic>();
|
|
|
|
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,
|
|
nodeId
|
|
});
|
|
var _result = await _res.Content.ReadAsStringAsync();
|
|
var orgs = JsonConvert.DeserializeObject<NodeAllRequest>(_result);
|
|
|
|
if (orgs == null || orgs.result == null)
|
|
return Error("ไม่พบหน่วยงานนี้ในระบบ", 404);
|
|
|
|
int no = 1;
|
|
|
|
foreach (var org in orgs.result.isRootTrue)
|
|
{
|
|
//เกษียณ
|
|
var retire = _context.RetirementPeriods
|
|
.Include(x => x.RetirementProfiles.Where(x =>
|
|
(node == 0 ? x.rootDnaId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaId.Contains(org.child4DnaId) : true)))
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.Type.Trim().ToUpper() == "OFFICER")
|
|
.FirstOrDefault();
|
|
|
|
var rt_count = retire != null ? retire.RetirementProfiles.Count() : 0;
|
|
|
|
//ลาออก
|
|
var retirementResigns = _context.RetirementResigns
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.rootOldId == org.rootId &&
|
|
x.IsCancel == false && x.Status == "DONE")
|
|
.ToList();
|
|
|
|
var career_count = retirementResigns.Where(x => x.Reason == "CAREER").Count();
|
|
var move_count = retirementResigns.Where(x => x.Reason == "MOVE").Count();
|
|
var family_count = retirementResigns.Where(x => x.Reason == "FAMILY").Count();
|
|
var education_count = retirementResigns.Where(x => x.Reason == "EDUCATION").Count();
|
|
var other_count = retirementResigns.Where(x => x.Reason == "OTHER").Count();
|
|
|
|
//ขอโอน
|
|
var pt_count = _context.PlacementTransfers
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
(node == 0 ? x.rootDnaOldId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaOldId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaOldId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaOldId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaOldId.Contains(org.child4DnaId) : true) &&
|
|
x.Status.Trim().ToUpper() == "DONE")
|
|
.Count();
|
|
|
|
//ถึงแก่กรรม
|
|
var rd_count = _context.RetirementDeceaseds
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
|
(node == 0 ? x.rootDnaId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaId.Contains(org.child4DnaId) : true))
|
|
.Count();
|
|
|
|
//ให้ออก
|
|
var ro_count = _context.RetirementOuts
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.Status.Trim().ToUpper() == "DONE" &&
|
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
|
(node == 0 ? x.rootDnaOldId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaOldId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaOldId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaOldId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaOldId.Contains(org.child4DnaId) : true))
|
|
.Count();
|
|
|
|
//ปลดออก
|
|
var dl_cm19_count = _contextDiscipline.ProfileComplaintInvestigate
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
|
x.commandType.Trim().ToUpper() == "C-PM-19" &&
|
|
(node == 0 ? x.rootDnaId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaId.Contains(org.child4DnaId) : true))
|
|
.Count();
|
|
|
|
//ไล่ออก
|
|
var dl_cm20_count = _contextDiscipline.ProfileComplaintInvestigate
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
|
x.commandType.Trim().ToUpper() == "C-PM-20" &&
|
|
(node == 0 ? x.rootDnaId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaId.Contains(org.child4DnaId) : true))
|
|
.Count();
|
|
|
|
data1.Add(new
|
|
{
|
|
no = no,
|
|
rootName = org.name,
|
|
rt_count,
|
|
career_count,
|
|
move_count,
|
|
family_count,
|
|
education_count,
|
|
other_count,
|
|
pt_count,
|
|
rd_count,
|
|
ro_count,
|
|
dl_cm19_count,
|
|
dl_cm20_count,
|
|
total = (rt_count + career_count + move_count + family_count + education_count + other_count + pt_count + rd_count + ro_count + dl_cm19_count + dl_cm20_count)
|
|
});
|
|
no++;
|
|
}
|
|
|
|
no = 1;
|
|
foreach (var org in orgs.result.isRootFalse)
|
|
{
|
|
//เกษียณ
|
|
var retire = _context.RetirementPeriods
|
|
.Include(x => x.RetirementProfiles.Where(x =>
|
|
(node == 0 ? x.rootDnaId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaId.Contains(org.child4DnaId) : true)))
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.Type.Trim().ToUpper() == "OFFICER")
|
|
.FirstOrDefault();
|
|
|
|
var rt_count = retire != null ? retire.RetirementProfiles.Count() : 0;
|
|
|
|
//ลาออก
|
|
var retirementResigns = _context.RetirementResigns
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
(node == 0 ? x.rootDnaOldId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaOldId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaOldId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaOldId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaOldId.Contains(org.child4DnaId) : true) &&
|
|
x.IsCancel == false && x.Status == "DONE")
|
|
.ToList();
|
|
|
|
var career_count = retirementResigns.Where(x => x.Reason == "CAREER").Count();
|
|
var move_count = retirementResigns.Where(x => x.Reason == "MOVE").Count();
|
|
var family_count = retirementResigns.Where(x => x.Reason == "FAMILY").Count();
|
|
var education_count = retirementResigns.Where(x => x.Reason == "EDUCATION").Count();
|
|
var other_count = retirementResigns.Where(x => x.Reason == "OTHER").Count();
|
|
|
|
//ขอโอน
|
|
var pt_count = _context.PlacementTransfers
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
(node == 0 ? x.rootDnaOldId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaOldId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaOldId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaOldId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaOldId.Contains(org.child4DnaId) : true) &&
|
|
x.Status.Trim().ToUpper() == "DONE")
|
|
.Count();
|
|
|
|
//ถึงแก่กรรม
|
|
var rd_count = _context.RetirementDeceaseds
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
|
(node == 0 ? x.rootDnaId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaId.Contains(org.child4DnaId) : true))
|
|
.Count();
|
|
|
|
//ให้ออก
|
|
var ro_count = _context.RetirementOuts
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.Status.Trim().ToUpper() == "DONE" &&
|
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
|
(node == 0 ? x.rootDnaOldId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaOldId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaOldId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaOldId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaOldId.Contains(org.child4DnaId) : true))
|
|
.Count();
|
|
|
|
//ปลดออก
|
|
var dl_cm19_count = _contextDiscipline.ProfileComplaintInvestigate
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
|
x.commandType.Trim().ToUpper() == "C-PM-19" &&
|
|
(node == 0 ? x.rootDnaId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaId.Contains(org.child4DnaId) : true))
|
|
.Count();
|
|
|
|
//ไล่ออก
|
|
var dl_cm20_count = _contextDiscipline.ProfileComplaintInvestigate
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.profileType.Trim().ToUpper() == "OFFICER" &&
|
|
x.commandType.Trim().ToUpper() == "C-PM-20" &&
|
|
(node == 0 ? x.rootDnaId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaId.Contains(org.child4DnaId) : true))
|
|
.Count();
|
|
|
|
data2.Add(new
|
|
{
|
|
no = no,
|
|
rootName = org.name,
|
|
rt_count,
|
|
career_count,
|
|
move_count,
|
|
family_count,
|
|
education_count,
|
|
other_count,
|
|
pt_count,
|
|
rd_count,
|
|
ro_count,
|
|
dl_cm19_count,
|
|
dl_cm20_count,
|
|
total = (rt_count + career_count + move_count + family_count + education_count + other_count + pt_count + rd_count + ro_count + dl_cm19_count + dl_cm20_count)
|
|
});
|
|
no++;
|
|
}
|
|
}
|
|
|
|
data = new
|
|
{
|
|
template = "reportRetirement01All",
|
|
reportName = "xlsx-report",
|
|
data = new
|
|
{
|
|
date = $"ตั้งแต่วันที่ {startDate.Value.Date.ToThaiShortDate().ToThaiNumber()} ถึง {endDate.Value.Date.ToThaiShortDate().ToThaiNumber()}",
|
|
dateCurrent = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}",
|
|
data1,
|
|
data1Count = new
|
|
{
|
|
rt_count = data1.Where(x => x.rt_count > 0).Sum(x => x.rt_count),
|
|
career_count = data1.Where(x => x.career_count > 0).Sum(x => x.career_count),
|
|
move_count = data1.Where(x => x.move_count > 0).Sum(x => x.move_count),
|
|
family_count = data1.Where(x => x.family_count > 0).Sum(x => x.family_count),
|
|
education_count = data1.Where(x => x.education_count > 0).Sum(x => x.education_count),
|
|
other_count = data1.Where(x => x.other_count > 0).Sum(x => x.other_count),
|
|
pt_count = data1.Where(x => x.pt_count > 0).Sum(x => x.pt_count),
|
|
rd_count = data1.Where(x => x.rd_count > 0).Sum(x => x.rd_count),
|
|
ro_count = data1.Where(x => x.ro_count > 0).Sum(x => x.ro_count),
|
|
dl_cm19_count = data1.Where(x => x.dl_cm19_count > 0).Sum(x => x.dl_cm19_count),
|
|
dl_cm20_count = data1.Where(x => x.dl_cm20_count > 0).Sum(x => x.dl_cm20_count),
|
|
total = data1.Where(x => x.total > 0).Sum(x => x.total)
|
|
},
|
|
data2,
|
|
data2Count = new
|
|
{
|
|
rt_count = data2.Where(x => x.rt_count > 0).Sum(x => x.rt_count),
|
|
career_count = data2.Where(x => x.career_count > 0).Sum(x => x.career_count),
|
|
move_count = data2.Where(x => x.move_count > 0).Sum(x => x.move_count),
|
|
family_count = data2.Where(x => x.family_count > 0).Sum(x => x.family_count),
|
|
education_count = data2.Where(x => x.education_count > 0).Sum(x => x.education_count),
|
|
other_count = data2.Where(x => x.other_count > 0).Sum(x => x.other_count),
|
|
pt_count = data2.Where(x => x.pt_count > 0).Sum(x => x.pt_count),
|
|
rd_count = data2.Where(x => x.rd_count > 0).Sum(x => x.rd_count),
|
|
ro_count = data2.Where(x => x.ro_count > 0).Sum(x => x.ro_count),
|
|
dl_cm19_count = data2.Where(x => x.dl_cm19_count > 0).Sum(x => x.dl_cm19_count),
|
|
dl_cm20_count = data2.Where(x => x.dl_cm20_count > 0).Sum(x => x.dl_cm20_count),
|
|
total = data2.Where(x => x.total > 0).Sum(x => x.total)
|
|
},
|
|
sum = new
|
|
{
|
|
rt_count = data1.Where(x => x.rt_count > 0).Sum(x => x.rt_count) + data2.Where(x => x.rt_count > 0).Sum(x => x.rt_count),
|
|
career_count = data1.Where(x => x.career_count > 0).Sum(x => x.career_count) + data2.Where(x => x.career_count > 0).Sum(x => x.career_count),
|
|
move_count = data1.Where(x => x.move_count > 0).Sum(x => x.move_count) + data2.Where(x => x.move_count > 0).Sum(x => x.move_count),
|
|
family_count = data1.Where(x => x.family_count > 0).Sum(x => x.family_count) + data2.Where(x => x.family_count > 0).Sum(x => x.family_count),
|
|
education_count = data1.Where(x => x.education_count > 0).Sum(x => x.education_count) + data2.Where(x => x.education_count > 0).Sum(x => x.education_count),
|
|
other_count = data1.Where(x => x.other_count > 0).Sum(x => x.other_count) + data2.Where(x => x.other_count > 0).Sum(x => x.other_count),
|
|
pt_count = data1.Where(x => x.pt_count > 0).Sum(x => x.pt_count) + data2.Where(x => x.pt_count > 0).Sum(x => x.pt_count),
|
|
rd_count = data1.Where(x => x.rd_count > 0).Sum(x => x.rd_count) + data2.Where(x => x.rd_count > 0).Sum(x => x.rd_count),
|
|
ro_count = data1.Where(x => x.ro_count > 0).Sum(x => x.ro_count) + data2.Where(x => x.ro_count > 0).Sum(x => x.ro_count),
|
|
dl_cm19_count = data1.Where(x => x.dl_cm19_count > 0).Sum(x => x.dl_cm19_count) + data2.Where(x => x.dl_cm19_count > 0).Sum(x => x.dl_cm19_count),
|
|
dl_cm20_count = data1.Where(x => x.dl_cm20_count > 0).Sum(x => x.dl_cm20_count) + data2.Where(x => x.dl_cm20_count > 0).Sum(x => x.dl_cm20_count),
|
|
total = data1.Where(x => x.total > 0).Sum(x => x.total) + data2.Where(x => x.total > 0).Sum(x => x.total)
|
|
}
|
|
}
|
|
};
|
|
return Success(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// report2
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("report2")]
|
|
public async Task<ActionResult<ResponseObject>> report2(string nodeId = "", int? node = null, DateTime? startDate = null, DateTime? endDate = null)
|
|
{
|
|
|
|
var apiUrl = $"{_configuration["API"]}/org/find/node-all";
|
|
var data = new object();
|
|
var data1 = new List<dynamic>();
|
|
var data2 = new List<dynamic>();
|
|
|
|
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,
|
|
nodeId
|
|
});
|
|
var _result = await _res.Content.ReadAsStringAsync();
|
|
var orgs = JsonConvert.DeserializeObject<NodeAllRequest>(_result);
|
|
|
|
if (orgs == null || orgs.result == null)
|
|
return Error("ไม่พบหน่วยงานนี้ในระบบ", 404);
|
|
|
|
int no = 1;
|
|
|
|
foreach (var org in orgs.result.isRootTrue)
|
|
{
|
|
//เกษียณ
|
|
var retire = _context.RetirementPeriods
|
|
.Include(x => x.RetirementProfiles.Where(x =>
|
|
(node == 0 ? x.rootDnaId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaId.Contains(org.child4DnaId) : true)))
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.Type.Trim().ToUpper() == "EMPLOYEE")
|
|
.FirstOrDefault();
|
|
|
|
var rt_count = retire != null ? retire.RetirementProfiles.Count() : 0;
|
|
|
|
//ลาออก
|
|
var retirementResigns = _context.RetirementResignEmployees
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.rootOldId == org.rootId &&
|
|
x.IsCancel == false && x.Status == "DONE")
|
|
.ToList();
|
|
|
|
var career_count = retirementResigns.Where(x => x.Reason == "CAREER").Count();
|
|
var move_count = retirementResigns.Where(x => x.Reason == "MOVE").Count();
|
|
var family_count = retirementResigns.Where(x => x.Reason == "FAMILY").Count();
|
|
var education_count = retirementResigns.Where(x => x.Reason == "EDUCATION").Count();
|
|
var other_count = retirementResigns.Where(x => x.Reason == "OTHER").Count();
|
|
|
|
//ถึงแก่กรรม
|
|
var rd_count = _context.RetirementDeceaseds
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.profileType.Trim().ToUpper() == "EMPLOYEE" &&
|
|
(node == 0 ? x.rootDnaId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaId.Contains(org.child4DnaId) : true))
|
|
.Count();
|
|
|
|
//ให้ออก
|
|
var ro_count = _context.RetirementOuts
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.Status.Trim().ToUpper() == "DONE" &&
|
|
x.profileType.Trim().ToUpper() == "EMPLOYEE" &&
|
|
x.rootOldId.Contains(org.rootId))
|
|
.Count();
|
|
|
|
//ปลดออก
|
|
var dl_cm19_count = _contextDiscipline.ProfileComplaintInvestigate
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.profileType.Trim().ToUpper() == "EMPLOYEE" &&
|
|
x.commandType.Trim().ToUpper() == "C-PM-19" &&
|
|
(node == 0 ? x.rootDnaId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaId.Contains(org.child4DnaId) : true))
|
|
.Count();
|
|
|
|
//ไล่ออก
|
|
var dl_cm20_count = _contextDiscipline.ProfileComplaintInvestigate
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.profileType.Trim().ToUpper() == "EMPLOYEE" &&
|
|
x.commandType.Trim().ToUpper() == "C-PM-20" &&
|
|
(node == 0 ? x.rootDnaId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaId.Contains(org.child4DnaId) : true))
|
|
.Count();
|
|
|
|
data1.Add(new
|
|
{
|
|
no = no,
|
|
rootName = org.name,
|
|
rt_count,
|
|
career_count,
|
|
move_count,
|
|
family_count,
|
|
education_count,
|
|
other_count,
|
|
rd_count,
|
|
ro_count,
|
|
dl_cm19_count,
|
|
dl_cm20_count,
|
|
total = (rt_count + career_count + move_count + family_count + education_count + other_count + rd_count + ro_count + dl_cm19_count + dl_cm20_count)
|
|
});
|
|
no++;
|
|
}
|
|
|
|
no = 1;
|
|
foreach (var org in orgs.result.isRootFalse)
|
|
{
|
|
//เกษียณ
|
|
var retire = _context.RetirementPeriods
|
|
.Include(x => x.RetirementProfiles.Where(x =>
|
|
(node == 0 ? x.rootDnaId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaId.Contains(org.child4DnaId) : true)))
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.Type.Trim().ToUpper() == "EMPLOYEE")
|
|
.FirstOrDefault();
|
|
|
|
var rt_count = retire != null ? retire.RetirementProfiles.Count() : 0;
|
|
|
|
//ลาออก
|
|
var retirementResigns = _context.RetirementResignEmployees
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.rootOldId == org.rootId &&
|
|
x.IsCancel == false && x.Status == "DONE")
|
|
.ToList();
|
|
|
|
var career_count = retirementResigns.Where(x => x.Reason == "CAREER").Count();
|
|
var move_count = retirementResigns.Where(x => x.Reason == "MOVE").Count();
|
|
var family_count = retirementResigns.Where(x => x.Reason == "FAMILY").Count();
|
|
var education_count = retirementResigns.Where(x => x.Reason == "EDUCATION").Count();
|
|
var other_count = retirementResigns.Where(x => x.Reason == "OTHER").Count();
|
|
|
|
//ถึงแก่กรรม
|
|
var rd_count = _context.RetirementDeceaseds
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.profileType.Trim().ToUpper() == "EMPLOYEE" &&
|
|
(node == 0 ? x.rootDnaId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaId.Contains(org.child4DnaId) : true))
|
|
.Count();
|
|
|
|
//ให้ออก
|
|
var ro_count = _context.RetirementOuts
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.Status.Trim().ToUpper() == "DONE" &&
|
|
x.profileType.Trim().ToUpper() == "EMPLOYEE" &&
|
|
x.rootOldId.Contains(org.rootId))
|
|
.Count();
|
|
|
|
//ปลดออก
|
|
var dl_cm19_count = _contextDiscipline.ProfileComplaintInvestigate
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.profileType.Trim().ToUpper() == "EMPLOYEE" &&
|
|
x.commandType.Trim().ToUpper() == "C-PM-19" &&
|
|
(node == 0 ? x.rootDnaId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaId.Contains(org.child4DnaId) : true))
|
|
.Count();
|
|
|
|
//ไล่ออก
|
|
var dl_cm20_count = _contextDiscipline.ProfileComplaintInvestigate
|
|
.Where(x =>
|
|
x.CreatedAt.Date >= startDate &&
|
|
x.CreatedAt.Date <= endDate &&
|
|
x.profileType.Trim().ToUpper() == "EMPLOYEE" &&
|
|
x.commandType.Trim().ToUpper() == "C-PM-20" &&
|
|
(node == 0 ? x.rootDnaId.Contains(org.rootDnaId) : true) &&
|
|
(node == 1 ? x.child1DnaId.Contains(org.child1DnaId) : true) &&
|
|
(node == 2 ? x.child2DnaId.Contains(org.child2DnaId) : true) &&
|
|
(node == 3 ? x.child3DnaId.Contains(org.child3DnaId) : true) &&
|
|
(node == 4 ? x.child4DnaId.Contains(org.child4DnaId) : true))
|
|
.Count();
|
|
|
|
data2.Add(new
|
|
{
|
|
no = no,
|
|
rootName = org.name,
|
|
rt_count,
|
|
career_count,
|
|
move_count,
|
|
family_count,
|
|
education_count,
|
|
other_count,
|
|
rd_count,
|
|
ro_count,
|
|
dl_cm19_count,
|
|
dl_cm20_count,
|
|
total = (rt_count + career_count + move_count + family_count + education_count + other_count + rd_count + ro_count + dl_cm19_count + dl_cm20_count)
|
|
});
|
|
no++;
|
|
}
|
|
}
|
|
|
|
data = new
|
|
{
|
|
template = "reportRetirement02All",
|
|
reportName = "xlsx-report",
|
|
data = new
|
|
{
|
|
date = $"ตั้งแต่วันที่ {startDate.Value.Date.ToThaiShortDate().ToThaiNumber()} ถึง {endDate.Value.Date.ToThaiShortDate().ToThaiNumber()}",
|
|
dateCurrent = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}",
|
|
data1,
|
|
data1Count = new
|
|
{
|
|
rt_count = data1.Where(x => x.rt_count > 0).Sum(x => x.rt_count),
|
|
career_count = data1.Where(x => x.career_count > 0).Sum(x => x.career_count),
|
|
move_count = data1.Where(x => x.move_count > 0).Sum(x => x.move_count),
|
|
family_count = data1.Where(x => x.family_count > 0).Sum(x => x.family_count),
|
|
education_count = data1.Where(x => x.education_count > 0).Sum(x => x.education_count),
|
|
other_count = data1.Where(x => x.other_count > 0).Sum(x => x.other_count),
|
|
rd_count = data1.Where(x => x.rd_count > 0).Sum(x => x.rd_count),
|
|
ro_count = data1.Where(x => x.ro_count > 0).Sum(x => x.ro_count),
|
|
dl_cm19_count = data1.Where(x => x.dl_cm19_count > 0).Sum(x => x.dl_cm19_count),
|
|
dl_cm20_count = data1.Where(x => x.dl_cm20_count > 0).Sum(x => x.dl_cm20_count),
|
|
total = data1.Where(x => x.total > 0).Sum(x => x.total)
|
|
},
|
|
data2,
|
|
data2Count = new
|
|
{
|
|
rt_count = data2.Where(x => x.rt_count > 0).Sum(x => x.rt_count),
|
|
career_count = data2.Where(x => x.career_count > 0).Sum(x => x.career_count),
|
|
move_count = data2.Where(x => x.move_count > 0).Sum(x => x.move_count),
|
|
family_count = data2.Where(x => x.family_count > 0).Sum(x => x.family_count),
|
|
education_count = data2.Where(x => x.education_count > 0).Sum(x => x.education_count),
|
|
other_count = data2.Where(x => x.other_count > 0).Sum(x => x.other_count),
|
|
rd_count = data2.Where(x => x.rd_count > 0).Sum(x => x.rd_count),
|
|
ro_count = data2.Where(x => x.ro_count > 0).Sum(x => x.ro_count),
|
|
dl_cm19_count = data2.Where(x => x.dl_cm19_count > 0).Sum(x => x.dl_cm19_count),
|
|
dl_cm20_count = data2.Where(x => x.dl_cm20_count > 0).Sum(x => x.dl_cm20_count),
|
|
total = data2.Where(x => x.total > 0).Sum(x => x.total)
|
|
},
|
|
sum = new
|
|
{
|
|
rt_count = data1.Where(x => x.rt_count > 0).Sum(x => x.rt_count) + data2.Where(x => x.rt_count > 0).Sum(x => x.rt_count),
|
|
career_count = data1.Where(x => x.career_count > 0).Sum(x => x.career_count) + data2.Where(x => x.career_count > 0).Sum(x => x.career_count),
|
|
move_count = data1.Where(x => x.move_count > 0).Sum(x => x.move_count) + data2.Where(x => x.move_count > 0).Sum(x => x.move_count),
|
|
family_count = data1.Where(x => x.family_count > 0).Sum(x => x.family_count) + data2.Where(x => x.family_count > 0).Sum(x => x.family_count),
|
|
education_count = data1.Where(x => x.education_count > 0).Sum(x => x.education_count) + data2.Where(x => x.education_count > 0).Sum(x => x.education_count),
|
|
other_count = data1.Where(x => x.other_count > 0).Sum(x => x.other_count) + data2.Where(x => x.other_count > 0).Sum(x => x.other_count),
|
|
rd_count = data1.Where(x => x.rd_count > 0).Sum(x => x.rd_count) + data2.Where(x => x.rd_count > 0).Sum(x => x.rd_count),
|
|
ro_count = data1.Where(x => x.ro_count > 0).Sum(x => x.ro_count) + data2.Where(x => x.ro_count > 0).Sum(x => x.ro_count),
|
|
dl_cm19_count = data1.Where(x => x.dl_cm19_count > 0).Sum(x => x.dl_cm19_count) + data2.Where(x => x.dl_cm19_count > 0).Sum(x => x.dl_cm19_count),
|
|
dl_cm20_count = data1.Where(x => x.dl_cm20_count > 0).Sum(x => x.dl_cm20_count) + data2.Where(x => x.dl_cm20_count > 0).Sum(x => x.dl_cm20_count),
|
|
total = data1.Where(x => x.total > 0).Sum(x => x.total) + data2.Where(x => x.total > 0).Sum(x => x.total)
|
|
}
|
|
}
|
|
};
|
|
return Success(data);
|
|
}
|
|
|
|
/// <summary>
|
|
/// เกษียณอายุราชการ
|
|
/// </summary>
|
|
/// <param name="type">ประเภทUser(officer,employee)(ตัวใหญ่หรือเล็กก็ได้)</param>
|
|
/// <param name="year">ปีงบประมาณ(ค.ศ.)</param>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("update-status/{type}/{year}")]
|
|
public async Task<ActionResult<ResponseObject>> UpdateStatusRetirement(string type, int year)
|
|
{
|
|
var retirePeriodOfficer = await _context.RetirementPeriods
|
|
.Include(x => x.RetirementRawProfiles.Where(y => y.Remove != "REMOVE"))
|
|
.Where(x => x.Year == year && x.Type.Trim().ToUpper().Contains(type))
|
|
.FirstOrDefaultAsync();
|
|
|
|
if (retirePeriodOfficer == null)
|
|
return Error("ไม่พบรอบประกาศเกษียณอายุราชการ");
|
|
|
|
var data = retirePeriodOfficer.RetirementRawProfiles
|
|
.Select(x => new
|
|
{
|
|
profileId = x.profileId
|
|
})
|
|
.ToList();
|
|
|
|
return Success(data);
|
|
}
|
|
|
|
#region 31-ประกาศเกษียณข้าราชการ & 32-ประกาศเกษียณลูกจ้างประจำ
|
|
/// <summary>
|
|
/// 31-ประกาศเกษียณข้าราชการ & 32-ประกาศเกษียณลูกจ้างประจำ
|
|
/// </summary>
|
|
/// <param name="Id">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>
|
|
[HttpGet("31/{exportType}/{Id}")]
|
|
public async Task<ActionResult<ResponseObject>> GetProfileRetirement([FromRoute] Guid Id, string exportType = "pdf")
|
|
{
|
|
var retire = await _service.GetProfileRetirementdAsync(Id);
|
|
if (retire != null)
|
|
{
|
|
var reportfile = string.Empty;
|
|
exportType = exportType.Trim();
|
|
switch (retire.GetType().GetProperty("Type").GetValue(retire))
|
|
{
|
|
case "OFFICER":
|
|
if (string.IsNullOrEmpty(retire.GetType().GetProperty("TypeReport").GetValue(retire)))
|
|
{
|
|
reportfile = $"retire-1";
|
|
}
|
|
else if (retire.GetType().GetProperty("TypeReport").GetValue(retire) == "ADD" || retire.GetType().GetProperty("TypeReport").GetValue(retire) == "EDIT")
|
|
{
|
|
reportfile = $"retire-2";
|
|
}
|
|
else if (retire.GetType().GetProperty("TypeReport").GetValue(retire) == "REMOVE")
|
|
{
|
|
reportfile = $"retire-3";
|
|
}
|
|
else
|
|
{
|
|
return Error(retire.GetType().GetProperty("TypeReport").GetValue(retire));
|
|
}
|
|
break;
|
|
case "EMPLOYEE":
|
|
if (string.IsNullOrEmpty(retire.GetType().GetProperty("TypeReport").GetValue(retire)))
|
|
{
|
|
reportfile = $"retire-emp-1";
|
|
}
|
|
else if (retire.GetType().GetProperty("TypeReport").GetValue(retire) == "ADD" || retire.GetType().GetProperty("TypeReport").GetValue(retire) == "EDIT")
|
|
{
|
|
reportfile = $"retire-emp-2";
|
|
}
|
|
else if (retire.GetType().GetProperty("TypeReport").GetValue(retire) == "REMOVE")
|
|
{
|
|
reportfile = $"retire-emp-3";
|
|
}
|
|
else
|
|
{
|
|
return Error(retire.GetType().GetProperty("TypeReport").GetValue(retire));
|
|
}
|
|
break;
|
|
default:
|
|
return Error(retire.GetType().GetProperty("Type").GetValue(retire));
|
|
}
|
|
|
|
var data = new
|
|
{
|
|
template = reportfile,
|
|
reportName = "docx-report",
|
|
data = retire
|
|
};
|
|
return Success(data);
|
|
}
|
|
else
|
|
{
|
|
return NotFound();
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|