瀏覽代碼

VSM接口提交

Murphy 2 年之前
父節點
當前提交
11be085ed9

+ 54 - 0
MicroServices/Business/Business.Application.Contracts/Dto/VSMDto.cs

@@ -1,4 +1,5 @@
 using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Metadata.Internal;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -209,5 +210,58 @@ namespace Business.Dto
         /// </summary>
         public string Date { get; set; }
     }
+
+    public partial class ModelMonthOutkDto
+    {
+        public string Month0 { get; set; }
+        public decimal Month1 { get; set; }
+        public decimal Month2 { get; set; }
+        public decimal Month3 { get; set; }
+        public decimal Month4 { get; set; }
+        public decimal Month5 { get; set; }
+        public decimal Month6 { get; set; }
+        public decimal Month7 { get; set; }
+        public decimal Month8 { get; set; }
+        public decimal Month9 { get; set; }
+        public decimal Month10 { get; set; }
+        public decimal Month11 { get; set; }
+        public decimal Month12 { get; set; }
+        public decimal Month13 { get; set; }
+        public decimal Month14 { get; set; }
+    }
+
+    public partial class ForecastActualDto
+    {
+        public string ItemNum { get; set; }
+        public string GroupBy { get; set; }
+        public decimal ThreeMonthSales { get; set; }
+        public decimal StockTurnOver { get; set; }
+        public decimal M1Plan { get; set; }
+        public decimal M1Real { get; set; }
+        public string M1Diff { get; set; }
+        public decimal M2Plan { get; set; }
+        public decimal M2Real { get; set; }
+        public string M2Diff { get; set; }
+    }
+
+    public partial class InventoryDto
+    {
+        public string ItemNumber { get; set; }
+        public string ItemName { get; set; }
+        public string ProLine { get; set; }
+        public string Series { get; set; }
+        public string Model { get; set; }
+        public decimal FactoryInv { get; set; }
+        public decimal GKInv { get; set; }
+        public decimal HWInv { get; set; }
+        public decimal TotalInv { get; set; }
+        public decimal T1MonthlyDemand { get; set; }
+        public decimal HWMonthlyDemand { get; set; }
+        public decimal GKMonthlyDemand { get; set; }
+        public decimal TotalMonthlyDemand { get; set; }
+        public decimal HWCoverageMonth { get; set; }
+        public decimal GKCoverageMonth { get; set; }
+        public decimal TotalCoverageMonth { get; set; }
+    }
 }
 

+ 15 - 0
MicroServices/Business/Business.Application.Contracts/VSM/IVSMAppService.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using Business;
 using Business.Dto;
@@ -66,6 +67,20 @@ namespace Business.VSM
         string ChartLineOutStockOption(string factory_id, string model);
 
         /// <summary>
+        ///终端出货趋势列表
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        string ChartLineOutStock(string factory_id, string model);
+
+        /// <summary>
+        ///月度发货计划预测实际对比
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        string ForecastActual(string factory_id, string isItemNum, string itemNumRange, string itemNum, string groupBy);
+
+        /// <summary>
         /// 每日计算进出存快照
         /// </summary>
         /// <param name="domain"></param>

+ 2 - 2
MicroServices/Business/Business.Application/ReplenishmentManagement/ReplenishmentAppService.cs

@@ -692,9 +692,9 @@ namespace Business.Replenishment
                     await _businessDbContext.BulkDeleteAsync(toDelete);
                     await _businessDbContext.BulkInsertAsync(annualProductionOutlines);
                     await CalcLongPeriodItemPR(input);
-                    //await CalcROP(input);
+                    await CalcROP(input);
                     await SaveProductionMasterPlan(input, annualProductionOutlines);
-                    //await CalcWeekPlan(input);
+                    await CalcWeekPlan(input);
                     await unitOfWork.CompleteAsync();
                 }
                 catch (Exception e)

+ 351 - 71
MicroServices/Business/Business.Application/VSM/VSMAppService.cs

@@ -9,6 +9,7 @@ using Business.ResourceExamineManagement;
 using Business.ResourceExamineManagement.Dto;
 using Business.StructuredDB.MES;
 using Business.StructuredDB.MES.IC;
+using Business.StructuredDB.SaleFcst;
 using Business.StructuredDB.WMS;
 using Business.VSM;
 using EFCore.BulkExtensions;
@@ -19,7 +20,6 @@ using Microsoft.Extensions.Configuration;
 using MongoDB.Driver.Linq;
 using Newtonsoft.Json;
 using NLog;
-using Org.BouncyCastle.Asn1.X509;
 using System;
 using System.Collections.Generic;
 using System.Data;
