Example #1
0
        public virtual void AuditData(bool result, string message)
        {
            if (CoreContextProvider.CurrentSysUser == null)
            {
                return;
            }
            var sysLog = new SysLog();

            sysLog.Id            = Common.GuId();
            sysLog.Date          = DateTime.Now;
            sysLog.Account       = CoreContextProvider.CurrentSysUser == null ? "" : CoreContextProvider.CurrentSysUser.Account;
            sysLog.NickName      = CoreContextProvider.CurrentSysUser == null ? "" : CoreContextProvider.CurrentSysUser.RealName;
            sysLog.IPAddress     = CoreContextProvider.HttpContext.GetIP();
            sysLog.IPAddressName = NetClient.GetLocation(sysLog.IPAddress);
            sysLog.Result        = result;
            sysLog.Description   = message;
            System.Threading.Tasks.Task.Factory.StartNew(() => {
                try
                {
                    var logService = CoreContextProvider.GetService <ISysLogRespository>(true);
                    logService.OperatLog(sysLog);
                }
                catch (Exception ex)
                { }
            });
        }
Example #2
0
        /// <summary>
        /// 写入阅读数量
        /// </summary>
        /// <param name="readType"></param>
        /// <param name="id"></param>
        public void UserRead(ReadType readType, string id)
        {
            var hasRead = CoreContextProvider.HttpContext.GetCookie($"{readType}_{id}").IsEmpty();

            if (hasRead)
            {
                CoreContextProvider.HttpContext.WriteCookie($"{readType}_{id}", id);
                Task.Run(() =>
                {
                    switch (readType)
                    {
                    case ReadType.News:
                        CoreContextProvider.GetService <INewsService>(true).ClientRead(id);
                        break;

                    case ReadType.Topic:
                        CoreContextProvider.GetService <IArticleTopicService>(true).ClientRead(id);
                        break;

                    case ReadType.Article:
                        CoreContextProvider.GetService <IArticleService>(true).ClientRead(id);
                        break;
                    }
                });
            }
        }
Example #3
0
        public List <MemScoreDetailView> GetList(bool isTop, int count)
        {
            var expression = base.GetFilterEnabled();
            Func <IQueryable <MemberScore>, IOrderedQueryable <MemberScore> > order = o => o.OrderBy(b => b.SortCode);

            if (isTop)
            {
                order = o => o.OrderByDescending(w => w.CreatorTime);
            }
            var data = _Respository.GetFeilds(u => new MemScoreDetailView
            {
                Score      = u.Score,
                Member     = u.Member.UserName,
                MemberId   = u.MemberId,
                ScoreType  = u.ScoreType,
                OperatType = u.OperatType,
            }, expression, order, "Member").Take(count).ToList();

            var scoreTypes      = data.Select(w => w.ScoreType + "").Distinct().ToArray();
            var itemDataService = CoreContextProvider.GetService <ISysItemsDetailService>();
            var itemDatas       = itemDataService.GetListItem("ScoreType", scoreTypes);

            data.ForEach(d =>
            {
                var t           = d.OperatType == 0 ? "ScoreType" : "ScoreType1";
                d.ScoreTypeName = itemDatas.Where(w => w.ParentId == t && w.Code == d.ScoreType + "").Select(w => w.Text).FirstOrDefault();
            });
            return(data);
        }
Example #4
0
 /// <summary>
 /// 获取文章分类
 /// </summary>
 /// <param name="parentId"></param>
 /// <returns></returns>
 public List <ListItem> GetArticleCateList(IArticleCategoryService articleCategoryService, string currentId, string parentId, bool containsChild = false)
 {
     if (articleCategoryService == null)
     {
         articleCategoryService = CoreContextProvider.GetService <IArticleCategoryService>();
     }
     return(articleCategoryService.GetCateList(currentId, parentId, containsChild));
 }
Example #5
0
        ISysLogRespository _SysLogRespository;//取出表名Name
        public AuditedRespository(ISkyMallDbContext skyMallDbContext) : base(skyMallDbContext)
        {
            _SysLogRespository = CoreContextProvider.GetService <ISysLogRespository>();
            var modelType = typeof(TCreatorEntity).GetCustomAttributes(typeof(DisplayNameAttribute), true).FirstOrDefault();

            if (modelType != null)
            {
                TableScName = ((DisplayNameAttribute)modelType).DisplayName;
            }
        }
        private bool ActionAuthorize(ActionExecutingContext filterContext)
        {
            var operatorProvider = CoreContextProvider.CurrentSysUser;
            var roleId           = operatorProvider.RoleId;
            var moduleId         = WebHelper.GetCookie("nfine_currentmoduleid");
            var action           = CoreContextProvider.HttpContext.Request.Headers["SCRIPT_NAME"].ToString();

            return(CoreContextProvider.GetService <SkyMallCore.Services.ISysRoleAuthorizeService>()
                   .ActionValidate(roleId, moduleId, action));
        }
