api จัดสรรเครื่องราช

This commit is contained in:
Kittapath 2023-08-18 14:35:45 +07:00
parent d30030141a
commit d5ffd5cb08
9 changed files with 15307 additions and 3 deletions

View file

@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Application.Requests
{
public class InsigniaManageRequest
{
public Guid Insignia { get; set; }
public int Year { get; set; }
public int Total { get; set; }
public string Type { get; set; }
}
}

View file

@ -0,0 +1,21 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using BMA.EHR.Domain.Models.Base;
using System.ComponentModel.DataAnnotations.Schema;
using BMA.EHR.Domain.Models.Documents;
using BMA.EHR.Domain.Models.MetaData;
namespace BMA.EHR.Domain.Models.Insignias
{
public class InsigniaManage : EntityBase
{
[Comment("ชื่อเครื่องราช")]
public Insignia Insignia { get; set; }
[Comment("ปี")]
public int Year { get; set; }
[Comment("จำนวนทั้งหมด")]
public int Total { get; set; }
[Comment("ประเภทเครื่องราช")]
public string Type { get; set; }
}
}

View file

@ -39,6 +39,7 @@
public static readonly string RelationshipNotFound = "ไม่พบข้อมูลความสัมพันธ์";
public static readonly string BloodGroupNotFound = "ไม่พบข้อมูลกลุ่มเลือก";
public static readonly string ReligionNotFound = "ไม่พบข้อมูลศาสนา";
public static readonly string InsigniaNotFound = "ไม่พบข้อมูลเครื่องราชย์ฯ";
#endregion
@ -75,8 +76,10 @@
#region " Insignia "
public static readonly string InsigniaDupicate = "มีการยื่นรอบรอบนี้ในปีนี้ไว้อยู่แล้ว";
public static readonly string InsigniaRequestNotFound = "ไม่พบข้อมูลการยื่นขอพระราชทานเครื่องราชย์ของหน่วยงานที่ระบุ!!";
public static readonly string InsigniaPeriodNotFound = "ไม่พบรอบการยื่นขอพระราชทานเครื่องราชย์อิสริยาภรณ์";
public static readonly string InsigniaManageDupicate = "มีการกำหนดจัดสรรเครื่องราชย์ฯ รอบนี้ในปีนี้ไว้อยู่แล้ว";
public static readonly string InsigniaRequestNotFound = "ไม่พบข้อมูลการยื่นขอพระราชทานเครื่องราชย์ฯ ของหน่วยงานที่ระบุ!!";
public static readonly string InsigniaPeriodNotFound = "ไม่พบรอบการยื่นขอพระราชทานเครื่องราชย์อิสริยาภรณ์ฯ ";
public static readonly string InsigniaManageNotFound = "ไม่พบจัดสรรเครื่องราชย์ฯ ที่ระบุ";
public static readonly string CoinPeriodNotFound = "ไม่พบรอบการขอพระราชทานเหรียญจักรพรรดิมาลาที่ระบุ!!";
public static readonly string OCNotFound = "ไม่พบหน่วยงานที่ระบุในระบบ";
#endregion

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,60 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class addtableinsigniamanage : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "InsigniaManages",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, comment: "PrimaryKey", collation: "ascii_general_ci"),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "สร้างข้อมูลเมื่อ"),
CreatedUserId = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false, comment: "User Id ที่สร้างข้อมูล")
.Annotation("MySql:CharSet", "utf8mb4"),
LastUpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "แก้ไขข้อมูลล่าสุดเมื่อ"),
LastUpdateUserId = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: false, comment: "User Id ที่แก้ไขข้อมูลล่าสุด")
.Annotation("MySql:CharSet", "utf8mb4"),
CreatedFullName = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "ชื่อ User ที่สร้างข้อมูล")
.Annotation("MySql:CharSet", "utf8mb4"),
LastUpdateFullName = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "ชื่อ User ที่แก้ไขข้อมูลล่าสุด")
.Annotation("MySql:CharSet", "utf8mb4"),
InsigniaId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
Year = table.Column<int>(type: "int", nullable: false, comment: "ปี"),
Total = table.Column<int>(type: "int", nullable: false, comment: "จำนวนทั้งหมด"),
Type = table.Column<string>(type: "longtext", nullable: false, comment: "ประเภทเครื่องราช")
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
{
table.PrimaryKey("PK_InsigniaManages", x => x.Id);
table.ForeignKey(
name: "FK_InsigniaManages_Insignias_InsigniaId",
column: x => x.InsigniaId,
principalTable: "Insignias",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_InsigniaManages_InsigniaId",
table: "InsigniaManages",
column: "InsigniaId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "InsigniaManages");
}
}
}

