แก้ขอโอนกับทะเบียนใหม่

This commit is contained in:
Kittapath 2024-05-17 18:12:45 +07:00
parent 94c43e5479
commit 2a17eff17d
10 changed files with 18654 additions and 347 deletions

View file

@ -1018,12 +1018,10 @@ namespace BMA.EHR.Application.Repositories.Commands
// 2. Query // 2. Query
var appointPeople = await _dbContext.Set<PlacementTransfer>() var appointPeople = await _dbContext.Set<PlacementTransfer>()
.Include(x => x.Profile)
.ThenInclude(x => x.Prefix)
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId) //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
.Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!)) .Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.Status.Trim().ToUpper() == "REPORT") .Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.Profile!.CitizenId) .OrderBy(x => x.citizenId)
.ToListAsync(); .ToListAsync();
// 3. Create new Record // 3. Create new Record
@ -1033,10 +1031,10 @@ namespace BMA.EHR.Application.Repositories.Commands
var receiver = new CommandReceiver var receiver = new CommandReceiver
{ {
Sequence = seq, Sequence = seq,
CitizenId = item.Profile!.CitizenId!, CitizenId = item.citizenId,
Prefix = item.Profile!.Prefix!.Name, Prefix = item.prefix,
FirstName = item.Profile!.FirstName!, FirstName = item.firstName,
LastName = item.Profile!.LastName!, LastName = item.lastName,
RefPlacementProfileId = item.Id, RefPlacementProfileId = item.Id,
Amount = item.AmountOld, Amount = item.AmountOld,
}; };
@ -5633,154 +5631,150 @@ namespace BMA.EHR.Application.Repositories.Commands
foreach (var recv in command.Receivers) foreach (var recv in command.Receivers)
{ {
var data = await _dbContext.Set<PlacementTransfer>() var data = await _dbContext.Set<PlacementTransfer>()
.Include(x => x.Profile)
.ThenInclude(x => x.Salaries)
.Include(x => x.Profile)
.ThenInclude(x => x.PositionLevel)
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (data == null) if (data == null)
throw new Exception(GlobalMessages.DataNotFound); throw new Exception(GlobalMessages.DataNotFound);
data.Profile.IsActive = false; //data.Profile.IsActive = false;
data.Profile.IsLeave = true; //data.Profile.IsLeave = true;
data.Profile.LeaveReason = "คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ"; //data.Profile.LeaveReason = "คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ";
data.Profile.LeaveDate = command.CommandAffectDate; //data.Profile.LeaveDate = command.CommandAffectDate;
var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); //var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
var order = 1; //var order = 1;
if (lastSarary != null && lastSarary.Order != null) //if (lastSarary != null && lastSarary.Order != null)
order = lastSarary.Order.Value + 1; //order = lastSarary.Order.Value + 1;
var salary = new ProfileSalary // var salary = new ProfileSalary
{ // {
Order = order, // Order = order,
Date = command.CommandAffectDate, // Date = command.CommandAffectDate,
Amount = lastSarary == null ? null : lastSarary.Amount, // Amount = lastSarary == null ? null : lastSarary.Amount,
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount, // PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount, // MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
SalaryClass = "", // SalaryClass = "",
SalaryRef = "คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", // SalaryRef = "คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
OcId = lastSarary == null ? null : lastSarary.OcId, // OcId = lastSarary == null ? null : lastSarary.OcId,
PositionId = lastSarary == null ? null : lastSarary.PositionId, // PositionId = lastSarary == null ? null : lastSarary.PositionId,
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel, // PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId, // PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId, // PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId, // OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
PosNoId = lastSarary == null ? null : lastSarary.PosNoId, // PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", // CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", // RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
CommandTypeName = command.CommandType.Name, // CommandTypeName = command.CommandType.Name,
PositionEmployeeGroupId = null, // PositionEmployeeGroupId = null,
PositionEmployeeLevelId = null, // PositionEmployeeLevelId = null,
PositionEmployeePositionId = null, // PositionEmployeePositionId = null,
PositionEmployeePositionSideId = null, // PositionEmployeePositionSideId = null,
PosNoEmployee = "", // PosNoEmployee = "",
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null, // //PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId, // PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId, // //PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
IsActive = true, // IsActive = true,
CreatedAt = DateTime.Now, // CreatedAt = DateTime.Now,
CreatedFullName = FullName ?? "System Administrator", // CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "", // CreatedUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now, // LastUpdatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator", // LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "", // LastUpdateUserId = UserId ?? "",
}; // };
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; // if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; // if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
data.Profile.Salaries.Add(salary); // data.Profile.Salaries.Add(salary);
// remove profile position // // remove profile position
var profilePosition = await _dbContext.Set<ProfilePosition>() // var profilePosition = await _dbContext.Set<ProfilePosition>()
.Include(x => x.Profile) // .Include(x => x.Profile)
.Include(x => x.OrganizationPosition) // .Include(x => x.OrganizationPosition)
.FirstOrDefaultAsync(x => x.Profile!.Id == data.Id); // .FirstOrDefaultAsync(x => x.Profile!.Id == data.Id);
if (profilePosition != null) // if (profilePosition != null)
_dbContext.Set<ProfilePosition>().Remove(profilePosition); // _dbContext.Set<ProfilePosition>().Remove(profilePosition);
// update placementstatus // // update placementstatus
//data.Status = "DONE"; data.Status = "DONE";
await _dbContext.SaveChangesAsync(); // await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ // // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email // // Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; // var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; // var body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com"); // _emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox // var inbox = new Inbox
{ // {
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", // Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", // Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = data.Id, // ReceiverUserId = data.Id,
Payload = payload_str, // Payload = payload_str,
}; // };
_dbContext.Set<Inbox>().Add(inbox); // _dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification // var noti = new Notification
{ // {
Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", // Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = data.Id, // ReceiverUserId = data.Id,
Type = "LINK", // Type = "LINK",
Payload = payload_str, // Payload = payload_str,
}; // };
_dbContext.Set<Notification>().Add(noti); // _dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync(); // await _dbContext.SaveChangesAsync();
} }
// send cc noti inbox // send cc noti inbox
foreach (var cc in command.Deployments) // foreach (var cc in command.Deployments)
{ // {
var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); // var pf = await _dbContext.Set<Profile>().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId);
if (pf != null) // if (pf != null)
{ // {
if (cc.IsSendInbox) // if (cc.IsSendInbox)
{ // {
var inbox = new Inbox // var inbox = new Inbox
{ // {
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", // Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", // Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = pf.Id, // ReceiverUserId = pf.Id,
Payload = payload_str, // Payload = payload_str,
}; // };
_dbContext.Set<Inbox>().Add(inbox); // _dbContext.Set<Inbox>().Add(inbox);
} // }
if (cc.IsSendMail) // if (cc.IsSendMail)
{ // {
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ // // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email // // Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; // var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}"; // var body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com"); // _emailSenderService.SendMail(subject, body, "dev@frappet.com");
} // }
var noti = new Notification // var noti = new Notification
{ // {
Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", // Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = pf.Id, // ReceiverUserId = pf.Id,
Type = "LINK", // Type = "LINK",
Payload = payload_str, // Payload = payload_str,
}; // };
_dbContext.Set<Notification>().Add(noti); // _dbContext.Set<Notification>().Add(noti);
} // }
} // }
// change command status // change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5); var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);

View file

