เพิ่มรับคืนเครื่องราช
This commit is contained in:
parent
59f782e8cf
commit
1619a502d4
22 changed files with 33518 additions and 41 deletions
|
|
@ -18,10 +18,14 @@ namespace BMA.EHR.Application.Repositories
|
|||
{
|
||||
private readonly IApplicationDBContext _dbContext;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
public InsigniaPeriodsRepository(IApplicationDBContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
private readonly MinIOService _documentService;
|
||||
public InsigniaPeriodsRepository(IApplicationDBContext dbContext,
|
||||
MinIOService documentService,
|
||||
IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_documentService = documentService;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<InsigniaPeriod>> FindByNameAsync(string name)
|
||||
|
|
@ -5706,6 +5710,7 @@ namespace BMA.EHR.Application.Repositories
|
|||
else
|
||||
{
|
||||
var request = await _dbContext.Set<InsigniaRequest>()
|
||||
.Include(x => x.Document)
|
||||
.Include(x => x.Organization)
|
||||
.ThenInclude(x => x.OrganizationOrganization)
|
||||
.Where(x => x.Organization != null)
|
||||
|
|
@ -5721,7 +5726,8 @@ namespace BMA.EHR.Application.Repositories
|
|||
RequestId = request == null ? null : request.Id,
|
||||
RequestNote = request == null ? "" : request.RequestNote,
|
||||
RequestStatus = request == null ? null : request.RequestStatus,
|
||||
OrganizationName = request == null ? "" : request.Organization.OrganizationOrganization.Name
|
||||
OrganizationName = request == null ? "" : request.Organization.OrganizationOrganization.Name,
|
||||
Document = request == null ? null : (request.Document == null ? null : await _documentService.ImagesPath(request.Document.Id)),
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -5850,7 +5856,8 @@ namespace BMA.EHR.Application.Repositories
|
|||
IsApprove = h.IsApprove,
|
||||
RequestDate = h.RequestDate,
|
||||
Status = h.Status,
|
||||
RequestNote = h.Reason,
|
||||
RequestNote = h.ReasonReject,
|
||||
Reason = h.Reason,
|
||||
// Docs = GetDocFile(h.Profile.Id),
|
||||
MatchingConditions = h.MatchingConditions == null ? null : JsonConvert.DeserializeObject<List<MatchingCondition>>(h.MatchingConditions)
|
||||
})).ToList();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Application.Responses;
|
||||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using BMA.EHR.Domain.Models.Organizations;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
|
@ -28,7 +29,7 @@ namespace BMA.EHR.Application.Repositories
|
|||
|
||||
#region " Methods "
|
||||
|
||||
public string GetOrganizationNameFullPath(Guid id, bool showRoot = false, bool descending = false,string seperator = " ")
|
||||
public string GetOrganizationNameFullPath(Guid id, bool showRoot = false, bool descending = false, string seperator = " ")
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -96,6 +97,62 @@ namespace BMA.EHR.Application.Repositories
|
|||
throw;
|
||||
}
|
||||
}
|
||||
private List<string> GetOcNameFullPath(Guid id, bool showRoot = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ocList = new List<string>();
|
||||
|
||||
var oc = (from o in _dbContext.Set<OrganizationEntity>().Include(x => x.Parent).Include(x => x.OrganizationOrganization).Where(x => x.OrganizationOrganization != null).AsQueryable()
|
||||
join oc_name in _dbContext.Set<OrganizationOrganization>().AsQueryable() on o.OrganizationOrganization.Id equals oc_name.Id
|
||||
where o.Parent != null
|
||||
select new
|
||||
{
|
||||
Id = o.Id,
|
||||
Name = oc_name.Name,
|
||||
o.IsActive,
|
||||
o.Parent
|
||||
}).FirstOrDefault(x => x.Id == id && x.IsActive);
|
||||
|
||||
if (oc == null)
|
||||
return ocList;
|
||||
|
||||
ocList.Add(oc.Name);
|
||||
|
||||
if (oc.Parent?.Id != null)
|
||||
{
|
||||
ocList.AddRange(GetOcNameFullPath(oc.Parent.Id, showRoot));
|
||||
}
|
||||
|
||||
return ocList;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
private string FindOCFullPath(Guid id, bool showRoot = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ocList = GetOcNameFullPath(id, showRoot);
|
||||
var ret = String.Empty;
|
||||
foreach (var oc in ocList)
|
||||
{
|
||||
ret = oc + "/" + ret;
|
||||
}
|
||||
|
||||
if (ret.Length > 2)
|
||||
ret = ret.Substring(0, ret.Length - 1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ namespace BMA.EHR.Application.Repositories.Reports
|
|||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
private readonly OrganizationCommonRepository _organizationCommonRepository;
|
||||
private readonly NotificationRepository _repositoryNoti;
|
||||
private readonly InsigniaPeriodsRepository _repositoryInsignia;
|
||||
private readonly string CRLF = "\r\n";
|
||||
|
||||
#endregion
|
||||
|
|
@ -30,14 +31,16 @@ namespace BMA.EHR.Application.Repositories.Reports
|
|||
#region " Constructor and Destructor "
|
||||
|
||||
public InsigniaReportRepository(IApplicationDBContext dbContext,
|
||||
OrganizationCommonRepository organizationCommonRepository,
|
||||
NotificationRepository repositoryNoti,
|
||||
IWebHostEnvironment hostEnvironment)
|
||||
OrganizationCommonRepository organizationCommonRepository,
|
||||
InsigniaPeriodsRepository repositoryInsignia,
|
||||
NotificationRepository repositoryNoti,
|
||||
IWebHostEnvironment hostEnvironment)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_hostingEnvironment = hostEnvironment;
|
||||
_repositoryNoti = repositoryNoti;
|
||||
_organizationCommonRepository = organizationCommonRepository;
|
||||
_repositoryInsignia = repositoryInsignia;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -904,6 +907,8 @@ namespace BMA.EHR.Application.Repositories.Reports
|
|||
|
||||
return data;
|
||||
}
|
||||
|
||||
//noti ยื่นเสนอคน
|
||||
public async Task NotifyInsignia()
|
||||
{
|
||||
var insigniaPeriods = await _dbContext.Set<InsigniaPeriod>()
|
||||
|
|
@ -931,6 +936,147 @@ namespace BMA.EHR.Application.Repositories.Reports
|
|||
}
|
||||
}
|
||||
|
||||
//ล็อกข้อมูล โอนคนไปบันทึกผล
|
||||
public async Task LockInsignia()
|
||||
{
|
||||
var insigniaPeriods = await _dbContext.Set<InsigniaPeriod>()
|
||||
.AsQueryable()
|
||||
.Include(x => x.InsigniaRequests)
|
||||
.Include(x => x.ReliefDoc)
|
||||
.ToListAsync();
|
||||
foreach (var insigniaPeriod in insigniaPeriods)
|
||||
{
|
||||
if (insigniaPeriod.EndDate.Date.AddDays(5) == DateTime.Now.Date)
|
||||
continue;
|
||||
insigniaPeriod.IsLock = true;
|
||||
var insigniaNote = await _dbContext.Set<InsigniaNote>()
|
||||
.Include(x => x.InsigniaNoteProfiles)
|
||||
.ThenInclude(x => x.Profile)
|
||||
.Include(x => x.InsigniaNoteProfiles)
|
||||
.ThenInclude(x => x.RequestInsignia)
|
||||
.FirstOrDefaultAsync(x => x.Year == insigniaPeriod.Year);
|
||||
if (insigniaNote == null)
|
||||
{
|
||||
insigniaNote = new InsigniaNote
|
||||
{
|
||||
// Round = insigniaPeriod.Round,
|
||||
Name = $"รอบการเสนอขอพระราชทานเครื่องราชปี {insigniaPeriod.Year + 543}",
|
||||
Year = insigniaPeriod.Year,
|
||||
// StartDate = insigniaPeriod.StartDate,
|
||||
// EndDate = insigniaPeriod.EndDate,
|
||||
// Amount = insigniaPeriod.Amount,
|
||||
// ReliefDoc = insigniaPeriod.ReliefDoc,
|
||||
CreatedUserId = "System Administrator",
|
||||
CreatedFullName = "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = "System Administrator",
|
||||
LastUpdateUserId = "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
};
|
||||
await _dbContext.Set<InsigniaNote>().AddAsync(insigniaNote);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
insigniaNote = await _dbContext.Set<InsigniaNote>()
|
||||
.Include(x => x.InsigniaNoteProfiles)
|
||||
.ThenInclude(x => x.Profile)
|
||||
.Include(x => x.InsigniaNoteProfiles)
|
||||
.ThenInclude(x => x.RequestInsignia)
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaNote.Id);
|
||||
}
|
||||
var requestOlds = await _dbContext.Set<InsigniaRequest>()
|
||||
.Where(p => p.Period == insigniaPeriod)
|
||||
.Where(p => p.RequestStatus == "st5")
|
||||
.ToListAsync();
|
||||
foreach (var requestOld in requestOlds)
|
||||
{
|
||||
var profileOlds = await _dbContext.Set<InsigniaRequestProfile>()
|
||||
.Include(x => x.Profile)
|
||||
.Include(x => x.RequestInsignia)
|
||||
.Where(p => p.Request == requestOld)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var profileOld in profileOlds)
|
||||
{
|
||||
if (profileOld.Status == "DELETE" || profileOld.Status == "REJECT")
|
||||
continue;
|
||||
var noreProfileOld = insigniaNote.InsigniaNoteProfiles
|
||||
.Where(x => x.Profile == profileOld.Profile)
|
||||
.FirstOrDefault();
|
||||
if (noreProfileOld != null)
|
||||
{
|
||||
noreProfileOld.RequestDate = profileOld.RequestDate;
|
||||
noreProfileOld.Salary = profileOld.Salary;
|
||||
noreProfileOld.IsApprove = profileOld.IsApprove;
|
||||
noreProfileOld.RequestInsignia = profileOld.RequestInsignia;
|
||||
noreProfileOld.CreatedUserId = "System Administrator";
|
||||
noreProfileOld.CreatedFullName = "";
|
||||
noreProfileOld.CreatedAt = DateTime.Now;
|
||||
noreProfileOld.LastUpdateFullName = "System Administrator";
|
||||
noreProfileOld.LastUpdateUserId = "";
|
||||
noreProfileOld.LastUpdatedAt = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (profileOld.Profile == null)
|
||||
continue;
|
||||
await _dbContext.Set<InsigniaNoteProfile>().AddAsync(new InsigniaNoteProfile
|
||||
{
|
||||
RequestDate = profileOld.RequestDate,
|
||||
Salary = profileOld.Salary,
|
||||
IsApprove = profileOld.IsApprove,
|
||||
Status = "PENDING",
|
||||
Profile = profileOld.Profile,
|
||||
RequestInsignia = profileOld.RequestInsignia,
|
||||
OrganizationOrganizationSend = profileOld.Profile == null || profileOld.Profile.OcId == null ? null : _organizationCommonRepository.GetOrganizationNameFullPath(profileOld.Profile.OcId.Value, false, false),
|
||||
InsigniaNote = insigniaNote,
|
||||
CreatedUserId = "System Administrator",
|
||||
CreatedFullName = "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = "System Administrator",
|
||||
LastUpdateUserId = "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
//คำนวนผู้ได้รับเครื่องราช
|
||||
public async Task CalInsignaiRequestBkk()
|
||||
{
|
||||
var insigniaPeriods = await _dbContext.Set<InsigniaPeriod>()
|
||||
.AsQueryable()
|
||||
.ToListAsync();
|
||||
foreach (var insigniaPeriod in insigniaPeriods)
|
||||
{
|
||||
if (insigniaPeriod.StartDate == DateTime.Now.Date)
|
||||
continue;
|
||||
var organizationType = await _dbContext.Set<OrganizationType>().Where(x => x.Name == "หน่วยงาน").FirstOrDefaultAsync();
|
||||
if (organizationType == null)
|
||||
continue;
|
||||
var organizations = await _dbContext.Set<OrganizationEntity>().Where(x => x.OrganizationType == organizationType).ToListAsync();
|
||||
foreach (var organization in organizations)
|
||||
{
|
||||
if (organization == null)
|
||||
continue;
|
||||
|
||||
var result = await _repositoryInsignia.GetInsigniaRequest(insigniaPeriod.Id, organization.Id);
|
||||
if (result != null)
|
||||
{
|
||||
Guid period = result.PeriodId;
|
||||
string requestStatus = result.RequestStatus;
|
||||
var candidate = await _repositoryInsignia.GetInsigniaCandidateBKK(insigniaPeriod.Id, organization.Id);
|
||||
// ตรวจสอบว่ารายการอยู่ใน table insignia_request_new
|
||||
if (requestStatus == null)
|
||||
{
|
||||
// บันทึกรายชื่อ
|
||||
await _repositoryInsignia.InsertCandidate(period, organization.Id, candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue