ningshuxia
2023-02-24 1e4b358de58e36bfbf692ab2538ff9e7d60fd025
BLL/IStation.BLL.Logic/logic_tree/LogicTree.cs
@@ -16,12 +16,12 @@
        #region Cache 
        //根据 projectId 获取缓存
        //根据 projectId 查询缓存
        private List<Model.LogicTree> GetProjectCache(long projectId)
        {
            return LogicTreeCacheHelper.GetSet(projectId, () =>
            {
                var entities = _dal.QueryAll(projectId);
                var entities = _dal.GetAll(projectId);
                var models = Entity2Models(entities);
                if (models == null)
                {
@@ -34,7 +34,7 @@
        //根据 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);
@@ -53,7 +53,7 @@
        {
            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));
@@ -72,35 +72,45 @@
        #endregion
        #region Query
        #region Get
        /// <summary>
        /// 查询全部
        /// </summary>
        public List<Model.LogicTree> QueryAll(long projectId)
        public List<Model.LogicTree> GetAll(long projectId)
        {
            var all = GetProjectCache(projectId);
            return all.OrderBy(x => x.SortCode).ToList();
        }
        /// <summary>
        /// 根据Id查询
        /// 根据 Id查询
        /// </summary>
        public Model.LogicTree QueryById(long projectId, long Id)
        public Model.LogicTree GetById(long projectId, long Id)
        {
            var all = QueryAll(projectId);
            var all = GetAll(projectId);
            return all.Find(x => x.Id == Id);
        }
        /// <summary>
        /// 根据 Ids 获取
        /// 根据 Ids 查询
        /// </summary>
        public List<Model.LogicTree> QueryByIds(long projectId, IEnumerable<long> Ids)
        public List<Model.LogicTree> GetByIds(long projectId, IEnumerable<long> Ids)
        {
            if (Ids == null || Ids.Count() < 1)
                return default;
            var all = QueryAll(projectId);
            var all = GetAll(projectId);
            return all.Where(x => Ids.Contains(x.Id)).ToList();
        }
        /// <summary>
        /// 根据 LogicType LogicId 查询
        /// </summary>
        public Model.LogicTree GetByLogicTypeAndLogicId(long projectId, string logicType, long logicId)
        {
            var all = GetAll(projectId);
            return all.Find(x => x.LogicType == logicType&&x.LogicId== logicId);
        }
        #endregion
@@ -196,7 +206,7 @@
        /// </summary>
        public bool IsExistById(long projectId, long Id)
        {
            var all = QueryAll(projectId);
            var all = GetAll(projectId);
            return all.Exists(x => x.Id == Id);
        } 
        #endregion
@@ -219,5 +229,44 @@
        #endregion
        #region Cover
        /// <summary>
        /// 批量覆盖
        /// </summary>
        public bool Covers(long projectId, IEnumerable<Model.LogicTree> 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)
            {
                LogicTreeCacheHelper.Remove(projectId);
            }
            return bol;
        }
        /// <summary>
        /// 批量覆盖并返回
        /// </summary>
        public List<Entity.LogicTree> CoversR(long projectId, IEnumerable<Model.LogicTree> 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)
            {
                LogicTreeCacheHelper.Remove(projectId);
            }
            return models;
        }
        #endregion
    }
}