@ -32,19 +32,13 @@ namespace BMA.EHR.Application.Repositories.Reports
public async Task<dynamic> GetData1Transfer(Guid id) public async Task<dynamic> GetData1Transfer(Guid id)
{ {
var data = await _dbContext.Set<PlacementTransfer>().AsQueryable() var data = await _dbContext.Set<PlacementTransfer>().AsQueryable()
.Include(x => x.Profile)
.Where(x => x.Id == id) .Where(x => x.Id == id)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
var profile = await _dbContext.Set<Profile>().AsQueryable()
.Include(x => x.Prefix)
.Where(x => x.Id == data.Profile.Id).FirstOrDefaultAsync();
var prefix = string.IsNullOrEmpty(profile.Prefix.Name) ? string.Empty : profile.Prefix.Name;
return new return new
{ {
CurrentDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM")).ToThaiFullDate().ToString().ToThaiNumber().Remove(0, 15), CurrentDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM")).ToThaiFullDate().ToString().ToThaiNumber().Remove(0, 15),
Name = $"{prefix}{data.Profile.FirstName} {data.Profile.LastName}", Name = $"{data.prefix}{data.firstName} {data.lastName}",
}; };
} }
#endregion #endregion
@ -53,20 +47,14 @@ namespace BMA.EHR.Application.Repositories.Reports
public async Task<dynamic> GetData2Transfer(Guid id) public async Task<dynamic> GetData2Transfer(Guid id)
{ {
var data = await _dbContext.Set<PlacementTransfer>().AsQueryable() var data = await _dbContext.Set<PlacementTransfer>().AsQueryable()
.Include(x => x.Profile)
.Where(x => x.Id == id) .Where(x => x.Id == id)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
var profile = await _dbContext.Set<Profile>().AsQueryable()
.Include(x => x.Prefix)
.Where(x => x.Id == data.Profile.Id).FirstOrDefaultAsync();
var prefix = string.IsNullOrEmpty(profile.Prefix.Name) ? string.Empty : profile.Prefix.Name;
return new return new
{ {
CurrentDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM")).ToThaiFullDate().ToString().ToThaiNumber().Remove(0, 15), CurrentDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM")).ToThaiFullDate().ToString().ToThaiNumber().Remove(0, 15),
Subject = $"ข้าราชการกรุงเทพมหานครสามัญขอโอน", Subject = $"ข้าราชการกรุงเทพมหานครสามัญขอโอน",
Name = $"{prefix}{data.Profile.FirstName} {data.Profile.LastName}", Name = $"{data.prefix}{data.firstName} {data.lastName}",
}; };
} }
#endregion #endregion
@ -75,20 +63,13 @@ namespace BMA.EHR.Application.Repositories.Reports
public async Task<dynamic> GetData3Transfer(Guid id) public async Task<dynamic> GetData3Transfer(Guid id)
{ {
var data = await _dbContext.Set<PlacementTransfer>().AsQueryable() var data = await _dbContext.Set<PlacementTransfer>().AsQueryable()
.Include(x => x.Profile)
.Where(x => x.Id == id) .Where(x => x.Id == id)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
var profile = await _dbContext.Set<Profile>().AsQueryable()
.Include(x => x.Prefix)
.Where(x => x.Id == data.Profile.Id).FirstOrDefaultAsync();
var prefix = string.IsNullOrEmpty(profile.Prefix.Name) ? string.Empty : profile.Prefix.Name;
return new return new
{ {
CurrentDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM")).ToThaiFullDate().ToString().ToThaiNumber().Remove(0, 15), CurrentDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM")).ToThaiFullDate().ToString().ToThaiNumber().Remove(0, 15),
Subject = $"ข้าราชการขอโอน", Subject = $"ข้าราชการขอโอน",
Name = $"{prefix}{data.Profile.FirstName} {data.Profile.LastName}", Name = $"{data.prefix}{data.firstName} {data.lastName}",
}; };
} }
#endregion #endregion
@ -97,15 +78,9 @@ namespace BMA.EHR.Application.Repositories.Reports
public async Task<dynamic> GetData4Transfer(Guid id) public async Task<dynamic> GetData4Transfer(Guid id)
{ {
var data = await _dbContext.Set<PlacementTransfer>().AsQueryable() var data = await _dbContext.Set<PlacementTransfer>().AsQueryable()
.Include(x => x.Profile)
.Where(x => x.Id == id) .Where(x => x.Id == id)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
var profile = await _dbContext.Set<Profile>().AsQueryable()
.Include(x => x.Prefix)
.Where(x => x.Id == data.Profile.Id).FirstOrDefaultAsync();
var prefix = string.IsNullOrEmpty(profile.Prefix.Name) ? string.Empty : profile.Prefix.Name;
return new return new
{ {
CurrentDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM")).ToThaiFullDate().ToString().ToThaiNumber().Remove(0, 15), CurrentDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM")).ToThaiFullDate().ToString().ToThaiNumber().Remove(0, 15),
@ -113,9 +88,9 @@ namespace BMA.EHR.Application.Repositories.Reports
Subject2 = $"ตรวจสอบหนี้สิน และภาระผูกพันกับกรุงเทพมหานครของข้าราชการ", Subject2 = $"ตรวจสอบหนี้สิน และภาระผูกพันกับกรุงเทพมหานครของข้าราชการ",
Subject3 = $"ตรวจสอบหนี้สินและภาระผูกพันของข้าราชการ", Subject3 = $"ตรวจสอบหนี้สินและภาระผูกพันของข้าราชการ",
Location = $"สำนักงานคณะกรรมการข้าราชการกรุงเทพมหานคร 173 ถนนดินสอ กทม. 10200", Location = $"สำนักงานคณะกรรมการข้าราชการกรุงเทพมหานคร 173 ถนนดินสอ กทม. 10200",
Name = $"{prefix}{data.Profile.FirstName} {data.Profile.LastName}", Name = $"{data.prefix}{data.firstName} {data.lastName}",
Position = $"{data.Profile.Position}", Position = $"{data.position}",
OrganizationOrganization = $"{data.Profile.OrganizationOrganization}", OrganizationOrganization = $"{data.Organization}",
}; };
} }
#endregion #endregion
@ -124,15 +99,9 @@ namespace BMA.EHR.Application.Repositories.Reports
public async Task<dynamic> GetData5Transfer(Guid id) public async Task<dynamic> GetData5Transfer(Guid id)
{ {
var data = await _dbContext.Set<PlacementTransfer>().AsQueryable() var data = await _dbContext.Set<PlacementTransfer>().AsQueryable()
.Include(x => x.Profile)
.Where(x => x.Id == id) .Where(x => x.Id == id)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
var profile = await _dbContext.Set<Profile>().AsQueryable()
.Include(x => x.Prefix)
.Where(x => x.Id == data.Profile.Id).FirstOrDefaultAsync();
var prefix = string.IsNullOrEmpty(profile.Prefix.Name) ? string.Empty : profile.Prefix.Name;
return new return new
{ {
CurrentDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM")).ToThaiFullDate().ToString().ToThaiNumber().Remove(0, 15), CurrentDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM")).ToThaiFullDate().ToString().ToThaiNumber().Remove(0, 15),
@ -140,9 +109,9 @@ namespace BMA.EHR.Application.Repositories.Reports
Subject2 = $"ตรวจสอบพฤติการณ์ทางวินัย และภาระหนี้สิน (เงินกู้สวัสดิการข้าราชการ) ของข้าราชการ", Subject2 = $"ตรวจสอบพฤติการณ์ทางวินัย และภาระหนี้สิน (เงินกู้สวัสดิการข้าราชการ) ของข้าราชการ",
Subject3 = $"ตรวจสอบภาระผูกพันกับกรุงเทพมหานครเกี่ยวกับการลาศึกษา อบรม ของข้าราชการ", Subject3 = $"ตรวจสอบภาระผูกพันกับกรุงเทพมหานครเกี่ยวกับการลาศึกษา อบรม ของข้าราชการ",
Location = $"สำนักงานคณะกรรมการข้าราชการกรุงเทพมหานคร 173 ถนนดินสอ กทม. 10200", Location = $"สำนักงานคณะกรรมการข้าราชการกรุงเทพมหานคร 173 ถนนดินสอ กทม. 10200",
Name = $"{prefix}{data.Profile.FirstName} {data.Profile.LastName}", Name = $"{data.prefix}{data.firstName} {data.lastName}",
Position = $"{data.Profile.Position}", Position = $"{data.position}",
OrganizationOrganization = $"{data.Profile.OrganizationOrganization}", OrganizationOrganization = $"{data.Organization}",
}; };
} }
#endregion #endregion
@ -151,15 +120,9 @@ namespace BMA.EHR.Application.Repositories.Reports
public async Task<dynamic> GetData6Transfer(Guid id) public async Task<dynamic> GetData6Transfer(Guid id)
{ {
var data = await _dbContext.Set<PlacementTransfer>().AsQueryable() var data = await _dbContext.Set<PlacementTransfer>().AsQueryable()
.Include(x => x.Profile)
.Where(x => x.Id == id) .Where(x => x.Id == id)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
var profile = await _dbContext.Set<Profile>().AsQueryable()
.Include(x => x.Prefix)
.Where(x => x.Id == data.Profile.Id).FirstOrDefaultAsync();
var prefix = string.IsNullOrEmpty(profile.Prefix.Name) ? string.Empty : profile.Prefix.Name;
return new return new
{ {
CurrentDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM")).ToThaiFullDate().ToString().ToThaiNumber().Remove(0, 15), CurrentDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM")).ToThaiFullDate().ToString().ToThaiNumber().Remove(0, 15),
@ -169,9 +132,9 @@ namespace BMA.EHR.Application.Repositories.Reports
Subject4 = $"ตรวจสอบหนี้สิน และภาระผูกพันกับกรุงเทพมหานครของข้าราชการ", Subject4 = $"ตรวจสอบหนี้สิน และภาระผูกพันกับกรุงเทพมหานครของข้าราชการ",
Subject5 = $"ตรวจสอบหนี้สินและภาระผูกพันของข้าราชการ", Subject5 = $"ตรวจสอบหนี้สินและภาระผูกพันของข้าราชการ",
Location = $"สำนักงานคณะกรรมการข้าราชการกรุงเทพมหานคร 173 ถนนดินสอ กทม. 10200", Location = $"สำนักงานคณะกรรมการข้าราชการกรุงเทพมหานคร 173 ถนนดินสอ กทม. 10200",
Name = $"{prefix}{data.Profile.FirstName} {data.Profile.LastName}", Name = $"{data.prefix}{data.firstName} {data.lastName}",
Position = $"{data.Profile.Position}", Position = $"{data.position}",
OrganizationOrganization = $"{data.Profile.OrganizationOrganization}", OrganizationOrganization = $"{data.Organization}",
}; };
} }
#endregion #endregion

