//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; /// /// 设备-编辑 /// public class RedactDevice : MonoBehaviour { public Body mybody = new Body(); public Root URlreturn = new Root(); DeviceQuery.DeviceList device = null; ///// ///// 类型 ///// //public Dropdown type; /// /// 设备类型 /// [Header("设备类型")] public Dropdown deviceTypeCode; /// /// 设施类型 /// [Header("设施类型")] public Dropdown deviceType; /// /// 网络等级(1国网;2华东网;3省网;4地区网) /// [Header("网络等级")] public Dropdown networkLevel; /// /// 板卡类型 /// [Header("板卡类型")] public Dropdown cardType; /// /// 名称 /// [Header("名称")] public InputField deviceName; /// /// 编号 /// [Header("编号")] public InputField deviceCode; /// /// 板卡槽位 /// [Header("板卡槽位")] public InputField devicePosition; /// /// 状态 /// [Header("状态")] public Dropdown status; /// /// /// public Dropdown rackType; /// /// /// public Dropdown openFlag; #region 机柜的 /// /// 机柜型号 /// [Header("机柜型号")] public InputField machineModel; /// /// 功能说明 /// [Header("功能说明")] public InputField functionDescription; /// /// 生产厂家 /// [Header("生产厂家")] public InputField manufacturer; #endregion /// /// 设备主任 /// [Header("设备主任")] public InputField directorName; /// /// 电话 /// [Header("电话")] public InputField phone; public Button save_bt; /// /// /// [Header("模型编号")] public Text modelNum; /// /// 投运时间 /// [Header("投运时间")] public InputField operationTime; /// /// 板卡功能 /// [Header("板卡功能")] public InputField cardFunction; public Button close_bt; /// /// 控制大小 /// public GameObject contentSizeFitter; //MapperConfiguration config; //IMapper mapper; public void OnEnable() { //Debug.Log("版本号 1.1.1"); mybody = new Body(); //config = new MapperConfiguration(cfg => //{ // cfg.CreateMap(); // cfg.CreateMap(); //}); //mapper = config.CreateMapper(); init(); 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(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.deviceTypeCode = device.deviceTypeCode; mybody.functionDescription = device.functionDescription; 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 = CombineJSON.Decrypt(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; mybody.networkLevel = device.networkLevel; } } } catch (Exception e) { Debug.Log(e.StackTrace + "**********" + e.Message); } if (deviceTypeCode) deviceTypeCode.value = int.Parse(String.IsNullOrEmpty(mybody.type) ? "0" : mybody.type); if (deviceType) deviceType.value = String.IsNullOrEmpty(mybody.deviceType) ? 0 : int.Parse(mybody.deviceType); if (cardType) cardType.value = String.IsNullOrEmpty(mybody.cardType) ? 0 : int.Parse(mybody.cardType); if (networkLevel) networkLevel.value = String.IsNullOrEmpty(mybody.networkLevel) ? 0 : int.Parse(mybody.networkLevel); 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 (functionDescription) functionDescription.text = mybody.functionDescription; 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 (directorName) directorName.text = mybody.directorName; if (phone) phone.text = mybody.phone; if (operationTime) operationTime.text = mybody.operationTime; if (cardFunction) cardFunction.text = mybody.cardFunction; if (GameManager.Inst.nowDevice.GetComponent().deviceList.deviceType == "1") { var part = GameManager.Inst.FindParent(GameManager.Inst.nowDevice, GameManager.Inst.IsDesiredParent); mybody.rackId = part.GetComponent().deviceList.id; mybody.devicePosition = GameManager.Inst.nowDevice.transform.parent.name; if (devicePosition) devicePosition.text = mybody.devicePosition; } else if (GameManager.Inst.nowDevice.GetComponent().deviceList.deviceType == "3") { var cabinet = GameManager.Inst.FindParent(GameManager.Inst.nowDevice, GameManager.Inst.IsDesiredParent); var shelf = GameManager.Inst.FindParent(GameManager.Inst.nowDevice, GameManager.Inst.IsFindRacks_go); if (shelf) mybody.shelfId = shelf.GetComponent().deviceList.id; mybody.devicePosition = GameManager.Inst.nowDevice.transform.parent.name; if (cabinet) mybody.rackId = cabinet.GetComponent().deviceList.id; } if (!string.IsNullOrEmpty(mybody.modelNum)) modelNum.text = mybody.modelNum; else modelNum.text = null; //Debug.Log("版本号 1.1.1"); UIShow(mybody.deviceType == "3"); } public void init() { if (deviceTypeCode) findIndex(deviceTypeCode, ""); if (deviceType) findIndex(deviceType, ""); if (networkLevel) findIndex(networkLevel, ""); if (cardType) findIndex(cardType, ""); if (deviceName) deviceName.text = null; if (deviceCode) deviceCode.text = null; if (devicePosition) devicePosition.text = null; if (machineModel) machineModel.text = null; if (functionDescription) functionDescription.text = null; if (status) findIndex(status, ""); if (manufacturer) manufacturer.text = null; if (directorName) directorName.text = null; if (phone) phone.text = null; if (operationTime) operationTime.text = null; if (cardFunction) cardFunction.text = null; mybody.rackId = null; mybody.devicePosition = null; mybody.shelfId = null; } private void Start() { save_bt.onClick.AddListener(() => { GameManager.Inst.editorMenu.gameObject.SetActive(false); StartCoroutine(SaveJsonCoroutine()); }); close_bt.onClick.AddListener(() => { gameObject.SetActive(false); if (CabinetUIManager.Instance.current_menu == Menu.M_数字机房_场景管理) { GameManager.Inst.objectToShow_add.SetActive(true); GameManager.Inst.search_box.SetActive(true); } }); } /// /// 寻找下拉菜单选项 /// /// /// public string findIndex(Dropdown _dro, string _name) { int index = _dro.options.FindIndex(x => x.text == _name); if (index != -1) { _dro.captionText.text = _dro.options[index].text; _dro.value = index; return index.ToString(); } return null; } private IEnumerator SaveJsonCoroutine() { yield return StartCoroutine(saveJson((y) => { if (string.IsNullOrEmpty(y)) { Debug.Log("编辑设备失败"); SecondConfirmPanel.DeleteConform(null, string.IsNullOrEmpty(URlreturn.message) ? "编辑设备失败" : URlreturn.message); refurbish(); } else if (y == "reFillIn") { Debug.Log(URlreturn.message); SecondConfirmPanel.DeleteConform(null, URlreturn.message); } else { if (URlreturn != null && URlreturn.message == "操作成功") { StartCoroutine(Succeed((x) => { if (x) { refurbish(); } else { SecondConfirmPanel.DeleteConform(null, "更新场景失败"); Debug.Log("接口获取数据失败(编辑设备-初始化失败)"); } })); } else { Debug.Log("编辑设备失败: " + URlreturn.message); SecondConfirmPanel.DeleteConform(null, string.IsNullOrEmpty(URlreturn.message) ? "编辑设备失败" : URlreturn.message); refurbish(); } } })); } /// /// 刷新 /// public void refurbish() { Array.ForEach(GameManager.Inst.pop_ups.ToArray(), (itme) => { itme.gameObject.SetActive(false); }); GameManager.Inst.objectToShow_add.gameObject.SetActive(true); GameManager.Inst.search_box.SetActive(true); var SN1 = GameManager.Inst.objectToShow_add.GetComponent(); SN1.hide_menu(); } public IEnumerator Succeed(Action callback) { Array.ForEach(GameObject.FindObjectsOfType(), (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); else callback.Invoke(false); }, true)); } private void Update() { } //类型:1-机柜;2-设备 //private String type; /// /// /// /// 是否是机柜 private void UIShow(bool isType) { //机柜显示 deviceCode.transform.parent.gameObject.SetActive(!isType); deviceTypeCode.transform.parent.gameObject.SetActive(!isType); networkLevel.transform.parent.gameObject.SetActive(!isType); functionDescription.transform.parent.gameObject.SetActive(!isType); operationTime.transform.parent.gameObject.SetActive(!isType); manufacturer.transform.parent.gameObject.SetActive(!isType); directorName.transform.parent.gameObject.SetActive(!isType); phone.transform.parent.gameObject.SetActive(!isType); //设备显示 devicePosition.transform.parent.gameObject.SetActive(isType); cardType.transform.parent.gameObject.SetActive(isType); cardFunction.transform.parent.gameObject.SetActive(isType); //都显示 deviceName.transform.parent.gameObject.SetActive(true); machineModel.transform.parent.gameObject.SetActive(true); status.transform.parent.gameObject.SetActive(true); deviceName.transform.parent.GetComponent().text = isType ? "板卡名称:" : "设备名称:";//gameObject.SetActive(isType); machineModel.transform.parent.GetComponent().text = isType ? "板卡型号:" : "设备型号:"; status.transform.parent.GetComponent().text = isType ? "板卡状态:" : "运行状态:"; contentSizeFitter.SetActive(true); Invoke("Add", 0.5f); } void Add() { contentSizeFitter.SetActive(false); } public IEnumerator saveJson(Action callback) { // 回调为 reFillIn 时为重新填写不关闭弹窗 //if (deviceTypeCode.value == 0 || deviceType.value == 0 || status.value > 1) yield break; if (string.IsNullOrEmpty(mybody.id)) yield break; try { if (deviceTypeCode) mybody.deviceTypeCode = deviceTypeCode.value.ToString(); if (networkLevel) mybody.networkLevel = networkLevel.value.ToString(); if (deviceType) mybody.deviceType = deviceType.value == 0 ? null : deviceType.value.ToString(); if (cardType) mybody.cardType = cardType.value == 0 ? null : cardType.value.ToString(); if (deviceName) mybody.deviceName = deviceName.text; if (string.IsNullOrWhiteSpace(deviceName.text)) { URlreturn.message = "设备名不允许为空"; callback?.Invoke("reFillIn"); yield break; } if (deviceCode) mybody.deviceCode = deviceCode.text; if (devicePosition) mybody.devicePosition = devicePosition.text; if (machineModel) mybody.machineModel = machineModel.text; if (functionDescription) mybody.functionDescription = functionDescription.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; if (directorName) mybody.directorName = directorName.text; if (phone) mybody.phone = phone.text; if (operationTime) mybody.operationTime = operationTime.text; if (cardFunction) mybody.cardFunction = cardFunction.text; } catch (Exception e) { Debug.Log("修改设备错误:" + e.Message); //gameObject.SetActive(false); callback.Invoke(null); yield break; } string newData = JsonConvert.SerializeObject(mybody); Debug.Log("保存数据:" + newData); yield return StartCoroutine( CombineJSON.UpdateJson_POST(GameManager.Inst.Jk_URL.sb_bj, GameManager.Inst.arguments.token, newData, (jsonResult) => { try { URlreturn = JsonConvert.DeserializeObject(jsonResult); callback?.Invoke(jsonResult); } catch (Exception e) { Debug.Log("修改设备接口错误:" + e.Message); callback.Invoke(null); } } )); } #region JSON [System.Serializable] public class Body { /// /// id /// public string id; /// /// 名称 /// public string deviceName; /// /// 类型:1-机柜;2-设备(废旧) /// public string type; /// /// (设备类型:1-传输设备;2-交换设备;3-电源设备;4-综合数据网设备;5-光纤配线设备;6-数字配线设备;7-音频配线设备) /// public string deviceTypeCode; /// /// 投运时间 /// public string operationTime; /// /// 是否启用:1-正常;0-禁用 /// public string status; /// /// 负责人 /// public string directorName; /// /// 联系电话 /// public string phone; /// /// 机柜型号 /// public string machineModel; /// /// 网络等级(1国网;2华东网;3省网;4地区网) /// public string networkLevel; /// /// 机柜位置 /// public string machinePosition; /// /// 机柜位置 /// public string functionDescription; /// /// 编号 /// [Tooltip("编号")] public string deviceCode; /// /// 类型:1-机柜;2-设备 /// [Tooltip("类型:1-机柜;2-设备")] public string typeStr; /// /// (板卡类型:1-处理板;2-交叉板;3-光口板;4-线路板;5-主控板;6-以太网板) /// [Tooltip("设备类型:1-机框;2-机槽;3-板卡")] public string deviceType; /// /// 设备类型:1-机框;2-机槽;3-板卡 /// [Tooltip("设备类型:1-机框;2-机槽;3-板卡")] public string deviceTypeStr; /// /// 所属机柜id /// [Tooltip("所属机柜id")] public string rackId; /// /// 所属机框id /// [Tooltip("所属机框id")] public string shelfId; /// /// 所属机槽id /// [Tooltip("所属机槽id")] public string slotId; /// /// 设备位置 /// [Tooltip("设备位置")] public string devicePosition; /// /// /// [Tooltip("")] public string conDeviceName; /// /// 机柜类型:1-通信机柜;2-非通信机柜 /// [Tooltip("机柜类型:1-通信机柜;2-非通信机柜")] public string rackType; /// /// 柜门是否打开:1-开;0-关 /// [Tooltip("柜门是否打开:1-开;0-关")] public string openFlag; /// /// 后柜门是否打开:1-开;0-关 /// [Tooltip("后柜门是否打开:1-开;0-关")] public string backDoorFlag; /// /// 模型编号 /// [Tooltip("模型编号")] public string modelNum; /// /// U位占用数量 /// [Tooltip("U位占用数量")] public string occupyNum; /// /// /// [Tooltip("")] public string residueNum; /// /// 生产厂家 /// [Tooltip("生产厂家")] public string manufacturer; /// /// 电源属性 /// [Tooltip("电源属性")] public string powerProperties; /// /// 维护单位 /// [Tooltip("维护单位")] public string maintenanceUnit; /// /// 机框高度 /// [Tooltip("机框高度")] public string machineFrameHigh; /// /// 机框宽度 /// [Tooltip("机框宽度")] public string machineFrameWide; /// /// 机框厚度 /// [Tooltip("机框厚度")] public string machineFrameThick; /// /// 插槽数量 /// [Tooltip("插槽数量")] public string slotNum; /// /// 插槽排列方式 /// [Tooltip("插槽排列方式")] public string slotSort; /// /// 安装方式 /// [Tooltip("安装方式")] public string installMethod; /// /// 所属机框 /// [Tooltip("所属机框")] public string affiliationFrame; /// /// 父插槽名称 /// [Tooltip("父插槽名称")] public string parentSlotName; /// /// 插槽类型 /// [Tooltip("插槽类型")] public string slotType; /// /// 占用状态 /// [Tooltip("占用状态")] public string occupyStatus; /// /// 所属机槽名称 /// [Tooltip("所属机槽名称")] public string affiliationSlot; /// /// 端口数量 /// [Tooltip("端口数量")] public string portNum; /// /// 板卡功能 /// [Tooltip("板卡功能")] public string cardFunction; /// /// 板卡类型 /// [Tooltip("板卡类型")] public string cardType; /// /// 运行状态 /// [Tooltip("运行状态")] public string runStatus; /// /// 备注 /// [Tooltip("备注")] public string remark; } [System.Serializable] public class Root { /// /// /// public string code; /// /// 反馈结果 /// public string message; /// /// 返回内容 /// public string data; /// /// /// public string serverTime; } #endregion }