public List <DictionaryVmodel> UpdateProMonthReportDetail(string rpts, string strMonthReportOrderType, string info, bool IncludeHaveDetail, string strMonthReportID) { List <DictionaryVmodel> ListObj = new List <DictionaryVmodel>(); //首先拿到数据 ReportInstance rpt = JsonHelper.Deserialize <ReportInstance>(rpts); //在难道需要编辑的数据 V_ProjectCompany ProDetail = JsonHelper.Deserialize <V_ProjectCompany>(info); //循环指标 foreach (V_ProjectTarget item in ProDetail.ProjectTargets) { //获取修改的实体 B_MonthlyReportDetail B_detail = B_MonthlyreportdetailOperator.Instance.GetMonthlyreportdetail(item.ProMonthlyReportDetailID); if (B_detail != null) { B_detail.NActualAmmount = item.NActualAmmount; //当月实际值 B_detail.NAccumulativeActualAmmount = item.NAccumulativeActualAmmount; //当月实际累计值 } //重新计算 B_MonthlyReportDetail UpdateData = CalculationEvaluationEngine.CalculationEvaluationService.Calculation(B_detail, ""); //修改数据 B_MonthlyreportdetailOperator.Instance.UpdateMonthlyreportdetail(UpdateData); rpt.ReportDetails.Remove(rpt.ReportDetails.Find(p => p.ID == B_detail.ID)); rpt.ReportDetails.Add(B_detail.ToVModel()); } ListObj.Add(new DictionaryVmodel("ReportInstance", rpt)); ListObj.Add(new DictionaryVmodel("MonthDetail", GetTargetDetailList(rpt, strMonthReportOrderType, IncludeHaveDetail))); ListObj.Add(new DictionaryVmodel("Misstarget", GetMissTargetList(rpt, strMonthReportID, true))); ListObj.Add(new DictionaryVmodel("MonthReportDescription", GetMonthTRptDescription(rpt))); ListObj.Add(new DictionaryVmodel("CurrentMissTargetList", GetCurrentMissTargetList(rpt, strMonthReportID.ToString(), true))); SaveJsonData(strMonthReportID.ToGuid(), rpt, ListObj); return(ListObj); }
/// <summary> /// 获取总计的数据(第二步) /// </summary> /// <param name="ProList"></param> /// <returns></returns> private List <V_ProjectCompany> GetProjectModel(List <V_ProjectCompany> ProList, ProjectCounter ProCounter) { //项目公司 List <V_ProjectCompany> ProCompanyList = new List <V_ProjectCompany>(); //项目公司指标 List <V_ProjectTarget> _ProTargetLists = new List <V_ProjectTarget>(); List <V_ProjectTarget> ProTargetListSum = new List <V_ProjectTarget>(); //把所有区域的指标拿出来 ProList.ForEach(p => ProTargetListSum.AddRange(p.ProjectTargets)); /* * 这里的总计需要注意:因每个区域系统都是独立的指标,所以只能按照指标名称来比对 * 所以在各个区域系统的指标名称一定要一样,不然无法统计 */ #region 总计的指标总和 List <C_Target> _TargetList = StaticResource.Instance.TargetList[_SystemID].ToList(); foreach (C_Target itemTarget in _TargetList.OrderBy(g => g.Sequence)) { V_ProjectTarget VModel = new V_ProjectTarget(); //从明细表中获取数据 MonthlyReportDetail tempModel = new MonthlyReportDetail(); VModel.ProMonthlyReportDetailID = Guid.Empty; VModel.ProTargetID = itemTarget.ID; VModel.ProTargetName = itemTarget.TargetName; VModel.ProTargetSequence = itemTarget.Sequence; VModel.ProCompayID = Guid.Empty; VModel.IsMissTarget = false; VModel.IsMissTargetCurrent = false; VModel.Counter = 0; //总计: 当月数据字段 VModel.NPlanAmmount = ProTargetListSum.FindAll(f => f.ProTargetName == itemTarget.TargetName).Sum(s => s.NPlanAmmount); //总计:当月计划数 ,从区域小计上获取 VModel.NActualAmmount = ProTargetListSum.FindAll(f => f.ProTargetName == itemTarget.TargetName).Sum(s => s.NActualAmmount); //总计:当月实际数 ,从区域小计上获取 if (VModel.NPlanAmmount == 0) { VModel.NActualRate = ""; VModel.NDisplayRate = "/"; } else { VModel.NActualRate = ""; VModel.NDisplayRate = Math.Round((VModel.NActualAmmount / VModel.NPlanAmmount), 5, MidpointRounding.AwayFromZero).ToString("P1");; } //总计:当月累计计划数 VModel.NAccumulativePlanAmmount = ProTargetListSum.FindAll(f => f.ProTargetName == itemTarget.TargetName).Sum(s => s.NAccumulativePlanAmmount); // ?累计的指标怎么算? VModel.NAccumulativeActualAmmount = ProTargetListSum.FindAll(f => f.ProTargetName == itemTarget.TargetName).Sum(s => s.NAccumulativeActualAmmount); if (VModel.NAccumulativePlanAmmount == 0) { VModel.NAccumulativeActualRate = ""; VModel.NAccumulativeDisplayRate = "/"; } else { VModel.NAccumulativeActualRate = ""; VModel.NAccumulativeDisplayRate = Math.Round((VModel.NAccumulativeActualAmmount / VModel.NAccumulativePlanAmmount), 5, MidpointRounding.AwayFromZero).ToString("P1");; } //总计:年度计划值 VModel.NActualAmmountByYear = 0; VModel.NPlanAmmountByYear = ProTargetListSum.FindAll(f => f.ProTargetName == itemTarget.TargetName).Sum(s => s.NPlanAmmountByYear);; if (VModel.NPlanAmmountByYear != 0) { VModel.NDisplayRateByYear = Math.Round((VModel.NAccumulativeActualAmmount / VModel.NPlanAmmountByYear), 5, MidpointRounding.AwayFromZero).ToString("P1"); } else { VModel.NPlanAmmountByYear = 0; VModel.NDisplayRateByYear = "/"; } VModel.NActualRateByYear = ""; _ProTargetLists.Add(VModel); } #endregion V_ProjectCompany tempProCompany = new V_ProjectCompany(); tempProCompany.ProCompanySequence = -100; tempProCompany.SystemID = Guid.Empty; tempProCompany.ProCompayName = ProCounter.Title; tempProCompany.ProCompayID = Guid.Empty; tempProCompany.ProCompanyProperty1 = ""; tempProCompany.FinYear = FinYear; tempProCompany.FinMonth = FinMonth; //tempProCompany.CompayModel = itemCompany; tempProCompany.ProRowSpan = 0; tempProCompany.ProCompanyNumber = 0; tempProCompany.ProjectTargets = _ProTargetLists; tempProCompany.ProDataType = "XML"; ProCompanyList.Add(tempProCompany); return(ProCompanyList); }
/// <summary> /// 获取区域公司总计的实体(第一步) /// </summary> /// <param name="ProCounter"></param> /// <returns></returns> private List <V_ProjectCompany> GetProjectModel(ProjectCounter ProCounter) { Guid SysId = Guid.Empty; //从XML中获取的系统ID Guid _CompanyId = Guid.Empty; if (!string.IsNullOrEmpty(ProCounter.CompanyID)) { _CompanyId = Guid.Parse(ProCounter.CompanyID); } //公司,区域小计的ID,从XML中获取的 C_Company itemCompany = C_CompanyOperator.Instance.GetCompany(_CompanyId); SysId = itemCompany.SystemID; //指标List List <C_Target> targetList = StaticResource.Instance.TargetList[SysId].ToList(); //项目公司 List <V_ProjectCompany> ProCompanyList = new List <V_ProjectCompany>(); ReportInstance rpt = null; //获取批次ID,如果_MonthReportID 不是为Guid.Empty ,表示:是从上报页面过来的 //反之,则代表是从查询页面传递过来的 if (currRptModel._MonthReportID != Guid.Empty) { //上报页面 ExceptionHelper.TrueThrow(currRptModel.LastestMonthlyReport == null, "B_MonthlyReport表为Null"); if (currRptModel.LastestMonthlyReport.SystemBatchID != Guid.Empty) { B_SystemBatch _BatchModel = B_SystemBatchOperator.Instance.GetSystemBatch(currRptModel.LastestMonthlyReport.SystemBatchID); List <V_SubReport> subRptList = JsonHelper.Deserialize <List <V_SubReport> >(_BatchModel.SubReport); subRptList.ForEach(p => { if (p.SystemID == SysId) { rpt = new ReportInstance(p.ReportID, true);// 从B表中获取根据ReportID获取 } }); } else { rpt = currRptModel; } } else { //查询页面, 通过系统倒序查找相应的项目系统 rpt = new ReportInstance(SysId, FinYear, FinMonth, IsLatestVersion); } ProjectCompanyDetails = rpt.ReportDetails; //计划指标,包含了 区域小计的指标 List <A_TargetPlanDetail> TargetPlanList = new List <A_TargetPlanDetail>(); if (currRptModel._MonthReportID != Guid.Empty) { //上报的时候总是获取最新的指标。 TargetPlanList = StaticResource.Instance.GetTargetPlanList(SysId, FinYear, FinMonth); } else { //查询的时候按照版本查询,从B表中查出后转换成A表的数据 List <B_TargetPlanDetail> _bTargetPlanList = new List <B_TargetPlanDetail>(); _bTargetPlanList = B_TargetplandetailOperator.Instance.GetTargetplandetailList(rpt.ReportDetails[0].TargetPlanID).ToList(); //将B 表数据添加到 A表中 _bTargetPlanList.ForEach(tp => TargetPlanList.Add(tp.ToAModel())); } List <V_ProjectTarget> ProTargetList = new List <V_ProjectTarget>(); V_ProjectCompany tempProCompany = new V_ProjectCompany(); tempProCompany.ProCompanySequence = itemCompany.Sequence; tempProCompany.SystemID = itemCompany.SystemID; tempProCompany.ProCompayName = itemCompany.CompanyName; tempProCompany.ProCompayID = itemCompany.ID; tempProCompany.ProCompanyProperty1 = itemCompany.CompanyProperty1; tempProCompany.FinYear = FinYear; tempProCompany.FinMonth = FinMonth; tempProCompany.CompayModel = itemCompany; tempProCompany.ProRowSpan = 0; tempProCompany.ProCompanyNumber = 0; //获取批次ID,如果_MonthReportID 不是为Guid.Empty ,表示:是从上报页面过来的 //反之,则代表是从查询页面传递过来的 if (currRptModel._MonthReportID != Guid.Empty) { tempProCompany.ProjectTargets = SingleProTargetLists(targetList, rpt.ReportDetails, TargetPlanList, itemCompany, false); } else { tempProCompany.ProjectTargets = SingleProTargetLists(targetList, rpt.ReportDetails, TargetPlanList, itemCompany, true); } tempProCompany.ProDataType = "XML"; ProCompanyList.Add(tempProCompany); return(ProCompanyList); }
/// <summary> /// 项目公司详细数据(第三步) /// </summary> /// <param name="IsProLatestVersion">false :从A表中获取 , true:从B表中获取</param> /// <param name="IsPlan">是否获取计划指标</param> /// <returns></returns> public List <V_ProjectCompany> GetProjectCompany() { List <V_ProjectCompany> ProCompanyList = new List <V_ProjectCompany>(); ProjectCompanyDetails = ReportDetails; List <C_Company> companyList = StaticResource.Instance.CompanyList[_SystemID].ToList(); List <C_Target> targetList = StaticResource.Instance.TargetList[_SystemID].ToList(); List <A_TargetPlanDetail> TargetPlanList = StaticResource.Instance.GetTargetPlanList(_System.ID, FinYear, FinMonth); foreach (C_Company itemCompany in companyList.OrderBy(o => o.Sequence)) { //已经上报的明细数据 List <MonthlyReportDetail> TempProCompany = ProjectCompanyDetails.FindAll(p => p.CompanyID == itemCompany.ID).ToList(); //本月计划指标分解表 List <A_TargetPlanDetail> TempTargetPlan = TargetPlanList.FindAll(p => p.CompanyID == itemCompany.ID).ToList(); //指标计划详细 List <V_ProjectTarget> ProTargetList = new List <V_ProjectTarget>(); if (IsPlanStr == "ProPlan") { if (TempTargetPlan.Count == 0) { continue; } } else { if (TempProCompany.Count == 0) { continue; } } V_ProjectCompany tempProCompany = new V_ProjectCompany(); tempProCompany.ProCompanySequence = itemCompany.Sequence; tempProCompany.SystemID = itemCompany.SystemID; tempProCompany.ProCompayName = itemCompany.CompanyName; tempProCompany.ProCompayID = itemCompany.ID; tempProCompany.ProCompanyProperty1 = itemCompany.CompanyProperty1; tempProCompany.FinYear = FinYear; tempProCompany.FinMonth = FinMonth; tempProCompany.CompayModel = itemCompany; tempProCompany.ProRowSpan = 1; tempProCompany.ProCompanyNumber = 0; if (itemCompany.CompanyProperty1 == "尾盘") { tempProCompany.ProDataType = "Remain"; } else { tempProCompany.ProDataType = "Data"; } tempProCompany.ProjectTargets = ProTargetLists(itemCompany, IsPlanStr, TempProCompany, TempTargetPlan); ProCompanyList.Add(tempProCompany); } //必须要有数据,否则直接过 if (ProCompanyList.Count != 0) { //获取当前的系统指标 List <A_TargetPlanDetail> TargetPlanListByYear = StaticResource.Instance.GetTargetPlanList(_System.ID, FinYear); #region 对有分组的数据 分组数据 属性:CompanyProperty2 List <string> value = (from v in companyList select v.CompanyProperty2).Distinct().ToList(); foreach (var item in value) { if (!string.IsNullOrEmpty(item)) { List <MonthlyReportDetail> FilterMonthRptDetails = new List <MonthlyReportDetail>(); List <A_TargetPlanDetail> FilterTargetPlanList = new List <A_TargetPlanDetail>(); //过滤分组后的数据 List <C_Company> Filter = companyList.FindAll(p => p.CompanyProperty2 == item.ToString()).OrderBy(o => o.Sequence).ToList(); for (int i = 0; i < Filter.Count; i++) { //得到分组数据的第一条数据,设置通行的行数 V_ProjectCompany proModel = ProCompanyList.Find(p => p.ProCompayID == Filter[i].ID); //是否是在计划指标下载 if (IsPlanStr != "ProPlan") { //页面展示时,通行 if (i == 0) { proModel.ProRowSpan = Filter.Count + 1; } else { proModel.ProRowSpan = 0; } // MonthRptDetails分组的数据,包含有指标,便于计算合计 FilterMonthRptDetails.AddRange(ProjectCompanyDetails.FindAll(f => f.CompanyID == Filter[i].ID).ToList()); //年度计划指标 FilterTargetPlanList.AddRange(TargetPlanListByYear.FindAll(f => f.CompanyID == Filter[i].ID).ToList()); } else { //页面展示时,通行 if (i == 0) { proModel.ProRowSpan = Filter.Count; } else { proModel.ProRowSpan = 0; } } } #region 添加 分组合计数据 ,只在查询的时候出现,其它时候不出现 if (IsPlanStr != "ProPlan") { V_ProjectCompany _LastGroupData = ProCompanyList.Find(p => p.ProCompayID == Filter[Filter.Count - 1].ID); V_ProjectCompany groupSumProModel = new V_ProjectCompany(); groupSumProModel.ProCompayID = Guid.Parse("88888888-8888-8888-8888-888888888888"); groupSumProModel.ProCompayName = item + "小计"; groupSumProModel.ProDataType = _LastGroupData.ProDataType; groupSumProModel.ProRowSpan = 0; groupSumProModel.SystemID = _LastGroupData.SystemID; groupSumProModel.FinYear = FinYear; groupSumProModel.FinMonth = FinMonth; groupSumProModel.ProCompanyNumber = _LastGroupData.ProCompanyNumber; groupSumProModel.ProjectTargets = ProTargetListByGroupSum(FilterMonthRptDetails, FilterTargetPlanList); groupSumProModel.ProCompanySequence = _LastGroupData.ProCompanySequence; ProCompanyList.Add(groupSumProModel); } #endregion } } #endregion #region 分组数据 属性:CompanyProperty1 尾盘 List <string> RemainData = (from v in companyList select v.CompanyProperty1).Distinct().ToList(); foreach (string itemR in RemainData) { if (!string.IsNullOrEmpty(itemR)) { List <C_Company> _Filter = companyList.FindAll(p => p.CompanyProperty1 == itemR.ToString()).OrderBy(o => o.Sequence).ToList(); for (int i = 0; i < _Filter.Count; i++) { //得到分组数据的第一条数据,设置通行的行数 V_ProjectCompany proModel = ProCompanyList.Find(p => p.ProCompayID == _Filter[i].ID); if (proModel != null) { if (i == 0) { proModel.ExcelGroupRow = _Filter.Count; } else { proModel.ExcelGroupRow = 0; } } } } } #endregion #region 循环添加项目的序号 int j = 1; foreach (var itemNumber in ProCompanyList.FindAll(p => p.ProRowSpan > 0).OrderBy(p => p.ProCompanySequence).ToList()) { itemNumber.ProCompanyNumber = j++; } #endregion } return(ProCompanyList.OrderBy(d => d.ProCompanySequence).ToList()); }