public void ContentFormSubmited(int siteId, int channelId, IContentInfo contentInfo, IDictionary <string, object> form)
        {
            var categoryChannelId    = TranslateUtils.Get <int>(form, "categoryChannelId");
            var categoryDepartmentId = TranslateUtils.Get <int>(form, "categoryDepartmentId");

            if (categoryChannelId == 0)
            {
                throw new Exception("请选择正确的主题分类");
            }
            contentInfo.ChannelId = categoryChannelId;
            if (categoryDepartmentId == 0)
            {
                throw new Exception("请选择正确的机构分类");
            }
            contentInfo.Set(ContentAttribute.DepartmentId, categoryDepartmentId.ToString());

            var classInfoList = Main.CategoryClassRepository.GetCategoryClassInfoList(siteId);

            foreach (var classInfo in classInfoList)
            {
                if (classInfo.IsSystem || !classInfo.IsEnabled)
                {
                    continue;
                }

                var attributeName  = PublicManager.GetCategoryContentAttributeName(classInfo.ClassCode);
                var attributeValue = TranslateUtils.Get <int>(form, attributeName);

                contentInfo.Set(attributeName, attributeValue.ToString());

                //if (attributeValue > 0)
                //{
                //    CategoryDao.UpdateContentNum(PublishmentSystemInfo, categoryClassInfo.ContentAttributeName, categoryId);
                //}
            }

            if (contentInfo.Id == 0)
            {
                var identifier = PublicManager.GetIdentifier(siteId, categoryChannelId,
                                                             categoryDepartmentId, contentInfo);
                contentInfo.Set(nameof(ContentAttribute.Identifier), identifier);
            }
            else
            {
                var effectDate = contentInfo.Get <DateTime>(ContentAttribute.EffectDate);
                if (string.IsNullOrEmpty(contentInfo.Get <string>(ContentAttribute.Identifier)) || PublicManager.IsIdentifierChanged(siteId, categoryChannelId, categoryDepartmentId, effectDate, contentInfo))
                {
                    var identifier = PublicManager.GetIdentifier(siteId, categoryChannelId,
                                                                 categoryDepartmentId, contentInfo);
                    contentInfo.Set(nameof(ContentAttribute.Identifier), identifier);
                }
            }
        }
示例#2
0
        public static bool IsIdentifierChanged(int siteId, int channelId, int departmentId, DateTime effectDate, IContentInfo contentInfo)
        {
            var isIdentifierChanged = false;
            var ruleInfoList        = Main.IdentifierRuleRepository.GetRuleInfoList(siteId);

            foreach (var ruleInfo in ruleInfoList)
            {
                var identifierType = EIdentifierTypeUtils.GetEnumType(ruleInfo.IdentifierType);
                if (identifierType == EIdentifierType.Department)
                {
                    if (contentInfo.Get <int>(nameof(ContentAttribute.DepartmentId)) != departmentId)
                    {
                        isIdentifierChanged = true;
                    }
                }
                else if (identifierType == EIdentifierType.Channel)
                {
                    if (contentInfo.Id != channelId)
                    {
                        isIdentifierChanged = true;
                    }
                }
                else if (identifierType == EIdentifierType.Attribute)
                {
                    if (Utils.EqualsIgnoreCase(ruleInfo.AttributeName, ContentAttribute.EffectDate) && TranslateUtils.ToDateTime(contentInfo.Get <string>(ruleInfo.AttributeName)) != effectDate)
                    {
                        isIdentifierChanged = true;
                    }
                }
            }
            return(isIdentifierChanged);
        }
示例#3
0
        public static void UpdateCache(SiteInfo siteInfo, ChannelInfo channelInfo, IContentInfo contentInfoToUpdate)
        {
            var dict = ContentCache.GetContentDict(channelInfo.Id);

            var contentInfo = GetContentInfo(siteInfo, channelInfo, contentInfoToUpdate.Id);

            if (contentInfo != null)
            {
                var isClearCache = contentInfo.IsTop != contentInfoToUpdate.IsTop;

                if (!isClearCache)
                {
                    var orderAttributeName =
                        ETaxisTypeUtils.GetContentOrderAttributeName(
                            ETaxisTypeUtils.GetEnumType(channelInfo.Additional.DefaultTaxisType));
                    if (contentInfo.Get(orderAttributeName) != contentInfoToUpdate.Get(orderAttributeName))
                    {
                        isClearCache = true;
                    }
                }

                if (isClearCache)
                {
                    ListCache.Remove(channelInfo.Id);
                }
            }


            dict[contentInfoToUpdate.Id] = (ContentInfo)contentInfoToUpdate;

            StlContentCache.ClearCache();
        }
示例#4
0
        public static string GetIdentifier(int siteId, int channelId, int departmentId, IContentInfo contentInfo)
        {
            if (contentInfo == null)
            {
                return(string.Empty);
            }
            var channelInfo = Context.ChannelApi.GetChannelInfo(siteId, channelId);

            if (channelInfo == null)
            {
                return(string.Empty);
            }

            var builder = new StringBuilder();

            var ruleInfoList = Main.IdentifierRuleRepository.GetRuleInfoList(siteId);

            foreach (var ruleInfo in ruleInfoList)
            {
                var identifierType = EIdentifierTypeUtils.GetEnumType(ruleInfo.IdentifierType);
                if (identifierType == EIdentifierType.Department)
                {
                    var departmentCode = DepartmentManager.GetDepartmentCode(siteId, departmentId);
                    if (ruleInfo.MinLength > 0)
                    {
                        builder.Append(departmentCode.PadLeft(ruleInfo.MinLength, '0')).Append(ruleInfo.Suffix);
                    }
                    else
                    {
                        builder.Append(departmentCode).Append(ruleInfo.Suffix);
                    }
                }
                else if (identifierType == EIdentifierType.Channel)
                {
                    var channelCode = channelInfo.Id.ToString();
                    if (ruleInfo.MinLength > 0)
                    {
                        builder.Append(channelCode.PadLeft(ruleInfo.MinLength, '0')).Append(ruleInfo.Suffix);
                    }
                    else
                    {
                        builder.Append(channelCode).Append(ruleInfo.Suffix);
                    }
                }
                else if (identifierType == EIdentifierType.Attribute)
                {
                    if (ruleInfo.AttributeName == ContentAttribute.AbolitionDate || ruleInfo.AttributeName == ContentAttribute.EffectDate || ruleInfo.AttributeName == ContentAttribute.PublishDate || ruleInfo.AttributeName == nameof(IContentInfo.AddDate))
                    {
                        var dateTime = TranslateUtils.ToDateTime(contentInfo.Get <string>(ruleInfo.AttributeName));
                        if (ruleInfo.MinLength > 0)
                        {
                            builder.Append(dateTime.ToString(ruleInfo.FormatString).PadLeft(ruleInfo.MinLength, '0')).Append(ruleInfo.Suffix);
                        }
                        else
                        {
                            builder.Append(dateTime.ToString(ruleInfo.FormatString)).Append(ruleInfo.Suffix);
                        }
                    }
                    else
                    {
                        var attributeValue = contentInfo.Get <string>(ruleInfo.AttributeName);
                        if (ruleInfo.MinLength > 0)
                        {
                            builder.Append(attributeValue.PadLeft(ruleInfo.MinLength, '0')).Append(ruleInfo.Suffix);
                        }
                        else
                        {
                            builder.Append(attributeValue).Append(ruleInfo.Suffix);
                        }
                    }
                }
                else if (identifierType == EIdentifierType.Sequence)
                {
                    var targetSiteId    = siteId;
                    var targetChannelId = 0;
                    if (ruleInfo.IsSequenceChannelZero)
                    {
                        targetChannelId = channelInfo.Id;
                    }
                    var targetDepartmentId = 0;
                    if (ruleInfo.IsSequenceDepartmentZero)
                    {
                        targetDepartmentId = departmentId;
                    }
                    var targetAddYear = 0;
                    if (ruleInfo.IsSequenceYearZero && contentInfo.AddDate != null)
                    {
                        targetAddYear = contentInfo.AddDate.Value.Year;
                    }

                    var sequence = Main.IdentifierSeqRepository.GetSequence(targetSiteId, targetChannelId, targetDepartmentId, targetAddYear, ruleInfo.Sequence);

                    if (ruleInfo.MinLength > 0)
                    {
                        builder.Append(sequence.ToString().PadLeft(ruleInfo.MinLength, '0')).Append(ruleInfo.Suffix);
                    }
                    else
                    {
                        builder.Append(sequence.ToString()).Append(ruleInfo.Suffix);
                    }
                }
            }

            return(builder.ToString());
        }