Пример #1
0
        /// <summary>
        /// 更新页面版本
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public InvokeResult RecoveryBodyVersion(int Id, int sysUserId)
        {
            InvokeResult result = new InvokeResult()
            {
                Status = Status.Successful
            };
            PageBodyBll bodyBll  = PageBodyBll._(this._ctx);
            BookPageBll pageBll  = BookPageBll._(this._ctx);
            var         bVersion = FindById(Id);
            var         Page     = bVersion.SourceBson("pageId");

            if (bVersion != null && Page != null)
            {
                var currentBody = Page.ChildBsonList("PageBody").FirstOrDefault();
                //currentBody.lastVersion = currentBody.lastVersion + 1;
                if (currentBody == null)
                {
                    result.Status  = Status.Failed;
                    result.Message = "该对象被删除,请刷新后重试";
                    return(result);
                }
                var currentBodyUpdateBson = new BsonDocument();
                currentBodyUpdateBson.Add("body", bVersion.Text("body"));
                currentBodyUpdateBson.Add("lastVersion", currentBody.Int("lastVersion") + 1);
                var newBodyVersion = new BsonDocument();
                newBodyVersion.Add("body", bVersion.Text("body"));
                newBodyVersion.Add("userId", sysUserId);
                newBodyVersion.Add("bodyVersion", currentBody.Int("lastVersion") + 1);
                newBodyVersion.Add("bodyId", bVersion.Text("bodyId"));
                this._ctx.Update(Page, string.Format("lastVersion={0}", currentBody.Int("lastVersion") + 1));
                using (TransactionScope tran = new TransactionScope())
                {
                    var draft = Page.ChildBsonList("PageTempBody").Where(r => r.Int("saveUserId") == sysUserId).FirstOrDefault();
                    if (draft != null)
                    {
                        var delRet = this._ctx.Delete("PageTempBody", string.Format("tempBodyId={0}", draft.Text("tempBodyId")));
                    }
                    result = this._ctx.Insert("PageBodyVersion", newBodyVersion);
                    result = bodyBll.Update(currentBody, currentBodyUpdateBson);

                    tran.Complete();
                }
                try
                {
                    pageBll.GenerateSnapshot(Page.Int("pageId"));
                    //pageBll.BuildIndex(Page);
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                result.Status  = Status.Failed;
                result.Message = "该版本可能已经被刷新请重新刷新!";
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 保存内容
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="refPageId"></param>
        /// <param name="tagList"></param>
        /// <param name="strTag"></param>
        /// <param name="retIds">成果Id</param>
        /// <returns></returns>
        public InvokeResult Save(BsonDocument entity, int refPageId, List <BsonDocument> tagList, string strTag, int[] retIds)
        {
            InvokeResult result  = new InvokeResult();
            BookPageBll  pageBll = BookPageBll._(this._ctx);
            //ObjectEntityTagBll tagBll = ObjectEntityTagBll._(this._ctx);
            BsonDocument curAvaiableEntity = entity;

            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    var oldBody = this._ctx.FindOneByKeyVal("PageBody", "pageId", entity.Text("pageId"));
                    if (oldBody != null)
                    {
                        var updateBson = new BsonDocument();
                        updateBson.Add("body", entity.Text("body"));
                        result = this._ctx.Update(oldBody, updateBson);
                        if (result.Status != Status.Successful)
                        {
                            return(result);
                        }
                        curAvaiableEntity = result.BsonInfo;
                        var oldPage        = oldBody.SourceBson("pageId");
                        var pageUpdateBson = new BsonDocument();
                        pageUpdateBson.Add("customTag", strTag);
                        result = _ctx.Update(oldPage, pageUpdateBson);
                        if (result.Status != Status.Successful)
                        {
                            return(result);
                        }
                    }
                    else
                    {
                        result = _ctx.Insert("PageBody", entity);
                        if (result.Status != Status.Successful)
                        {
                            return(result);
                        }
                    }


                    var bodyId = oldBody == null?entity.Int("bodyId") : oldBody.Int("bodyId");

                    var query     = this._ctx.FindAllByKeyVal("PageBodyVersion", "pageId", entity.Text("pageId"));
                    var Max       = query.Count() > 0 ? query.Max(c => c.Int("bodyVersion")) : 0;
                    var versionId = Max + 1;
                    var version   = new BsonDocument();
                    version.Add("pageId", curAvaiableEntity.Text("pageId"));
                    version.Add("bodyId", bodyId);
                    version.Add("userId", curAvaiableEntity.Text("createUserId"));
                    version.Add("body", curAvaiableEntity.Text("body"));
                    version.Add("bodyVersion", versionId);
                    result = this._ctx.Insert("PageBodyVersion", version);
                    if (result.Status != Status.Successful)
                    {
                        return(result);
                    }

                    var versionUpdateBson = new BsonDocument();
                    versionUpdateBson.Add("lastVersion", versionId);
                    if (oldBody != null)
                    {
                        _ctx.Update(oldBody, versionUpdateBson);
                    }
                    else
                    {
                        _ctx.Update(entity, versionUpdateBson);
                    }


                    var page = this._ctx.FindOneByKeyVal("BookPage", "pageId", entity.Text("pageId"));
                    if (page != null)
                    {
                        var lastVersionBson = new BsonDocument();
                        lastVersionBson.Add("lastVersion", versionId);
                        _ctx.Update(page, versionUpdateBson);
                    }


                    var deletePageTempBody = _ctx.FindAllByKeyVal("PageTempBody", "pageId", entity.Text("pageId"));
                    result = this._ctx.QuickDelete("PageTempBody", deletePageTempBody.ToList());
                    if (result.Status == Status.Successful)
                    {
                        return(result);
                    }
                    //var oriTagList = tagBll.FindAll(3, entity.pageId).ToList();
                    //#region 删除标签索引
                    //tagBll.DeleteIndex(oriTagList);//删除标签索引
                    //#endregion
                    //this._ctx.ObjectEntityTags.DeleteAllOnSubmit(oriTagList);
                    ////添加标签
                    //if (tagList.Count() > 0)
                    //{
                    //    this._ctx.ObjectEntityTags.InsertAllOnSubmit(tagList);
                    //    this._ctx.SubmitChanges();

                    //}
                    #region 添加成果关联 2010.12.31更新
                    PageRefResultBll refRetBll = PageRefResultBll._(this._ctx);
                    var tempResult             = refRetBll.Insert(entity.Int("pageId"), retIds);
                    if (tempResult.Status != Status.Successful)
                    {
                        return(tempResult);
                    }
                    #endregion
                    scope.Complete();
                }
                result.Status  = Status.Successful;
                result.Message = "保存成功!";
                try
                {
                    var BookPage = pageBll.FindById(entity.Int("pageId"));
                    // pageBll.SubsribeUpdateObjInfo(curAvaiableEntity);//添加标签订阅相关;
                    //pageBll.BuildIndex(BookPage);//添加索引
                    // tagBll.BuildIndex(tagList);//添加标签索引
                    BookPageBll._().GenerateSnapshot(entity.Int("pageId"));
                }
                catch (Exception ex)
                {
                }
            }
            catch (Exception ex)
            {
                result.Status  = Status.Failed;
                result.Message = ex.Message;
            }
            return(result);
        }
Пример #3
0
        /// <summary>
        /// 保存任务书
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
        public InvokeResult Save(BsonDocument entity, int[] ids, int nodeType, int projNodeId, int engId)
        {
            if (entity == null)
            {
                throw new ArgumentNullException();
            }
            InvokeResult result     = new InvokeResult();
            var          needCreate = 0;
            var          needCopy   = 0;

            try
            {
                if (!CheckName(entity.Int("bookId"), entity.Int("type"), entity.Text("name"), nodeType, projNodeId))
                {
                    result.Status  = Status.Failed;
                    result.Message = "名称不能重复";
                    return(result);
                }
                List <BsonDocument> newBookPageList = new List <BsonDocument>();
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                {
                    if (entity.Int("bookId") == 0)
                    {
                        if (entity.Int("refBookId") == -1 || entity.Int("refBookId") == 0)
                        {
                            needCreate = 1;
                            this._ctx.Update(entity, string.Format("refBookId={0}", ""));
                        }
                        else
                        {
                            needCopy = 1;
                        }
                        result = this._ctx.Insert("BookTask", entity);
                        if (result.Status != Status.Successful)
                        {
                            return(result);
                        }

                        if (projNodeId != 0)
                        {
                            BsonDocument epsSummary = new BsonDocument();
                            epsSummary.Add("bookId", entity.Int("bookId"));
                            epsSummary.Add("nodeType", nodeType);

                            switch (nodeType)
                            {
                            case 0:
                            default:
                                epsSummary.Add("engId", projNodeId);
                                break;

                            case 1:
                            case 2:
                                epsSummary.Add("engId", engId);
                                epsSummary.Add("epsId", projNodeId);
                                break;

                            case 3:
                                epsSummary.Add("engId", engId);
                                epsSummary.Add("projId", projNodeId);
                                break;
                            }
                            result = this._ctx.Insert("EpsSummary", epsSummary);
                            if (result.Status != Status.Successful)
                            {
                                return(result);
                            }
                        }
                    }
                    else
                    {
                        var rootPage = entity.ChildBsonList("BookPage").Where(m => m.Int("nodePid") == 0).FirstOrDefault();
                        if (rootPage != null)
                        {
                            var rootPageUpdateBson = new BsonDocument();
                            rootPageUpdateBson.Add("name", entity.Text("name"));
                            this._ctx.Update(rootPage, rootPageUpdateBson);
                        }
                    }
                    var bookId      = entity.Int("bookId");
                    var delBsonList = this._ctx.FindAllByKeyVal("BookTaskPattern", "bookId", entity.Text("bookId")).ToList();
                    if (delBsonList.Count() > 0)
                    {
                        this._ctx.QuickDelete("BookTaskPattern", delBsonList);
                    }

                    if (ids.Count() > 0)
                    {
                        List <BsonDocument> bookTaskPatterns = new List <BsonDocument>();
                        foreach (var id in ids)
                        {
                            var newBsonDoc = new BsonDocument();
                            newBsonDoc.Add("bookId", bookId);
                            newBsonDoc.Add("patternId", id);
                            bookTaskPatterns.Add(newBsonDoc);
                        }
                        this._ctx.QuickInsert("BookTaskPattern", bookTaskPatterns);
                    }
                    #region 默认创建一个页面
                    if (needCreate == 1)
                    {
                        var bookPage = new BsonDocument();
                        bookPage.Add("name", entity.Text("name"));
                        bookPage.Add("IsPageTempate", entity.Text("name"));
                        bookPage.Add("lastVersion", 0);
                        bookPage.Add("categoryId", entity.Text("categoryId"));
                        List <BsonDocument> bookPageList = new List <BsonDocument>();
                        bookPageList.Add(bookPage);
                        List <int> temp = new List <int>();
                        BookPageBll._(this._ctx).Create(bookPageList, 0, entity.Int("bookId"), temp);
                    }
                    if (needCopy == 1)
                    {
                        var updateBookTaskBson = new BsonDocument();
                        var bookTask           = this._ctx.FindOneByKeyVal("BookTask", "bookId", entity.Text("refBookId"));
                        updateBookTaskBson.Add("refTime", bookTask.Int("refTime") + 1);
                        this._ctx.Update(bookTask, updateBookTaskBson);
                        var oldBookPageList = bookTask.ChildBsonList("BookPage").ToList();
                        CopyNode(newBookPageList, oldBookPageList, 0, null, entity);
                    }
                    #endregion
                    scope.Complete();
                    //#region 添加索引
                    //if (entity.type == 0)
                    //{
                    //    try
                    //    {
                    //        BuildIndex(entity);
                    //    }
                    //    catch (Exception ex)
                    //    { }
                    //}
                    //#endregion
                }

                //建设索引
                //foreach (var bookPage in newBookPageList)
                //    BookPageBll._(this._ctx).BuildIndex(bookPage);
                result.Status  = Status.Successful;
                result.Message = "保存成功!";
            }
            catch (Exception ex)
            {
                result.Status  = Status.Failed;
                result.Message = ex.Message;
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public InvokeResult Delete(int id)
        {
            InvokeResult result = new InvokeResult();

            result.Status = Status.Failed;
            BookPageBll bookPageBll = BookPageBll._(_ctx);

            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    #region 关联删除
                    var entity = this.FindById(id);
                    if (entity != null)
                    {
                        var bookPages = entity.ChildBsonList("BookPage").ToList();
                        foreach (var bookPage in bookPages)
                        {
                            if (bookPageBll.Delete(bookPage).Status != Status.Successful)
                            {
                                return(result);
                            }
                        }

                        if (entity.Int("type") == 0 && !string.IsNullOrEmpty(entity.Text("refBookId")))
                        {
                            var refBookTask = this.FindById(entity.Int("refBookId"));
                            if (refBookTask != null && refBookTask.Int("refTime") > 0)
                            {
                                var refBookTaskUpdateBosn = new BsonDocument();
                                refBookTaskUpdateBosn.Add("refTime", refBookTask.Int("refTime") - 1);
                                result = this._ctx.Update(refBookTask, refBookTaskUpdateBosn);
                                if (result.Status != Status.Successful)
                                {
                                    return(result);
                                }
                            }
                        }
                        //删除关联业态
                        var delBsonList = this._ctx.FindAllByKeyVal("BookTaskPattern", "bookId", entity.Text("bookId")).ToList();
                        if (delBsonList.Count() == 0)
                        {
                            delBsonList = this._ctx.FindAllByQuery("BookTaskPattern", MongoDB.Driver.Builders.Query.EQ("bookId", entity.Text("bookId"))).ToList();
                        }
                        if (delBsonList.Count() > 0)
                        {
                            result = this._ctx.QuickDelete("BookTaskPattern", delBsonList);
                            if (result.Status != Status.Successful)
                            {
                                return(result);
                            }
                        }

                        result = this._ctx.Delete("BookTask", "db.BookTask.distinct('_id',{'bookId':'" + id + "'})");
                    }
                    #endregion
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Status  = Status.Failed;
                result.Message = ex.Message;
            }

            return(result);
        }
Пример #5
0
        /// <summary>
        /// 保存任务书模板
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
        public InvokeResult Save(BsonDocument entity, BsonDocument updateEntityBson, int[] ids)
        {
            if (entity == null)
            {
                throw new ArgumentNullException();
            }
            InvokeResult result     = new InvokeResult();
            var          needCreate = 0;
            var          needCopy   = 0;

            try
            {
                if (!CheckTemplateName(entity.Int("bookId"), entity.Int("type"), string.IsNullOrEmpty(updateEntityBson.Text("name")) ? entity.Text("name") : updateEntityBson.Text("name"), entity.Int("categoryId")))
                {
                    result.Status = Status.Failed;
                    if (entity.Int("type") == 0)
                    {
                        result.Message = "任务书名称不能重复!";
                    }
                    else
                    {
                        result.Message = "任务书模板名称不能重复!";
                    }
                    return(result);
                }
                List <BsonDocument> newBookPageList = new List <BsonDocument>();
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 10, 0)))
                {
                    var entityUpdateBson = new BsonDocument();
                    if (entity.Int("bookId") == 0)
                    {
                        if (entity.Int("refBookId") == -1 || string.IsNullOrEmpty(entity.Text("refBookId")))
                        {
                            needCreate = 1;
                            entity.Add("refBookId", "");
                        }
                        else
                        {
                            needCopy = 1;
                        }
                        //entity.Add("type", "1");
                        result = this._ctx.Insert("BookTask", entity);
                        if (result.Status != Status.Successful)
                        {
                            return(result);
                        }
                        else
                        {
                            entity = result.BsonInfo;
                        }
                    }
                    else
                    {
                        var entityResult = this._ctx.Update(entity, updateEntityBson);
                        if (entityResult.Status != Status.Successful)
                        {
                            return(entityResult);
                        }
                        entity = entityResult.BsonInfo;
                        var rootPage = entity.ChildBsonList("BookPage").Where(m => m.Int("nodePid") == 0).FirstOrDefault();
                        if (rootPage != null)
                        {
                            var rootPageUpdateBson = new BsonDocument();
                            rootPageUpdateBson.Add("name", entity.Text("name"));
                            this._ctx.Update(rootPage, rootPageUpdateBson);
                        }
                    }
                    var bookId      = entity.Int("bookId");
                    var delBsonList = this._ctx.FindAll("BookTaskPattern").Where(x => x.Int("bookId") == entity.Int("bookId")).ToList();//.FindAllByKeyVal("BookTaskPattern", "bookId", entity.Text("bookId")).ToList();
                    if (delBsonList.Count() > 0)
                    {
                        this._ctx.QuickDelete("BookTaskPattern", delBsonList);
                    }
                    if (ids.Count() > 0)
                    {
                        List <BsonDocument> bookTaskPatterns = new List <BsonDocument>();
                        foreach (var id in ids)
                        {
                            var newBsonDoc = new BsonDocument();
                            newBsonDoc.Add("bookId", bookId);
                            newBsonDoc.Add("patternId", id);
                            bookTaskPatterns.Add(newBsonDoc);
                        }
                        this._ctx.QuickInsert("BookTaskPattern", bookTaskPatterns);
                    }
                    #region 默认创建一个页面
                    if (needCreate == 1)
                    {
                        var bookPage = new BsonDocument();
                        bookPage.Add("name", entity.Text("name"));
                        bookPage.Add("IsPageTempate", entity.Text("name"));
                        bookPage.Add("lastVersion", 0);
                        bookPage.Add("categoryId", entity.Text("categoryId"));
                        List <BsonDocument> bookPageList = new List <BsonDocument>();
                        bookPageList.Add(bookPage);
                        List <int> temp = new List <int>();
                        BookPageBll._(this._ctx).Create(bookPageList, 0, entity.Int("bookId"), temp);
                    }
                    if (needCopy == 1)
                    {
                        var updateBookTaskBson = new BsonDocument();
                        var bookTask           = this._ctx.FindOneByKeyVal("BookTask", "bookId", entity.Text("refBookId"));
                        updateBookTaskBson.Add("refTime", bookTask.Int("refTime") + 1);
                        this._ctx.Update(bookTask, updateBookTaskBson);
                        var oldBookPageList = bookTask.ChildBsonList("BookPage").ToList();
                        CopyNode(newBookPageList, oldBookPageList, 0, null, entity);
                    }
                    #endregion
                    scope.Complete();
                }
                if (entity.Int("type") == 0)
                {
                    try
                    {
                        //BuildIndex(entity);
                    }
                    catch (Exception ex)
                    { }
                }

                result.Status  = Status.Successful;
                result.Message = "保存成功!";
            }
            catch (Exception ex)
            {
                result.Status  = Status.Failed;
                result.Message = ex.Message;
            }
            return(result);
        }