314 lines
11 KiB
C#
314 lines
11 KiB
C#
using CsharpHttpHelper;
|
|
using DeviceRepair.DataAccess;
|
|
using DeviceRepair.Models;
|
|
using DeviceRepair.Utils.Security;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace DeviceRepairAndOptimization.Biz
|
|
{
|
|
/// <summary>
|
|
/// 设备信息
|
|
/// </summary>
|
|
public class DeviceManager
|
|
{
|
|
private static DeviceManager manager;
|
|
public static DeviceManager Instance
|
|
{
|
|
get
|
|
{
|
|
if (manager == null)
|
|
manager = new DeviceManager();
|
|
return manager;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取设备路径
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public APIResponseData GetDeviceRoute()
|
|
{
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "没有查询到数据!" };
|
|
try
|
|
{
|
|
switch (DeviceRepair.Utils.Config.Configurations.Properties.ConnType?.ToLower())
|
|
{
|
|
case "api":
|
|
apiResponseData = ApiHelper.Instance.SendMessage(new HttpItem
|
|
{
|
|
URL = ServiceRouteConstValue.GetDeviceRoute,
|
|
Method = "Get",
|
|
ContentType = "application/json; charset=utf-8"
|
|
});
|
|
break;
|
|
case "sql":
|
|
apiResponseData = DeviceAccess.Instance.GetDeviceRoute();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
apiResponseData.Code = -1;
|
|
apiResponseData.Message = ex.Message;
|
|
}
|
|
return apiResponseData;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过设备编号查询设备信息
|
|
/// </summary>
|
|
/// <param name="EquipmentID"></param>
|
|
/// <returns></returns>
|
|
public APIResponseData GetModelByEquipmentID(string EquipmentID)
|
|
{
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "没有查询到数据!" };
|
|
try
|
|
{
|
|
switch (DeviceRepair.Utils.Config.Configurations.Properties.ConnType?.ToLower())
|
|
{
|
|
case "api":
|
|
|
|
apiResponseData = ApiHelper.Instance.SendMessage(new HttpItem
|
|
{
|
|
URL = ServiceRouteConstValue.GetDeviceByEquipmentID + "?EquipmentID=" + EncryptionHelper.UrlEncry(EquipmentID),
|
|
Method = "Get",
|
|
ContentType = "application/json; charset=utf-8"
|
|
});
|
|
break;
|
|
case "sql":
|
|
apiResponseData = DeviceAccess.Instance.GetModelByEquipmentID(EquipmentID);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
apiResponseData.Code = -1;
|
|
apiResponseData.Message = ex.Message;
|
|
}
|
|
return apiResponseData;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设备台账数据获取
|
|
/// </summary>
|
|
/// <param name="FilterValue"></param>
|
|
/// <returns></returns>
|
|
public APIResponseData GetQuery(string FilterValue)
|
|
{
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "查询失败!" };
|
|
try
|
|
{
|
|
switch (DeviceRepair.Utils.Config.Configurations.Properties.ConnType?.ToLower())
|
|
{
|
|
case "api":
|
|
apiResponseData = ApiHelper.Instance.SendMessage(new HttpItem
|
|
{
|
|
URL = $"{ServiceRouteConstValue.GetDeviceQuery}?FilterString={FilterValue}",
|
|
Method = "Get",
|
|
ContentType = "application/json;charset=utf-8",
|
|
});
|
|
break;
|
|
|
|
default:
|
|
apiResponseData = DeviceAccess.Instance.GetQuery(FilterValue);
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
apiResponseData.Code = -1;
|
|
apiResponseData.Message = ex.Message;
|
|
}
|
|
return apiResponseData;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取树形结构
|
|
/// </summary>
|
|
/// <param name="FilterValue"></param>
|
|
/// <returns></returns>
|
|
public APIResponseData GetDeviceTreeDatas(string FilterValue, string OEMORKH = "ALL")
|
|
{
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "查询失败!" };
|
|
try
|
|
{
|
|
switch (DeviceRepair.Utils.Config.Configurations.Properties.ConnType?.ToLower())
|
|
{
|
|
case "api":
|
|
apiResponseData = ApiHelper.Instance.SendMessage(new HttpItem
|
|
{
|
|
URL = $"{ServiceRouteConstValue.GetDeviceTreeDatas}?FilterString={FilterValue}&OEMORKH={OEMORKH}",
|
|
Method = "Get",
|
|
ContentType = "application/json;charset=utf-8",
|
|
});
|
|
break;
|
|
|
|
default:
|
|
apiResponseData = DeviceAccess.Instance.GetDeviceTreeDatas(FilterValue);
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
apiResponseData.Code = -1;
|
|
apiResponseData.Message = ex.Message;
|
|
}
|
|
return apiResponseData;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改设备信息
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <returns></returns>
|
|
public APIResponseData UpdateDriveInformation(Dictionary<string, object> data)
|
|
{
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "查询失败!" };
|
|
try
|
|
{
|
|
switch (DeviceRepair.Utils.Config.Configurations.Properties.ConnType?.ToLower())
|
|
{
|
|
case "api":
|
|
apiResponseData = ApiHelper.Instance.SendMessage(new HttpItem
|
|
{
|
|
URL = $"{ServiceRouteConstValue.UpdateDeviceInformation}",
|
|
Method = "Post",
|
|
ContentType = "application/json;charset=utf-8",
|
|
Postdata = JsonConvert.SerializeObject(data)
|
|
});
|
|
break;
|
|
default:
|
|
apiResponseData = DeviceAccess.Instance.UpdateDriveInformation(data, GlobalInfo.OperationInfo);
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
apiResponseData.Code = -1;
|
|
apiResponseData.Message = ex.Message;
|
|
}
|
|
return apiResponseData;
|
|
}
|
|
|
|
|
|
/// <通过设备表主键编号查询数据>
|
|
/// 查询数据
|
|
/// </summary>
|
|
/// <param name="FilterValue"></param>
|
|
/// <returns></returns>
|
|
public APIResponseData GetDataByAutoID(int AutoID)
|
|
{
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "查询失败!" };
|
|
try
|
|
{
|
|
switch (DeviceRepair.Utils.Config.Configurations.Properties.ConnType?.ToLower())
|
|
{
|
|
case "api":
|
|
#region api
|
|
|
|
apiResponseData = ApiHelper.Instance.SendMessage(new HttpItem
|
|
{
|
|
URL = $"{ServiceRouteConstValue.GetDeviceDataByAutoID}?pk={AutoID}",
|
|
Method = "Get",
|
|
ContentType = "application/json; charset=utf-8",
|
|
});
|
|
|
|
#endregion
|
|
break;
|
|
default:
|
|
apiResponseData = DeviceAccess.Instance.GetDataByAutoID(AutoID);
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
apiResponseData.Code = -1;
|
|
apiResponseData.Message = ex.Message;
|
|
}
|
|
return apiResponseData;
|
|
}
|
|
|
|
|
|
#region PM
|
|
|
|
/// <summary>
|
|
/// KH设备台账数据获取
|
|
/// </summary>
|
|
/// <param name="FilterValue"></param>
|
|
/// <returns></returns>
|
|
public APIResponseData GetQueryKH(string FilterValue)
|
|
{
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "查询失败!" };
|
|
try
|
|
{
|
|
switch (DeviceRepair.Utils.Config.Configurations.Properties.ConnType?.ToLower())
|
|
{
|
|
case "api":
|
|
apiResponseData = ApiHelper.Instance.SendMessage(new HttpItem
|
|
{
|
|
URL = $"{ServiceRouteConstValue.GetDeviceQueryKH}?FilterString={FilterValue}",
|
|
Method = "Get",
|
|
ContentType = "application/json;charset=utf-8",
|
|
});
|
|
break;
|
|
|
|
default:
|
|
apiResponseData = DeviceAccess.Instance.GetQueryKH(FilterValue);
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
apiResponseData.Code = -1;
|
|
apiResponseData.Message = ex.Message;
|
|
}
|
|
return apiResponseData;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过设备编号查询设备信息
|
|
/// </summary>
|
|
/// <param name="EquipmentID"></param>
|
|
/// <returns></returns>
|
|
public APIResponseData GetPMDeviceInfoModelByEquipmentID(string EquipmentID)
|
|
{
|
|
APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "没有查询到数据!" };
|
|
try
|
|
{
|
|
switch (DeviceRepair.Utils.Config.Configurations.Properties.ConnType?.ToLower())
|
|
{
|
|
case "api":
|
|
|
|
apiResponseData = ApiHelper.Instance.SendMessage(new HttpItem
|
|
{
|
|
URL = ServiceRouteConstValue.GetPMDeviceInfoModelByEquipmentID + "?EquipmentID=" + EncryptionHelper.UrlEncry(EquipmentID),
|
|
Method = "Get",
|
|
ContentType = "application/json; charset=utf-8"
|
|
});
|
|
break;
|
|
case "sql":
|
|
apiResponseData = DeviceAccess.Instance.GetPMDeviceInfoModelByEquipmentID(EquipmentID);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
apiResponseData.Code = -1;
|
|
apiResponseData.Message = ex.Message;
|
|
}
|
|
return apiResponseData;
|
|
}
|
|
|
|
|
|
#endregion
|
|
}
|
|
}
|