public IHttpActionResult PostClosureWOCheckList(ClosureWOCheckList entity)
        {
            string _debugInfo = string.Format("[Ln 571] Start Run PostClosureWOCheckList - Entity: {0}", JsonConvert.SerializeObject(entity));

            Log4netHelper.WriteInfoLog(_debugInfo, this.GetType(), "PostClosureWOCheckList");

            //ClosureInfo closure = new ClosureInfo();
            //closure = closure.GetByProjectId(entity.ProjectId.Value);

            var task = _db.TaskWork.First(
                e => e.ReceiverAccount == ClientCookie.UserCode && e.Status == 0 && e.SourceCode == FlowCode.Closure &&
                e.TypeCode == FlowCode.Closure_WOCheckList && e.RefID == entity.ProjectId
                );

            task.Status       = TaskWorkStatus.Finished;
            task.FinishTime   = DateTime.Now;
            task.Url          = SiteInfo.GetProjectViewPageUrl(FlowCode.Closure_WOCheckList, task.RefID);
            task.RefTableName = ClosureWOCheckList.TableName;
            task.RefTableId   = entity.Id;

            _db.TaskWork.Attach(task);
            _db.Entry(task).State = EntityState.Modified;

            int result = _db.SaveChanges();

            _debugInfo = string.Format("[Ln 611] Task:{0}", TaskWork.ConvertToJson(task));
            //DateTime.Parse()
            Log4netHelper.WriteInfoLog(_debugInfo, this.GetType(), "PostClosureWOCheckList");

            if (result > 0)
            {
                // Start K2 Process
                var _procCode       = WFClosureWOCheckList.ProcessCode;
                var _listDataFields = new List <ProcessDataField>();

                _listDataFields.Add(new ProcessDataField("dest_Creator", ClientCookie.UserCode));
                _listDataFields.Add(new ProcessDataField("dest_PMSupervisor", entity.PMSupervisorAccount));                                                                                    // 工程PM直属上级
                _listDataFields.Add(new ProcessDataField("dest_MCCLApprovers", string.Join(";", entity.MCCLApproverAccount, entity.MCCLITApproverAccount, entity.MCCLMCCLEqApproverAccount))); // MCCL Approvers
                _listDataFields.Add(new ProcessDataField("ProcessCode", _procCode));
                //_listDataFields.Add(new ProcessDataField("dest_Receiver", "")); 知会人

                //将WOCheckList的任务传给K2
                var taskJson = Newtonsoft.Json.JsonConvert.SerializeObject(task);
                _listDataFields.Add(new ProcessDataField("ProjectTaskInfo", taskJson));

                _debugInfo = string.Format("[Ln 630] DataFields: {0}", JsonConvert.SerializeObject(_listDataFields));
                Log4netHelper.WriteInfoLog(_debugInfo, this.GetType(), "PostClosureWOCheckList");

                var _procInstID = K2FxContext.Current.StartProcess(_procCode, ClientCookie.UserCode, _listDataFields);


                _debugInfo = string.Format("[Ln 637] ProcInstID: {0}", _procInstID);
                Log4netHelper.WriteInfoLog(_debugInfo, this.GetType(), "PostClosureWOCheckList");

                if (_procInstID > 0)
                {
                    // 更新 WOCheckList表的ProcInstId
                    entity.ProcInstID = _procInstID;
                    if (entity.Id == Guid.Empty)
                    {
                        entity.Id                = Guid.NewGuid();
                        entity.CreateTime        = DateTime.Now;
                        entity.CreateUserAccount = ClientCookie.UserCode;
                    }
                    entity.Save();

                    _db.Entry(entity).State = EntityState.Modified;
                    SaveCommers(entity, ProjectCommentAction.Submit, ProjectCommentStatus.Submit);

                    result = _db.SaveChanges();
                }
                ProjectInfo.FinishNode(entity.ProjectId, FlowCode.Closure_WOCheckList,
                                       NodeCode.Closure_WOCheckList_ClosingCost);
            }

            return(Ok(result));
        }
