| | |
| | | public partial class MonitorPointGroup |
| | | { |
| | | private readonly IDAL.IMonitorPointGroup<Entity.MonitorPointGroup> _dal |
| | | = DAL.Factory.DataAccessBase.CreateDAL<IDAL.IMonitorPointGroup<Entity.MonitorPointGroup>>(Settings.DataAccess.MonitorDLLName, Settings.DataAccess.DALNameSpace); |
| | | = DAL.Factory.DataAccess.CreateDAL<IDAL.IMonitorPointGroup<Entity.MonitorPointGroup>>(Settings.DataAccess.MonitorDLLName, Settings.DataAccess.DALNameSpace); |
| | | |
| | | #region Cache |
| | | |
| | | //通过 projectId 获取缓存 |
| | | //根据 projectId 查询缓存 |
| | | private List<Model.MonitorPointGroup> GetProjectCache(long projectId) |
| | | { |
| | | return MonitorPointGroupCacheHelper.GetSet(projectId, () => |
| | | { |
| | | var entities = _dal.QueryAll(projectId); |
| | | var entities = _dal.GetAll(projectId); |
| | | var models = Entity2Models(entities); |
| | | if (models == null) |
| | | { |
| | |
| | | }, ConfigHelper.CacheKeepTime, ConfigHelper.CacheRandomTime); |
| | | } |
| | | |
| | | //通过 Id 更新缓存 |
| | | private void UpdateProjectCache(long projectId, long id) |
| | | //根据 Id 更新缓存 |
| | | private void UpdateProjectCache(long projectId, long Id) |
| | | { |
| | | var entity_ds = _dal.QueryById(projectId, id); |
| | | var entity_ds = _dal.GetById(projectId, Id); |
| | | var model_ds = Entity2Model(entity_ds); |
| | | var all = GetProjectCache(projectId); |
| | | var model = all.Find(x => x.Id == id); |
| | | var model = all.Find(x => x.Id == Id); |
| | | if (model == null) |
| | | { |
| | | all.Add(model_ds); |
| | |
| | | } |
| | | } |
| | | |
| | | //通过 Ids 更新缓存 |
| | | private void UpdateProjectCache(long projectId, IEnumerable<long> ids) |
| | | //根据 Ids 更新缓存 |
| | | private void UpdateProjectCache(long projectId, IEnumerable<long> Ids) |
| | | { |
| | | if (ids == null || ids.Count() < 1) |
| | | if (Ids == null || Ids.Count() < 1) |
| | | return; |
| | | var entities = _dal.QueryByIds(projectId, ids); |
| | | var entities = _dal.GetByIds(projectId, Ids); |
| | | var models = Entity2Models(entities); |
| | | var all = GetProjectCache(projectId); |
| | | all.RemoveAll(x => ids.Contains(x.Id)); |
| | | all.RemoveAll(x => Ids.Contains(x.Id)); |
| | | if (models != null && models.Count > 0) |
| | | { |
| | | all.AddRange(models); |
| | | } |
| | | } |
| | | |
| | | //通过 Id 移除缓存 |
| | | //根据 Id 移除缓存 |
| | | private void RemoveProjectCache(long projectId, long Id) |
| | | { |
| | | var all = GetProjectCache(projectId); |
| | |
| | | |
| | | #endregion |
| | | |
| | | #region Query |
| | | #region Get |
| | | |
| | | /// <summary> |
| | | /// 查询全部 |
| | | /// </summary> |
| | | public List<Model.MonitorPointGroup> QueryAll(long projectId) |
| | | public List<Model.MonitorPointGroup> GetAll(long projectId) |
| | | { |
| | | var all = GetProjectCache(projectId); |
| | | return all.OrderBy(x => x.SortCode).ToList(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据Id查询 |
| | | /// 根据 Id查询 |
| | | /// </summary> |
| | | public Model.MonitorPointGroup QueryById(long projectId, long id) |
| | | public Model.MonitorPointGroup GetById(long projectId, long Id) |
| | | { |
| | | var all = QueryAll(projectId); |
| | | return all.Find(x => x.Id == id); |
| | | var all = GetAll(projectId); |
| | | return all.Find(x => x.Id == Id); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 通过 Ids 获取 |
| | | /// 根据 Ids 查询 |
| | | /// </summary> |
| | | public List<Model.MonitorPointGroup> QueryByIds(long projectId, IEnumerable<long> ids) |
| | | public List<Model.MonitorPointGroup> GetByIds(long projectId, IEnumerable<long> Ids) |
| | | { |
| | | if (ids == null || ids.Count() < 1) |
| | | if (Ids == null || Ids.Count() < 1) |
| | | return default; |
| | | var all = QueryAll(projectId); |
| | | return all.Where(x => ids.Contains(x.Id)).ToList(); |
| | | var all = GetAll(projectId); |
| | | return all.Where(x => Ids.Contains(x.Id)).ToList(); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 根据 BelongType BelongId 查询 |
| | | /// </summary> |
| | | public List<Model.MonitorPointGroup> GetByBelongTypeAndBelongId(long projectId, string belongType, long belongId) |
| | | { |
| | | var all = GetAll(projectId); |
| | | return all.Where(x => x.BelongType == belongType && x.BelongId == belongId).ToList(); |
| | | } |
| | | #endregion |
| | | |
| | |
| | | if (model == null) |
| | | return default; |
| | | var entities = Model2Entity(model); |
| | | var id = _dal.Insert(projectId, entities); |
| | | if (id > 0) |
| | | var Id = _dal.Insert(projectId, entities); |
| | | if (Id > 0) |
| | | { |
| | | UpdateProjectCache(projectId, id); |
| | | UpdateProjectCache(projectId, Id); |
| | | } |
| | | return id; |
| | | return Id; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | if (list == null || list.Count() < 1) |
| | | return default; |
| | | var entities = Model2Entities(list.ToList()); |
| | | var ids = _dal.InsertsR(projectId, entities); |
| | | if (ids != null && ids.Count > 0) |
| | | var Ids = _dal.InsertsR(projectId, entities); |
| | | if (Ids != null && Ids.Count > 0) |
| | | { |
| | | UpdateProjectCache(projectId, ids); |
| | | UpdateProjectCache(projectId, Ids); |
| | | return true; |
| | | } |
| | | return false; |
| | |
| | | /// </summary> |
| | | public bool Update(long projectId, Model.MonitorPointGroup model) |
| | | { |
| | | if (projectId < 0) |
| | | if (projectId < 1) |
| | | return default; |
| | | if (model == null) |
| | | return default; |
| | |
| | | /// </summary> |
| | | public bool Updates(long projectId, List<Model.MonitorPointGroup> list) |
| | | { |
| | | if (projectId < 0) |
| | | if (projectId < 1) |
| | | return default; |
| | | if (list == null || list.Count() < 1) |
| | | return default; |
| | |
| | | /// </summary> |
| | | public bool IsExistById(long projectId, long Id) |
| | | { |
| | | var all = QueryAll(projectId); |
| | | var all = GetAll(projectId); |
| | | return all.Exists(x => x.Id == Id); |
| | | } |
| | | #endregion |
| | |
| | | #region Delete |
| | | |
| | | /// <summary> |
| | | /// 通过 Id 删除 |
| | | /// 根据 Id 删除 |
| | | /// </summary> |
| | | public bool DeleteById(long projectId, long id, out string msg) |
| | | public bool DeleteById(long projectId, long Id, out string msg) |
| | | { |
| | | msg = string.Empty; |
| | | var bol = _dal.DeleteById(projectId, id); |
| | | var bol = _dal.DeleteById(projectId, Id); |
| | | if (bol) |
| | | { |
| | | RemoveProjectCache(projectId, id); |
| | | RemoveProjectCache(projectId, Id); |
| | | } |
| | | return bol; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region Cover |
| | | |
| | | /// <summary> |
| | | /// 批量覆盖 |
| | | /// </summary> |
| | | public bool Covers(long projectId, IEnumerable<Model.MonitorPointGroup> list) |
| | | { |
| | | if (projectId < 1) |
| | | return default; |
| | | if (list == null || list.Count() < 1) |
| | | return default; |
| | | var entities = Model2Entities(list.ToList()); |
| | | var bol = _dal.Covers(projectId, entities); |
| | | if (bol) |
| | | { |
| | | MonitorPointGroupCacheHelper.Remove(projectId); |
| | | } |
| | | return bol; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 批量覆盖并返回 |
| | | /// </summary> |
| | | public List<Entity.MonitorPointGroup> CoversR(long projectId, IEnumerable<Model.MonitorPointGroup> list) |
| | | { |
| | | if (projectId < 1) |
| | | return default; |
| | | if (list == null || list.Count() < 1) |
| | | return default; |
| | | var entities = Model2Entities(list.ToList()); |
| | | var models = _dal.CoversR(projectId, entities); |
| | | if (models != null && models.Count > 0) |
| | | { |
| | | MonitorPointGroupCacheHelper.Remove(projectId); |
| | | } |
| | | return models; |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |