From 1ce1e8400b27b4626dc70176dd15147dfd309490 Mon Sep 17 00:00:00 2001 From: dev02 Date: Fri, 19 May 2023 11:18:38 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=89=8D=E5=8F=B0=20=E7=B7=8A=E6=80=A5=E4=BD=BF=E7=94=A8api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EmergencyContactController.cs | 6 +- .../EmergencyDeviceController.cs | 57 ++--- .../EmergencyRecordController.cs | 6 +- .../ApiControllers/RescueDeviceController.cs | 8 +- .../Controllers/EmergencyContactController.cs | 201 ------------------ .../Controllers/EmergencyRecordController.cs | 94 -------- FrontendWebApi/Controllers/LoginController.cs | 89 -------- .../Controllers/MyBaseController.cs | 4 - 8 files changed, 40 insertions(+), 425 deletions(-) diff --git a/FrontendWebApi/ApiControllers/EmergencyContactController.cs b/FrontendWebApi/ApiControllers/EmergencyContactController.cs index c6b7a83..b8b4fba 100644 --- a/FrontendWebApi/ApiControllers/EmergencyContactController.cs +++ b/FrontendWebApi/ApiControllers/EmergencyContactController.cs @@ -90,7 +90,7 @@ namespace FrontendWebApi.ApiControllers try { Emergency_member_tables = await backendRepository.GetAllAsync($@" - select v.system_key groupingName,va.system_key departmentName,* from emergency_member em left join variable v on em.grouping = v.id + select v.system_key groupingName,va.system_key departmentName, em.* from emergency_member em left join variable v on em.grouping = v.id left join (select * from variable vs where vs.system_type = 'department' and vs.deleted = 0) va on va.system_value = em.department where em.grouping in @groupinglist and em.deleted = 0", new { groupinglist = selectgroupidlist }); apiResult.Code = "0000"; @@ -120,7 +120,7 @@ namespace FrontendWebApi.ApiControllers try { var Emergency_member_tables = await backendRepository.GetAllAsync($@" - select v.system_key groupingName,va.system_key departmentName,* from emergency_member em left join variable v on em.grouping = v.id + select v.system_key groupingName,va.system_key departmentName, em.* from emergency_member em left join variable v on em.grouping = v.id left join (select * from variable vs where vs.system_type = 'department' and vs.deleted = 0) va on va.system_value = em.department where em.grouping in @groupinglist and em.deleted = 0", new { groupinglist = post.groupidlist }); using (var doc = new Document()) @@ -236,7 +236,7 @@ namespace FrontendWebApi.ApiControllers try { var Emergency_member_tables = await backendRepository.GetAllAsync($@" - select v.system_key groupingName,va.system_key departmentName,* from emergency_member em left join variable v on em.grouping = v.id + select v.system_key groupingName,va.system_key departmentName, em.* from emergency_member em left join variable v on em.grouping = v.id left join (select * from variable vs where vs.system_type = 'department' and vs.deleted = 0) va on va.system_value = em.department where em.grouping in @groupinglist and em.deleted = 0", new { groupinglist = post.groupidlist }); var sheet = workbook.CreateSheet(post.disaster + "-聯絡清單"); diff --git a/FrontendWebApi/ApiControllers/EmergencyDeviceController.cs b/FrontendWebApi/ApiControllers/EmergencyDeviceController.cs index c74bccf..e2e78b4 100644 --- a/FrontendWebApi/ApiControllers/EmergencyDeviceController.cs +++ b/FrontendWebApi/ApiControllers/EmergencyDeviceController.cs @@ -125,7 +125,7 @@ namespace FrontendWebApi.ApiControllers d.device_guid, d.device_number, d.full_name AS device_name, - d.building_guid, + d.device_building_tag, b.full_name AS building_name, CONCAT(b.ip_address , ':', b.ip_port) AS ip_address, v.layer2, @@ -137,27 +137,27 @@ namespace FrontendWebApi.ApiControllers floor.full_name floorname, floor.floor_guid floorguid from - (SELECT * - FROM device d - WHERE d.deleted = 0 - AND d.building_guid = '{selectdevice.selectbuilding}' - AND d.floor_guid in @floor - AND d.device_system_category_layer3 IN @layer3) d - left join floor on floor.floor_guid = d.floor_guid + (SELECT * + FROM device d + WHERE d.deleted = 0 + AND d.device_building_tag = '{selectdevice.selectbuilding}' + AND d.device_floor_tag in @floor + AND d.device_name_tag IN @layer3) d + left join floor on floor.full_name = d.device_floor_tag and floor.building_tag = d.device_building_tag left join ( - SELECT - v.*, - v2.system_key AS layer2_name, - v2.system_value AS layer2 - FROM ( - select * - from variable v - where v.system_type = 'device_system_category_layer3') v - LEFT JOIN variable v2 ON v2.deleted = 0 AND v.system_parent_id = v2.id - ) v on v.system_value = d.device_system_category_layer3 + SELECT + v.*, + v2.system_key AS layer2_name, + v2.system_value AS layer2 + FROM ( + select * + from variable v + where v.system_type = 'device_system_category_layer3') v + LEFT JOIN variable v2 ON v2.deleted = 0 AND v.system_parent_id = v2.id + ) v on v.system_value = d.device_system_category_layer3 left join device_disaster dd on dd.device_guid = d.device_guid left join (select * from variable v where v.system_type = 'disaster') ddd on ddd.system_value = dd.device_system_value - LEFT JOIN building b ON b.deleted = 0 AND d.building_guid = b.building_guid + LEFT JOIN building b ON b.deleted = 0 AND d.device_building_tag = b.building_tag where dd.device_system_value IN @disasters ORDER BY d.device_number "; @@ -451,7 +451,7 @@ namespace FrontendWebApi.ApiControllers try { Emergency_member_tables = await backendRepository.GetAllAsync($@" - select v.system_key groupingName,va.system_key departmentName,* from emergency_member em left join variable v on em.grouping = v.id + select v.system_key groupingName,va.system_key departmentName, em.* from emergency_member em left join variable v on em.grouping = v.id left join (select * from variable vs where vs.system_type = 'department' and vs.deleted = 0) va on va.system_value = em.department where em.grouping in @groupinglist and em.deleted = 0", new { groupinglist = selectgroupidlist }); apiResult.Code = "0000"; @@ -486,13 +486,16 @@ namespace FrontendWebApi.ApiControllers try { getDeviceGroup = await backendRepository.GetAllAsync($@" - select dg.*,vd.system_key disater_name,b.full_name building_name,f.full_name floor_name,v2.system_key system_category_layer2,v3.system_key system_category_layer3 from (SELECT * FROM device_group dg WHERE dg.device_disaster != 0) dg - left join (select * from variable v where v.system_type = 'disaster' and v.deleted = 0) vd on vd.system_value = dg.device_disaster - left join building b on b.building_guid = dg.device_building_guid - left join floor f on f.floor_guid = dg.device_floor_guid - left join (select * from variable v where v.system_type = 'device_system_category_layer2' and v.deleted = 0) v2 on v2.system_value = dg.device_system_category_layer2 - left join (select * from variable v where v.system_type = 'device_system_category_layer3' and v.deleted = 0) v3 on v3.system_value = dg.device_system_category_layer3 - order by vd.system_priority,b.priority,f.priority,v2.system_priority,v3.system_priority"); + select dg.*,vd.system_key disater_name,b.full_name building_name,f.full_name floor_name,v2.system_key system_category_layer2,v3.system_key system_category_layer3 + from ( + SELECT * + FROM device_group dg WHERE dg.device_disaster != 0) dg + left join (select * from variable v where v.system_type = 'disaster' and v.deleted = 0) vd on vd.system_value = dg.device_disaster + left join building b on b.building_tag = dg.device_building_guid + left join floor f on f.floor_guid = dg.device_floor_guid + left join (select * from variable v where v.system_type = 'device_system_category_layer2' and v.deleted = 0) v2 on v2.system_value = dg.device_system_category_layer2 + left join (select * from variable v where v.system_type = 'device_system_category_layer3' and v.deleted = 0) v3 on v3.system_value = dg.device_system_category_layer3 + order by vd.system_priority,b.priority,f.priority,v2.system_priority,v3.system_priority"); var dis = getDeviceGroup.GroupBy(a => a.device_disaster); //finalDeviceGroup.disaster = new List(); diff --git a/FrontendWebApi/ApiControllers/EmergencyRecordController.cs b/FrontendWebApi/ApiControllers/EmergencyRecordController.cs index 70dd040..871cb49 100644 --- a/FrontendWebApi/ApiControllers/EmergencyRecordController.cs +++ b/FrontendWebApi/ApiControllers/EmergencyRecordController.cs @@ -35,7 +35,7 @@ namespace FrontendWebApi.ApiControllers try { - var sqlString = @$"select building_guid as Value, full_name as Name from building a where a.deleted = 0 and a.status = 0"; + var sqlString = @$"select building_tag as Value, full_name as Name from building a where a.deleted = 0 and a.status = 0"; KeyValue = await backendRepository.GetAllAsync(sqlString); apiResult.Code = "0000"; @@ -74,8 +74,8 @@ namespace FrontendWebApi.ApiControllers select d.device_number device_name,v.system_key disaster_name,ee.*,b.full_name building_name from emergency_event ee left join (select * from variable v where v.system_type = 'disaster') v on v.system_value = ee.disaster left join device d on d.device_guid = ee.device_guid - left join building b on b.building_guid = ee.building_guid - where ee.deleted = 0 and ee.building_guid = '{post.selectaBuild}' and ee.disaster = '{post.selectaDisaster}' {sqlplus} + left join building b on b.building_tag = ee.building_tag + where ee.deleted = 0 and ee.building_tag = '{post.selectaBuild}' and ee.disaster = '{post.selectaDisaster}' {sqlplus} "); apiResult.Code = "0000"; apiResult.Data = EmergencyRecordEvent; diff --git a/FrontendWebApi/ApiControllers/RescueDeviceController.cs b/FrontendWebApi/ApiControllers/RescueDeviceController.cs index 9182f91..ac58c9f 100644 --- a/FrontendWebApi/ApiControllers/RescueDeviceController.cs +++ b/FrontendWebApi/ApiControllers/RescueDeviceController.cs @@ -33,7 +33,7 @@ namespace FrontendWebApi.ApiControllers try { - var sqlString = @$"select floor_guid as Value, full_name as Name from floor a where a.deleted = 0 and a.building_guid = '{Building}' and a.status = 0 order by a.priority"; + var sqlString = @$"select floor_guid as Value, full_name as Name from floor a where a.deleted = 0 and a.building_tag = '{Building}' and a.status = 0 order by a.priority"; KeyValue = await backendRepository.GetAllAsync(sqlString); apiResult.Code = "0000"; @@ -61,7 +61,7 @@ namespace FrontendWebApi.ApiControllers ApiResult> apiResult = new ApiResult>(); try { - RescueDeviceTables = await backendRepository.GetAllAsync("rescue_device", $"building_guid = '{post.build}' and floor_guid in @floors and rescue_device_kind = {post.kind}", new { floors = post.floors }, "floor_name"); + RescueDeviceTables = await backendRepository.GetAllAsync("rescue_device", $"building_tag = '{post.build}' and floor_guid in @floors and rescue_device_kind = {post.kind}", new { floors = post.floors }, "floor_name"); apiResult.Code = "0000"; apiResult.Data = RescueDeviceTables; } @@ -88,7 +88,7 @@ namespace FrontendWebApi.ApiControllers try { - var sqlString = @$"select building_guid as Value, full_name as Name from building a where a.deleted = 0 and a.status = 0 ORDER BY A.priority ASC, A.created_at DESC"; + var sqlString = @$"select building_tag as Value, full_name as Name from building a where a.deleted = 0 and a.status = 0 ORDER BY A.priority ASC, A.created_at DESC"; KeyValue = await backendRepository.GetAllAsync(sqlString); apiResult.Code = "0000"; @@ -159,7 +159,7 @@ namespace FrontendWebApi.ApiControllers devicename = "AED"; } var sheet = workbook.CreateSheet(devicename); - var RescueDevices = backendRepository.GetAllAsync("rescue_device", $"building_guid = '{postObject.build}' and rescue_device_kind = {postObject.kind}",null, "floor_name"); + var RescueDevices = backendRepository.GetAllAsync("rescue_device", $"building_tag = '{postObject.build}' and rescue_device_kind = {postObject.kind}",null, "floor_name"); int RowPosition = 0; IRow row = sheet.CreateRow(RowPosition); ICell cell = row.CreateCell(1); diff --git a/FrontendWebApi/Controllers/EmergencyContactController.cs b/FrontendWebApi/Controllers/EmergencyContactController.cs index 15b5625..ae0d89d 100644 --- a/FrontendWebApi/Controllers/EmergencyContactController.cs +++ b/FrontendWebApi/Controllers/EmergencyContactController.cs @@ -27,206 +27,5 @@ namespace FrontendWebApi.Controllers { return View(); } - - [HttpPost] - public async Task EmergencyContactTable (List selectgroupidlist) - { - List Emergency_member_tables = new List(); - ApiResult> apiResult = new ApiResult>(); - try - { - Emergency_member_tables = await backendRepository.GetAllAsync($@" - select v.system_key groupingName,va.system_key departmentName,* from emergency_member em left join variable v on em.grouping = v.id - left join (select * from variable vs where vs.system_type = 'department' and vs.deleted = 0) va on va.system_value = em.department - where em.grouping in @groupinglist and em.deleted = 0",new { groupinglist = selectgroupidlist }); - apiResult.Code = "0000"; - apiResult.Data = Emergency_member_tables; - } - catch (Exception exception) - { - apiResult.Code = "9999"; - apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; - Logger.LogError("【" + controllerName + "/" + actionName + "】"); - Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); - } - var result = Json(new - { - data = apiResult - }); - return result; - } - - - public FileResult ExportPDF(string post) - { - var grouping = JsonConvert.DeserializeObject(post); - var stream = new MemoryStream(); - try - { - var Emergency_member_tables = backendRepository.GetAllAsync($@" - select v.system_key groupingName,va.system_key departmentName,* from emergency_member em left join variable v on em.grouping = v.id - left join (select * from variable vs where vs.system_type = 'department' and vs.deleted = 0) va on va.system_value = em.department - where em.grouping in @groupinglist and em.deleted = 0", new { groupinglist = grouping.groupidlist }); - using (var doc = new Document()) - { - using (var writer = PdfWriter.GetInstance(doc, stream)) - { - writer.CloseStream = false; - BaseFont BaseF = BaseFont.CreateFont("C:\\Windows\\Fonts\\kaiu.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); - Font fontCh = new Font(BaseF, 14); - doc.Open(); - PdfPTable table = new PdfPTable(new float[] { 1, 1, 1, 1, 1 ,1 }); - table.TotalWidth = 480f; - table.LockedWidth = true; - PdfPCell header = new PdfPCell(new Phrase(grouping.disaster+"-聯絡清單", fontCh)); - header.Colspan = 6; - table.AddCell(header); - table.AddCell(new Phrase("組別", fontCh)); - table.AddCell(new Phrase("姓名", fontCh)); - table.AddCell(new Phrase("部門", fontCh)); - table.AddCell(new Phrase("電話", fontCh)); - table.AddCell(new Phrase("LINE ID", fontCh)); - table.AddCell(new Phrase("電子信箱", fontCh)); - - foreach(var group in Emergency_member_tables.Result) - { - table.AddCell(new Phrase(group.groupingName, fontCh)); - table.AddCell(new Phrase(group.full_name, fontCh)); - table.AddCell(new Phrase(group.departmentName, fontCh)); - table.AddCell(new Phrase(group.phone, fontCh)); - table.AddCell(new Phrase(group.lineid, fontCh)); - table.AddCell(new Phrase(group.email, fontCh)); - } - doc.Add(table); - doc.Close(); - } - } - var bytes = stream.ToArray(); - stream.Position = 0; - } - catch (Exception exception) - { - Logger.LogError("【" + controllerName + "/" + actionName + "】"); - Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); - } - return File(stream, "application/pdf", grouping.disaster+"-聯絡清單.pdf"); - } - - public FileResult ExportExcel(string post) - { - var grouping = JsonConvert.DeserializeObject(post); - var workbook = new XSSFWorkbook(); - var ms = new NpoiMemoryStream - { - AllowClose = false - }; - #region excel設定 - IFont font12 = workbook.CreateFont(); - font12.FontName = "新細明體"; - font12.FontHeightInPoints = 12; - ICellStyle style12 = workbook.CreateCellStyle(); - style12.SetFont(font12); - style12.Alignment = HorizontalAlignment.Center; - style12.VerticalAlignment = VerticalAlignment.Center; - IFont font12Times = workbook.CreateFont(); - font12Times.FontName = "Times New Roman"; - font12Times.FontHeightInPoints = 12; - IFont font18 = workbook.CreateFont(); - font18.FontName = "新細明體"; - font18.FontHeightInPoints = 18; - font18.IsBold = true; - ICellStyle styleTitle18 = workbook.CreateCellStyle(); - styleTitle18.SetFont(font18); - styleTitle18.Alignment = HorizontalAlignment.Center; - styleTitle18.VerticalAlignment = VerticalAlignment.Center; - ICellStyle styleLeft12 = workbook.CreateCellStyle(); - styleLeft12.SetFont(font12); - styleLeft12.Alignment = HorizontalAlignment.Left; - styleLeft12.VerticalAlignment = VerticalAlignment.Center; - ICellStyle styleLine12 = workbook.CreateCellStyle(); - styleLine12.SetFont(font12); - styleLine12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; - styleLine12.VerticalAlignment = VerticalAlignment.Center; - styleLine12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; - styleLine12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; - styleLine12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; - styleLine12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; - ICellStyle stylein12 = workbook.CreateCellStyle(); - stylein12.SetFont(font12Times); - stylein12.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left; - stylein12.VerticalAlignment = VerticalAlignment.Center; - stylein12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; - stylein12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; - stylein12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; - stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; - stylein12.WrapText = true; - #endregion - try - { - var Emergency_member_tables = backendRepository.GetAllAsync($@" - select v.system_key groupingName,va.system_key departmentName,* from emergency_member em left join variable v on em.grouping = v.id - left join (select * from variable vs where vs.system_type = 'department' and vs.deleted = 0) va on va.system_value = em.department - where em.grouping in @groupinglist and em.deleted = 0", new { groupinglist = grouping.groupidlist }).Result; - var sheet = workbook.CreateSheet(grouping.disaster+"-聯絡清單"); - int RowPosition = 0; - IRow row = sheet.CreateRow(RowPosition); - sheet.SetColumnWidth(0, 4 * 160 * 6); - sheet.SetColumnWidth(1, 4 * 160 * 6); - sheet.SetColumnWidth(2, 4 * 160 * 6); - sheet.SetColumnWidth(3, 4 * 160 * 6); - sheet.SetColumnWidth(4, 4 * 160 * 6); - sheet.SetColumnWidth(5, 4 * 160 * 6); - ICell cell = row.CreateCell(0); - cell.SetCellValue("組別"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(1); - cell.SetCellValue("姓名"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(2); - cell.SetCellValue("部門"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(3); - cell.SetCellValue("電話"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(4); - cell.SetCellValue("LINE ID"); - cell.CellStyle = styleLine12; - cell = row.CreateCell(5); - cell.SetCellValue("電子信箱"); - cell.CellStyle = styleLine12; - foreach (var group in Emergency_member_tables) - { - RowPosition += 1; - row = sheet.CreateRow(RowPosition); - cell = row.CreateCell(0); - cell.SetCellValue(group.groupingName); - cell.CellStyle = style12; - cell = row.CreateCell(1); - cell.SetCellValue(group.full_name); - cell.CellStyle = style12; - cell = row.CreateCell(2); - cell.SetCellValue(group.departmentName); - cell.CellStyle = style12; - cell = row.CreateCell(3); - cell.SetCellValue(group.phone); - cell.CellStyle = style12; - cell = row.CreateCell(4); - cell.SetCellValue(group.lineid); - cell.CellStyle = style12; - cell = row.CreateCell(5); - cell.SetCellValue(group.email); - cell.CellStyle = style12; - } - workbook.Write(ms); - ms.Flush(); - ms.Seek(0, SeekOrigin.Begin); - } - catch(Exception exception) - { - Logger.LogError("【" + controllerName + "/" + actionName + "】"); - Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); - } - return File(ms, "application/vnd.ms-excel", grouping.disaster + "-聯絡清單.xlsx"); - } } } diff --git a/FrontendWebApi/Controllers/EmergencyRecordController.cs b/FrontendWebApi/Controllers/EmergencyRecordController.cs index 5857d1d..4f04f29 100644 --- a/FrontendWebApi/Controllers/EmergencyRecordController.cs +++ b/FrontendWebApi/Controllers/EmergencyRecordController.cs @@ -44,99 +44,5 @@ namespace FrontendWebApi.Controllers return apiResult; } - - [HttpPost] - public async Task>> BuildInfoList() - { - ApiResult> apiResult = new ApiResult>(); - List KeyValue = new List(); - - try - { - var sqlString = @$"select building_guid as Value, full_name as Name from building a where a.deleted = 0 and a.status = 0 ORDER BY A.priority ASC, A.created_at DESC"; - KeyValue = await backendRepository.GetAllAsync(sqlString); - - apiResult.Code = "0000"; - apiResult.Data = KeyValue; - } - catch (Exception exception) - { - apiResult.Code = "9999"; - apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; - Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); - } - - return apiResult; - } - - [HttpPost] - public async Task EmergencyRecordTable(EmergencyRecordEventPost post) - { - List EmergencyRecordEvent = new List(); - ApiResult> apiResult = new ApiResult>(); - try - { - var sqlplus = ""; - if(post.selectaType != 2 ) - { - sqlplus = $"and ee.type = '{post.selectaType}'"; - } - if (post.dateranger != null) - { - var date = post.dateranger.Replace(" ", "").Split("-"); - sqlplus += $"and ee.created_at between '{date[0].Replace(" / ", " - ")} 00:00:00' and '{date[1].Replace(" / ", " - ")} 23:59:59'"; - } - - EmergencyRecordEvent = await backendRepository.GetAllAsync($@" - select d.device_number device_name,v.system_key disaster_name,ee.*,b.full_name building_name from emergency_event ee - left join (select * from variable v where v.system_type = 'disaster') v on v.system_value = ee.disaster - left join device d on d.device_guid = ee.device_guid - left join building b on b.building_guid = ee.building_guid - where ee.deleted = 0 and ee.building_guid = '{post.selectaBuild}' and ee.disaster = '{post.selectaDisaster}' {sqlplus} - "); - apiResult.Code = "0000"; - apiResult.Data = EmergencyRecordEvent; - } - catch (Exception exception) - { - apiResult.Code = "9999"; - apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; - Logger.LogError("【" + controllerName + "/" + actionName + "】"); - Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); - } - var result = Json(new - { - data = apiResult - }); - return result; - } - - - [HttpPost] - public async Task EmergencyItemTable(string event_guid) - { - List EmergencyRecordEvent = new List(); - ApiResult> apiResult = new ApiResult>(); - try - { - EmergencyRecordEvent = await backendRepository.GetAllAsync($@" - select * from emergency_item where event_guid = '{event_guid}' order by created_at desc - "); - apiResult.Code = "0000"; - apiResult.Data = EmergencyRecordEvent; - } - catch (Exception exception) - { - apiResult.Code = "9999"; - apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; - Logger.LogError("【" + controllerName + "/" + actionName + "】"); - Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); - } - var result = Json(new - { - data = apiResult - }); - return result; - } } } diff --git a/FrontendWebApi/Controllers/LoginController.cs b/FrontendWebApi/Controllers/LoginController.cs index 8e7dc50..464ada6 100644 --- a/FrontendWebApi/Controllers/LoginController.cs +++ b/FrontendWebApi/Controllers/LoginController.cs @@ -51,94 +51,5 @@ namespace FrontendWebApi.Controllers ViewBag.ProjectName = backendRepository.GetOneAsync("select system_key from variable where deleted = 0 and system_type = 'project_name';").Result; return View(); } - - [HttpPost] - [Route("api/Login")] - public async Task>> Login(Login login) - { - ApiResult apiResult = new ApiResult(null); - ErrorCode errorCode = new ErrorCode(); - try - { - ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*"); - EDFunction eDFunction = new EDFunction(); - - //string SHA256Pwd = eDFunction.GetSHA256Encryption(login.password); - var User = await backendRepository.GetOneAsync("userinfo", @$"account = '{login.account}' and deleted = 0"); - if (User == null) - { - apiResult.Code = "9998"; - return Ok(apiResult); - } - JwtLogin jwtLoing = new JwtLogin() - { - account = User.account, - email = User.email, - full_name = User.full_name, - userinfo_guid = User.userinfo_guid - }; - apiResult.Code = "0000"; - apiResult.Data = jwt.GenerateToken(jwtLoing); - } - catch - { - apiResult.Code = "9999"; - return BadRequest(apiResult); - } - return Ok(apiResult); - } - - - [HttpPost] - public async Task>> CheckJwt() - { - ApiResult apiResult = new ApiResult(null); - ErrorCode errorCode = new ErrorCode(); - try - { - var ctx = ControllerContext.HttpContext; - ctx.Response.Headers.Add("Access-Control-Allow-Origin", "*"); - ctx.Response.Headers.Add("Access-Control-Allow-Headers", "*"); - ctx.Response.Headers.Add("Access-Control-Allow-Credentials", "true"); - var a = User.Claims.Select(p => new { Type = p.Type, Value = p.Value }).ToList(); - myUser = new JwtGet() - { - account = User.Claims.Where(a => a.Type == "account").Select(e => e.Value).FirstOrDefault(), - email = User.Claims.Where(a => a.Type == "email").Select(e => e.Value).FirstOrDefault(), - full_name = User.Claims.Where(a => a.Type == "full_name").Select(e => e.Value).FirstOrDefault(), - exp = User.Claims.Where(a => a.Type == "exp").Select(e => Convert.ToInt32(e.Value)).FirstOrDefault(), - nbf = User.Claims.Where(a => a.Type == "nbf").Select(e => Convert.ToInt32(e.Value)).FirstOrDefault(), - userinfo_guid = User.Claims.Where(a => a.Type == "userinfo_guid").Select(e => e.Value).FirstOrDefault(), - }; - - if (myUser.exp == 0) - { - jwt_str = "Jwt Token不合法"; - jwtlife = false; - } - else - { - //if (myUser.exp <= DateTime.Now.AddHours(-8).AddMinutes(10).Subtract(new DateTime(1970, 1, 1)).TotalSeconds) - //{ - //取得當前登入使用者資訊 - EDFunction edFunction = new EDFunction(); - HttpContext.Session.SetString("MyApiAccount", edFunction.AESEncrypt(myUser.account)); //將帳號透過AES加密 - //} - } - - apiResult.Code = "0000"; - } - catch(Exception exception) - { - apiResult.Code = "9999"; - string json = System.Text.Json.JsonSerializer.Serialize(myUser.account); - logger.LogError("【Login/Index - 登入資訊】" + json); - logger.LogError("【Login/Index】" + exception.Message); - - return Ok(apiResult); - } - - return Ok(apiResult); - } } } diff --git a/FrontendWebApi/Controllers/MyBaseController.cs b/FrontendWebApi/Controllers/MyBaseController.cs index c319e00..70408ab 100644 --- a/FrontendWebApi/Controllers/MyBaseController.cs +++ b/FrontendWebApi/Controllers/MyBaseController.cs @@ -25,13 +25,9 @@ namespace FrontendWebApi.Controllers { private ILogger _logger; protected ILogger Logger => _logger ?? (_logger = HttpContext?.RequestServices.GetService>()); - - private IBackendRepository backendRepository => HttpContext?.RequestServices.GetService(); private IJwtHelpers jwt => HttpContext?.RequestServices.GetService(); - private IFrontendRepository frontendRepository => HttpContext?.RequestServices.GetService(); - public BackgroundService backgroundService; public MyBaseController() { } protected MyUserInfo myUserInfo = null; protected JwtGet myUser;