123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848 |
- using IoTIntegrationPlatform.Common;
- using IoTIntegrationPlatform.Interface;
- using IoTIntegrationPlatform.Model.common;
- using IoTIntegrationPlatform.Model.Dto;
- using IoTIntegrationPlatform.Model.Enum;
- using IoTIntegrationPlatform.Model.Model;
- using MySqlX.XDevAPI.Relational;
- using SqlSugar;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using static IoTIntegrationPlatform.Model.Enum.EnumDevice;
- namespace IoTIntegrationPlatform.Services
- {
- /// <summary>
- /// 设备服务
- /// </summary>
- public class DeviceService : IDeviceService
- {
- private ISqlSugarClient db { get; }
- public DeviceService(ISqlSugarClient _db)
- {
- db = _db;
- }
- #region 类句柄操作
- private IntPtr handle;
- private bool disposed = false;
- //关闭句柄
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Interoperability", "CA1401:PInvokesShouldNotBeVisible"), System.Runtime.InteropServices.DllImport("Kernel32")]
- public extern static Boolean CloseHandle(IntPtr handle);
- /// <summary>
- /// 释放对象资源
- /// </summary>
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- /// <summary>
- /// 释放对象资源
- /// </summary>
- /// <param name="disposing"></param>
- protected virtual void Dispose(bool disposing)
- {
- if (!this.disposed)
- {
- if (handle != IntPtr.Zero)
- {
- CloseHandle(handle);
- handle = IntPtr.Zero;
- }
- }
- disposed = true;
- }
- ~DeviceService()
- {
- Dispose(false);
- }
- #endregion
- #region 平台型号
- /// <summary>
- /// 获取平台型号
- /// </summary>
- /// <param name="platformModelId"></param>
- /// <param name="code"></param>
- /// <returns></returns>
- public PlatformModel GetPlatformModelInfo(int platformModelId, string code)
- {
- PlatformModel model = new PlatformModel();
- try
- {
- model = db.Queryable<PlatformModel>()
- .Where(it => it.IsValid == true)
- .WhereIF(platformModelId > 0, it => it.PlatformModelId == platformModelId)
- .WhereIF(!string.IsNullOrEmpty(code), it => it.PlatformModelCode.Equals(code))
- .First();
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return model;
- }
- /// <summary>
- /// 获取平台型号列表
- /// </summary>
- /// <param name="parm"></param>
- /// <param name="page"></param>
- /// <returns></returns>
- public List<PlatformModel> GetPlatformModelList(BaseParm parm, ref int page)
- {
- List<PlatformModel> list = new List<PlatformModel>();
- try
- {
- list = db.Queryable<PlatformModel>()
- .Where(it => it.IsValid == true)
- .WhereIF(!string.IsNullOrEmpty(parm.Code), it => it.PlatformModelCode.Equals(parm.Code))
- .ToPageList(parm.PageIndex, parm.PageSize, ref page);
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return list;
- }
- /// <summary>
- /// 添加平台型号
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public bool AddPlatformModel(PlatformModel model)
- {
- bool result = false;
- try
- {
- model.CreateTime = DateTime.Now;
- model.UpdateTime = DateTime.Now;
- model.IsValid = true;
- int row = db.Insertable(model).ExecuteCommand();
- if (row > 0)
- {
- result = true;
- }
- }
- catch (Exception ex)
- {
- Logging.Error(ex, "添加平台设备型号");
- }
- return result;
- }
- /// <summary>
- /// 编辑平台设备型号
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public bool UpdatedPlatformModel(PlatformModel model)
- {
- bool result = false;
- try
- {
- var row = db.Updateable(model).IgnoreColumns(it => new { it.PlatformModelId, it.CreateTime, it.IsValid })
- .Where(it => it.PlatformModelId == model.PlatformModelId)
- .ExecuteCommand();
- if (row > 0)
- {
- result = true;
- }
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return result;
- }
- /// <summary>
- /// 删除平台设备型号
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool DeletePlatformModel(int id)
- {
- bool result = false;
- try
- {
- int row = db.Updateable<PlatformModel>()
- .SetColumns(it => new PlatformModel { UpdateTime = DateTime.Now, IsValid = false })
- .Where(it => it.PlatformModelId == id)
- .ExecuteCommand();
- if (row > 0)
- {
- result = true;
- }
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return result;
- }
- #endregion
- #region 平台型号明细
- /// <summary>
- /// 获取设备明细信息
- /// </summary>
- /// <param name="detailId"></param>
- /// <param name="deviceName"></param>
- /// <param name="platformModelId"></param>
- /// <param name="deviceType"></param>
- /// <param name="deviceCommunicationType"></param>
- /// <returns></returns>
- public PlatformModelDetail GetPlatformModelDetailInfo(int detailId, string deviceName, int platformModelId, int deviceType, int deviceCommunicationType)
- {
- PlatformModelDetail model = new PlatformModelDetail();
- try
- {
- model = db.Queryable<PlatformModelDetail>()
- .Where(it => it.IsValid == true)
- .WhereIF(detailId > 0, it => it.PlatformModelDetailId == detailId)
- .WhereIF(!string.IsNullOrEmpty(deviceName), it => it.DeviceName.Contains(deviceName))
- .WhereIF(platformModelId > 0, it => it.PlatformModelId == platformModelId)
- .WhereIF(deviceType > 0, it => it.DeviceType == (EnumDeviceType)deviceType)
- .WhereIF(deviceType > 0, it => it.DeviceCommunicationType == (EnumDeviceCommunicationType)deviceCommunicationType)
- .First();
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return model;
- }
- /// <summary>
- /// 获取平台型号明细列表
- /// </summary>
- /// <param name="parm"></param>
- /// <param name="page"></param>
- /// <returns></returns>
- public List<PlatformModelDetail> GetPlatformModelDetailList(BaseParm parm, ref int page)
- {
- List<PlatformModelDetail> list = new List<PlatformModelDetail>();
- try
- {
- list = db.Queryable<PlatformModelDetail>()
- .Where(it => it.IsValid == true)
- .WhereIF(!string.IsNullOrEmpty(parm.Name), it => it.DeviceName.Contains(parm.Name))
- .WhereIF(parm.Int1 > 0, it => it.DeviceType == (EnumDeviceType)parm.Int1)
- .WhereIF(parm.Int2 > 0, it => it.DeviceCommunicationType == (EnumDeviceCommunicationType)parm.Int2)
- .WhereIF(parm.Type > 0, it => it.ModbusRegisterType == (EnumModbusRegisterType)parm.Type)
- .OrderBy(it => it.CreateTime)
- .ToPageList(parm.PageIndex, parm.PageSize, ref page);
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return list;
- }
- /// <summary>
- /// 添加平台型号明细
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public bool AddPlatformModelDetail(PlatformModelDetail model)
- {
- bool result = false;
- try
- {
- model.CreateTime = DateTime.Now;
- model.UpdateTime = DateTime.Now;
- model.IsValid = true;
- int row = db.Insertable(model).ExecuteCommand();
- if (row > 0)
- {
- result = true;
- }
- }
- catch (Exception ex)
- {
- Logging.Error(ex, "添加平台设备型号");
- }
- return result;
- }
- /// <summary>
- /// 编辑平台设备型号
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public bool UpdatedPlatformModelDetail(PlatformModelDetail model)
- {
- bool result = false;
- try
- {
- var row = db.Updateable(model).IgnoreColumns(it => new { it.PlatformModelDetailId, it.CreateTime, it.IsValid })
- .Where(it => it.PlatformModelDetailId == model.PlatformModelDetailId)
- .ExecuteCommand();
- if (row > 0)
- {
- result = true;
- }
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return result;
- }
- /// <summary>
- /// 删除平台设备型号
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool DeletePlatformModelDetail(int id)
- {
- bool result = false;
- try
- {
- int row = db.Updateable<PlatformModelDetail>()
- .SetColumns(it => new PlatformModelDetail { UpdateTime = DateTime.Now, IsValid = false })
- .Where(it => it.PlatformModelDetailId == id)
- .ExecuteCommand();
- if (row > 0)
- {
- result = true;
- }
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return result;
- }
- #endregion
- #region 平台设备
- /// <summary>
- /// 获取平台设备信息
- /// </summary>
- /// <param name="platformId"></param>
- /// <param name="code"></param>
- /// <param name="customerId"></param>
- /// <returns></returns>
- public PlatformDeviceInfo GetPlatformDeviceInfoInfo(int platformId, string code, int customerId)
- {
- PlatformDeviceInfo model = new PlatformDeviceInfo();
- try
- {
- model = db.Queryable<PlatformDeviceInfo>()
- .Where(it => it.IsValid == true)
- .WhereIF(platformId > 0, it => it.PlatformId == platformId)
- .WhereIF(!string.IsNullOrEmpty(code), it => it.PlatformCode.Equals(code))
- .WhereIF(customerId > 0, it => it.CustomerId == customerId)
- .First();
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return model;
- }
- /// <summary>
- /// 获取平台设备列表
- /// </summary>
- /// <param name="parm"></param>
- /// <param name="page"></param>
- /// <returns></returns>
- public List<PlatformDeviceInfoDto> GetPlatformDeviceList(BaseParm parm, ref int page)
- {
- List<PlatformDeviceInfoDto> list = new List<PlatformDeviceInfoDto>();
- try
- {
- list = db.Queryable<PlatformDeviceInfo>()
- .Where(it => it.IsValid == true)
- .WhereIF(!string.IsNullOrEmpty(parm.Param), it => it.PlatformCode.Contains(parm.Param))
- .WhereIF(!string.IsNullOrEmpty(parm.Code), it => it.PlatformCode.Equals(parm.Code))//平台编号
- .WhereIF(parm.Int1 > 0, it => it.PlatformModelId == parm.Int1)//平台型号id
- .WhereIF(parm.CustomerId > 0, it => it.CustomerId == parm.CustomerId)//客户id
- .WhereIF(parm.Status > 0, it => it.PlatformStatus == (EnumPlatformStatus)parm.Status)//平台状态
- .Select(it => new PlatformDeviceInfoDto()
- {
- PlatformId = it.PlatformId,
- PlatformCode = it.PlatformCode,
- PlatformModelId = it.PlatformModelId,
- CustomerId = it.CustomerId,
- EffectiveTime = it.EffectiveTime,
- ExpireTime = it.ExpireTime,
- DeviceMac = it.DeviceMac,
- HeartbeatTime = it.HeartbeatTime,
- DeviceState = it.DeviceState,
- PlatformStatus = it.PlatformStatus,
- Remark = it.Remark,
- UpdateTime = it.UpdateTime,
- OperationId = it.OperationId,
- OperationName = it.OperationName,
- CustomerCode = SqlFunc.Subqueryable<CustomerInfo>().Where(t => t.IsValid && t.CustomerId == it.CustomerId).Select(t => t.CustomerCode),
- CustomerName = SqlFunc.Subqueryable<CustomerInfo>().Where(t => t.IsValid && t.CustomerId == it.CustomerId).Select(t => t.CustomerName),
- PlatformModelCode = SqlFunc.Subqueryable<PlatformModel>().Where(t => t.IsValid && t.PlatformModelId == it.PlatformModelId).Select(t => t.PlatformModelCode),
- PlatformModelName = SqlFunc.Subqueryable<PlatformModel>().Where(t => t.IsValid && t.PlatformModelId == it.PlatformModelId).Select(t => t.PlatformModelName)
- })
- .ToPageList(parm.PageIndex, parm.PageSize, ref page);
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return list;
- }
- /// <summary>
- /// 添加平台设备
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public bool AddPlatformDeviceInfo(PlatformDeviceInfo model)
- {
- bool result = false;
- db.Ado.BeginTran();
- try
- {
- //序列号
- string serialNumber = RandomHelper.GenerateRandomStr(16);
- model.CreateTime = DateTime.Now;
- model.UpdateTime = DateTime.Now;
- model.DeviceMac = DeviceHelper.GenerateDeviceMacAddress(serialNumber);
- model.HeartbeatTime = DateTime.Now;
- model.DeviceState = EnumDeviceStatus.Close;
- model.IsValid = true;
- model.PlatformStatus = EnumPlatformStatus.NotActivated;
- model.PlatformId = db.Insertable(model).ExecuteReturnIdentity();
- //根据物联网平台型号id获取平台型号明细设备
- //物联网平台型号id
- int platformModelId = model.PlatformModelId;
- //获取当前平台型号下的明细设备
- List<PlatformModelDetail> platformModelDeviceList = db.Queryable<PlatformModelDetail>().Where(it => it.IsValid && it.PlatformModelId == platformModelId).OrderBy(it => it.PlatformModelDetailId).ToList();
- //平台子设备
- List<PlatformDeviceDetail> subDevicelist = new List<PlatformDeviceDetail>();
- foreach (var item in platformModelDeviceList)
- {
- PlatformDeviceDetail subDevicdModel = new PlatformDeviceDetail();
- subDevicdModel = Mapping.EntityMapping<PlatformDeviceDetail, PlatformModelDetail>(item);
- subDevicdModel.DeviceId = Guid.NewGuid().ToString();
- subDevicdModel.PlatformId = model.PlatformId;
- subDevicdModel.DeviceName = item.DeviceName;
- subDevicdModel.DeviceType = item.DeviceType;
- subDevicdModel.DeviceTypeName = EnumExtension.GetDescription(subDevicdModel.DeviceType);
- subDevicdModel.DeviceState = EnumDeviceStatus.Close;
- subDevicdModel.DeviceValue = item.DeviceValue;
- subDevicdModel.CreateTime = DateTime.Now;
- subDevicdModel.UpdateTime = DateTime.Now;
- subDevicdModel.IsValid = true;
- subDevicelist.Add(subDevicdModel);
- }
- int row = db.Insertable(subDevicelist).ExecuteCommand();
- if (row > 0)
- {
- db.Ado.CommitTran();
- result = true;
- }
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- db.Ado.RollbackTran();
- }
- return result;
- }
- /// <summary>
- /// 编辑平台设备
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public bool UpdatedPlatformDeviceInfo(PlatformDeviceInfo model)
- {
- bool result = false;
- try
- {
- model.UpdateTime = DateTime.Now;
- var row = db.Updateable(model).IgnoreColumns(it => new { it.PlatformId, it.PlatformCode, it.UpdateTime, it.IsValid })
- .Where(it => it.PlatformId == model.PlatformId)
- .ExecuteCommand();
- if (row > 0)
- {
- result = true;
- }
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return result;
- }
- /// <summary>
- /// 批量编辑平台设备状态
- /// </summary>
- /// <param name="dataList"></param>
- /// <returns></returns>
- public bool BatchUpdatePlatformDeviceStatus(List<PlatformDeviceInfoDto> dataList)
- {
- bool result = false;
- db.Ado.BeginTran();
- try
- {
- foreach (var item in dataList)
- {
- db.Updateable<PlatformDeviceInfo>()
- .SetColumns(it => new PlatformDeviceInfo() { UpdateTime = DateTime.Now, DeviceState = item.DeviceState })
- .Where(it => it.IsValid && it.PlatformId == item.PlatformId)
- .ExecuteCommand();
- }
- db.Ado.CommitTran();
- }
- catch (Exception ex)
- {
- db.Ado.RollbackTran();
- Logging.Error(ex, "BatchUpdateDeviceStatus");
- }
- return result;
- }
- /// <summary>
- /// 编辑平台状态
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public bool UpdatedPlatformState(PlatformDeviceInfo model)
- {
- bool result = false;
- try
- {
- model.UpdateTime = DateTime.Now;
- var row = 0;
- if (model.PlatformStatus == EnumPlatformStatus.NotActivated)
- {
- model.ExpireTime = DateTime.Now;
- row = db.Updateable(model).UpdateColumns(it => new { it.PlatformStatus, it.UpdateTime }).Where(it => it.PlatformId == model.PlatformId).ExecuteCommand();
- }
- else if (model.PlatformStatus == EnumPlatformStatus.Normal)
- {
- model.EffectiveTime = DateTime.Now;
- row = db.Updateable(model).UpdateColumns(it => new { it.PlatformStatus, it.UpdateTime, it.EffectiveTime, it.ExpireTime }).Where(it => it.PlatformId == model.PlatformId).ExecuteCommand();
- }
- else if (model.PlatformStatus == EnumPlatformStatus.HaveExpired)
- {
- model.ExpireTime = DateTime.Now;
- row = db.Updateable(model).UpdateColumns(it => new { it.PlatformStatus, it.UpdateTime, it.ExpireTime }).Where(it => it.PlatformId == model.PlatformId).ExecuteCommand();
- }
- if (row > 0)
- {
- result = true;
- }
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return result;
- }
- /// <summary>
- /// 删除平台设备
- /// </summary>
- /// <param name="platformId"></param>
- /// <returns></returns>
- public bool DeletePlatformDeviceInfo(int platformId)
- {
- bool result = false;
- try
- {
- int row = db.Updateable<PlatformDeviceInfo>()
- .SetColumns(it => new PlatformDeviceInfo { UpdateTime = DateTime.Now, IsValid = false })
- .Where(it => it.PlatformId == platformId)
- .ExecuteCommand();
- if (row > 0)
- {
- result = true;
- }
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return result;
- }
- /// <summary>
- /// 根据mac地址修改平台设备心跳时间
- /// </summary>
- /// <param name="deviceMac"></param>
- /// <returns></returns>
- public bool UpdateGatewayDeviceHeartTime(string deviceMac)
- {
- bool result = false;
- try
- {
- int row = db.Updateable<PlatformDeviceInfo>()
- .SetColumns(it => new PlatformDeviceInfo { UpdateTime = DateTime.Now, HeartbeatTime = DateTime.Now, DeviceState = EnumDeviceStatus.Open })
- .Where(it => it.IsValid && it.DeviceMac == deviceMac)
- .ExecuteCommand();
- if (row > 0)
- {
- result = true;
- }
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return result;
- }
- #endregion
- #region 平台设备明细
- /// <summary>
- /// 获取平台设备明细列表
- /// </summary>
- /// <param name="parm"></param>
- /// <param name="page"></param>
- /// <returns></returns>
- public List<PlatformDeviceDetailDto> GetPlatformDeviceDetailList(BaseParm parm, ref int page)
- {
- List<PlatformDeviceDetailDto> list = new List<PlatformDeviceDetailDto>();
- try
- {
- list = db.Queryable<PlatformDeviceDetail>()
- .Where(it => it.IsValid)
- .WhereIF(parm.Id > 0, it => it.PlatformId == parm.Id)//平台id
- .WhereIF(!string.IsNullOrEmpty(parm.Name), it => it.DeviceName.Contains(parm.Name))//设备名称
- .WhereIF(parm.Int1 > 0, it => it.DeviceType == (EnumDeviceType)parm.Int1)//设备类型
- .WhereIF(parm.Int2 > 0, it => it.DeviceCommunicationType == (EnumDeviceCommunicationType)parm.Int2)//设备通讯方式
- .OrderBy(it => it.PlatformModelDetailId)
- .Select(it => new PlatformDeviceDetailDto()
- {
- DeviceCommunicationTypeName = "Rs485",
- ModbusRegisterTypeName = "保持寄存器"
- },
- true)//开启自动映射
- .ToPageList(parm.PageIndex, parm.PageSize, ref page);
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return list;
- }
- /// <summary>
- /// 编辑平台设备
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public bool UpdatedPlatformSubDeviceInfo(PlatformDeviceDetail model)
- {
- bool result = false;
- try
- {
- var row = db.Updateable(model).IgnoreColumns(it => new { it.DeviceId, it.PlatformId, it.CreateTime, it.IsValid })
- .Where(it => it.DeviceId == model.DeviceId)
- .ExecuteCommand();
- if (row > 0)
- {
- result = true;
- }
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return result;
- }
- /// <summary>
- /// 编辑平台明细设备值
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public bool UpdatedPlatformSubDeviceValue(PlatformDeviceDetail model)
- {
- bool result = false;
- try
- {
- model.UpdateTime = DateTime.Now;
- var row = db.Updateable(model).UpdateColumns(it => new { it.DeviceValue, it.UpdateTime }).Where(it => it.DeviceId == model.DeviceId).ExecuteCommand();
- if (row > 0)
- {
- result = true;
- }
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return result;
- }
- /// <summary>
- /// 删除平台子设备
- /// </summary>
- /// <param name="deviceId"></param>
- /// <returns></returns>
- public bool DeletePlatformSubDeviceInfo(string deviceId)
- {
- bool result = false;
- try
- {
- int row = db.Updateable<PlatformDeviceDetail>()
- .SetColumns(it => new PlatformDeviceDetail { UpdateTime = DateTime.Now, IsValid = false })
- .Where(it => it.DeviceId == deviceId)
- .ExecuteCommand();
- if (row > 0)
- {
- result = true;
- }
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return result;
- }
- /// <summary>
- /// 编辑设备状态或值(根据设备ID)
- /// </summary>
- /// <param name="deviceId"></param>
- /// <param name="deviceStatus"></param>
- /// <param name="deviceValue"></param>
- /// <returns></returns>
- public bool UpdateDeviceStateOrValue(string deviceId, EnumDeviceStatus deviceStatus, string deviceValue)
- {
- bool result = false;
- try
- {
- //int row = db.Updateable<PlatformDeviceDetail>()
- // .SetColumns(it => new PlatformDeviceDetail { UpdateTime = DateTime.Now, DeviceState = deviceStatus, DeviceValue = deviceValue })
- // .Where(it => it.DeviceId == deviceId)
- // .ExecuteCommand();
- if (1 > 0)
- {
- result = true;
- }
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return result;
- }
- /// <summary>
- /// 获取设备信息
- /// </summary>
- /// <param name="device_id"></param>
- /// <param name="deviceMac"></param>
- /// <param name="type"></param>
- /// <returns></returns>
- public PlatformDeviceDetail GetDevideInfo(string device_id)
- {
- PlatformDeviceDetail model = new PlatformDeviceDetail();
- try
- {
- model = db.Queryable<PlatformDeviceDetail>()
- .Where(it => it.IsValid)
- .WhereIF(!string.IsNullOrEmpty(device_id), it => it.DeviceId.Equals(device_id))
- .First();
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return model;
- }
- /// <summary>
- /// 编辑设备读取数据状态
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- public bool UpdateDeviceReadState(PlatformDeviceDetail model)
- {
- bool result = false;
- try
- {
- model.UpdateTime = DateTime.Now;
- var row = db.Updateable(model).UpdateColumns(it => new { it.UpdateTime, it.IsRead }).Where(it => it.DeviceId == model.DeviceId).ExecuteCommand();
- if (row > 0)
- {
- result = true;
- }
- }
- catch (Exception ex)
- {
- Logging.Error(ex, ex.Message);
- }
- return result;
- }
- #endregion
- }
- }
|