public IHttpActionResult Finnish(ClosureWOCheckList entity)
        {
            entity.ProgressRate = 100;
            entity.Status       = (int)WOCheckListStatus.Finish;
            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);

            _db.TaskWork.Attach(task);
            _db.ClosureWOCheckList.Attach(entity);
            var result = _db.SaveChanges();

            return(Ok(result));
        }
Пример #2
0
        public IHttpActionResult PostExcutiveSummary(ClosureExecutiveSummary entity)
        {
            var task = TaskWork.FirstOrDefault(
                e => e.ReceiverAccount == ClientCookie.UserCode && e.Status == 0 && e.SourceCode == FlowCode.Closure &&
                e.TypeCode == FlowCode.Closure_ExecutiveSummary && e.RefID == entity.ProjectId);


            if (task != null)
            {
                task.Status     = TaskWorkStatus.K2ProcessApproved;
                task.Url        = SiteInfo.GetProjectViewPageUrl(FlowCode.Closure_ExecutiveSummary, task.RefID);
                task.FinishTime = DateTime.Now;
                var ProcInstID = entity.StartProcess(task);
                task.ProcInstID   = ProcInstID;
                entity.ProcInstID = ProcInstID;

                entity.Update();
                TaskWork.Update(task);

                ProjectInfo.FinishNode(entity.ProjectId, FlowCode.Closure_ExecutiveSummary, NodeCode.Closure_ExecutiveSummary_Input);
            }
            return(Ok());
        }
        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));
        }
