示例#1
0
        /// <summary>
        /// 审核专题
        /// </summary>
        /// <param name="id"></param>
        /// <param name="auditStatus"></param>
        /// <returns></returns>
        public InvokeResult <bool> AuditTopic(string id, int auditStatus, string auditMessage)
        {
            var entity = GetForm(id);

            if (entity.TopicStatus == (int)TopicStatus.Audited)
            {
                return(RequestResult.Failed <bool>("该专题已审核成功,不能重复审核!"));
            }
            entity.TopicStatus  = auditStatus;
            entity.EnabledMark  = true;
            entity.AuditMessage = auditMessage;

            //审核其他文件操作
            using (var tran = _Respository.BeginTransaction())
            {
                try
                {
                    var b        = false;
                    var articles = new List <Article>();
                    //先处理文件
                    string[] unZipFiles = new string[] { };
                    if (auditStatus == (int)TopicStatus.Audited && !entity.Attachment.IsEmpty())
                    {
                        //后台审核通过时写入
                        //压缩包文件 解压,把数据写入文库
                        if (File.Exists(FileHelper.MapFilePath(entity.Attachment)))
                        {
                            var zipfileInfo = new FileInfo(FileHelper.MapFilePath(entity.Attachment));//存在则覆盖
                            var unzipDir    = FileDownHelper.UnZip(zipfileInfo.FullName, zipfileInfo.FullName.Replace(zipfileInfo.Extension, "topic"));
                            unZipFiles = Directory.GetFiles(unzipDir);
                            if (!unZipFiles.Any())
                            {
                                tran.Rollback();
                                return(RequestResult.Failed <bool>("资源解压后无文件,审核失败"));
                            }

                            System.Threading.Thread.Sleep(800);

                            foreach (var file in unZipFiles)
                            {
                                var extension = FileHelper.GetExtension(file);
                                var dir       = $"/{ConfigManager.SysConfiguration.UploadFolder}/{DateTime.Now.ToString("yyyyMMdd")}";
                                if (!Directory.Exists(FileHelper.MapFilePath(dir)))
                                {
                                    Directory.CreateDirectory(FileHelper.MapFilePath(dir));
                                }
                                var newFileName = $"{dir}/{Common.GuId().Replace("-", "")}{extension}";
                                FileHelper.CopyFile(file, FileHelper.MapFilePath(newFileName));
                                var title   = FileHelper.GetFileName(file, false);
                                var article = new Article()
                                {
                                    Title           = title,
                                    ShortTitle      = title,
                                    Keyword         = title,
                                    Description     = title,
                                    Attachment      = newFileName,
                                    AllowDownload   = false,
                                    SpecialTopicId  = id,
                                    IsOnline        = true,
                                    MemberId        = entity.CreatorUserId,
                                    OnlinePageCount = 5,
                                    RequireAmount   = 0,
                                    PageCount       = 5,
                                    ResourceSize    = (int)FileHelper.GetFileSize(file),
                                    ResourceType    = extension.Replace(".", ""),
                                    BookStatus      = (int)BookStatus.审核通过,
                                    HasImages       = true,
                                };
                                articles.Add(article);

                                b = _ArticleRespository.CreateOrUpdate(article);
                                if (!b)
                                {
                                    tran.Rollback();
                                    return(RequestResult.Failed <bool>("解压数据处理失败"));
                                }

                                CoreContextProvider.ConvertFileToImage(article.Attachment.Split(',').ToList(), article.PageCount, _logger);
                            }
                        }
                    }

                    //后处理专题
                    if (!articles.Any())
                    {
                        tran.Rollback();
                        return(RequestResult.Failed <bool>("审核解压后文档数为0,审核失败!"));
                    }
                    entity.ResourceCount = articles.Count;
                    b = _Respository.UpdateFields(entity, "TopicStatus", "AuditMessage", "ResourceCount", "EnabledMark");
                    if (!b)
                    {
                        tran.Rollback();
                        return(RequestResult.Failed <bool>("审核失败"));
                    }

                    if (!entity.CreatorUserId.IsEmpty())
                    {
                        var memberScoreService = CoreContextProvider.GetService <IMemberScoreService>();
                        b = memberScoreService.AddScore(entity.CreatorUserId, ScoreType.addtopic, id).Success;
                        if (!b)
                        {
                            tran.Rollback();
                            return(RequestResult.Failed <bool>("审核处理积分失败"));
                        }
                    }

                    if (unZipFiles != null && unZipFiles.Any())
                    {
                        //[method.AuditTopic(cea705b9-ae49-40f6-ad4c-bb06fef1ff7d,1)]:Cannot access destination table 'Article'.
                        //insert into articles
                        //articleService.AddBetch(articles);
                    }

                    tran.Commit();
                    return(RequestResult.Success(true));
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    _logger.LogError($"[method.AuditTopic({id},{auditStatus})]:" + ex.ToString());
                    return(RequestResult.Failed <bool>("审核失败,数据异常"));
                }
            }
        }