View file

@ -29,8 +29,8 @@ namespace BMA.EHR.Domain.Models.Placement
public string? OrganizationPositionOld { get; set; } public string? OrganizationPositionOld { get; set; }
[Comment("สังกัดเดิม")] [Comment("สังกัดเดิม")]
public string? OrganizationOld { get; set; } public string? OrganizationOld { get; set; }
[Comment("ตำแหน่งเดิม")] // [Comment("ตำแหน่งเดิม")]
public string? PositionOld { get; set; } // public string? PositionOld { get; set; }
[Comment("ข้อมูลหน่วยงานเดิม ตำแหน่งประเภท")] [Comment("ข้อมูลหน่วยงานเดิม ตำแหน่งประเภท")]
public string? PositionTypeOld { get; set; } public string? PositionTypeOld { get; set; }
[Comment("ข้อมูลหน่วยงานเดิม ระดับ")] [Comment("ข้อมูลหน่วยงานเดิม ระดับ")]

View file

@ -9,14 +9,16 @@ namespace BMA.EHR.Domain.Models.Placement
{ {
public class PlacementTransfer : EntityBase public class PlacementTransfer : EntityBase
{ {
[Required, Comment("Id User")] [Comment("หน่วยงานที่ส่งตัวกลับไป")]
public Profile Profile { get; set; }
[Comment("หน่วยงานที่ขอโอนไป")]
public string? Organization { get; set; } = string.Empty; public string? Organization { get; set; } = string.Empty;
[Comment("เหตุผล")] [Comment("เหตุผล")]
public string? Reason { get; set; } = string.Empty; public string? Reason { get; set; } = string.Empty;
[Comment("สังกัด")] [Comment("สังกัด")]
public string? OrganizationPositionOld { get; set; } public string? OrganizationPositionOld { get; set; }
[Comment("สังกัดเดิม")]
public string? OrganizationOld { get; set; }
[Comment("ตำแหน่งเดิม")]
public string? PositionOld { get; set; }
[Comment("ตั้งแต่วันที่")] [Comment("ตั้งแต่วันที่")]
public DateTime? Date { get; set; } public DateTime? Date { get; set; }
[Comment("ข้อมูลหน่วยงานเดิม ตำแหน่งประเภท")] [Comment("ข้อมูลหน่วยงานเดิม ตำแหน่งประเภท")]
@ -31,6 +33,61 @@ namespace BMA.EHR.Domain.Models.Placement
public string Status { get; set; } = "WAITTING"; public string Status { get; set; } = "WAITTING";
[Comment("สถานะการใช้งาน")] [Comment("สถานะการใช้งาน")]
public bool IsActive { get; set; } = true; public bool IsActive { get; set; } = true;
[Comment("profile Id")]
public string? profileId { get; set; }
[Comment("คำนำหน้า")]
public string? prefix { get; set; }
[Comment("ชื่อ")]
public string? firstName { get; set; }
[Comment("นามสกุล")]
public string? lastName { get; set; }
[Comment("เลขบัตรประชาชน")]
public string? citizenId { get; set; }
[Comment("ชื่อหน่วยงาน root")]
public string? root { get; set; }
[Comment("id หน่วยงาน root")]
public string? rootId { get; set; }
[Comment("ชื่อย่อหน่วยงาน root")]
public string? rootShortName { get; set; }
[Comment("ชื่อหน่วยงาน child1")]
public string? child1 { get; set; }
[Comment("id หน่วยงาน child1")]
public string? child1Id { get; set; }
[Comment("ชื่อย่อหน่วยงาน child1")]
public string? child1ShortName { get; set; }
[Comment("ชื่อหน่วยงาน child2")]
public string? child2 { get; set; }
[Comment("id หน่วยงาน child2")]
public string? child2Id { get; set; }
[Comment("ชื่อย่อหน่วยงาน child2")]
public string? child2ShortName { get; set; }
[Comment("ชื่อหน่วยงาน child3")]
public string? child3 { get; set; }
[Comment("id หน่วยงาน child3")]
public string? child3Id { get; set; }
[Comment("ชื่อย่อหน่วยงาน child3")]
public string? child3ShortName { get; set; }
[Comment("ชื่อหน่วยงาน child4")]
public string? child4 { get; set; }
[Comment("id หน่วยงาน child4")]
public string? child4Id { get; set; }
[Comment("ชื่อย่อหน่วยงาน child4")]
public string? child4ShortName { get; set; }
// [Comment("id revision")]
// public string? orgRevisionId { get; set; }
[Comment("เลขที่ตำแหน่ง")]
public int? posMasterNo { get; set; }
[Comment("ชื่อตำแหน่งในสายงาน")]
public string? position { get; set; }
[Comment("id ประเภทตำแหน่ง")]
public string? posTypeId { get; set; }
[Comment("ชื่อประเภทตำแหน่ง")]
public string? posTypeName { get; set; }
[Comment("id ระดับตำแหน่ง")]
public string? posLevelId { get; set; }
[Comment("ชื่อระดับตำแหน่ง")]
public string? posLevelName { get; set; }
public virtual List<PlacementTransferDoc> PlacementTransferDocs { get; set; } = new List<PlacementTransferDoc>(); public virtual List<PlacementTransferDoc> PlacementTransferDocs { get; set; } = new List<PlacementTransferDoc>();
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,435 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class updatetableplacementtranAddchild : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_PlacementTransfers_Profiles_ProfileId",
table: "PlacementTransfers");
migrationBuilder.DropIndex(
name: "IX_PlacementTransfers_ProfileId",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "PositionOld",
table: "PlacementAppointments");
migrationBuilder.RenameColumn(
name: "ProfileId",
table: "PlacementTransfers",
newName: "profileId");
migrationBuilder.AlterColumn<string>(
name: "profileId",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "profile Id",
oldClrType: typeof(Guid),
oldType: "char(36)")
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("Relational:Collation", "ascii_general_ci");
migrationBuilder.AlterColumn<string>(
name: "Organization",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "หน่วยงานที่ส่งตัวกลับไป",
oldClrType: typeof(string),
oldType: "longtext",
oldNullable: true,
oldComment: "หน่วยงานที่ขอโอนไป")
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "OrganizationOld",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "สังกัดเดิม")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "PositionOld",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "ตำแหน่งเดิม")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child1",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "ชื่อหน่วยงาน child1")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child1Id",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "id หน่วยงาน child1")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child1ShortName",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "ชื่อย่อหน่วยงาน child1")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child2",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "ชื่อหน่วยงาน child2")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child2Id",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "id หน่วยงาน child2")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child2ShortName",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "ชื่อย่อหน่วยงาน child2")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child3",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "ชื่อหน่วยงาน child3")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child3Id",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "id หน่วยงาน child3")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child3ShortName",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "ชื่อย่อหน่วยงาน child3")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child4",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "ชื่อหน่วยงาน child4")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child4Id",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "id หน่วยงาน child4")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "child4ShortName",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "ชื่อย่อหน่วยงาน child4")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "citizenId",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "เลขบัตรประชาชน")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "firstName",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "ชื่อ")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "lastName",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "นามสกุล")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "posLevelId",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "id ระดับตำแหน่ง")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "posLevelName",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "ชื่อระดับตำแหน่ง")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<int>(
name: "posMasterNo",
table: "PlacementTransfers",
type: "int",
nullable: true,
comment: "เลขที่ตำแหน่ง");
migrationBuilder.AddColumn<string>(
name: "posTypeId",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "id ประเภทตำแหน่ง")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "posTypeName",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "ชื่อประเภทตำแหน่ง")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "position",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "ชื่อตำแหน่งในสายงาน")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "prefix",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "คำนำหน้า")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "root",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "ชื่อหน่วยงาน root")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "rootId",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "id หน่วยงาน root")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "rootShortName",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "ชื่อย่อหน่วยงาน root")
.Annotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "OrganizationOld",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "PositionOld",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "child1",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "child1Id",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "child1ShortName",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "child2",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "child2Id",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "child2ShortName",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "child3",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "child3Id",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "child3ShortName",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "child4",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "child4Id",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "child4ShortName",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "citizenId",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "firstName",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "lastName",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "posLevelId",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "posLevelName",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "posMasterNo",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "posTypeId",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "posTypeName",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "position",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "prefix",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "root",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "rootId",
table: "PlacementTransfers");
migrationBuilder.DropColumn(
name: "rootShortName",
table: "PlacementTransfers");
migrationBuilder.RenameColumn(
name: "profileId",
table: "PlacementTransfers",
newName: "ProfileId");
migrationBuilder.AlterColumn<Guid>(
name: "ProfileId",
table: "PlacementTransfers",
type: "char(36)",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
collation: "ascii_general_ci",
oldClrType: typeof(string),
oldType: "longtext",
oldNullable: true,
oldComment: "profile Id")
.OldAnnotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AlterColumn<string>(
name: "Organization",
table: "PlacementTransfers",
type: "longtext",
nullable: true,
comment: "หน่วยงานที่ขอโอนไป",
oldClrType: typeof(string),
oldType: "longtext",
oldNullable: true,
oldComment: "หน่วยงานที่ส่งตัวกลับไป")
.Annotation("MySql:CharSet", "utf8mb4")
.OldAnnotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "PositionOld",
table: "PlacementAppointments",
type: "longtext",
nullable: true,
comment: "ตำแหน่งเดิม")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_PlacementTransfers_ProfileId",
table: "PlacementTransfers",
column: "ProfileId");
migrationBuilder.AddForeignKey(
name: "FK_PlacementTransfers_Profiles_ProfileId",
table: "PlacementTransfers",
column: "ProfileId",
principalTable: "Profiles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View file

@ -11155,10 +11155,6 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("longtext") .HasColumnType("longtext")
.HasComment("ข้อมูลหน่วยงานเดิม เลขที่"); .HasComment("ข้อมูลหน่วยงานเดิม เลขที่");
b.Property<string>("PositionOld")
.HasColumnType("longtext")
.HasComment("ตำแหน่งเดิม");
b.Property<string>("PositionTypeOld") b.Property<string>("PositionTypeOld")
.HasColumnType("longtext") .HasColumnType("longtext")
.HasComment("ข้อมูลหน่วยงานเดิม ตำแหน่งประเภท"); .HasComment("ข้อมูลหน่วยงานเดิม ตำแหน่งประเภท");
@ -13522,7 +13518,11 @@ namespace BMA.EHR.Infrastructure.Migrations
b.Property<string>("Organization") b.Property<string>("Organization")
.HasColumnType("longtext") .HasColumnType("longtext")
.HasComment("หน่วยงานที่ขอโอนไป"); .HasComment("หน่วยงานที่ส่งตัวกลับไป");
b.Property<string>("OrganizationOld")
.HasColumnType("longtext")
.HasComment("สังกัดเดิม");
b.Property<string>("OrganizationPositionOld") b.Property<string>("OrganizationPositionOld")
.HasColumnType("longtext") .HasColumnType("longtext")
@ -13536,13 +13536,14 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("longtext") .HasColumnType("longtext")
.HasComment("ข้อมูลหน่วยงานเดิม เลขที่"); .HasComment("ข้อมูลหน่วยงานเดิม เลขที่");
b.Property<string>("PositionOld")
.HasColumnType("longtext")
.HasComment("ตำแหน่งเดิม");
b.Property<string>("PositionTypeOld") b.Property<string>("PositionTypeOld")
.HasColumnType("longtext") .HasColumnType("longtext")
.HasComment("ข้อมูลหน่วยงานเดิม ตำแหน่งประเภท"); .HasComment("ข้อมูลหน่วยงานเดิม ตำแหน่งประเภท");
b.Property<Guid>("ProfileId")
.HasColumnType("char(36)");
b.Property<string>("Reason") b.Property<string>("Reason")
.HasColumnType("longtext") .HasColumnType("longtext")
.HasComment("เหตุผล"); .HasComment("เหตุผล");
@ -13552,9 +13553,111 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("longtext") .HasColumnType("longtext")
.HasComment("สถานะคำขอ"); .HasComment("สถานะคำขอ");
b.HasKey("Id"); b.Property<string>("child1")
.HasColumnType("longtext")
.HasComment("ชื่อหน่วยงาน child1");
b.HasIndex("ProfileId"); b.Property<string>("child1Id")
.HasColumnType("longtext")
.HasComment("id หน่วยงาน child1");
b.Property<string>("child1ShortName")
.HasColumnType("longtext")
.HasComment("ชื่อย่อหน่วยงาน child1");
b.Property<string>("child2")
.HasColumnType("longtext")
.HasComment("ชื่อหน่วยงาน child2");
b.Property<string>("child2Id")
.HasColumnType("longtext")
.HasComment("id หน่วยงาน child2");
b.Property<string>("child2ShortName")
.HasColumnType("longtext")
.HasComment("ชื่อย่อหน่วยงาน child2");
b.Property<string>("child3")
.HasColumnType("longtext")
.HasComment("ชื่อหน่วยงาน child3");
b.Property<string>("child3Id")
.HasColumnType("longtext")
.HasComment("id หน่วยงาน child3");
b.Property<string>("child3ShortName")
.HasColumnType("longtext")
.HasComment("ชื่อย่อหน่วยงาน child3");
b.Property<string>("child4")
.HasColumnType("longtext")
.HasComment("ชื่อหน่วยงาน child4");
b.Property<string>("child4Id")
.HasColumnType("longtext")
.HasComment("id หน่วยงาน child4");
b.Property<string>("child4ShortName")
.HasColumnType("longtext")
.HasComment("ชื่อย่อหน่วยงาน child4");
b.Property<string>("citizenId")
.HasColumnType("longtext")
.HasComment("เลขบัตรประชาชน");
b.Property<string>("firstName")
.HasColumnType("longtext")
.HasComment("ชื่อ");
b.Property<string>("lastName")
.HasColumnType("longtext")
.HasComment("นามสกุล");
b.Property<string>("posLevelId")
.HasColumnType("longtext")
.HasComment("id ระดับตำแหน่ง");
b.Property<string>("posLevelName")
.HasColumnType("longtext")
.HasComment("ชื่อระดับตำแหน่ง");
b.Property<int?>("posMasterNo")
.HasColumnType("int")
.HasComment("เลขที่ตำแหน่ง");
b.Property<string>("posTypeId")
.HasColumnType("longtext")
.HasComment("id ประเภทตำแหน่ง");
b.Property<string>("posTypeName")
.HasColumnType("longtext")
.HasComment("ชื่อประเภทตำแหน่ง");
b.Property<string>("position")
.HasColumnType("longtext")
.HasComment("ชื่อตำแหน่งในสายงาน");
b.Property<string>("prefix")
.HasColumnType("longtext")
.HasComment("คำนำหน้า");
b.Property<string>("profileId")
.HasColumnType("longtext")
.HasComment("profile Id");
b.Property<string>("root")
.HasColumnType("longtext")
.HasComment("ชื่อหน่วยงาน root");
b.Property<string>("rootId")
.HasColumnType("longtext")
.HasComment("id หน่วยงาน root");
b.Property<string>("rootShortName")
.HasColumnType("longtext")
.HasComment("ชื่อย่อหน่วยงาน root");
b.HasKey("Id");
b.ToTable("PlacementTransfers"); b.ToTable("PlacementTransfers");
}); });
@ -17070,17 +17173,6 @@ namespace BMA.EHR.Infrastructure.Migrations
b.Navigation("PlacementRelocation"); b.Navigation("PlacementRelocation");
}); });
modelBuilder.Entity("BMA.EHR.Domain.Models.Placement.PlacementTransfer", b =>
{
b.HasOne("BMA.EHR.Domain.Models.HR.Profile", "Profile")
.WithMany()
.HasForeignKey("ProfileId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Profile");
});
modelBuilder.Entity("BMA.EHR.Domain.Models.Placement.PlacementTransferDoc", b => modelBuilder.Entity("BMA.EHR.Domain.Models.Placement.PlacementTransferDoc", b =>
{ {
b.HasOne("BMA.EHR.Domain.Models.Documents.Document", "Document") b.HasOne("BMA.EHR.Domain.Models.Documents.Document", "Document")

View file

@ -146,7 +146,7 @@ namespace BMA.EHR.Placement.Service.Controllers
p.AmountOld, p.AmountOld,
p.OrganizationOld, p.OrganizationOld,
p.posmasterId, p.posmasterId,
p.PositionOld, p.positionOld,
p.CreatedAt, p.CreatedAt,
p.typeCommand, p.typeCommand,
}) })
@ -241,7 +241,7 @@ namespace BMA.EHR.Placement.Service.Controllers
p.PositionDate, p.PositionDate,
p.AmountOld, p.AmountOld,
p.OrganizationOld, p.OrganizationOld,
p.PositionOld, p.positionOld,
// PlacementAppointmentDocs = p.PlacementAppointmentDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }), // PlacementAppointmentDocs = p.PlacementAppointmentDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
p.typeCommand, p.typeCommand,
p.posmasterId, p.posmasterId,
@ -336,7 +336,7 @@ namespace BMA.EHR.Placement.Service.Controllers
data.PositionDate, data.PositionDate,
data.AmountOld, data.AmountOld,
data.OrganizationOld, data.OrganizationOld,
data.PositionOld, data.positionOld,
// Docs = placementAppointmentDocs, // Docs = placementAppointmentDocs,
data.typeCommand, data.typeCommand,
data.posmasterId, data.posmasterId,
@ -430,7 +430,7 @@ namespace BMA.EHR.Placement.Service.Controllers
// placementAppointment.EducationOld = profile.Educations.Count() == 0 ? null : $"{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Degree}-{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Field}"; // placementAppointment.EducationOld = profile.Educations.Count() == 0 ? null : $"{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Degree}-{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Field}";
// placementAppointment.AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount; // placementAppointment.AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount;
placementAppointment.PositionOld = org.result.position; placementAppointment.positionOld = org.result.position;
placementAppointment.PositionLevelOld = org.result.posLevelName; placementAppointment.PositionLevelOld = org.result.posLevelName;
placementAppointment.PositionTypeOld = org.result.posTypeName; placementAppointment.PositionTypeOld = org.result.posTypeName;
placementAppointment.PositionNumberOld = org.result.nodeShortName + org.result.posMasterNo; placementAppointment.PositionNumberOld = org.result.nodeShortName + org.result.posMasterNo;