@@ -34,6 +34,7 @@ using Volo.Abp.Domain.Repositories;
 using Volo.Abp.MultiTenancy;
 using WkHtmlToPdfDotNet;
 using ZstdSharp.Unsafe;
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
 
 namespace Business.VSMManagement
 {
@@ -48,7 +49,10 @@ namespace Business.VSMManagement
         private readonly IExtRASqlRepository<DMS_IN_PODETAIL> _DMS_IN_PODETAIL;
         private readonly IExtRASqlRepository<DMS_IN_LOCDETAIL> _DMS_IN_LOCDETAIL;
         private readonly IExtRASqlRepository<DMS_IN_ITEMMAPPING> _DMS_IN_ITEMMAPPING;
+        private readonly IExtRASqlRepository<DMS_IN_SHIPPINGDETAIL> _DMS_IN_SHIPPINGDETAIL;
         private readonly ISqlRepository<SAPInv> _SAPInv;
+        private readonly IRepository<MonthlyShipmentPlan> _monthlyShipmentPlan;
+        private readonly ISqlRepository<ASNBOLShipperDetail> _aSNBOLShipperDetail;
         private readonly BusinessDbContext _businessDbContext;
         public VSMAppService(
          ISqlRepository<ItemMaster> itemMaster,
@@ -60,7 +64,10 @@ namespace Business.VSMManagement
          IExtRASqlRepository<DMS_IN_PODETAIL> dms_IN_PODETAIL,
          IExtRASqlRepository<DMS_IN_LOCDETAIL> dms_IN_LOCDETAIL,
          IExtRASqlRepository<DMS_IN_ITEMMAPPING> dms_IN_ITEMMAPPING,
+         IExtRASqlRepository<DMS_IN_SHIPPINGDETAIL> dms_IN_SHIPPINGDETAIL,
          ISqlRepository<SAPInv> SAPInv,
+         IRepository<MonthlyShipmentPlan> monthlyShipmentPlan,
+         ISqlRepository<ASNBOLShipperDetail> aSNBOLShipperDetail,
         BusinessDbContext businessDbContext
          )
         {
@@ -73,7 +80,10 @@ namespace Business.VSMManagement
             _DMS_IN_PODETAIL = dms_IN_PODETAIL;
             _DMS_IN_LOCDETAIL= dms_IN_LOCDETAIL;
             _DMS_IN_ITEMMAPPING= dms_IN_ITEMMAPPING;
-            _SAPInv=SAPInv;
+            _DMS_IN_SHIPPINGDETAIL = dms_IN_SHIPPINGDETAIL;
+            _SAPInv =SAPInv;
+            _monthlyShipmentPlan=monthlyShipmentPlan;
+            _aSNBOLShipperDetail = aSNBOLShipperDetail;
             _businessDbContext = businessDbContext;
         }
         public string ValueFrequency(string Loc, string BeginDate, string EndDate, string KanBan, string Frequency)
@@ -312,68 +322,6 @@ namespace Business.VSMManagement
 
         public string ChartLineOption(string Loc, string BeginDate, string EndDate, string ItemNum,string TurnOver,string KanBan)
         {
-            //if(KanBan=="3")
-            //{
-            //    string sql = @"select t.[Date] AS [Date],t.DateStockQty AS StockQty,t.DateOutStockQty AS OutStockQty,t.DateInStockQty AS InStockQty,[SuggestStockQty] AS SuggestQty  from [dbo].[3KanBan] t";
-            //    var chartDtosTest = _businessDbContext.ValueFrequencyChartDto.FromSqlRaw(sql).ToList();
-            //    StringBuilder sb = new StringBuilder();
-            //    StringBuilder sbDays = new StringBuilder();
-            //    StringBuilder sbDaysStock = new StringBuilder();
-            //    StringBuilder sbDaysInStock = new StringBuilder();
-            //    StringBuilder sbDaysOutStock = new StringBuilder();
-            //    StringBuilder sbDaysSuggest = new StringBuilder();
-            //    sb.Append("{tooltip:{trigger:'axis'},legend:{data: ['日库存数量','日出库数量','日入库数量','推荐日库存数量']},grid:{left:'3%',right:'4%',bottom:'3%',containLabel:true},toolbox:{feature:{saveAsImage: {}}},xAxis: {type:'category',boundaryGap: false,data:[");
-            //    chartDtosTest.ForEach(a =>
-            //    {
-            //        sbDays.Append(string.Format("'{0}',", a.Date));
-            //        sbDaysStock.Append(string.Format("{0},", a.StockQty));
-            //        sbDaysOutStock.Append(string.Format("{0},", a.OutStockQty));
-            //        sbDaysInStock.Append(string.Format("{0},", a.InStockQty));
-            //        sbDaysSuggest.Append(string.Format("{0},", a.SuggestQty));
-            //    });
-            //    sb.Append(sbDays.ToString().TrimEnd(',')).
-            //       Append("]},yAxis:{type:'value',},series:[{name:'日库存数量',type:'line',data:[").
-            //       Append(sbDaysStock.ToString().TrimEnd(',')).
-            //       Append("]},{name:'日出库数量',type:'line',data:[").
-            //       Append(sbDaysOutStock.ToString().TrimEnd(',')).
-            //       Append("]},{name:'日入库数量',type:'line',data:[").
-            //       Append(sbDaysInStock.ToString().TrimEnd(',')).
-            //       Append("]},{name:'推荐日库存数量',type:'line',data:[").
-            //       Append(sbDaysSuggest.ToString().TrimEnd(',')).
-            //       Append("]}]}");
-            //    return sb.ToString();
-            //}
-            //else if(KanBan=="2")
-            //{
-            //    string sql = @"select t.[Date] AS [Date],t.DateStockQty AS StockQty,t.DateOutStockQty AS OutStockQty,t.DateInStockQty AS InStockQty,[SuggestStockQty] AS SuggestQty  from [dbo].[2KanBan] t";
-            //    var chartDtosTest = _businessDbContext.ValueFrequencyChartDto.FromSqlRaw(sql).ToList();
-            //    StringBuilder sb = new StringBuilder();
-            //    StringBuilder sbDays = new StringBuilder();
-            //    StringBuilder sbDaysStock = new StringBuilder();
-            //    StringBuilder sbDaysInStock = new StringBuilder();
-            //    StringBuilder sbDaysOutStock = new StringBuilder();
-            //    StringBuilder sbDaysSuggest = new StringBuilder();
-            //    sb.Append("{tooltip:{trigger:'axis'},legend:{data: ['日库存数量','日出库数量','日入库数量','推荐日库存数量']},grid:{left:'3%',right:'4%',bottom:'3%',containLabel:true},toolbox:{feature:{saveAsImage: {}}},xAxis: {type:'category',boundaryGap: false,data:[");
-            //    chartDtosTest.ForEach(a =>
-            //    {
-            //        sbDays.Append(string.Format("'{0}',", a.Date));
-            //        sbDaysStock.Append(string.Format("{0},", a.StockQty));
-            //        sbDaysOutStock.Append(string.Format("{0},", a.OutStockQty));
-            //        sbDaysInStock.Append(string.Format("{0},", a.InStockQty));
-            //        sbDaysSuggest.Append(string.Format("{0},", a.SuggestQty));
-            //    });
-            //    sb.Append(sbDays.ToString().TrimEnd(',')).
-            //       Append("]},yAxis:{type:'value',},series:[{name:'日库存数量',type:'line',data:[").
-            //       Append(sbDaysStock.ToString().TrimEnd(',')).
-            //       Append("]},{name:'日出库数量',type:'line',data:[").
-            //       Append(sbDaysOutStock.ToString().TrimEnd(',')).
-            //       Append("]},{name:'日入库数量',type:'line',data:[").
-            //       Append(sbDaysInStock.ToString().TrimEnd(',')).
-            //       Append("]},{name:'推荐日库存数量',type:'line',data:[").
-            //       Append(sbDaysSuggest.ToString().TrimEnd(',')).
-            //       Append("]}]}");
-            //    return sb.ToString();
-            //}
             try
             {
                 DateTime beginDate = Convert.ToDateTime(BeginDate);
@@ -394,10 +342,20 @@ namespace Business.VSMManagement
                 {
                     ValueFrequencyChartDto dtoChart = new ValueFrequencyChartDto();
                     dtoChart.Date = beginDate.AddDays(i).ToString("yyyy-MM-dd");
-                    dtoChart.InStockQty = InvTransHistDayDto.Where(a => beginDate.AddDays(i).Date== a.HistDayTime.Date).First().QtyChangeAdvance;
-                    dtoChart.OutStockQty = InvTransHistDayDto.Where(a => beginDate.AddDays(i).Date == a.HistDayTime.Date).First().QtyChangeOut;
-                    dtoChart.StockQty = InvTransHistDayDto.Where(a => beginDate.AddDays(i).Date == a.HistDayTime.Date).First().BalanceNum;
-                    dtoChart.SuggestQty =chartKanBan*chartPLT;
+                    var itemDays = InvTransHistDayDto.Where(a => beginDate.AddDays(i).Date == a.HistDayTime.Date).ToList();
+                    if(itemDays.Count>0)
+                    {
+                        dtoChart.InStockQty = itemDays[0].QtyChangeAdvance;
+                        dtoChart.OutStockQty = itemDays[0].QtyChangeOut;
+                        dtoChart.StockQty = itemDays[0].BalanceNum;
+                        dtoChart.SuggestQty = chartKanBan * chartPLT;
+                    }else
+                    {
+                        dtoChart.InStockQty = 0;
+                        dtoChart.OutStockQty = 0;
+                        dtoChart.StockQty = 0;
+                        dtoChart.SuggestQty = 0;
+                    }
                     chartDtos.Add(dtoChart);
                 }
                 chartDtos = chartDtos.Where(a => string.Compare(a.Date, BeginDate) >= 0 && string.Compare(a.Date, EndDate) <= 0).ToList();
@@ -563,7 +521,7 @@ namespace Business.VSMManagement
                 total = 0;
             }
             StringBuilder sb = new StringBuilder();
-            sb.Append("{xAxis:{type:'category',data:['海王库存','国科库存','T1','Total']},yAxis:{type:'value'},series:[{data:[" +hw+","+gk+","+t1+","+total+"],type:'bar',label:{show:true,position:'top'},itemStyle:{normal:{color:function(params){if(params.value<4){return 'red';}else{return '#5470c6';}}}}}]}");
+            sb.Append("{title: {text:'库存可供应周期(月)',left: 'center'},xAxis:{type:'category',data:['海王库存','国科库存','T1','Total']},yAxis:{type:'value'},series:[{data:[" + hw+","+gk+","+t1+","+total+"],type:'bar',label:{show:true,position:'top'},itemStyle:{normal:{color:function(params){if(params.value<4){return 'red';}else{return '#5470c6';}}}}}]}");
             return sb.ToString();
         }
 
@@ -591,7 +549,7 @@ namespace Business.VSMManagement
             StringBuilder sb = new StringBuilder();
             sb.Append("{title: {text:'");
             sb.Append(model+"出货趋势',");
-            sb.Append("left: 'center',},tooltip: {trigger: 'axis'},legend: {data:['海王', '国科', 'T1','Total'],bottom: '0',orient: 'horizontal'},grid: {left: '3%',right: '4%',bottom: '3%',containLabel: true},toolbox: {feature: {saveAsImage: {}}},xAxis:{type: 'category',boundaryGap: false,data:[");
+            sb.Append("left: 'center',},tooltip: {trigger: 'axis'},legend: {data:['海王', '国科', 'T1','Total'],bottom:-5,orient: 'horizontal'},grid: {left: '3%',right: '4%',bottom: '3%',containLabel: true},toolbox: {feature: {saveAsImage: {}}},xAxis:{type: 'category',boundaryGap: false,data:[");
             sb.Append(sbDate.ToString().TrimEnd(',')).
                   Append("]},yAxis:{type:'value',},series:[{name:'海王',type:'line',stack: 'Total',data:[").
                   Append(sbHWOutStock.ToString().TrimEnd(',')).
@@ -605,12 +563,334 @@ namespace Business.VSMManagement
             return sb.ToString();
         }
 
