api บันทึกเครื่องราช

This commit is contained in:
Kittapath 2023-08-23 20:30:30 +07:00
parent 9abb9c5422
commit 51bdcf4041
50 changed files with 162548 additions and 111 deletions

View file

@ -161,11 +161,13 @@ namespace BMA.EHR.Retirement.Service.Controllers
Total = x.Total,
TypeReport = x.TypeReport,
Json = true,
Document = x.Document == null ? false : true,
})
.ToListAsync();
var retire = await _context.RetirementPeriods
.Include(x => x.RetirementProfiles)
.Include(x => x.Document)
.Where(x => x.Year == year)
.Where(x => x.Type.Trim().ToUpper().Contains(type.Trim().ToUpper()))
.FirstOrDefaultAsync();
@ -180,6 +182,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
Total = retire.RetirementProfiles.Count(),
TypeReport = retire.TypeReport,
Json = false,
Document = retire.Document == null ? false : true,
});
}
@ -208,6 +211,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
var round = 1;
var retire = await _context.RetirementPeriods
.Include(x => x.Document)
.Include(x => x.RetirementPeriodHistorys)
.Include(x => x.RetirementProfiles)
.ThenInclude(x => x.Profile)
@ -259,6 +263,8 @@ namespace BMA.EHR.Retirement.Service.Controllers
}
else
{
if (retire.Document == null)
return Error(GlobalMessages.RetirementNotCreated);
if (req.Option == null)
req.Option = "EDIT";
var file_name = $"retire_tmp_{DateTime.Now.ToString("yyyyMMddTHHmmss")}";
@ -295,6 +301,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
TypeReport = retire.TypeReport,
Year = retire.Year,
Type = retire.Type,
Document = retire.Document,
Total = retire.RetirementProfiles.Count(),
ProfileFile = file_name,
CreatedUserId = FullName ?? "",
@ -307,6 +314,7 @@ namespace BMA.EHR.Retirement.Service.Controllers
await _context.RetirementPeriodHistorys.AddAsync(history);
// await _context.SaveChangesAsync();
retire.Document = null;
retire.Round = retire.Round + 1;
retire.TypeReport = req.Option.Trim().ToUpper();
retire.LastUpdateFullName = FullName ?? "System Administrator";
@ -430,11 +438,13 @@ namespace BMA.EHR.Retirement.Service.Controllers
{
var retire = await _context.RetirementPeriods
.Include(x => x.RetirementProfiles)
.Include(x => x.Document)
.FirstOrDefaultAsync(x => x.Id == retireId);
if (retire == null)
{
var profileHistorys = await _context.RetirementPeriodHistorys.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == retireId);
.Include(x => x.Document)
.FirstOrDefaultAsync(x => x.Id == retireId);
if (profileHistorys == null)
return Error(GlobalMessages.RetirementHistoryNotFound, 404);
using (var client = new HttpClient())
@ -442,8 +452,9 @@ namespace BMA.EHR.Retirement.Service.Controllers
var url = $"https://s3cluster.frappet.com/bma-ehr-fpt/{profileHistorys.ProfileFile}.json";
var responseTask = client.GetAsync(url);
var results = responseTask.Result;
var filehis = profileHistorys.Document == null ? null : await _documentService.ImagesPath(profileHistorys.Document.Id);
// Console.WriteLine(results.Content.ReadAsStringAsync().Result);
return Success(new { Json = true, profileHistorys.Id, profileHistorys.CreatedAt, profileHistorys.Year, profileHistorys.Round, profileHistorys.Type, profileHistorys.TypeReport, profile = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ProfileJsonRequest>>(results.Content.ReadAsStringAsync().Result) });
return Success(new { Json = true, profileHistorys.Id, profileHistorys.CreatedAt, profileHistorys.Year, profileHistorys.Round, profileHistorys.Type, profileHistorys.TypeReport, profile = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ProfileJsonRequest>>(results.Content.ReadAsStringAsync().Result), File = filehis });
}
}
var profile_new = await _context.RetirementProfiles
@ -470,8 +481,8 @@ namespace BMA.EHR.Retirement.Service.Controllers
posNoEmployee = x.Profile.PosNoEmployee,
})
.ToListAsync();
return Success(new { Json = false, retire.Id, retire.CreatedAt, retire.Year, retire.Round, retire.Type, retire.TypeReport, profile = profile_new });
var file = retire.Document == null ? null : await _documentService.ImagesPath(retire.Document.Id);
return Success(new { Json = false, retire.Id, retire.CreatedAt, retire.Year, retire.Round, retire.Type, retire.TypeReport, profile = profile_new, File = file });
}
/// <summary>
@ -672,5 +683,61 @@ namespace BMA.EHR.Retirement.Service.Controllers
return Success();
}
/// <summary>
/// อัพเอกสารเกษียณอายุราชการ
/// </summary>
/// <param name="retireId">Id ประกาศ</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPut("upload/{retireId:length(36)}")]
public async Task<ActionResult<ResponseObject>> UploadRetirement([FromForm] RetirementFileRequest req, Guid retireId)
{
var retire = await _context.RetirementPeriods
.FirstOrDefaultAsync(x => x.Id == retireId);
if (retire == null)
return Error(GlobalMessages.DataNotFound, 404);
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);
var _doc = await _context.Documents.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == doc.Id);
retire.Document = _doc;
retire.LastUpdateFullName = FullName ?? "System Administrator";
retire.LastUpdateUserId = UserId ?? "";
retire.LastUpdatedAt = DateTime.Now;
}
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// ตรวจสอบการอัพเอกสารเกษียญ false=ยังไม่อัพโหลด true=อัพโหลดเอกสารแล้ว
/// </summary>
/// <param name="retireId">Id ประกาศ</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("upload/check/{retireId:length(36)}")]
public async Task<ActionResult<ResponseObject>> CheckUploadRetirement(Guid retireId)
{
var retire = await _context.RetirementPeriods
.Include(x => x.Document)
.FirstOrDefaultAsync(x => x.Id == retireId);
if (retire == null)
return Error(GlobalMessages.DataNotFound, 404);
if (retire.Document == null)
return Success(false);
return Success(true);
}
}
}