Merge branch 'master' of https://gitea.mjm-staging.developers-homelab.net/BIMS/BIMS
This commit is contained in:
commit
14285abf75
@ -695,39 +695,119 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string authHeader = HttpContext.Request.Headers["Authorization"];
|
if (change.ChooseTable == 0)
|
||||||
var websiteurl = await frontendRepository.GetOneAsync<string>("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);
|
//一般設備
|
||||||
}
|
var GetOne = await backendRepository.GetOneAsync<Device>("device", $" device_number = '{change.TagName}'");
|
||||||
|
if (GetOne == null)
|
||||||
|
{
|
||||||
|
apiResult.Data = "查無資料";
|
||||||
|
apiResult.Code = "0001";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//修改設備名稱
|
||||||
|
Dictionary<string, object> ChangeN = new Dictionary<string, object>();
|
||||||
|
ChangeN = new Dictionary<string, object>()
|
||||||
|
{
|
||||||
|
{ "@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();
|
Dictionary<string, object> userOperatorLog = new Dictionary<string, object>()
|
||||||
var statusNumber = (int)response.StatusCode;
|
{
|
||||||
if (statusNumber != 200)
|
{ "@user_guid", myUser.userinfo_guid },
|
||||||
{
|
{ "@operation_type", 1 }, //1:名稱修改
|
||||||
throw new NotImplementedException(responseString);
|
{ "@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
|
else
|
||||||
{
|
{
|
||||||
//解析回傳內容
|
//燈控設備
|
||||||
var final = JObject.Parse(responseString);
|
var GetOne = await backendRepository.GetOneAsync<string>("device_master", $" device_master_number = '{change.TagName}'");
|
||||||
|
if (GetOne == null)
|
||||||
|
{
|
||||||
|
apiResult.Data = "查無資料";
|
||||||
|
apiResult.Code = "0001";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Dictionary<string, object> ChangeN = new Dictionary<string, object>();
|
||||||
|
ChangeN = new Dictionary<string, object>()
|
||||||
|
{
|
||||||
|
{ "@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<string, object> userOperatorLog = new Dictionary<string, object>()
|
||||||
|
//{
|
||||||
|
// { "@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<string>("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)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user