498 lines
14 KiB
C#
498 lines
14 KiB
C#
using AutoMapper;
|
||
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Threading.Tasks;
|
||
using Unity.VisualScripting.Antlr3.Runtime;
|
||
using UnityEngine;
|
||
using UnityEngine.Events;
|
||
using UnityEngine.UI;
|
||
using static GameManager;
|
||
/// <summary>
|
||
/// 设备-新增
|
||
/// </summary>
|
||
public class AddDevice : MonoBehaviour
|
||
{
|
||
public Root URlreturn;
|
||
public Body mybody = new Body();
|
||
public Button save_bt;
|
||
|
||
/// <summary>
|
||
/// 类型:1-机柜;2-设备
|
||
/// </summary>
|
||
public Dropdown type;
|
||
/// <summary>
|
||
/// 设备类型:1-机框;2-机槽;3-板卡
|
||
/// </summary>
|
||
public Dropdown deviceType;
|
||
/// <summary>
|
||
/// 所属机柜id
|
||
/// </summary>
|
||
public Dropdown rackId;
|
||
/// <summary>
|
||
/// 所属机框id
|
||
/// </summary>
|
||
public Dropdown shelfId;
|
||
/// <summary>
|
||
/// 所属机槽id
|
||
/// </summary>
|
||
public Dropdown slotId;
|
||
/// <summary>
|
||
/// 设备位置
|
||
/// </summary>
|
||
//public InputField devicePosition;
|
||
/// <summary>
|
||
/// 是否启用:1-正常;0-禁用
|
||
/// </summary>
|
||
public Dropdown status;
|
||
|
||
//MapperConfiguration config;
|
||
//IMapper mapper;
|
||
DeviceQuery.DeviceList device;
|
||
private void OnEnable()
|
||
{
|
||
init();
|
||
//config = new MapperConfiguration(cfg =>
|
||
//{
|
||
// cfg.CreateMap<AddDevice.Body, DeviceQuery.DeviceList>();
|
||
// cfg.CreateMap<DeviceQuery.DeviceList, AddDevice.Body>();
|
||
//});
|
||
//mapper = config.CreateMapper();
|
||
try
|
||
{
|
||
if (GameManager.Inst.nowDevice.GetComponent<DeviceQuery>().deviceList.deviceType != "1")
|
||
{
|
||
if (!string.IsNullOrEmpty(GameManager.Inst.nowDeviceID))
|
||
{
|
||
for (int i = 0; i < GameManager.Inst.root_AllDevice.data.Count; i++)
|
||
{
|
||
if (GameManager.Inst.TmsPorts[i].id == GameManager.Inst.nowDeviceID)
|
||
{
|
||
device = GameManager.Inst.root_AllDevice.data[i];
|
||
break;
|
||
}
|
||
}
|
||
if (device != null)
|
||
{
|
||
//mybody = mapper.Map<AddDevice.Body>(deviceList);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//mybody = mapper.Map<AddDevice.Body>(GameManager.Inst.nowDevice.GetComponent<DeviceQuery>().deviceList);
|
||
}
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Debug.Log(e.StackTrace + "**********" + e.Message);
|
||
}
|
||
tbinfo();
|
||
}
|
||
|
||
public void tbinfo()
|
||
{
|
||
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;
|
||
mybody.modelNum = GameManager.Inst.objectToShow_add.transform.Find("DragInstruct").GetComponent<DragController>().oriObjectPrefab.gameObject.name;
|
||
}
|
||
}
|
||
|
||
public void init()
|
||
{
|
||
rackId.options.Clear();
|
||
shelfId.options.Clear();
|
||
slotId.options.Clear();
|
||
|
||
List<string> rackId_ops = new List<string>();
|
||
rackId_ops.Add("");
|
||
for (int i = 0; i < GameManager.Inst.Cabinets.Count; i++)
|
||
{
|
||
rackId_ops.Add(GameManager.Inst.Cabinets[i].id);
|
||
}
|
||
rackId.AddOptions(rackId_ops);
|
||
|
||
List<string> shelfId_ops = new List<string>();
|
||
shelfId_ops.Add("");
|
||
for (int i = 0; i < GameManager.Inst.Racks.Count; i++)
|
||
{
|
||
shelfId_ops.Add(GameManager.Inst.Racks[i].id);
|
||
}
|
||
shelfId.AddOptions(shelfId_ops);
|
||
|
||
List<string> slotId_ops = new List<string>();
|
||
slotId_ops.Add("");
|
||
for (int i = 0; i < GameManager.Inst.MachineSlots.Count; i++)
|
||
{
|
||
slotId_ops.Add(GameManager.Inst.MachineSlots[i].id);
|
||
}
|
||
slotId.AddOptions(slotId_ops);
|
||
|
||
//devicePosition.text = "";
|
||
|
||
status.value = 0;
|
||
}
|
||
|
||
private void Start()
|
||
{
|
||
rackId.onValueChanged.AddListener(rackId_fuc);//机柜
|
||
//shelfId.onValueChanged.AddListener(shelfId_fuc);//机框
|
||
//slotId.onValueChanged.AddListener(slotId_fuc);//基槽
|
||
|
||
save_bt.onClick.AddListener(() =>
|
||
{
|
||
GameManager.Inst.editorMenu.gameObject.SetActive(false);
|
||
|
||
StartCoroutine(SaveJsonCoroutine());
|
||
});
|
||
}
|
||
|
||
private IEnumerator SaveJsonCoroutine()
|
||
{
|
||
yield return StartCoroutine(saveJson((x) =>
|
||
{
|
||
if (URlreturn != null && URlreturn.message == "操作成功")
|
||
{
|
||
//StartCoroutine(Succeed());
|
||
|
||
StartCoroutine(Succeed((x) =>
|
||
{
|
||
if (x)
|
||
{
|
||
DestroyImmediate(GameManager.Inst.nowDevice);
|
||
GameManager.Inst.lastDeviceID = URlreturn.data;
|
||
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();
|
||
}
|
||
}));
|
||
|
||
}
|
||
}));
|
||
|
||
}
|
||
|
||
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);
|
||
}
|
||
|
||
|
||
private void slotId_fuc(int arg0)
|
||
{
|
||
//办卡
|
||
}
|
||
|
||
private void shelfId_fuc(int arg0)
|
||
{
|
||
//办卡
|
||
}
|
||
|
||
private void rackId_fuc(int arg0)
|
||
{
|
||
//该机柜下 机框-基槽
|
||
//rackId.options[arg0].text;//机柜ID
|
||
|
||
shelfId.options.Clear();
|
||
slotId.options.Clear();
|
||
List<string> shelfId_ops = new List<string>();
|
||
shelfId_ops.Add("");
|
||
for (int i = 0; i < GameManager.Inst.Racks_go.Count; i++)
|
||
{
|
||
var n = GameManager.Inst.Racks_go[i].GetComponent<DeviceQuery>().deviceList;
|
||
if (n.rackId == rackId.options[arg0].text)
|
||
shelfId_ops.Add(n.id);
|
||
}
|
||
shelfId.AddOptions(shelfId_ops);
|
||
|
||
List<string> slotId_ops = new List<string>();
|
||
slotId_ops.Add("");
|
||
for (int i = 0; i < GameManager.Inst.MachineSlots_go.Count; i++)
|
||
{
|
||
var n = GameManager.Inst.MachineSlots_go[i].GetComponent<DeviceQuery>().deviceList;
|
||
if (n.rackId == rackId.options[arg0].text)
|
||
slotId_ops.Add(n.id);
|
||
}
|
||
slotId.AddOptions(slotId_ops);
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
|
||
|
||
}
|
||
|
||
public IEnumerator saveJson(Action<Root> callback = null)
|
||
{
|
||
//if (type.value == 0 || deviceType.value == 0 || status.value == 2) yield break;
|
||
try
|
||
{
|
||
DragTest1 d = new DragTest1();
|
||
if (GameManager.Inst.nowDevice.GetComponent<DeviceQuery>())
|
||
{
|
||
d = GameManager.Inst.nowDevice.GetComponent<DragTest1>();
|
||
mybody.occupyNum = d.volume.ToString();
|
||
mybody.modelNum = d.name.Replace("(Clone)", "");
|
||
mybody.devicePosition = d.transform.parent.name;
|
||
}
|
||
|
||
|
||
mybody.type = type.value.ToString();
|
||
|
||
mybody.deviceType = deviceType.value.ToString();
|
||
|
||
//mybody.rackId = rackId.options[rackId.value].text;
|
||
|
||
//mybody.shelfId = shelfId.options[shelfId.value].text;
|
||
|
||
//mybody.slotId = slotId.options[slotId.value].text;
|
||
|
||
//mybody.devicePosition = devicePosition.text;
|
||
|
||
mybody.status = status.value.ToString();
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Debug.Log("新增设备错误:" + e.Message);
|
||
gameObject.SetActive(false);
|
||
yield break;
|
||
}
|
||
|
||
|
||
var newData = JsonConvert.SerializeObject(mybody);
|
||
|
||
//var jsonResult = await CombineJSON.UpdateJson_POST(GameManager.Inst.Jk_URL.sb_xz, GameManager.Inst.token, newData);
|
||
|
||
//URlreturn = JsonConvert.DeserializeObject<Root>(jsonResult);
|
||
|
||
yield return
|
||
StartCoroutine(
|
||
CombineJSON.UpdateJson_POST(GameManager.Inst.Jk_URL.sb_xz, GameManager.Inst.arguments.token, newData, (jsonResult) =>
|
||
{
|
||
try
|
||
{
|
||
URlreturn = JsonConvert.DeserializeObject<Root>(jsonResult);
|
||
callback?.Invoke(URlreturn);
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Debug.Log("新增设备接口错误:" + e.Message);
|
||
}
|
||
})
|
||
);
|
||
}
|
||
|
||
#region JSON
|
||
[System.Serializable]
|
||
public class Body
|
||
{
|
||
/// <summary>
|
||
/// 名称
|
||
/// </summary>
|
||
public string deviceName;
|
||
/// <summary>
|
||
/// 设备编号
|
||
/// </summary>
|
||
public string deviceCode;
|
||
/// <summary>
|
||
/// 类型:1-机柜;2-设备
|
||
/// </summary>
|
||
public string type;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string typeStr;
|
||
/// <summary>
|
||
/// 设备类型:1-机框;2-机槽;3-板卡
|
||
/// </summary>
|
||
public string deviceType;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string deviceTypeStr;
|
||
/// <summary>
|
||
/// 所属机柜id
|
||
/// </summary>
|
||
public string rackId;
|
||
/// <summary>
|
||
/// 所属机框id
|
||
/// </summary>
|
||
public string shelfId;
|
||
/// <summary>
|
||
/// 所属机槽id
|
||
/// </summary>
|
||
public string slotId;
|
||
/// <summary>
|
||
/// 设备位置
|
||
/// </summary>
|
||
public string devicePosition;
|
||
/// <summary>
|
||
/// 机柜型号
|
||
/// </summary>
|
||
public string machineModel;
|
||
/// <summary>
|
||
/// 是否启用:1-正常;0-禁用
|
||
/// </summary>
|
||
public string status;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string conDeviceName;
|
||
/// <summary>
|
||
/// 机柜类型:1-通信机柜;2-非通信机柜
|
||
/// </summary>
|
||
public string rackType;
|
||
/// <summary>
|
||
/// 柜门是否打开:1-开;0-关
|
||
/// </summary>
|
||
public string openFlag;
|
||
/// <summary>
|
||
/// 模型编号
|
||
/// </summary>
|
||
public string modelNum;
|
||
/// <summary>
|
||
/// U位占用数量
|
||
/// </summary>
|
||
public string occupyNum;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string residueNum;
|
||
/// <summary>
|
||
/// 投运时间
|
||
/// </summary>
|
||
public string operationTime;
|
||
/// <summary>
|
||
/// 负责人
|
||
/// </summary>
|
||
public string directorName;
|
||
/// <summary>
|
||
/// 联系电话
|
||
/// </summary>
|
||
public string phone;
|
||
/// <summary>
|
||
/// 生产厂家
|
||
/// </summary>
|
||
public string manufacturer;
|
||
/// <summary>
|
||
/// 电源属性
|
||
/// </summary>
|
||
public string powerProperties;
|
||
/// <summary>
|
||
/// 维护单位
|
||
/// </summary>
|
||
public string maintenanceUnit;
|
||
/// <summary>
|
||
/// 机框高度
|
||
/// </summary>
|
||
public string machineFrameHigh;
|
||
/// <summary>
|
||
/// 机框宽度
|
||
/// </summary>
|
||
public string machineFrameWide;
|
||
/// <summary>
|
||
/// 机框厚度
|
||
/// </summary>
|
||
public string machineFrameThick;
|
||
/// <summary>
|
||
/// 插槽数量
|
||
/// </summary>
|
||
public string slotNum;
|
||
/// <summary>
|
||
/// 插槽排列方式
|
||
/// </summary>
|
||
public string slotSort;
|
||
/// <summary>
|
||
/// 安装方式
|
||
/// </summary>
|
||
public string installMethod;
|
||
/// <summary>
|
||
/// 所属机框
|
||
/// </summary>
|
||
public string affiliationFrame;
|
||
/// <summary>
|
||
/// 父插槽名称
|
||
/// </summary>
|
||
public string parentSlotName;
|
||
/// <summary>
|
||
/// 插槽类型
|
||
/// </summary>
|
||
public string slotType;
|
||
/// <summary>
|
||
/// 占用状态
|
||
/// </summary>
|
||
public string occupyStatus;
|
||
/// <summary>
|
||
/// 所属机槽名称
|
||
/// </summary>
|
||
public string affiliationSlot;
|
||
/// <summary>
|
||
/// 端口数量
|
||
/// </summary>
|
||
public string portNum;
|
||
/// <summary>
|
||
/// 板卡功能
|
||
/// </summary>
|
||
public string cardFunction;
|
||
/// <summary>
|
||
/// 板卡类型
|
||
/// </summary>
|
||
public string cardType;
|
||
/// <summary>
|
||
/// 运行状态
|
||
/// </summary>
|
||
public string runStatus;
|
||
/// <summary>
|
||
/// 备注
|
||
/// </summary>
|
||
public string remark;
|
||
}
|
||
|
||
[System.Serializable]
|
||
public class Root
|
||
{
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string code;
|
||
/// <summary>
|
||
/// 反馈结果
|
||
/// </summary>
|
||
public string message;
|
||
/// <summary>
|
||
/// 返回内容(ID)
|
||
/// </summary>
|
||
public string data;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string serverTime;
|
||
}
|
||
|
||
#endregion
|
||
}
|