Пример #4
0
        public IHttpActionResult Send(PostClosureMemoModel model)
        {
            var actor = ProjectUsers.GetProjectUser(model.Entity.ProjectId, ProjectUserRoleCode.AssetActor);

            using (TransactionScope tranScope = new TransactionScope())
            {
                Save(model.Entity);
                ClosureTool closureTool        = ClosureTool.FirstOrDefault(ct => ct.ProjectId == model.Entity.ProjectId);
                string      compensationAwards = "";
                string      compensation       = "暂无数据";
                if (closureTool != null && closureTool.Compensation.HasValue)
                {
                    compensationAwards = closureTool.Compensation.Value > 0 ? "Yes" : "No";
                    compensation       = closureTool.Compensation.Value.ToString("N");
                }
                Dictionary <string, string> pdfData = new Dictionary <string, string>();
                pdfData.Add("WorkflowName", "Closure");
                pdfData.Add("ProjectID", model.Entity.ProjectId);
                pdfData.Add("RegionNameENUS", model.Entity.RegionNameENUS);
                pdfData.Add("RegionNameZHCN", model.Entity.RegionNameZHCN);
                pdfData.Add("MarketNameENUS", model.Entity.MarketNameENUS);
                pdfData.Add("MarketNameZHCN", model.Entity.MarketNameZHCN);
                pdfData.Add("ProvinceNameENUS", model.Entity.ProvinceNameENUS);
                pdfData.Add("ProvinceNameZHCN", model.Entity.ProvinceNameZHCN);
                pdfData.Add("CityNameENUS", model.Entity.CityNameENUS);
                pdfData.Add("CityNameZHCN", model.Entity.CityNameZHCN);
                pdfData.Add("StoreNameENUS", model.Entity.StoreNameENUS);
                pdfData.Add("StoreNameZHCN", model.Entity.StoreNameZHCN);
                pdfData.Add("StoreAddressENUS", model.Entity.StoreAddressENUS);
                pdfData.Add("StoreAddressZHCN", model.Entity.StoreAddressZHCN);
                pdfData.Add("USCode", model.Entity.USCode);
                pdfData.Add("OpenDate", model.Entity.OpenDate.Value.ToString("yyyy-MM-dd"));
                pdfData.Add("ClosureDate", model.Entity.ClosureDate.Value.ToString("yyyy-MM-dd"));
                pdfData.Add("ClosureNature", model.Entity.ClosureNature.ToString());
                if (model.Entity.BecauseOfReimaging.HasValue)
                {
                    pdfData.Add("BecauseOfReimaging", model.Entity.BecauseOfReimaging.Value ? "Yes" : "No");
                }
                else
                {
                    pdfData.Add("BecauseOfReimaging", "");
                }

                if (model.Entity.BecauseOfRemodel.HasValue)
                {
                    pdfData.Add("BecauseOfRemodel", model.Entity.BecauseOfRemodel.Value ? "Yes" : "No");
                }
                else
                {
                    pdfData.Add("BecauseOfRemodel", "");
                }

                if (model.Entity.BecauseOfDespute.HasValue)
                {
                    pdfData.Add("BecauseOfDespute", model.Entity.BecauseOfDespute.Value ? "Yes" : "No");
                }
                else
                {
                    pdfData.Add("BecauseOfDespute", "");
                }

                if (model.Entity.BecauseOfRedevelopment.HasValue)
                {
                    pdfData.Add("BecauseOfRedevelopment", model.Entity.BecauseOfRedevelopment.Value ? "Yes" : "No");
                }
                else
                {
                    pdfData.Add("BecauseOfRedevelopment", "");
                }

                if (model.Entity.BecauseOfPlanedClosure.HasValue)
                {
                    pdfData.Add("BecauseOfPlanedClosure", model.Entity.BecauseOfPlanedClosure.Value ? "Yes" : "No");
                }
                else
                {
                    pdfData.Add("BecauseOfPlanedClosure", "");
                }

                if (model.Entity.BecauseOfRebuild.HasValue)
                {
                    pdfData.Add("BecauseOfRebuild", model.Entity.BecauseOfRebuild.Value ? "Yes" : "No");
                }
                else
                {
                    pdfData.Add("BecauseOfRebuild", "");
                }

                pdfData.Add("BecauseOfOthers", model.Entity.BecauseOfOthers);

                if (model.Entity.PermanentCloseOpportunity.HasValue)
                {
                    pdfData.Add("PermanentCloseOpportunity", model.Entity.PermanentCloseOpportunity.Value ? "Yes" : "No");
                }
                else
                {
                    pdfData.Add("PermanentCloseOpportunity", "");
                }

                if (model.Entity.HasRelocationPlan.HasValue)
                {
                    pdfData.Add("HasRelocationPlan", model.Entity.HasRelocationPlan.Value ? "Yes" : "No");
                }
                else
                {
                    pdfData.Add("HasRelocationPlan", "");
                }

                pdfData.Add("PipelineName", model.Entity.PipelineName);
                pdfData.Add("CompensationAwarded", compensationAwards);
                pdfData.Add("Compensation", compensation);
                string pdfPath = HtmlConversionUtility.HtmlConvertToPDF(HtmlTempalteType.ClosureMemo, pdfData, null);
                EmailSendingResultType result;
                //邮件模板中的数据
                Dictionary <string, string> bodyValues = new Dictionary <string, string>();
                //邮件内容中的键值对
                //bodyValues.Add("ApplicantName", ClientCookie.UserNameENUS);//--提交人
                bodyValues.Add("StoreCode", model.Entity.USCode);
                bodyValues.Add("StoreName", model.Entity.StoreNameENUS);
                bodyValues.Add("Actor", actor.RoleNameENUS);            ////--呈递人
                bodyValues.Add("WorkflowName", Constants.Closure_Memo); ////--流程名称
                bodyValues.Add("ProjectName", Constants.Closure);       //项目名称
                var webRootUrl = ConfigurationManager.AppSettings["webHost"];
                var viewPage   = string.Format("{0}Closure/Main#/ClosureMemo/ClosureMemoView?projectId={1}",
                                               webRootUrl, model.Entity.ProjectId);
                bodyValues.Add("FormUrl", viewPage);

                //调用邮件服务发送邮件
                using (EmailServiceClient client = new EmailServiceClient())
                {
                    EmailMessage  message = new EmailMessage();
                    StringBuilder sbTo    = new StringBuilder();
                    Dictionary <string, string> attachments = new Dictionary <string, string>();
                    foreach (Employee emp in model.Receivers)
                    {
                        if (sbTo.Length > 0)
                        {
                            sbTo.Append(";");
                        }
                        if (!string.IsNullOrEmpty(emp.Mail))
                        {
                            sbTo.Append(emp.Mail);
                        }
                    }
                    if (sbTo.Length > 0)
                    {
                        sbTo.Append(";");
                    }
                    message.EmailBodyValues = bodyValues;
                    attachments.Add(pdfPath, model.Entity.USCode + " " + FlowCode.Closure_Memo + ".pdf");
                    message.AttachmentsDict = attachments;
                    message.To           = sbTo.ToString();
                    message.TemplateCode = EmailTemplateCode.GBMemoNotification;
                    result = client.SendNotificationEmail(message);
                }

                if (!result.Successful)
                {
                    return(BadRequest(result.ErrorMessage + " " + pdfPath));
                }

                //store关闭不在这里设置,需要判断project状态和closuredata
                //var store = StoreBasicInfo.GetStorInfo(model.Entity.USCode);
                //store.StoreStatus = "suoya301003";
                //store.statusName = "Closed";
                //store.Update();


                if (model.Entity.ClosureNature == ClosureNatureType.Permanent)
                {
                    //选项为永久关闭并且发送成功后关闭任务
                    McdAMEntities _db  = new McdAMEntities();
                    var           task = _db.TaskWork.FirstOrDefault(e => e.ReceiverAccount == ClientCookie.UserCode && e.Status == 0 && e.SourceCode == FlowCode.Closure && e.TypeCode == FlowCode.Closure_Memo && e.RefID == model.Entity.ProjectId);
                    if (task != null)
                    {
                        task.Status     = TaskWorkStatus.K2ProcessApproved;
                        task.FinishTime = DateTime.Now;
                        task.Url        = SiteInfo.GetProjectViewPageUrl(FlowCode.Closure_Memo, task.RefID);

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

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

                        ProjectInfo.FinishNode(model.Entity.ProjectId, FlowCode.Closure_Memo, NodeCode.Closure_ClosureMemo_Input);
                        ProjectInfo.FinishNode(model.Entity.ProjectId, FlowCode.Closure_Memo, NodeCode.Closure_ClosureMemo_SendMemo, ProjectStatus.Finished);

                        #region Memo完成后,设定计划任务
                        var closureConsInvtChecking = new ClosureConsInvtChecking();
                        closureConsInvtChecking.GenerateConsInvtCheckingTask(model.Entity.ProjectId);

                        if (model.Entity.ClosureDate.HasValue)
                        {
                            ScheduleLog.UpdateStoreStatusSchedule(model.Entity.USCode, model.Entity.ProjectId, model.Entity.ClosureDate.Value, ClientCookie.UserCode);
                        }
                        #endregion
                    }
                    ProjectInfo.CompleteMainIfEnable(model.Entity.ProjectId);
                }
                tranScope.Complete();
                return(Ok());
            }
        }
Пример #5
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));
        }