Example #7
0
        public MemberDetailView GetMember(string memberId)
        {
            //if (memberId.IsEmpty())
            //{
            //    memberId = CoreContextProvider.CurrentMember.UserId;
            //}
            var data   = CoreContextProvider.GetService <IMemberService>().GetMember(memberId);
            var result = AutoMapper.Mapper.Map <MemberDetailView>(data);

            if (result == null)
            {
                result = new MemberDetailView {
                    UserName = "******"
                };
            }
            return(result);
        }
Example #8
0
        public InvokeResult <bool> DeleteForm(string keyValue)
        {
            //被购买不可删除
            var scoreDao = CoreContextProvider.GetService <IMemberScoreRespository>();

            if (scoreDao.Any(w => w.KeyId == keyValue))
            {
                return(RequestResult.Failed <bool>("该文库已被购买,不可删除"));
            }

            var entyFile = _Respository.GetFeild(u => u.CoverUrl + "," + u.Attachment + "," + u.ResourceUrl, w => w.Id == keyValue);
            var b        = _Respository.Delete(keyValue);

            if (b)
            {
                //删除文件
                CoreContextProvider.DeleteFiles(entyFile);
            }
            return(RequestResult.Result(b));
        }
        public virtual void WriteDbLog(string msg, bool b = true)
        {
            var sysLog = new SysLog();

            sysLog.Id            = Common.GuId();
            sysLog.Date          = DateTime.Now;
            sysLog.Account       = CoreContextProvider.CurrentSysUser == null ? "" : CoreContextProvider.CurrentSysUser.Account;
            sysLog.NickName      = CoreContextProvider.CurrentSysUser == null ? "" : CoreContextProvider.CurrentSysUser.RealName;
            sysLog.IPAddress     = HttpContext.GetIP();
            sysLog.IPAddressName = NetClient.GetLocation(sysLog.IPAddress);
            sysLog.Result        = b;
            sysLog.Description   = msg;
            Task.Factory.StartNew(() => {
                try
                {
                    var logService = CoreContextProvider.GetService <SkyMallCore.Respository.ISysLogRespository>(true);
                    logService.OperatLog(sysLog);
                }
                catch
                { }
            });
        }
Example #10
0
        /// <summary>
        /// 下载数量
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public InvokeResult <Article> ClientDownLoad(string id)
        {
            var entity = GetForm(id);

            if (CoreContextProvider.CurrentMember.UserId == entity.MemberId)
            {
                return(RequestResult.Success(entity));
            }
            //下载更新积分
            //此下载直接按购买处理
            var memScoreService = CoreContextProvider.GetService <IMemberScoreService>();
            var scoreResult     = memScoreService.MarketBuy(CoreContextProvider.CurrentMember.UserId, ScoreType.buybook, id, entity.RequireAmount, entity.MemberId);

            if (!scoreResult.Success)
            {
                _logger.LogError($"用户{CoreContextProvider.CurrentMember.Account}[{CoreContextProvider.CurrentMember.UserId}]下载文库[{id}]积分更新失败:");
                return(RequestResult.Failed <Article>(scoreResult.Message ?? "下载操作失败请重试!"));
            }
            entity.DownloadCount++;
            var b = _Respository.UpdateFields(entity, "DownloadCount");

            return(RequestResult.Success(entity));
        }
 public SysBaseController()
 {
     _logService = CoreContextProvider.GetService <ISysLogService>();
 }
Example #12
0
        /// <summary>
        /// 获取系统字典
        /// </summary>
        /// <param name="enCode"></param>
        /// <returns></returns>
        public static List <ListItem> GetItemDictionary(string enCode)
        {
            var sysItemsDetailService = CoreContextProvider.GetService <ISysItemsDetailService>();

            return(sysItemsDetailService.GetListItem(enCode));
        }
