예제 #1
0
 public void TestMethod1()
 {
     var file     = @"D:\temp\░╦Абкио╩┐пок.zip";//@"D:\SkyeSpace\wwwnet\ClientPorjects\SkyMall\branches\SkyOilWeb\web\SkyMallCoreWeb\wwwroot\UploadFiles\20181127\e1194fc79236417c9c90b3b3688a00bc.zip";
     var unzipDir = FileDownHelper.UnZip(file, file.Replace(".zip", "topic"));
 }
예제 #2
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>("审核失败,数据异常"));
                }
            }
        }