Receive and Deploy Command

This commit is contained in:
Suphonchai Phoonsawat 2023-07-28 15:04:26 +07:00
parent 297b1efb57
commit 4e8b7ea32b
24 changed files with 49003 additions and 87 deletions

View file

@ -13,7 +13,7 @@ namespace BMA.EHR.Application
services.AddTransient<PlacementRepository>();
services.AddTransient<OrganizationEmployeeRepository>();
services.AddTransient<MessageQueueRepository>();
services.AddTransient<PlacementCommandRepository>();
services.AddTransient<CommandRepository>();
services.AddTransient<CommandTypeRepository>();
services.AddTransient<CommandStatusRepository>();
services.AddTransient<InsigniaPeriodsRepository>();

View file

@ -0,0 +1,318 @@
using Amazon.S3.Model.Internal.MarshallTransformations;
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Domain.Models.Commands.Core;
using BMA.EHR.Domain.Models.Organizations;
using BMA.EHR.Domain.Models.Placement;
using BMA.EHR.Domain.Shared;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Command = BMA.EHR.Domain.Models.Commands.Core.Command;
namespace BMA.EHR.Application.Repositories.Commands
{
public class CommandRepository : GenericRepository<Guid, Command>
{
#region " Fields "
private readonly IApplicationDBContext _dbContext;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destuctor "
public CommandRepository(IApplicationDBContext dbContext,
IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Methods "
#region " Override "
public override async Task<Command?> GetByIdAsync(Guid id)
{
return await _dbContext.Set<Command>()
.Include(x => x.Placement)
.Include(x => x.CommandType)
.FirstOrDefaultAsync(x => x.Id == id);
}
#endregion
public async Task<List<CommandReceiver>> GetReceiverByCommmandIdAsync(Guid Id)
{
try
{
var command = await _dbContext.Set<Command>()
.Include(x => x.Receivers)
.Include(x => x.CommandType)
.FirstOrDefaultAsync(x => x.Id == Id);
if (command == null)
throw new Exception(GlobalMessages.CommandNotFound);
else
{
if (command.Receivers != null || command!.Receivers!.Count > 0)
{
return command.Receivers;
}
else
{
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
.Include(x => x.Command)
.ThenInclude(x => x.CommandType)
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-01")
.Where(x => x.Id != Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<PlacementProfile>()
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
//.Where(x => x.OrganizationPosition.Organization.Id )
.Where(x => !otherCommandReceivers.Contains(x.CitizenId!))
.Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN")
.Where(x => x.Draft! == true)
.OrderBy(x => x.ExamNumber)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.CitizenId!,
Prefix = item.Prefix!.Name,
FirstName = item.Firstname!,
LastName = item.Lastname!,
RefPlacementProfileId = item.Id
};
seq++;
command.Receivers.Add(receiver);
}
await _dbContext.SaveChangesAsync();
// query for new list
return command.Receivers;
}
}
}
catch
{
throw;
}
}
public async Task<CommandReceiver> DeleteCommandReceiverAsync(Guid personalId)
{
try
{
var deleted = await _dbContext.Set<CommandReceiver>()
.FirstOrDefaultAsync(x => x.Id == personalId);
if (deleted == null)
throw new Exception(GlobalMessages.DataNotFound);
_dbContext.Set<CommandReceiver>().Remove(deleted);
await _dbContext.SaveChangesAsync();
return deleted;
}
catch
{
throw;
}
}
public async Task<List<CommandDeployment>> GetDeploymentByCommandIdAsync(Guid id)
{
try
{
var command = await _dbContext.Set<Command>()
.Include(x => x.Deployments)
.FirstOrDefaultAsync(x => x.Id == id);
if (command == null)
throw new Exception(GlobalMessages.CommandNotFound);
else
{
if (command.Deployments != null || command!.Deployments!.Count > 0)
{
return command.Deployments;
}
else
{
var orgPos = await _dbContext.Set<ProfilePosition>()
.Include(x => x.Profile)
.ThenInclude(x => x!.Prefix)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.Organization)
.ThenInclude(x => x!.OrganizationOrganization)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.PositionMaster)
.ThenInclude(x => x!.PositionPath)
.Where(x => x.OrganizationPosition!.IsDirector! == true)
.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
.FirstOrDefaultAsync();
if (orgPos != null)
{
if (orgPos.Profile != null)
{
var dp = new CommandDeployment
{
Sequence = 1,
ReceiveUserId = orgPos!.Profile!.Id!.ToString("D"),
CitizenId = orgPos!.Profile!.CitizenId!,
Prefix = orgPos!.Profile!.Prefix!.Name,
FirstName = orgPos!.Profile!.FirstName!,
LastName = orgPos!.Profile!.LastName!,
IsSendInbox = true,
IsSendMail = true,
IsSendNotification = true,
OrganizationName = orgPos!.OrganizationPosition!.Organization!.OrganizationOrganization!.Name,
PositionName = orgPos!.OrganizationPosition!.PositionMaster!.PositionPath!.Name
};
command.Deployments.Add(dp);
}
await _dbContext.SaveChangesAsync();
}
// query for new list
return command.Deployments;
}
}
}
catch
{
throw;
}
}
public async Task<List<ProfilePosition>> GetProfileByOrganizationIdAsync(Guid orgId)
{
try
{
var orgProfiles = await _dbContext.Set<ProfilePosition>()
.Include(x => x.Profile)
.ThenInclude(x => x!.Prefix)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.Organization)
.ThenInclude(x => x!.OrganizationOrganization)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.PositionMaster)
.ThenInclude(x => x!.PositionPath)
.Where(x => x.OrganizationPosition!.Organization!.Id == orgId)
.ToListAsync();
return orgProfiles;
}
catch
{
throw;
}
}
public async Task CreateCommandDeploymentAsync(Guid commandId, List<CommandDeployment> deploy)
{
try
{
var command = await _dbContext.Set<Command>()
.Include(x => x.Deployments)
.FirstOrDefaultAsync(x => x.Id == commandId);
if (command == null)
throw new Exception(GlobalMessages.CommandNotFound);
else
{
var lastSeq = 0;
var dep = command.Deployments.OrderByDescending(x => x.Sequence).FirstOrDefault();
if (dep == null) lastSeq = 1;
else lastSeq = dep.Sequence;
foreach (var dep2 in deploy)
{
dep2.Sequence = lastSeq;
lastSeq++;
}
command.Deployments.AddRange(deploy);
await _dbContext.SaveChangesAsync();
}
}
catch
{
throw;
}
}
public async Task UpdatCommandDeploymentAsync(List<CommandDeployment> deploys)
{
try
{
foreach (var dp in deploys)
{
var updated = await _dbContext.Set<CommandDeployment>().FirstOrDefaultAsync(x => x.Id == dp.Id);
if (updated != null)
{
updated.IsSendMail = dp.IsSendMail;
updated.IsSendInbox = dp.IsSendInbox;
}
}
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
public async Task DeleteCommandDeploymentAsync(Guid id)
{
try
{
var deleted = await _dbContext.Set<CommandDeployment>().FirstOrDefaultAsync(x => x.Id == id);
if (deleted == null)
throw new Exception(GlobalMessages.DataNotFound);
_dbContext.Set<CommandDeployment>().Remove(deleted);
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
public async Task<CommandDeployment?> GetCommandDeploymentById(Guid id)
{
try
{
var data = await _dbContext.Set<CommandDeployment>().FirstOrDefaultAsync(x => x.Id == id);
return data;
}
catch
{
throw;
}
}
#endregion
}
}

View file

@ -1,54 +0,0 @@
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Domain.Models.Commands.Core;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Application.Repositories.Commands
{
public class PlacementCommandRepository : GenericRepository<Guid, Command>
{
#region " Fields "
private readonly IApplicationDBContext _dbContext;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destuctor "
public PlacementCommandRepository(IApplicationDBContext dbContext,
IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Methods "
public async Task<List<CommandReceiver>> GetReceiverByCommmandIdAsync(Guid Id)
{
try
{
var command = await _dbContext.Set<Command>()
.Include(x => x.Receivers)
.FirstOrDefaultAsync(x => x.Id == Id);
if(command == null)
{
return new List<CommandReceiver>();
}
else
return command.Receivers;
}
catch
{
throw;
}
}
#endregion
}
}

View file

@ -37,17 +37,17 @@ namespace BMA.EHR.Application.Repositories
#region " Methods "
public async Task<IReadOnlyList<T>> GetAllAsync()
public virtual async Task<IReadOnlyList<T>> GetAllAsync()
{
return await _dbSet.ToListAsync();
}
public async Task<T?> GetByIdAsync(S id)
public virtual async Task<T?> GetByIdAsync(S id)
{
return await _dbSet.FindAsync(id);
}
public async Task<T> AddAsync(T entity)
public virtual async Task<T> AddAsync(T entity)
{
//if (entity is IAuditableEntity)
//{
@ -63,7 +63,7 @@ namespace BMA.EHR.Application.Repositories
return entity;
}
public async Task<T> UpdateAsync(T entity)
public virtual async Task<T> UpdateAsync(T entity)
{
//if (entity is IAuditableEntity)
//{
@ -78,7 +78,7 @@ namespace BMA.EHR.Application.Repositories
return entity;
}
public async Task DeleteAsync(T entity)
public virtual async Task DeleteAsync(T entity)
{
_dbSet.Remove(entity);
await _dbContext.SaveChangesAsync();

View file

@ -1,8 +1,11 @@
using BMA.EHR.Application.Repositories;
using Amazon.S3.Model.Internal.MarshallTransformations;
using BMA.EHR.Application.Repositories;
using BMA.EHR.Application.Repositories.Commands;
using BMA.EHR.Command.Service.Requests;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Commands.Core;
using BMA.EHR.Domain.Models.MetaData;
using BMA.EHR.Domain.Shared;
using BMA.EHR.Infrastructure.Persistence;
using Microsoft.AspNetCore.Authorization;
@ -24,27 +27,30 @@ namespace BMA.EHR.Command.Service.Controllers
{
#region " Fields "
private readonly PlacementCommandRepository _repository;
private readonly CommandRepository _repository;
private readonly PlacementRepository _placementRepository;
private readonly ApplicationDBContext _context;
private readonly MinIOService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly GenericRepository<Guid, Prefix> _prefixRepository;
#endregion
#region " Constuctor and Destructor "
public OrderController(PlacementCommandRepository repository,
public OrderController(CommandRepository repository,
PlacementRepository placementRepository,
ApplicationDBContext context,
MinIOService documentService,
IHttpContextAccessor httpContextAccessor)
IHttpContextAccessor httpContextAccessor,
GenericRepository<Guid, Prefix> prefixRepository)
{
_repository = repository;
_context = context;
_documentService = documentService;
_httpContextAccessor = httpContextAccessor;
_placementRepository = placementRepository;
_prefixRepository = prefixRepository;
}
#endregion
@ -189,7 +195,7 @@ namespace BMA.EHR.Command.Service.Controllers
orderBy = data.IssuerOrganizationId,
signatoryBy = data.AuthorizedUserFullName,
signatoryPosition = data.AuthorizedPosition,
examRound = data.ExamRoundId,
examRound = data.Placement.Round,
registerPosition = "",
conclusionRegisterNo = data.ConclusionRegisterNo,
conclusionRegisterDate = data.ConclusionRegisterDate,
@ -231,7 +237,7 @@ namespace BMA.EHR.Command.Service.Controllers
IssuerOrganizationId = req.orderBy,
AuthorizedUserFullName = req.signatoryBy,
AuthorizedPosition = req.signatoryPosition,
ExamRoundId = req.examRound,
PlacementId = req.examRound,
ConclusionRegisterNo = req.conclusionRegisterNo,
ConclusionRegisterDate = req.conclusionRegisterDate,
ConclusionResultNo = req.conclusionResultNo,
@ -292,21 +298,228 @@ namespace BMA.EHR.Command.Service.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[AllowAnonymous]
public async Task<ActionResult<ResponseObject>> GetCommandReceiver(Guid orderId)
public async Task<ActionResult<ResponseObject>> GetCommandReceiverAsync(Guid orderId)
{
try
{
var receivers = await _repository.GetReceiverByCommmandIdAsync(orderId);
if (receivers.Count() > 0)
// TODO : หาค่า Education มาแสดง
var receivers = (await _repository.GetReceiverByCommmandIdAsync(orderId))
.Select(r => new
{
personId = r.Id,
sequence = r.Sequence,
idCard = r.CitizenId,
name = $"{r.Prefix!}{r.FirstName!} {r.LastName!}",
selectStatus = true,
education = "" // ยังหาไม่เจอว่าอยุ่ field ไหน
}).ToList();
return Success(receivers);
}
catch
{
throw;
}
}
/// <summary>
/// PM7-27 : ข้อมูลเลือกรายชื่อออกคำสั่ง
/// </summary>
/// <param name="personalId">Record Id ของผู้รับคำสั่งในรายการบัญชีแนบท้าย</param>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpDelete("persons/{personalId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> DeleteCommandReceiverAsync(Guid personalId)
{
try
{
var receiver = await _repository.DeleteCommandReceiverAsync(personalId);
return Success(receiver);
}
catch
{
throw;
}
}
/// <summary>
/// PM7-28 : ข้อมูลเลือกรายชื่อส่งสำเนาคำสั่ง
/// </summary>
/// <param name="orderId">Record Id ของคำสั่ง</param>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("persons/{personalId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetCommandDeploymentAsync(Guid orderId)
{
try
{
var deployments = (await _repository.GetDeploymentByCommandIdAsync(orderId))
.Select(x => new
{
personalId = x.Id,
sequence = x.Sequence,
selectStatus = true,
idCard = x.CitizenId,
name = $"{x.Prefix}{x.FirstName} {x.LastName}",
position = x.PositionName,
unit = x.OrganizationName,
emailChannel = x.IsSendMail,
inboxChannel = x.IsSendInbox
})
.ToList();
return Success(deployments);
}
catch
{
throw;
}
}
/// <summary>
/// PM7-30 : popup - เลือกรายชื่อส่งสำเนาคำสั่ง
/// </summary>
/// <param name="organizationId">Record Id ของหน่วยงาน</param>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("copy-order/persons/{organizationId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> GetPeopleByOrganizationIdAsync(Guid organizationId)
{
try
{
var people = (await _repository.GetProfileByOrganizationIdAsync(organizationId))
.Select(x => new
{
profileId = x.Profile!.Id,
idCard = x.Profile!.CitizenId,
name = $"{x.Profile!.Prefix!.Name}{x.Profile!.FirstName} {x.Profile!.LastName}",
position = x.OrganizationPosition!.PositionMaster!.PositionPath!.Name,
unit = x.OrganizationPosition!.Organization!.OrganizationOrganization!.Name,
prefixId = x.Profile!.Prefix!.Id,
firstName = x.Profile!.FirstName,
lastName = x.Profile!.LastName
})
.ToList();
return Success(people);
}
catch
{
throw;
}
}
/// <summary>
/// PM7-31 : เพิ่มรายชื่อคนที่ต้องการส่งสำเนาคำสั่ง
/// </summary>
/// <param name="orderId">Record Id ของคำสั่ง</param>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("copy-order/persons/{orderId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> CreateCommandDeploymentAsync(Guid orderId, [FromBody] List<CreateCommandDeploymentRequest> req)
{
try
{
// transform req
var deploys = new List<CommandDeployment>();
foreach (var p in req)
{
return Success(receivers);
var prefix = await _prefixRepository.GetByIdAsync(p.PrefixId);
deploys.Add(new CommandDeployment
{
CitizenId = p.IdCard,
Prefix = prefix.Name,
FirstName = p.FirstName,
LastName = p.LastName,
OrganizationName = p.Unit,
PositionName = p.Position
});
}
else
await _repository.CreateCommandDeploymentAsync(orderId, deploys);
return Success();
}
catch
{
throw;
}
}
/// <summary>
/// PM7-32 : บันทึกช่องทางการส่งสำเนาคำสั่ง
/// </summary>
/// <param name="orderId">Record Id ของคำสั่ง</param>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("copy-order")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> UpdateCommandDeploymentAsync([FromBody] List<UpdateCommandDeploymentRequest> req)
{
try
{
// transform
var deploys = new List<CommandDeployment>();
foreach(var p in req)
{
// ไม่เจอข้อมูลไปอ่านจากระบบสรรหาที่สง้รายชื่อมาแล้ว insert
return Success();
var updated = await _repository.GetCommandDeploymentById(p.PersonalId);
updated!.IsSendInbox = p.InboxChannel;
updated!.IsSendMail = p.EmailChannel;
deploys.Add(updated);
}
await _repository.UpdatCommandDeploymentAsync(deploys);
return Success();
}
catch
{
throw;
}
}
/// <summary>
/// PM7-33 : ลบรายชื่อคนที่ต้องการส่งสำเนาคำสั่ง
/// </summary>
/// <param name="personalId">Record Id ของผู้รับสำเนาคำสั่ง</param>
/// <returns></returns>
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpDelete("copy-order/{personalId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> DeleteCommandDeloymentAsync(Guid personalId)
{
try
{
await _repository.DeleteCommandDeploymentAsync(personalId);
return Success();
}
catch
{

View file

@ -7,7 +7,12 @@ EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["BMA.EHR.Domain/BMA.EHR.Domain.csproj", "BMA.EHR.Domain/"]
COPY ["BMA.EHR.Application/BMA.EHR.Application.csproj", "BMA.EHR.Application/"]
COPY ["BMA.EHR.Infrastructure/BMA.EHR.Infrastructure.csproj", "BMA.EHR.Infrastructure/"]
COPY ["BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj", "BMA.EHR.Command.Service/"]
RUN dotnet restore "BMA.EHR.Command.Service/BMA.EHR.Command.Service.csproj"
COPY . .
WORKDIR "/src/BMA.EHR.Command.Service"

View file

@ -0,0 +1,19 @@
namespace BMA.EHR.Command.Service.Requests
{
public class CreateCommandDeploymentRequest
{
public Guid ProfileId { get; set; } = Guid.Empty;
public string IdCard { get; set; } = string.Empty;
public Guid PrefixId { get; set;} = Guid.Empty;
public string FirstName { get; set;} = string.Empty;
public string LastName { get; set;} = string.Empty;
public string Position { get; set;} = string.Empty;
public string Unit { get; set;} = string.Empty;
}
}

View file

@ -0,0 +1,11 @@
namespace BMA.EHR.Command.Service.Requests
{
public class UpdateCommandDeploymentRequest
{
public Guid PersonalId { get; set; } = Guid.Empty;
public bool EmailChannel { get; set; } = true;
public bool InboxChannel { get; set; } = true;
}
}

View file

@ -49,7 +49,9 @@ namespace BMA.EHR.Domain.Models.Commands.Core
#region " For Placement Command "
[Required, Comment("อ้างอิงรอบการสอบ")]
public Guid ExamRoundId { get; set; }
public Guid PlacementId { get; set; }
public Placement.Placement Placement { get; set; }
[Required, Comment("ตำแหน่งที่บรรจุ")]
public string PositionName { get; set; } = string.Empty;

View file

@ -4,17 +4,32 @@ using System.ComponentModel.DataAnnotations;
namespace BMA.EHR.Domain.Models.Commands.Core
{
public class CommandDeployment:EntityBase
public class CommandDeployment : EntityBase
{
[Comment("รหัสอ้างอิงคำสั่ง")]
public Guid CommandId { get; set; } = Guid.Empty;
public Command Command { get; set; } = new();
[Required,Comment("รหัสอ้างอิงผู้ใช้งานระบบ")]
[Required, Comment("รหัสอ้างอิงผู้ใช้งานระบบ")]
public string ReceiveUserId { get; set; } = string.Empty;
[Required,Comment("ส่งอีเมล์หรือไม่?")]
[Required, Comment("ลำดับ")]
public int Sequence { get; set; } = 0;
[MaxLength(13), Required, Comment("เลขประจำตัวประชาชน")]
public string CitizenId { get; set; } = string.Empty;
[MaxLength(50), Required, Comment("คำนำหน้านาม")]
public string Prefix { get; set; } = string.Empty;
[MaxLength(100), Required, Comment("ชื่อ")]
public string FirstName { get; set; } = string.Empty;
[MaxLength(100), Required, Comment("นามสกุล")]
public string LastName { get; set; } = string.Empty;
[Required, Comment("ส่งอีเมล์หรือไม่?")]
public bool IsSendMail { get; set; } = true;
[Required, Comment("ส่งกล่องข้อความหรือไม่?")]
@ -22,5 +37,11 @@ namespace BMA.EHR.Domain.Models.Commands.Core
[Required, Comment("ส่งแจ้งเตือนหรือไม่?")]
public bool IsSendNotification { get; set; } = true;
[Comment("ชื่อหน่วยงานของผู้รับสำเนาคำสั่ง")]
public string OrganizationName { get; set; } = string.Empty;
[Comment("ชื่อตำแหน่งของผู้รับสำเนาคำสั่ง")]
public string PositionName { get; set; } = string.Empty;
}
}

View file

@ -12,13 +12,13 @@ namespace BMA.EHR.Domain.Models.Commands.Core
public Command Command { get; set; } = new();
[Required,Comment("ลำดับในบัญชีแนบท้าย")]
[Required, Comment("ลำดับในบัญชีแนบท้าย")]
public int Sequence { get; set; } = 0;
[MaxLength(13), Required, Comment("เลขประจำตัวประชาชน")]
public string CitizenId { get; set; } = string.Empty;
[MaxLength(50),Required,Comment("คำนำหน้านาม")]
[MaxLength(50), Required, Comment("คำนำหน้านาม")]
public string Prefix { get; set; } = string.Empty;
[MaxLength(100), Required, Comment("ชื่อ")]
@ -27,7 +27,10 @@ namespace BMA.EHR.Domain.Models.Commands.Core
[MaxLength(100), Required, Comment("นามสกุล")]
public string LastName { get; set; } = string.Empty;
[Column(TypeName = "text"),Comment("หมายเหตุ")]
public string Comment { get; set; }
[Column(TypeName = "text"), Comment("หมายเหตุ")]
public string Comment { get; set; } = string.Empty;
[Comment("รหัสอ้างอิงไปยังข้อมูลผู้บรรจุ")]
public Guid? RefPlacementProfileId { get; set; }
}
}

View file

@ -11,5 +11,8 @@ namespace BMA.EHR.Domain.Models.Commands.Core
[Required, MaxLength(100), Comment("ประเภทคำสั่ง")]
public string Category { get; set; } = string.Empty;
[Comment("รหัสของประเภทคำสั่ง")]
public string CommandCode { get; set; } = string.Empty;
}
}

View file

@ -78,5 +78,11 @@
public static readonly string InvalidRetirementRequest = "ไม่พบข้อมูลการประกาศเกษียณอายุราชการ";
#endregion
#region " Command "
public static readonly string CommandNotFound = "ไม่พบรายการคำสั่งนี้ในระบบ โปรดตรวจความถูกต้อง";
#endregion
}
}

View file

@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AddCommandCodetoCommandTypeTable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "CommandCode",
table: "CommandTypes",
type: "longtext",
nullable: false,
comment: "รหัสของประเภทคำสั่ง")
.Annotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CommandCode",
table: "CommandTypes");
}
}
}