View file

@ -5131,6 +5131,76 @@ namespace BMA.EHR.Infrastructure.Migrations
b.ToTable("TypeLeaves");
});
modelBuilder.Entity("BMA.EHR.Domain.Models.Insignias.InsigniaManage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)")
.HasColumnOrder(0)
.HasComment("PrimaryKey")
.HasAnnotation("Relational:JsonPropertyName", "id");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)")
.HasColumnOrder(100)
.HasComment("สร้างข้อมูลเมื่อ");
b.Property<string>("CreatedFullName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("varchar(200)")
.HasColumnOrder(104)
.HasComment("ชื่อ User ที่สร้างข้อมูล");
b.Property<string>("CreatedUserId")
.IsRequired()
.HasMaxLength(40)
.HasColumnType("varchar(40)")
.HasColumnOrder(101)
.HasComment("User Id ที่สร้างข้อมูล");
b.Property<Guid>("InsigniaId")
.HasColumnType("char(36)");
b.Property<string>("LastUpdateFullName")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("varchar(200)")
.HasColumnOrder(105)
.HasComment("ชื่อ User ที่แก้ไขข้อมูลล่าสุด");
b.Property<string>("LastUpdateUserId")
.IsRequired()
.HasMaxLength(40)
.HasColumnType("varchar(40)")
.HasColumnOrder(103)
.HasComment("User Id ที่แก้ไขข้อมูลล่าสุด");
b.Property<DateTime?>("LastUpdatedAt")
.HasColumnType("datetime(6)")
.HasColumnOrder(102)
.HasComment("แก้ไขข้อมูลล่าสุดเมื่อ");
b.Property<int>("Total")
.HasColumnType("int")
.HasComment("จำนวนทั้งหมด");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("longtext")
.HasComment("ประเภทเครื่องราช");
b.Property<int>("Year")
.HasColumnType("int")
.HasComment("ปี");
b.HasKey("Id");
b.HasIndex("InsigniaId");
b.ToTable("InsigniaManages");
});
modelBuilder.Entity("BMA.EHR.Domain.Models.Insignias.InsigniaPeriod", b =>
{
b.Property<Guid>("Id")
@ -13425,6 +13495,17 @@ namespace BMA.EHR.Infrastructure.Migrations
b.Navigation("ProfileTraining");
});
modelBuilder.Entity("BMA.EHR.Domain.Models.Insignias.InsigniaManage", b =>
{
b.HasOne("BMA.EHR.Domain.Models.MetaData.Insignia", "Insignia")
.WithMany()
.HasForeignKey("InsigniaId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Insignia");
});
modelBuilder.Entity("BMA.EHR.Domain.Models.Insignias.InsigniaPeriod", b =>
{
b.HasOne("BMA.EHR.Domain.Models.Documents.Document", "ReliefDoc")

View file

@ -306,6 +306,7 @@ namespace BMA.EHR.Infrastructure.Persistence
public DbSet<InsigniaRequest> InsigniaRequests { get; set; }
public DbSet<InsigniaRequestProfile> InsigniaRequestProfiles { get; set; }
public DbSet<InsigniaManage> InsigniaManages { get; set; }
#endregion

View file

@ -0,0 +1,225 @@
using System.Security.Claims;
using BMA.EHR.Application.Repositories;
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 Newtonsoft.Json;
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 string Royal_Type = "Royal";
public InsigniaManageController(ApplicationDBContext context,
MinIOService documentService,
InsigniaPeriodsRepository repository,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_documentService = documentService;
_repository = repository;
_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>
/// <param name="type">ประเภทเครื่องราช(insignia=เครื่องราช,coin=เหรียญ)</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("{type}")]
public async Task<ActionResult<ResponseObject>> GetList(string type)
{
var data = await _context.InsigniaManages.AsQueryable()
.Where(x => x.Type == type.Trim().ToUpper())
.OrderByDescending(x => x.Year)
.Select(p => new
{
Id = p.Id,
Insignia = p.Insignia.Name,
InsigniaId = p.Insignia.Id,
Year = p.Year,
Total = p.Total,
Type = p.Type,
LastUpdatedAt = p.LastUpdatedAt,
CreatedAt = p.CreatedAt,
})
.ToListAsync();
return Success(data);
}
/// <summary>
/// get รายละเอียดจัดสรรเครื่องราช
/// </summary>
/// <param name="id">Id จัดสรรเครื่องราช</param>
/// <param name="type">ประเภทเครื่องราช(insignia=เครื่องราช,coin=เหรียญ)</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("{type}/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> GetById(string type, Guid id)
{
var data = await _context.InsigniaManages.AsQueryable()
.Where(x => x.Type == type.Trim().ToUpper())
.Where(x => x.Id == id)
.Select(p => new
{
Id = p.Id,
Insignia = p.Insignia.Name,
InsigniaId = p.Insignia.Id,
Year = p.Year,
Total = p.Total,
Type = p.Type,
LastUpdatedAt = p.LastUpdatedAt,
CreatedAt = p.CreatedAt,
})
.FirstOrDefaultAsync();
if (data == null)
return Error(GlobalMessages.InsigniaManageNotFound, 404);
return Success(data);
}
/// <summary>
/// สร้างจัดสรรเครื่องราช
/// </summary>
/// <param name="type">ประเภทเครื่องราช(insignia=เครื่องราช,coin=เหรียญ)</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("{type}")]
public async Task<ActionResult<ResponseObject>> Post([FromForm] InsigniaManageRequest req, string type)
{
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.InsigniaManageNotFound);
var period = new InsigniaManage
{
Insignia = insignia,
Year = req.Year,
Total = req.Total,
Type = type.Trim().ToUpper(),
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.InsigniaManages.AddAsync(period);
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// ลบจัดสรรเครื่องราช
/// </summary>
/// <param name="id">Id จัดสรรเครื่องราช</param>
/// <param name="type">ประเภทเครื่องราช(insignia=เครื่องราช,coin=เหรียญ)</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpDelete("{type}/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> Delete(Guid id, string type)
{
var deleted = await _context.InsigniaManages.AsQueryable()
.Where(x => x.Type == type.Trim().ToUpper())
.Where(x => x.Id == id)
.FirstOrDefaultAsync();
if (deleted == null)
return Error(GlobalMessages.InsigniaManageNotFound);
_context.InsigniaManages.Remove(deleted);
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// แก้ไขจัดสรรเครื่องราช
/// </summary>
/// <param name="id">Id จัดสรรเครื่องราช</param>
/// <param name="type">ประเภทเครื่องราช(insignia=เครื่องราช,coin=เหรียญ)</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("{type}/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> Put([FromForm] InsigniaManageRequest req, Guid id, string type)
{
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 != id)
.FirstOrDefaultAsync();
if (insigniaManage != null)
return Error(GlobalMessages.InsigniaManageNotFound);
var uppdated = await _context.InsigniaManages.AsQueryable()
.Include(x => x.Insignia)
.FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null)
return Error(GlobalMessages.InsigniaManageNotFound);
uppdated.Insignia = insignia;
uppdated.Year = req.Year;
uppdated.Total = req.Total;
uppdated.Type = type.Trim().ToUpper();
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync();
return Success();
}
}
}

View file

@ -260,7 +260,7 @@ namespace BMA.EHR.Insignia.Service.Controllers
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("{insigniaPeriodId:length(36)}/{role}/{status}")]
[HttpGet("{insigniaPeriodId:length(36)}/{ocId:length(36)}/{role}/{status}")]
public async Task<ActionResult<ResponseObject>> GetInsignaiRequestBkk(Guid insigniaPeriodId, Guid ocId, string role, string status)
{
// var profile = await _context.Profiles.AsQueryable()