Example #13
0
        /// <summary>
        /// 包含详细信息
        /// </summary>
        /// <param name="searchView"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public PagedList <TopicDetailView> GetTopicInfoList(ArticleTopicSearchView searchView, int pageIndex, int pageSize)
        {
            var expression = base.GetFilterEnabled();
            var order      = base.Order();

            if (searchView.IgnoreCate.HasValue && searchView.IgnoreCate == true)
            {
                expression = expression.And(w => w.ParentId != null);
                if (!searchView.ParentId.IsEmpty())
                {
                    expression = expression.And(w => searchView.ParentId.Contains(w.ParentId));
                }
            }
            else
            {
                if (searchView.ParentId == null)
                {
                    expression = expression.And(w => w.ParentId == null);
                }
                else
                {
                    expression = expression.And(w => searchView.ParentId.Contains(w.ParentId));
                }
            }

            if (!searchView.TopicId.IsEmpty())
            {
                expression = expression.And(w => w.Id == searchView.TopicId);
            }


            if (searchView.HotTopic.HasValue && searchView.HotTopic.Value)
            {
                order = o => o.OrderByDescending(w => w.ReadCount);
            }

            var data = _Respository.GetPagedList(u => new TopicDetailView
            {
                Id            = u.Id,
                Title         = u.Title,
                CreatorTime   = u.CreatorTime,
                ParentId      = u.ParentId,
                ShortTitle    = u.ShortTitle,
                CoverUrl      = u.CoverUrl,
                BigCoverUrl   = u.BigCoverUrl,
                ReadCount     = u.ReadCount,
                MemberId      = u.CreatorUserId,
                PackageAmount = u.PackageAmount,
                TopicStatus   = u.TopicStatus,
                MemberName    = "admin",
                ResourceCount = u.ResourceCount
            }, expression, pageIndex, pageSize, o => o.OrderBy(b => b.SortCode));

            var parentIds = data.Where(w => w.ParentId != null).Select(u => u.Id).Distinct().ToList();
            Dictionary <string, int> valuePairs = new Dictionary <string, int>();

            if (parentIds.Any())
            {
                //资源数量统计
                if (parentIds.Any())
                {
                    var articleService = CoreContextProvider.GetService <IArticleRespository>();
                    valuePairs = articleService.GetStaticsCount(parentIds, true);
                }
            }

            //默认全是管理员
            List <Member> memberDics = new List <Member>();
            var           memberIds  = data.Where(w => w.MemberId != null).Select(u => u.MemberId).Distinct().ToArray();

            if (memberIds.Any())
            {
                var memberRespository = CoreContextProvider.GetService <IMemberRespository>();
                memberDics = memberRespository.GetMemberInfos(memberIds);
            }

            //相关用户统计
            data.ForEach(cate =>
            {
                var statics = valuePairs.TryGetValue(cate.Id);
                if (cate.ResourceCount == 0 && parentIds.Any())
                {
                    cate.ResourceCount = statics;
                }
                if (memberDics.Any())
                {
                    var mem = memberDics.Where(w => w.Id == cate.MemberId).FirstOrDefault();
                    if (mem != null)
                    {
                        cate.MemberName = mem.UserName;
                        cate.MemHeader  = mem.HeadIcon;
                        cate.UserLevel  = mem.UserLevel;
                    }
                }
            });


            return(data);
        }
Example #14
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>("审核失败,数据异常"));
                }
            }
        }
Example #15
0
        /// <summary>
        /// 加载列表
        /// </summary>
        /// <param name="searchView"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public PagedList <TopicDetailView> GetTopicsList(ArticleTopicSearchView searchView, int pageIndex = 1, int pageSize = 20)
        {
            var expression = base.GetFilterEnabled();
            var order      = base.Order();

            if (!searchView.Keyword.IsEmpty())
            {
                expression = expression.And(w => w.Title.Contains(searchView.Keyword));
            }

            if (searchView.IgnoreCate.HasValue && searchView.IgnoreCate == true)
            {
                expression = expression.And(w => w.ParentId != null);
                if (!searchView.ParentId.IsEmpty())
                {
                    expression = expression.And(w => searchView.ParentId.Contains(w.ParentId));
                }
            }
            else
            {
                //if (searchView.ParentId == null)
                //{
                //    expression = expression.And(w => w.ParentId == null);
                //}
                //else
                //{
                //    expression = expression.And(w => searchView.ParentId.Contains(w.ParentId));
                //}
                if (searchView.ParentId != null)
                {
                    searchView.ParentId = searchView.ParentId.Where(w => !w.IsEmpty()).ToArray();
                    if (searchView.ParentId.Any())
                    {
                        expression = expression.And(w => searchView.ParentId.Contains(w.ParentId));
                    }
                }
            }

            if (searchView.TopicStatus.HasValue)
            {
                expression = expression.And(w => w.TopicStatus == (int)searchView.TopicStatus);
            }


            if (!searchView.MemberId.IsEmpty())
            {
                expression = expression.And(w => w.CreatorUserId == searchView.MemberId);
            }


            if (searchView.IsRemmand.HasValue)
            {
                order = o => o.OrderBy(w => w.SortCode);
            }

            var data = _Respository.GetPagedList(u => new TopicDetailView
            {
                Id            = u.Id,
                Title         = u.Title,
                CreatorTime   = u.CreatorTime,
                ParentId      = u.ParentId,
                ShortTitle    = u.ShortTitle,
                CoverUrl      = u.CoverUrl,
                BigCoverUrl   = u.BigCoverUrl,
                ReadCount     = u.ReadCount,
                MemberId      = u.CreatorUserId,
                TopicStatus   = u.TopicStatus,
                EnabledMark   = u.EnabledMark,
                Description   = u.Description,
                SortCode      = u.SortCode,
                PackageAmount = u.PackageAmount
            }, expression, pageIndex, pageSize, order);

            if (searchView.IsRemmand.HasValue)
            {
                var parentIds = data.Select(u => u.Id).ToArray();
                var articles  = CoreContextProvider.GetService <IArticleService>().GetTopArticles(ArticleTopEnum.NewHotArticle, 14, parentIds);
                data.ForEach(cate => {
                    cate.ArticleDetails = articles.Where(w => w.CategoryId == cate.Id).ToList();
                });
            }
            return(data);
        }
Example #16
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>("审核失败,数据异常"));
                }
            }
        }