using DeviceRepair.Models; using DeviceRepair.Models.Device; using DeviceRepair.Models.SFC; using DeviceRepair.Utils; using NLog; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Runtime.InteropServices; using TsSFCDevice.Client.Biz.Base.Service; using TsSFCDevice.Client.Biz.Base.Utils; namespace TsSFCDevice.Client.Biz.Impl { public class DevRepository { private readonly Logger log; private static DevRepository manager; private IDictionary m_ApiParameters; /// /// API输入参数 /// public IDictionary ApiParameters { get { return m_ApiParameters; } set { m_ApiParameters = value; } } public static DevRepository Instance { get { if (manager == null) manager = new DevRepository(); return manager; } } public DevRepository() { log = LogManager.GetCurrentClassLogger(); m_ApiParameters = new Dictionary(); } internal string GetParameters(string cOperator = "", bool bFlag = true) { return ParametersObject.GetInstance(cOperator).GetJsonSerialized(m_ApiParameters); } public IList GetDatas(List Auths) { try { IList Data = new List(); if (Auths == null || Auths.Count == 0) return Data; byte[] btResults = null; ApiParameters?.Clear(); ApiParameters.Add("Auths", string.Join(",", Auths)); var Rtn = Utility.SfcBizService.CurrentSvc.GetDatas(DeviceSvc.SysModelType.DEVICE, GetParameters(), out btResults); if (Rtn.Code != 1) { throw new Exception(Rtn.Message); } DataSet dsResults = CompressionHelper.ExactDataSet(btResults); return DTOHelper.DataTableToList(dsResults.Tables[0]); } catch (Exception ex) { log.Error(ex.Message, ex); throw ex; } } /// /// 获取设备树形结构数据 /// /// /// public IList GetTreeDatas(List Auths,string FilterValue = "") { try { IList Data = new List(); if (Auths == null || Auths.Count == 0) return Data; byte[] btResults = null; ApiParameters?.Clear(); ApiParameters.Add("Auths", string.Join(",", Auths)); if (!FilterValue.IsNull()) ApiParameters.Add("FilterValue", FilterValue); var Rtn = Utility.SfcBizService.CurrentSvc.Get_DEVICE_TreeDatas(GetParameters(), out btResults); if (Rtn.Code != 1) { throw new Exception(Rtn.Message); } DataSet dsResults = CompressionHelper.ExactDataSet(btResults); return DTOHelper.DataTableToList(dsResults.Tables[0]); } catch (Exception ex) { log.Error(ex.Message, ex); throw ex; } } /// /// 获取设备分组数据 /// /// /// public IList Get_DEVICE_Route(List Auths) { try { IList Data = new List(); if (Auths == null || Auths.Count == 0) return Data; byte[] btResults = null; ApiParameters?.Clear(); ApiParameters.Add("Auths", string.Join(",", Auths)); var Rtn = Utility.SfcBizService.CurrentSvc.Get_DEVICE_Route(GetParameters(), out btResults); if (Rtn.Code != 1) { throw new Exception(Rtn.Message); } DataSet dsResults = CompressionHelper.ExactDataSet(btResults); return DTOHelper.DataTableToList(dsResults.Tables[0]); } catch (Exception ex) { log.Error(ex.Message, ex); throw ex; } } /// /// 判断设备编号是否存在 /// /// /// public bool EquipmentID_EXISTS(string EquipmentID) { try { ApiParameters?.Clear(); bool EXISTS = true; var Rtn = Utility.SfcBizService.CurrentSvc.Get_DEVICE_EXISTS(GetParameters(), EquipmentID, out EXISTS); ; if (Rtn.Code != 1) { throw new Exception(Rtn.Message); } return EXISTS; } catch (Exception ex) { log.Error(ex.Message, ex); throw ex; } } /// /// 设备新增 /// /// /// public APIResponseData Insert(DeviceInformationInfo Data, out DeviceInformationInfo Item) { Item = null; try { ApiParameters?.Clear(); byte[] btResults = null; var Rtn = Utility.SfcBizService.CurrentSvc.Insert_DEVICE_Data(GetParameters(), new List { Data }.ToDataTable(), out btResults); if (Rtn.Code != 1) { throw new Exception(Rtn.Message); } DataSet dsResults = CompressionHelper.ExactDataSet(btResults); IList ResultLst = DTOHelper.DataTableToList(dsResults.Tables[0]); if (ResultLst == null) { throw new Exception("实例化当前导出数据时发生异常错误!"); } Item = ResultLst.FirstOrDefault(); return new APIResponseData { Code = 1, Message = Rtn.Message }; } catch (Exception ex) { log.Error(ex.Message, ex); throw ex; } } /// /// 设备信息修改 /// /// /// /// public APIResponseData Update(DeviceInformationInfo Data, out DateTime OperationTime) { OperationTime = DateTime.MinValue; try { ApiParameters?.Clear(); var Rtn = Utility.SfcBizService.CurrentSvc.Updata_DEVICE_Update(GetParameters(), new List { Data }.ToDataTable(), out OperationTime); if (Rtn.Code != 1) { throw new Exception(Rtn.Message); } return new APIResponseData { Code = 1, Message = Rtn.Message }; } catch (Exception ex) { log.Error(ex.Message, ex); throw ex; } } /// /// 修改设备状态 /// /// /// /// public APIResponseData ChangeStatus(int AutoID, out DateTime OperationTime) { OperationTime = DateTime.MinValue; try { ApiParameters?.Clear(); var Rtn = Utility.SfcBizService.CurrentSvc.Update_DEVICE_Status(GetParameters(), AutoID, out OperationTime); if (Rtn.Code != 1) { throw new Exception(Rtn.Message); } return new APIResponseData { Code = 1, Message = Rtn.Message }; } catch (Exception ex) { log.Error(ex.Message, ex); throw ex; } } } }