From 2c69e4d0b2c57c7e999d9fb346fa7c123b9c600a Mon Sep 17 00:00:00 2001 From: dev02 Date: Tue, 24 Oct 2023 17:59:04 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=BE=8C=E7=AB=AF]=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/DeviceManageController.cs | 132 ++++++++++++++---- 1 file changed, 106 insertions(+), 26 deletions(-) diff --git a/FrontendWebApi/ApiControllers/DeviceManageController.cs b/FrontendWebApi/ApiControllers/DeviceManageController.cs index 70b3dab..7083306 100644 --- a/FrontendWebApi/ApiControllers/DeviceManageController.cs +++ b/FrontendWebApi/ApiControllers/DeviceManageController.cs @@ -695,39 +695,119 @@ namespace FrontendWebApi.ApiControllers } try { - string authHeader = HttpContext.Request.Headers["Authorization"]; - var websiteurl = await frontendRepository.GetOneAsync("select system_value from variable where system_type = 'website_config' and system_key = 'website_url' "); - //傳送到後台API - HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"{websiteurl}api/Device/SaveChangeName"); - request.Method = "POST"; - request.Headers.Add("Authorization", authHeader); - request.ContentType = "application/x-www-form-urlencoded"; - request.PreAuthenticate = true; - NameValueCollection postParams = System.Web.HttpUtility.ParseQueryString(string.Empty); - postParams.Add("TagName", change.TagName); - postParams.Add("ChangeN", change.ChangeN); - postParams.Add("ChooseTable", change.ChooseTable.ToString()); - byte[] postData = Encoding.UTF8.GetBytes(postParams.ToString()); - using (Stream st = request.GetRequestStream()) + if (change.ChooseTable == 0) { - st.Write(postData, 0, postData.Length); - } + //一般設備 + var GetOne = await backendRepository.GetOneAsync("device", $" device_number = '{change.TagName}'"); + if (GetOne == null) + { + apiResult.Data = "查無資料"; + apiResult.Code = "0001"; + } + else + { + //修改設備名稱 + Dictionary ChangeN = new Dictionary(); + ChangeN = new Dictionary() + { + { "@full_name", change.ChangeN}, + { "@updated_at",DateTime.Now}, + }; + await backendRepository.UpdateOneByCustomTable(ChangeN, "device", $" device_number = '{change.TagName}'"); - HttpWebResponse response = (HttpWebResponse)request.GetResponse(); - var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); - var statusNumber = (int)response.StatusCode; - if (statusNumber != 200) - { - throw new NotImplementedException(responseString); + //記錄使用者操作紀錄 + Dictionary userOperatorLog = new Dictionary() + { + { "@user_guid", myUser.userinfo_guid }, + { "@operation_type", 1 }, //1:名稱修改 + { "@building_tag", GetOne.device_building_tag }, + { "@main_system_tag", GetOne.device_system_tag }, + { "@sub_system_tag", GetOne.device_name_tag }, + { "@floor_tag", GetOne.device_floor_tag }, + { "@device_guid", GetOne.device_guid }, + { "@action_name", "修改名稱" }, + { "@parameter", JsonConvert.SerializeObject(change) }, + }; + + await backendRepository.AddOneByCustomTable(userOperatorLog, "operation_log"); + + apiResult.Data = "更改成功"; + apiResult.Code = "0000"; + } } else { - //解析回傳內容 - var final = JObject.Parse(responseString); + //燈控設備 + var GetOne = await backendRepository.GetOneAsync("device_master", $" device_master_number = '{change.TagName}'"); + if (GetOne == null) + { + apiResult.Data = "查無資料"; + apiResult.Code = "0001"; + } + else + { + Dictionary ChangeN = new Dictionary(); + ChangeN = new Dictionary() + { + { "@device_master_full_name", change.ChangeN}, + { "@updated_at",DateTime.Now}, + }; + await backendRepository.UpdateOneByCustomTable(ChangeN, "device_master", $" device_master_number = '{change.TagName}'"); - apiResult.Code = final["code"].ToString(); - apiResult.Data = final["data"].ToString(); + ////記錄使用者操作紀錄 + //Dictionary userOperatorLog = new Dictionary() + //{ + // { "@user_guid", myUser }, + // { "@operation_type", 1 }, //1:名稱修改 + // { "@building_guid", GetOne.Building_guid }, + // { "@main_system_guid", GetOne.Main_system_guid }, + // { "@sub_system_guid", GetOne.Sub_system_guid }, + // { "@floor_guid", GetOne.Floor_guid }, + // { "@device_guid", GetOne.Device_guid }, + // { "@action_name", "修改名稱" }, + // { "@parameter", JsonConvert.SerializeObject(change) }, + //}; + + //await backendRepository.AddOneByCustomTable(userOperatorLog, "operation_log"); + + apiResult.Data = "更改成功"; + apiResult.Code = "0000"; + } } + + //string authHeader = HttpContext.Request.Headers["Authorization"]; + //var websiteurl = await frontendRepository.GetOneAsync("select system_value from variable where system_type = 'website_config' and system_key = 'website_url' "); + ////傳送到後台API + //HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"{websiteurl}api/Device/SaveChangeName"); + //request.Method = "POST"; + //request.Headers.Add("Authorization", authHeader); + //request.ContentType = "application/x-www-form-urlencoded"; + //request.PreAuthenticate = true; + //NameValueCollection postParams = System.Web.HttpUtility.ParseQueryString(string.Empty); + //postParams.Add("TagName", change.TagName); + //postParams.Add("ChangeN", change.ChangeN); + //postParams.Add("ChooseTable", change.ChooseTable.ToString()); + //byte[] postData = Encoding.UTF8.GetBytes(postParams.ToString()); + //using (Stream st = request.GetRequestStream()) + //{ + // st.Write(postData, 0, postData.Length); + //} + + //HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + //var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); + //var statusNumber = (int)response.StatusCode; + //if (statusNumber != 200) + //{ + // throw new NotImplementedException(responseString); + //} + //else + //{ + // //解析回傳內容 + // var final = JObject.Parse(responseString); + + // apiResult.Code = final["code"].ToString(); + // apiResult.Data = final["data"].ToString(); + //} } catch (Exception exception) {