コード例 #1
0
        public static AtomConfigModel Get(string code)
        {
            //缓存策略
            var key   = "atom_conf_get_" + code;
            var exist = AtomConfigCacheManage.GetIfExist <AtomConfigModel>(key);

            if (exist != null)
            {
                return(exist);
            }

            var now    = DateTime.Now;
            var result = SonFact.Cur.Top <AtomConfig, AtomConfigModel>(t => t.ConfigCode == code && t.Enable == true);

            if (result.StartTime != null && result.StartTime.Value > now)
            {
                return(null);
            }
            if (result.EndTime != null && result.EndTime.Value < now)
            {
                return(null);
            }

            if (result != null)
            {
                AtomConfigCacheManage.AddCache(code, result);
            }
            return(result);
        }
コード例 #2
0
        public static List <AtomConfigValueModel> GetVals(string pCode, int relId)
        {
            //缓存策略
            var key   = "atom_conf_getvals_" + pCode + "_" + relId;
            var exist = AtomConfigCacheManage.GetIfExist <List <AtomConfigValueModel> >(key);

            if (exist != null)
            {
                return(exist);
            }

            var now    = DateTime.Now;
            var result = new List <AtomConfigValueModel>();

            var cate = GetCate(pCode);

            if (cate == null || cate.CateChildren == null || cate.CateChildren.Count == 0)
            {
                return(null);
            }

            foreach (var item in cate.CateChildren)
            {
                result.Add(GetVal(item.CateCode, relId));
            }

            if (result != null)
            {
                AtomConfigCacheManage.AddCache(key, result);
            }
            return(result);
        }
コード例 #3
0
        public static AtomCateConfigModel GetCate(string pCode)
        {
            //缓存策略
            var key   = "atom_conf_getcate_" + pCode;
            var exist = AtomConfigCacheManage.GetIfExist <AtomCateConfigModel>(key);

            if (exist != null)
            {
                return(exist);
            }

            var result = SonFact.Cur.Top <AtomCateConfig, AtomCateConfigModel>(t => t.CateCode == pCode && t.Enable == true);

            if (result == null)
            {
                return(null);
            }

            var cates = SonFact.Cur.FindMany <AtomCateConfig, AtomCateConfigModel>(t => t.ParentCateCode == pCode && t.Enable == true);

            result.CateChildren = cates;

            if (result != null)
            {
                AtomConfigCacheManage.AddCache(key, result);
            }
            return(result);
        }
コード例 #4
0
        public static AtomConfigModel Gets(string parentCode)
        {
            //缓存策略
            var key   = "atom_conf_gets_" + parentCode;
            var exist = AtomConfigCacheManage.GetIfExist <AtomConfigModel>(key);

            if (exist != null)
            {
                return(exist);
            }

            var now    = DateTime.Now;
            var result = SonFact.Cur.Top <AtomConfig, AtomConfigModel>(t => t.ConfigCode == parentCode && t.Enable == true);

            if (result.StartTime != null && result.StartTime.Value > now)
            {
                return(null);
            }
            if (result.EndTime != null && result.EndTime.Value < now)
            {
                return(null);
            }
            if (result == null)
            {
                return(null);
            }

            result.AtomChildren = new List <AtomConfigModel>();

            var list = SonFact.Cur.FindMany <AtomConfig, AtomConfigModel>(t => t.ParentCode == result.ConfigCode && t.Enable == true);

            foreach (var item in list)
            {
                if (item.StartTime != null && item.StartTime.Value > now)
                {
                    continue;
                }
                if (item.EndTime != null && item.EndTime.Value < now)
                {
                    continue;
                }
                result.AtomChildren.Add(item);
            }

            if (result != null)
            {
                AtomConfigCacheManage.AddCache(key, result);
            }
            return(result);
        }
コード例 #5
0
        public static AtomConfigValueModel GetVal(string code, int relId)
        {
            //缓存策略
            var key   = "atom_conf_getval_" + code + "_" + relId;
            var exist = AtomConfigCacheManage.GetIfExist <AtomConfigValueModel>(key);

            if (exist != null)
            {
                return(exist);
            }

            var now    = DateTime.Now;
            var result = SonFact.Cur.Top <AtomConfigValue, AtomConfigValueModel>(t => t.CateCode == code && t.RelId == relId && t.Enable == true);

            //如果没有可用的配置则使用默认配置
            if (result == null || result.StartTime != null && result.StartTime.Value > now || result.EndTime != null && result.EndTime.Value < now)
            {
                result = SonFact.Cur.Top <AtomConfigValue, AtomConfigValueModel>(t => t.CateCode == code && t.RelId == 0 && t.Enable == true);
            }

            if (result == null)
            {
                return(null);
            }
            if (result.StartTime != null && result.StartTime.Value > now)
            {
                return(null);
            }
            if (result.EndTime != null && result.EndTime.Value < now)
            {
                return(null);
            }

            var cate = SonFact.Cur.Find <AtomCateConfig>(result.ConfigValueId);

            result.CateName = cate.CateName;

            if (result != null)
            {
                AtomConfigCacheManage.AddCache(key, result);
            }
            return(result);
        }