From 33a69603f954e43c5470b6c051eb42e6f16c960f Mon Sep 17 00:00:00 2001 From: dev02 Date: Fri, 28 Oct 2022 09:36:45 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=89=8D=E5=8F=B0]=20=E5=88=AA=E9=99=A4contro?= =?UTF-8?q?llers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/EmergencyContactController.cs | 232 ------------------ .../EmergencyDeviceMenuController.cs | 24 -- .../Controllers/EmergencyRecordController.cs | 142 ----------- FrontendWebApi/Controllers/HomeController.cs | 25 -- FrontendWebApi/Controllers/LoginController.cs | 145 ----------- .../Controllers/MyBaseController.cs | 167 ------------- .../Controllers/RescueDeviceController.cs | 34 --- 7 files changed, 769 deletions(-) delete mode 100644 FrontendWebApi/Controllers/EmergencyContactController.cs delete mode 100644 FrontendWebApi/Controllers/EmergencyDeviceMenuController.cs delete mode 100644 FrontendWebApi/Controllers/EmergencyRecordController.cs delete mode 100644 FrontendWebApi/Controllers/HomeController.cs delete mode 100644 FrontendWebApi/Controllers/LoginController.cs delete mode 100644 FrontendWebApi/Controllers/MyBaseController.cs delete mode 100644 FrontendWebApi/Controllers/RescueDeviceController.cs diff --git a/FrontendWebApi/Controllers/EmergencyContactController.cs b/FrontendWebApi/Controllers/EmergencyContactController.cs deleted file mode 100644 index 15b5625..0000000 --- a/FrontendWebApi/Controllers/EmergencyContactController.cs +++ /dev/null @@ -1,232 +0,0 @@ -using FrontendWebApi.Models; -using iTextSharp.text; -using iTextSharp.text.html.simpleparser; -using iTextSharp.text.pdf; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using NPOI.SS.UserModel; -using NPOI.XSSF.UserModel; -using Repository.BackendRepository.Interface; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; - -namespace FrontendWebApi.Controllers -{ - public class EmergencyContactController : MyBaseController - { - private readonly IBackendRepository backendRepository; - public EmergencyContactController(IBackendRepository backendRepository) - { - this.backendRepository = backendRepository; - } - public IActionResult Index() - { - 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/EmergencyDeviceMenuController.cs b/FrontendWebApi/Controllers/EmergencyDeviceMenuController.cs deleted file mode 100644 index eddf142..0000000 --- a/FrontendWebApi/Controllers/EmergencyDeviceMenuController.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace FrontendWebApi.Controllers -{ - public class EmergencyDeviceMenuController : MyBaseController - { - private readonly ILogger _logger; - - public EmergencyDeviceMenuController(ILogger logger) - { - _logger = logger; - } - - public IActionResult Index() - { - return View(); - } - } -} diff --git a/FrontendWebApi/Controllers/EmergencyRecordController.cs b/FrontendWebApi/Controllers/EmergencyRecordController.cs deleted file mode 100644 index 5857d1d..0000000 --- a/FrontendWebApi/Controllers/EmergencyRecordController.cs +++ /dev/null @@ -1,142 +0,0 @@ -using FrontendWebApi.Models; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using Repository.BackendRepository.Interface; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace FrontendWebApi.Controllers -{ - public class EmergencyRecordController : MyBaseController - { - private readonly IBackendRepository backendRepository; - public EmergencyRecordController(IBackendRepository backendRepository) - { - this.backendRepository = backendRepository; - } - public IActionResult Index() - { - return View(); - } - - [HttpPost] - public async Task>> DisasterList() - { - ApiResult> apiResult = new ApiResult>(); - List Variable = new List(); - - try - { - var sqlString = @$"select system_value as Value, system_key as Name from variable a where a.system_type = 'disaster' and a.deleted = 0"; - Variable = await backendRepository.GetAllAsync(sqlString); - - apiResult.Code = "0000"; - apiResult.Data = Variable; - } - catch (Exception exception) - { - apiResult.Code = "9999"; - apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; - Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); - } - - 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/HomeController.cs b/FrontendWebApi/Controllers/HomeController.cs deleted file mode 100644 index 78e9710..0000000 --- a/FrontendWebApi/Controllers/HomeController.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace FrontendWebApi.Controllers -{ - public class HomeController : MyBaseController - { - private readonly ILogger _logger; - - public HomeController(ILogger logger) - { - _logger = logger; - } - - public IActionResult Index() - { - return View(); - } - - } -} diff --git a/FrontendWebApi/Controllers/LoginController.cs b/FrontendWebApi/Controllers/LoginController.cs deleted file mode 100644 index 8b73555..0000000 --- a/FrontendWebApi/Controllers/LoginController.cs +++ /dev/null @@ -1,145 +0,0 @@ -using FrontendWebApi.Jwt; -using FrontendWebApi.Models; -using iTextSharp.text; -using iTextSharp.text.pdf; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using NPOI.SS.UserModel; -using NPOI.XSSF.UserModel; -using Repository.BackendRepository.Interface; -using Repository.FrontendRepository.Interface; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Threading.Tasks; - -namespace FrontendWebApi.Controllers -{ - public class LoginController : Controller - { - private readonly ILogger logger; - private readonly IBackendRepository backendRepository; - private readonly IFrontendRepository frontendRepository; - private readonly IJwtHelpers jwt; - //string jwt_str = "login"; - protected MyUserInfo myUserInfo = null; - protected JwtGet myUser; - protected string jwt_str = null; - protected bool jwtlife = true; - - public LoginController - ( - ILogger logger, - IBackendRepository backendRepository, - IFrontendRepository frontendRepository, - IJwtHelpers jwt - ) - { - this.logger = logger; - this.jwt = jwt; - this.backendRepository = backendRepository; - this.frontendRepository = frontendRepository; - } - - public IActionResult Index(string jwt) - { - ViewBag.jwt = jwt; - return View(); - } - - [HttpPost] - [Route("api/Login")] - public async Task>> Login([FromBody] 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"; - apiResult.Msg = "查無此帳戶"; - 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.Msg = "登入成功"; - 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 deleted file mode 100644 index f6962de..0000000 --- a/FrontendWebApi/Controllers/MyBaseController.cs +++ /dev/null @@ -1,167 +0,0 @@ -using FrontendWebApi.Jwt; -using FrontendWebApi.Models; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.Extensions.Configuration; -using Repository.BackendRepository.Interface; -using Repository.BaseRepository.Interface; -using Repository.FrontendRepository.Interface; -using Repository.Helper; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.AspNetCore.Routing; -using System.Diagnostics; - -namespace FrontendWebApi.Controllers -{ - public class MyBaseController : Controller where T : MyBaseController - { - private ILogger _logger; - protected ILogger Logger => _logger ?? (_logger = HttpContext?.RequestServices.GetService>()); - - private IJwtHelpers jwt => HttpContext?.RequestServices.GetService(); - - private IFrontendRepository frontendRepository => HttpContext?.RequestServices.GetService(); - - public MyBaseController() { } - protected MyUserInfo myUserInfo = null; - protected JwtGet myUser; - protected string jwt_str = null; - protected bool jwtlife = true; - public string controllerName; - public string actionName; - public ErrorCode errorCode = new ErrorCode(); - [Authorize] - public override void OnActionExecuting(ActionExecutingContext filterContext) - { - EDFunction edFunction = new EDFunction(); - var myAccount = edFunction.AESDecrypt(HttpContext.Session.GetString("MyApiAccount")); - controllerName = ControllerContext.RouteData.Values["controller"].ToString(); //controller名稱 - actionName = ControllerContext.RouteData.Values["action"].ToString(); //action名稱 - - //紀錄當前PID - Process currentProcess = Process.GetCurrentProcess(); - Dictionary updateProcess = new Dictionary(); - updateProcess.Add("@system_value", currentProcess.Id.ToString()); - - frontendRepository.UpdateProcessPID(updateProcess, "variable", "system_type = 'watchDogCongfig' AND system_key = 'AlarmPID'"); - - bool isAjaxCall = filterContext.HttpContext.Request.Headers["x-requested-with"] == "XMLHttpRequest"; - if (string.IsNullOrEmpty(myAccount)) - { - - if (isAjaxCall) - { - filterContext.HttpContext.Response.Clear(); - filterContext.HttpContext.Response.StatusCode = 499; - return; - } - else - { - filterContext.Result = new RedirectToRouteResult( - new RouteValueDictionary - { - {"controller", "Login"}, - {"action", "Index"} - }); - return; - } - } - else - { - //取得當前登入使用者資訊 - myUserInfo = frontendRepository.GetMyUserInfoByAccount(myAccount); - var showview = frontendRepository.GetAllAsync($@"select ap.ShowView from userinfo us - left join role_auth ra on ra.role_guid = us.role_guid - left join auth_page ap on ap.AuthCode = ra.AuthCode - where us.userinfo_guid = '{myUserInfo.Userinfo_guid}'"); - myUserInfo.ShowView = showview.Result; - ViewBag.myUserInfo = myUserInfo; - ViewBag.role = showview.Result; - - //var showviewt = new List() - // { - // "EmergencyDeviceMenuIndex", - // "EmergencyContactIndex", - // "EmergencyRecordIndex", - // "RescueDeviceFireExtinguisher", - // "RescueDeviceAED", - // }; - //ViewBag.role = showviewt; - } - - //var ctx = filterContext.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(), - //}; - - //TODO 模擬JWT,記得刪除 - //myUser.account = "Bajascript"; - //myUser.email = "asd@com"; - //myUser.full_name = "野原廣志"; - //myUser.exp = 3600; - //myUser.userinfo_guid = "1EF9CEAC-4DBF-E2BE-8B1D-CB3014E0DA17"; - - //if (myUser.exp == 0) - //{ - // jwt_str = "Jwt Token不合法"; - // jwtlife = false; - - // ViewBag.myUserInfo = null; - // ViewBag.role = null; - //} - //else - //{ - // if (myUser.exp <= DateTime.Now.AddHours(-8).AddMinutes(10).Subtract(new DateTime(1970, 1, 1)).TotalSeconds) - // { - // //取得當前登入使用者資訊 - // myUserInfo = frontendRepository.GetMyUserInfoByAccount(myUser.account); - // //var showview = frontendRepository.GetAllAsync($@"select ap.ShowView from userinfo us - // // left join role_auth ra on ra.role_guid = us.role_guid - // // left join auth_page ap on ap.AuthCode = ra.AuthCode - // // where us.userinfo_guid = '{myUserInfo.Userinfo_guid}'"); - // //myUserInfo.ShowView = showview.Result; - // ViewBag.myUserInfo = myUserInfo; - - // var showviewt = new List() - // { - // "EmergencyDeviceMenuIndex", - // "EmergencyContactIndex", - // "EmergencyRecordIndex", - // "RescueDeviceFireExtinguisher", - // "RescueDeviceAED", - // }; - // //ViewBag.role = showview.Result; - // ViewBag.role = showviewt; - - // jwtlife = true; - // JwtLogin jwtLoing = new JwtLogin() - // { - // account = myUser.account, - // email = myUser.email, - // full_name = myUser.full_name, - // userinfo_guid = myUser.userinfo_guid - // }; - // jwt_str = jwt.GenerateToken(jwtLoing).token; - // } - //} - base.OnActionExecuting(filterContext); - } - } -} diff --git a/FrontendWebApi/Controllers/RescueDeviceController.cs b/FrontendWebApi/Controllers/RescueDeviceController.cs deleted file mode 100644 index 1d97a1b..0000000 --- a/FrontendWebApi/Controllers/RescueDeviceController.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using NPOI.HSSF.UserModel; -using NPOI.SS.UserModel; -using NPOI.XSSF.UserModel; -using Repository.BackendRepository.Interface; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; - -namespace FrontendWebApi.Controllers -{ - public class RescueDeviceController : MyBaseController - { - private readonly IBackendRepository backendRepository; - - public RescueDeviceController(IBackendRepository backendRepository) - { - this.backendRepository = backendRepository; - } - public IActionResult FireExtinguisher() - { - return View(); - } - public IActionResult AED() - { - return View(); - } - } -}