View file

@ -0,0 +1,31 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AddRefToPlacementProfiletoCommandReceiverTable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "RefPlacementProfileId",
table: "CommandReceivers",
type: "char(36)",
nullable: true,
comment: "รหัสอ้างอิงไปยังข้อมูลผู้บรรจุ",
collation: "ascii_general_ci");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "RefPlacementProfileId",
table: "CommandReceivers");
}
}
}

View file

@ -0,0 +1,129 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AddFieldtoCommandDeploymentTable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "ExamRoundId",
table: "Commands",
newName: "PlacementId");
migrationBuilder.AddColumn<string>(
name: "CitizenId",
table: "CommandDeployments",
type: "varchar(13)",
maxLength: 13,
nullable: false,
defaultValue: "",
comment: "เลขประจำตัวประชาชน")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "FirstName",
table: "CommandDeployments",
type: "varchar(100)",
maxLength: 100,
nullable: false,
defaultValue: "",
comment: "ชื่อ")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "LastName",
table: "CommandDeployments",
type: "varchar(100)",
maxLength: 100,
nullable: false,
defaultValue: "",
comment: "นามสกุล")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "OrganizationName",
table: "CommandDeployments",
type: "longtext",
nullable: false,
comment: "ชื่อหน่วยงานของผู้รับสำเนาคำสั่ง")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "Prefix",
table: "CommandDeployments",
type: "varchar(50)",
maxLength: 50,
nullable: false,
defaultValue: "",
comment: "คำนำหน้านาม")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<int>(
name: "Sequence",
table: "CommandDeployments",
type: "int",
nullable: false,
defaultValue: 0,
comment: "ลำดับ");
migrationBuilder.CreateIndex(
name: "IX_Commands_PlacementId",
table: "Commands",
column: "PlacementId");
migrationBuilder.AddForeignKey(
name: "FK_Commands_Placements_PlacementId",
table: "Commands",
column: "PlacementId",
principalTable: "Placements",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Commands_Placements_PlacementId",
table: "Commands");
migrationBuilder.DropIndex(
name: "IX_Commands_PlacementId",
table: "Commands");
migrationBuilder.DropColumn(
name: "CitizenId",
table: "CommandDeployments");
migrationBuilder.DropColumn(
name: "FirstName",
table: "CommandDeployments");
migrationBuilder.DropColumn(
name: "LastName",
table: "CommandDeployments");
migrationBuilder.DropColumn(
name: "OrganizationName",
table: "CommandDeployments");
migrationBuilder.DropColumn(
name: "Prefix",
table: "CommandDeployments");
migrationBuilder.DropColumn(
name: "Sequence",
table: "CommandDeployments");
migrationBuilder.RenameColumn(
name: "PlacementId",
table: "Commands",
newName: "ExamRoundId");
}
}
}