示例#2
0
        /// <summary>
        /// 审核状态
        /// </summary>
        /// <param name="aid"></param>
        /// <param name="auditStatus"></param>
        /// <returns></returns>
        public InvokeResult <bool> AuditArticle(string aid, int auditStatus, string auditMessage)
        {
            var entity = GetForm(aid);

            entity.BookStatus   = auditStatus;
            entity.AuditMessage = auditMessage;
            using (var trans = _Respository.BeginTransaction())
            {
                try
                {
                    var updateFileds = new List <string>()
                    {
                        "BookStatus", "AuditMessage"
                    };
                    if (!entity.ResourceType.IsEmpty() && auditStatus == (int)BookStatus.审核通过)
                    {
                        if (entity.ResourceType == "pdf" || entity.ResourceType == "doc" || entity.ResourceType == "docx" ||
                            entity.ResourceType == "ppt" || entity.ResourceType == "pptx" || entity.ResourceType == "xls" ||
                            entity.ResourceType == "xlsx")
                        {
                            entity.HasImages = false;
                        }
                        else
                        {
                            entity.HasImages = true;
                        }
                        //updateFileds.Add("HasImages");
                        if (entity.CoverUrl.IsEmpty() && !entity.Attachment.IsEmpty())
                        {
                            var attFile = entity.Attachment.Split(',')[0];
                            entity.CoverUrl = $"{attFile.Replace(FileHelper.GetExtension(FileHelper.MapFilePath(attFile)), "")}/{FileHelper.GetFileNameNoExtension(attFile)}1.jpg";
                            updateFileds.Add("CoverUrl");
                        }
                    }
                    var b = _Respository.UpdateFields(entity, updateFileds.ToArray());
                    if (!b)
                    {
                        trans.Rollback();
                        return(RequestResult.Failed <bool>("审核处理积分失败"));
                    }
                    if (auditStatus == (int)BookStatus.审核通过)
                    {
                        //关联专题      数量处理
                        if (!entity.SpecialTopicId.IsEmpty())
                        {
                            var articleTopicRespository = CoreContextProvider.GetService <IArticleTopicRespository>();
                            var topic = articleTopicRespository.Get(entity.SpecialTopicId);
                            if (topic != null)
                            {
                                topic.ResourceCount++;
                                if (!articleTopicRespository.UpdateFields(topic, "ResourceCount"))
                                {
                                    trans.Rollback();
                                    _logger.LogError($"审核时更新{topic.Id}:topic.ResourceCount+1失败!");
                                    return(RequestResult.Failed <bool>("审核处理失败,请重试"));
                                }
                            }
                        }

                        //积分
                        var memberScoreService = CoreContextProvider.GetService <IMemberScoreService>();
                        var scoreResult        = memberScoreService.AddScore(entity.MemberId, ScoreType.addbook, aid);
                        if (!scoreResult.Success)
                        {
                            trans.Rollback();
                            _logger.LogError(scoreResult.Message);
                            return(RequestResult.Failed <bool>("审核处理积分失败"));
                        }
                    }
                    trans.Commit();
                    //资源文件生成图片操作
                    if (!entity.ResourceType.IsEmpty() && auditStatus == (int)BookStatus.审核通过)
                    {
                        //if (entity.ResourceType == "pdf" || entity.ResourceType == "doc" || entity.ResourceType == "docx"
                        //  || entity.ResourceType == "ppt" || entity.ResourceType == "pptx" || entity.ResourceType == "xls"
                        //  || entity.ResourceType == "xlsx")
                        CoreContextProvider.ConvertFileToImage(entity.Attachment.Split(',').ToList(), entity.PageCount, _logger);
                    }
                    return(RequestResult.Success(true));
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    _logger.LogError($"[method.AuditArticle({aid},{auditStatus})]:" + ex.Message);
                    return(RequestResult.Failed <bool>("审核失败,数据异常"));
                }
            }
        }