using System.Collections.Generic;
|
using System.Data;
|
using System.Linq;
|
using System.Threading.Tasks;
|
using SqlSugar;
|
|
namespace IStation.DAL
|
{
|
/// <summary>
|
/// 测点映射
|
/// </summary>
|
public partial class MonitorPointMapping : CorpDAL_Sorter<Entity.MonitorPointMapping>
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public override ConnectionConfig ConnectionConfig
|
{
|
get { return ConfigHelper.DefaultConnectionConfig; }
|
}
|
|
/// <summary>
|
/// 通过 MonitorPointID 获取
|
/// </summary>
|
public List<Entity.MonitorPointMapping> GetByMonitorPointID(long CorpID, long MonitorPointID)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Queryable<Entity.MonitorPointMapping>()
|
.Where(x => x.CorpID == CorpID && x.MonitorPointID == MonitorPointID).ToList();
|
}
|
}
|
|
/// <summary>
|
/// 通过 MonitorPointIds 获取
|
/// </summary>
|
public List<Entity.MonitorPointMapping> GetByMonitorPointIds(long CorpID, List<long> MonitorPointIds)
|
{
|
if (MonitorPointIds == null || MonitorPointIds.Count < 1)
|
return default;
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Queryable<Entity.MonitorPointMapping>()
|
.Where(x => x.CorpID == CorpID && MonitorPointIds.Contains(x.MonitorPointID)).ToList();
|
}
|
}
|
|
/// <summary>
|
/// 通过 ObjectType 和 ObjectID 获取
|
/// </summary>
|
public List<Entity.MonitorPointMapping> GetByObjectTypeAndObjectID(long CorpID, string ObjectType, long ObjectID)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Queryable<Entity.MonitorPointMapping>()
|
.Where(x => x.CorpID == CorpID && x.ObjectType == ObjectType && x.ObjectID == ObjectID).ToList();
|
}
|
}
|
|
/// <summary>
|
/// 更新 AccordParas
|
/// </summary>
|
public bool UpdateAccordParas(long CorpID, long ID, string AccordParas)
|
{
|
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Updateable<Entity.MonitorPointMapping>()
|
.SetColumns(x => x.AccordParas == AccordParas)
|
.Where(x => x.CorpID == CorpID && x.ID == ID)
|
.ExecuteCommand() > 0;
|
}
|
}
|
|
/// <summary>
|
/// 通过 MonitorPointID 删除
|
/// </summary>
|
public bool DeleteByMonitorPointID(long CorpID, long MonitorPointID)
|
{
|
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Deleteable<Entity.MonitorPointMapping>()
|
.Where(x => x.CorpID == CorpID && x.MonitorPointID == MonitorPointID)
|
.ExecuteCommand() > 0;
|
}
|
}
|
|
/// <summary>
|
/// 通过 ObjectType 和 ObjectID 删除
|
/// </summary>
|
public bool DeleteByObjectTypeAndObjectID(long CorpID, string ObjectType, long ObjectID)
|
{
|
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Deleteable<Entity.MonitorPointMapping>()
|
.Where(x => x.CorpID == CorpID && x.ObjectType == ObjectType && x.ObjectID == ObjectID)
|
.ExecuteCommand() > 0;
|
}
|
}
|
|
/// <summary>
|
/// 通过 ObjectType 和 ObjectID 设置
|
/// </summary>
|
public bool SetOfObject(long CorpID, string ObjectType, long ObjectID, List<Entity.MonitorPointMapping> list)
|
{
|
if (list == null || list.Count() < 1)
|
{
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
return db.Deleteable<Entity.MonitorPointMapping>()
|
.Where(x => x.CorpID == CorpID && x.ObjectType == ObjectType && x.ObjectID == ObjectID)
|
.ExecuteCommand() > 0;
|
}
|
}
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
try
|
{
|
db.BeginTran();
|
var add_list = list.Where(x => x.ID < 1).ToList();
|
var update_list = list.Where(x => x.ID > 0).ToList();
|
var ids_exist = update_list.Select(x => x.ID).Distinct().ToList();
|
db.Deleteable<Entity.MonitorPointMapping>()
|
.Where(x => x.CorpID == CorpID && x.ObjectType == ObjectType && x.ObjectID == ObjectID && !ids_exist.Contains(x.ID))
|
.ExecuteCommand();
|
if (add_list.Count > 0)
|
{
|
var result = db.Insertable(add_list).ExecuteReturnSnowflakeIdList().Count > 0;
|
if (!result)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
}
|
if (update_list.Count > 0)
|
{
|
var result = db.Updateable(update_list).ExecuteCommand() > 0;
|
if (!result)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
}
|
db.CommitTran();
|
return true;
|
}
|
catch
|
{
|
db.RollbackTran();
|
throw;
|
}
|
|
}
|
}
|
|
|
}
|
}
|