แก้บั้กออกคำสั่ง + ใส่ Payload ใน inbox + noti
This commit is contained in:
parent
e451149b2f
commit
356fcba76a
9 changed files with 785 additions and 222 deletions
|
|
@ -10,8 +10,11 @@ using BMA.EHR.Domain.Extensions;
|
|||
using BMA.EHR.Domain.Models.Commands.Core;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.pdf;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Security.Claims;
|
||||
|
|
@ -38,6 +41,12 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
private readonly CommandStatusRepository _commandStatusRepository;
|
||||
private readonly UserProfileRepository _userProfileRepository;
|
||||
private readonly EmailSenderService _emailSenderService;
|
||||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
private readonly MinIOService _minIOService;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
// for add watermark
|
||||
private BaseFont baseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -52,7 +61,10 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
CommandTypeRepository commandTypeRepository,
|
||||
CommandStatusRepository commandStatusRepository,
|
||||
UserProfileRepository userProfileRepository,
|
||||
EmailSenderService emailSenderService)
|
||||
EmailSenderService emailSenderService,
|
||||
IWebHostEnvironment hostingEnvironment,
|
||||
MinIOService minIOService,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
_repository = repository;
|
||||
_context = context;
|
||||
|
|
@ -64,6 +76,9 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
_commandStatusRepository = commandStatusRepository;
|
||||
_userProfileRepository = userProfileRepository;
|
||||
_emailSenderService = emailSenderService;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_minIOService = minIOService;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -91,21 +106,58 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
|
||||
#region " Methods "
|
||||
|
||||
//[HttpGet("mail")]
|
||||
//[AllowAnonymous]
|
||||
//public IActionResult TestSendMail()
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// _emailSenderService.SendMail("test send mail", "test body", "suphonchai@frappet.com");
|
||||
#region " Add Watermark "
|
||||
|
||||
// return Ok();
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// throw;
|
||||
// }
|
||||
//}
|
||||
private void AddWaterMarkText(PdfContentByte pdfData, string watermarkText, BaseFont font, float fontSize, float angle, BaseColor color, Rectangle realPageSize)
|
||||
{
|
||||
var gstate = new PdfGState { FillOpacity = 0.5f, StrokeOpacity = 0.3f };
|
||||
pdfData.SaveState();
|
||||
pdfData.SetGState(gstate);
|
||||
pdfData.SetColorFill(color);
|
||||
pdfData.BeginText();
|
||||
pdfData.SetFontAndSize(font, fontSize);
|
||||
var x = (realPageSize.Right + realPageSize.Left) / 2;
|
||||
var y = (realPageSize.Bottom + realPageSize.Top) / 2;
|
||||
pdfData.ShowTextAligned(Element.ALIGN_CENTER, watermarkText, x, y, angle);
|
||||
pdfData.EndText();
|
||||
pdfData.RestoreState();
|
||||
}
|
||||
|
||||
private bool AddWatermark(string inputfilepath, string outputfilepath, string watermark_text)
|
||||
{
|
||||
PdfReader pdfReader = null;
|
||||
PdfStamper pdfStamper = null;
|
||||
try
|
||||
{
|
||||
|
||||
pdfReader = new PdfReader(inputfilepath);
|
||||
int numberOfPages = pdfReader.NumberOfPages;
|
||||
iTextSharp.text.Rectangle pagesize = pdfReader.GetPageSize(1);
|
||||
pdfStamper = new PdfStamper(pdfReader, new FileStream(outputfilepath, FileMode.Create));
|
||||
|
||||
for (int i = 1; i <= numberOfPages; i++)
|
||||
{
|
||||
var dc = pdfStamper.GetOverContent(i);
|
||||
AddWaterMarkText(dc, watermark_text, baseFont, 30, 45, BaseColor.DARK_GRAY, pdfReader.GetPageSizeWithRotation(i));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.Message.Trim();
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (pdfStamper != null)
|
||||
pdfStamper.Close();
|
||||
|
||||
if (pdfReader != null)
|
||||
pdfReader.Close();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// แสดงปีเป็นปีพุทธศักราช โดยดึงจากข้อมูลที่มีในระบบ
|
||||
|
|
@ -2602,7 +2654,7 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
try
|
||||
{
|
||||
var rawData = commandCode.Trim().ToUpper() == "C-PM-01" ? await _placementRepository.GetCompetitivePlacementAsync() :
|
||||
commandCode.Trim().ToUpper() == "C-PM-02" ? await _placementRepository.GetQualifyingPlacementAsync() :
|
||||
commandCode.Trim().ToUpper() == "C-PM-02" ? await _placementRepository.GetQualifyingPlacementAsync() :
|
||||
await _placementRepository.GetAllPlacementAsync();
|
||||
|
||||
|
||||
|
|
@ -3027,6 +3079,96 @@ namespace BMA.EHR.Command.Service.Controllers
|
|||
|
||||
#region " Documents "
|
||||
|
||||
/// <summary>
|
||||
/// Download เอกสารแนบ
|
||||
/// </summary>
|
||||
/// <param name="docId">Record Id ของเอกสารแนบ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("download/attachment/{docId}")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> DownloadAttachment(Guid docId)
|
||||
{
|
||||
var now = DateTime.Now.ToString("yyyyMMdd-HHmmss");
|
||||
var file = Path.Combine(_hostingEnvironment.ContentRootPath, "tmp", $"tmp-{now}.pdf");
|
||||
var file_copy = Path.Combine(_hostingEnvironment.ContentRootPath, "tmp", $"tmp-{now}-copy.pdf");
|
||||
|
||||
try
|
||||
{
|
||||
var doc = await _minIOService.DownloadFileAsync(docId);
|
||||
|
||||
// Copy to File
|
||||
System.IO.File.WriteAllBytes(file, doc.FileContent);
|
||||
var watermark_text = "COPY COPY COPY COPY";
|
||||
var fName = Path.GetFileName(file);
|
||||
|
||||
AddWatermark(file, file_copy, watermark_text);
|
||||
|
||||
using (var fileStream = new System.IO.FileStream(file_copy, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
fileStream.CopyTo(ms);
|
||||
ms.Flush();
|
||||
return File(ms.ToArray(), "application/octet-stream", fName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (System.IO.File.Exists(file))
|
||||
System.IO.File.Delete(file);
|
||||
|
||||
if (System.IO.File.Exists(file_copy))
|
||||
System.IO.File.Delete(file_copy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("gen-payload/{orderId}")]
|
||||
[AllowAnonymous]
|
||||
public async Task<ActionResult<ResponseObject>> GetPayloadStr(Guid orderId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var command = await _repository.GetByIdAsync(orderId);
|
||||
if (command == null)
|
||||
throw new Exception(GlobalMessages.CommandNotFound);
|
||||
|
||||
// create command payload
|
||||
var payload_attach = command.Documents
|
||||
.Select(x => new PayloadAttachment
|
||||
{
|
||||
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
|
||||
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
|
||||
})
|
||||
.ToList();
|
||||
|
||||
var payload = new CommandPayload()
|
||||
{
|
||||
attachments = payload_attach
|
||||
};
|
||||
|
||||
var payload_str = JsonConvert.SerializeObject(payload);
|
||||
|
||||
return Success(payload_str);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// PM7-34 : ข้อมูลรายละเอียดคำสั่งและแนบท้าย
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue