129 lines
5.5 KiB
C#
129 lines
5.5 KiB
C#
|
using Backend.Models;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
using Microsoft.Extensions.Logging;
|
|||
|
using Newtonsoft.Json;
|
|||
|
using Repository.BackendRepository.Interface;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Net;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace Backend.ApiControllers
|
|||
|
{
|
|||
|
public class DeviceApiController : MyBaseApiController<DeviceApiController>
|
|||
|
{
|
|||
|
private readonly IBackendRepository backendRepository;
|
|||
|
public DeviceApiController(IBackendRepository backendRepository)
|
|||
|
{
|
|||
|
this.backendRepository = backendRepository;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 修改設備名稱
|
|||
|
/// </summary>
|
|||
|
/// <param name="change"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpPost]
|
|||
|
[Route("api/Device/SaveChangeName")]
|
|||
|
public async Task<ActionResult<ApiResult<string>>> SaveChangeName(ChangeName change)
|
|||
|
{
|
|||
|
ApiResult<string> apiResult = new ApiResult<string>();
|
|||
|
if (!jwtlife)
|
|||
|
{
|
|||
|
apiResult.Code = "5000";
|
|||
|
return BadRequest(apiResult);
|
|||
|
}
|
|||
|
try
|
|||
|
{
|
|||
|
if (change.ChooseTable == 0)
|
|||
|
{
|
|||
|
//一般設備
|
|||
|
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}'");
|
|||
|
|
|||
|
//記錄使用者操作紀錄
|
|||
|
Dictionary<string, object> userOperatorLog = new Dictionary<string, object>()
|
|||
|
{
|
|||
|
{ "@user_guid", myUser.userinfo_guid },
|
|||
|
{ "@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";
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//燈控設備
|
|||
|
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}'");
|
|||
|
|
|||
|
////記錄使用者操作紀錄
|
|||
|
//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";
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception exception)
|
|||
|
{
|
|||
|
apiResult.Code = "9999";
|
|||
|
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
|||
|
return Ok(apiResult);
|
|||
|
}
|
|||
|
return Ok(apiResult);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|