View file

@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AddPositionNametoCommandDeploymentTable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "PositionName",
table: "CommandDeployments",
type: "longtext",
nullable: false,
comment: "ชื่อตำแหน่งของผู้รับสำเนาคำสั่ง")
.Annotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "PositionName",
table: "CommandDeployments");
}
}
}

View file

@ -113,10 +113,6 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnOrder(101)
.HasComment("User Id ที่สร้างข้อมูล");
b.Property<Guid>("ExamRoundId")
.HasColumnType("char(36)")
.HasComment("อ้างอิงรอบการสอบ");
b.Property<Guid>("IssuerOrganizationId")
.HasColumnType("char(36)")
.HasComment("รหัสอ้างอิงหน่วยงานที่ออกคำสั่ง");
@ -149,6 +145,10 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("char(36)")
.HasComment("รหัสส่วนราชการผู้ออกคำสั่ง");
b.Property<Guid>("PlacementId")
.HasColumnType("char(36)")
.HasComment("อ้างอิงรอบการสอบ");
b.Property<string>("PositionName")
.IsRequired()
.HasColumnType("longtext")
@ -160,6 +160,8 @@ namespace BMA.EHR.Infrastructure.Migrations
b.HasIndex("CommandTypeId");
b.HasIndex("PlacementId");
b.ToTable("Commands");
});
@ -172,6 +174,12 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasComment("PrimaryKey")
.HasAnnotation("Relational:JsonPropertyName", "id");
b.Property<string>("CitizenId")
.IsRequired()
.HasMaxLength(13)
.HasColumnType("varchar(13)")
.HasComment("เลขประจำตัวประชาชน");
b.Property<Guid>("CommandId")
.HasColumnType("char(36)")
.HasComment("รหัสอ้างอิงคำสั่ง");
@ -195,6 +203,12 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnOrder(101)
.HasComment("User Id ที่สร้างข้อมูล");
b.Property<string>("FirstName")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)")
.HasComment("ชื่อ");
b.Property<bool>("IsSendInbox")
.HasColumnType("tinyint(1)")
.HasComment("ส่งกล่องข้อความหรือไม่?");
@ -207,6 +221,12 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("tinyint(1)")
.HasComment("ส่งแจ้งเตือนหรือไม่?");
b.Property<string>("LastName")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)")
.HasComment("นามสกุล");
b.Property<string>("LastUpdateFullName")
.IsRequired()
.HasMaxLength(200)
@ -226,11 +246,31 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnOrder(102)
.HasComment("แก้ไขข้อมูลล่าสุดเมื่อ");
b.Property<string>("OrganizationName")
.IsRequired()
.HasColumnType("longtext")
.HasComment("ชื่อหน่วยงานของผู้รับสำเนาคำสั่ง");
b.Property<string>("PositionName")
.IsRequired()
.HasColumnType("longtext")
.HasComment("ชื่อตำแหน่งของผู้รับสำเนาคำสั่ง");
b.Property<string>("Prefix")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("varchar(50)")
.HasComment("คำนำหน้านาม");
b.Property<string>("ReceiveUserId")
.IsRequired()
.HasColumnType("longtext")
.HasComment("รหัสอ้างอิงผู้ใช้งานระบบ");
b.Property<int>("Sequence")
.HasColumnType("int")
.HasComment("ลำดับ");
b.HasKey("Id");
b.HasIndex("CommandId");
@ -385,6 +425,10 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("varchar(50)")
.HasComment("คำนำหน้านาม");
b.Property<Guid?>("RefPlacementProfileId")
.HasColumnType("char(36)")
.HasComment("รหัสอ้างอิงไปยังข้อมูลผู้บรรจุ");
b.Property<int>("Sequence")
.HasColumnType("int")
.HasComment("ลำดับในบัญชีแนบท้าย");
@ -473,6 +517,11 @@ namespace BMA.EHR.Infrastructure.Migrations
.HasColumnType("varchar(100)")
.HasComment("ประเภทคำสั่ง");
b.Property<string>("CommandCode")
.IsRequired()
.HasColumnType("longtext")
.HasComment("รหัสของประเภทคำสั่ง");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)")
.HasColumnOrder(100)
@ -10594,9 +10643,17 @@ namespace BMA.EHR.Infrastructure.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BMA.EHR.Domain.Models.Placement.Placement", "Placement")
.WithMany()
.HasForeignKey("PlacementId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CommandStatus");
b.Navigation("CommandType");
b.Navigation("Placement");
});
modelBuilder.Entity("BMA.EHR.Domain.Models.Commands.Core.CommandDeployment", b =>

View file

@ -70,7 +70,8 @@ namespace BMA.EHR.Infrastructure.Persistence
{
Id = Guid.Parse(workSheet?.Cells[row, 1]?.GetValue<string>()!),
Name = workSheet?.Cells[row, 2]?.GetValue<string>()!,
Category = workSheet?.Cells[row, 3]?.GetValue<string>()!
Category = workSheet?.Cells[row, 3]?.GetValue<string>()!,
CommandCode = workSheet?.Cells[row, 4]?.GetValue<string>()!
};
await service.AddAsync(inserted);