public void BuildSubProjectWBS(S_W_WBS parentWBS, List <Dictionary <string, object> > subProjectList, List <Dictionary <string, object> > majorList) { foreach (var subProject in subProjectList) { //子项 var sCode = subProject.GetValue("Code").ToString(); S_W_WBS subprojectwbs = parentWBS.AllChildren.FirstOrDefault(c => c.Code == sCode); if (subprojectwbs == null) { #region 新增 subprojectwbs = new S_W_WBS { WBSType = WBSNodeType.SubProject.ToString(), Code = subProject.GetValue("Code").ToString(), Name = subProject.GetValue("Name").ToString(), ChargeUserID = subProject.GetValue("ChargeUserID").ToString(), ChargeUserName = subProject.GetValue("ChargeUserName").ToString() }; if (!string.IsNullOrEmpty(subProject.GetValue("PlanStartDate"))) { subprojectwbs.PlanStartDate = Convert.ToDateTime(subProject.GetValue("PlanStartDate")); } if (!string.IsNullOrEmpty(subProject.GetValue("PlanEndDate"))) { subprojectwbs.PlanEndDate = Convert.ToDateTime(subProject.GetValue("PlanEndDate")); } parentWBS.AddChild(subprojectwbs); #endregion } else { subprojectwbs.Name = subProject.GetValue("Name").ToString(); if (!String.IsNullOrEmpty(subProject.GetValue("ChargeUserID"))) { subprojectwbs.ChargeUserID = subProject.GetValue("ChargeUserID"); subprojectwbs.ChargeUserName = subProject.GetValue("ChargeUserName"); } if (!string.IsNullOrEmpty(subProject.GetValue("PlanStartDate"))) { subprojectwbs.PlanStartDate = Convert.ToDateTime(subProject.GetValue("PlanStartDate")); } if (!string.IsNullOrEmpty(subProject.GetValue("PlanEndDate"))) { subprojectwbs.PlanEndDate = Convert.ToDateTime(subProject.GetValue("PlanEndDate")); } } BuildMajorWBS(subprojectwbs, majorList); } }
/// <summary> /// 根据专业同步WBS /// </summary> /// <param name="parentNode"></param> public void SynchMajorWBSNode(List <S_D_RoleDefine> roleDefineList, S_W_WBS parentNode, string rbsList = "") { var projectEntities = FormulaHelper.GetEntities <ProjectEntities>(); if (parentNode == null) { throw new Formula.Exceptions.BusinessException("传入的WBS节点为空。"); } var majorList = ""; if (!string.IsNullOrEmpty(rbsList)) { majorList = rbsList; } else { majorList = this.MajorList; } #region 除不需要的专业 //sll edit 2018-8-8 //改前var delMajors = parentNode.Children.Where(d => !this.Major.Contains(d.WBSValue)).ToList(); var delMajors = parentNode.Children.Where(d => !this.Major.Contains(d.WBSValue) && d.WBSType == WBSNodeType.Major.ToString()).ToList(); foreach (var item in delMajors) { item.Delete(); parentNode.Children.Remove(item); } #endregion if (!string.IsNullOrEmpty(majorList)) { var majorNodes = JsonHelper.ToList(majorList); var majorAttrList = BaseConfigFO.GetWBSAttrList(WBSNodeType.Major); var majorWBSType = WBSNodeType.Major.ToString(); foreach (var majorNode in majorNodes) { if (majorNode.GetValue("Valid") == "0") { var thisMajorValue = majorNode.GetValue("MajorCode"); var thisMajorNode = parentNode.Children.SingleOrDefault(c => c.WBSValue == thisMajorValue); if (thisMajorNode != null) { thisMajorNode.Delete(); } continue; } var value = majorNode.GetValue("MajorCode"); var majorAttr = majorAttrList.SingleOrDefault(c => c.Code == value); if (majorAttr == null) { continue; } var childNode = parentNode.Children.SingleOrDefault(c => c.WBSValue == value); if (!this.Major.Split(',').Contains(value)) { if (childNode != null) { childNode.Delete(); } continue; } if (childNode == null) { childNode = projectEntities.Set <S_W_WBS>().Create(); if (string.IsNullOrEmpty(childNode.ID)) { childNode.ID = FormulaHelper.CreateGuid(); } childNode._state = EntityState.Added.ToString(); childNode.WBSType = majorWBSType; childNode.Name = majorAttr.Name; childNode.WBSValue = majorAttr.Code; childNode.MajorCode = majorAttr.Code; childNode.Code = majorAttr.WBSCode; } childNode.SortIndex = majorAttr.SortIndex; childNode.ChargeUserID = majorNode.GetValue("MajorPrinciple"); childNode.ChargeUserName = majorNode.GetValue("MajorPrincipleName"); if (childNode._state == EntityState.Added.ToString()) { parentNode.AddChild(childNode); } #region 步设校审人员信息 var roleList = roleDefineList.Where(a => majorNode.ContainsKey(a.RoleCode) && !string.IsNullOrEmpty(majorNode.GetValue(a.RoleCode))); foreach (var roleDef in roleList) { childNode.SetUsers(roleDef.RoleCode, majorNode.GetValue(roleDef.RoleCode).Split(','), true, false, true, true); } #endregion } } }
/// <summary> /// 根据阶段、子项信息、专业信息同步WBS节点 /// </summary> public void SynchWBSNode(Dictionary <string, string> dic, S_W_WBS rootWBS = null) { var enumService = FormulaHelper.GetService <IEnumService>(); var userInfo = FormulaHelper.GetUserInfo(); var projectEntities = FormulaHelper.GetEntities <ProjectEntities>(); var projectInfo = projectEntities.Set <S_I_ProjectInfo>().Find(this.ProjectInfoID); if (projectInfo == null) { throw new Formula.Exceptions.BusinessException("根据当前项目策划单,未找到对应的项目信息"); } if (rootWBS == null) { //获取项目信息 rootWBS = projectInfo.WBSRoot; if (rootWBS == null) { throw new Formula.Exceptions.BusinessException("未获取到当前项目的WBS根节点。"); } } var detailList = this.T_SC_SchemeForm_OEM_Szsow_SubProjectList.OrderBy(d => d.SortIndex).ToList(); var roleDefineList = BaseConfigFO.GetRoleDefineList(); var phaseWBSes = rootWBS.Children.ToList(); var phaseAttrs = BaseConfigFO.GetWBSAttrList(WBSNodeType.Phase); foreach (var phaseValue in projectInfo.PhaseValue.Split(',')) { #region 阶段节点 var phaseName = enumService.GetEnumText("Project.Phase", phaseValue); var attr = phaseAttrs.FirstOrDefault(a => a.Code == phaseValue); if (attr == null) { throw new Formula.Exceptions.BusinessException("未定义阶段【" + phaseValue + "】" + phaseName + ",操作失败"); } var phaseWBSNode = phaseWBSes.FirstOrDefault(d => d.WBSValue == phaseValue && d.WBSType == WBSNodeType.Phase.ToString()); if (phaseWBSNode == null) { phaseWBSNode = new S_W_WBS(); phaseWBSNode.ID = FormulaHelper.CreateGuid(); phaseWBSNode.WBSType = WBSNodeType.Phase.ToString(); phaseWBSNode.Name = phaseName; phaseWBSNode.Code = attr.WBSCode; phaseWBSNode.WBSValue = attr.Code; rootWBS.AddChild(phaseWBSNode); } else { phaseWBSNode.Name = phaseName; phaseWBSNode.Code = attr.WBSCode; phaseWBSNode.WBSValue = attr.Code; phaseWBSNode.Save(); phaseWBSes.Remove(phaseWBSNode); } #endregion #region 子项节点 var subwbses = phaseWBSNode.Children.ToList(); foreach (var subProject in detailList.Where(a => a.PhaseValue.Split(',').Contains(phaseValue)).ToList()) { var subWBSNode = subwbses.FirstOrDefault(d => d.WBSValue == subProject.Code && d.WBSType == WBSNodeType.SubProject.ToString()); if (subWBSNode == null) { subWBSNode = new S_W_WBS(); subWBSNode.ID = FormulaHelper.CreateGuid(); subWBSNode.WBSType = WBSNodeType.SubProject.ToString(); subWBSNode.Name = subProject.Name; subWBSNode.Code = ""; subWBSNode.WBSValue = subProject.Code; subWBSNode.ExtField1 = subProject.Area.HasValue ? subProject.Area.ToString() : ""; subWBSNode.ExtField2 = subProject.Unit; phaseWBSNode.AddChild(subWBSNode); } else { subWBSNode.Name = subProject.Name; subWBSNode.WBSValue = subProject.Code; subWBSNode.ExtField1 = subProject.Area.HasValue ? subProject.Area.ToString() : ""; subWBSNode.ExtField2 = subProject.Unit; subWBSNode.Save(); subwbses.Remove(subWBSNode); } subProject.PhaseWBSID = phaseWBSNode.ID; #region 新增单体 var wonomerList = subWBSNode.S_W_Monomer.ToList(); if (String.IsNullOrEmpty(subProject.Unit)) { var wonomer = wonomerList.FirstOrDefault(d => d.Name == subProject.Name); if (wonomer == null) { wonomer = new S_W_Monomer(); wonomer.ID = FormulaHelper.CreateGuid(); wonomer.Name = subProject.Name; wonomer.ProjectInfoID = this.ProjectInfoID; wonomer.Code = ""; wonomer.CreateDate = DateTime.Now; wonomer.CreateUser = userInfo.UserName; wonomer.CreateUserID = userInfo.UserID; wonomer.SchemeFormSubID = this.ID; subWBSNode.S_W_Monomer.Add(wonomer); } } else if (!string.IsNullOrEmpty(subProject.Name)) { foreach (var item in subProject.Unit.Replace(",", ",").Split(',')) { var wonomer = subWBSNode.S_W_Monomer.FirstOrDefault(d => d.Name == item); if (wonomer == null) { wonomer = new S_W_Monomer(); wonomer.ID = FormulaHelper.CreateGuid(); wonomer.Name = item; wonomer.ProjectInfoID = this.ProjectInfoID; wonomer.Code = ""; wonomer.CreateDate = DateTime.Now; wonomer.CreateUser = userInfo.UserName; wonomer.CreateUserID = userInfo.UserID; wonomer.SchemeFormSubID = this.ID; subWBSNode.S_W_Monomer.Add(wonomer); } else { wonomerList.Remove(wonomer); } } } foreach (var delWonomer in wonomerList) //移除不需要的单体 { projectEntities.S_W_Monomer.Remove(delWonomer); } #endregion //增加名称判断逻辑 if (string.IsNullOrEmpty(subProject.Name)) { //将空名子项的专业挂到阶段下 SynchMajorWBSNode(roleDefineList, subWBSNode.Parent, subProject.RBSJson); //删除空名子项 subWBSNode.Delete(); //排除在阶段下的专业 var rbsDicList = JsonHelper.ToList(subProject.RBSJson ?? MajorList); subwbses.RemoveAll(a => rbsDicList.Any(b => a.WBSValue == b.GetValue("MajorCode"))); } else { subProject.SubProjectWBSID = subWBSNode.ID; SynchMajorWBSNode(roleDefineList, subWBSNode, subProject.RBSJson); } //this.InitMileStone(subWBSNode); } #endregion //删除阶段节点下多余的子项和专业 subwbses.ForEach(t => { if (t.WBSType == WBSNodeType.Major.ToString()) { //删除阶段下层专业时,同时删除挂在阶段下的专业计划、发图计划 projectEntities.Set <S_P_MileStone>().Delete(d => d.WBSID == phaseWBSNode.ID && d.MajorValue == t.WBSValue); } t.Delete(); }); } phaseWBSes.ForEach(t => t.Delete()); //删除多余的阶段 this.SubProjectList = JsonHelper.ToJson <List <T_SC_SchemeForm_OEM_Szsow_SubProjectList> >(detailList); }
/// <summary> /// 根据子项和专业列表同步WBS表 /// </summary> public void SynchSubProjectWBSNode(Dictionary <string, string> dic, S_W_WBS rootWBS = null) { var userInfo = FormulaHelper.GetUserInfo(); var projectEntities = FormulaHelper.GetEntities <ProjectEntities>(); var projectInfo = projectEntities.Set <S_I_ProjectInfo>().Find(this.ProjectInfoID); if (projectInfo == null) { throw new Formula.Exceptions.BusinessException("根据当前项目策划单,未找到对应的项目信息"); } if (rootWBS == null) { //获取项目信息 rootWBS = projectInfo.WBSRoot; if (rootWBS == null) { throw new Formula.Exceptions.BusinessException("未获取到当前项目的WBS根节点。"); } } var roleDefineList = BaseConfigFO.GetRoleDefineList(); var enumSubProject = WBSNodeType.SubProject.ToString(); var subwbses = rootWBS.Children.ToList(); if (this.T_SC_MixProjectScheme_SubProjectList.ToList().Count == 0) { SynchMajorWBSNode(roleDefineList, rootWBS, ""); subwbses.RemoveWhere(a => a.WBSType == WBSNodeType.Major.ToString()); } foreach (var subProject in this.T_SC_MixProjectScheme_SubProjectList.OrderBy(d => d.SortIndex).ToList()) { var subWBSNode = subwbses.FirstOrDefault(d => d.WBSValue == subProject.Code && d.WBSType == WBSNodeType.SubProject.ToString()); if (subWBSNode == null) { subWBSNode = new S_W_WBS(); subWBSNode.ID = FormulaHelper.CreateGuid(); subWBSNode.WBSType = WBSNodeType.SubProject.ToString(); subWBSNode.Name = subProject.Name; subWBSNode.Code = ""; subWBSNode.WBSValue = subProject.Code; subWBSNode.PhaseCode = subProject.PhaseValue; subWBSNode.ExtField1 = subProject.Area.HasValue ? subProject.Area.ToString() : ""; subWBSNode.ExtField2 = subProject.Unit; rootWBS.AddChild(subWBSNode); } else { subWBSNode.Name = subProject.Name; subWBSNode.PhaseCode = subProject.PhaseValue; subWBSNode.ExtField1 = subProject.Area.HasValue ? subProject.Area.ToString() : ""; subWBSNode.ExtField2 = subProject.Unit; subWBSNode.Save(); subwbses.Remove(subWBSNode); } #region 新增单体 var wonomerList = subWBSNode.S_W_Monomer.ToList(); if (String.IsNullOrEmpty(subProject.Unit)) { var wonomer = wonomerList.FirstOrDefault(d => d.Name == subProject.Name); if (wonomer == null) { wonomer = new S_W_Monomer(); wonomer.ID = FormulaHelper.CreateGuid(); wonomer.Name = subProject.Name; wonomer.ProjectInfoID = this.ProjectInfoID; wonomer.Code = ""; wonomer.CreateDate = DateTime.Now; wonomer.CreateUser = userInfo.UserName; wonomer.CreateUserID = userInfo.UserID; wonomer.SchemeFormSubID = this.ID; subWBSNode.S_W_Monomer.Add(wonomer); } } else { foreach (var item in subProject.Unit.Replace(",", ",").Split(',')) { var wonomer = subWBSNode.S_W_Monomer.FirstOrDefault(d => d.Name == item); if (wonomer == null) { wonomer = new S_W_Monomer(); wonomer.ID = FormulaHelper.CreateGuid(); wonomer.Name = item; wonomer.ProjectInfoID = this.ProjectInfoID; wonomer.Code = ""; wonomer.CreateDate = DateTime.Now; wonomer.CreateUser = userInfo.UserName; wonomer.CreateUserID = userInfo.UserID; wonomer.SchemeFormSubID = this.ID; subWBSNode.S_W_Monomer.Add(wonomer); } else { wonomerList.Remove(wonomer); } } } foreach (var delWonomer in wonomerList) //移除不需要的单体 { projectEntities.S_W_Monomer.Remove(delWonomer); } #endregion SynchMajorWBSNode(roleDefineList, subWBSNode, subProject.RBSJson); //this.InitMileStone(subWBSNode); } subwbses.ForEach(t => t.Delete()); //删除多余的子项 }
public void BuildMajorWBS(S_W_WBS majorParentWBS, List <Dictionary <string, object> > majorList) { if (majorList == null || majorList.Count <= 0) { return; } var majorEnum = BaseConfigFO.GetWBSEnum(WBSNodeType.Major) .AsEnumerable() .Select(c => new DicItem { Text = c["text"].ToString(), Value = c["value"].ToString() }).ToList(); var majorAttrList = BaseConfigFO.GetWBSAttrList(WBSNodeType.Major.ToString()); foreach (var major in majorList) { var mCode = major.GetValue("Major").ToString(); S_W_WBS majorwbs = majorParentWBS.AllChildren.FirstOrDefault(c => c.WBSValue == mCode); if (majorwbs == null) { #region 新增 majorwbs = new S_W_WBS { WBSType = WBSNodeType.Major.ToString(), Name = majorEnum.FirstOrDefault(c => c.Value == mCode).Text, WBSValue = mCode //Code = mCode, }; var attrDefine = majorAttrList.FirstOrDefault(d => d.Code == majorwbs.WBSValue); if (attrDefine != null) { majorwbs.SortIndex = attrDefine.SortIndex; } majorParentWBS.AddChild(majorwbs); #endregion } else { majorwbs.Name = majorEnum.FirstOrDefault(c => c.Value == mCode).Text; var attrDefine = majorAttrList.FirstOrDefault(d => d.Code == majorwbs.WBSValue); if (attrDefine != null) { majorwbs.SortIndex = attrDefine.SortIndex; } } if (!String.IsNullOrEmpty(major.GetValue("MajorPrincipleID"))) { majorwbs.SetUsers(ProjectRole.MajorPrinciple.ToString(), major.GetValue("MajorPrincipleID").ToString().Split(',')); } if (!String.IsNullOrEmpty(major.GetValue("DesignID"))) { majorwbs.SetUsers(ProjectRole.Designer.ToString(), major.GetValue("DesignID").Split(',')); } if (!String.IsNullOrEmpty(major.GetValue("CollactorID"))) { majorwbs.SetUsers(ProjectRole.Collactor.ToString(), major.GetValue("CollactorID").Split(',')); } if (!String.IsNullOrEmpty(major.GetValue("AuditorID"))) { majorwbs.SetUsers(ProjectRole.Auditor.ToString(), major.GetValue("AuditorID").Split(',')); } if (!String.IsNullOrEmpty(major.GetValue("CheckID"))) { majorwbs.SetUsers(ProjectRole.Approver.ToString(), major.GetValue("CheckID").Split(',')); } } }