using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
namespace IStation.DAL
|
{
|
/// <summary>
|
/// 设备监测映射
|
/// </summary>
|
public class EquipmentMonitorMapping : BaseDAL<Entity.EquipmentMonitorMapping>
|
{
|
public override ConnectionConfig ConnectionConfig
|
{
|
get { return ConnectionFactory.BasicConnection(SettingsD.Project.ID); }
|
}
|
|
|
/// <summary>
|
/// 通过 EquipmentID 获取
|
/// </summary>
|
public List<Entity.EquipmentMonitorMapping> GetByEquipmentID(long equipmentId)
|
{
|
if (equipmentId < 1)
|
return default;
|
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Queryable<Entity.EquipmentMonitorMapping>()
|
.Where(x => x.EquipmentID == equipmentId)
|
.ToList();
|
}
|
}
|
|
/// <summary>
|
/// 设置
|
/// </summary>
|
public bool SetOfObject(long equipmentId, List<Entity.EquipmentMonitorMapping> list)
|
{
|
if (equipmentId < 1)
|
return default;
|
|
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
|
{
|
try
|
{
|
db.Ado.BeginTran();
|
var existList = db.Queryable<Entity.EquipmentMonitorMapping>()
|
.Where(x => x.EquipmentID == equipmentId)
|
.ToList();
|
if (existList.Count > 0)
|
{
|
var bol = db.Deleteable(existList).ExecuteCommand() > 0;
|
if (!bol)
|
{
|
db.Ado.RollbackTran();
|
return false;
|
}
|
}
|
|
if (list != null && list.Any())
|
{
|
list.ForEach(x => x.ID = SnowflakeIdHelper.NextId());
|
var bol = db.Insertable(list).ExecuteCommand() > 0;
|
if (!bol)
|
{
|
db.Ado.RollbackTran();
|
return false;
|
}
|
}
|
db.Ado.CommitTran();
|
}
|
catch (Exception ex)
|
{
|
db.Ado.RollbackTran();
|
throw ex;
|
}
|
}
|
return true;
|
}
|
|
|
/// <summary>
|
/// 通过 EquipmentID 删除
|
/// </summary>
|
public bool DeleteByEquipmentID(long equipmentId)
|
{
|
if (equipmentId < 1)
|
return default;
|
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Deleteable<Entity.EquipmentMonitorMapping>().Where(x => x.EquipmentID == equipmentId).ExecuteCommand() > 0;
|
}
|
}
|
|
/// <summary>
|
/// 通过 EquipmentIs 删除
|
/// </summary>
|
public bool DeleteByEquipmentIds(List<long> equipmentIds)
|
{
|
if (equipmentIds == null || equipmentIds.Count() < 1)
|
return false;
|
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Deleteable<Entity.EquipmentMonitorMapping>().Where(x => equipmentIds.Contains(x.ID)).ExecuteCommand() > 0;
|
}
|
}
|
|
}
|
|
}
|