ningshuxia
2022-12-01 ad494f13d2ddf31f142cf7fb908b3a6e90395a1a
Service/IStation.Service.Basic/property/special_property_mapping/SpecialPropertyMapping.cs
@@ -66,6 +66,36 @@
            }
        }
        //通过 CatalogID 更新缓存
        private void UpdateCorpCacheByCatalogID(long CorpID, long CatalogID)
        {
            var dal = new DAL.SpecialPropertyMapping();
            var entity_list = dal.GetByCatalogID(CorpID, CatalogID);
            var model_list = Entity2Models(entity_list);
            var all = GetCorpCache(CorpID);
            all.RemoveAll(x => x.CorpID== CatalogID);
            if (model_list != null && model_list.Count > 0)
            {
                all.AddRange(model_list);
            }
        }
        //通过 CatalogIds 更新缓存
        private void UpdateCorpCacheByCatalogIds(long CorpID, List<long> CatalogIds)
        {
            if (CatalogIds == null || CatalogIds.Count() < 1)
                return;
            var dal = new DAL.SpecialPropertyMapping();
            var entity_list = dal.GetByCatalogIds(CorpID, CatalogIds);
            var model_list = Entity2Models(entity_list);
            var all = GetCorpCache(CorpID);
            all.RemoveAll(x => CatalogIds.Contains(x.CatalogID));
            if (model_list != null && model_list.Count > 0)
            {
                all.AddRange(model_list);
            }
        }
        //通过 ID 移除缓存
        private void RemoveCorpCache(long CorpID, long ID)
        {
@@ -107,6 +137,26 @@
        }
        /// <summary>
        /// 通过 CatalogID 获取
        /// </summary>
        public List<Model.SpecialPropertyMapping> GetByCatalogID(long CorpID, long CatalogID)
        {
            var all = GetByCorpID(CorpID);
            return all.Where(x => x.CatalogID == CatalogID).ToList();
        }
        /// <summary>
        /// 通过 CatalogIds 获取
        /// </summary>
        public List<Model.SpecialPropertyMapping> GetByCatalogIds(long CorpID, List<long> CatalogIds)
        {
            if (CatalogIds == null || CatalogIds.Count < 1)
                return default;
            var all = GetByCorpID(CorpID);
            return all.Where(x => CatalogIds.Contains(x.CatalogID)).ToList();
        }
        /// <summary>
        /// 通过 PropertyID 获取
        /// </summary>
        public List<Model.SpecialPropertyMapping> GetByPropertyID(long CorpID, long PropertyID)
@@ -116,14 +166,15 @@
        }
        /// <summary>
        /// 通过 CatalogID 获取
        /// 通过 PropertyIds 获取
        /// </summary>
        public List<Model.SpecialPropertyMapping> GetByCatalogID(long CorpID, long CatalogID)
        public List<Model.SpecialPropertyMapping> GetByPropertyIds(long CorpID, List<long> PropertyIds)
        {
            if (PropertyIds == null || PropertyIds.Count < 1)
                return default;
            var all = GetByCorpID(CorpID);
            return all.Where(x=>x.CatalogID == CatalogID).ToList();
            return all.Where(x => PropertyIds.Contains(x.PropertyID)).ToList();
        }
        #endregion
@@ -250,6 +301,29 @@
        #endregion
        #region Set
        /// <summary>
        /// 设置
        /// </summary>
        public bool Set(List<Model.SpecialPropertyMappingSelected> list)
        {
            if (list == null || list.Count() < 1)
                return false;
            var corpIds = list.Select(x => x.CorpID).Distinct().ToList();
            if (corpIds.Count != 1|| corpIds[0] < 1)
                return false;
            var dal = new DAL.SpecialPropertyMapping();
            var bol = dal.Set(list.ToEntityList());
            if (bol)
            {
                UpdateCorpCacheByCatalogIds(corpIds[0], list.Select(x => x.CatalogID).ToList());
            }
            return bol;
        }
        #endregion
    }
}