Check in and Check Out

This commit is contained in:
Suphonchai Phoonsawat 2023-11-13 15:26:14 +07:00
parent 065314fd6c
commit 8bf646230a
7 changed files with 769 additions and 50 deletions

View file

@ -12,6 +12,8 @@ using Amazon;
using BMA.EHR.Domain.Models.Organizations;
using MimeTypes;
using Profile = BMA.EHR.Domain.Models.HR.Profile;
using System.IO;
using Amazon.S3.Transfer;
namespace BMA.EHR.Application.Repositories
{
@ -238,6 +240,42 @@ namespace BMA.EHR.Application.Repositories
#endregion
private async Task<bool> IsExistBucketAsync(string bucketName)
{
try
{
var response = await _s3Client.ListObjectsV2Async(new ListObjectsV2Request
{
BucketName = bucketName
});
return true;
}
catch
{
return false;
}
}
private async Task<bool> CreateBucketAsync(string bucketName)
{
try
{
var request = new PutBucketRequest
{
BucketName = bucketName,
UseClientRegion = true,
};
var response = await _s3Client.PutBucketAsync(request);
return response.HttpStatusCode == System.Net.HttpStatusCode.OK;
}
catch
{
return false;
}
}
public List<Guid> GetAllIdByRoot(Guid? id)
{
try
@ -315,6 +353,33 @@ namespace BMA.EHR.Application.Repositories
}
}
public async Task UploadFileAsync(string fileName, MemoryStream fileStream)
{
try
{
//var fileTransferUtility = new TransferUtility(_s3Client);
var fileExt = Path.GetExtension(fileName);
var fileType = MimeTypeMap.GetMimeType(fileExt);
var file_name = Path.GetFileName(fileName);
var request = new PutObjectRequest
{
BucketName = _bucketName,
Key = file_name,
InputStream = fileStream,
ContentType = fileType,
CannedACL = S3CannedACL.BucketOwnerFullControl
};
await _s3Client.PutObjectAsync(request);
}
catch
{
throw;
}
}
public async Task UploadFileAsync(string fileName, string subFolder)
{
try
@ -325,11 +390,6 @@ namespace BMA.EHR.Application.Repositories
var fileExt = Path.GetExtension(fileName);
var fileType = MimeTypeMap.GetMimeType(fileExt);
var file_name = Path.GetFileName(fileName);
Console.WriteLine($"{_bucketName}{subFolder}");
Console.WriteLine(fileName);
Console.WriteLine(file_name);
Console.WriteLine(filestream);
Console.WriteLine(fileType);
var request = new PutObjectRequest
{

View file

@ -18,27 +18,48 @@ namespace BMA.EHR.Domain.Models.Leave.TimeAttendants
[Required, Comment("นำไปประมวลผลแล้วหรือยัง")]
public bool IsProcess { get; set; } = false;
[Required, Comment("พิกัดละติจูด")]
public double Lat { get; set; } = 0;
[Required, Comment("พิกัดละติจูด Check-In")]
public double CheckInLat { get; set; } = 0;
[Required, Comment("พิกัดลองจิจูด")]
public double Lon { get; set; } = 0;
[Required, Comment("พิกัดลองจิจูด Check-In")]
public double CheckInLon { get; set; } = 0;
[Required, Comment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์")]
public string POI { get; set; } = string.Empty;
[Required, Comment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-In")]
public string CheckInPOI { get; set; } = string.Empty;
[Required, Comment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง")]
public bool IsLocation { get; set; } = true;
[Required, Comment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-In")]
public bool IsLocationCheckIn { get; set; } = true;
[Comment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่")]
public string? LocationName { get; set; } = string.Empty;
[Comment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-In")]
public string? CheckInLocationName { get; set; } = string.Empty;
[Required, Comment("รูปถ่ายสถานที่ checkin/checkout")]
public string ImageUrl { get; set; } = string.Empty;
[Required, Comment("รูปถ่ายสถานที่ Check-In")]
public string CheckInImageUrl { get; set; } = string.Empty;
[Comment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-In")]
public string? CheckInRemark { get; set; } = string.Empty;
[Required, Comment("พิกัดละติจูด Check-Out")]
public double CheckOutLat { get; set; } = 0;
[Required, Comment("พิกัดลองจิจูด Check-Out")]
public double CheckOutLon { get; set; } = 0;
[Required, Comment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-Out")]
public string CheckOutPOI { get; set; } = string.Empty;
[Required, Comment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-Out")]
public bool IsLocationCheckOut { get; set; } = true;
[Comment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-Out")]
public string? CheckOutLocationName { get; set; } = string.Empty;
[Required, Comment("รูปถ่ายสถานที่ Check-Out")]
public string CheckOutImageUrl { get; set; } = string.Empty;
[Comment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-Out")]
public string? CheckOutRemark { get; set; } = string.Empty;
[Comment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้)")]
public string? Remark { get; set; } = string.Empty;
}
}

View file

@ -0,0 +1,240 @@
// <auto-generated />
using System;
using BMA.EHR.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
{
[DbContext(typeof(LeaveDbContext))]
[Migration("20231113082133_ update field user timestamps (add) ")]
partial class updatefieldusertimestampsadd
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.9")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.DutyTime", 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<string>("Description")
.IsRequired()
.HasColumnType("longtext")
.HasComment("คำอธิบาย");
b.Property<string>("EndTimeAfternoon")
.IsRequired()
.HasColumnType("longtext")
.HasComment("เวลาออกงานช่วงบ่าย");
b.Property<string>("EndTimeMorning")
.IsRequired()
.HasColumnType("longtext")
.HasComment("เวลาออกงานช่วงเช้า");
b.Property<bool>("IsActive")
.HasColumnType("tinyint(1)")
.HasComment("สถานะการเปิดใช้งาน (เปิด/ปิด)");
b.Property<bool>("IsDefault")
.HasColumnType("tinyint(1)")
.HasComment("สถานะว่ารอบใดเป็นค่า Default ของข้าราชการ (สำหรับทุกคนที่ยังไม่ได้ทำการเลือกรอบ)");
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<string>("StartTimeAfternoon")
.IsRequired()
.HasColumnType("longtext")
.HasComment("เวลาเข้างานช่วงบ่าย");
b.Property<string>("StartTimeMorning")
.IsRequired()
.HasColumnType("longtext")
.HasComment("เวลาเข้างานช่วงเช้า");
b.HasKey("Id");
b.ToTable("DutyTimes");
});
modelBuilder.Entity("BMA.EHR.Domain.Models.Leave.TimeAttendants.UserTimeStamp", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)")
.HasColumnOrder(0)
.HasComment("PrimaryKey")
.HasAnnotation("Relational:JsonPropertyName", "id");
b.Property<DateTime>("CheckIn")
.HasColumnType("datetime(6)")
.HasComment("วัน เวลา เข้างาน");
b.Property<string>("CheckInImageUrl")
.IsRequired()
.HasColumnType("longtext")
.HasComment("รูปถ่ายสถานที่ Check-In");
b.Property<double>("CheckInLat")
.HasColumnType("double")
.HasComment("พิกัดละติจูด Check-In");
b.Property<string>("CheckInLocationName")
.HasColumnType("longtext")
.HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-In");
b.Property<double>("CheckInLon")
.HasColumnType("double")
.HasComment("พิกัดลองจิจูด Check-In");
b.Property<string>("CheckInPOI")
.IsRequired()
.HasColumnType("longtext")
.HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-In");
b.Property<string>("CheckInRemark")
.HasColumnType("longtext")
.HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-In");
b.Property<DateTime?>("CheckOut")
.HasColumnType("datetime(6)")
.HasComment("วัน เวลา ออกงาน");
b.Property<string>("CheckOutImageUrl")
.IsRequired()
.HasColumnType("longtext")
.HasComment("รูปถ่ายสถานที่ Check-Out");
b.Property<double>("CheckOutLat")
.HasColumnType("double")
.HasComment("พิกัดละติจูด Check-Out");
b.Property<string>("CheckOutLocationName")
.HasColumnType("longtext")
.HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-Out");
b.Property<double>("CheckOutLon")
.HasColumnType("double")
.HasComment("พิกัดลองจิจูด Check-Out");
b.Property<string>("CheckOutPOI")
.IsRequired()
.HasColumnType("longtext")
.HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-Out");
b.Property<string>("CheckOutRemark")
.HasColumnType("longtext")
.HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-Out");
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<bool>("IsLocationCheckIn")
.HasColumnType("tinyint(1)")
.HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-In");
b.Property<bool>("IsLocationCheckOut")
.HasColumnType("tinyint(1)")
.HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-Out");
b.Property<bool>("IsProcess")
.HasColumnType("tinyint(1)")
.HasComment("นำไปประมวลผลแล้วหรือยัง");
b.Property<Guid>("KeycloakUserId")
.HasColumnType("char(36)")
.HasComment("รหัส User ของ Keycloak");
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.HasKey("Id");
b.ToTable("UserTimeStamps");
});
#pragma warning restore 612, 618
}
}
}

View file

@ -0,0 +1,270 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
{
/// <inheritdoc />
public partial class updatefieldusertimestampsadd : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ImageUrl",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "IsLocation",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "Lat",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "LocationName",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "Lon",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "POI",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "Remark",
table: "UserTimeStamps");
migrationBuilder.AddColumn<string>(
name: "CheckInImageUrl",
table: "UserTimeStamps",
type: "longtext",
nullable: false,
comment: "รูปถ่ายสถานที่ Check-In")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<double>(
name: "CheckInLat",
table: "UserTimeStamps",
type: "double",
nullable: false,
defaultValue: 0.0,
comment: "พิกัดละติจูด Check-In");
migrationBuilder.AddColumn<string>(
name: "CheckInLocationName",
table: "UserTimeStamps",
type: "longtext",
nullable: true,
comment: "กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-In")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<double>(
name: "CheckInLon",
table: "UserTimeStamps",
type: "double",
nullable: false,
defaultValue: 0.0,
comment: "พิกัดลองจิจูด Check-In");
migrationBuilder.AddColumn<string>(
name: "CheckInPOI",
table: "UserTimeStamps",
type: "longtext",
nullable: false,
comment: "ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-In")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "CheckInRemark",
table: "UserTimeStamps",
type: "longtext",
nullable: true,
comment: "ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-In")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "CheckOutImageUrl",
table: "UserTimeStamps",
type: "longtext",
nullable: false,
comment: "รูปถ่ายสถานที่ Check-Out")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<double>(
name: "CheckOutLat",
table: "UserTimeStamps",
type: "double",
nullable: false,
defaultValue: 0.0,
comment: "พิกัดละติจูด Check-Out");
migrationBuilder.AddColumn<string>(
name: "CheckOutLocationName",
table: "UserTimeStamps",
type: "longtext",
nullable: true,
comment: "กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-Out")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<double>(
name: "CheckOutLon",
table: "UserTimeStamps",
type: "double",
nullable: false,
defaultValue: 0.0,
comment: "พิกัดลองจิจูด Check-Out");
migrationBuilder.AddColumn<string>(
name: "CheckOutPOI",
table: "UserTimeStamps",
type: "longtext",
nullable: false,
comment: "ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-Out")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "CheckOutRemark",
table: "UserTimeStamps",
type: "longtext",
nullable: true,
comment: "ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-Out")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<bool>(
name: "IsLocationCheckIn",
table: "UserTimeStamps",
type: "tinyint(1)",
nullable: false,
defaultValue: false,
comment: "true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-In");
migrationBuilder.AddColumn<bool>(
name: "IsLocationCheckOut",
table: "UserTimeStamps",
type: "tinyint(1)",
nullable: false,
defaultValue: false,
comment: "true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-Out");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CheckInImageUrl",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "CheckInLat",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "CheckInLocationName",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "CheckInLon",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "CheckInPOI",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "CheckInRemark",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "CheckOutImageUrl",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "CheckOutLat",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "CheckOutLocationName",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "CheckOutLon",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "CheckOutPOI",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "CheckOutRemark",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "IsLocationCheckIn",
table: "UserTimeStamps");
migrationBuilder.DropColumn(
name: "IsLocationCheckOut",
table: "UserTimeStamps");
migrationBuilder.AddColumn<string>(
name: "ImageUrl",
table: "UserTimeStamps",
type: "longtext",
nullable: false,
comment: "รูปถ่ายสถานที่ checkin/checkout")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<bool>(
name: "IsLocation",
table: "UserTimeStamps",
type: "tinyint(1)",
nullable: false,
defaultValue: false,
comment: "true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง");
migrationBuilder.AddColumn<double>(
name: "Lat",
table: "UserTimeStamps",
type: "double",
nullable: false,
defaultValue: 0.0,
comment: "พิกัดละติจูด");
migrationBuilder.AddColumn<string>(
name: "LocationName",
table: "UserTimeStamps",
type: "longtext",
nullable: true,
comment: "กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<double>(
name: "Lon",
table: "UserTimeStamps",
type: "double",
nullable: false,
defaultValue: 0.0,
comment: "พิกัดลองจิจูด");
migrationBuilder.AddColumn<string>(
name: "POI",
table: "UserTimeStamps",
type: "longtext",
nullable: false,
comment: "ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์")
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "Remark",
table: "UserTimeStamps",
type: "longtext",
nullable: true,
comment: "ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้)")
.Annotation("MySql:CharSet", "utf8mb4");
}
}
}

View file

@ -117,10 +117,62 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
.HasColumnType("datetime(6)")
.HasComment("วัน เวลา เข้างาน");
b.Property<string>("CheckInImageUrl")
.IsRequired()
.HasColumnType("longtext")
.HasComment("รูปถ่ายสถานที่ Check-In");
b.Property<double>("CheckInLat")
.HasColumnType("double")
.HasComment("พิกัดละติจูด Check-In");
b.Property<string>("CheckInLocationName")
.HasColumnType("longtext")
.HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-In");
b.Property<double>("CheckInLon")
.HasColumnType("double")
.HasComment("พิกัดลองจิจูด Check-In");
b.Property<string>("CheckInPOI")
.IsRequired()
.HasColumnType("longtext")
.HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-In");
b.Property<string>("CheckInRemark")
.HasColumnType("longtext")
.HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-In");
b.Property<DateTime?>("CheckOut")
.HasColumnType("datetime(6)")
.HasComment("วัน เวลา ออกงาน");
b.Property<string>("CheckOutImageUrl")
.IsRequired()
.HasColumnType("longtext")
.HasComment("รูปถ่ายสถานที่ Check-Out");
b.Property<double>("CheckOutLat")
.HasColumnType("double")
.HasComment("พิกัดละติจูด Check-Out");
b.Property<string>("CheckOutLocationName")
.HasColumnType("longtext")
.HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่ Check-Out");
b.Property<double>("CheckOutLon")
.HasColumnType("double")
.HasComment("พิกัดลองจิจูด Check-Out");
b.Property<string>("CheckOutPOI")
.IsRequired()
.HasColumnType("longtext")
.HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์ Check-Out");
b.Property<string>("CheckOutRemark")
.HasColumnType("longtext")
.HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้) Check-Out");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)")
.HasColumnOrder(100)
@ -140,14 +192,13 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
.HasColumnOrder(101)
.HasComment("User Id ที่สร้างข้อมูล");
b.Property<string>("ImageUrl")
.IsRequired()
.HasColumnType("longtext")
.HasComment("รูปถ่ายสถานที่ checkin/checkout");
b.Property<bool>("IsLocation")
b.Property<bool>("IsLocationCheckIn")
.HasColumnType("tinyint(1)")
.HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง");
.HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-In");
b.Property<bool>("IsLocationCheckOut")
.HasColumnType("tinyint(1)")
.HasComment("true คือ ณ สถานที่ตั้ง, false คือ นอกสถานที่ตั้ง Check-Out");
b.Property<bool>("IsProcess")
.HasColumnType("tinyint(1)")
@ -176,27 +227,6 @@ namespace BMA.EHR.Infrastructure.Migrations.LeaveDb
.HasColumnOrder(102)
.HasComment("แก้ไขข้อมูลล่าสุดเมื่อ");
b.Property<double>("Lat")
.HasColumnType("double")
.HasComment("พิกัดละติจูด");
b.Property<string>("LocationName")
.HasColumnType("longtext")
.HasComment("กรณีเลือกนอกสถานที่ตั้ง ต้องระบุข้อมูลชื่อสถานะที่");
b.Property<double>("Lon")
.HasColumnType("double")
.HasComment("พิกัดลองจิจูด");
b.Property<string>("POI")
.IsRequired()
.HasColumnType("longtext")
.HasComment("ชื่อสถานที่ ได้มาจากระบบ ArcGis ของกองสารสนเทศภูมิศาสตร์");
b.Property<string>("Remark")
.HasColumnType("longtext")
.HasComment("ข้อความหมายเหตุที่ต้องการระบุเพิ่ม(มีเผื่อไว้อาจไม่ได้ใช้)");
b.HasKey("Id");
b.ToTable("UserTimeStamps");

View file

@ -3,7 +3,6 @@ using BMA.EHR.Application.Repositories.Leaves.TimeAttendants;
using BMA.EHR.Command.Service.DTOs.CheckIn;
using BMA.EHR.Command.Service.DTOs.DutyTime;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Models.Leave;
using BMA.EHR.Domain.Models.Leave.TimeAttendants;
using BMA.EHR.Domain.Shared;
using BMA.EHR.Infrastructure.Persistence;
@ -31,6 +30,9 @@ namespace BMA.EHR.Command.Service.Controllers
private readonly IConfiguration _configuration;
private readonly UserProfileRepository _userProfileRepository;
private readonly UserTimeStampRepository _userTimeStampRepository;
private readonly MinIOService _minIOService;
private readonly string _bucketName = "check-in";
#endregion
@ -42,7 +44,8 @@ namespace BMA.EHR.Command.Service.Controllers
IWebHostEnvironment hostingEnvironment,
IConfiguration configuration,
UserProfileRepository userProfileRepository,
UserTimeStampRepository userTimeStampRepository)
UserTimeStampRepository userTimeStampRepository,
MinIOService minIOService)
{
_dutyTimeRepository = dutyTimeRepository;
_context = context;
@ -51,6 +54,7 @@ namespace BMA.EHR.Command.Service.Controllers
_configuration = configuration;
_userProfileRepository = userProfileRepository;
_userTimeStampRepository = userTimeStampRepository;
_minIOService = minIOService;
}
#endregion
@ -345,6 +349,72 @@ namespace BMA.EHR.Command.Service.Controllers
return Success(ret);
}
/// <summary>
/// LV1_005 - ลงเวลาเข้า-ออกงาน (USER)
/// </summary>
/// <returns>
/// </returns>
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("check-in"), DisableRequestSizeLimit]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<ResponseObject>> CheckInAsync([FromForm] CheckTimeDto data)
{
if (data.Img == null) throw new Exception(GlobalMessages.NoFileToUpload);
var currentDate = DateTime.Now;
var fileName = $"{_bucketName}/{UserId}/{DateTime.Now.ToString("dd-MM-yyyy")}/{data.Img.FileName}";
using (var ms = new MemoryStream())
{
data.Img.CopyTo(ms);
await _minIOService.UploadFileAsync(fileName, ms);
}
// create check in object
if (data.CheckInId == null)
{
var checkin = new UserTimeStamp
{
KeycloakUserId = UserId != null ? Guid.Parse(UserId) : Guid.Empty,
CheckInLat = data.Lat,
CheckInLon = data.Lon,
IsLocationCheckIn = data.IsLocation,
CheckInLocationName = data.LocationName,
CheckInPOI = data.POI,
CheckInRemark = data.Remark,
CheckInImageUrl = fileName,
CheckIn = currentDate
};
await _userTimeStampRepository.AddAsync(checkin);
}
else
{
var checkout = await _userTimeStampRepository.GetByIdAsync(data.CheckInId.Value);
if (checkout != null)
{
checkout.CheckOutLat = data.Lat;
checkout.CheckOutLon = data.Lon;
checkout.IsLocationCheckOut = data.IsLocation;
checkout.CheckOutLocationName = data.LocationName;
checkout.CheckOutPOI = data.POI;
checkout.CheckOutRemark = data.Remark;
checkout.CheckOutImageUrl = fileName;
checkout.CheckOut = currentDate;
}
else
{
throw new Exception(GlobalMessages.DataNotFound);
}
}
return Success(new { date = currentDate });
}
#endregion
#endregion

View file

@ -0,0 +1,28 @@
using System.ComponentModel.DataAnnotations;
namespace BMA.EHR.Command.Service.DTOs.CheckIn
{
public class CheckTimeDto
{
public Guid? CheckInId { get; set; }
[Required]
public IFormFile? Img { get; set; }
[Required]
public double Lat { get; set; } = 0;
[Required]
public double Lon { get; set; } = 0;
[Required]
public string POI { get; set; } = string.Empty;
[Required]
public bool IsLocation { get; set; } = true;
public string? LocationName { get; set; } = string.Empty;
public string? Remark { get; set;} = string.Empty;
}
}