View file

@ -146,7 +146,7 @@ namespace BMA.EHR.Placement.Service.Controllers
p.AmountOld, p.AmountOld,
p.OrganizationOld, p.OrganizationOld,
p.posmasterId, p.posmasterId,
p.PositionOld, p.positionOld,
p.CreatedAt, p.CreatedAt,
p.typeCommand, p.typeCommand,
}) })
@ -239,7 +239,7 @@ namespace BMA.EHR.Placement.Service.Controllers
p.PositionDate, p.PositionDate,
p.AmountOld, p.AmountOld,
p.OrganizationOld, p.OrganizationOld,
p.PositionOld, p.positionOld,
// PlacementAppointmentDocs = p.PlacementAppointmentDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }), // PlacementAppointmentDocs = p.PlacementAppointmentDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
p.typeCommand, p.typeCommand,
}) })
@ -333,7 +333,7 @@ namespace BMA.EHR.Placement.Service.Controllers
data.PositionDate, data.PositionDate,
data.AmountOld, data.AmountOld,
data.OrganizationOld, data.OrganizationOld,
data.PositionOld, data.positionOld,
// Docs = placementAppointmentDocs, // Docs = placementAppointmentDocs,
data.typeCommand, data.typeCommand,
}; };
@ -426,7 +426,7 @@ namespace BMA.EHR.Placement.Service.Controllers
// placementAppointment.EducationOld = profile.Educations.Count() == 0 ? null : $"{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Degree}-{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Field}"; // placementAppointment.EducationOld = profile.Educations.Count() == 0 ? null : $"{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Degree}-{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Field}";
// placementAppointment.AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount; // placementAppointment.AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount;
placementAppointment.PositionOld = org.result.position; placementAppointment.positionOld = org.result.position;
placementAppointment.PositionLevelOld = org.result.posLevelName; placementAppointment.PositionLevelOld = org.result.posLevelName;
placementAppointment.PositionTypeOld = org.result.posTypeName; placementAppointment.PositionTypeOld = org.result.posTypeName;
placementAppointment.PositionNumberOld = org.result.nodeShortName + org.result.posMasterNo; placementAppointment.PositionNumberOld = org.result.nodeShortName + org.result.posMasterNo;

