454 lines
15 KiB
C#
454 lines
15 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()
|
||
{
|
||
mybody = new Body();
|
||
//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);
|
||
if (device != null)
|
||
{
|
||
mybody.id = device.id;
|
||
mybody.deviceName = device.deviceName;
|
||
mybody.deviceCode = device.deviceCode;
|
||
mybody.type = device.type;
|
||
mybody.typeStr = device.typeStr;
|
||
mybody.deviceType = device.deviceType;
|
||
mybody.deviceTypeStr = device.deviceTypeStr;
|
||
mybody.rackId = device.rackId;
|
||
mybody.shelfId = device.shelfId;
|
||
mybody.slotId = device.slotId;
|
||
mybody.devicePosition = device.devicePosition;
|
||
mybody.machineModel = device.machineModel;
|
||
mybody.status = device.status;
|
||
mybody.conDeviceName = device.conDeviceName;
|
||
mybody.rackType = device.rackType;
|
||
mybody.openFlag = device.openFlag;
|
||
mybody.backDoorFlag = device.backDoorFlag;
|
||
mybody.modelNum = device.modelNum;
|
||
mybody.occupyNum = device.occupyNum;
|
||
mybody.residueNum = device.residueNum;
|
||
mybody.operationTime = device.operationTime;
|
||
mybody.directorName = device.directorName;
|
||
mybody.phone = device.phone;
|
||
mybody.manufacturer = device.manufacturer;
|
||
mybody.powerProperties = device.powerProperties;
|
||
mybody.maintenanceUnit = device.maintenanceUnit;
|
||
mybody.machineFrameHigh = device.machineFrameHigh;
|
||
mybody.machineFrameWide = device.machineFrameWide;
|
||
mybody.machineFrameThick = device.machineFrameThick;
|
||
mybody.slotNum = device.slotNum;
|
||
mybody.slotSort = device.slotSort;
|
||
mybody.installMethod = device.installMethod;
|
||
mybody.affiliationFrame = device.affiliationFrame;
|
||
mybody.parentSlotName = device.parentSlotName;
|
||
mybody.slotType = device.slotType;
|
||
mybody.occupyStatus = device.occupyStatus;
|
||
mybody.affiliationSlot = device.affiliationSlot;
|
||
mybody.portNum = device.portNum;
|
||
mybody.cardFunction = device.cardFunction;
|
||
mybody.cardType = device.cardType;
|
||
mybody.runStatus = device.runStatus;
|
||
}
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Debug.Log(e.StackTrace + "**********" + e.Message);
|
||
}
|
||
|
||
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) ? "2" : mybody.status);
|
||
if (rackType) rackType.value = String.IsNullOrEmpty(mybody.rackType) ? 0 : int.Parse(mybody.rackType);
|
||
if (openFlag) openFlag.value = String.IsNullOrEmpty(mybody.openFlag) ? 0 : int.Parse(mybody.openFlag);
|
||
if (manufacturer) manufacturer.text = mybody.manufacturer;
|
||
|
||
if (GameManager.Inst.nowDevice.GetComponent<DeviceQuery>().deviceList.deviceType == "1")
|
||
{
|
||
var part = GameManager.Inst.FindParent(GameManager.Inst.nowDevice, GameManager.Inst.IsDesiredParent);
|
||
mybody.rackId = part.GetComponent<DeviceQuery>().deviceList.id;
|
||
mybody.devicePosition = GameManager.Inst.nowDevice.transform.parent.name;
|
||
if (devicePosition) devicePosition.text = mybody.devicePosition;
|
||
}
|
||
}
|
||
|
||
private void Start()
|
||
{
|
||
save_bt.onClick.AddListener(() =>
|
||
{
|
||
GameManager.Inst.editorMenu.gameObject.SetActive(false);
|
||
StartCoroutine(SaveJsonCoroutine());
|
||
});
|
||
}
|
||
|
||
private IEnumerator SaveJsonCoroutine()
|
||
{
|
||
yield return StartCoroutine(saveJson());
|
||
if (URlreturn != null && URlreturn.message == "操作成功")
|
||
{
|
||
|
||
StartCoroutine(Succeed((x) =>
|
||
{
|
||
if (x)
|
||
{
|
||
Array.ForEach(GameManager.Inst.pop_ups.ToArray(), (itme) =>
|
||
{
|
||
itme.gameObject.SetActive(false);
|
||
});
|
||
GameManager.Inst.objectToShow_add.gameObject.SetActive(true);
|
||
var SN1 = GameManager.Inst.objectToShow_add.GetComponent<SearchName1>();
|
||
SN1.hide_menu();
|
||
}
|
||
}));
|
||
|
||
}
|
||
else
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
public IEnumerator Succeed(Action<bool> callback)
|
||
{
|
||
Array.ForEach(GameObject.FindObjectsOfType<UPosItem>(), (item) =>
|
||
{
|
||
item.isOccupied = false;
|
||
});
|
||
GameManager.Inst.isLoading = false;
|
||
|
||
//TransparentGlowManage.Inst.addScript();
|
||
|
||
//yield return StartCoroutine(GameManager.Inst.init_Device());
|
||
|
||
//yield return StartCoroutine(GameManager.Inst.init_Port());
|
||
|
||
|
||
//yield return StartCoroutine(LineQuery.Inst.getJsonCoroutine());
|
||
|
||
//GameManager.Inst.LoadScene();
|
||
//callback.Invoke(true);
|
||
yield return null;
|
||
StartCoroutine(GameManager.Inst.Initialize((x) =>
|
||
{
|
||
if (!string.IsNullOrEmpty(x))
|
||
callback.Invoke(true);
|
||
}));
|
||
}
|
||
|
||
|
||
private void Update()
|
||
{
|
||
|
||
}
|
||
|
||
public IEnumerator saveJson()
|
||
{
|
||
if (type.value == 0 || deviceType.value == 0 || status.value == 2) yield break;
|
||
if (string.IsNullOrEmpty(mybody.id)) yield break;
|
||
|
||
try
|
||
{
|
||
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 == 0 ? null : openFlag.value.ToString();
|
||
if (manufacturer) mybody.manufacturer = manufacturer.text;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Debug.Log("修改设备错误:" + e.Message);
|
||
//gameObject.SetActive(false);
|
||
yield break;
|
||
}
|
||
|
||
|
||
string newData = JsonConvert.SerializeObject(mybody);
|
||
|
||
yield return StartCoroutine(
|
||
CombineJSON.UpdateJson_POST(GameManager.Inst.Jk_URL.sb_bj, GameManager.Inst.arguments.token, newData, (jsonResult) =>
|
||
{
|
||
try
|
||
{
|
||
URlreturn = JsonConvert.DeserializeObject<Root>(jsonResult);
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Debug.Log("修改设备接口错误:" + e.Message);
|
||
}
|
||
}
|
||
));
|
||
}
|
||
|
||
#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>
|
||
/// 后柜门是否打开:1-开;0-关
|
||
/// </summary>
|
||
[Tooltip("后柜门是否打开:1-开;0-关")] public string backDoorFlag;
|
||
/// <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
|
||
|
||
}
|