fix : เปลี่ยนชื่อ Folder + Project เอาคำว่า Service ออก เพื่อให้สามารถ run บน macOS Sonoma ได้ (ไม่เปลี่ยนจะไม่สามารถ run ได้ เนื่องจาก macOS จะมองว่าเป็น application ของ mac)
This commit is contained in:
parent
9d90c98800
commit
59340500b7
42 changed files with 21614 additions and 3532 deletions
50
BMA.EHR.Insignia/BMA.EHR.Insignia.csproj
Normal file
50
BMA.EHR.Insignia/BMA.EHR.Insignia.csproj
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>93677512-b64b-4a19-9e7d-dd283c7ec901</UserSecretsId>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<DockerfileContext>.</DockerfileContext>
|
||||
<RootNamespace>BMA.EHR.Insignia.Service</RootNamespace>
|
||||
<AssemblyName>BMA.EHR.Insignia</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Hangfire" Version="1.8.5"/>
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.5"/>
|
||||
<PackageReference Include="Hangfire.MySqlStorage" Version="2.0.3"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.9"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.9"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="5.1.0"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.9"/>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.IdentityModel.Logging" Version="6.32.0"/>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1"/>
|
||||
<PackageReference Include="runtime.osx.10.10-x64.CoreCompat.System.Drawing" Version="6.0.5.128"/>
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0"/>
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0"/>
|
||||
<PackageReference Include="Sentry.AspNetCore" Version="3.33.1"/>
|
||||
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0"/>
|
||||
<PackageReference Include="Serilog.Exceptions" Version="8.4.0"/>
|
||||
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0"/>
|
||||
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="9.0.3"/>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0"/>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BMA.EHR.Infrastructure\BMA.EHR.Infrastructure.csproj"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="Templates/PersonInsignia.xlsx">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
84
BMA.EHR.Insignia/ConfigureSwaggerOptions.cs
Normal file
84
BMA.EHR.Insignia/ConfigureSwaggerOptions.cs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using System.Reflection;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service
|
||||
{
|
||||
public class ConfigureSwaggerOptions : IConfigureNamedOptions<SwaggerGenOptions>
|
||||
{
|
||||
private readonly IApiVersionDescriptionProvider _provider;
|
||||
|
||||
public ConfigureSwaggerOptions(
|
||||
IApiVersionDescriptionProvider provider)
|
||||
{
|
||||
_provider = provider;
|
||||
}
|
||||
|
||||
public void Configure(SwaggerGenOptions options)
|
||||
{
|
||||
// add swagger document for every API version discovered
|
||||
foreach (var description in _provider.ApiVersionDescriptions)
|
||||
{
|
||||
options.EnableAnnotations();
|
||||
|
||||
options.SwaggerDoc(
|
||||
description.GroupName,
|
||||
CreateVersionInfo(description));
|
||||
}
|
||||
|
||||
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
||||
{
|
||||
In = ParameterLocation.Header,
|
||||
Description = "Please enter a valid token",
|
||||
Name = "Authorization",
|
||||
Type = SecuritySchemeType.Http,
|
||||
BearerFormat = "JWT",
|
||||
Scheme = "Bearer"
|
||||
});
|
||||
|
||||
options.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||
{
|
||||
{
|
||||
new OpenApiSecurityScheme
|
||||
{
|
||||
Reference = new OpenApiReference
|
||||
{
|
||||
Type = ReferenceType.SecurityScheme,
|
||||
Id = "Bearer"
|
||||
}
|
||||
},
|
||||
new string[]{}
|
||||
}
|
||||
});
|
||||
|
||||
// generate the XML docs that'll drive the swagger docs
|
||||
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
||||
options.IncludeXmlComments(xmlPath);
|
||||
}
|
||||
|
||||
public void Configure(string name, SwaggerGenOptions options)
|
||||
{
|
||||
Configure(options);
|
||||
}
|
||||
|
||||
private OpenApiInfo CreateVersionInfo(
|
||||
ApiVersionDescription desc)
|
||||
{
|
||||
var info = new OpenApiInfo()
|
||||
{
|
||||
Title = "BMA EHR Insignia Service Document",
|
||||
Version = desc.ApiVersion.ToString()
|
||||
};
|
||||
|
||||
if (desc.IsDeprecated)
|
||||
{
|
||||
info.Description += " This API version has been deprecated. Please use one of the new APIs available from the explorer.";
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
||||
721
BMA.EHR.Insignia/Controllers/InsigniaManageController.cs
Normal file
721
BMA.EHR.Insignia/Controllers/InsigniaManageController.cs
Normal file
|
|
@ -0,0 +1,721 @@
|
|||
using System.Security.Claims;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Repositories.MessageQueue;
|
||||
using BMA.EHR.Application.Requests;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Models.Insignias;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
|
||||
using Newtonsoft.Json;
|
||||
using OfficeOpenXml.Export.ToDataTable;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/insignia/manage")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
[SwaggerTag("จัดสรรเครื่องราชฯ")]
|
||||
public class InsigniaManageController : BaseController
|
||||
{
|
||||
private readonly ApplicationDBContext _context;
|
||||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly InsigniaPeriodsRepository _repository;
|
||||
private readonly NotificationRepository _repositoryNoti;
|
||||
private readonly UserProfileRepository _userProfileRepository;
|
||||
|
||||
public InsigniaManageController(ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
InsigniaPeriodsRepository repository,
|
||||
NotificationRepository repositoryNoti,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
UserProfileRepository userProfileRepository)
|
||||
{
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_repository = repository;
|
||||
_repositoryNoti = repositoryNoti;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_userProfileRepository = userProfileRepository;
|
||||
}
|
||||
|
||||
#region " Properties "
|
||||
|
||||
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
||||
|
||||
private string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// list จัดสรรเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <param name="year">ปีการจัดสรร</param>
|
||||
/// <param name="insigniaTypeId">Id ประเภทเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("type/{year}/{insigniaTypeId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetList(int year, Guid insigniaTypeId)
|
||||
{
|
||||
var insigniaType = await _context.InsigniaTypes
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaTypeId);
|
||||
if (insigniaType == null)
|
||||
return Error(GlobalMessages.InsigniaTypeNotFound);
|
||||
var data = await _context.InsigniaManages.AsQueryable()
|
||||
.Where(x => x.Insignia.InsigniaType == insigniaType)
|
||||
.Where(x => x.Year == year)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(p => new
|
||||
{
|
||||
Id = p.Id,
|
||||
Insignia = p.Insignia.Name,
|
||||
InsigniaId = p.Insignia.Id,
|
||||
Year = p.Year,
|
||||
Total = p.Total,
|
||||
Allocate = p.InsigniaManageOrganiations.Sum(x => x.Total),
|
||||
Remain = p.Total - p.InsigniaManageOrganiations.Sum(x => x.Total),
|
||||
LastUpdatedAt = p.LastUpdatedAt,
|
||||
CreatedAt = p.CreatedAt,
|
||||
})
|
||||
.ToListAsync();
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get รายละเอียดจัดสรรเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageId">Id จัดสรรเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("{insigniaManageId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetById(Guid insigniaManageId)
|
||||
{
|
||||
var data = await _context.InsigniaManages.AsQueryable()
|
||||
.Where(x => x.Id == insigniaManageId)
|
||||
.Select(p => new
|
||||
{
|
||||
Id = p.Id,
|
||||
Insignia = p.Insignia.Name,
|
||||
InsigniaId = p.Insignia.Id,
|
||||
Year = p.Year,
|
||||
Total = p.Total,
|
||||
LastUpdatedAt = p.LastUpdatedAt,
|
||||
CreatedAt = p.CreatedAt,
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
if (data == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound, 404);
|
||||
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// สร้างจัดสรรเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost()]
|
||||
public async Task<ActionResult<ResponseObject>> Post([FromBody] InsigniaManageRequest req)
|
||||
{
|
||||
var insignia = await _context.Insignias.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == req.Insignia);
|
||||
if (insignia == null)
|
||||
return Error(GlobalMessages.InsigniaNotFound);
|
||||
|
||||
var insigniaManage = await _context.InsigniaManages.AsQueryable()
|
||||
.Where(x => x.Insignia == insignia && x.Year == req.Year)
|
||||
.FirstOrDefaultAsync();
|
||||
if (insigniaManage != null)
|
||||
return Error(GlobalMessages.InsigniaManageDupicate);
|
||||
|
||||
await _context.InsigniaManages.AddAsync(
|
||||
new InsigniaManage
|
||||
{
|
||||
Insignia = insignia,
|
||||
Year = req.Year,
|
||||
Total = req.Total,
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ลบจัดสรรเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageId">Id จัดสรรเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpDelete("{insigniaManageId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> Delete(Guid insigniaManageId)
|
||||
{
|
||||
var deleted = await _context.InsigniaManages.AsQueryable()
|
||||
.Where(x => x.Id == insigniaManageId)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (deleted == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
_context.InsigniaManages.Remove(deleted);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// แก้ไขจัดสรรเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageId">Id จัดสรรเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("{insigniaManageId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> Put([FromBody] InsigniaManageRequest req, Guid insigniaManageId)
|
||||
{
|
||||
var insignia = await _context.Insignias.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == req.Insignia);
|
||||
if (insignia == null)
|
||||
return Error(GlobalMessages.InsigniaNotFound);
|
||||
|
||||
var insigniaManage = await _context.InsigniaManages.AsQueryable()
|
||||
.Where(x => x.Insignia == insignia && x.Year == req.Year && x.Id != insigniaManageId)
|
||||
.FirstOrDefaultAsync();
|
||||
if (insigniaManage != null)
|
||||
return Error(GlobalMessages.InsigniaManageDupicate);
|
||||
|
||||
var uppdated = await _context.InsigniaManages.AsQueryable()
|
||||
.Include(x => x.Insignia)
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaManageId);
|
||||
if (uppdated == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
|
||||
uppdated.Insignia = insignia;
|
||||
// uppdated.Year = req.Year;
|
||||
uppdated.Total = req.Total;
|
||||
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
uppdated.LastUpdateUserId = UserId ?? "";
|
||||
uppdated.LastUpdatedAt = DateTime.Now;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// list หน่วยงานจัดสรรเครื่องราชอิสริยาภรณ์
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageId">Id จัดสรรเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("org/{insigniaManageId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetListOrganization(Guid insigniaManageId)
|
||||
{
|
||||
var insigniaManage = await _context.InsigniaManages.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaManageId);
|
||||
if (insigniaManage == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
|
||||
var insigniaManageOrg = await _context.InsigniaManageOrganiations.AsQueryable()
|
||||
.Where(x => x.InsigniaManage == insigniaManage)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(p => new
|
||||
{
|
||||
Id = p.Id,
|
||||
OrganizationOrganization = _userProfileRepository.GetOc(p.OrganizationId, 0, AccessToken) == null ? "" : _userProfileRepository.GetOc(p.OrganizationId, 0, AccessToken)!.Root,
|
||||
Total = p.Total,
|
||||
Allocate = p.InsigniaManageProfiles.Where(x => x.Status == false).Count(),
|
||||
Remain = p.Total - p.InsigniaManageProfiles.Where(x => x.Status == false).Count(),
|
||||
LastUpdatedAt = p.LastUpdatedAt,
|
||||
CreatedAt = p.CreatedAt,
|
||||
})
|
||||
.ToListAsync();
|
||||
return Success(insigniaManageOrg);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// สร้างหน่วยงานจัดสรรเครื่องราชอิสริยาภรณ์
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost("org")]
|
||||
public async Task<ActionResult<ResponseObject>> PostOrganization([FromBody] InsigniaManageOrganizationRequest req)
|
||||
{
|
||||
|
||||
var organization = _userProfileRepository.GetOc(req.OrganizationOrganizationId, 0, AccessToken);
|
||||
|
||||
//var organization = await _context.Organizations.AsQueryable()
|
||||
// .Include(x => x.OrganizationOrganization)
|
||||
// .FirstOrDefaultAsync(x => x.Id == req.OrganizationOrganizationId);
|
||||
if (organization == null)
|
||||
return Error(GlobalMessages.OrganizationNotFound);
|
||||
//if (organization.OrganizationOrganization == null)
|
||||
// return Error(GlobalMessages.OrganizationNotFound);
|
||||
|
||||
var insigniaManage = await _context.InsigniaManages.AsQueryable()
|
||||
.Include(x => x.InsigniaManageOrganiations)
|
||||
//.ThenInclude(x => x.OrganizationOrganization)
|
||||
.FirstOrDefaultAsync(x => x.Id == req.insigniaManageId);
|
||||
if (insigniaManage == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
|
||||
var insigniaManageOrganiation = await _context.InsigniaManageOrganiations.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.OrganizationId == organization.RootId && x.InsigniaManage == insigniaManage);
|
||||
if (insigniaManageOrganiation != null)
|
||||
return Error(GlobalMessages.InsigniaManageOrgDupicate);
|
||||
|
||||
var total = insigniaManage.InsigniaManageOrganiations.Where(x => x.OrganizationId != organization.RootId).Sum(x => x.Total);
|
||||
if (req.Total + total > insigniaManage.Total)
|
||||
return Error(GlobalMessages.InsigniaManageOrgLimit);
|
||||
await _context.InsigniaManageOrganiations.AddAsync(
|
||||
new InsigniaManageOrganiation
|
||||
{
|
||||
//OrganizationOrganization = organization.OrganizationOrganization,
|
||||
OrganizationId = organization.RootId ?? Guid.Empty,
|
||||
Total = req.Total,
|
||||
InsigniaManage = insigniaManage,
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ลบหน่วยงานจัดสรรเครื่องราชอิสริยาภรณ์
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageOrgId">Id หน่วยงานจัดสรรเครื่องราชอิสริยาภรณ์</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpDelete("org/{insigniaManageOrgId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> DeleteOrganization(Guid insigniaManageOrgId)
|
||||
{
|
||||
var deleted = await _context.InsigniaManageOrganiations.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaManageOrgId);
|
||||
|
||||
if (deleted == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
_context.InsigniaManageOrganiations.Remove(deleted);
|
||||
await _context.SaveChangesAsync();
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// แก้ไขหน่วยงานจัดสรรเครื่องราชอิสริยาภรณ์
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageOrgId">Id หน่วยงานจัดสรรเครื่องราชอิสริยาภรณ์</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("org/{insigniaManageOrgId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> PutOrganization([FromBody] InsigniaManageOrganizationUpdateRequest req, Guid insigniaManageOrgId)
|
||||
{
|
||||
var uppdated = await _context.InsigniaManageOrganiations.AsQueryable()
|
||||
//.Include(x => x.OrganizationOrganization)
|
||||
.Include(x => x.InsigniaManage)
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaManageOrgId);
|
||||
if (uppdated == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
|
||||
var insigniaManage = await _context.InsigniaManages.AsQueryable()
|
||||
.Include(x => x.InsigniaManageOrganiations)
|
||||
//.ThenInclude(x => x.OrganizationOrganization)
|
||||
.FirstOrDefaultAsync(x => x.Id == uppdated.InsigniaManage.Id);
|
||||
if (insigniaManage == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
var total = insigniaManage.InsigniaManageOrganiations.Where(x => x.Id != insigniaManageOrgId).Sum(x => x.Total);
|
||||
if (req.Total + total > insigniaManage.Total)
|
||||
return Error(GlobalMessages.InsigniaManageOrgLimit);
|
||||
|
||||
uppdated.Total = req.Total;
|
||||
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
uppdated.LastUpdateUserId = UserId ?? "";
|
||||
uppdated.LastUpdatedAt = DateTime.Now;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// list dashboard หน่วยงานจัดสรรเครื่องราชอิสริยาภรณ์
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageId">Id จัดสรรเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("org/dashboard/{insigniaManageId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetListDashboardOrganization(Guid insigniaManageId)
|
||||
{
|
||||
var insigniaManage = await _context.InsigniaManages.AsQueryable()
|
||||
.Include(x => x.InsigniaManageOrganiations)
|
||||
.Select(p => new
|
||||
{
|
||||
Id = p.Id,
|
||||
Insignia = p.Insignia.Name,
|
||||
InsigniaId = p.Insignia.Id,
|
||||
Year = p.Year,
|
||||
Total = p.Total,
|
||||
Allocate = p.InsigniaManageOrganiations.Sum(x => x.Total),
|
||||
Remain = p.Total - p.InsigniaManageOrganiations.Sum(x => x.Total),
|
||||
LastUpdatedAt = p.LastUpdatedAt,
|
||||
CreatedAt = p.CreatedAt,
|
||||
})
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaManageId);
|
||||
if (insigniaManage == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
|
||||
return Success(insigniaManage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ยืมเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost("borrow")]
|
||||
public async Task<ActionResult<ResponseObject>> PostBorrowInsignia([FromBody] InsigniaBorrowRequest req)
|
||||
{
|
||||
|
||||
var insigniaNoteProfile = await _context.InsigniaNoteProfiles.AsQueryable()
|
||||
.Include(x => x.RequestInsignia)
|
||||
.Include(x => x.InsigniaNote)
|
||||
//.Include(x => x.Profile)
|
||||
.FirstOrDefaultAsync(x => x.Id == req.InsigniaNoteProfileId);
|
||||
if (insigniaNoteProfile == null)
|
||||
return Error(GlobalMessages.InsigniaRequestProfileNotFound);
|
||||
if (insigniaNoteProfile.Status != "DONE")
|
||||
return Error(GlobalMessages.InsigniaNoBorrow);
|
||||
|
||||
//var _organization = await _context.Organizations.AsQueryable()
|
||||
// .FirstOrDefaultAsync(x => x.Id == insigniaNoteProfile.Profile.OcId);
|
||||
|
||||
//TODO : Hardcode OCId
|
||||
if (req.BorrowOrganizationId == null) req.BorrowOrganizationId = Guid.Parse("e8493cd1-d371-402e-add6-566e68d5d1b3");
|
||||
|
||||
var organization = _userProfileRepository.GetOc(req.BorrowOrganizationId.Value, 0, AccessToken);
|
||||
//if (organization == null)
|
||||
// return Error(GlobalMessages.OrganizationNotFound);
|
||||
|
||||
//var organization = await _context.Organizations.AsQueryable()
|
||||
// .Include(x => x.OrganizationOrganization)
|
||||
// .FirstOrDefaultAsync(x => x.Id == _organization.OrganizationAgencyId);
|
||||
//if (organization == null)
|
||||
// return Error(GlobalMessages.OrganizationNotFound);
|
||||
|
||||
var insigniaManage = await _context.InsigniaManages.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Year == insigniaNoteProfile.InsigniaNote.Year && x.Insignia == insigniaNoteProfile.RequestInsignia);
|
||||
if (insigniaManage == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
|
||||
var insigniaManageOrganiation = await _context.InsigniaManageOrganiations.AsQueryable()
|
||||
.Include(x => x.InsigniaManageProfiles)
|
||||
.FirstOrDefaultAsync(x => x.OrganizationId == organization.RootId && x.InsigniaManage == insigniaManage);
|
||||
if (insigniaManageOrganiation == null)
|
||||
return Error(GlobalMessages.InsigniaManageOrgNotFound);
|
||||
|
||||
var insigniaManageProfile = await _context.InsigniaManageProfiles.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.InsigniaNoteProfile == insigniaNoteProfile && x.Status == false);
|
||||
if (insigniaManageProfile != null)
|
||||
return Error(GlobalMessages.InsigniaNotReturn);
|
||||
|
||||
if (insigniaManageOrganiation.Total <= insigniaManageOrganiation.InsigniaManageProfiles.Count())
|
||||
return Error(GlobalMessages.InsigniaBorrowOrgLimit);
|
||||
|
||||
await _context.InsigniaManageProfiles.AddAsync(
|
||||
new InsigniaManageProfile
|
||||
{
|
||||
Status = false,
|
||||
InsigniaManageOrganiation = insigniaManageOrganiation,
|
||||
BorrowOrganizationId = organization.RootId,
|
||||
BorrowDate = req.BorrowDate,
|
||||
InsigniaNoteProfile = insigniaNoteProfile,
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
});
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// คืนเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageProfileId">Id ยืมเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("return/{insigniaManageProfileId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> PutReturnInsignia([FromBody] InsigniaReturnRequest req, Guid insigniaManageProfileId)
|
||||
{
|
||||
|
||||
var uppdated = await _context.InsigniaManageProfiles.AsQueryable()
|
||||
//.Include(x => x.BorrowOrganization)
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaManageProfileId);
|
||||
if (uppdated == null)
|
||||
return Error(GlobalMessages.InsigniaManageNotFound);
|
||||
|
||||
uppdated.Status = true;
|
||||
uppdated.ReturnDate = req.ReturnDate;
|
||||
// if (req.ReturnOrganizationId == Guid.Parse("00000000-0000-0000-0000-000000000000"))
|
||||
// {
|
||||
uppdated.ReturnOrganizationId = uppdated.BorrowOrganizationId;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var organization = await _context.Organizations.AsQueryable()
|
||||
// .Include(x => x.OrganizationOrganization)
|
||||
// .FirstOrDefaultAsync(x => x.Id == req.ReturnOrganizationId);
|
||||
// if (organization == null)
|
||||
// return Error(GlobalMessages.OrganizationNotFound);
|
||||
// uppdated.ReturnOrganization = organization.OrganizationOrganization;
|
||||
// }
|
||||
uppdated.ReturnReason = req.ReturnReason;
|
||||
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
uppdated.LastUpdateUserId = UserId ?? "";
|
||||
uppdated.LastUpdatedAt = DateTime.Now;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// list รายการยืม/คืนเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <param name="year">ปียืมขอ</param>
|
||||
/// <param name="insigniaTypeId">Id ประเภทเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("borrow/{year}/{insigniaTypeId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> ListBorrowReturnInsignia(int year, Guid insigniaTypeId)
|
||||
{
|
||||
var insigniaType = await _context.InsigniaTypes
|
||||
.FirstOrDefaultAsync(x => x.Id == insigniaTypeId);
|
||||
if (insigniaType == null)
|
||||
return Error(GlobalMessages.InsigniaTypeNotFound);
|
||||
|
||||
|
||||
var rawData = await _context.InsigniaManageProfiles.AsQueryable()
|
||||
.Where(x => x.InsigniaNoteProfile.RequestInsignia.InsigniaType == insigniaType)
|
||||
.Where(x => year == 0 ? x.Id != null : x.InsigniaManageOrganiation.InsigniaManage.Year == year)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(p => new
|
||||
{
|
||||
Id = p.Id,
|
||||
BorrowOrganization = p.BorrowOrganizationId == null ? null : _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken),
|
||||
ReturnOrganization = p.ReturnOrganizationId == null ? null : _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken),
|
||||
Profile = p.InsigniaNoteProfile.ProfileId == null ? null : _userProfileRepository.GetOfficerProfileById(p.InsigniaNoteProfile.ProfileId.Value, AccessToken),
|
||||
|
||||
Status = p.Status,
|
||||
BorrowDate = p.BorrowDate,
|
||||
ReturnDate = p.ReturnDate,
|
||||
ReturnReason = p.ReturnReason,
|
||||
LastUpdatedAt = p.LastUpdatedAt,
|
||||
CreatedAt = p.CreatedAt,
|
||||
|
||||
InsigniaNoteProfileId = p.InsigniaNoteProfile.Id,
|
||||
RequestInsignia = p.InsigniaNoteProfile.RequestInsignia == null ? null : p.InsigniaNoteProfile.RequestInsignia.Name,
|
||||
RequestInsigniaId = p.InsigniaNoteProfile.RequestInsignia == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.InsigniaNoteProfile.RequestInsignia.Id,
|
||||
RequestInsigniaShortName = p.InsigniaNoteProfile.RequestInsignia == null ? null : p.InsigniaNoteProfile.RequestInsignia.ShortName,
|
||||
p.InsigniaNoteProfile.DateReceive,
|
||||
p.InsigniaNoteProfile.OrganizationOrganizationSend,
|
||||
p.InsigniaNoteProfile.OrganizationOrganizationReceive,
|
||||
InsigniaNoteProfileStatus = p.InsigniaNoteProfile.Status,
|
||||
p.InsigniaNoteProfile.Issue,
|
||||
p.InsigniaNoteProfile.Date,
|
||||
p.InsigniaNoteProfile.VolumeNo,
|
||||
p.InsigniaNoteProfile.Section,
|
||||
p.InsigniaNoteProfile.Page,
|
||||
p.InsigniaNoteProfile.No,
|
||||
p.InsigniaNoteProfile.DatePayment,
|
||||
p.InsigniaNoteProfile.TypePayment,
|
||||
p.InsigniaNoteProfile.Address,
|
||||
p.InsigniaNoteProfile.Number,
|
||||
p.InsigniaNoteProfile.Salary,
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var data = rawData
|
||||
.Select(p => new
|
||||
{
|
||||
p.Id,
|
||||
p.Status,
|
||||
BorrowOrganization = p.BorrowOrganization == null ? "" : p.BorrowOrganization.Root,
|
||||
BorrowOrganizationId = p.BorrowOrganization == null ? Guid.Empty : p.BorrowOrganization.RootId,
|
||||
p.BorrowDate,
|
||||
p.ReturnDate,
|
||||
ReturnOrganization = p.ReturnOrganization == null ? "" : p.ReturnOrganization.Root,
|
||||
ReturnOrganizationId = p.ReturnOrganization == null ? Guid.Empty : p.ReturnOrganization.RootId,
|
||||
p.ReturnReason,
|
||||
p.LastUpdatedAt,
|
||||
p.CreatedAt,
|
||||
p.InsigniaNoteProfileId,
|
||||
CitizenId = p.Profile == null ? "" : p.Profile.CitizenId,
|
||||
Prefix = p.Profile == null ? "" : p.Profile.Prefix,
|
||||
Position = p.Profile == null ? "" : p.Profile.Position,
|
||||
FullName = p.Profile == null ? "" : $"{p.Profile.Prefix}{p.Profile.FirstName} {p.Profile.LastName}",
|
||||
ProfileType = p.Profile == null ? "" : p.Profile.ProfileType,
|
||||
p.RequestInsignia,
|
||||
p.RequestInsigniaId,
|
||||
p.RequestInsigniaShortName,
|
||||
p.DateReceive,
|
||||
p.OrganizationOrganizationSend,
|
||||
p.OrganizationOrganizationReceive,
|
||||
p.InsigniaNoteProfileStatus,
|
||||
p.Issue,
|
||||
p.Date,
|
||||
p.VolumeNo,
|
||||
p.Section,
|
||||
p.Page,
|
||||
p.No,
|
||||
p.DatePayment,
|
||||
p.TypePayment,
|
||||
p.Address,
|
||||
p.Number,
|
||||
p.Salary,
|
||||
|
||||
})
|
||||
.ToList();
|
||||
|
||||
//var data = await _context.InsigniaManageProfiles.AsQueryable()
|
||||
// .Where(x => x.InsigniaNoteProfile.RequestInsignia.InsigniaType == insigniaType)
|
||||
// .Where(x => year == 0 ? x.Id != null : x.InsigniaManageOrganiation.InsigniaManage.Year == year)
|
||||
// .OrderByDescending(x => x.CreatedAt)
|
||||
// .Select(p => new
|
||||
// {
|
||||
// Id = p.Id,
|
||||
// Status = p.Status,
|
||||
// BorrowOrganization = _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken) == null ? null : _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken).Root,
|
||||
// BorrowOrganizationId = _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken) == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken).RootId,
|
||||
// BorrowDate = p.BorrowDate,
|
||||
// ReturnDate = p.ReturnDate,
|
||||
// ReturnOrganization = _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken) == null ? null : _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken).Root,
|
||||
// ReturnOrganizationId = _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken) == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken).RootId,
|
||||
// ReturnReason = p.ReturnReason,
|
||||
// LastUpdatedAt = p.LastUpdatedAt,
|
||||
// CreatedAt = p.CreatedAt,
|
||||
|
||||
// InsigniaNoteProfileId = p.InsigniaNoteProfile.Id,
|
||||
// Prefix = _userProfileRepository.GetOfficerProfileById(p.InsigniaNoteProfile.ProfileId.Value, AccessToken).Prefix,
|
||||
// Position = _userProfileRepository.GetOfficerProfileById(p.InsigniaNoteProfile.ProfileId.Value, AccessToken).Position,
|
||||
// _userProfileRepository.GetOfficerProfileById(p.InsigniaNoteProfile.ProfileId.Value, AccessToken).CitizenId,
|
||||
// _userProfileRepository.GetOfficerProfileById(p.InsigniaNoteProfile.ProfileId.Value, AccessToken).ProfileType,
|
||||
// FullName = $"{_userProfileRepository.GetOfficerProfileById(p.InsigniaNoteProfile.ProfileId.Value, AccessToken).Prefix}{_userProfileRepository.GetOfficerProfileById(p.InsigniaNoteProfile.ProfileId.Value, AccessToken).FirstName} {_userProfileRepository.GetOfficerProfileById(p.InsigniaNoteProfile.ProfileId.Value, AccessToken).LastName}",
|
||||
// RequestInsignia = p.InsigniaNoteProfile.RequestInsignia == null ? null : p.InsigniaNoteProfile.RequestInsignia.Name,
|
||||
// RequestInsigniaId = p.InsigniaNoteProfile.RequestInsignia == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.InsigniaNoteProfile.RequestInsignia.Id,
|
||||
// RequestInsigniaShortName = p.InsigniaNoteProfile.RequestInsignia == null ? null : p.InsigniaNoteProfile.RequestInsignia.ShortName,
|
||||
// p.InsigniaNoteProfile.DateReceive,
|
||||
// p.InsigniaNoteProfile.OrganizationOrganizationSend,
|
||||
// p.InsigniaNoteProfile.OrganizationOrganizationReceive,
|
||||
// InsigniaNoteProfileStatus = p.InsigniaNoteProfile.Status,
|
||||
// p.InsigniaNoteProfile.Issue,
|
||||
// p.InsigniaNoteProfile.Date,
|
||||
// p.InsigniaNoteProfile.VolumeNo,
|
||||
// p.InsigniaNoteProfile.Section,
|
||||
// p.InsigniaNoteProfile.Page,
|
||||
// p.InsigniaNoteProfile.No,
|
||||
// p.InsigniaNoteProfile.DatePayment,
|
||||
// p.InsigniaNoteProfile.TypePayment,
|
||||
// p.InsigniaNoteProfile.Address,
|
||||
// p.InsigniaNoteProfile.Number,
|
||||
// p.InsigniaNoteProfile.Salary,
|
||||
// })
|
||||
// .ToListAsync();
|
||||
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get รายการยืม/คืนเครื่องราชฯ
|
||||
/// </summary>
|
||||
/// <param name="insigniaManageProfileId">Id ประเภทเครื่องราชฯ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("borrow/{insigniaManageProfileId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetBorrowReturnInsignia(Guid insigniaManageProfileId)
|
||||
{
|
||||
var data = await _context.InsigniaManageProfiles.AsQueryable()
|
||||
.Where(x => x.Id == insigniaManageProfileId)
|
||||
.Select(p => new
|
||||
{
|
||||
Id = p.Id,
|
||||
Status = p.Status,
|
||||
BorrowOrganization = _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken) == null ? null : _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken).Root,
|
||||
BorrowOrganizationId = _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken) == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : _userProfileRepository.GetOc(p.BorrowOrganizationId!.Value, 0, AccessToken).RootId,
|
||||
BorrowDate = p.BorrowDate,
|
||||
ReturnDate = p.ReturnDate,
|
||||
ReturnOrganization = _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken) == null ? null : _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken).Root,
|
||||
ReturnOrganizationId = _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken) == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : _userProfileRepository.GetOc(p.ReturnOrganizationId!.Value, 0, AccessToken).RootId,
|
||||
ReturnReason = p.ReturnReason,
|
||||
LastUpdatedAt = p.LastUpdatedAt,
|
||||
CreatedAt = p.CreatedAt,
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
if (data == null)
|
||||
return Error(GlobalMessages.InsigniaBorrowNotFound);
|
||||
return Success(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
294
BMA.EHR.Insignia/Controllers/InsigniaPeriodController.cs
Normal file
294
BMA.EHR.Insignia/Controllers/InsigniaPeriodController.cs
Normal file
|
|
@ -0,0 +1,294 @@
|
|||
using System.Security.Claims;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Repositories.MessageQueue;
|
||||
using BMA.EHR.Application.Requests;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Models.Insignias;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/insignia/period")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
[SwaggerTag("รอบเครื่องราชฯ")]
|
||||
public class InsigniaPeriodController : BaseController
|
||||
{
|
||||
private readonly ApplicationDBContext _context;
|
||||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly InsigniaPeriodsRepository _repository;
|
||||
private readonly NotificationRepository _repositoryNoti;
|
||||
|
||||
public InsigniaPeriodController(ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
InsigniaPeriodsRepository repository,
|
||||
NotificationRepository repositoryNoti,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_repository = repository;
|
||||
_repositoryNoti = repositoryNoti;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
#region " Properties "
|
||||
|
||||
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// list รอบเครื่องราช
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet()]
|
||||
public async Task<ActionResult<ResponseObject>> GetList()
|
||||
{
|
||||
var insigniaPeriods = await _context.InsigniaPeriods.AsQueryable()
|
||||
// .Where(x => x.Type == type)
|
||||
.OrderByDescending(x => x.Year)
|
||||
.ThenByDescending(x => x.StartDate)
|
||||
.Select(p => new
|
||||
{
|
||||
period_id = p.Id,
|
||||
period_amount = p.Amount,
|
||||
period_name = p.Name,
|
||||
period_round = p.Round,
|
||||
period_start = p.StartDate,
|
||||
period_end = p.EndDate,
|
||||
period_status = p.IsLock == true ? "DONE" : (p.InsigniaRequests.Count() == 0 ? "WAITTING" : "PENDING"),
|
||||
period_year = p.Year,
|
||||
period_isActive = p.IsActive,
|
||||
period_doc = p.ReliefDoc == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.ReliefDoc.Id,
|
||||
})
|
||||
.ToListAsync();
|
||||
var data = new List<dynamic>();
|
||||
foreach (var insigniaPeriod in insigniaPeriods)
|
||||
{
|
||||
var _data = new
|
||||
{
|
||||
period_id = insigniaPeriod.period_id,
|
||||
period_amount = insigniaPeriod.period_amount,
|
||||
period_name = insigniaPeriod.period_name,
|
||||
period_round = insigniaPeriod.period_round,
|
||||
period_start = insigniaPeriod.period_start,
|
||||
period_end = insigniaPeriod.period_end,
|
||||
period_status = insigniaPeriod.period_status,
|
||||
period_year = insigniaPeriod.period_year,
|
||||
period_isActive = insigniaPeriod.period_isActive,
|
||||
period_doc = insigniaPeriod.period_doc == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(insigniaPeriod.period_doc),
|
||||
};
|
||||
data.Add(_data);
|
||||
}
|
||||
|
||||
return Success(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get รายละเอียดรอบเครื่องราช
|
||||
/// </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("{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetById(Guid id)
|
||||
{
|
||||
var data = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Where(x => x.Id == id)
|
||||
.Select(p => new
|
||||
{
|
||||
period_id = p.Id,
|
||||
period_amount = p.Amount,
|
||||
period_name = p.Name,
|
||||
period_round = p.Round,
|
||||
period_start = p.StartDate,
|
||||
period_end = p.EndDate,
|
||||
period_status = p.IsLock == true ? "DONE" : (p.InsigniaRequests.Count() == 0 ? "WAITTING" : "PENDING"),
|
||||
period_year = p.Year,
|
||||
period_isActive = p.IsActive,
|
||||
period_doc = p.ReliefDoc == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.ReliefDoc.Id,
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
if (data == null)
|
||||
return Error(GlobalMessages.DataNotFound, 404);
|
||||
|
||||
var _data = new
|
||||
{
|
||||
period_id = data.period_id,
|
||||
period_amount = data.period_amount,
|
||||
period_name = data.period_name,
|
||||
period_round = data.period_round,
|
||||
period_start = data.period_start,
|
||||
period_end = data.period_end,
|
||||
period_status = data.period_status,
|
||||
period_year = data.period_year,
|
||||
period_isActive = data.period_isActive,
|
||||
period_doc = data.period_doc == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.period_doc),
|
||||
};
|
||||
|
||||
return Success(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// สร้างรอบเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="req.Round">รอบที่</param>
|
||||
/// <param name="req.Name">ชื่อรอบ</param>
|
||||
/// <param name="req.Year">ปีที่เสนอ</param>
|
||||
/// <param name="req.StartDate">วันที่เริ่มต้น</param>
|
||||
/// <param name="req.EndDate">วันที่สิ้นสุด</param>
|
||||
/// <param name="req.Amount">จำนวนวันแจ้งเตือน</param>
|
||||
/// <param name="req.File">เอกสารประกอบ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost()]
|
||||
public async Task<ActionResult<ResponseObject>> Post([FromForm] InsigniaPeriodRequest req)
|
||||
{
|
||||
var insigniaPeriod = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Where(x => x.Round == req.Round && x.Year == req.Year)
|
||||
.FirstOrDefaultAsync();
|
||||
if (insigniaPeriod != null)
|
||||
return Error(GlobalMessages.InsigniaDupicate);
|
||||
|
||||
var period = new InsigniaPeriod
|
||||
{
|
||||
Round = req.Round,
|
||||
Name = req.Name,
|
||||
Year = req.Year,
|
||||
StartDate = req.StartDate,
|
||||
EndDate = req.EndDate,
|
||||
Amount = req.Amount,
|
||||
IsActive = true,
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
};
|
||||
await _context.InsigniaPeriods.AddAsync(period);
|
||||
await _context.SaveChangesAsync();
|
||||
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);
|
||||
period.ReliefDoc = doc;
|
||||
}
|
||||
|
||||
// await _context.InsigniaPeriods.AddAsync(period);
|
||||
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("{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> Delete(Guid id)
|
||||
{
|
||||
var deleted = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Include(x => x.ReliefDoc)
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
if (deleted == null)
|
||||
return NotFound();
|
||||
_context.InsigniaPeriods.Remove(deleted);
|
||||
await _context.SaveChangesAsync();
|
||||
if (deleted.ReliefDoc != null)
|
||||
await _documentService.DeleteFileAsync(deleted.ReliefDoc.Id);
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// แก้ไขรอบเครื่องราช
|
||||
/// </summary>
|
||||
/// <param name="id">Id เครื่องราช</param>
|
||||
/// <param name="req.Round">รอบที่</param>
|
||||
/// <param name="req.Name">ชื่อรอบ</param>
|
||||
/// <param name="req.Year">ปีที่เสนอ</param>
|
||||
/// <param name="req.StartDate">วันที่เริ่มต้น</param>
|
||||
/// <param name="req.EndDate">วันที่สิ้นสุด</param>
|
||||
/// <param name="req.Amount">จำนวนวันแจ้งเตือน</param>
|
||||
/// <param name="req.File">เอกสารประกอบ</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> Put([FromForm] InsigniaPeriodRequest req, Guid id)
|
||||
{
|
||||
if (req == null)
|
||||
return BadRequest();
|
||||
|
||||
var insigniaPeriod = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Where(x => x.Round == req.Round && x.Year == req.Year && x.Id != id)
|
||||
.FirstOrDefaultAsync();
|
||||
if (insigniaPeriod != null)
|
||||
return Error(GlobalMessages.InsigniaDupicate);
|
||||
|
||||
var uppdated = await _context.InsigniaPeriods.AsQueryable()
|
||||
.Include(x => x.ReliefDoc)
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
if (uppdated == null)
|
||||
return NotFound();
|
||||
|
||||
uppdated.Round = req.Round;
|
||||
uppdated.Name = req.Name;
|
||||
uppdated.Year = req.Year;
|
||||
uppdated.StartDate = req.StartDate;
|
||||
uppdated.EndDate = req.EndDate;
|
||||
uppdated.Amount = req.Amount;
|
||||
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
uppdated.LastUpdateUserId = UserId ?? "";
|
||||
uppdated.LastUpdatedAt = DateTime.Now;
|
||||
|
||||
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
|
||||
{
|
||||
if (uppdated.ReliefDoc != null)
|
||||
await _documentService.DeleteFileAsync(uppdated.ReliefDoc.Id);
|
||||
var file = Request.Form.Files[0];
|
||||
var fileExtension = Path.GetExtension(file.FileName);
|
||||
|
||||
var doc = await _documentService.UploadFileAsync(file, file.FileName);
|
||||
uppdated.ReliefDoc = doc;
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
}
|
||||
}
|
||||
248
BMA.EHR.Insignia/Controllers/InsigniaReceiveController.cs
Normal file
248
BMA.EHR.Insignia/Controllers/InsigniaReceiveController.cs
Normal file
|
|
@ -0,0 +1,248 @@
|
|||
using System.Security.Claims;
|
||||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Repositories.MessageQueue;
|
||||
using BMA.EHR.Application.Requests;
|
||||
using BMA.EHR.Application.Responses.Insignias;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Models.Insignias;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/insignia/receive")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
[SwaggerTag("เครื่องราช")]
|
||||
public class InsigniaReceiveController : BaseController
|
||||
{
|
||||
private readonly ApplicationDBContext _context;
|
||||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly InsigniaPeriodsRepository _repository;
|
||||
private readonly NotificationRepository _repositoryNoti;
|
||||
|
||||
private readonly UserProfileRepository _userProfileRepository;
|
||||
|
||||
public InsigniaReceiveController(ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
InsigniaPeriodsRepository repository,
|
||||
NotificationRepository repositoryNoti,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
UserProfileRepository userProfileRepository)
|
||||
{
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_repository = repository;
|
||||
_repositoryNoti = repositoryNoti;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_userProfileRepository = userProfileRepository;
|
||||
}
|
||||
|
||||
private string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
|
||||
|
||||
[HttpGet("{type}/{ocId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetInsigniaList(string type, Guid id, Guid ocId)
|
||||
{
|
||||
var result = _repository.GetInsigniaRequest(id, ocId);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
// var request = _context.InsigniaRequestProfiles
|
||||
// .Include(x => x.Request)
|
||||
// .ThenInclude(x => x.Period)
|
||||
// .Include(x => x.RequestInsignia)
|
||||
// .ThenInclude(x => x.InsigniaType)
|
||||
// .Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.AcademicStanding)
|
||||
// .Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.Position)
|
||||
// .Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.Insignias)
|
||||
// .ThenInclude(x => x.Insignia)
|
||||
// .ThenInclude(x => x.InsigniaType)
|
||||
// .Include(x => x.Profile)
|
||||
// .ThenInclude(x => x.PositionNumber)
|
||||
// .Where(x => x.Request.Period.Id == result.PeriodId)
|
||||
// .Where(x => x.Request.RequestStatus == "st5p")
|
||||
// .Where(x => x.IsApprove)
|
||||
// .Select(p => new
|
||||
// {
|
||||
// Profile = p.Profile.Id,
|
||||
// Name = $"{p.Profile.Prefix} {p.Profile.FirstName} {p.Profile.LastName}",
|
||||
// Insignia = p.RequestInsignia,
|
||||
// Type = p.RequestInsignia.InsigniaType,
|
||||
// IsApprove = p.IsApprove,
|
||||
// InsigniaId = p.RequestInsignia.Id,
|
||||
// Year = p.Request.Period.Year,
|
||||
// Special = p.Special,
|
||||
// LastInsignia = p.Profile.Insignias.AsQueryable()
|
||||
// .Include(x => x.Insignia)
|
||||
// .Where(x => x.Insignia.Id == p.RequestInsignia.Id)
|
||||
// .Where(x => x.Year == p.Request.Period.Year)
|
||||
// .FirstOrDefault()
|
||||
// })
|
||||
// .ToList()
|
||||
// .Select(r => new InsigniaReceiveResponse
|
||||
// {
|
||||
// Profile = r.Profile,
|
||||
// Name = r.Name,
|
||||
// Insignia = r.Insignia.Name,
|
||||
// TypeId = r.Type == null ? null : r.Type.Id,
|
||||
// TypeName = r.Type == null ? "" : r.Type.Description,
|
||||
// IsApprove = r.IsApprove,
|
||||
// InsigniaId = r.InsigniaId,
|
||||
// InsigniaPage = r.LastInsignia == null ? "" : r.LastInsignia.Page,
|
||||
// InsigniaNo = r.LastInsignia == null ? "" : r.LastInsignia.No,
|
||||
// InsigniaIssue = r.LastInsignia == null ? "" : r.LastInsignia.Issue,
|
||||
// InsigniaVolumeno = r.LastInsignia == null ? "" : r.LastInsignia.VolumeNo,
|
||||
// InsigniaVolume = r.LastInsignia == null ? "" : r.LastInsignia.Volume,
|
||||
// InsigniaSection = r.LastInsignia == null ? "" : r.LastInsignia.Section,
|
||||
// InsigniaDatereceive = r.LastInsignia == null ? null : r.LastInsignia.DateReceive,
|
||||
// InsigniaDateannounce = r.LastInsignia == null ? null : r.LastInsignia.DateAnnounce,
|
||||
// Special = r.Special
|
||||
// })
|
||||
// .ToList()
|
||||
// .GroupBy(r => new { r.TypeId, r.TypeName })
|
||||
// .Select(r => new
|
||||
// {
|
||||
// TypeId = r.Key.TypeId,
|
||||
// InsigniaIssue = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaIssue : "",
|
||||
// InsigniaVolumeno = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaVolumeno : null,
|
||||
// InsigniaVolume = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaVolume : "",
|
||||
// InsigniaSection = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaSection : "",
|
||||
// InsigniaDatereceive = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaDatereceive : null,
|
||||
// InsigniaDateannounce = r.Where(r => r.InsigniaIssue != "").FirstOrDefault() != null ? r.Where(r => r.InsigniaIssue != "").FirstOrDefault().InsigniaDateannounce : null,
|
||||
// TypeName = r.Key.TypeName,
|
||||
// Profile = r.Select(r => new
|
||||
// {
|
||||
// Profile = r.Profile,
|
||||
// Name = r.Name,
|
||||
// Insignia = r.Insignia,
|
||||
// InsigniaId = r.InsigniaId,
|
||||
// InsigniaPage = r.InsigniaPage,
|
||||
// InsigniaNo = r.InsigniaNo,
|
||||
// //Special = bool.Parse(r.Special)
|
||||
// }).ToList(),
|
||||
// Docs = new List<dynamic>()
|
||||
// });
|
||||
|
||||
return Success();
|
||||
// return Success(request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("{type}")]
|
||||
public async Task<ActionResult<ResponseObject>> SaveToProfile([FromBody] SaveToProfileRequest items, string type)
|
||||
{
|
||||
var item = new Kp7Item
|
||||
{
|
||||
InsigniaDatereceive = items.InsigniaDatereceive,
|
||||
InsigniaLevel = items.InsigniaLevel,
|
||||
InsigniaIssue = items.InsigniaIssue,
|
||||
InsigniaVolumeno = items.InsigniaVolumeno,
|
||||
InsigniaVolume = items.InsigniaVolume,
|
||||
InsigniaSection = items.InsigniaSection,
|
||||
InsigniaDateannounce = items.InsigniaDateannounce
|
||||
};
|
||||
|
||||
if (items.Profile.Count() != 0)
|
||||
{
|
||||
foreach(var p in items.Profile)
|
||||
{
|
||||
await _userProfileRepository.PostProfileInsigniaAsync(new PostProfileInsigniaDto
|
||||
{
|
||||
profileId = Guid.Parse(p.FkProfileId),
|
||||
year = item.InsigniaDateannounce.Value.Year,
|
||||
no = p.InsigniaNo,
|
||||
volume = item.InsigniaVolume,
|
||||
section = item.InsigniaSection,
|
||||
page = p.InsigniaPage,
|
||||
receiveDate = item.InsigniaDatereceive.Value,
|
||||
insigniaId = p.Kp7InsigniaId,
|
||||
dateAnnounce = item.InsigniaDateannounce.Value,
|
||||
issue = item.InsigniaIssue,
|
||||
volumeNo = item.InsigniaVolumeno.Value.ToString(),
|
||||
note = "",
|
||||
refCommandDate = null,
|
||||
refCommandNo = "",
|
||||
|
||||
}, AccessToken);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// foreach (var i in items.Profile)
|
||||
// {
|
||||
// var profile = _context.Profiles.AsQueryable()
|
||||
// .Include(x => x.Insignias)
|
||||
// .ThenInclude(x => x.Insignia)
|
||||
// .Where(x => x.Id == i.FkProfileId)
|
||||
// .FirstOrDefault();
|
||||
// if (profile != null)
|
||||
// {
|
||||
// var kp7 = profile.Insignias.AsQueryable()
|
||||
// .Where(x => x.Insignia.Id == i.Kp7InsigniaId)
|
||||
// .FirstOrDefault();
|
||||
|
||||
// if (kp7 != null)
|
||||
// {
|
||||
// // exit item update to database
|
||||
// kp7.DateReceive = items.InsigniaDatereceive.Value;
|
||||
// kp7.Level = items.InsigniaLevel;
|
||||
// kp7.Issue = items.InsigniaIssue;
|
||||
// kp7.VolumeNo = items.InsigniaVolumeno.Value.ToString();
|
||||
// kp7.Volume = items.InsigniaVolume;
|
||||
// kp7.Section = items.InsigniaSection;
|
||||
// kp7.DateAnnounce = items.InsigniaDateannounce.Value;
|
||||
// kp7.Page = i.InsigniaPage;
|
||||
// kp7.No = i.InsigniaNo;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // insert new item to kp7
|
||||
// var insignia_item = _context.Insignias.FirstOrDefault(x => x.Id == i.Kp7InsigniaId);
|
||||
// var result = _repository.GetInsigniaRequest(type, items.OCId);
|
||||
|
||||
// var period = _context.InsigniaPeriods.FirstOrDefault(x => x.Id == result.PeriodId);
|
||||
|
||||
// kp7 = new Models.HR.ProfileInsignia
|
||||
// {
|
||||
// Order = profile.Insignias.ToList().Count + 1,
|
||||
// Year = period.Year,
|
||||
// Insignia = insignia_item,
|
||||
// DateReceive = items.InsigniaDatereceive.Value,
|
||||
// DateStamp = DateTime.Now,
|
||||
// Level = items.InsigniaLevel,
|
||||
// Issue = items.InsigniaIssue,
|
||||
// VolumeNo = items.InsigniaVolumeno.Value.ToString(),
|
||||
// Volume = items.InsigniaVolume,
|
||||
// Section = items.InsigniaSection,
|
||||
// DateAnnounce = items.InsigniaDateannounce.Value,
|
||||
// Page = i.InsigniaPage,
|
||||
// No = i.InsigniaNo,
|
||||
// };
|
||||
// profile.Insignias.Add(kp7);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// return NotFound("Profile not found!!!");
|
||||
// }
|
||||
}
|
||||
//_context.SaveChanges();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
2524
BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs
Normal file
2524
BMA.EHR.Insignia/Controllers/InsigniaRequestController.cs
Normal file
File diff suppressed because it is too large
Load diff
27
BMA.EHR.Insignia/Dockerfile
Normal file
27
BMA.EHR.Insignia/Dockerfile
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
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.Insignia/BMA.EHR.Insignia.csproj", "BMA.EHR.Insignia/"]
|
||||
|
||||
RUN dotnet restore "BMA.EHR.Insignia/BMA.EHR.Insignia.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/BMA.EHR.Insignia"
|
||||
RUN dotnet build "BMA.EHR.Insignia.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "BMA.EHR.Insignia.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "BMA.EHR.Insignia.dll"]
|
||||
6214
BMA.EHR.Insignia/FileSql/Dump20230821.sql
Normal file
6214
BMA.EHR.Insignia/FileSql/Dump20230821.sql
Normal file
File diff suppressed because one or more lines are too long
16
BMA.EHR.Insignia/Filters/CustomAuthorizeFilter.cs
Normal file
16
BMA.EHR.Insignia/Filters/CustomAuthorizeFilter.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using Hangfire.Dashboard;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Filters
|
||||
{
|
||||
public class CustomAuthorizeFilter : IDashboardAuthorizationFilter
|
||||
{
|
||||
public bool Authorize([NotNull] DashboardContext context)
|
||||
{
|
||||
//var httpcontext = context.GetHttpContext();
|
||||
//return httpcontext.User.Identity.IsAuthenticated;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
207
BMA.EHR.Insignia/Program.cs
Normal file
207
BMA.EHR.Insignia/Program.cs
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
using BMA.EHR.Application;
|
||||
using BMA.EHR.Application.Repositories.Reports;
|
||||
using BMA.EHR.Domain.Middlewares;
|
||||
using BMA.EHR.Infrastructure;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using BMA.EHR.Insignia.Service;
|
||||
using BMA.EHR.Insignia.Service.Controllers;
|
||||
using BMA.EHR.Insignia.Service.Filters;
|
||||
using Hangfire;
|
||||
using Hangfire.Common;
|
||||
using Hangfire.MySql;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||
using Microsoft.AspNetCore.Mvc.Versioning;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Logging;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Serilog;
|
||||
using Serilog.Exceptions;
|
||||
using Serilog.Sinks.Elasticsearch;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Transactions;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
{
|
||||
var issuer = builder.Configuration["Jwt:Issuer"];
|
||||
var key = builder.Configuration["Jwt:Key"];
|
||||
|
||||
|
||||
IdentityModelEventSource.ShowPII = true;
|
||||
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
|
||||
builder.Services.AddApiVersioning(opt =>
|
||||
{
|
||||
opt.DefaultApiVersion = new ApiVersion(1, 0);
|
||||
opt.AssumeDefaultVersionWhenUnspecified = true;
|
||||
opt.ReportApiVersions = true;
|
||||
opt.ApiVersionReader = ApiVersionReader.Combine(new UrlSegmentApiVersionReader(),
|
||||
new HeaderApiVersionReader("x-api-version"),
|
||||
new MediaTypeApiVersionReader("x-api-version"));
|
||||
});
|
||||
|
||||
builder.Services.AddVersionedApiExplorer(setup =>
|
||||
{
|
||||
setup.GroupNameFormat = "'v'VVV";
|
||||
setup.SubstituteApiVersionInUrl = true;
|
||||
});
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
||||
// Authorization
|
||||
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(opt =>
|
||||
{
|
||||
opt.RequireHttpsMetadata = false; //false for dev
|
||||
opt.Authority = issuer;
|
||||
opt.TokenValidationParameters = new()
|
||||
{
|
||||
ValidateIssuer = true,
|
||||
ValidateAudience = false,
|
||||
ValidateLifetime = true,
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = issuer,
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key))
|
||||
};
|
||||
});
|
||||
builder.Services.AddAuthorization();
|
||||
|
||||
// use serilog
|
||||
ConfigureLogs();
|
||||
builder.Host.UseSerilog();
|
||||
|
||||
// Add config CORS
|
||||
builder.Services.AddCors(options => options.AddDefaultPolicy(builder =>
|
||||
{
|
||||
builder
|
||||
.AllowAnyOrigin()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader()
|
||||
.SetIsOriginAllowedToAllowWildcardSubdomains();
|
||||
}));
|
||||
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddApplication();
|
||||
builder.Services.AddPersistence(builder.Configuration);
|
||||
|
||||
builder.Services.AddLeaveApplication();
|
||||
builder.Services.AddLeavePersistence(builder.Configuration);
|
||||
|
||||
builder.Services.AddControllers(options =>
|
||||
{
|
||||
options.SuppressAsyncSuffixInActionNames = false;
|
||||
})
|
||||
.AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
|
||||
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.ConfigureOptions<ConfigureSwaggerOptions>();
|
||||
|
||||
// Register DbContext
|
||||
var defaultConnection = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||
builder.Services.AddDbContext<ApplicationDBContext>(options =>
|
||||
options.UseMySql(defaultConnection, ServerVersion.AutoDetect(defaultConnection)));
|
||||
builder.Services.AddHealthChecks();
|
||||
// Add Hangfire services.
|
||||
builder.Services.AddHangfire(configuration => configuration
|
||||
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
|
||||
.UseSimpleAssemblyNameTypeSerializer()
|
||||
.UseRecommendedSerializerSettings()
|
||||
.UseStorage(
|
||||
new MySqlStorage(
|
||||
defaultConnection,
|
||||
new MySqlStorageOptions
|
||||
{
|
||||
TransactionIsolationLevel = IsolationLevel.ReadCommitted,
|
||||
QueuePollInterval = TimeSpan.FromSeconds(15),
|
||||
JobExpirationCheckInterval = TimeSpan.FromHours(1),
|
||||
CountersAggregateInterval = TimeSpan.FromMinutes(5),
|
||||
PrepareSchemaIfNecessary = true,
|
||||
DashboardJobListLimit = 50000,
|
||||
TransactionTimeout = TimeSpan.FromMinutes(1),
|
||||
InvisibilityTimeout = TimeSpan.FromHours(3),
|
||||
TablesPrefix = "Hangfire"
|
||||
})));
|
||||
builder.Services.AddHangfireServer();
|
||||
}
|
||||
|
||||
var app = builder.Build();
|
||||
{
|
||||
var apiVersionDescriptionProvider = app.Services.GetRequiredService<IApiVersionDescriptionProvider>();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(options =>
|
||||
{
|
||||
foreach (var description in apiVersionDescriptionProvider.ApiVersionDescriptions)
|
||||
{
|
||||
options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json",
|
||||
description.GroupName.ToUpperInvariant());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
app.MapHealthChecks("/health");
|
||||
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseCors();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.UseDefaultFiles();
|
||||
app.UseStaticFiles();
|
||||
app.MapControllers();
|
||||
app.UseMiddleware<ErrorHandlerMiddleware>();
|
||||
app.UseHangfireDashboard("/hangfire", new DashboardOptions()
|
||||
{
|
||||
Authorization = new[] { new CustomAuthorizeFilter() }
|
||||
});
|
||||
var manager = new RecurringJobManager();
|
||||
if (manager != null)
|
||||
{
|
||||
manager.AddOrUpdate("แจ้งเตือนรอบเครื่องราชฯ", Job.FromExpression<InsigniaReportRepository>(x => x.NotifyInsignia()), Cron.Daily(Int32.Parse(builder.Configuration["KeycloakCron:Hour"]), Int32.Parse(builder.Configuration["KeycloakCron:Minute"])), TimeZoneInfo.Local);
|
||||
manager.AddOrUpdate("ล็อกข้อมูลรอบเครื่องราชฯ", Job.FromExpression<InsigniaReportRepository>(x => x.LockInsignia()), Cron.Daily(Int32.Parse(builder.Configuration["KeycloakCron:Hour"]), Int32.Parse(builder.Configuration["KeycloakCron:Minute"])), TimeZoneInfo.Local);
|
||||
manager.AddOrUpdate("คำนวนผู้ได้รับเครื่องราชฯ", Job.FromExpression<InsigniaReportRepository>(x => x.CalInsignaiRequestBkk()), Cron.Daily(Int32.Parse(builder.Configuration["KeycloakCron:Hour"]), Int32.Parse(builder.Configuration["KeycloakCron:Minute"])), TimeZoneInfo.Local);
|
||||
}
|
||||
|
||||
// apply migrations
|
||||
await using var scope = app.Services.CreateAsyncScope();
|
||||
await using var db = scope.ServiceProvider.GetRequiredService<ApplicationDBContext>();
|
||||
await db.Database.MigrateAsync();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
|
||||
void ConfigureLogs()
|
||||
{
|
||||
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
.AddJsonFile(
|
||||
$"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json",
|
||||
optional: true)
|
||||
.Build();
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.Enrich.FromLogContext()
|
||||
.MinimumLevel.Error()
|
||||
.WriteTo.Console()
|
||||
.Enrich.WithExceptionDetails()
|
||||
.WriteTo.Elasticsearch(ConfigureElasticSink(configuration, environment ?? ""))
|
||||
.Enrich.WithProperty("Environment", environment)
|
||||
.ReadFrom.Configuration(configuration)
|
||||
.CreateLogger();
|
||||
}
|
||||
|
||||
ElasticsearchSinkOptions ConfigureElasticSink(IConfigurationRoot configuration, string environment)
|
||||
{
|
||||
return new ElasticsearchSinkOptions(new Uri(configuration["ElasticConfiguration:Uri"] ?? ""))
|
||||
{
|
||||
AutoRegisterTemplate = true,
|
||||
IndexFormat = $"{Assembly.GetExecutingAssembly()?.GetName()?.Name?.ToLower().Replace(".", "-")}-{environment?.ToLower().Replace(".", "-")}"
|
||||
};
|
||||
}
|
||||
|
||||
48
BMA.EHR.Insignia/Properties/launchSettings.json
Normal file
48
BMA.EHR.Insignia/Properties/launchSettings.json
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5014"
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "https://localhost:7270;http://localhost:5014"
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"Docker": {
|
||||
"commandName": "Docker",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
|
||||
"publishAllPorts": true,
|
||||
"useSSL": true
|
||||
}
|
||||
},
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:11516",
|
||||
"sslPort": 44362
|
||||
}
|
||||
}
|
||||
}
|
||||
15
BMA.EHR.Insignia/Requests/AddUserRequestInsigniaRequest.cs
Normal file
15
BMA.EHR.Insignia/Requests/AddUserRequestInsigniaRequest.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Requests
|
||||
{
|
||||
public class AddUserRequestInsigniaRequest
|
||||
{
|
||||
public Guid ProfileId { get; set; }
|
||||
public Guid insigniaId { get; set; }
|
||||
public Guid insigniaPeriodId { get; set; }
|
||||
public string? Reason { get; set; }
|
||||
|
||||
public Guid OcId { get; set; }
|
||||
}
|
||||
}
|
||||
12
BMA.EHR.Insignia/Requests/ExportFileInsigniaRequest.cs
Normal file
12
BMA.EHR.Insignia/Requests/ExportFileInsigniaRequest.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Requests
|
||||
{
|
||||
public class ExportFileInsigniaRequest
|
||||
{
|
||||
public string? ProfileType { get; set; }
|
||||
public Guid? InsigniaId { get; set; }
|
||||
// public Guid? OrgId { get; set; }
|
||||
}
|
||||
}
|
||||
10
BMA.EHR.Insignia/Requests/ImportFileRequest.cs
Normal file
10
BMA.EHR.Insignia/Requests/ImportFileRequest.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Requests
|
||||
{
|
||||
public class ImportFileRequest
|
||||
{
|
||||
public List<FormFile>? File { get; set; }
|
||||
}
|
||||
}
|
||||
14
BMA.EHR.Insignia/Requests/ImportInvoiceRequest.cs
Normal file
14
BMA.EHR.Insignia/Requests/ImportInvoiceRequest.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Requests
|
||||
{
|
||||
public class ImportInvoiceRequest
|
||||
{
|
||||
public string? CitizanId { get; set; }
|
||||
public string? Number { get; set; }
|
||||
public DateTime? DatePayment { get; set; }
|
||||
public string? TypePayment { get; set; }
|
||||
public string? Address { get; set; }
|
||||
}
|
||||
}
|
||||
23
BMA.EHR.Insignia/Requests/ImportReceiveRequest.cs
Normal file
23
BMA.EHR.Insignia/Requests/ImportReceiveRequest.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Requests
|
||||
{
|
||||
public class ImportReceiveRequest
|
||||
{
|
||||
public string? Number { get; set; }
|
||||
public string? RequestInsignia { get; set; }
|
||||
public string? CitizanId { get; set; }
|
||||
public string? Prefix { get; set; }
|
||||
public string? FullName { get; set; }
|
||||
public string? Position { get; set; }
|
||||
public DateTime? DateReceive { get; set; }
|
||||
public string? OrgSend { get; set; }
|
||||
public string? OrgReceive { get; set; }
|
||||
public DateTime? Date { get; set; }
|
||||
public string? VolumeNo { get; set; }
|
||||
public string? Section { get; set; }
|
||||
public string? Page { get; set; }
|
||||
public string? No { get; set; }
|
||||
}
|
||||
}
|
||||
12
BMA.EHR.Insignia/Requests/InsigniaNoteDocRequest.cs
Normal file
12
BMA.EHR.Insignia/Requests/InsigniaNoteDocRequest.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Requests
|
||||
{
|
||||
public class InsigniaNoteDocRequest
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
public string? Reason { get; set; }
|
||||
public List<FormFile>? File { get; set; }
|
||||
}
|
||||
}
|
||||
10
BMA.EHR.Insignia/Requests/InsigniaNoteNameRequest.cs
Normal file
10
BMA.EHR.Insignia/Requests/InsigniaNoteNameRequest.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Requests
|
||||
{
|
||||
public class InsigniaNoteNameRequest
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
||||
25
BMA.EHR.Insignia/Requests/InsigniaNoteRequest.cs
Normal file
25
BMA.EHR.Insignia/Requests/InsigniaNoteRequest.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Requests
|
||||
{
|
||||
public class InsigniaNoteRequest
|
||||
{
|
||||
public string CitizanId { get; set; }
|
||||
public Guid? InsigniaId { get; set; }
|
||||
|
||||
public string? Issue { get; set; }
|
||||
public string? Number { get; set; }
|
||||
public DateTime? DateReceive { get; set; }
|
||||
public DateTime? Date { get; set; }
|
||||
public string? VolumeNo { get; set; }
|
||||
public string? Section { get; set; }
|
||||
public string? Page { get; set; }
|
||||
public string? No { get; set; }
|
||||
public DateTime? DatePayment { get; set; }
|
||||
public string? TypePayment { get; set; }
|
||||
public string? Address { get; set; }
|
||||
public string? OrganizationOrganizationSend { get; set; }
|
||||
public string? OrganizationOrganizationReceive { get; set; }
|
||||
}
|
||||
}
|
||||
12
BMA.EHR.Insignia/Requests/InsigniaNoteSearchRequest.cs
Normal file
12
BMA.EHR.Insignia/Requests/InsigniaNoteSearchRequest.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Requests
|
||||
{
|
||||
public class InsigniaNoteSearchRequest
|
||||
{
|
||||
public Guid InsigniaTypeId { get; set; }
|
||||
public Guid InsigniaNoteId { get; set; }
|
||||
public Guid? InsigniaId { get; set; }
|
||||
}
|
||||
}
|
||||
12
BMA.EHR.Insignia/Requests/InsigniaReturnRequest.cs
Normal file
12
BMA.EHR.Insignia/Requests/InsigniaReturnRequest.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Requests
|
||||
{
|
||||
public class InsigniaNoteReturnRequest
|
||||
{
|
||||
public List<FormFile>? File { get; set; }
|
||||
public DateTime? Date { get; set; }
|
||||
public Guid OrgId { get; set; }
|
||||
}
|
||||
}
|
||||
10
BMA.EHR.Insignia/Requests/RetirementReasonRequest.cs
Normal file
10
BMA.EHR.Insignia/Requests/RetirementReasonRequest.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Requests
|
||||
{
|
||||
public class InsigniaReasonRequest
|
||||
{
|
||||
public string Reason { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
using BMA.EHR.Domain.Models.MetaData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Insignia.Service.Requests
|
||||
{
|
||||
public class UpdateUserRequestInsigniaRequest
|
||||
{
|
||||
public Guid insigniaId { get; set; }
|
||||
}
|
||||
}
|
||||
77
BMA.EHR.Insignia/Services/NotifyService.cs
Normal file
77
BMA.EHR.Insignia/Services/NotifyService.cs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
// using System.Net.Http.Headers;
|
||||
// using BMA.EHR.Domain.Extensions;
|
||||
// using Microsoft.EntityFrameworkCore;
|
||||
// using Newtonsoft.Json;
|
||||
|
||||
// namespace BMA.EHR.Insignia.Service.Services
|
||||
// {
|
||||
// public class NotifyService
|
||||
// {
|
||||
// private readonly ApplicationDbContext _context;
|
||||
// private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
// private readonly IConfiguration _configuration;
|
||||
// private readonly AppointmentService _serviceAppoint;
|
||||
// private readonly AppointmentReserveLineService _serviceAppointRe;
|
||||
// public NotifyService(ApplicationDbContext context, IHttpContextAccessor httpContextAccessor, IConfiguration configuration, AppointmentService serviceAppoint, AppointmentReserveLineService serviceAppointRe) : base(httpContextAccessor)
|
||||
// {
|
||||
// _context = context;
|
||||
// _httpContextAccessor = httpContextAccessor;
|
||||
// _configuration = configuration;
|
||||
// _serviceAppoint = serviceAppoint;
|
||||
// _serviceAppointRe = serviceAppointRe;
|
||||
// }
|
||||
// public async Task<dynamic> notiAppointments()
|
||||
// {
|
||||
// Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
|
||||
// var data = await _context.Tb15AppointmentReserve.Where(x => x.AppointDate.ToDateTime(x.AppointTimeStart).Date == DateTime.Now.AddDays(1).Date).ToListAsync();
|
||||
// foreach (var _data in data)
|
||||
// {
|
||||
// var message = new
|
||||
// {
|
||||
// type = "text",
|
||||
// text = $"เรียน อาสาสมัคร\n พรุ่งนี้ท่านมีนัดกับโครงการศิริราชวันเฮลท์ที่ ชั้น 1 ตึกศูนย์วิจัยการแพทย์ศิริราช (SiMR) โครงการดำเนินการ เวลา {(_data.AppointDate).ToDateTime(_data.AppointTimeStart).ToShortTimeString()} - {(_data.AppointDate).ToDateTime(_data.AppointTimeEnd).ToShortTimeString()} น. ขอความกรุณา ดังนี้\n 1. 'ไม่ต้องงด' อาหารและเครื่องดื่ม\nท่านจะได้รับการตรวจน้ำตาลสะสม (A1C) และอื่น ๆ ตามปกติ ยกเว้น น้ำตาลในเลือดและอินซูลิน\n 2. ทำแบบสอบถาม ที่แถบเมนู “ทำแบบสอบถาม” ให้ครบ\n 3. แจ้งชื่อ-นามสกุล ณ จุดลงทะเบียน และแจ้งสถานะการเข้าร่วมโครงการจีโนมิกส์ประเทศไทย (จากรูปที่แคปไว้)\n 4. ดำเนินกิจกรรมทั้งหมด 6 ฐาน\n*เนื่องจากมีการวัดองค์ประกอบร่างกายด้วยเครื่อง BIA รบกวนหลีกเลี่ยงการใส่เครื่องประดับที่มีโลหะ\n\nหลังวันนัด\n 1. อาสาสมัครที่ผ่านเกณฑ์การตรวจอุจจาระ เจ้าหน้าที่จะติดต่อเพื่อนัดรับอุปกรณ์อีกครั้ง\n 2. เจ้าหน้าที่จะแจ้งผลตรวจตามที่อาสาสมัครตรวจจริงภายใน 2-3 เดือน"
|
||||
// };
|
||||
// if (_data.AppointTimeStart == TimeOnly.Parse("08:00"))
|
||||
// {
|
||||
// message = new
|
||||
// {
|
||||
// type = "text",
|
||||
// text = $"เรียน อาสาสมัคร\n พรุ่งนี้ท่านมีนัดกับโครงการศิริราชวันเฮลท์ที่ ชั้น 1 ตึกศูนย์วิจัยการแพทย์ศิริราช (SiMR) โครงการดำเนินการ เวลา {(_data.AppointDate).ToDateTime(_data.AppointTimeStart).ToShortTimeString()} - {(_data.AppointDate).ToDateTime(_data.AppointTimeEnd).ToShortTimeString()} น. ขอความกรุณา ดังนี้\n 1. งดอาหารและเครื่องดื่ม ยกเว้นน้ำเปล่า หลังเที่ยงคืน (หากท่านไม่สะดวกงดอาหาร ท่านจะไม่ได้รับการตรวจน้ำตาลในเลือดและอินซูลิน)\n 2. ทำแบบสอบถาม ที่แถบเมนู “ทำแบบสอบถาม” ให้ครบ\n 3. แจ้งชื่อ-นามสกุล ณ จุดลงทะเบียน และแจ้งสถานะการเข้าร่วมโครงการจีโนมิกส์ประเทศไทย (จากรูปที่แคปไว้)\n 4. ดำเนินกิจกรรมทั้งหมด 6 ฐาน\n*เนื่องจากมีการวัดองค์ประกอบร่างกายด้วยเครื่อง BIA รบกวนหลีกเลี่ยงการใส่เครื่องประดับที่มีโลหะ\n\nหลังวันนัด\n 1. อาสาสมัครที่ผ่านเกณฑ์การตรวจอุจจาระ เจ้าหน้าที่จะติดต่อเพื่อนัดรับอุปกรณ์อีกครั้ง\n 2. เจ้าหน้าที่จะแจ้งผลตรวจตามที่อาสาสมัครตรวจจริงภายใน 2-3 เดือน"
|
||||
// };
|
||||
// }
|
||||
// else if (_data.AppointTimeStart == TimeOnly.Parse("09:00"))
|
||||
// {
|
||||
// message = new
|
||||
// {
|
||||
// type = "text",
|
||||
// text = $"เรียน อาสาสมัคร\n พรุ่งนี้ท่านมีนัดกับโครงการศิริราชวันเฮลท์ที่ ชั้น 1 ตึกศูนย์วิจัยการแพทย์ศิริราช (SiMR) โครงการดำเนินการ เวลา {(_data.AppointDate).ToDateTime(_data.AppointTimeStart).ToShortTimeString()} - {(_data.AppointDate).ToDateTime(_data.AppointTimeEnd).ToShortTimeString()} น. ขอความกรุณา ดังนี้\n 1. 'ไม่ต้องงด' อาหารและเครื่องดื่ม\nท่านจะได้รับการตรวจน้ำตาลสะสม (A1C) และอื่น ๆ ตามปกติ ยกเว้น น้ำตาลในเลือดและอินซูลิน\n 2. ทำแบบสอบถาม ที่แถบเมนู “ทำแบบสอบถาม” ให้ครบ\n 3. แจ้งชื่อ-นามสกุล ณ จุดลงทะเบียน และแจ้งสถานะการเข้าร่วมโครงการจีโนมิกส์ประเทศไทย (จากรูปที่แคปไว้)\n 4. ดำเนินกิจกรรมทั้งหมด 6 ฐาน\n*เนื่องจากมีการวัดองค์ประกอบร่างกายด้วยเครื่อง BIA รบกวนหลีกเลี่ยงการใส่เครื่องประดับที่มีโลหะ\n\nหลังวันนัด\n 1. อาสาสมัครที่ผ่านเกณฑ์การตรวจอุจจาระ เจ้าหน้าที่จะติดต่อเพื่อนัดรับอุปกรณ์อีกครั้ง\n 2. เจ้าหน้าที่จะแจ้งผลตรวจตามที่อาสาสมัครตรวจจริงภายใน 2-3 เดือน"
|
||||
// };
|
||||
// }
|
||||
// Object[] messageArray = new Object[] { message };
|
||||
|
||||
// var profile = await _context.Tb1Profile.FirstOrDefaultAsync(x => x.UserId == _data.UserId);
|
||||
// if (profile != null && profile.LineId != null)
|
||||
// {
|
||||
// var result = new
|
||||
// {
|
||||
// to = profile.LineId,
|
||||
// messages = messageArray
|
||||
// };
|
||||
// using (var client = new HttpClient())
|
||||
// {
|
||||
// var json = JsonConvert.SerializeObject(result);
|
||||
// var _result = new StringContent(json, null, "application/json");
|
||||
// var url = "https://api.line.me/v2/bot/message/push";
|
||||
// // //HTTP POST
|
||||
// client.DefaultRequestHeaders.Authorization
|
||||
// = new AuthenticationHeaderValue("Bearer", _configuration["ACCESS_TOKEN"]);
|
||||
// var responseTask = client.PostAsync(url, _result);
|
||||
// var results = responseTask.Result;
|
||||
// // Console.WriteLine(results.Content.ReadAsStringAsync().Result);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return data;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
BIN
BMA.EHR.Insignia/Templates/PersonInsignia.xlsx
Normal file
BIN
BMA.EHR.Insignia/Templates/PersonInsignia.xlsx
Normal file
Binary file not shown.
8
BMA.EHR.Insignia/appsettings.Development.json
Normal file
8
BMA.EHR.Insignia/appsettings.Development.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
47
BMA.EHR.Insignia/appsettings.json
Normal file
47
BMA.EHR.Insignia/appsettings.json
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Override": {
|
||||
"Microsoft": "Information",
|
||||
"System": "Warning"
|
||||
}
|
||||
}
|
||||
},
|
||||
"ElasticConfiguration": {
|
||||
"Uri": "http://localhost:9200"
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
//"DefaultConnection": "User Id=sys;Password=P@ssw0rd;DBA Privilege=SYSDBA;Data Source=localhost:1521/ORCLCDB",
|
||||
//"DefaultConnection": "server=192.168.1.9;user=root;password=adminVM123;port=3306;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;"
|
||||
"DefaultConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;",
|
||||
"ExamConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_exam_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;",
|
||||
"LeaveConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_leave_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;",
|
||||
"DisciplineConnection": "server=192.168.1.80;user=root;password=adminVM123;port=3306;database=bma_ehr_discipline_demo;Convert Zero Datetime=True;Allow User Variables=true;Pooling=True;"
|
||||
},
|
||||
"Jwt": {
|
||||
"Key": "HP-FnQMUj9msHMSD3T9HtdEnphAKoCJLEl85CIqROFI",
|
||||
"Issuer": "https://id.frappet.synology.me/realms/bma-ehr"
|
||||
},
|
||||
"EPPlus": {
|
||||
"ExcelPackage": {
|
||||
"LicenseContext": "NonCommercial"
|
||||
}
|
||||
},
|
||||
"MinIO": {
|
||||
"Endpoint": "https://s3cluster.frappet.com/",
|
||||
"AccessKey": "frappet",
|
||||
"SecretKey": "FPTadmin2357",
|
||||
"BucketName": "bma-ehr-fpt"
|
||||
},
|
||||
"KeycloakCron": {
|
||||
"Hour": "08",
|
||||
"Minute": "00"
|
||||
},
|
||||
"Protocol": "HTTPS",
|
||||
"Node": {
|
||||
"API": "https://bma-ehr.frappet.synology.me/api/v1/probation"
|
||||
},
|
||||
"API": "https://bma-ehr.frappet.synology.me/api/v1"
|
||||
}
|
||||
8
BMA.EHR.Insignia/nuget.config
Normal file
8
BMA.EHR.Insignia/nuget.config
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
|
||||
<clear />
|
||||
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
184
BMA.EHR.Insignia/wwwroot/index.html
Normal file
184
BMA.EHR.Insignia/wwwroot/index.html
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
<!--
|
||||
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||
~ and other contributors as indicated by the @author tags.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<script src="./keycloak.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div>
|
||||
<button onclick="keycloak.login()">Login</button>
|
||||
<button onclick="keycloak.login({ action: 'UPDATE_PASSWORD' })">Update Password</button>
|
||||
<button onclick="keycloak.logout()">Logout</button>
|
||||
<button onclick="keycloak.register()">Register</button>
|
||||
<button onclick="keycloak.accountManagement()">Account</button>
|
||||
<button onclick="refreshToken(9999)">Refresh Token</button>
|
||||
<button onclick="refreshToken(30)">Refresh Token (if <30s validity)</button>
|
||||
<button onclick="loadProfile()">Get Profile</button>
|
||||
<button onclick="updateProfile()">Update profile</button>
|
||||
<button onclick="loadUserInfo()">Get User Info</button>
|
||||
<button onclick="output(keycloak.tokenParsed)">Show Token</button>
|
||||
<button onclick="output(keycloak.refreshTokenParsed)">Show Refresh Token</button>
|
||||
<button onclick="output(keycloak.idTokenParsed)">Show ID Token</button>
|
||||
<button onclick="showExpires()">Show Expires</button>
|
||||
<button onclick="output(keycloak)">Show Details</button>
|
||||
<button onclick="output(keycloak.createLoginUrl())">Show Login URL</button>
|
||||
<button onclick="output(keycloak.createLogoutUrl())">Show Logout URL</button>
|
||||
<button onclick="output(keycloak.createRegisterUrl())">Show Register URL</button>
|
||||
<button onclick="output(keycloak.createAccountUrl())">Show Account URL</button>
|
||||
|
||||
</div>
|
||||
|
||||
<h2>Result</h2>
|
||||
<pre style="background-color: #ddd; border: 1px solid #ccc; padding: 10px; word-wrap: break-word; white-space: pre-wrap;" id="output"></pre>
|
||||
|
||||
<h2>Events</h2>
|
||||
<pre style="background-color: #ddd; border: 1px solid #ccc; padding: 10px; word-wrap: break-word; white-space: pre-wrap;" id="events"></pre>
|
||||
|
||||
|
||||
<script>
|
||||
function loadProfile() {
|
||||
keycloak.loadUserProfile().success(function(profile) {
|
||||
output(profile);
|
||||
}).error(function() {
|
||||
output('Failed to load profile');
|
||||
});
|
||||
}
|
||||
|
||||
function updateProfile() {
|
||||
var url = keycloak.createAccountUrl().split('?')[0];
|
||||
var req = new XMLHttpRequest();
|
||||
req.open('POST', url, true);
|
||||
req.setRequestHeader('Accept', 'application/json');
|
||||
req.setRequestHeader('Content-Type', 'application/json');
|
||||
req.setRequestHeader('Authorization', 'bearer ' + keycloak.token);
|
||||
|
||||
req.onreadystatechange = function () {
|
||||
if (req.readyState == 4) {
|
||||
if (req.status == 200) {
|
||||
output('Success');
|
||||
} else {
|
||||
output('Failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
req.send('{"email":"myemail@foo.bar","firstName":"test","lastName":"bar"}');
|
||||
}
|
||||
|
||||
function loadUserInfo() {
|
||||
keycloak.loadUserInfo().success(function(userInfo) {
|
||||
output(userInfo);
|
||||
}).error(function() {
|
||||
output('Failed to load user info');
|
||||
});
|
||||
}
|
||||
|
||||
function refreshToken(minValidity) {
|
||||
keycloak.updateToken(minValidity).then(function(refreshed) {
|
||||
if (refreshed) {
|
||||
output(keycloak.tokenParsed);
|
||||
} else {
|
||||
output('Token not refreshed, valid for ' + Math.round(keycloak.tokenParsed.exp + keycloak.timeSkew - new Date().getTime() / 1000) + ' seconds');
|
||||
}
|
||||
}).catch(function() {
|
||||
output('Failed to refresh token');
|
||||
});
|
||||
}
|
||||
|
||||
function showExpires() {
|
||||
if (!keycloak.tokenParsed) {
|
||||
output("Not authenticated");
|
||||
return;
|
||||
}
|
||||
|
||||
var o = 'Token Expires:\t\t' + new Date((keycloak.tokenParsed.exp + keycloak.timeSkew) * 1000).toLocaleString() + '\n';
|
||||
o += 'Token Expires in:\t' + Math.round(keycloak.tokenParsed.exp + keycloak.timeSkew - new Date().getTime() / 1000) + ' seconds\n';
|
||||
|
||||
if (keycloak.refreshTokenParsed) {
|
||||
o += 'Refresh Token Expires:\t' + new Date((keycloak.refreshTokenParsed.exp + keycloak.timeSkew) * 1000).toLocaleString() + '\n';
|
||||
o += 'Refresh Expires in:\t' + Math.round(keycloak.refreshTokenParsed.exp + keycloak.timeSkew - new Date().getTime() / 1000) + ' seconds';
|
||||
}
|
||||
|
||||
output(o);
|
||||
}
|
||||
|
||||
function output(data) {
|
||||
if (typeof data === 'object') {
|
||||
data = JSON.stringify(data, null, ' ');
|
||||
}
|
||||
document.getElementById('output').innerHTML = data;
|
||||
}
|
||||
|
||||
function event(event) {
|
||||
var e = document.getElementById('events').innerHTML;
|
||||
document.getElementById('events').innerHTML = new Date().toLocaleString() + "\t" + event + "\n" + e;
|
||||
}
|
||||
|
||||
var keycloak = Keycloak();
|
||||
|
||||
keycloak.onAuthSuccess = function () {
|
||||
event('Auth Success');
|
||||
};
|
||||
|
||||
keycloak.onAuthError = function (errorData) {
|
||||
event("Auth Error: " + JSON.stringify(errorData) );
|
||||
};
|
||||
|
||||
keycloak.onAuthRefreshSuccess = function () {
|
||||
event('Auth Refresh Success');
|
||||
};
|
||||
|
||||
keycloak.onAuthRefreshError = function () {
|
||||
event('Auth Refresh Error');
|
||||
};
|
||||
|
||||
keycloak.onAuthLogout = function () {
|
||||
event('Auth Logout');
|
||||
};
|
||||
|
||||
keycloak.onTokenExpired = function () {
|
||||
event('Access token expired.');
|
||||
};
|
||||
|
||||
keycloak.onActionUpdate = function (status) {
|
||||
switch (status) {
|
||||
case 'success':
|
||||
event('Action completed successfully'); break;
|
||||
case 'cancelled':
|
||||
event('Action cancelled by user'); break;
|
||||
case 'error':
|
||||
event('Action failed'); break;
|
||||
}
|
||||
};
|
||||
|
||||
// Flow can be changed to 'implicit' or 'hybrid', but then client must enable implicit flow in admin console too
|
||||
var initOptions = {
|
||||
responseMode: 'fragment',
|
||||
flow: 'standard'
|
||||
};
|
||||
|
||||
keycloak.init(initOptions).then(function(authenticated) {
|
||||
output('Init Success (' + (authenticated ? 'Authenticated' : 'Not Authenticated') + ')');
|
||||
}).catch(function() {
|
||||
output('Init Error');
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
1766
BMA.EHR.Insignia/wwwroot/keycloak.js
Normal file
1766
BMA.EHR.Insignia/wwwroot/keycloak.js
Normal file
File diff suppressed because one or more lines are too long
7
BMA.EHR.Insignia/wwwroot/keycloak.json
Normal file
7
BMA.EHR.Insignia/wwwroot/keycloak.json
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"realm": "bma-ehr",
|
||||
"auth-server-url": "https://id.frappet.synology.me",
|
||||
"ssl-required": "external",
|
||||
"resource": "bma-ehr",
|
||||
"public-client": true
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue