365 lines
11 KiB
C#
365 lines
11 KiB
C#
using AutoMapper;
|
||
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Net.Http;
|
||
using System.Net.Http.Headers;
|
||
using System.Threading.Tasks;
|
||
using UnityEngine;
|
||
using UnityEngine.Networking;
|
||
using UnityEngine.UI;
|
||
using static GameManager;
|
||
|
||
/// <summary>
|
||
/// 设备-编辑
|
||
/// </summary>
|
||
public class RedactDevice : MonoBehaviour
|
||
{
|
||
public Body mybody;
|
||
public Root URlreturn;
|
||
DeviceQuery.DeviceList device;
|
||
|
||
/// <summary>
|
||
/// 类型
|
||
/// </summary>
|
||
public Dropdown type;
|
||
/// <summary>
|
||
/// 设备类型
|
||
/// </summary>
|
||
public Dropdown deviceType;
|
||
public InputField deviceName;
|
||
public InputField deviceCode;
|
||
public InputField devicePosition;
|
||
public Dropdown status;
|
||
public Dropdown rackType;
|
||
public Dropdown openFlag;
|
||
|
||
#region 机柜的
|
||
public InputField machineModel;
|
||
public InputField manufacturer;
|
||
#endregion
|
||
public Button save_bt;
|
||
|
||
|
||
|
||
MapperConfiguration config;
|
||
IMapper mapper;
|
||
public void OnEnable()
|
||
{
|
||
config = new MapperConfiguration(cfg =>
|
||
{
|
||
cfg.CreateMap<RedactDevice.Body, DeviceQuery.DeviceList>();
|
||
cfg.CreateMap<DeviceQuery.DeviceList, RedactDevice.Body>();
|
||
});
|
||
mapper = config.CreateMapper();
|
||
try
|
||
{
|
||
if (!string.IsNullOrEmpty(GameManager.Inst.nowDeviceID))
|
||
{
|
||
for (int i = 0; i < GameManager.Inst.root_AllDevice.data.Count; i++)
|
||
{
|
||
if (GameManager.Inst.root_AllDevice.data[i].id == GameManager.Inst.nowDeviceID)
|
||
{
|
||
device = GameManager.Inst.root_AllDevice.data[i];
|
||
break;
|
||
}
|
||
}
|
||
mybody = mapper.Map<RedactDevice.Body>(device);
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
|
||
if (type) type.value = int.Parse(String.IsNullOrEmpty(mybody.type) ? "0" : mybody.type);
|
||
if (deviceType) deviceType.value = String.IsNullOrEmpty(mybody.deviceType) ? 0 : int.Parse(mybody.deviceType);
|
||
if (deviceName) deviceName.text = mybody.deviceName;
|
||
if (deviceCode) deviceCode.text = mybody.deviceCode;
|
||
if (devicePosition) devicePosition.text = mybody.devicePosition;
|
||
if (machineModel) machineModel.text = mybody.machineModel;
|
||
if (status) status.value = int.Parse(String.IsNullOrEmpty(mybody.status) ? "0" : mybody.status);
|
||
if (rackType) rackType.value = String.IsNullOrEmpty(mybody.rackType) ? 0 : int.Parse(mybody.rackType);
|
||
if (openFlag) openFlag.value = String.IsNullOrEmpty(mybody.openFlag) ? 2 : int.Parse(mybody.openFlag);
|
||
if (manufacturer) manufacturer.text = mybody.manufacturer;
|
||
}
|
||
|
||
private void Start()
|
||
{
|
||
save_bt.onClick.AddListener(() =>
|
||
{
|
||
StartCoroutine(SaveJsonCoroutine());
|
||
});
|
||
}
|
||
|
||
private IEnumerator SaveJsonCoroutine()
|
||
{
|
||
yield return StartCoroutine(saveJson());
|
||
if (URlreturn.message == "操作成功")
|
||
{
|
||
yield return StartCoroutine(GameManager.Inst.LoadAddress((ct) =>
|
||
{
|
||
if (ct != null)
|
||
{
|
||
GameManager.Inst.Jk_URL = new webURL(ct);
|
||
StartCoroutine(GameManager.Inst.Initialize());
|
||
}
|
||
else
|
||
{
|
||
Debug.Log("获取穿透错误!");
|
||
}
|
||
}));
|
||
|
||
Array.ForEach(GameManager.Inst.pop_ups.ToArray(), (itme) =>
|
||
{
|
||
itme.gameObject.SetActive(false);
|
||
});
|
||
}
|
||
else
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
|
||
}
|
||
|
||
public IEnumerator saveJson()
|
||
{
|
||
if (string.IsNullOrEmpty(mybody.id)) yield break;
|
||
|
||
if (type) mybody.type = type.value.ToString();
|
||
if (deviceType) mybody.deviceType = deviceType.value == 0 ? null : deviceType.value.ToString();
|
||
if (deviceName) mybody.deviceName = deviceName.text;
|
||
if (deviceCode) mybody.deviceCode = deviceCode.text;
|
||
if (devicePosition) mybody.devicePosition = devicePosition.text;
|
||
if (machineModel) mybody.machineModel = machineModel.text;
|
||
if (status) mybody.status = status.value.ToString();
|
||
if (rackType) mybody.rackType = rackType.value == 0 ? null : rackType.value.ToString();
|
||
if (openFlag) mybody.openFlag = openFlag.value == 2 ? null : openFlag.value.ToString();
|
||
if (manufacturer) mybody.manufacturer = manufacturer.text;
|
||
|
||
string json = JsonConvert.SerializeObject(mybody);
|
||
//Debug.Log(json);
|
||
|
||
using (UnityWebRequest request = UnityWebRequest.Post(GameManager.Inst.Jk_URL.sb_bj, json))
|
||
{
|
||
request.SetRequestHeader("X-Token", GameManager.Inst.arguments.token);
|
||
request.SetRequestHeader("Content-Type", "application/json");
|
||
|
||
yield return request.SendWebRequest();
|
||
|
||
if (request.isNetworkError || request.isHttpError)
|
||
{
|
||
Debug.LogError(request.error);
|
||
}
|
||
else
|
||
{
|
||
string body = request.downloadHandler.text;
|
||
URlreturn = JsonConvert.DeserializeObject<Root>(body);
|
||
Debug.Log(body);
|
||
}
|
||
}
|
||
}
|
||
|
||
#region JSON
|
||
[System.Serializable]
|
||
public class Body
|
||
{
|
||
/// <summary>
|
||
/// id
|
||
/// </summary>
|
||
public string id;
|
||
/// <summary>
|
||
/// 名称
|
||
/// </summary>
|
||
public string deviceName;
|
||
/// <summary>
|
||
/// 类型:1-机柜;2-设备
|
||
/// </summary>
|
||
public string type;
|
||
/// <summary>
|
||
/// 投运时间
|
||
/// </summary>
|
||
public string operationTime;
|
||
/// <summary>
|
||
/// 是否启用:1-正常;0-禁用
|
||
/// </summary>
|
||
public string status;
|
||
/// <summary>
|
||
/// 负责人
|
||
/// </summary>
|
||
public string directorName;
|
||
/// <summary>
|
||
/// 联系电话
|
||
/// </summary>
|
||
public string phone;
|
||
/// <summary>
|
||
/// 机柜型号
|
||
/// </summary>
|
||
public string machineModel;
|
||
/// <summary>
|
||
/// 机柜位置
|
||
/// </summary>
|
||
public string machinePosition;
|
||
|
||
/// <summary>
|
||
/// 编号
|
||
/// </summary>
|
||
[Tooltip("编号")] public string deviceCode;
|
||
/// <summary>
|
||
/// 类型:1-机柜;2-设备
|
||
/// </summary>
|
||
[Tooltip("类型:1-机柜;2-设备")] public string typeStr;
|
||
/// <summary>
|
||
/// 设备类型:1-机框;2-机槽;3-板卡
|
||
/// </summary>
|
||
[Tooltip("设备类型:1-机框;2-机槽;3-板卡")] public string deviceType;
|
||
/// <summary>
|
||
/// 设备类型:1-机框;2-机槽;3-板卡
|
||
/// </summary>
|
||
[Tooltip("设备类型:1-机框;2-机槽;3-板卡")] public string deviceTypeStr;
|
||
/// <summary>
|
||
/// 所属机柜id
|
||
/// </summary>
|
||
[Tooltip("所属机柜id")] public string rackId;
|
||
/// <summary>
|
||
/// 所属机框id
|
||
/// </summary>
|
||
[Tooltip("所属机框id")] public string shelfId;
|
||
/// <summary>
|
||
/// 所属机槽id
|
||
/// </summary>
|
||
[Tooltip("所属机槽id")] public string slotId;
|
||
/// <summary>
|
||
/// 设备位置
|
||
/// </summary>
|
||
[Tooltip("设备位置")] public string devicePosition;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
[Tooltip("")] public string conDeviceName;
|
||
/// <summary>
|
||
/// 机柜类型:1-通信机柜;2-非通信机柜
|
||
/// </summary>
|
||
[Tooltip("机柜类型:1-通信机柜;2-非通信机柜")] public string rackType;
|
||
/// <summary>
|
||
/// 柜门是否打开:1-开;0-关
|
||
/// </summary>
|
||
[Tooltip("柜门是否打开:1-开;0-关")] public string openFlag;
|
||
/// <summary>
|
||
/// 模型编号
|
||
/// </summary>
|
||
[Tooltip("模型编号")] public string modelNum;
|
||
/// <summary>
|
||
/// U位占用数量
|
||
/// </summary>
|
||
[Tooltip("U位占用数量")] public string occupyNum;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
[Tooltip("")] public string residueNum;
|
||
/// <summary>
|
||
/// 生产厂家
|
||
/// </summary>
|
||
[Tooltip("生产厂家")] public string manufacturer;
|
||
/// <summary>
|
||
/// 电源属性
|
||
/// </summary>
|
||
[Tooltip("电源属性")] public string powerProperties;
|
||
/// <summary>
|
||
/// 维护单位
|
||
/// </summary>
|
||
[Tooltip("维护单位")] public string maintenanceUnit;
|
||
/// <summary>
|
||
/// 机框高度
|
||
/// </summary>
|
||
[Tooltip("机框高度")] public string machineFrameHigh;
|
||
/// <summary>
|
||
/// 机框宽度
|
||
/// </summary>
|
||
[Tooltip("机框宽度")] public string machineFrameWide;
|
||
/// <summary>
|
||
/// 机框厚度
|
||
/// </summary>
|
||
[Tooltip("机框厚度")] public string machineFrameThick;
|
||
/// <summary>
|
||
/// 插槽数量
|
||
/// </summary>
|
||
[Tooltip("插槽数量")] public string slotNum;
|
||
/// <summary>
|
||
/// 插槽排列方式
|
||
/// </summary>
|
||
[Tooltip("插槽排列方式")] public string slotSort;
|
||
/// <summary>
|
||
/// 安装方式
|
||
/// </summary>
|
||
[Tooltip("安装方式")] public string installMethod;
|
||
/// <summary>
|
||
/// 所属机框
|
||
/// </summary>
|
||
[Tooltip("所属机框")] public string affiliationFrame;
|
||
/// <summary>
|
||
/// 父插槽名称
|
||
/// </summary>
|
||
[Tooltip("父插槽名称")] public string parentSlotName;
|
||
/// <summary>
|
||
/// 插槽类型
|
||
/// </summary>
|
||
[Tooltip("插槽类型")] public string slotType;
|
||
/// <summary>
|
||
/// 占用状态
|
||
/// </summary>
|
||
[Tooltip("占用状态")] public string occupyStatus;
|
||
/// <summary>
|
||
/// 所属机槽名称
|
||
/// </summary>
|
||
[Tooltip("所属机槽名称")] public string affiliationSlot;
|
||
/// <summary>
|
||
/// 端口数量
|
||
/// </summary>
|
||
[Tooltip("端口数量")] public string portNum;
|
||
/// <summary>
|
||
/// 板卡功能
|
||
/// </summary>
|
||
[Tooltip("板卡功能")] public string cardFunction;
|
||
/// <summary>
|
||
/// 板卡类型
|
||
/// </summary>
|
||
[Tooltip("板卡类型")] public string cardType;
|
||
/// <summary>
|
||
/// 运行状态
|
||
/// </summary>
|
||
[Tooltip("运行状态")] public string runStatus;
|
||
/// <summary>
|
||
/// 备注
|
||
/// </summary>
|
||
[Tooltip("备注")] public string remark;
|
||
}
|
||
|
||
[System.Serializable]
|
||
public class Root
|
||
{
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string code;
|
||
/// <summary>
|
||
/// 反馈结果
|
||
/// </summary>
|
||
public string message;
|
||
/// <summary>
|
||
/// 返回内容
|
||
/// </summary>
|
||
public string data;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string serverTime;
|
||
}
|
||
#endregion
|
||
|
||
}
|