View file

@ -8,7 +8,9 @@ using BMA.EHR.Placement.Service.Requests;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Swashbuckle.AspNetCore.Annotations; using Swashbuckle.AspNetCore.Annotations;
using System.Net.Http.Headers;
using System.Security.Claims; using System.Security.Claims;
namespace BMA.EHR.Placement.Service.Controllers namespace BMA.EHR.Placement.Service.Controllers
@ -26,18 +28,21 @@ namespace BMA.EHR.Placement.Service.Controllers
private readonly ApplicationDBContext _context; private readonly ApplicationDBContext _context;
private readonly MinIOService _documentService; private readonly MinIOService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor; private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IConfiguration _configuration;
public PlacementTransferController(PlacementRepository repository, public PlacementTransferController(PlacementRepository repository,
NotificationRepository repositoryNoti, NotificationRepository repositoryNoti,
ApplicationDBContext context, ApplicationDBContext context,
MinIOService documentService, MinIOService documentService,
IHttpContextAccessor httpContextAccessor) IHttpContextAccessor httpContextAccessor,
IConfiguration configuration)
{ {
_repository = repository; _repository = repository;
_repositoryNoti = repositoryNoti; _repositoryNoti = repositoryNoti;
_context = context; _context = context;
_documentService = documentService; _documentService = documentService;
_httpContextAccessor = httpContextAccessor; _httpContextAccessor = httpContextAccessor;
_configuration = configuration;
} }
#region " Properties " #region " Properties "
@ -45,6 +50,7 @@ namespace BMA.EHR.Placement.Service.Controllers
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private string? token => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1"); private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
@ -61,36 +67,58 @@ namespace BMA.EHR.Placement.Service.Controllers
[HttpGet("user")] [HttpGet("user")]
public async Task<ActionResult<ResponseObject>> GetListByProfile() public async Task<ActionResult<ResponseObject>> GetListByProfile()
{ {
var profile = await _context.Profiles var apiUrl = $"{_configuration["API"]}org/profile/keycloak/position";
.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(UserId)); using (var client = new HttpClient())
if (profile == null) {
return Error(GlobalMessages.DataNotFound, 404); 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 placementTransfers = await _context.PlacementTransfers.AsQueryable() var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
.Where(x => x.Profile == profile)
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : (p.Profile.PositionEmployeePosition == null ? null : p.Profile.PositionEmployeePosition.Name),
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : (p.Profile.PositionEmployeeLevel == null ? null : p.Profile.PositionEmployeeLevel.Name),
// salary = p.Profile.Salaries.Count() == 0 ? null : p.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount,
p.CreatedAt,
p.Organization,
p.Reason,
p.Status,
p.Date,
salary = p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.IsActive,
})
.ToListAsync();
return Success(placementTransfers); if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
var placementTransfers = await _context.PlacementTransfers.AsQueryable()
.Where(x => x.profileId == org.result.profileId)
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
p.profileId,
p.prefix,
p.firstName,
p.lastName,
p.root,
p.rootShortName,
p.child1,
p.child1ShortName,
p.child2,
p.child2ShortName,
p.child3,
p.child3ShortName,
p.child4,
p.child4ShortName,
p.posMasterNo,
p.position,
p.posLevelName,
p.posTypeName,
p.CreatedAt,
p.Organization,
p.Reason,
p.Status,
p.Date,
salary = p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.IsActive,
})
.ToListAsync();
return Success(placementTransfers);
}
} }
/// <summary> /// <summary>
@ -104,36 +132,69 @@ namespace BMA.EHR.Placement.Service.Controllers
[HttpGet()] [HttpGet()]
public async Task<ActionResult<ResponseObject>> GetListByAdmin() public async Task<ActionResult<ResponseObject>> GetListByAdmin()
{ {
var rootId = "";
var child1Id = "";
var child2Id = "";
var child3Id = "";
var child4Id = "";
var apiUrl = $"{_configuration["API"]}org/profile/keycloak/position";
using (var client = new HttpClient())
{
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 placementTransfers = await _context.PlacementTransfers.AsQueryable() var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
p.Profile.FirstName,
p.Profile.LastName,
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : (p.Profile.PositionEmployeePosition == null ? null : p.Profile.PositionEmployeePosition.Name),
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee,
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : (p.Profile.PositionEmployeeLevel == null ? null : p.Profile.PositionEmployeeLevel.Name),
// salary = p.Profile.Salaries.Count() == 0 ? null : p.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount,
p.CreatedAt,
p.Organization,
p.Reason,
p.Status,
p.Date,
salary = p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.IsActive,
})
.ToListAsync();
if (PlacementAdmin == true)
placementTransfers = placementTransfers.Where(x => !x.Status.Trim().ToUpper().Contains("WAITTING")).ToList();
return Success(placementTransfers); if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
rootId = org.result.rootId == null ? "" : org.result.rootId;
child1Id = org.result.child1Id == null ? "" : org.result.child1Id;
child2Id = org.result.child2Id == null ? "" : org.result.child2Id;
child3Id = org.result.child3Id == null ? "" : org.result.child3Id;
child4Id = org.result.child4Id == null ? "" : org.result.child4Id;
var placementTransfers = await _context.PlacementTransfers.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Where(x => PlacementAdmin == true ? true : (rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))))
.Select(p => new
{
p.Id,
p.profileId,
p.prefix,
p.firstName,
p.lastName,
p.root,
p.rootShortName,
p.child1,
p.child1ShortName,
p.child2,
p.child2ShortName,
p.child3,
p.child3ShortName,
p.child4,
p.child4ShortName,
p.posMasterNo,
p.position,
p.posLevelName,
p.posTypeName,
p.CreatedAt,
p.Organization,
p.Reason,
p.Status,
p.Date,
salary = p.AmountOld,
p.PositionTypeOld,
p.PositionLevelOld,
p.PositionNumberOld,
p.OrganizationPositionOld,
p.IsActive,
})
.ToListAsync();
return Success(placementTransfers);
}
} }
/// <summary> /// <summary>
@ -150,19 +211,27 @@ namespace BMA.EHR.Placement.Service.Controllers
{ {
var data = await _context.PlacementTransfers.AsQueryable() var data = await _context.PlacementTransfers.AsQueryable()
.Where(x => x.Id == id) .Where(x => x.Id == id)
.Where(x => x.Profile != null)
.Select(p => new .Select(p => new
{ {
p.Id, p.Id,
PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id, p.profileId,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name, p.prefix,
p.Profile.FirstName, p.firstName,
p.Profile.LastName, p.lastName,
ProfileId = p.Profile.Id, p.root,
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : (p.Profile.PositionEmployeePosition == null ? null : p.Profile.PositionEmployeePosition.Name), p.rootShortName,
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee, p.child1,
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : (p.Profile.PositionEmployeeLevel == null ? null : p.Profile.PositionEmployeeLevel.Name), p.child1ShortName,
organizationOrganization = p.Profile.OrganizationOrganization, p.child2,
p.child2ShortName,
p.child3,
p.child3ShortName,
p.child4,
p.child4ShortName,
p.posMasterNo,
p.position,
p.posLevelName,
p.posTypeName,
p.Reason, p.Reason,
p.Status, p.Status,
p.Organization, p.Organization,
@ -173,7 +242,7 @@ namespace BMA.EHR.Placement.Service.Controllers
p.PositionLevelOld, p.PositionLevelOld,
p.PositionNumberOld, p.PositionNumberOld,
p.OrganizationPositionOld, p.OrganizationPositionOld,
Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id, p.PositionOld,
PlacementTransferDocs = p.PlacementTransferDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }), PlacementTransferDocs = p.PlacementTransferDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
}) })
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
@ -193,26 +262,35 @@ namespace BMA.EHR.Placement.Service.Controllers
var _data = new var _data = new
{ {
data.Id, data.Id,
data.ProfileId, data.profileId,
data.PrefixId, data.prefix,
data.Prefix, data.firstName,
data.FirstName, data.lastName,
data.LastName, data.root,
data.rootShortName,
data.child1,
data.child1ShortName,
data.child2,
data.child2ShortName,
data.child3,
data.child3ShortName,
data.child4,
data.child4ShortName,
data.posMasterNo,
data.position, data.position,
data.posNo, data.posLevelName,
data.positionLevel, data.posTypeName,
data.organizationOrganization,
data.Reason, data.Reason,
data.Status, data.Status,
data.Organization, data.Organization,
data.CreatedAt,
data.Date, data.Date,
data.salary, data.salary,
data.CreatedAt,
data.PositionTypeOld, data.PositionTypeOld,
data.PositionLevelOld, data.PositionLevelOld,
data.PositionNumberOld, data.PositionNumberOld,
data.OrganizationPositionOld, data.OrganizationPositionOld,
Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar), data.PositionOld,
Docs = placementTransferDocs, Docs = placementTransferDocs,
}; };
@ -233,20 +311,27 @@ namespace BMA.EHR.Placement.Service.Controllers
{ {
var data = await _context.PlacementTransfers.AsQueryable() var data = await _context.PlacementTransfers.AsQueryable()
.Where(x => x.Id == id) .Where(x => x.Id == id)
.Where(x => x.Profile != null)
.Select(p => new .Select(p => new
{ {
p.Id, p.Id,
PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id, p.profileId,
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name, p.prefix,
AvatarId = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id, p.firstName,
p.Profile.FirstName, p.lastName,
p.Profile.LastName, p.root,
ProfileId = p.Profile.Id, p.rootShortName,
position = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.Position == null ? null : p.Profile.Position.Name) : (p.Profile.PositionEmployeePosition == null ? null : p.Profile.PositionEmployeePosition.Name), p.child1,
posNo = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PosNo == null ? null : p.Profile.PosNo.Name) : p.Profile.PosNoEmployee, p.child1ShortName,
positionLevel = p.Profile.ProfileType.Trim().ToUpper().Contains("OFFICER") ? (p.Profile.PositionLevel == null ? null : p.Profile.PositionLevel.Name) : (p.Profile.PositionEmployeeLevel == null ? null : p.Profile.PositionEmployeeLevel.Name), p.child2,
organizationOrganization = p.Profile.OrganizationOrganization, p.child2ShortName,
p.child3,
p.child3ShortName,
p.child4,
p.child4ShortName,
p.posMasterNo,
p.position,
p.posLevelName,
p.posTypeName,
p.Reason, p.Reason,
p.Status, p.Status,
p.Organization, p.Organization,
@ -257,6 +342,7 @@ namespace BMA.EHR.Placement.Service.Controllers
p.PositionLevelOld, p.PositionLevelOld,
p.PositionNumberOld, p.PositionNumberOld,
p.OrganizationPositionOld, p.OrganizationPositionOld,
p.PositionOld,
PlacementTransferDocs = p.PlacementTransferDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }), PlacementTransferDocs = p.PlacementTransferDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
}) })
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
@ -276,26 +362,35 @@ namespace BMA.EHR.Placement.Service.Controllers
var _data = new var _data = new
{ {
data.Id, data.Id,
data.ProfileId, data.profileId,
AvataPath = data.AvatarId == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.AvatarId), data.prefix,
data.PrefixId, data.firstName,
data.Prefix, data.lastName,
data.FirstName, data.root,
data.LastName, data.rootShortName,
data.child1,
data.child1ShortName,
data.child2,
data.child2ShortName,
data.child3,
data.child3ShortName,
data.child4,
data.child4ShortName,
data.posMasterNo,
data.position, data.position,
data.posNo, data.posLevelName,
data.positionLevel, data.posTypeName,
data.organizationOrganization,
data.Reason, data.Reason,
data.Status, data.Status,
data.Organization, data.Organization,
data.CreatedAt,
data.Date, data.Date,
data.salary, data.salary,
data.CreatedAt,
data.PositionTypeOld, data.PositionTypeOld,
data.PositionLevelOld, data.PositionLevelOld,
data.PositionNumberOld, data.PositionNumberOld,
data.OrganizationPositionOld, data.OrganizationPositionOld,
data.PositionOld,
Docs = placementTransferDocs, Docs = placementTransferDocs,
}; };
@ -313,28 +408,10 @@ namespace BMA.EHR.Placement.Service.Controllers
[HttpPost()] [HttpPost()]
public async Task<ActionResult<ResponseObject>> Post([FromForm] PlacementTransferRequest req) public async Task<ActionResult<ResponseObject>> Post([FromForm] PlacementTransferRequest req)
{ {
var profile = await _context.Profiles
.Include(x => x.PositionLevel)
.Include(x => x.PositionType)
.Include(x => x.PosNo)
.Include(x => x.Salaries)
.Include(x => x.Position)
.Include(x => x.Prefix)
.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(UserId));
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
var placementTransfer = new PlacementTransfer var placementTransfer = new PlacementTransfer
{ {
Profile = profile,
Organization = req.Organization, Organization = req.Organization,
Reason = req.Reason, Reason = req.Reason,
Date = req.Date,
AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount,
PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
Status = "WAITTING", Status = "WAITTING",
CreatedFullName = FullName ?? "System Administrator", CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "", CreatedUserId = UserId ?? "",
@ -343,6 +420,57 @@ namespace BMA.EHR.Placement.Service.Controllers
LastUpdateUserId = UserId ?? "", LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now, LastUpdatedAt = DateTime.Now,
}; };
var apiUrl = $"{_configuration["API"]}org/profile/keycloak/position";
using (var client = new HttpClient())
{
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);
placementTransfer.profileId = org.result.profileId;
placementTransfer.prefix = org.result.prefix;
placementTransfer.firstName = org.result.firstName;
placementTransfer.lastName = org.result.lastName;
placementTransfer.citizenId = org.result.citizenId;
placementTransfer.root = org.result.root;
placementTransfer.rootId = org.result.rootId;
placementTransfer.rootShortName = org.result.rootShortName;
placementTransfer.child1 = org.result.child1;
placementTransfer.child1Id = org.result.child1Id;
placementTransfer.child1ShortName = org.result.child1ShortName;
placementTransfer.child2 = org.result.child2;
placementTransfer.child2Id = org.result.child2Id;
placementTransfer.child2ShortName = org.result.child2ShortName;
placementTransfer.child3 = org.result.child3;
placementTransfer.child3Id = org.result.child3Id;
placementTransfer.child3ShortName = org.result.child3ShortName;
placementTransfer.child4 = org.result.child4;
placementTransfer.child4Id = org.result.child4Id;
placementTransfer.child4ShortName = org.result.child4ShortName;
placementTransfer.posMasterNo = org.result.posMasterNo;
placementTransfer.position = org.result.position;
placementTransfer.posTypeId = org.result.posTypeId;
placementTransfer.posTypeName = org.result.posTypeName;
placementTransfer.posLevelId = org.result.posLevelId;
placementTransfer.posLevelName = org.result.posLevelName;
placementTransfer.PositionOld = org.result.position;
placementTransfer.PositionLevelOld = org.result.posLevelName;
placementTransfer.PositionTypeOld = org.result.posTypeName;
placementTransfer.PositionNumberOld = org.result.nodeShortName + org.result.posMasterNo;
placementTransfer.OrganizationOld = (org.result.child4 == null ? "" : org.result.child4 + "/") +
(org.result.child3 == null ? "" : org.result.child3 + "/") +
(org.result.child2 == null ? "" : org.result.child2 + "/") +
(org.result.child1 == null ? "" : org.result.child1 + "/") +
(org.result.root == null ? "" : org.result.root + "/");
placementTransfer.OrganizationPositionOld = org.result.position + "-" + placementTransfer.OrganizationOld;
}
await _context.PlacementTransfers.AddAsync(placementTransfer); await _context.PlacementTransfers.AddAsync(placementTransfer);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
if (Request.Form.Files != null && Request.Form.Files.Count != 0) if (Request.Form.Files != null && Request.Form.Files.Count != 0)
@ -372,13 +500,13 @@ namespace BMA.EHR.Placement.Service.Controllers
} }
} }
} }
await _repositoryNoti.PushNotificationAsync( // await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dbc953-6268-4e2c-80a3-aca65eedc6d0"), // Guid.Parse("08dbc953-6268-4e2c-80a3-aca65eedc6d0"),
$"{profile.Prefix?.Name}{profile.FirstName} {profile.LastName} ได้ทำการยื่นคำขอโอน", // $"{profile.Prefix?.Name}{profile.FirstName} {profile.LastName} ได้ทำการยื่นคำขอโอน",
$"{profile.Prefix?.Name}{profile.FirstName} {profile.LastName} ได้ทำการยื่นคำขอโอนไปยัง {req.Organization}", // $"{profile.Prefix?.Name}{profile.FirstName} {profile.LastName} ได้ทำการยื่นคำขอโอนไปยัง {req.Organization}",
"", // "",
true // true
); // );
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return Success(); return Success();
@ -429,8 +557,6 @@ namespace BMA.EHR.Placement.Service.Controllers
public async Task<ActionResult<ResponseObject>> AdminConfirm(Guid id) public async Task<ActionResult<ResponseObject>> AdminConfirm(Guid id)
{ {
var uppdated = await _context.PlacementTransfers var uppdated = await _context.PlacementTransfers
.Include(x => x.Profile)
.ThenInclude(x => x.Prefix)
.FirstOrDefaultAsync(x => x.Id == id); .FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null) if (uppdated == null)
return Error(GlobalMessages.PlacementTransferNotFound, 404); return Error(GlobalMessages.PlacementTransferNotFound, 404);
@ -439,20 +565,20 @@ namespace BMA.EHR.Placement.Service.Controllers
uppdated.LastUpdateFullName = FullName ?? "System Administrator"; uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? ""; uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now; uppdated.LastUpdatedAt = DateTime.Now;
await _repositoryNoti.PushNotificationAsync( // await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dbc953-6268-4e2c-80a3-aca65eedc6d0"), // Guid.Parse("08dbc953-6268-4e2c-80a3-aca65eedc6d0"),
$"{uppdated.Profile.Prefix?.Name}{uppdated.Profile.FirstName} {uppdated.Profile.LastName} ได้ทำการยื่นคำขอโอนได้รับการอนุมัติ", // $"{uppdated.Profile.Prefix?.Name}{uppdated.Profile.FirstName} {uppdated.Profile.LastName} ได้ทำการยื่นคำขอโอนได้รับการอนุมัติ",
$"{uppdated.Profile.Prefix?.Name}{uppdated.Profile.FirstName} {uppdated.Profile.LastName} ได้ทำการยื่นคำขอโอนไปยัง {uppdated.Organization}ได้รับการอนุมัติ", // $"{uppdated.Profile.Prefix?.Name}{uppdated.Profile.FirstName} {uppdated.Profile.LastName} ได้ทำการยื่นคำขอโอนไปยัง {uppdated.Organization}ได้รับการอนุมัติ",
"", // "",
true // true
); // );
await _repositoryNoti.PushNotificationAsync( // await _repositoryNoti.PushNotificationAsync(
Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6"), // Guid.Parse("08dbca3a-8b6a-4a4e-8b23-1f62e4f30ef6"),
$"{uppdated.Profile.Prefix?.Name}{uppdated.Profile.FirstName} {uppdated.Profile.LastName} ได้ทำการยื่นคำขอโอน", // $"{uppdated.Profile.Prefix?.Name}{uppdated.Profile.FirstName} {uppdated.Profile.LastName} ได้ทำการยื่นคำขอโอน",
$"{uppdated.Profile.Prefix?.Name}{uppdated.Profile.FirstName} {uppdated.Profile.LastName} ได้ทำการยื่นคำขอโอนไปยัง {uppdated.Organization}ได้รับการอนุมัติ", // $"{uppdated.Profile.Prefix?.Name}{uppdated.Profile.FirstName} {uppdated.Profile.LastName} ได้ทำการยื่นคำขอโอนไปยัง {uppdated.Organization}ได้รับการอนุมัติ",
"", // "",
true // true
); // );
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return Success(); return Success();