เพิ่มรับคืนเครื่องราช
This commit is contained in:
parent
59f782e8cf
commit
1619a502d4
22 changed files with 33518 additions and 41 deletions
|
|
@ -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