示例#2
0
        public IHttpActionResult PostClosureLegalReview(ClosureLegalReview entity)
        {
            var task = _db.TaskWork.First(
                e => e.ReceiverAccount == ClientCookie.UserCode && e.Status == 0 && e.SourceCode == FlowCode.Closure &&
                e.TypeCode == FlowCode.Closure_LegalReview && e.RefID == entity.ProjectId
                );

            task.Status     = TaskWorkStatus.Finished;
            task.FinishTime = DateTime.Now;
            task.Url        = SiteInfo.GetProjectViewPageUrl(FlowCode.Closure_LegalReview, task.RefID);

            //var enableExecutiveSummary = handler.EnableExecutiveSummary(entity.ProjectId.Value);

            _db.TaskWork.Attach(task);
            _db.Entry(task).State = EntityState.Modified;

            var entityInfo = ClosureLegalReview.Get(entity.ProjectId);

            //GUID通过页面JS生成需要判断否存在


            if (entityInfo == null)
            {
                //entity = new ClosureLegalReview();
                entity.CreateTime        = DateTime.Now;
                entity.CreateUserAccount = ClientCookie.UserCode;
                entity.Id        = Guid.NewGuid();
                entity.IsHistory = false;
                _db.ClosureLegalReview.Add(entity);
                //}
            }
            else
            {
                try
                {
                    //entityInfo.LegalCommers = entity.Comments;
                    _db.ClosureLegalReview.Attach(entityInfo);
                    _db.Entry(entityInfo).State = EntityState.Modified;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            //bllActionLog.Add(new ActionLog
            //{
            //    Id = Guid.NewGuid(),
            //    ProjectId = entity.ProjectId,
            //    Action = ActionType.Submit,
            //    CreateTime = DateTime.Now,
            //    Operator = entity.CreateUserAccount,
            //    OperatorENUS = entity.UserNameENUS,
            //    OperatorZHCN = entity.UserNameZHCN,
            //    Remark = "提交LegalReview流程",
            //    OperatorTitle = "提交LegalReview流程"
            //});


            var result = _db.SaveChanges();

            if (result > 0)
            {
                // Start K2 Process
                string _procCode = WFClosureLegalReview.ProcessCode;
                List <ProcessDataField> _listDataFields = new List <ProcessDataField>();

                _listDataFields.Add(new ProcessDataField("dest_Creator", ClientCookie.UserCode)); // 发起人

                var closureInfo = ClosureInfo.GetByProjectId(entity.ProjectId);


                //string legalAccount = userPositionHandler.GetAccounts(entity.ProjectId.Value,
                //   UserPositionHandler.LegalCounselCode );

                string legalAccount = entity.LegalAccount;

                _listDataFields.Add(new ProcessDataField("dest_Legal", legalAccount));//entity.   Legal

                _listDataFields.Add(new ProcessDataField("ProcessCode", _procCode));
                //_listDataFields.Add(new ProcessDataField("dest_Receiver", "")); 知会人

                if (_listDataFields.Exists(o => string.IsNullOrEmpty(o.DataFieldValue)))
                {
                    result = 0;
                }
                else
                {
                    //将TaskWork生成任务传给K2
                    var taskJson = TaskWork.ConvertToJson(task);
                    _listDataFields.Add(new ProcessDataField("ProjectTaskInfo", taskJson));

                    var _debugInfo = string.Format("[Ln 326] DataFields: {0}", JsonConvert.SerializeObject(_listDataFields));
                    Log4netHelper.WriteInfoLog(_debugInfo, this.GetType(), "PostClosureLegalReview");

                    int _procInstID = 0;

                    try
                    {
                        _procInstID = K2FxContext.Current.StartProcess(_procCode, ClientCookie.UserCode, _listDataFields);
                    }
                    catch (Exception ex)
                    {
                        _debugInfo = string.Format("[Ln 339] Result: {0}", ex.Message);
                        Log4netHelper.Log4netWriteErrorLog(_debugInfo, ex);
                        Log4netHelper.WriteErrorLog(_debugInfo);
                        Log4netHelper.WriteInfoLog(_debugInfo);
                        throw ex;
                    }

                    _debugInfo = string.Format("[Ln 345] Result: {0}", _procInstID);
                    Log4netHelper.WriteInfoLog(_debugInfo, this.GetType(), "PostClosureLegalReview");



                    if (_procInstID > 0)
                    {
                        if (entityInfo == null)
                        {
                            _db.ClosureLegalReview.Attach(entity);
                            _db.Entry(entity).State = EntityState.Modified;
                        }
                        else
                        {
                            entity.Id             = entityInfo.Id;
                            entityInfo.ProcInstID = _procInstID;
                            _db.ClosureLegalReview.Attach(entityInfo);
                            _db.Entry(entityInfo).State = EntityState.Modified;
                        }

                        entity.ProcInstID = _procInstID;
                        SaveCommers(entity, ProjectCommentAction.Submit, ProjectCommentStatus.Submit);
                        result = _db.SaveChanges();
                    }
                }
            }

            ProjectInfo.FinishNode(entity.ProjectId, FlowCode.Closure_LegalReview,
                                   NodeCode.Closure_LegalReview_Input);

            return(Ok(result));
        }