+        public string ChartLineOutStock(string factory_id, string model)
+        {
+            DateOnly dateOnly = DateOnly.FromDateTime(DateTime.Now.AddMonths(-14));
+            var polist = _DMS_IN_PODETAIL.Select(a => a.UPN == model && a.OrderStatus != "Revoked" && a.OrderStatus != "Rejected" && a.SubmitDate >= dateOnly);
+            List<ModelMonthOutkDto> modelMonthOuts=new List<ModelMonthOutkDto>();
+            ModelMonthOutkDto stockDto1 = new ModelMonthOutkDto();
+            stockDto1.Month0 = "海王";
+            stockDto1.Month1 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-14)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-13)) && a.DealerCode == "RQ000002" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value);
+            stockDto1.Month2 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-13)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-12)) && a.DealerCode == "RQ000002" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); 
+            stockDto1.Month3 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-12)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-11)) && a.DealerCode == "RQ000002" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value);
+            stockDto1.Month4 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-11)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-10)) && a.DealerCode == "RQ000002" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); 
+            stockDto1.Month5 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-10)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-9)) && a.DealerCode == "RQ000002" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); 
+            stockDto1.Month6 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-9)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-8)) && a.DealerCode == "RQ000002" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); 
+            stockDto1.Month7 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-8)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-7)) && a.DealerCode == "RQ000002" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); 
+            stockDto1.Month8 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-7)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-6)) && a.DealerCode == "RQ000002" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); 
+            stockDto1.Month9 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-6)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-5)) && a.DealerCode == "RQ000002" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); 
+            stockDto1.Month10 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-5)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-4)) && a.DealerCode == "RQ000002" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); 
+            stockDto1.Month11 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-4)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-3)) && a.DealerCode == "RQ000002" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); 
+            stockDto1.Month12 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-3)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-2)) && a.DealerCode == "RQ000002" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); 
+            stockDto1.Month13 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-2)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-1)) && a.DealerCode == "RQ000002" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); 
+            stockDto1.Month14 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-1)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(0)) && a.DealerCode == "RQ000002" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value);  
+            modelMonthOuts.Add(stockDto1);
+
+            ModelMonthOutkDto stockDto2 = new ModelMonthOutkDto();
+            stockDto2.Month0 = "国科";
+            stockDto2.Month1 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-14)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-13)) && a.DealerCode == "RQ000005" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value);
+            stockDto2.Month2 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-13)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-12)) && a.DealerCode == "RQ000005" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); ;
+            stockDto2.Month3 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-12)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-11)) && a.DealerCode == "RQ000005" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); ;
+            stockDto2.Month4 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-11)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-10)) && a.DealerCode == "RQ000005" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); ;
+            stockDto2.Month5 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-10)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-9)) && a.DealerCode == "RQ000005" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); ;
+            stockDto2.Month6 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-9)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-8)) && a.DealerCode == "RQ000005" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); ;
+            stockDto2.Month7 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-8)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-7)) && a.DealerCode == "RQ000005" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); ;
+            stockDto2.Month8 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-7)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-6)) && a.DealerCode == "RQ000005" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); ;
+            stockDto2.Month9 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-6)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-5)) && a.DealerCode == "RQ000005" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); ;
+            stockDto2.Month10 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-5)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-4)) && a.DealerCode == "RQ000005" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); ;
+            stockDto2.Month11 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-4)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-3)) && a.DealerCode == "RQ000005" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); ;
+            stockDto2.Month12 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-3)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-2)) && a.DealerCode == "RQ000005" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); ;
+            stockDto2.Month13 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-2)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-1)) && a.DealerCode == "RQ000005" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); ;
+            stockDto2.Month14 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-1)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(0)) && a.DealerCode == "RQ000005" && a.DealerLevel == "LP").Sum(a => a.RequiredQty.Value); ;
+            modelMonthOuts.Add(stockDto2);
+
+            ModelMonthOutkDto stockDto3 = new ModelMonthOutkDto();
+            stockDto3.Month0 = "T1";
+            stockDto3.Month1 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-14)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-13)) && (a.DealerLevel == "LP" || a.DealerLevel == "LS")).Sum(a => a.RequiredQty.Value);
+            stockDto3.Month2 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-13)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-12)) && (a.DealerLevel == "LP" || a.DealerLevel == "LS")).Sum(a => a.RequiredQty.Value); ;
+            stockDto3.Month3 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-12)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-11)) && (a.DealerLevel == "LP" || a.DealerLevel == "LS")).Sum(a => a.RequiredQty.Value); ;
+            stockDto3.Month4 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-11)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-10)) && (a.DealerLevel == "LP" || a.DealerLevel == "LS")).Sum(a => a.RequiredQty.Value); ;
+            stockDto3.Month5 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-10)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-9)) && (a.DealerLevel == "LP" || a.DealerLevel == "LS")).Sum(a => a.RequiredQty.Value); ;
+            stockDto3.Month6 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-9)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-8)) && (a.DealerLevel == "LP" || a.DealerLevel == "LS")).Sum(a => a.RequiredQty.Value); ;
+            stockDto3.Month7 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-8)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-7)) && (a.DealerLevel == "LP" || a.DealerLevel == "LS")).Sum(a => a.RequiredQty.Value); ;
+            stockDto3.Month8 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-7)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-6)) && (a.DealerLevel == "LP" || a.DealerLevel == "LS")).Sum(a => a.RequiredQty.Value); ;
+            stockDto3.Month9 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-6)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-5)) && (a.DealerLevel == "LP" || a.DealerLevel == "LS")).Sum(a => a.RequiredQty.Value); ;
+            stockDto3.Month10 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-5)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-4)) && (a.DealerLevel == "LP" || a.DealerLevel == "LS")).Sum(a => a.RequiredQty.Value); ;
+            stockDto3.Month11 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-4)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-3)) && (a.DealerLevel == "LP" || a.DealerLevel == "LS")).Sum(a => a.RequiredQty.Value); ;
+            stockDto3.Month12 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-3)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-2)) && (a.DealerLevel == "LP" || a.DealerLevel == "LS")).Sum(a => a.RequiredQty.Value); ;
+            stockDto3.Month13 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-2)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(-1)) && (a.DealerLevel == "LP" || a.DealerLevel == "LS")).Sum(a => a.RequiredQty.Value); ;
+            stockDto3.Month14 = polist.Where(a => a.SubmitDate >= DateOnly.FromDateTime(DateTime.Now.AddMonths(-1)) && a.SubmitDate < DateOnly.FromDateTime(DateTime.Now.AddMonths(0)) && (a.DealerLevel == "LP" || a.DealerLevel == "LS")).Sum(a => a.RequiredQty.Value); ;
+            modelMonthOuts.Add(stockDto3);
+
+            ModelMonthOutkDto stockDto4 = new ModelMonthOutkDto();
+            stockDto4.Month0 = "Total";
+            stockDto4.Month1 =stockDto1.Month1+stockDto2.Month1+stockDto3.Month1;
+            stockDto4.Month2 = stockDto1.Month2 + stockDto2.Month2 + stockDto3.Month2; 
+            stockDto4.Month3 = stockDto1.Month3 + stockDto2.Month3 + stockDto3.Month3;
+            stockDto4.Month4 = stockDto1.Month4 + stockDto2.Month4 + stockDto3.Month4;
+            stockDto4.Month5 = stockDto1.Month5 + stockDto2.Month5 + stockDto3.Month5;
+            stockDto4.Month6 = stockDto1.Month6 + stockDto2.Month6 + stockDto3.Month6;
+            stockDto4.Month7 = stockDto1.Month7 + stockDto2.Month7 + stockDto3.Month7;
+            stockDto4.Month8 = stockDto1.Month8 + stockDto2.Month8 + stockDto3.Month8;
+            stockDto4.Month9 = stockDto1.Month9 + stockDto2.Month9 + stockDto3.Month9;
+            stockDto4.Month10 = stockDto1.Month10 + stockDto2.Month10 + stockDto3.Month10;
+            stockDto4.Month11 = stockDto1.Month11 + stockDto2.Month11 + stockDto3.Month11;
+            stockDto4.Month12 = stockDto1.Month12 + stockDto2.Month12 + stockDto3.Month12;
+            stockDto4.Month13 = stockDto1.Month13 + stockDto2.Month13 + stockDto3.Month13;
+            stockDto4.Month14 = stockDto1.Month14 + stockDto2.Month14 + stockDto3.Month14;
+            modelMonthOuts.Add(stockDto4);
+
+            ModelMonthOutkDto stockDto5 = new ModelMonthOutkDto();
+            stockDto5.Month0 = "海王均值";
+            stockDto5.Month1 = decimal.Ceiling((stockDto1.Month12+stockDto1.Month13+stockDto1.Month14)/3);
+            stockDto5.Month2 = decimal.Ceiling((stockDto1.Month12 + stockDto1.Month13 + stockDto1.Month14) / 3);
+            stockDto5.Month3 = decimal.Ceiling((stockDto1.Month12 + stockDto1.Month13 + stockDto1.Month14) / 3);
+            stockDto5.Month4 = decimal.Ceiling((stockDto1.Month12 + stockDto1.Month13 + stockDto1.Month14) / 3);
+            stockDto5.Month5 = decimal.Ceiling((stockDto1.Month12 + stockDto1.Month13 + stockDto1.Month14) / 3);
+            stockDto5.Month6 = decimal.Ceiling((stockDto1.Month12 + stockDto1.Month13 + stockDto1.Month14) / 3);
+            stockDto5.Month7 = decimal.Ceiling((stockDto1.Month12 + stockDto1.Month13 + stockDto1.Month14) / 3);
+            stockDto5.Month8 = decimal.Ceiling((stockDto1.Month12 + stockDto1.Month13 + stockDto1.Month14) / 3);
+            stockDto5.Month9 = decimal.Ceiling((stockDto1.Month12 + stockDto1.Month13 + stockDto1.Month14) / 3);
+            stockDto5.Month10 = decimal.Ceiling((stockDto1.Month12 + stockDto1.Month13 + stockDto1.Month14) / 3);
+            stockDto5.Month11 = decimal.Ceiling((stockDto1.Month12 + stockDto1.Month13 + stockDto1.Month14) / 3);
+            stockDto5.Month12 = decimal.Ceiling((stockDto1.Month12 + stockDto1.Month13 + stockDto1.Month14) / 3);
+            stockDto5.Month13 = decimal.Ceiling((stockDto1.Month12 + stockDto1.Month13 + stockDto1.Month14) / 3);
+            stockDto5.Month14 = decimal.Ceiling((stockDto1.Month12 + stockDto1.Month13 + stockDto1.Month14) / 3);
+            modelMonthOuts.Add(stockDto5);
+
+            ModelMonthOutkDto stockDto6 = new ModelMonthOutkDto();
+            stockDto6.Month0 = "国科均值";
+            stockDto6.Month1 = decimal.Ceiling((stockDto2.Month12 + stockDto2.Month13 + stockDto2.Month14) / 3);
+            stockDto6.Month2 = decimal.Ceiling((stockDto2.Month12 + stockDto2.Month13 + stockDto2.Month14) / 3);
+            stockDto6.Month3 = decimal.Ceiling((stockDto2.Month12 + stockDto2.Month13 + stockDto2.Month14) / 3);
+            stockDto6.Month4 = decimal.Ceiling((stockDto2.Month12 + stockDto2.Month13 + stockDto2.Month14) / 3);
+            stockDto6.Month5 = decimal.Ceiling((stockDto2.Month12 + stockDto2.Month13 + stockDto2.Month14) / 3);
+            stockDto6.Month6 = decimal.Ceiling((stockDto2.Month12 + stockDto2.Month13 + stockDto2.Month14) / 3);
+            stockDto6.Month7 = decimal.Ceiling((stockDto2.Month12 + stockDto2.Month13 + stockDto2.Month14) / 3);
+            stockDto6.Month8 = decimal.Ceiling((stockDto2.Month12 + stockDto2.Month13 + stockDto2.Month14) / 3);
+            stockDto6.Month9 = decimal.Ceiling((stockDto2.Month12 + stockDto2.Month13 + stockDto2.Month14) / 3);
+            stockDto6.Month10 = decimal.Ceiling((stockDto2.Month12 + stockDto2.Month13 + stockDto2.Month14) / 3);
+            stockDto6.Month11 = decimal.Ceiling((stockDto2.Month12 + stockDto2.Month13 + stockDto2.Month14) / 3);
+            stockDto6.Month12 = decimal.Ceiling((stockDto2.Month12 + stockDto2.Month13 + stockDto2.Month14) / 3);
+            stockDto6.Month13 = decimal.Ceiling((stockDto2.Month12 + stockDto2.Month13 + stockDto2.Month14) / 3);
+            stockDto6.Month14 = decimal.Ceiling((stockDto2.Month12 + stockDto2.Month13 + stockDto2.Month14) / 3);
+            modelMonthOuts.Add(stockDto6);
+
+            ModelMonthOutkDto stockDto7 = new ModelMonthOutkDto();
+            stockDto7.Month0 = "T1均值";
+            stockDto7.Month1 = decimal.Ceiling((stockDto3.Month12 + stockDto3.Month13 + stockDto3.Month14) / 3);
+            stockDto7.Month2 = decimal.Ceiling((stockDto3.Month12 + stockDto3.Month13 + stockDto3.Month14) / 3);
+            stockDto7.Month3 = decimal.Ceiling((stockDto3.Month12 + stockDto3.Month13 + stockDto3.Month14) / 3);
+            stockDto7.Month4 = decimal.Ceiling((stockDto3.Month12 + stockDto3.Month13 + stockDto3.Month14) / 3);
+            stockDto7.Month5 = decimal.Ceiling((stockDto3.Month12 + stockDto3.Month13 + stockDto3.Month14) / 3);
+            stockDto7.Month6 = decimal.Ceiling((stockDto3.Month12 + stockDto3.Month13 + stockDto3.Month14) / 3);
+            stockDto7.Month7 = decimal.Ceiling((stockDto3.Month12 + stockDto3.Month13 + stockDto3.Month14) / 3);
+            stockDto7.Month8 = decimal.Ceiling((stockDto3.Month12 + stockDto3.Month13 + stockDto3.Month14) / 3);
+            stockDto7.Month9 = decimal.Ceiling((stockDto3.Month12 + stockDto3.Month13 + stockDto3.Month14) / 3);
+            stockDto7.Month10 = decimal.Ceiling((stockDto3.Month12 + stockDto3.Month13 + stockDto3.Month14) / 3);
+            stockDto7.Month11 = decimal.Ceiling((stockDto3.Month12 + stockDto3.Month13 + stockDto3.Month14) / 3);
+            stockDto7.Month12 = decimal.Ceiling((stockDto3.Month12 + stockDto3.Month13 + stockDto3.Month14) / 3);
+            stockDto7.Month13 = decimal.Ceiling((stockDto3.Month12 + stockDto3.Month13 + stockDto3.Month14) / 3);
+            stockDto7.Month14 = decimal.Ceiling((stockDto3.Month12 + stockDto3.Month13 + stockDto3.Month14) / 3);
+            modelMonthOuts.Add(stockDto7);
+
+            ModelMonthOutkDto stockDto8 = new ModelMonthOutkDto();
+            stockDto8.Month0 = "Total均值";
+            stockDto8.Month1 = decimal.Ceiling((stockDto4.Month12 + stockDto4.Month13 + stockDto4.Month14) / 3);
+            stockDto8.Month2 = decimal.Ceiling((stockDto4.Month12 + stockDto4.Month13 + stockDto4.Month14) / 3);
+            stockDto8.Month3 = decimal.Ceiling((stockDto4.Month12 + stockDto4.Month13 + stockDto4.Month14) / 3);
+            stockDto8.Month4 = decimal.Ceiling((stockDto4.Month12 + stockDto4.Month13 + stockDto4.Month14) / 3);
+            stockDto8.Month5 = decimal.Ceiling((stockDto4.Month12 + stockDto4.Month13 + stockDto4.Month14) / 3);
+            stockDto8.Month6 = decimal.Ceiling((stockDto4.Month12 + stockDto4.Month13 + stockDto4.Month14) / 3);
+            stockDto8.Month7 = decimal.Ceiling((stockDto4.Month12 + stockDto4.Month13 + stockDto4.Month14) / 3);
+            stockDto8.Month8 = decimal.Ceiling((stockDto4.Month12 + stockDto4.Month13 + stockDto4.Month14) / 3);
+            stockDto8.Month9 = decimal.Ceiling((stockDto4.Month12 + stockDto4.Month13 + stockDto4.Month14) / 3);
+            stockDto8.Month10 = decimal.Ceiling((stockDto4.Month12 + stockDto4.Month13 + stockDto4.Month14) / 3);
+            stockDto8.Month11 = decimal.Ceiling((stockDto4.Month12 + stockDto4.Month13 + stockDto4.Month14) / 3);
+            stockDto8.Month12 = decimal.Ceiling((stockDto4.Month12 + stockDto4.Month13 + stockDto4.Month14) / 3);
+            stockDto8.Month13 = decimal.Ceiling((stockDto4.Month12 + stockDto4.Month13 + stockDto4.Month14) / 3);
+            stockDto8.Month14 = decimal.Ceiling((stockDto4.Month12 + stockDto4.Month13 + stockDto4.Month14) / 3);
+            modelMonthOuts.Add(stockDto8);
+            return JsonConvert.SerializeObject(modelMonthOuts);
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="factory_id"></param>
+        /// <param name="isItemNum">统计维度:M物料、S系列</param>
+        /// <param name="itemNumRange">统计范围:F工厂、G国科、H海王、A工厂+平台</param>
+        /// <param name="itemNum">物料编码</param>
+        /// <param name="groupBy">系列</param>
+        /// <returns></returns>
+        public string ForecastActual(string factory_id, string isItemNum, string itemNumRange, string itemNum, string groupBy)
+        {
+            string sql = $"exec [dbo].[pr_DOP_InventoryMonitoring]";
+            var InventoryDto = _businessDbContext.InventoryDto.FromSqlRaw(sql).ToList();
+
+            DateOnly dateOnly = DateOnly.FromDateTime(DateTime.Now.AddMonths(-2));
+            var polist = _DMS_IN_PODETAIL.Select(a =>a.SubmitDate >= dateOnly && a.OrderStatus != "Revoked" && a.OrderStatus != "Rejected");
+            var rqShip = _aSNBOLShipperDetail.Select(a => a.CreateTime >= DateTime.Now.AddMonths(-2) && a.Domain == factory_id);
+            List<ForecastActualDto> modelMonthOuts = new List<ForecastActualDto>();
+            //按照物料统计
+            if (isItemNum == "M")
+            {
+                switch (itemNumRange)
+                {
+                    case "F":
+                        if(itemNum!="")
+                        {
+                            var shipPlan=_monthlyShipmentPlan.GetListAsync(a => a.SAPItemNumber == itemNum 
+                            && (a.PlanMonth==DateTime.Now.AddMonths(-1).ToString("yyyy-MM") || a.PlanMonth == DateTime.Now.ToString("yyyy-MM"))
+                            && a.DistributionChannel == "瑞奇").Result;
+                            var itemDto = InventoryDto.Find(a => a.ItemNumber == itemNum);
+                            if(itemDto!=null)
+                            {
+                                ForecastActualDto forecastActualDto = new ForecastActualDto();
+                                forecastActualDto.ItemNum = itemNum;
+                                forecastActualDto.GroupBy = itemDto.Series;
+                                forecastActualDto.StockTurnOver = itemDto.GKMonthlyDemand + itemDto.HWMonthlyDemand==0?0:decimal.Ceiling((itemDto.GKInv+ itemDto.HWInv)/(itemDto.GKMonthlyDemand+ itemDto.HWMonthlyDemand));
+                                //月度发货计划找不到可以去月度发货计划历史表按照版本号找,暂不处理
+                                forecastActualDto.M1Plan = 0;
+                                forecastActualDto.M2Plan = 0;
+                                if (shipPlan.Any(a=> a.PlanMonth == DateTime.Now.AddMonths(-1).ToString("yyyy-MM")))
+                                {
+                                    forecastActualDto.M1Plan = shipPlan.Find(a=>a.PlanMonth == DateTime.Now.AddMonths(-1).ToString("yyyy-MM")).Qty;
+                                }
+                                if (shipPlan.Any(a => a.PlanMonth == DateTime.Now.ToString("yyyy-MM")))
+                                {
+                                    forecastActualDto.M2Plan = shipPlan.Find(a => a.PlanMonth == DateTime.Now.ToString("yyyy-MM")).Qty;
+                                }
+                                forecastActualDto.M1Real = rqShip.Where(a=>a.ContainerItem==itemNum && a.CreateTime>=DateTime.Now.AddMonths(-2) && a.CreateTime < DateTime.Now.AddMonths(-1)).Sum(b=>b.QtyToShip.Value);
+                                forecastActualDto.M2Real = rqShip.Where(a => a.ContainerItem == itemNum && a.CreateTime >= DateTime.Now.AddMonths(-1) && a.CreateTime < DateTime.Now).Sum(b => b.QtyToShip.Value);
+                                forecastActualDto.M1Diff = (forecastActualDto.M1Plan == 0 || forecastActualDto.M1Real == 0) ? "100%" : $"{decimal.Ceiling(forecastActualDto.M1Real / forecastActualDto.M1Plan)}%";
+                                forecastActualDto.M2Diff = (forecastActualDto.M2Plan == 0 || forecastActualDto.M2Real == 0) ? "100%" : $"{decimal.Ceiling(forecastActualDto.M2Real / forecastActualDto.M2Plan)}%";
+                                modelMonthOuts.Add(forecastActualDto);
+                            }
+                        }else
+                        {
+                            var shipPlan = _monthlyShipmentPlan.GetListAsync(a => (a.PlanMonth == DateTime.Now.AddMonths(-1).ToString("yyyy-MM") || a.PlanMonth == DateTime.Now.ToString("yyyy-MM"))
+                            && a.DistributionChannel == "瑞奇").Result;
+                            var itemList= shipPlan.Select(a=>a.SAPItemNumber).Distinct().ToList();
+                            itemList.ForEach(x=>
+                            {
+                                var itemDto = InventoryDto.Find(a => a.ItemNumber == x);
+                                if (itemDto != null)
+                                {
+                                    ForecastActualDto forecastActualDto = new ForecastActualDto();
+                                    forecastActualDto.ItemNum = x;
+                                    forecastActualDto.GroupBy = itemDto.Series;
+                                    forecastActualDto.StockTurnOver = itemDto.GKMonthlyDemand + itemDto.HWMonthlyDemand == 0 ? 0 : decimal.Ceiling((itemDto.GKInv + itemDto.HWInv) / (itemDto.GKMonthlyDemand + itemDto.HWMonthlyDemand));
+                                    //月度发货计划找不到可以去月度发货计划历史表按照版本号找,暂不处理
+                                    forecastActualDto.M1Plan = 0;
+                                    forecastActualDto.M2Plan = 0;
+                                    if (shipPlan.Any(a => a.PlanMonth == DateTime.Now.AddMonths(-1).ToString("yyyy-MM")))
+                                    {
+                                        forecastActualDto.M1Plan = shipPlan.Find(a => a.PlanMonth == DateTime.Now.AddMonths(-1).ToString("yyyy-MM")).Qty;
+                                    }
+                                    if (shipPlan.Any(a => a.PlanMonth == DateTime.Now.ToString("yyyy-MM")))
+                                    {
+                                        forecastActualDto.M2Plan = shipPlan.Find(a => a.PlanMonth == DateTime.Now.ToString("yyyy-MM")).Qty;
+                                    }
+                                    forecastActualDto.M1Real = rqShip.Where(a => a.ContainerItem == itemNum && a.CreateTime >= DateTime.Now.AddMonths(-2) && a.CreateTime < DateTime.Now.AddMonths(-1)).Sum(b => b.QtyToShip.Value);
+                                    forecastActualDto.M2Real = rqShip.Where(a => a.ContainerItem == itemNum && a.CreateTime >= DateTime.Now.AddMonths(-1) && a.CreateTime < DateTime.Now).Sum(b => b.QtyToShip.Value);
+                                    forecastActualDto.M1Diff = (forecastActualDto.M1Plan == 0 || forecastActualDto.M1Real == 0) ? "100%" : $"{decimal.Ceiling(forecastActualDto.M1Real / forecastActualDto.M1Plan)}%";
+                                    forecastActualDto.M2Diff = (forecastActualDto.M2Plan == 0 || forecastActualDto.M2Real == 0) ? "100%" : $"{decimal.Ceiling(forecastActualDto.M2Real / forecastActualDto.M2Plan)}%";
+                                    modelMonthOuts.Add(forecastActualDto);
+                                }
+                            });
+                        }
+                        break;
+                    case "G":
+                        if (itemNum != "")
+                        {
+                            var shipPlan = _monthlyShipmentPlan.GetListAsync(a => a.SAPItemNumber == itemNum
+                            && (a.PlanMonth == DateTime.Now.AddMonths(-1).ToString("yyyy-MM") || a.PlanMonth == DateTime.Now.ToString("yyyy-MM"))
+                            && a.DistributionChannel == "国科").Result;
+
+                            var item=_DMS_IN_ITEMMAPPING.Select(a => a.CfnERPCode == itemNum);
+                            if(item!=null)
+                            {
+                                var itemDto = InventoryDto.Find(a => a.ItemNumber == itemNum);
+                                if (itemDto != null)
+                                {
+                                    ForecastActualDto forecastActualDto = new ForecastActualDto();
+                                    forecastActualDto.ItemNum = itemNum;
+                                    forecastActualDto.GroupBy = itemDto.Series;
+                                    forecastActualDto.StockTurnOver = itemDto.GKMonthlyDemand + itemDto.HWMonthlyDemand == 0 ? 0 : decimal.Ceiling((itemDto.GKInv + itemDto.HWInv) / (itemDto.GKMonthlyDemand + itemDto.HWMonthlyDemand));
+                                    //月度发货计划找不到可以去月度发货计划历史表按照版本号找,暂不处理
+                                    forecastActualDto.M1Plan = 0;
+                                    forecastActualDto.M2Plan = 0;
+                                    if (shipPlan.Any(a => a.PlanMonth == DateTime.Now.AddMonths(-1).ToString("yyyy-MM")))
+                                    {
+                                        forecastActualDto.M1Plan = shipPlan.Find(a => a.PlanMonth == DateTime.Now.AddMonths(-1).ToString("yyyy-MM")).Qty;
+                                    }
+                                    if (shipPlan.Any(a => a.PlanMonth == DateTime.Now.ToString("yyyy-MM")))
+                                    {
+                                        forecastActualDto.M2Plan = shipPlan.Find(a => a.PlanMonth == DateTime.Now.ToString("yyyy-MM")).Qty;
+                                    }
+                                    forecastActualDto.M1Real = rqShip.Where(a => a.ContainerItem == itemNum && a.CreateTime >= DateTime.Now.AddMonths(-2) && a.CreateTime < DateTime.Now.AddMonths(-1)).Sum(b => b.QtyToShip.Value);
+                                    forecastActualDto.M2Real = rqShip.Where(a => a.ContainerItem == itemNum && a.CreateTime >= DateTime.Now.AddMonths(-1) && a.CreateTime < DateTime.Now).Sum(b => b.QtyToShip.Value);
+                                    forecastActualDto.M1Diff = (forecastActualDto.M1Plan == 0 || forecastActualDto.M1Real == 0) ? "100%" : $"{decimal.Ceiling(forecastActualDto.M1Real / forecastActualDto.M1Plan)}%";
+                                    forecastActualDto.M2Diff = (forecastActualDto.M2Plan == 0 || forecastActualDto.M2Real == 0) ? "100%" : $"{decimal.Ceiling(forecastActualDto.M2Real / forecastActualDto.M2Plan)}%";
+                                    modelMonthOuts.Add(forecastActualDto);
+                                }
+                            }
+                        }
+                        else
+                        {
+                            var shipPlan = _monthlyShipmentPlan.GetListAsync(a => (a.PlanMonth == DateTime.Now.AddMonths(-1).ToString("yyyy-MM") || a.PlanMonth == DateTime.Now.ToString("yyyy-MM"))
+                            && a.DistributionChannel == "瑞奇").Result;
+                            var itemList = shipPlan.Select(a => a.SAPItemNumber).Distinct().ToList();
+                            itemList.ForEach(x =>
+                            {
+                                var itemDto = InventoryDto.Find(a => a.ItemNumber == x);
+                                if (itemDto != null)
+                                {
+                                    ForecastActualDto forecastActualDto = new ForecastActualDto();
+                                    forecastActualDto.ItemNum = x;
+                                    forecastActualDto.GroupBy = itemDto.Series;
+                                    forecastActualDto.StockTurnOver = itemDto.GKMonthlyDemand + itemDto.HWMonthlyDemand == 0 ? 0 : decimal.Ceiling((itemDto.GKInv + itemDto.HWInv) / (itemDto.GKMonthlyDemand + itemDto.HWMonthlyDemand));
+                                    //月度发货计划找不到可以去月度发货计划历史表按照版本号找,暂不处理
+                                    forecastActualDto.M1Plan = 0;
+                                    forecastActualDto.M2Plan = 0;
+                                    if (shipPlan.Any(a => a.PlanMonth == DateTime.Now.AddMonths(-1).ToString("yyyy-MM")))
+                                    {
+                                        forecastActualDto.M1Plan = shipPlan.Find(a => a.PlanMonth == DateTime.Now.AddMonths(-1).ToString("yyyy-MM")).Qty;
+                                    }
+                                    if (shipPlan.Any(a => a.PlanMonth == DateTime.Now.ToString("yyyy-MM")))
+                                    {
+                                        forecastActualDto.M2Plan = shipPlan.Find(a => a.PlanMonth == DateTime.Now.ToString("yyyy-MM")).Qty;
+                                    }
+                                    forecastActualDto.M1Real = rqShip.Where(a => a.ContainerItem == itemNum && a.CreateTime >= DateTime.Now.AddMonths(-2) && a.CreateTime < DateTime.Now.AddMonths(-1)).Sum(b => b.QtyToShip.Value);
+                                    forecastActualDto.M2Real = rqShip.Where(a => a.ContainerItem == itemNum && a.CreateTime >= DateTime.Now.AddMonths(-1) && a.CreateTime < DateTime.Now).Sum(b => b.QtyToShip.Value);
+                                    forecastActualDto.M1Diff = (forecastActualDto.M1Plan == 0 || forecastActualDto.M1Real == 0) ? "100%" : $"{decimal.Ceiling(forecastActualDto.M1Real / forecastActualDto.M1Plan)}%";
+                                    forecastActualDto.M2Diff = (forecastActualDto.M2Plan == 0 || forecastActualDto.M2Real == 0) ? "100%" : $"{decimal.Ceiling(forecastActualDto.M2Real / forecastActualDto.M2Plan)}%";
+                                    modelMonthOuts.Add(forecastActualDto);
+                                }
+                            });
+                        }
+                        break;
+                    case "H":
+                        break;
+                    case "A":
+                        break;
+                    default:
+                        break;        
+                }
+            }else
+            {
+
+            }
+            return JsonConvert.SerializeObject(modelMonthOuts);
+        }
+
         public string CalcInvDayHist(string domain)
         {
             string sql = $"select distinct ItemNum,Min(CreateTime) AS HistMinTime from InvTransHist where Domain='{domain}' group by ItemNum";
             var InvTransHistDto = _businessDbContext.InvTransHistDayDto.FromSqlRaw(sql).ToList();
 
-            string invHistTime = $"select A.ItemNum,Sum((case when a.QtyChange>0 then a.QtyChange else 0 end)) as QtyChangeAdvance,Sum((case when a.QtyChange<0 then abs(a.QtyChange) else 0 end)) as QtyChangeOut,CONVERT(varchar,a.createTime, 23) AS createTime from InvTransHist A where Domain='{domain}'  group by ItemNum,CONVERT(varchar,a.createTime, 23)";
+            string invHistTime = $"select A.ItemNum,Sum((case when a.QtyChange>0 then a.QtyChange else 0 end)) as QtyChangeAdvance,Sum((case when a.QtyChange<0 then abs(a.QtyChange) else 0 end)) as QtyChangeOut,CONVERT(varchar,a.createTime, 23) AS createTime from InvTransHist A where Domain='{domain}' group by ItemNum,CONVERT(varchar,a.createTime, 23)";
             var InvTransHistDetailDto = _businessDbContext.InvTransHistDetailDto.FromSqlRaw(invHistTime).ToList();
 
             string sqlMaxTime = $"select t1.* from InvTransHistDay t1 inner join (SELECT max(HistDayTime) as HistDayTime, ItemNum FROM InvTransHistDay where Domain='{domain}' group by ItemNum) t2 on t1.HistDayTime=t2.HistDayTime and t1.ItemNum=t2.ItemNum and t1.Domain='{domain}'";

+ 2 - 0
MicroServices/Business/Business.EntityFrameworkCore/EntityFrameworkCore/DOP/BusinessDbContext.cs

@@ -65,6 +65,8 @@ namespace Business.EntityFrameworkCore
         public DbSet<QtyChangeDto> QtyChangeDto { get; set; }
 
         public DbSet<BalanceNumDto> BalanceNumDto { get; set; }
+
+        public DbSet<InventoryDto> InventoryDto { get; set; }
         #endregion
         #region MES
         public DbSet<mes_producedailyplan> mes_Producedailyplans { get; set; }

+ 22 - 0
MicroServices/Business/Business.HttpApi/Controllers/VSMController.cs

@@ -119,6 +119,28 @@ namespace Business.Controllers
 
 
         /// <summary>
+        /// 终端出货趋势列表
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet]
+        [Route("chartlineoutstock")]
+        public string ChartLineOutStock(string factory_id, string model)
+        {
+            return _VSMAppService.ChartLineOutStock(factory_id, model);
+        }
+
+        /// <summary>
+        /// 月度发货计划预测实际对比
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet]
+        [Route("forecastactual")]
+        public string ForecastActual(string factory_id, string isItemNum,string itemNumRange,string itemNum,string groupBy)
+        {
+            return _VSMAppService.ForecastActual(factory_id,isItemNum,itemNumRange,itemNum,groupBy);
+        }
+
+        /// <summary>
         /// 每日计算进出存快照
         /// </summary>
         /// <returns></returns>