api หนังสือเวียน
This commit is contained in:
parent
c54f3709ef
commit
6ab37f3ace
13 changed files with 32708 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ using BMA.EHR.Domain.Common;
|
|||
using BMA.EHR.Domain.Extensions;
|
||||
using BMA.EHR.Domain.Models.HR;
|
||||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using BMA.EHR.Domain.Models.Notifications;
|
||||
using BMA.EHR.Domain.Models.Retirement;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
|
|
@ -11,6 +12,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Security.Claims;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
|
|
@ -237,13 +239,14 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
};
|
||||
await _context.RetirementDeceaseds.AddAsync(retirementDeceased);
|
||||
await _context.SaveChangesAsync();
|
||||
var _doc = new Domain.Models.Documents.Document();
|
||||
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
|
||||
{
|
||||
var file = Request.Form.Files[0];
|
||||
var fileExtension = Path.GetExtension(file.FileName);
|
||||
|
||||
var doc = await _documentService.UploadFileAsync(file, file.FileName);
|
||||
var _doc = await _context.Documents.AsQueryable()
|
||||
_doc = await _context.Documents.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == doc.Id);
|
||||
if (_doc != null)
|
||||
retirementDeceased.Document = _doc;
|
||||
|
|
@ -256,6 +259,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
SalaryClass = "-",
|
||||
PosNoEmployee = "-",
|
||||
CommandTypeName = "-",
|
||||
SalaryStatus = "DEATH",
|
||||
Profile = profile,
|
||||
CreatedUserId = FullName ?? "",
|
||||
CreatedFullName = UserId ?? "System Administrator",
|
||||
|
|
@ -264,6 +268,22 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
if (_doc != null)
|
||||
{
|
||||
await _context.ProfilePapers.AddAsync(new ProfilePaper
|
||||
{
|
||||
Detail = "ถึงแก่กรรม",
|
||||
CategoryName = "DEATH",
|
||||
Document = _doc,
|
||||
Profile = profile,
|
||||
CreatedUserId = FullName ?? "",
|
||||
CreatedFullName = UserId ?? "System Administrator",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
|
|
@ -336,5 +356,189 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List รายชื่อส่งหนังสือเวียน
|
||||
/// </summary>
|
||||
/// <param name="id">Id การถึงแก่กรรม</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("detail/{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetDetail(Guid id)
|
||||
{
|
||||
var data = await _context.RetirementDeceasedNotis.AsQueryable()
|
||||
.Where(x => x.RetirementDeceased.Id == id)
|
||||
.Select(p => new
|
||||
{
|
||||
p.Id,
|
||||
p.CitizenId,
|
||||
p.Prefix,
|
||||
p.FirstName,
|
||||
p.LastName,
|
||||
p.IsSendMail,
|
||||
p.IsSendInbox,
|
||||
p.IsSendNotification,
|
||||
p.OrganizationName,
|
||||
p.PositionName,
|
||||
ProfileId = p.ReceiveUser.Id,
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// เพิ่มรายชื่อส่งหนังสือเวียน
|
||||
/// </summary>
|
||||
/// <param name="id">Id การถึงแก่กรรม</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("detail/{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> UpdateDetail([FromForm] RetirementDeceasedAddNotiRequest req, Guid id)
|
||||
{
|
||||
var retirementDeceased = await _context.RetirementDeceaseds.AsQueryable()
|
||||
.Include(x => x.RetirementDeceasedNotis)
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (retirementDeceased == null)
|
||||
return Error(GlobalMessages.RetirementDeceasedNotFound, 404);
|
||||
|
||||
var profile = await _context.Profiles.AsQueryable()
|
||||
.Include(x => x.Prefix)
|
||||
.Include(x => x.Position)
|
||||
.FirstOrDefaultAsync(x => x.Id == req.ProfileId);
|
||||
if (profile == null)
|
||||
return Error(GlobalMessages.DataNotFound, 404);
|
||||
|
||||
retirementDeceased.RetirementDeceasedNotis.Add(new RetirementDeceasedNoti
|
||||
{
|
||||
CitizenId = profile.CitizenId == null ? "" : profile.CitizenId,
|
||||
Prefix = profile.Prefix == null ? "" : profile.Prefix.Name,
|
||||
FirstName = profile.FirstName == null ? "" : profile.FirstName,
|
||||
LastName = profile.LastName == null ? "" : profile.LastName,
|
||||
// IsSendMail = req.IsSendMail,
|
||||
// IsSendInbox = req.IsSendInbox,
|
||||
// IsSendNotification = req.IsSendNotification,
|
||||
OrganizationName = profile.OrganizationOrganization == null ? "" : profile.OrganizationOrganization,
|
||||
PositionName = profile.Position == null ? null : profile.Position.Name,
|
||||
ReceiveUser = profile,
|
||||
CreatedUserId = FullName ?? "",
|
||||
CreatedFullName = UserId ?? "System Administrator",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ลบรายชื่อส่งหนังสือเวียน
|
||||
/// </summary>
|
||||
/// <param name="id">Id การถึงแก่กรรม</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpDelete("detail/{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> DeleteDetail(Guid id)
|
||||
{
|
||||
var retirementDeceasedNoti = await _context.RetirementDeceasedNotis.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (retirementDeceasedNoti == null)
|
||||
return Error(GlobalMessages.RetirementDeceasedNotiNotFound, 404);
|
||||
_context.RetirementDeceasedNotis.Remove(retirementDeceasedNoti);
|
||||
await _context.SaveChangesAsync();
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Noti ส่งหนังสือเวียน
|
||||
/// </summary>
|
||||
/// <param name="id">Id การถึงแก่กรรม</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("noti/{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> NotiDeceased([FromForm] RetirementDeceasedAddNotiPersonRequest req, Guid id)
|
||||
{
|
||||
var items = await _context.RetirementDeceasedNotis.AsQueryable()
|
||||
.Include(x => x.ReceiveUser)
|
||||
.Include(x => x.RetirementDeceased)
|
||||
.ThenInclude(x => x.Profile)
|
||||
.ThenInclude(x => x.Prefix)
|
||||
.Where(x => x.RetirementDeceased.Id == id)
|
||||
.ToListAsync();
|
||||
foreach (var item in items)
|
||||
{
|
||||
var prefix = item.RetirementDeceased.Profile.Prefix == null ? "" : item.RetirementDeceased.Profile.Prefix.Name;
|
||||
var profile = req.Person.FirstOrDefault(x => x.ProfileId == item.ReceiveUser.Id);
|
||||
if (profile != null)
|
||||
{
|
||||
if (profile.IsSendInbox == true)
|
||||
{
|
||||
var inbox = new Inbox
|
||||
{
|
||||
Subject = $"หนังสือเวียนถึงแก่กรรมของ {prefix}{item.RetirementDeceased.Profile.FirstName} {item.RetirementDeceased.Profile.LastName}",
|
||||
Body = $"แจ้งข่าวการถึงแก่กรรมของ {prefix}{item.RetirementDeceased.Profile.FirstName} {item.RetirementDeceased.Profile.LastName}",
|
||||
ReceiverUserId = item.ReceiveUser.Id,
|
||||
Payload = "",
|
||||
};
|
||||
_context.Inboxes.Add(inbox);
|
||||
}
|
||||
if (profile.IsSendNotification == true)
|
||||
{
|
||||
var noti = new Notification
|
||||
{
|
||||
Body = $"แจ้งข่าวการถึงแก่กรรมของ {prefix}{item.RetirementDeceased.Profile.FirstName} {item.RetirementDeceased.Profile.LastName}",
|
||||
ReceiverUserId = item.ReceiveUser.Id,
|
||||
Type = "",
|
||||
Payload = "",
|
||||
};
|
||||
_context.Notifications.Add(noti);
|
||||
}
|
||||
item.IsSendInbox = profile.IsSendInbox;
|
||||
item.IsSendNotification = profile.IsSendNotification;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.IsSendInbox == true)
|
||||
{
|
||||
var inbox = new Inbox
|
||||
{
|
||||
Subject = $"หนังสือเวียนถึงแก่กรรมของ {prefix}{item.RetirementDeceased.Profile.FirstName} {item.RetirementDeceased.Profile.LastName}",
|
||||
Body = $"แจ้งข่าวการถึงแก่กรรมของ {prefix}{item.RetirementDeceased.Profile.FirstName} {item.RetirementDeceased.Profile.LastName}",
|
||||
ReceiverUserId = item.ReceiveUser.Id,
|
||||
Payload = "",
|
||||
};
|
||||
_context.Inboxes.Add(inbox);
|
||||
}
|
||||
if (item.IsSendNotification == true)
|
||||
{
|
||||
var noti = new Notification
|
||||
{
|
||||
Body = $"แจ้งข่าวการถึงแก่กรรมของ {prefix}{item.RetirementDeceased.Profile.FirstName} {item.RetirementDeceased.Profile.LastName}",
|
||||
ReceiverUserId = item.ReceiveUser.Id,
|
||||
Type = "",
|
||||
Payload = "",
|
||||
};
|
||||
_context.Notifications.Add(noti);
|
||||
}
|
||||
}
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue