อัพ json เกษียญ

This commit is contained in:
Kittapath 2023-08-04 11:16:47 +07:00
parent 7a05335f22
commit ca945ebad6
3 changed files with 84 additions and 33 deletions

View file

@ -276,7 +276,8 @@ namespace BMA.EHR.Application.Repositories
var request = new PutObjectRequest
{
BucketName = $"{_bucketName}{subFolder}",
BucketName = $"{_bucketName}",
// BucketName = $"{_bucketName}{subFolder}",
Key = file_name,
InputStream = filestream,
ContentType = fileType,
@ -297,7 +298,7 @@ namespace BMA.EHR.Application.Repositories
if (!Directory.Exists(tmpDir))
Directory.CreateDirectory(tmpDir);
var tmpFile = Path.Combine(tmpDir, $"tmp_{DateTime.Now.ToString("ddMMyyyyHHmmss")}{fileName}.json");
var tmpFile = Path.Combine(tmpDir, $"{fileName}.json");
try
{

View file

@ -264,10 +264,10 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
if (req.Option == null)
req.Option = "EDIT";
var file_name = DateTime.Now.ToString("yyyyMMddTHHmmss");
var file_name = $"retire_tmp_{DateTime.Now.ToString("yyyyMMddTHHmmss")}";
var profile_old = await _context.RetirementProfiles
.Where(x => x.RetirementPeriod == retire)
.Select(x => new
.Select(x => new ProfileJsonRequest
{
order = x.Order,
id = x.Id,
@ -308,7 +308,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
LastUpdatedAt = DateTime.Now,
};
await _context.RetirementPeriodHistorys.AddAsync(history);
await _context.SaveChangesAsync();
// await _context.SaveChangesAsync();
retire.Round = retire.Round + 1;
retire.TypeReport = req.Option.Trim().ToUpper();
@ -322,15 +322,38 @@ namespace BMA.EHR.Retirement.Service.Controllers
var profileHistorys = await _context.RetirementPeriodHistorys.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == req.RetireHistoryId);
var profileOlds = new List<RetirementProfile>();
// var profileOlds = new List<dynamic>();
if (profileHistorys != null)
{
using (var client = new HttpClient())
{
var url = $"https://s3cluster.frappet.com/bma-ehr-fpt/retire/{profileHistorys.ProfileFile}";
var url = $"https://s3cluster.frappet.com/bma-ehr-fpt/{profileHistorys.ProfileFile}.json";
var responseTask = client.GetAsync(url);
var results = responseTask.Result;
profileOlds = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RetirementProfile>>(results.Content.ReadAsStringAsync().Result);
var profileOlds = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ProfileJsonRequest>>(results.Content.ReadAsStringAsync().Result);
if (profileOlds != null)
{
profileOlds = profileOlds.Where(x => !x.remove.Trim().ToUpper().Contains("REMOVE")).ToList();
foreach (var profileOld in profileOlds)
{
var _profile = await _context.Profiles.AsQueryable()
.FirstOrDefaultAsync(x => x.CitizenId == profileOld.citizenId);
var data = new RetirementProfile
{
Order = profileOld.order,
Remove = "PENDING",
RetirementPeriod = retire,
Profile = _profile,
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
retire.RetirementProfiles.Add(data);
}
}
}
}
else
@ -339,39 +362,39 @@ namespace BMA.EHR.Retirement.Service.Controllers
.FirstOrDefaultAsync(x => x.Id == req.RetireHistoryId);
if (retireOld == null)
return Error(GlobalMessages.InvalidRetirementRequest, 404);
profileOlds = await _context.RetirementProfiles.AsQueryable()
var profileOlds = await _context.RetirementProfiles.AsQueryable()
.Where(x => x.RetirementPeriod == retireOld)
.ToListAsync();
}
if (profileOlds != null)
{
profileOlds = profileOlds.Where(x => !x.Remove.Trim().ToUpper().Contains("REMOVE")).ToList();
foreach (var profileOld in profileOlds)
if (profileOlds != null)
{
var data = new RetirementProfile
profileOlds = profileOlds.Where(x => !x.Remove.Trim().ToUpper().Contains("REMOVE")).ToList();
foreach (var profileOld in profileOlds)
{
Order = profileOld.Order,
Remove = "PENDING",
RetirementPeriod = retire,
Profile = profileOld.Profile,
CreatedUserId = profileOld.CreatedUserId,
CreatedFullName = profileOld.CreatedFullName,
CreatedAt = profileOld.CreatedAt,
LastUpdateFullName = profileOld.LastUpdateFullName,
LastUpdateUserId = profileOld.LastUpdateUserId,
LastUpdatedAt = profileOld.LastUpdatedAt,
};
retire.RetirementProfiles.Add(data);
var data = new RetirementProfile
{
Order = profileOld.Order,
Remove = "PENDING",
RetirementPeriod = retire,
Profile = profileOld.Profile,
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
retire.RetirementProfiles.Add(data);
}
}
}
}
await _context.SaveChangesAsync();
}
await _context.SaveChangesAsync();
// await _context.SaveChangesAsync();
var profile_new = await _context.RetirementProfiles
.Where(x => x.RetirementPeriod == retire)
.Select(x => new
.Select(x => new ProfileJsonRequest
{
order = x.Order,
id = x.Id,
@ -419,16 +442,16 @@ namespace BMA.EHR.Retirement.Service.Controllers
return Error(GlobalMessages.InvalidRetirementHistoryRequest, 404);
using (var client = new HttpClient())
{
var url = $"https://s3cluster.frappet.com/bma-ehr-fpt/retire/{profileHistorys.ProfileFile}.json";
var url = $"https://s3cluster.frappet.com/bma-ehr-fpt/{profileHistorys.ProfileFile}.json";
var responseTask = client.GetAsync(url);
var results = responseTask.Result;
// Console.WriteLine(results.Content.ReadAsStringAsync().Result);
return Success(new { Json = true, profile = Newtonsoft.Json.JsonConvert.DeserializeObject<List<dynamic>>(results.Content.ReadAsStringAsync().Result) });
return Success(new { Json = true, profile = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ProfileJsonRequest>>(results.Content.ReadAsStringAsync().Result) });
}
}
var profile_new = await _context.RetirementProfiles
.Where(x => x.RetirementPeriod == retire)
.Select(x => new
.Select(x => new ProfileJsonRequest
{
order = x.Order,
id = x.Id,
@ -569,7 +592,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
}
/// <summary>
/// แก้ไขข้อมูลบุคคล
/// ลบข้อมูลบุคคล
/// </summary>
/// <param name="retireProfileId">Id ผู้ใช้งานในประกาศ</param>
/// <param name="reason">เหตุผล</param>

View file

@ -0,0 +1,27 @@
using BMA.EHR.Domain.Models.MetaData;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Retirement.Service.Requests
{
public class ProfileJsonRequest
{
public int order { get; set; }
public Guid id { get; set; }
public string reason { get; set; }
public string remove { get; set; }
public Guid profileId { get; set; }
public string? citizenId { get; set; }
public string? prefix { get; set; }
public string? fullName { get; set; }
public string? organizationOrganization { get; set; }
public string? oc { get; set; }
public string? position { get; set; }
public string? positionType { get; set; }
public string? positionExecutive { get; set; }
public string? posNo { get; set; }
public string? positionEmployeePosition { get; set; }
public string? positionEmployeeLevel { get; set; }
public string? positionEmployeeGroup { get; set; }
public string? posNoEmployee { get; set; }
}
}