ทmark alet insignia

This commit is contained in:
Kittapath 2023-09-27 13:20:00 +07:00
parent b7027ebe55
commit 9692af553b
9 changed files with 16687 additions and 241 deletions

View file

@ -5858,258 +5858,259 @@ namespace BMA.EHR.Application.Repositories
Status = h.Status,
RequestNote = h.ReasonReject,
Reason = h.Reason,
MarkALert = h.MarkALert == null ? new List<string>() : JsonConvert.DeserializeObject<List<string>>(h.MarkALert),
// Docs = GetDocFile(h.Profile.Id),
MatchingConditions = h.MatchingConditions == null ? null : JsonConvert.DeserializeObject<List<MatchingCondition>>(h.MatchingConditions)
})).ToList();
return result;
}
return result;
}
else
{
return null;
}
{
return null;
}
}
catch
{
throw;
}
}
// เช็คข้อมูลนำเข้า กับข้อมูลที่อยู่ใน database
// public async List<InsigniaRequestProfile> GetDuplicate(List<InsigniaRequestProfile> income, Guid period, Guid ocId, bool Duplicate = false)
// {
// try
// {
// var id = GetRequestId(period, ocId);
// เช็คข้อมูลนำเข้า กับข้อมูลที่อยู่ใน database
// public async List<InsigniaRequestProfile> GetDuplicate(List<InsigniaRequestProfile> income, Guid period, Guid ocId, bool Duplicate = false)
// {
// try
// {
// var id = GetRequestId(period, ocId);
// var req = await _dbContext.Set<InsigniaRequests>().FirstOrDefault(x => x.Id == id);
// var req = await _dbContext.Set<InsigniaRequests>().FirstOrDefault(x => x.Id == id);
// if (req == null)
// throw new Exception(GlobalMessages.InsigniaNotFound);
// if (req == null)
// throw new Exception(GlobalMessages.InsigniaNotFound);
// var profile = await _dbContext.Set<InsigniaRequestsProfiles>().AsQueryable()
// .Include(x => x.RequestInsignia)
// .ThenInclude(x => x.InsigniaType)
// .Include(x => x.Profile)
// .ThenInclude(x => x.Insignias)
// .Where(x => x.Request.Id == id)
// .Select(h => new DuplicateProfile
// {
// ProfileId = h.Profile.Id,
// IsApprove = h.IsApprove,
// RequestQualificationStatus = h.QualificationStatus,
// RequestDocumentStatus = h.DocumentStatus,
// Special = h.Special
// });
// var profile = await _dbContext.Set<InsigniaRequestsProfiles>().AsQueryable()
// .Include(x => x.RequestInsignia)
// .ThenInclude(x => x.InsigniaType)
// .Include(x => x.Profile)
// .ThenInclude(x => x.Insignias)
// .Where(x => x.Request.Id == id)
// .Select(h => new DuplicateProfile
// {
// ProfileId = h.Profile.Id,
// IsApprove = h.IsApprove,
// RequestQualificationStatus = h.QualificationStatus,
// RequestDocumentStatus = h.DocumentStatus,
// Special = h.Special
// });
// var newIncome = income.GroupJoin(profile,
// pdb => pdb.Profile.Id,
// dp => dp.ProfileId,
// (pdb, dp) => new
// {
// Profile = pdb.Profile,
// pdb.Profile.Insignias,
// pdb.RequestInsignia,
// //pdb.RequestInsignia.InsigniaType,
// pdb.Salary,
// pdb.RequestDate,
// ProfileDB = dp
// })
// .ToList()
// .Where(d => !Duplicate ? d.ProfileDB.Count() == 0 : d.ProfileDB.Count() != 0)
// .Select(d => !Duplicate ? new InsigniaRequestProfile
// {
// Request = req,
// Profile = d.Profile,
// RequestInsignia = d.RequestInsignia,
// Salary = d.Salary,
// RequestDate = d.RequestDate,
// } : new InsigniaRequestProfile
// {
// Request = req,
// Profile = d.Profile,
// RequestInsignia = d.RequestInsignia,
// Salary = d.Salary,
// RequestDate = d.RequestDate,
// IsApprove = d.ProfileDB.First().IsApprove,
// QualificationStatus = d.ProfileDB.First().RequestQualificationStatus,
// DocumentStatus = d.ProfileDB.First().RequestDocumentStatus,
// Special = d.ProfileDB.First().Special
// })
// .ToList();
// var newIncome = income.GroupJoin(profile,
// pdb => pdb.Profile.Id,
// dp => dp.ProfileId,
// (pdb, dp) => new
// {
// Profile = pdb.Profile,
// pdb.Profile.Insignias,
// pdb.RequestInsignia,
// //pdb.RequestInsignia.InsigniaType,
// pdb.Salary,
// pdb.RequestDate,
// ProfileDB = dp
// })
// .ToList()
// .Where(d => !Duplicate ? d.ProfileDB.Count() == 0 : d.ProfileDB.Count() != 0)
// .Select(d => !Duplicate ? new InsigniaRequestProfile
// {
// Request = req,
// Profile = d.Profile,
// RequestInsignia = d.RequestInsignia,
// Salary = d.Salary,
// RequestDate = d.RequestDate,
// } : new InsigniaRequestProfile
// {
// Request = req,
// Profile = d.Profile,
// RequestInsignia = d.RequestInsignia,
// Salary = d.Salary,
// RequestDate = d.RequestDate,
// IsApprove = d.ProfileDB.First().IsApprove,
// QualificationStatus = d.ProfileDB.First().RequestQualificationStatus,
// DocumentStatus = d.ProfileDB.First().RequestDocumentStatus,
// Special = d.ProfileDB.First().Special
// })
// .ToList();
// return newIncome;
// }
// catch
// {
// throw;
// }
// }
// return newIncome;
// }
// catch
// {
// throw;
// }
// }
// ลบข้อมูลใน db ที่ไม่เท่ากับ income
// public async List<InsigniaRequestProfile> DeleteProfile(List<InsigniaRequestProfile> income, Guid period, Guid ocId)
// {
// try
// {
// var id = GetRequestId(period, ocId);
// ลบข้อมูลใน db ที่ไม่เท่ากับ income
// public async List<InsigniaRequestProfile> DeleteProfile(List<InsigniaRequestProfile> income, Guid period, Guid ocId)
// {
// try
// {
// var id = GetRequestId(period, ocId);
// var incomProfileId = income.Select(i => i.Profile.Id).ToList();
// var incomProfileId = income.Select(i => i.Profile.Id).ToList();
// var arrayData = await _dbContext.Set<InsigniaRequestsProfiles>().AsQueryable()
// .Where(i => !(incomProfileId.Contains(i.Profile.Id)) && i.Request.Id == id)
// .ToList();
// var arrayData = await _dbContext.Set<InsigniaRequestsProfiles>().AsQueryable()
// .Where(i => !(incomProfileId.Contains(i.Profile.Id)) && i.Request.Id == id)
// .ToList();
// return arrayData;
// }
// catch
// {
// throw;
// }
// }
// return arrayData;
// }
// catch
// {
// throw;
// }
// }
// insert candidate list
public async Task InsertCandidate(Guid periodId, Guid ocId, List<InsigniaResultSet> items)
// insert candidate list
public async Task InsertCandidate(Guid periodId, Guid ocId, List<InsigniaResultSet> items)
{
try
{
try
var period = await _dbContext.Set<InsigniaPeriod>().FirstOrDefaultAsync(p => p.Id == periodId);
if (period == null)
throw new Exception(GlobalMessages.CoinPeriodNotFound);
var periodOlds = await _dbContext.Set<InsigniaPeriod>().Where(p => p.Year == period.Year).ToListAsync();
foreach (var periodOld in periodOlds)
{
var period = await _dbContext.Set<InsigniaPeriod>().FirstOrDefaultAsync(p => p.Id == periodId);
if (period == null)
throw new Exception(GlobalMessages.CoinPeriodNotFound);
var periodOlds = await _dbContext.Set<InsigniaPeriod>().Where(p => p.Year == period.Year).ToListAsync();
foreach (var periodOld in periodOlds)
var requestOlds = await _dbContext.Set<InsigniaRequest>().Where(p => p.Period == periodOld).ToListAsync();
foreach (var requestOld in requestOlds)
{
var requestOlds = await _dbContext.Set<InsigniaRequest>().Where(p => p.Period == periodOld).ToListAsync();
foreach (var requestOld in requestOlds)
{
var profileOlds = await _dbContext.Set<InsigniaRequestProfile>().Where(p => p.Request == requestOld).Select(x => x.Profile.Id).ToListAsync();
items = items.Where(x => !profileOlds.Contains(x.ProfileId)).ToList();
}
var profileOlds = await _dbContext.Set<InsigniaRequestProfile>().Where(p => p.Request == requestOld).Select(x => x.Profile.Id).ToListAsync();
items = items.Where(x => !profileOlds.Contains(x.ProfileId)).ToList();
}
var oc = await _dbContext.Set<OrganizationEntity>().FirstOrDefaultAsync(x => x.Id == ocId);
if (oc == null)
throw new Exception(GlobalMessages.OCNotFound);
var req = new InsigniaRequest
{
Period = period,
Organization = oc,
RequestStatus = "st1",
RequestNote = "",
CreatedUserId = UserId ?? "System Administrator",
CreatedFullName = FullName ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
foreach (var item in items)
{
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(p => p.Id == item.ProfileId);
var req_insignia = await _dbContext.Set<Insignia>().FirstOrDefaultAsync(i => i.Id == item.RequestInsignia.Id);
if (pf != null)
{
req.RequestProfiles.Add(new InsigniaRequestProfile
{
Status = "PENDING",
Profile = pf,
RequestInsignia = req_insignia,
Salary = item.Salary == null ? null : item.Salary,
RequestDate = DateTime.Now,
MatchingConditions = System.Text.Json.JsonSerializer.Serialize(item.MatchingConditions), // serialize to string
CreatedUserId = UserId ?? "System Administrator",
CreatedFullName = FullName ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
});
}
}
await _dbContext.Set<InsigniaRequest>().AddAsync(req);
await _dbContext.SaveChangesAsync();
}
catch
var oc = await _dbContext.Set<OrganizationEntity>().FirstOrDefaultAsync(x => x.Id == ocId);
if (oc == null)
throw new Exception(GlobalMessages.OCNotFound);
var req = new InsigniaRequest
{
throw;
Period = period,
Organization = oc,
RequestStatus = "st1",
RequestNote = "",
CreatedUserId = UserId ?? "System Administrator",
CreatedFullName = FullName ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
foreach (var item in items)
{
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(p => p.Id == item.ProfileId);
var req_insignia = await _dbContext.Set<Insignia>().FirstOrDefaultAsync(i => i.Id == item.RequestInsignia.Id);
if (pf != null)
{
req.RequestProfiles.Add(new InsigniaRequestProfile
{
Status = "PENDING",
Profile = pf,
RequestInsignia = req_insignia,
Salary = item.Salary == null ? null : item.Salary,
RequestDate = DateTime.Now,
MatchingConditions = System.Text.Json.JsonSerializer.Serialize(item.MatchingConditions), // serialize to string
CreatedUserId = UserId ?? "System Administrator",
CreatedFullName = FullName ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
});
}
}
await _dbContext.Set<InsigniaRequest>().AddAsync(req);
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
// เช็คข้อมูลใน kp7insignia
// public async ProfileInsignia ListKp7Insignia(string name, string profile, int year)
// {
// try
// {
// var item = await _dbContext.Set<ProfileInsignias>().AsQueryable()
// .Include(x => x.Insignia)
// .Include(x => x.Profile)
// .FirstOrDefault(x => x.Profile.Id == profile &&
// x.Year == year &&
// x.Insignia.Name.Contains(name));
// return item;
// }
// catch
// {
// throw;
// }
// }
// บันทึกข้อมูลลง กพ.7
// public async ProfileInsignia InsertKp7Insignia(InsigniaKp7Item kp7, InsigniaProfile profile)
// {
// try
// {
// var pf = await _dbContext.Set<Profiles>().FirstOrDefault(x => x.Id == profile.FkProfileId);
// var insignia = await _dbContext.Set<Insignias>().FirstOrDefault(x => x.Name == profile.InsigniaName);
// var kp7Insignia = new ProfileInsignia
// {
// Profile = pf,
// Year = DateTime.Now.Year,
// DateReceive = kp7.InsigniaDatereceive.Value,
// Insignia = insignia,
// Level = kp7.InsigniaLevel,
// No = profile.InsigniaNo,
// Issue = kp7.InsigniaIssue,
// VolumeNo = kp7.InsigniaVolumeno.Value.ToString(),
// Volume = kp7.InsigniaVolume,
// Section = kp7.InsigniaSection,
// DateStamp = DateTime.Now,
// DateAnnounce = kp7.InsigniaDateannounce.Value,
// Page = profile.InsigniaPage,
// };
// return kp7Insignia;
// }
// catch
// {
// throw;
// }
// }
// update กพ.7
// public async ProfileInsignia UpdateKp7Insignia(Guid id)
// {
// try
// {
// var item = await _dbContext.Set<ProfileInsignias>().FirstOrDefaultAsync(x => x.Id == id);
// return item;
// }
// catch
// {
// throw;
// }
// }
#endregion
}
// เช็คข้อมูลใน kp7insignia
// public async ProfileInsignia ListKp7Insignia(string name, string profile, int year)
// {
// try
// {
// var item = await _dbContext.Set<ProfileInsignias>().AsQueryable()
// .Include(x => x.Insignia)
// .Include(x => x.Profile)
// .FirstOrDefault(x => x.Profile.Id == profile &&
// x.Year == year &&
// x.Insignia.Name.Contains(name));
// return item;
// }
// catch
// {
// throw;
// }
// }
// บันทึกข้อมูลลง กพ.7
// public async ProfileInsignia InsertKp7Insignia(InsigniaKp7Item kp7, InsigniaProfile profile)
// {
// try
// {
// var pf = await _dbContext.Set<Profiles>().FirstOrDefault(x => x.Id == profile.FkProfileId);
// var insignia = await _dbContext.Set<Insignias>().FirstOrDefault(x => x.Name == profile.InsigniaName);
// var kp7Insignia = new ProfileInsignia
// {
// Profile = pf,
// Year = DateTime.Now.Year,
// DateReceive = kp7.InsigniaDatereceive.Value,
// Insignia = insignia,
// Level = kp7.InsigniaLevel,
// No = profile.InsigniaNo,
// Issue = kp7.InsigniaIssue,
// VolumeNo = kp7.InsigniaVolumeno.Value.ToString(),
// Volume = kp7.InsigniaVolume,
// Section = kp7.InsigniaSection,
// DateStamp = DateTime.Now,
// DateAnnounce = kp7.InsigniaDateannounce.Value,
// Page = profile.InsigniaPage,
// };
// return kp7Insignia;
// }
// catch
// {
// throw;
// }
// }
// update กพ.7
// public async ProfileInsignia UpdateKp7Insignia(Guid id)
// {
// try
// {
// var item = await _dbContext.Set<ProfileInsignias>().FirstOrDefaultAsync(x => x.Id == id);
// return item;
// }
// catch
// {
// throw;
// }
// }
#endregion
}
}

View file

@ -1,4 +1,5 @@
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Messaging;
using BMA.EHR.Application.Responses;
using BMA.EHR.Application.Responses.Messages;
using BMA.EHR.Domain.Models.HR;
@ -17,16 +18,19 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
private readonly IApplicationDBContext _dbContext;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly EmailSenderService _emailSenderService;
#endregion
#region " Constructor and Destuctor "
public NotificationRepository(IApplicationDBContext dbContext,
IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
EmailSenderService emailSenderService,
IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
_emailSenderService = emailSenderService;
}
#endregion
@ -130,19 +134,7 @@ namespace BMA.EHR.Application.Repositories.MessageQueue
}
if (IsSendMail == true)
{
// _context.Notifications.Add(new Notification
// {
// Body = req.Body,
// ReceiverUserId = req.ReceiverUserId,
// Type = "",
// Payload = "",
// CreatedUserId = UserId ?? "System Administrator",
// CreatedFullName = FullName ?? "",
// CreatedAt = DateTime.Now,
// LastUpdateFullName = FullName ?? "System Administrator",
// LastUpdateUserId = UserId ?? "",
// LastUpdatedAt = DateTime.Now,
// });
_emailSenderService.SendMail(Subject, Body, "kittapath@frappet.com");
}
await _dbContext.SaveChangesAsync();
}