using System;
|
using System.Text;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Runtime.Serialization;
|
using System.Linq;
|
using System.Security.Cryptography;
|
using System.IO;
|
|
namespace IStation.DAL.LocalFile
|
{
|
/// <summary>
|
/// 测点映射
|
/// </summary>
|
public class MonitorPointMapping : IDAL.IMonitorPointMapping<Entity.MonitorPointMapping>
|
{
|
|
#region Path
|
|
/// <summary>
|
/// 查询文件路径
|
/// </summary>
|
private string GetFolderPath(long projectId)
|
{
|
return FileHelper.GetProjectPath(projectId);
|
}
|
|
#endregion
|
|
#region Get
|
|
/// <summary>
|
/// 查询全部
|
/// </summary>
|
public List<Entity.MonitorPointMapping> GetAll(long projectId)
|
{
|
if (projectId < 1)
|
return default;
|
var path = GetFolderPath(projectId);
|
var all = FileIdHelper<Entity.MonitorPointMapping>.GetAll(path);
|
var entities = all?.OrderBy(x => x.SortCode).ToList();
|
return entities;
|
}
|
|
/// <summary>
|
/// 根据 Id查询
|
/// </summary>
|
public Entity.MonitorPointMapping GetById(long projectId, long Id)
|
{
|
if (projectId < 1)
|
return default;
|
if (Id < 0)
|
return default;
|
var all = GetAll(projectId);
|
var entities = all?.ToList();
|
return entities?.Find(t => t.Id == Id);
|
}
|
|
/// <summary>
|
/// 根据 Id集合查询
|
/// </summary>
|
public List<Entity.MonitorPointMapping> GetByIds(long projectId, IEnumerable<long> Ids)
|
{
|
if (projectId < 1)
|
return default;
|
if (Ids == null || Ids.Count() < 1)
|
return default;
|
var all = GetAll(projectId);
|
var entities = all?.Where(x => Ids.Contains(x.Id)).ToList();
|
return entities;
|
}
|
|
/// <summary>
|
/// 根据 MonitorPointId 查询
|
/// </summary>
|
public List<Entity.MonitorPointMapping> GetByMonitorPointId(long projectId, long monitorPointId)
|
{
|
if (projectId < 1)
|
return default;
|
if (monitorPointId < 0)
|
return default;
|
var all = GetAll(projectId);
|
var entities = all?.Where(x => x.MonitorPointId == monitorPointId).ToList();
|
return entities;
|
}
|
|
/// <summary>
|
///根据 ObjectType 和 ObjectId 查询
|
/// </summary>
|
public List<Entity.MonitorPointMapping> GetByObjectTypeAndObjectId(long projectId, string objectType, long objectId)
|
{
|
if (projectId < 1)
|
return default;
|
if (objectId < 0)
|
return default;
|
var all = GetAll(projectId);
|
var entities = all?.Where(x => x.ObjectType == objectType && x.ObjectId == objectId).ToList();
|
return entities;
|
}
|
|
/// <summary>
|
/// 根据 ObjectType 和 ObjectIds 查询
|
/// </summary>
|
public List<Entity.MonitorPointMapping> GetByObjectTypeAndObjectIds(long projectId, string objectType, IEnumerable<long> objectIds)
|
{
|
if (projectId < 1)
|
return default;
|
if (objectIds == null || objectIds.Count() < 1)
|
return default;
|
var all = GetAll(projectId);
|
var entities = all?.Where(x => x.ObjectType == objectType && objectIds.Contains(x.ObjectId)).ToList();
|
return entities;
|
}
|
|
#endregion
|
|
#region Set
|
|
/// <summary>
|
/// 根据 ObjectType 和 ObjectId 设置
|
/// </summary>
|
public bool SetOfObject(long projectId, string objectType, long objectId, IEnumerable<Entity.MonitorPointMapping> list)
|
{
|
if (list == null || list.Count() < 1)
|
{
|
return DeleteByObjectTypeAndObjectId(projectId, objectType, objectId);
|
}
|
var all = GetAll(projectId);
|
if (all == null)
|
all = new List<Entity.MonitorPointMapping>();
|
all.RemoveAll(x => x.ObjectType == objectType && x.ObjectId == objectId);
|
list.ToList().ForEach(x =>
|
{
|
if (x.Id < 1)
|
x.Id = FileHelper.NextId();
|
});
|
all.AddRange(list);
|
Covers(projectId, list);
|
return true;
|
}
|
|
#endregion
|
|
#region Insert
|
|
/// <summary>
|
/// 插入
|
/// </summary>
|
public long Insert(long projectId, Entity.MonitorPointMapping rhs)
|
{
|
if (projectId < 1)
|
return default;
|
if (rhs == null)
|
return default;
|
var path = GetFolderPath(projectId);
|
return FileIdHelper<Entity.MonitorPointMapping>.Insert(path, rhs);
|
}
|
|
/// <summary>
|
/// 批量插入
|
/// </summary>
|
public bool Inserts(long projectId, IEnumerable<Entity.MonitorPointMapping> list)
|
{
|
if (projectId < 1)
|
return default;
|
if (list == null || list.Count() < 1)
|
return default;
|
var path = GetFolderPath(projectId);
|
return FileIdHelper<Entity.MonitorPointMapping>.Inserts(path, list);
|
}
|
|
/// <summary>
|
/// 插入并返回
|
/// </summary>
|
public Entity.MonitorPointMapping InsertR(long projectId, Entity.MonitorPointMapping rhs)
|
{
|
if (projectId < 1)
|
return default;
|
if (rhs == null)
|
return default;
|
var path = GetFolderPath(projectId);
|
var entities = FileIdHelper<Entity.MonitorPointMapping>.InsertR(path, rhs);
|
return entities;
|
}
|
|
/// <summary>
|
/// 批量插入并返回
|
/// </summary>
|
public List<long> InsertsR(long projectId, IEnumerable<Entity.MonitorPointMapping> list)
|
{
|
if (projectId < 1)
|
return default;
|
if (list == null || list.Count() < 1)
|
return default;
|
var path = GetFolderPath(projectId);
|
var entities = FileIdHelper<Entity.MonitorPointMapping>.InsertRs(path, list);
|
return entities?.Select(x => x.Id).ToList();
|
}
|
|
#endregion
|
|
#region Update
|
|
/// <summary>
|
/// 更新
|
/// </summary>
|
public bool Update(long projectId, Entity.MonitorPointMapping rhs)
|
{
|
if (projectId < 1)
|
return default;
|
if (rhs == null)
|
return default;
|
var path = GetFolderPath(projectId);
|
return FileIdHelper<Entity.MonitorPointMapping>.Update(path, rhs);
|
}
|
|
/// <summary>
|
/// 批量更新
|
/// </summary>
|
public bool Updates(long projectId, IEnumerable<Entity.MonitorPointMapping> list)
|
{
|
if (projectId < 1)
|
return default;
|
if (list == null || list.Count() < 1)
|
return default;
|
var path = GetFolderPath(projectId);
|
return FileIdHelper<Entity.MonitorPointMapping>.Updates(path, list);
|
}
|
|
#endregion
|
|
|
#region Delete
|
|
/// <summary>
|
/// 根据 Id删除
|
/// </summary>
|
public bool DeleteById(long projectId, long Id)
|
{
|
if (projectId < 1)
|
return default;
|
if (Id < 0)
|
return default;
|
var path = GetFolderPath(projectId);
|
var bol = FileIdHelper<Entity.MonitorPointMapping>.DeleteById(path, Id);
|
return bol;
|
}
|
|
/// <summary>
|
/// 根据 Id集合删除
|
/// </summary>
|
public bool DeleteByIds(long projectId, IEnumerable<long> Ids)
|
{
|
if (projectId < 1)
|
return default;
|
if (Ids == null || Ids.Count() < 1)
|
return default;
|
var path = GetFolderPath(projectId);
|
var bol = FileIdHelper<Entity.MonitorPointMapping>.DeleteByIds(path, Ids);
|
return bol;
|
}
|
|
/// <summary>
|
/// 删除
|
/// </summary>
|
public bool Delete(long projectId, Entity.MonitorPointMapping rhs)
|
{
|
if (projectId < 1)
|
return default;
|
if (rhs == null)
|
return default;
|
var path = GetFolderPath(projectId);
|
var bol = FileIdHelper<Entity.MonitorPointMapping>.DeleteById(path, rhs.Id);
|
return bol;
|
}
|
|
/// <summary>
|
/// 批量删除
|
/// </summary>
|
public bool Deletes(long projectId, IEnumerable<Entity.MonitorPointMapping> list)
|
{
|
if (projectId < 1)
|
return default;
|
if (list == null || list.Count() < 1)
|
return default;
|
var path = GetFolderPath(projectId);
|
var Ids = list.Select(x => x.Id).ToList();
|
var bol = FileIdHelper<Entity.MonitorPointMapping>.DeleteByIds(path, Ids);
|
return bol;
|
}
|
|
/// <summary>
|
/// 删除全部
|
/// </summary>
|
public bool DeleteAll(long projectId)
|
{
|
if (projectId < 1)
|
return default;
|
var path = GetFolderPath(projectId);
|
var bol = FileIdHelper<Entity.MonitorPointMapping>.DeleteAll(path);
|
return bol;
|
}
|
|
|
/// <summary>
|
/// 根据 MonitorPointId 删除
|
/// </summary>
|
public bool DeleteByMonitorPointId(long projectId, long monitorPointId)
|
{
|
if (projectId < 1)
|
return default;
|
if (monitorPointId < 0)
|
return default;
|
var path = GetFolderPath(projectId);
|
var list = GetByMonitorPointId(projectId, monitorPointId);
|
if (list != null && list.Count > 0)
|
{
|
var Ids = list.Select(x => x.Id);
|
return FileIdHelper<Entity.MonitorPointMapping>.DeleteByIds(path, Ids);
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 根据 ObjectType 和 ObjectId 删除
|
/// </summary>
|
public bool DeleteByObjectTypeAndObjectId(long projectId, string objectType, long objectId)
|
{
|
if (projectId < 1)
|
return default;
|
if (objectId < 0)
|
return default;
|
var path = GetFolderPath(projectId);
|
var list = GetByObjectTypeAndObjectId(projectId, objectType, objectId);
|
if (list != null && list.Count > 0)
|
{
|
var Ids = list.Select(x => x.Id);
|
return FileIdHelper<Entity.MonitorPointMapping>.DeleteByIds(path, Ids);
|
}
|
return true;
|
}
|
|
#endregion
|
|
#region Cover
|
|
/// <summary>
|
/// 批量覆盖
|
/// </summary>
|
public bool Covers(long projectId, IEnumerable<Entity.MonitorPointMapping> list)
|
{
|
if (projectId < 1)
|
return default;
|
if (list == null || list.Count() < 1)
|
return default;
|
var path = GetFolderPath(projectId);
|
return FileIdHelper<Entity.MonitorPointMapping>.Covers(path, list);
|
}
|
|
/// <summary>
|
/// 批量覆盖并返回
|
/// </summary>
|
public List<Entity.MonitorPointMapping> CoversR(long projectId, IEnumerable<Entity.MonitorPointMapping> list)
|
{
|
if (projectId < 1)
|
return default;
|
if (list == null || list.Count() < 1)
|
return default;
|
var path = GetFolderPath(projectId);
|
return FileIdHelper<Entity.MonitorPointMapping>.CoversR(path, list);
|
}
|
|
#endregion
|
|
}
|
}
|