Ver código fonte

Merge branch 'dev' of http://123.60.180.165:4647/ZZYDOP/DOPCore into dev

heteng 2 anos atrás
pai
commit
35fa52f156
24 arquivos alterados com 2312 adições e 145 exclusões
  1. 69 0
      MicroServices/Business/Business.Application.Contracts/Dto/BindingSubstituteDto.cs
  2. 30 0
      MicroServices/Business/Business.Application.Contracts/Dto/EOPDto.cs
  3. 240 0
      MicroServices/Business/Business.Application.Contracts/Dto/MonthlyShipmentPlanDto.cs
  4. 17 0
      MicroServices/Business/Business.Application.Contracts/ResourceExamineManagement/IResourceExamineAppService.cs
  5. 20 0
      MicroServices/Business/Business.Application.Contracts/SaleForecast/IAnnualProductionOutlineAppService.cs
  6. 1 0
      MicroServices/Business/Business.Application/Business.Application.csproj
  7. 63 68
      MicroServices/Business/Business.Application/ResourceExamineManagement/CalcBomViewAppService.cs
  8. 792 15
      MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs
  9. 198 0
      MicroServices/Business/Business.Application/SaleForecastManagement/AnnualProductionOutlineAppService.cs
  10. 1 9
      MicroServices/Business/Business.Application/SaleForecastManagement/MonthlyCapacityLoadAppService.cs
  11. 123 0
      MicroServices/Business/Business.Domain/StructuredDB/MES/IC/ASNBOLShipperDetail.cs
  12. 78 0
      MicroServices/Business/Business.Domain/StructuredDB/MES/IC/InvTransHist.cs
  13. 12 0
      MicroServices/Business/Business.Domain/StructuredDB/MES/IC/ItemMaster.cs
  14. 2 2
      MicroServices/Business/Business.Domain/StructuredDB/Production/RoutingOpDetail.cs
  15. 285 0
      MicroServices/Business/Business.Domain/StructuredDB/Replenishment/ReplenishmentModel.cs
  16. 97 0
      MicroServices/Business/Business.Domain/StructuredDB/SaleFcst/AnnualProductionOutline.cs
  17. 94 0
      MicroServices/Business/Business.Domain/StructuredDB/SaleFcst/ProductionMasterPlan.cs
  18. 40 23
      MicroServices/Business/Business.Domain/StructuredDB/SaleFcst/YearDemandManagement.cs
  19. 48 28
      MicroServices/Business/Business.Domain/StructuredDB/SaleFcst/YearDemandManagementHistory.cs
  20. 5 0
      MicroServices/Business/Business.Domain/StructuredDB/WMS/WMS_PlatformInventory.cs
  21. 7 0
      MicroServices/Business/Business.EntityFrameworkCore/EntityFrameworkCore/BusinessDbContextModelCreatingExtensions.cs
  22. 16 0
      MicroServices/Business/Business.EntityFrameworkCore/EntityFrameworkCore/DOP/BusinessDbContext.cs
  23. 38 0
      MicroServices/Business/Business.HttpApi/Controllers/AnnualProductionOutlineController.cs
  24. 36 0
      MicroServices/Business/Business.HttpApi/Controllers/ResourceExamineController.cs

+ 69 - 0
MicroServices/Business/Business.Application.Contracts/Dto/BindingSubstituteDto.cs

@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.Dto
+{
+    public class BindingSubstituteDto
+    {
+        /// <summary>
+        /// BOM主键
+        /// </summary>
+        public long id { get; set; }
+
+        /// <summary>
+        /// 替代方案编码
+        /// </summary>
+        public string bom_number { get; set; }
+
+        /// <summary>
+        /// bom明细
+        /// </summary>
+        public List<BomDetails> bomDetail { get; set; }
+
+        /// <summary>
+        /// 租户ID
+        /// </summary>
+        public long? tenant_id { get; set; }
+
+        /// <summary>
+        /// 公司ID
+        /// </summary>
+        public long? company_id { get; set; }
+
+        /// <summary>
+        /// 工厂ID
+        /// </summary>
+        public long? factory_id { get; set; }
+
+        // <summary>
+        /// 用户id
+        /// </summary>
+        public long create_by { get; set; }
+
+        // <summary>
+        /// 用户名称
+        /// </summary>
+        public string create_by_name { get; set; }
+    }
+
+    public class BomDetails
+    {
+        /// <summary>
+        /// 替代明细主键
+        /// </summary>
+        public long? id { get; set; }
+
+        /// <summary>
+        /// 替代料编码
+        /// </summary>
+        public string icitem_number { get; set; }
+
+        /// <summary>
+        /// 替代方案
+        /// </summary>
+        public string substitute_code { get; set; }
+    }
+}

+ 30 - 0
MicroServices/Business/Business.Application.Contracts/Dto/EOPDto.cs

@@ -0,0 +1,30 @@
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.Dto
+{
+    /// <summary>
+    /// EOP
+    /// </summary>
+    public class EOPDto
+    {
+        /// <summary>
+        /// 物料编码
+        /// </summary>
+        public string ItemNumber { get; set; }
+
+        // <summary>
+        /// EOP
+        /// </summary>
+        public decimal Qty { get; set; }
+
+        /// <summary>
+        /// 销售/渠道   
+        /// </summary>
+        public string distributionchannel { get; set; }
+    }
+}

+ 240 - 0
MicroServices/Business/Business.Application.Contracts/Dto/MonthlyShipmentPlanDto.cs

@@ -0,0 +1,240 @@
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.Dto
+{
+    /// <summary>
+    /// 物料供应提前期
+    /// </summary>
+    public class MonthlyShipmentPlanDto
+    {
+        /// <summary>
+        /// 年    
+        /// </summary>
+        public int Year { get; set; }
+
+        /// <summary>
+        /// 地区    
+        /// </summary>
+        public string Area { get; set; }
+
+        /// <summary>
+        /// 产品线    
+        /// </summary>
+        public string ProdLine { get; set; }
+
+        /// <summary>
+        /// 产品系列    
+        /// </summary>
+        public string ProdRange { get; set; }
+
+        /// <summary>
+        /// 规格型号    
+        /// </summary>
+        public string Model { get; set; }
+
+        /// <summary>
+        /// 计划年月    
+        /// </summary>
+        public string PlanMonth { get; set; }
+
+        /// <summary>
+        /// 数量    
+        /// </summary>
+        public decimal Qty { get; set; }
+
+        /// <summary>
+        /// 排序编码    
+        /// </summary>
+        public int OrderNum { get; set; }
+
+        /// <summary>
+        /// 生命周期    
+        /// </summary>
+        public string LifeCycle { get; set; }
+
+        /// <summary>
+        /// SAP料号   
+        /// </summary>
+        public string SAPItemNumber { get; set; }
+
+        /// <summary>
+        /// 语种   
+        /// </summary>
+        public string Languages { get; set; }
+
+        /// <summary>
+        /// 销售/渠道   
+        /// </summary>
+        public string DistributionChannel { get; set; }
+
+        /// <summary>
+        /// 物料属性
+        /// </summary>
+        [Comment("物料属性")]
+        public int? erp_cls { get; set; }
+
+        /// <summary>
+        /// 供应提前期
+        /// </summary>
+        public decimal? PLT { get; set; }
+
+        /// <summary>
+        /// 是否长周期物料
+        /// </summary>
+        public bool IsLongPeriod { get; set; }
+
+        /// <summary>
+        /// 期初库存
+        /// </summary>
+        [Precision(20, 8)]
+        public decimal? actual_period_start_instock { get; set; }
+
+        /// <summary>
+        /// 计划发货数量
+        /// </summary>
+        [Precision(20, 8)]
+        public decimal? plan_out_qty { get; set; }
+
+        /// <summary>
+        /// 实际发货 为空或-1时表示不适用,为0时表示没有发货记录。注意能区分这两种形式
+        /// </summary>
+        [Precision(20, 8)]
+        public decimal? actual_out_qty { get; set; }
+
+        /// <summary>
+        /// 计划生产
+        /// </summary>
+        [Precision(20, 8)]
+        public decimal? plan_in { get; set; }
+
+        /// <summary>
+        /// 实际生产
+        /// </summary>
+        [Precision(20, 8)]
+        public decimal? actual_in { get; set; }
+
+        /// <summary>
+        /// 计划期末库存
+        /// </summary>
+        [Precision(20, 8)]
+        public decimal? plan_period_end_instock { get; set; }
+
+        /// <summary>
+        /// 实际期末库存
+        /// </summary>
+        [Precision(20, 8)]
+        public decimal? actual_period_end_instock { get; set; }
+
+        /// <summary>
+        /// 月均需求
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("月均需求")]
+        public decimal? monthl_avg_demand { get; set; }
+
+        /// <summary>
+        /// 月均需求标准差
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("月均需求标准差")]
+        public decimal? monthl_avg_demand_variance { get; set; }
+
+        /// <summary>
+        /// 月均出库
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("月均出库")]
+        public decimal? monthl_avg_outstock { get; set; }
+
+        /// <summary>
+        /// 供应前置期参数(天)
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("供应前置期参数(天)")]
+        public decimal? supply_leadtime { get; set; }
+
+
+        /// <summary>
+        /// ABC分类
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("ABC分类")]
+        public string? abc { get; set; }
+
+        /// <summary>
+        /// FMR分类
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("FMR分类")]
+        public string? fmr { get; set; }
+
+        /// <summary>
+        /// Z服务水平参数
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("Z服务水平参数")]
+        public decimal? service_level_pct { get; set; }
+
+        /// <summary>
+        /// 存货周转率
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("存货周转率")]
+        public decimal? stock_turnover { get; set; }
+
+
+        /// <summary>
+        /// 最小包装
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("最小包装")]
+        public decimal? min_pack_qty { get; set; }
+
+        /// <summary>
+        /// 最小批量
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("最小批量")]
+        public decimal? moq { get; set; }
+
+        /// <summary>
+        /// 安全库存
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("安全库存")]
+        public decimal? security_stock { get; set; }
+
+        /// <summary>
+        /// 圆整后供应批量
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("圆整后供应批量")]
+        public decimal? eop { get; set; }
+
+        /// <summary>
+        /// 重新订货点
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("重新订货点")]
+        public decimal? rop_computed { get; set; }
+
+        /// <summary>
+        /// 月均出库最高库存
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("月均出库最高库存")]
+        public decimal? max_stock_level { get; set; }
+
+        /// <summary>
+        /// 修正后重新订货点
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("修正后重新订货点")]
+        public decimal? rop_revised { get; set; }
+    }
+}

+ 17 - 0
MicroServices/Business/Business.Application.Contracts/ResourceExamineManagement/IResourceExamineAppService.cs

@@ -112,5 +112,22 @@ namespace Business.ResourceExamineManagement
         /// <returns></returns>
         Task<string> SubstituteSave(SubstituteDto dto);
 
+        /// <summary>
+        /// BOM关联替代方案
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        Task<string> BindingSubstitute(BindingSubstituteDto dto);
+
+        /// <summary>
+        /// 更新补货模型月度参数
+        /// </summary>
+        Task<string> WeekPlanParms(InputDto input);
+
+        /// <summary>
+        /// 更新周计划
+        /// </summary>
+        Task<string> WeekPlan(InputDto input);
+
     }
 }

+ 20 - 0
MicroServices/Business/Business.Application.Contracts/SaleForecast/IAnnualProductionOutlineAppService.cs

@@ -0,0 +1,20 @@
+using Business.Dto;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Volo.Abp.Application.Services;
+
+namespace Business.SaleForecast
+{
+    public interface IAnnualProductionOutlineAppService : IApplicationService
+    {
+        /// <summary>
+        /// 生成年度生产大纲
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        Task<string> SaveAnnualProductionOutline(InputDto input);
+    }
+}

+ 1 - 0
MicroServices/Business/Business.Application/Business.Application.csproj

@@ -17,6 +17,7 @@
 
   <ItemGroup>
     <PackageReference Include="Magicodes.IE.Pdf" Version="2.7.1" />
+    <PackageReference Include="MathNet.Numerics" Version="5.0.0" />
     <PackageReference Include="NLog" Version="5.1.2" />
     <PackageReference Include="Quartz.AspNetCore" Version="3.6.2" />
     <PackageReference Include="Volo.Abp.AutoMapper" Version="6.0.3" />

+ 63 - 68
MicroServices/Business/Business.Application/ResourceExamineManagement/CalcBomViewAppService.cs

@@ -1225,87 +1225,82 @@ namespace Business.ResourceExamineManagement
         private SRMPRDto CreateSRMPR(BomChildExamineDto returnlist, long? companyId, long factoryid, long bangId, int orderType, List<ICItemLeadTimeDto> iCItemLeadTimes, List<mo_srm_purchase> supplierList, List<mo_ic_item> planList, crm_seorderentry sentrys)
         {
             SRMPRDto sRMPR = new SRMPRDto();
-            var supplier = supplierList.OrderBy(s=>s.quota_priority).ToList();//默认取配额优先级
+            var supplier = supplierList.OrderBy(s => s.quota_priority).FirstOrDefault();//默认取配额优先级
             var plan = planList.Find(x => x.mysql_id == returnlist.item_id);
-            sRMPR.srm_Pr_Main = new List<mo_srm_pr_main>(); 
-            if (!supplier.Any() || plan == null)
+            sRMPR.srm_Pr_Main = new List<mo_srm_pr_main>();
+            if (supplier == null || plan == null)
             {
                 sRMPR.lastStartTmie = DateTime.Now.AddDays(7);//默认采购提前期
                 return sRMPR;
                 //throw new NotImplementedException("未找到物料ic_factory_details或ic_item_pur或ic_plan信息!");
             }
-
-            supplier.ForEach(x =>
+            mo_srm_pr_main srm_Pr = new mo_srm_pr_main();
+            srm_Pr.GenerateNewId(help.NextId());
+            srm_Pr.mysql_id = help.NextId();
+            srm_Pr.pr_billno = returnlist.erp_cls == 2 ? getOrderNum("WWPR") : getOrderNum("PR");//pr单号
+            if (mes_morder != null)
             {
-                mo_srm_pr_main srm_Pr = new mo_srm_pr_main();
-                srm_Pr.GenerateNewId(help.NextId());
-                srm_Pr.mysql_id = help.NextId();
-                srm_Pr.pr_billno = returnlist.erp_cls == 2 ? getOrderNum("WWPR") : getOrderNum("PR");//pr单号
-                if (mes_morder != null)
-                {
-                    srm_Pr.pr_mono = mes_morder.morder_no;//关联工单号
-                    srm_Pr.entity_id = 1;//工单行号
-                }
-                srm_Pr.IsRequireGoods = x.IsRequireGoods;
-                srm_Pr.pr_purchaseid = x.supplier_id;//供应商id  
-                srm_Pr.pr_purchasenumber = x.supplier_number;//供应商编码
-                srm_Pr.pr_purchasename = x.supplier_name;//供应商名称
-                srm_Pr.pr_purchaser = x.purcher;//采购员
-                srm_Pr.pr_purchaser_num = "";//采购员工号(采购信息表)
-                //数量圆整 按最小包装量向上圆整
-                decimal qty = Math.Ceiling(returnlist.lack_qty / (x.packaging_qty.GetValueOrDefault() == 0 ? 1 : x.packaging_qty.GetValueOrDefault()));
-                //判断最小起订量
-                qty = qty > x.qty_min ? qty : x.qty_min.GetValueOrDefault();
-                srm_Pr.pr_rqty = returnlist.lack_qty;//需求数量
-                srm_Pr.pr_aqty = qty;//申请数量
-                srm_Pr.pr_sqty = qty;//建议数量
-                srm_Pr.icitem_id = returnlist.item_id;//物料id
-                srm_Pr.icitem_name = returnlist.item_name;//物料名称
-                srm_Pr.num = returnlist.num;
-                var tomorrow = DateTime.Now.Date.AddDays(1);
-                srm_Pr.pr_order_type = 1;//单据类型
-                srm_Pr.pr_ssend_date = tomorrow;//系统建议下单日期
-                srm_Pr.pr_sarrive_date = DateTime.Now.AddDays((double)plan.order_leadtime).AddDays((double)plan.transportation_leadtime);//系统建议到达日期(建议到货日期)
-                srm_Pr.pr_psend_date = tomorrow;//计划下单日期
-                srm_Pr.pr_parrive_date = DateTime.Now.AddDays((double)plan.order_leadtime).AddDays((double)plan.transportation_leadtime);//计划到达日期
-                srm_Pr.pr_rarrive_date = DateTime.Now.AddDays((double)plan.order_leadtime).AddDays((double)plan.transportation_leadtime);//需求到货日期
-                srm_Pr.pr_sysprice = x.order_price;//系统价格(含税)
-                srm_Pr.pr_orderprice = qty * x.order_price;//订单价格(含税)
-                srm_Pr.pr_price = x.netpurchase_price;//采购净价(不含税)
-                /*srm_Pr.pr_sysprice = qty * x.netpurchase_price * (1 + x.taxrate);//系统价格(含税)
-                srm_Pr.pr_orderprice = qty * x.netpurchase_price * (1 + x.taxrate);//订单价格(含税)
-                srm_Pr.pr_price = x.netpurchase_price;//采购净价(不含税)*/
-                srm_Pr.pr_rate = x.taxrate;//税率
-                srm_Pr.pr_unit = returnlist.unit;//单位
-                srm_Pr.state = 1;//状态
-                srm_Pr.old_apply_aqty = 0;//已申请数量
-                srm_Pr.pr_type = orderType;//申请类型
-                srm_Pr.currencytype = x.currency_type == null ? 1 : x.currency_type.Value;//币种
-                srm_Pr.secInv_ratio = plan.secinv_ratio;//安全库存触发采购比例
-                srm_Pr.tenant_id = companyId.GetValueOrDefault();
-                srm_Pr.company_id = companyId;
-                srm_Pr.factory_id = factoryid;
-                srm_Pr.bang_id = bangId;
-                if (sentrys != null)
-                {
-                    srm_Pr.sentry_id = sentrys.Id;
-                }
-                //_srm_pr_main.InsertOne(srm_Pr);
-                decimal? totalLeadTime = plan.transportation_leadtime + plan.stock_leadtime + plan.production_leadtime + plan.order_leadtime;
-                srm_Pr.totalLeadTime= totalLeadTime;
-                srm_Pr.create_time = DateTime.Now;
-                srm_Pr.create_by_name = "admin";
-                srm_Pr.update_time = DateTime.Now;
-                srm_Pr.update_by_name = "admin";
-                sRMPR.srm_Pr_Main.Add(srm_Pr);
-            });
+                srm_Pr.pr_mono = mes_morder.morder_no;//关联工单号
+                srm_Pr.entity_id = 1;//工单行号
+            }
+            srm_Pr.IsRequireGoods = supplier.IsRequireGoods;
+            srm_Pr.pr_purchaseid = supplier.supplier_id;//供应商id  
+            srm_Pr.pr_purchasenumber = supplier.supplier_number;//供应商编码
+            srm_Pr.pr_purchasename = supplier.supplier_name;//供应商名称
+            srm_Pr.pr_purchaser = supplier.purcher;//采购员
+            srm_Pr.pr_purchaser_num = "";//采购员工号(采购信息表)
+                                         //数量圆整 按最小包装量向上圆整
+            decimal qty = Math.Ceiling(returnlist.lack_qty / (supplier.packaging_qty.GetValueOrDefault() == 0 ? 1 : supplier.packaging_qty.GetValueOrDefault()));
+            //判断最小起订量
+            qty = qty > supplier.qty_min ? qty : supplier.qty_min.GetValueOrDefault();
+            srm_Pr.pr_rqty = returnlist.lack_qty;//需求数量
+            srm_Pr.pr_aqty = qty;//申请数量
+            srm_Pr.pr_sqty = qty;//建议数量
+            srm_Pr.icitem_id = returnlist.item_id;//物料id
+            srm_Pr.icitem_name = returnlist.item_name;//物料名称
+            srm_Pr.num = returnlist.num;
+            var tomorrow = DateTime.Now.Date.AddDays(1);
+            srm_Pr.pr_order_type = 1;//单据类型
+            srm_Pr.pr_ssend_date = tomorrow;//系统建议下单日期
+            srm_Pr.pr_sarrive_date = DateTime.Now.AddDays((double)plan.order_leadtime).AddDays((double)plan.transportation_leadtime);//系统建议到达日期(建议到货日期)
+            srm_Pr.pr_psend_date = tomorrow;//计划下单日期
+            srm_Pr.pr_parrive_date = DateTime.Now.AddDays((double)plan.order_leadtime).AddDays((double)plan.transportation_leadtime);//计划到达日期
+            srm_Pr.pr_rarrive_date = DateTime.Now.AddDays((double)plan.order_leadtime).AddDays((double)plan.transportation_leadtime);//需求到货日期
+            srm_Pr.pr_sysprice = supplier.order_price;//系统价格(含税)
+            srm_Pr.pr_orderprice = qty * supplier.order_price;//订单价格(含税)
+            srm_Pr.pr_price = supplier.netpurchase_price;//采购净价(不含税)
+            /*srm_Pr.pr_sysprice = qty * x.netpurchase_price * (1 + x.taxrate);//系统价格(含税)
+            srm_Pr.pr_orderprice = qty * x.netpurchase_price * (1 + x.taxrate);//订单价格(含税)
+            srm_Pr.pr_price = x.netpurchase_price;//采购净价(不含税)*/
+            srm_Pr.pr_rate = supplier.taxrate;//税率
+            srm_Pr.pr_unit = returnlist.unit;//单位
+            srm_Pr.state = 1;//状态
+            srm_Pr.old_apply_aqty = 0;//已申请数量
+            srm_Pr.pr_type = orderType;//申请类型
+            srm_Pr.currencytype = supplier.currency_type == null ? 1 : supplier.currency_type.Value;//币种
+            srm_Pr.secInv_ratio = plan.secinv_ratio;//安全库存触发采购比例
+            srm_Pr.tenant_id = companyId.GetValueOrDefault();
+            srm_Pr.company_id = companyId;
+            srm_Pr.factory_id = factoryid;
+            srm_Pr.bang_id = bangId;
+            if (sentrys != null)
+            {
+                srm_Pr.sentry_id = sentrys.Id;
+            }
+            decimal? totalLeadTime = plan.transportation_leadtime + plan.stock_leadtime + plan.production_leadtime + plan.order_leadtime;
+            srm_Pr.totalLeadTime = totalLeadTime;
+            srm_Pr.create_time = DateTime.Now;
+            srm_Pr.create_by_name = "admin";
+            srm_Pr.update_time = DateTime.Now;
+            srm_Pr.update_by_name = "admin";
+            sRMPR.srm_Pr_Main.Add(srm_Pr);
             if (sRMPR.srm_Pr_Main.Any())
             {
                 sRMPR.srm_Pr_Main.OrderBy(x => x.totalLeadTime.GetValueOrDefault()).ThenBy(x => x.pr_orderprice.GetValueOrDefault()).First().isbestoptions = true;
             }
             sRMPR.item_no = returnlist.num;
             sRMPR.orderentry_id = returnlist.sentry_id;
-            sRMPR.lastStartTmie = DateTime.Now.AddDays((double)(sRMPR.srm_Pr_Main.MinBy(x=>x.totalLeadTime).totalLeadTime.GetValueOrDefault()+plan.clean_leadtime.GetValueOrDefault()));//加上提前期和备料期,得到齐套时间
+            sRMPR.lastStartTmie = DateTime.Now.AddDays((double)(sRMPR.srm_Pr_Main.MinBy(x => x.totalLeadTime).totalLeadTime.GetValueOrDefault() + plan.clean_leadtime.GetValueOrDefault()));//加上提前期和备料期,得到齐套时间
             return sRMPR;
         }
         // 生成订单编号 字母+年月日+8位随机数+时间戳

+ 792 - 15
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -7,6 +7,7 @@ using Business.EntityFrameworkCore;
 using Business.EntityFrameworkCore.SqlRepositories;
 using Business.PriorityManagement;
 using Business.ResourceExamineManagement.Dto;
+using Business.StructuredDB.SaleFcst;
 using Business.StructuredDB.WMS;
 using EFCore.BulkExtensions;
 using Microsoft.EntityFrameworkCore;
@@ -362,6 +363,18 @@ namespace Business.ResourceExamineManagement
         /// </summary>
         public List<HolidayMaster> holidays = new List<HolidayMaster>();
         private readonly IUnitOfWorkManager _unitOfWorkManager;
+
+        /// <summary>
+        /// 补货模型
+        /// </summary>
+        private IRepository<ReplenishmentModel, long> _replenishmentModel;
+        private IRepository<DomesticTerminalFcst, long> _domesticTerminalFcst;
+        private ISqlRepository<ASNBOLShipperDetail> _ASNBOLShipperDetail;
+        private IRepository<StandardItemModelSet, long> _standardItemModelSet;
+        private ISqlRepository<InvTransHist> _invTransHist;
+        private ISqlRepository<SAPInv> _SAPInv;
+        private IRepository<srm_purchase, long> _srmPurchase;
+        private ISqlRepository<MonthlyShipmentPlan> _monthlyShipmentPlan;
         #endregion
 
         #region 构造函数
@@ -455,10 +468,18 @@ namespace Business.ResourceExamineManagement
             ISqlRepository<ItemPackMaster> itemPackMaster,
             ISqlRepository<GeneralizedCodeMaster> generalizedCodeMaster,
             ISqlRepository<ScheduleResultOpMaster> scheduleResultOpMaster,
-            IUnitOfWorkManager unitOfWorkManager,
             IRepository<ic_substitute, long> mysql_ic_substitute,
             IRepository<ic_substitute_group, long> mysql_ic_substitute_group,
-            IRepository<ic_substitute_group_detail, long> mysql_ic_substitute_group_detail
+            IRepository<ic_substitute_group_detail, long> mysql_ic_substitute_group_detail,
+            IRepository<ReplenishmentModel, long> replenishmentModel,
+            IRepository<DomesticTerminalFcst, long> domesticTerminalFcst,
+            ISqlRepository<ASNBOLShipperDetail> ASNBOLShipperDetail,
+            IRepository<StandardItemModelSet, long> standardItemModelSet,
+            ISqlRepository<InvTransHist> invTransHist,
+            ISqlRepository<SAPInv> SAPInv,
+            ISqlRepository<MonthlyShipmentPlan> monthlyShipmentPlan,
+            IRepository<srm_purchase, long> srmPurchase,
+            IUnitOfWorkManager unitOfWorkManager
             )
         {
             _mes_technique = mes_technique;
@@ -546,6 +567,14 @@ namespace Business.ResourceExamineManagement
             _generalizedCodeMaster = generalizedCodeMaster;
             _unitOfWorkManager = unitOfWorkManager;
             _scheduleResultOpMaster = scheduleResultOpMaster;
+            _replenishmentModel = replenishmentModel;
+            _domesticTerminalFcst = domesticTerminalFcst;
+            _standardItemModelSet = standardItemModelSet;
+            _invTransHist = invTransHist;
+            _SAPInv = SAPInv;
+            _monthlyShipmentPlan = monthlyShipmentPlan;
+            _srmPurchase = srmPurchase;
+            _businessDbContext = businessDbContext;
         }
         #endregion
 
@@ -3768,7 +3797,7 @@ namespace Business.ResourceExamineManagement
                 var exm = exmResult.Find(s => s.morder_id == item.Id);
                 if (exm != null)
                 {
-                    var childs = childExamineList.Where(s => s.examine_id == exm.Id).ToList();
+                    var childs = childExamineList.Where(s => s.examine_id == exm.Id && s.is_use == true).ToList();
                     List<b_bom_child_examine> returnList = new List<b_bom_child_examine>();
                     GetWorkDetalis(childs.Where(s => s.level == 2).ToList(), returnList, childs);
                     if (returnList.Any())
@@ -3929,7 +3958,6 @@ namespace Business.ResourceExamineManagement
             _productExamineAppService.CalcSuggestTime(sentrys, kittingTimes, icitemlist);
         }
 
-
         /// <summary>
         /// 替代方案保存
         /// </summary>
@@ -3955,8 +3983,8 @@ namespace Business.ResourceExamineManagement
                 stt.substitute_code = dto.scode;
                 stt.substitute_mode = dto.smode;
                 stt.substitute_strategy = dto.sstrategy;
-                stt.create_by= dto.create_by;
-                stt.create_by_name= dto.create_by_name;
+                stt.create_by = dto.create_by;
+                stt.create_by_name = dto.create_by_name;
                 stt.create_time = DateTime.Now;
                 stt.update_by = dto.create_by;
                 stt.update_by_name = dto.create_by_name;
@@ -3991,16 +4019,17 @@ namespace Business.ResourceExamineManagement
                     }
                 }
             }
-            else {
+            else
+            {
                 //修改
                 stt = _mysql_ic_substitute.FirstAsync(s => s.Id == dto.id.Value).Result;
                 if (stt != null)
                 {
-                    if (_mysql_ic_substitute.GetListAsync(s => s.Id != dto.id && s.substitute_code == dto.scode && s.company_id==dto.company_id && s.factory_id==dto.factory_id).Result.Count > 0)
+                    if (_mysql_ic_substitute.GetListAsync(s => s.Id != dto.id && s.substitute_code == dto.scode && s.company_id == dto.company_id && s.factory_id == dto.factory_id).Result.Count > 0)
                     {
                         return "已存在【" + dto.scode + "】替代方案。";
                     }
-                    if (_ic_bom_child.GetListAsync(s => s.substitute_code == stt.substitute_code).Result.Count() > 0)
+                    if (_mysql_ic_bom_child.GetListAsync(s => s.substitute_code == stt.substitute_code).Result.Count() > 0)
                     {
                         return "替代方案已被关联使用,不允许修改。";
                     }
@@ -4053,11 +4082,12 @@ namespace Business.ResourceExamineManagement
                         }
                     }
                 }
-                else {
+                else
+                {
                     return "当前方案已被删除,请刷新重试。";
                 }
             }
-            
+
         }
 
         /// <summary>
@@ -4079,16 +4109,22 @@ namespace Business.ResourceExamineManagement
             {
                 return "请设置替代方案里的替代件。";
             }
-            if (dto.srows.Select(s => s.field_f8988ed2955a264f8f762faaed2c5f6a.GetValueOrDefault()).Count() <2)
+            if (dto.srows.Select(s => s.field_f8988ed2955a264f8f762faaed2c5f6a.GetValueOrDefault()).Count() < 2)
             {
                 return "替代方案最低存在两个优先级。";
             }
             //判断同一个优先级里,相同是否标准料
-            //dto.srows.GroupBy(i => new { i.field_f8988ed2955a264f8f762faaed2c5f6a.GetValueOrDefault(), i.field_83817a9f5a15a4f78686105c694b0a39.GetValueOrDefault(), })//.Where(g => g.Count() > 1).Count() > 0;
-            if (dto.srows.GroupBy(s => new { s.field_f8988ed2955a264f8f762faaed2c5f6a, s.field_83817a9f5a15a4f78686105c694b0a39 }).Where(g => g.Count() > 1).Count() > 0)
+            foreach (var r in dto.srows)
             {
-                return "同优先级群组里不允许既有标准件又有替代件。";
+                if (dto.srows.Where(s => s.field_f8988ed2955a264f8f762faaed2c5f6a == r.field_f8988ed2955a264f8f762faaed2c5f6a && s.field_83817a9f5a15a4f78686105c694b0a39 != r.field_83817a9f5a15a4f78686105c694b0a39).Count() > 0)
+                {
+                    return "同优先级群组里不允许既有标准件又有替代件。";
+                }
             }
+            /*if (dto.srows.GroupBy(s => new { s.field_f8988ed2955a264f8f762faaed2c5f6a, s.field_83817a9f5a15a4f78686105c694b0a39 }).Where(g => g.Count() > 1).Count() > 0)
+            {
+                return "同优先级群组里不允许既有标准件又有替代件。";
+            }*/
             return "ok";
         }
 
@@ -4155,5 +4191,746 @@ namespace Business.ResourceExamineManagement
             await _productionScheduleAppService.DoProductSchedule(workOrds, domain, 2);
             return "ok";
         }
+
+        /// <summary>
+        /// BOM关联替代方案
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        public async Task<string> BindingSubstitute(BindingSubstituteDto dto)
+        {
+            var list = _mysql_ic_bom_child.GetListAsync(s => s.bom_id == dto.id && s.tenant_id == dto.tenant_id && s.company_id == dto.company_id && s.factory_id == dto.factory_id).Result;
+
+            if (dto.bomDetail.Any())
+            {
+                list.ForEach(s => { s.substitute_code = ""; s.haveicsubs = 0; });
+                var codeList = dto.bomDetail.Where(s => string.IsNullOrEmpty(s.substitute_code) == false).Select(x => x.substitute_code).Distinct().ToList();
+                if (codeList.Any())
+                {
+                    var subGdtls = _mysql_ic_substitute_group.GetListAsync(s => s.tenant_id == dto.tenant_id && s.company_id == dto.company_id && s.factory_id == dto.factory_id && codeList.Contains(s.substitute_code)).Result;
+                    var subDetalis = _mysql_ic_substitute_group_detail.GetListAsync(s => s.tenant_id == dto.tenant_id && s.company_id == dto.company_id && s.factory_id == dto.factory_id && codeList.Contains(s.substitute_code)).Result;
+                    foreach (var code in codeList)
+                    {
+                        var g = subGdtls.Find(s => s.substitute_code == code && s.main_material == 1);
+                        if (g != null)
+                        {
+                            var dtls = subDetalis.Where(s => s.substitute_group_id == g.Id).ToList();
+                            foreach (var dtl in dtls)
+                            {
+                                var l = list.Find(s => s.item_number == dtl.icitem_number && s.qty == dtl.replace_qty);
+                                if (l == null)
+                                {
+                                    return "当前替代方案【" + code + "】的标准件未找到相同数量相同物料的BOM明细。";
+                                }
+                                if (string.IsNullOrEmpty(l.substitute_code))
+                                {
+                                    l.haveicsubs = 1;
+                                    l.substitute_code = code;
+                                }
+                                else
+                                {
+                                    return "当前替代方案【" + code + "】的标准件【" + l.item_number + "】与替代方案【" + l.substitute_code + "】冲突。";
+                                }
+                            }
+                        }
+                        else
+                        {
+                            return "当前替代方案【" + code + "】未设置标准件。";
+                        }
+                    }
+                }
+                await _mysql_ic_bom_child.UpdateManyAsync(list);
+            }
+            return "ok";
+        }
+
+        public async Task<string> WeekPlan(InputDto input)
+        {
+
+            //1.获取补货模型全局参数
+            ReplenishmentDto replenishmentDto = GetROPParam();
+
+            //到了配置的更新时间才更新
+            if (DateTime.Now.Day != replenishmentDto.SaleFcstEntryDate)
+                return "不在更新时间日期";
+
+
+            //获取月度发货计划
+            string planMonth = $"{DateTime.Now.AddMonths(1).Year}-{DateTime.Now.AddMonths(months: 1).Month}";
+            var planList = _monthlyShipmentPlan.Select(a => a.PlanMonth == planMonth && !a.IsDeleted);
+            var monthPlanList = ObjectMapper.Map<List<MonthlyShipmentPlan>, List<MonthlyShipmentPlanDto>>(planList);
+            var itemList = _ic_item.GetListAsync(a => planList.Select(p => p.SAPItemNumber).Contains(a.number) && a.tenant_id == input.tenant_id && a.company_id == input.company_id && !a.IsDeleted).Result;
+            var mesItemList = _itemMaster.Select(a => planList.Select(p => p.SAPItemNumber).Contains(a.ItemNum) && a.Domain == input.factory_id.ToString() && a.IsActive);
+            var srm_purchaseList = _srmPurchase.GetListAsync(a => planList.Select(p => p.SAPItemNumber).Contains(a.number) && a.tenant_id == input.tenant_id && a.company_id == input.company_id && !a.IsDeleted).Result;
+            //获取补货模型前一个周期和未来N个周期的数据
+            var ropModelList = _replenishmentModel.GetListAsync(a => a.zero_based_seqno >= 0 && a.zero_based_seqno <= replenishmentDto.UpdateWeeks).Result;
+            //发货计划物料列表
+            List<string> planItemList = planList?.Select(a => a.SAPItemNumber).ToList();
+            //补货模型物料列表
+            List<string> ropItemList = ropModelList?.Where(c => c.zero_based_seqno == 0).Select(a => a.number).ToList();
+            //第一次算或者新品物料列表
+            List<string> nohistoryItemList = planItemList.Except(ropItemList).ToList();
+            var sapItemInv = _SAPInv.Select(a => nohistoryItemList.Contains(a.MATNR) && a.WERKS == input.factory_id.ToString());
+
+
+
+            //取上一个月发货出库记录
+            var shipList = _ASNBOLShipperDetail.Select(a => a.Domain == input.factory_id.ToString() && a.IsActive && a.shtype == "SH" && a.Typed != "S" && a.ShipDate >= getMonthStartTime(-1) && a.ShipDate <= getMonthEndTime(-1) && a.RealQty > 0 && planItemList.Contains(a.ContainerItem));
+
+            //按照物料分组统计出货金额
+            var itemGroup = shipList.GroupBy(p => p.ContainerItem)
+                 .Select(p => new ASNBOLShipperDetail
+                 {
+                     QtyToShip = p.Sum(a => a.QtyToShip),
+                     ContainerItem = p.Key
+                 }).ToList();
+
+            monthPlanList?.ForEach(a =>
+            {
+                //物料属性:0.配置类 1.自制 2.委外加工 3.外购 4.虚拟件
+                a.erp_cls = itemList.Find(s => s.number == a.SAPItemNumber)?.erp_cls;
+                if (mesItemList.Find(s => s.ItemNum == a.SAPItemNumber) != null)
+                {
+                    a.stock_turnover = mesItemList.Find(s => s.ItemNum == a.SAPItemNumber).StockTurnOver;
+                    a.PLT = mesItemList.Find(s => s.ItemNum == a.SAPItemNumber)?.PurLT;
+                    a.IsLongPeriod = a.PLT >= replenishmentDto.LongPeriodDay;
+                }
+                else
+                {
+                    a.stock_turnover = 4;
+                }
+                if (srm_purchaseList.Find(s => s.number == a.SAPItemNumber) != null)
+                {
+                    a.PLT = srm_purchaseList.Find(s => s.number == a.SAPItemNumber).lead_time;
+                    a.IsLongPeriod = a.PLT >= replenishmentDto.LongPeriodDay;
+                }
+                //存在物料该物料编码表示之前算过,否则表示第一次算或者是新品
+                //之前算过,取算法模型数据,不存在表示第一次算要取默认值
+                if (ropModelList != null && ropModelList.Any(a => a.zero_based_seqno == 0))
+                {
+                    a.actual_period_start_instock = 0;
+                }
+                else
+                {
+                    if (sapItemInv.Find(s => s.MATNR == a.SAPItemNumber) != null)
+                    {
+                        a.actual_period_start_instock = Convert.ToDecimal(sapItemInv.Find(s => s.MATNR == a.SAPItemNumber).LABST);
+                    }
+                    else
+                    {
+                        a.actual_period_start_instock = 0;
+                    }
+                }
+            });
+
+
+            //第一周需要更新参数,其他周不要更新
+            if (WeekOfMonth(DateTime.Now, 1) == 1)
+            {
+
+            }
+            //每算一次都要把所有zero_based_seqno减去1
+
+
+
+            List<DomesticTerminalFcst> domesticFcst = _domesticTerminalFcst.GetListAsync(p => p.TypeEnum == 2 && p.Year == input.year && p.Month == input.month
+            && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id && !p.IsDeleted).Result;
+
+            var modelList = domesticFcst?.Select(a => a.Model);
+            var ItemModelSetList = _standardItemModelSet.GetListAsync(a => a.tenant_id == input.tenant_id && a.company_id == input.company_id && modelList.Contains(a.Model) && !a.IsDeleted).Result;
+            if (ItemModelSetList == null)
+            {
+                return "库存数据不存在";
+            }
+            var itemNumList = ItemModelSetList?.Select(a => a.ItemNumber).ToList();
+            List<mo_ic_bom> boms = _ic_bom.GetListAsync(p => itemNumList.Contains(p.item_number) && p.factory_id == input.factory_id && p.company_id == input.company_id && !p.IsDeleted).Result.ToList();
+            var pretreatments = _mysql_b_bom_pretreatment.GetListAsync(s => boms.Select(c => c.mysql_id).ToList().Contains(s.sourceid)).Result;
+            List<mo_ic_bom> autoCreates = new List<mo_ic_bom>();
+            boms.ForEach(p =>
+            {
+                if (!pretreatments.Where(s => s.sourceid == p.mysql_id).Any())
+                {
+                    autoCreates.Add(p);
+                }
+            });
+            if (autoCreates.Any())
+            {
+                AutoCreateBomBill(input.company_id.ToString(), autoCreates);
+                pretreatments = _mysql_b_bom_pretreatment.GetListAsync(s => boms.Select(c => c.mysql_id).ToList().Contains(s.sourceid)).Result;
+            }
+
+
+            return "OK";
+        }
+
+        /// <summary>
+        /// 每月15号更新周计划参数(考虑多次执行的情况)
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        public async Task<string> WeekPlanParms(InputDto input)
+        {
+            //1.获取补货模型全局参数
+            ReplenishmentDto replenishmentDto = GetROPParam();
+
+            //到了配置的更新时间才更新
+            if (DateTime.Now.Day != replenishmentDto.SaleFcstEntryDate)
+                return "不在更新时间日期";
+
+            //Step1:按照瑞奇、两大平台分别根据历史出库数据和预测出货数据计算ROP
+            //Step2:计算瑞奇的M-M+2共12周补货(每次补EOP/4),计算海王的M-M+2共12周补货(每次补EOP/4),计算国科的M-M+2共12周补货(每次补EOP/4)
+            //Step3:汇总Step2所有补货,为工厂的制造需求
+            //Step4:按照Step3制造需求做资源检查,按月统计各物料消耗预测
+            //Step5:按照各SKU的历史出库数据和Step4里计算的预测消耗数量计算参数
+            //Step6:计算各SKU的12周采购补货
+
+
+
+            //获取月度发货计划(一次导入三个月的销售预测),因为是固定格式yyyy-MM所以可以用字符串比较,避免写很多字符串判断相等
+            string planMonth = $"{DateTime.Now.Year}-{DateTime.Now.Month.ToString("00")}";
+            string planMonthMax = $"{DateTime.Now.AddMonths(replenishmentDto.SaleFcstMonth).Year}-{DateTime.Now.AddMonths(replenishmentDto.SaleFcstMonth).Month.ToString("00")}";
+            var planList = _monthlyShipmentPlan.Select(a => a.PlanMonth.CompareTo(planMonth) >= 0 && a.PlanMonth.CompareTo(planMonthMax) <= 0 && !a.IsDeleted).ToList();
+
+            var itemList = _ic_item.GetListAsync(a => planList.Select(p => p.SAPItemNumber).Contains(a.number) && a.tenant_id == input.tenant_id && a.company_id == input.company_id && !a.IsDeleted).Result;
+            var mesItemList = _itemMaster.Select(a => planList.Select(p => p.SAPItemNumber).Contains(a.ItemNum) && a.Domain == input.factory_id.ToString() && a.IsActive);
+            var srm_purchaseList = _srmPurchase.GetListAsync(a => planList.Select(p => p.SAPItemNumber).Contains(a.number) && a.tenant_id == input.tenant_id && a.company_id == input.company_id && !a.IsDeleted).Result;
+
+            //获取补货模型前H周期和未来F个周期的数据
+            var ropModelList = _replenishmentModel.GetListAsync(a => a.zero_based_seqno >= -1 * replenishmentDto.HistoryOutStockMonth && a.zero_based_seqno <= replenishmentDto.SaleFcstMonth).Result;
+            //发货计划物料列表
+            List<string> planItemList = planList?.Select(a => a.SAPItemNumber).ToList();
+            //获取成品库存、灭菌库存、在制库存(会从SAP同步的库存表更新到LocationDetail、ic_item表中)
+            //List<SAPInv> sAPInvs = _SAPInv.Select(p => p.WERKS == input.factory_id.ToString() && itemNums.Contains(p.MATNR));
+            var locations = _locationDetail.Select(p => p.Domain == input.factory_id.ToString() && planList.Select(a => a.SAPItemNumber).Contains(p.ItemNum) && p.IsActive);
+            var sapItemInv = _SAPInv.Select(a => planItemList.Contains(a.MATNR) && a.WERKS == input.factory_id.ToString());
+
+            //取上一个月发货出库记录
+            var shipList = _ASNBOLShipperDetail.Select(a => a.Domain == input.factory_id.ToString() && a.IsActive && a.shtype == "SH" && a.Typed != "S" && a.RealQty > 0 && planItemList.Contains(a.ContainerItem)).Where(s => s.ShipDate >= getMonthStartTime(-1) && s.ShipDate <= getMonthEndTime(-1));
+
+            //取本月发货出库记录
+            var shipMList = _ASNBOLShipperDetail.Select(a => a.Domain == input.factory_id.ToString() && a.IsActive && a.shtype == "SH" && a.Typed != "S" && a.RealQty > 0 && planItemList.Contains(a.ContainerItem)).Where(s => s.ShipDate.Value >= getMonthStartTime(0) && s.ShipDate <= DateTime.Now);
+            //按照物料分组统计出货金额
+            var itemGroup = shipList.GroupBy(p => p.ContainerItem)
+                 .Select(p => new ASNBOLShipperDetail
+                 {
+                     QtyToShip = p.Sum(a => a.QtyToShip),
+                     ContainerItem = p.Key
+                 }).ToList();
+            //按照物料分组统计出货金额
+            var itemMGroup = shipMList.GroupBy(p => p.ContainerItem)
+                 .Select(p => new ASNBOLShipperDetail
+                 {
+                     QtyToShip = p.Sum(a => a.QtyToShip),
+                     ContainerItem = p.Key
+                 }).ToList();
+            List<ReplenishmentModel> addList = new List<ReplenishmentModel>();
+            List<ReplenishmentModel> updateList = new List<ReplenishmentModel>();//更新上一个月的实际出库数量
+            var mathtool = new MathNet.Numerics.Distributions.Normal();
+            ropModelList?.Where(r => r.isparam && r.seqno == DateTime.Now.AddMonths(-1).Month && r.year == DateTime.Now.AddMonths(-1).Year).ToList()?.ForEach
+                (m =>
+                {
+                    if (itemGroup.Any(a => a.ContainerItem == m.number))
+                    {
+                        m.actual_out_qty = itemGroup.Find(a => a.ContainerItem == m.number)?.QtyToShip;
+                        updateList.Add(m);
+                    }
+                });
+            //需要按照成品资源检查计算原材料
+            planList?.Where(s => s.PlanMonth == planMonth).ToList()?.ForEach(a =>
+            {
+                ReplenishmentModel rop = new ReplenishmentModel();
+                rop.number = a.SAPItemNumber;
+                var icItem = itemList.Find(s => s.number == a.SAPItemNumber);
+                if (icItem != null)
+                {
+                    rop.name = icItem.name;
+                    rop.model = a.Model;
+                    rop.erp_cls = icItem.erp_cls; //物料属性: 0.配置类 1.自制 2.委外加工 3.外购 4.虚拟件
+                    rop.fversion = icItem.fversion;
+                    rop.min_pack_qty = icItem.minpackqty;
+                    rop.moq = icItem.moq;
+                }
+                rop.actual_period_start_instock = 0;
+                if (rop.distributionchannel == "海王" || rop.distributionchannel == "国科")
+                {
+                    rop.actual_period_start_instock = locations.Find(l => l.ItemNum == a.SAPItemNumber)?.QtyOnHand;
+                }
+                else
+                {
+                    rop.actual_period_start_instock = sapItemInv.Find(s => s.MATNR == a.SAPItemNumber)?.LABST.ToDecimal();
+                }
+                rop.distributionchannel = a.DistributionChannel;
+                rop.lifecycle = a.LifeCycle;
+                rop.area = a.Area;
+                rop.plan_out_qty = Math.Ceiling(a.Qty);
+                rop.actual_out_qty = 0;
+                if (itemMGroup.Any(m => m.ContainerItem == a.SAPItemNumber))
+                {
+                    rop.actual_out_qty = itemMGroup.Find(m => m.ContainerItem == a.SAPItemNumber)?.QtyToShip;
+                }
+                rop.year = DateTime.Now.Year;
+                rop.long_period = "Y";
+                rop.short_period = "M";
+                rop.seqno = DateTime.Now.Month;
+                rop.zero_based_seqno = 0;
+                rop.period_start_date = getMonthStartTime(0);
+                rop.period_end_date = getMonthEndTime(0);
+                rop.monthl_avg_demand = CalcAvgDemand(planList, a.SAPItemNumber);
+                rop.monthl_avg_demand_variance = Math.Ceiling(Convert.ToDecimal(CalcVariance(planList, a.SAPItemNumber)));
+                rop.monthl_avg_outstock = CalcAvgOutStock(ropModelList, replenishmentDto, rop.actual_out_qty.Value, a.SAPItemNumber);
+                if (mesItemList.Find(s => s.ItemNum == a.SAPItemNumber) != null)
+                {
+                    rop.stock_turnover = mesItemList.Find(s => s.ItemNum == a.SAPItemNumber).StockTurnOver;
+                    rop.supply_leadtime = mesItemList.Find(s => s.ItemNum == a.SAPItemNumber)?.PurLT;
+                    rop.stock_turnover = mesItemList.Find(s => s.ItemNum == a.SAPItemNumber)?.StockTurnOver;
+                }
+                else
+                {
+                    rop.stock_turnover = 4;
+                }
+                if (srm_purchaseList.Find(s => s.number == a.SAPItemNumber) != null)
+                {
+                    rop.supply_leadtime = srm_purchaseList.Find(s => s.number == a.SAPItemNumber).lead_time;
+                }
+                CalcFMRAndABC(rop, replenishmentDto, input);
+                rop.security_stock = Math.Ceiling((decimal)(mathtool.InverseCumulativeDistribution((double)rop.service_level_pct.Value) * (double)rop.monthl_avg_demand_variance));
+                rop.eop = Math.Ceiling(rop.monthl_avg_demand.Value * rop.supply_leadtime.Value / DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month));
+                rop.rop_computed = rop.security_stock + rop.eop;
+                rop.max_stock_level = rop.monthl_avg_outstock * (12 / rop.stock_turnover);
+                rop.rop_revised = Math.Min(rop.rop_computed.Value, rop.max_stock_level.Value);
+                rop.isparam = true;
+                rop.tenant_id = input.tenant_id;
+                rop.factory_id = input.factory_id;
+                rop.create_time = DateTime.Now;
+                rop.org_id = input.org_id;
+                addList.Add(rop);
+            });
+            addList?.ForEach(item => { item.GenerateNewId(help.NextId()); });
+
+            await _replenishmentModel.InsertManyAsync(addList);
+            await _replenishmentModel.UpdateManyAsync(updateList);
+            var ropModeAllList = _replenishmentModel.GetListAsync(a => a.year != DateTime.Now.Year && a.seqno != DateTime.Now.Month && a.isparam).Result;
+            ropModeAllList?.ForEach(item => { item.seqno = item.seqno - 1; });
+            await _replenishmentModel.UpdateManyAsync(ropModeAllList);
+            return "OK";
+        }
+
+        /// <summary>
+        /// GK和HW平台成品周计划
+        /// </summary>
+        /// <param name="planDtos"></param>
+        /// <param name="input"></param>
+        /// <param name="nohistoryItemList"></param>
+        /// <returns></returns>
+        public string PlatformWeekPlan(InputDto input)
+        {
+            //1.获取补货模型全局参数
+            ReplenishmentDto replenishmentDto = GetROPParam();
+
+            //到了配置的更新时间才更新
+            if (DateTime.Now.Day != replenishmentDto.SaleFcstEntryDate)
+                return "不在更新时间日期";
+
+
+            //获取月度发货计划
+            string planMonth = $"{DateTime.Now.AddMonths(1).Year}-{DateTime.Now.AddMonths(months: 1).Month}";
+            var planList = _monthlyShipmentPlan.Select(a => a.PlanMonth == planMonth && !a.IsDeleted);
+            var monthPlanList = ObjectMapper.Map<List<MonthlyShipmentPlan>, List<MonthlyShipmentPlanDto>>(planList);
+            var itemList = _ic_item.GetListAsync(a => planList.Select(p => p.SAPItemNumber).Contains(a.number) && a.tenant_id == input.tenant_id && a.company_id == input.company_id && !a.IsDeleted).Result;
+            var mesItemList = _itemMaster.Select(a => planList.Select(p => p.SAPItemNumber).Contains(a.ItemNum) && a.Domain == input.factory_id.ToString() && a.IsActive);
+            var srm_purchaseList = _srmPurchase.GetListAsync(a => planList.Select(p => p.SAPItemNumber).Contains(a.number) && a.tenant_id == input.tenant_id && a.company_id == input.company_id && !a.IsDeleted).Result;
+            //获取补货模型前一个周期和未来N个周期的数据
+            var ropModelList = _replenishmentModel.GetListAsync(a => a.zero_based_seqno >= 0 && a.zero_based_seqno <= replenishmentDto.UpdateWeeks).Result;
+            //发货计划物料列表
+            List<string> planItemList = planList?.Select(a => a.SAPItemNumber).ToList();
+            //补货模型物料列表
+            List<string> ropItemList = ropModelList?.Where(c => c.zero_based_seqno == 0).Select(a => a.number).ToList();
+            //第一次算或者新品物料列表
+            List<string> nohistoryItemList = planItemList.Except(ropItemList).ToList();
+            var sapItemInv = _SAPInv.Select(a => nohistoryItemList.Contains(a.MATNR) && a.WERKS == input.factory_id.ToString());
+
+            //1.6、获取成品库存、灭菌库存、在制库存(会从SAP同步的库存表更新到LocationDetail、ic_item表中)
+            //List<SAPInv> sAPInvs = _SAPInv.Select(p => p.WERKS == input.factory_id.ToString() && itemNums.Contains(p.MATNR));
+            var locations = _locationDetail.Select(p => p.Domain == input.factory_id.ToString() && planList.Select(a => a.SAPItemNumber).Contains(p.ItemNum) && p.IsActive);
+
+
+            //取上一个月发货出库记录
+            var shipList = _ASNBOLShipperDetail.Select(a => a.Domain == input.factory_id.ToString() && a.IsActive && a.shtype == "SH" && a.Typed != "S" && a.ShipDate >= getMonthStartTime(-1) && a.ShipDate <= getMonthEndTime(-1) && a.RealQty > 0 && planItemList.Contains(a.ContainerItem));
+
+            //按照物料分组统计出货金额
+            var itemGroup = shipList.GroupBy(p => p.ContainerItem)
+                 .Select(p => new ASNBOLShipperDetail
+                 {
+                     Price = p.Sum(a => a.QtyToShip),
+                     ContainerItem = p.Key
+                 }).ToList();
+
+            monthPlanList?.ForEach(a =>
+            {
+                //物料属性:0.配置类 1.自制 2.委外加工 3.外购 4.虚拟件
+                a.erp_cls = itemList.Find(s => s.number == a.SAPItemNumber)?.erp_cls;
+                if (mesItemList.Find(s => s.ItemNum == a.SAPItemNumber) != null)
+                {
+                    a.stock_turnover = mesItemList.Find(s => s.ItemNum == a.SAPItemNumber).StockTurnOver;
+                    a.PLT = mesItemList.Find(s => s.ItemNum == a.SAPItemNumber)?.PurLT;
+                    a.IsLongPeriod = a.PLT >= replenishmentDto.LongPeriodDay;
+                }
+                else
+                {
+                    a.stock_turnover = 4;
+                }
+                if (srm_purchaseList.Find(s => s.number == a.SAPItemNumber) != null)
+                {
+                    a.PLT = srm_purchaseList.Find(s => s.number == a.SAPItemNumber).lead_time;
+                    a.IsLongPeriod = a.PLT >= replenishmentDto.LongPeriodDay;
+                }
+                //存在物料该物料编码表示之前算过,否则表示第一次算或者是新品
+                //之前算过,取算法模型数据,不存在表示第一次算要取默认值
+                if (ropModelList != null && ropModelList.Any(a => a.zero_based_seqno == 0))
+                {
+                    a.actual_period_start_instock = 0;
+                }
+                else
+                {
+                    if (sapItemInv.Find(s => s.MATNR == a.SAPItemNumber) != null)
+                    {
+                        a.actual_period_start_instock = Convert.ToDecimal(sapItemInv.Find(s => s.MATNR == a.SAPItemNumber).LABST);
+                    }
+                    else
+                    {
+                        a.actual_period_start_instock = 0;
+                    }
+                }
+            });
+
+
+            //第一周需要更新参数,其他周不要更新
+            if (WeekOfMonth(DateTime.Now, 1) == 1)
+            {
+
+            }
+            //每算一次都要把所有zero_based_seqno减去1
+
+
+
+            List<DomesticTerminalFcst> domesticFcst = _domesticTerminalFcst.GetListAsync(p => p.TypeEnum == 2 && p.Year == input.year && p.Month == input.month
+            && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id && !p.IsDeleted).Result;
+
+            var modelList = domesticFcst?.Select(a => a.Model);
+            var ItemModelSetList = _standardItemModelSet.GetListAsync(a => a.tenant_id == input.tenant_id && a.company_id == input.company_id && modelList.Contains(a.Model) && !a.IsDeleted).Result;
+            if (ItemModelSetList == null)
+            {
+                return "库存数据不存在";
+            }
+            var itemNumList = ItemModelSetList?.Select(a => a.ItemNumber).ToList();
+            List<mo_ic_bom> boms = _ic_bom.GetListAsync(p => itemNumList.Contains(p.item_number) && p.factory_id == input.factory_id && p.company_id == input.company_id && !p.IsDeleted).Result.ToList();
+            var pretreatments = _mysql_b_bom_pretreatment.GetListAsync(s => boms.Select(c => c.mysql_id).ToList().Contains(s.sourceid)).Result;
+            List<mo_ic_bom> autoCreates = new List<mo_ic_bom>();
+            boms.ForEach(p =>
+            {
+                if (!pretreatments.Where(s => s.sourceid == p.mysql_id).Any())
+                {
+                    autoCreates.Add(p);
+                }
+            });
+            if (autoCreates.Any())
+            {
+                AutoCreateBomBill(input.company_id.ToString(), autoCreates);
+                pretreatments = _mysql_b_bom_pretreatment.GetListAsync(s => boms.Select(c => c.mysql_id).ToList().Contains(s.sourceid)).Result;
+            }
+
+
+            return "OK";
+        }
+
+        public ReplenishmentDto GetROPParam()
+        {
+            ReplenishmentDto replenishmentDto = new ReplenishmentDto();
+            replenishmentDto.ReplenishmentCalcPeriod = "W";
+            replenishmentDto.HistoryOutStockMonth = 2;
+            replenishmentDto.SaleFcstMonth = 2;
+            replenishmentDto.SaleFcstEntryDate = 27;
+            replenishmentDto.UpdateWeeks = 12;
+            replenishmentDto.WeekPlanUpdateDay = 7;//每周日更新
+            replenishmentDto.LongPeriodDay = 60;
+            return replenishmentDto;
+        }
+        /// <summary>
+        /// 计算ABC分类和FMR分类
+        /// </summary>
+        /// <param name="replenishmentModels"></param>
+        public void CalcFMRAndABC(List<ReplenishmentModel> replenishmentModels, ReplenishmentDto replenishmentDto, InputDto input)
+        {
+            var itemNumList = replenishmentModels?.Select(a => a.number).ToList();
+            //发货出库记录
+            var shipList = _ASNBOLShipperDetail.Select(a => a.Domain == input.factory_id.ToString() && a.IsActive && a.shtype == "SH" && a.Typed != "S" && a.ShipDate >= DateTime.Now.AddMonths(replenishmentDto.HistoryOutStockMonth * -1) && a.RealQty > 0 && itemNumList.Contains(a.ContainerItem));
+            //领料出库记录
+            //var pickbilllist = _NbrDetail.Select(a => a.Domain == input.factory_id.ToString() && a.Type == "SM" && a.IsActive && a.UpdateTime >= DateTime.Now.AddMonths(replenishmentDto.HistoryOutStockMonth * -1) && itemNumList.Contains(a.ItemNum));
+            var pickbilllist = _invTransHist.Select(a => a.Domain == input.factory_id.ToString() && a.TransType == "iss-wo" && a.IsActive && a.CreateTime >= DateTime.Now.AddMonths(replenishmentDto.HistoryOutStockMonth * -1) && itemNumList.Contains(a.ItemNum));
+            //总的移库次数
+            int totalCount = shipList.Count() + pickbilllist.Count();
+            //平均出库次数
+            decimal avgOutStock = totalCount / replenishmentDto.HistoryOutStockMonth;
+
+            //总出货金额
+            decimal? totalPrice = shipList.Sum(a => a.Price * a.QtyToShip);
+            //按照物料分组统计出货金额
+            var itemGroup = shipList.GroupBy(p => p.ContainerItem)
+                 .Select(p => new ASNBOLShipperDetail
+                 {
+                     Price = p.Sum(a => a.Price * a.QtyToShip) * 100 / totalPrice,
+                     ContainerItem = p.Key
+                 }).ToList().OrderByDescending(c => c.Price).ThenByDescending(c => c.ContainerItem);
+            var AIndex = (int)Math.Ceiling(itemGroup.Count() * 0.75);//A类:0-75%
+            var BIndex = (int)Math.Ceiling(itemGroup.Count() * 0.9) - AIndex;//A类:75%-90%
+            var CIndex = itemGroup.Count() - AIndex - BIndex;//A类:90%-100%
+            var AItem = itemGroup.Take(AIndex);
+            var BItem = itemGroup.Skip(AIndex).Take(BIndex);
+            var CItem = itemGroup.Skip(AIndex + BIndex).Take(CIndex);
+            replenishmentModels?.ForEach(replenishmentModel =>
+            {
+                if (AItem.Any(a => a.ContainerItem == replenishmentModel.number))
+                {
+                    replenishmentModel.abc = "A";//金额占比前75%的物料划为A类
+                }
+                else if (BItem.Any(a => a.ContainerItem == replenishmentModel.number))
+                {
+                    replenishmentModel.abc = "B";//金额占比前75%-90%的物料划为A类
+                }
+                else if (CItem.Any(a => a.ContainerItem == replenishmentModel.number))
+                {
+                    replenishmentModel.abc = "C";//金额占比后10%的物料划为A类
+                }
+                else
+                {
+                    replenishmentModel.abc = "B";//原材料默认为B
+                }
+                int itemMoveCount = shipList.Count(a => a.ContainerItem == replenishmentModel.number) + pickbilllist.Count(a => a.ItemNum == replenishmentModel.number);
+                if (itemMoveCount >= avgOutStock)
+                {
+                    replenishmentModel.fmr = "F";
+                }
+                else if (itemMoveCount >= avgOutStock / 2 && itemMoveCount < avgOutStock || itemMoveCount == 0)
+                {
+                    replenishmentModel.fmr = "M";//没有出库移库记录的默认为M
+                }
+                else if (itemMoveCount < avgOutStock / 2)
+                {
+                    replenishmentModel.fmr = "R";
+                }
+
+                if (replenishmentModel.abc == "A" && replenishmentModel.fmr == "R")
+                {
+                    replenishmentModel.service_level_pct = (decimal?)0.8;
+                }
+                if (replenishmentModel.abc != "C" && replenishmentModel.fmr != "R")
+                {
+                    replenishmentModel.service_level_pct = (decimal?)0.96;
+                }
+                if (replenishmentModel.abc == "C" || (replenishmentModel.abc == "B" && replenishmentModel.fmr == "R"))
+                {
+                    replenishmentModel.service_level_pct = (decimal?)0.9;
+                }
+            });
+        }
+
+        /// <summary>
+        /// 计算ABC分类和FMR分类
+        /// </summary>
+        /// <param name="replenishmentModels"></param>
+        public void CalcFMRAndABC(ReplenishmentModel replenishmentModel, ReplenishmentDto replenishmentDto, InputDto input)
+        {
+            //发货出库记录
+            var shipList = _ASNBOLShipperDetail.Select(a => a.Domain == input.factory_id.ToString() && a.IsActive && a.shtype == "SH" && a.Typed != "S" && a.ShipDate >= DateTime.Now.AddMonths(replenishmentDto.HistoryOutStockMonth * -1) && a.RealQty > 0 && replenishmentModel.number == a.ContainerItem);
+            //领料出库记录
+            //var pickbilllist = _NbrDetail.Select(a => a.Domain == input.factory_id.ToString() && a.Type == "SM" && a.IsActive && a.UpdateTime >= DateTime.Now.AddMonths(replenishmentDto.HistoryOutStockMonth * -1) && itemNumList.Contains(a.ItemNum));
+            var pickbilllist = _invTransHist.Select(a => a.Domain == input.factory_id.ToString() && a.TransType == "iss-wo" && a.IsActive && a.CreateTime >= DateTime.Now.AddMonths(replenishmentDto.HistoryOutStockMonth * -1) && replenishmentModel.number == a.ItemNum);
+            //总的移库次数
+            int totalCount = shipList.Count() + pickbilllist.Count();
+            //平均出库次数
+            decimal avgOutStock = totalCount / replenishmentDto.HistoryOutStockMonth;
+
+            //总出货金额
+            decimal? totalPrice = shipList.Sum(a => a.Price * a.QtyToShip);
+            //按照物料分组统计出货金额
+            var itemGroup = shipList.GroupBy(p => p.ContainerItem)
+                 .Select(p => new ASNBOLShipperDetail
+                 {
+                     Price = p.Sum(a => a.Price * a.QtyToShip) * 100 / totalPrice,
+                     ContainerItem = p.Key
+                 }).ToList().OrderByDescending(c => c.Price).ThenByDescending(c => c.ContainerItem);
+            var AIndex = (int)Math.Ceiling(itemGroup.Count() * 0.75);//A类:0-75%
+            var BIndex = (int)Math.Ceiling(itemGroup.Count() * 0.9) - AIndex;//A类:75%-90%
+            var CIndex = itemGroup.Count() - AIndex - BIndex;//A类:90%-100%
+            var AItem = itemGroup.Take(AIndex);
+            var BItem = itemGroup.Skip(AIndex).Take(BIndex);
+            var CItem = itemGroup.Skip(AIndex + BIndex).Take(CIndex);
+            if (AItem.Any(a => a.ContainerItem == replenishmentModel.number))
+            {
+                replenishmentModel.abc = "A";//金额占比前75%的物料划为A类
+            }
+            else if (BItem.Any(a => a.ContainerItem == replenishmentModel.number))
+            {
+                replenishmentModel.abc = "B";//金额占比前75%-90%的物料划为B类
+            }
+            else if (CItem.Any(a => a.ContainerItem == replenishmentModel.number))
+            {
+                replenishmentModel.abc = "C";//金额占比后10%的物料划为C类
+            }
+            else
+            {
+                replenishmentModel.abc = "B";//原材料默认为B
+            }
+            int itemMoveCount = shipList.Count(a => a.ContainerItem == replenishmentModel.number) + pickbilllist.Count(a => a.ItemNum == replenishmentModel.number);
+            if (itemMoveCount >= avgOutStock)
+            {
+                replenishmentModel.fmr = "F";
+            }
+            else if (itemMoveCount >= avgOutStock / 2 && itemMoveCount < avgOutStock || itemMoveCount == 0)
+            {
+                replenishmentModel.fmr = "M";//没有出库移库记录的默认为M
+            }
+            else if (itemMoveCount < avgOutStock / 2)
+            {
+                replenishmentModel.fmr = "R";
+            }
+
+            if (replenishmentModel.abc == "A" && replenishmentModel.fmr == "R")
+            {
+                replenishmentModel.service_level_pct = (decimal?)0.8;
+            }
+            if (replenishmentModel.fmr != "R")
+            {
+                replenishmentModel.service_level_pct = (decimal?)0.96;
+            }
+            if (replenishmentModel.abc != "A" && replenishmentModel.fmr == "R")
+            {
+                replenishmentModel.service_level_pct = (decimal?)0.9;
+            }
+        }
+
+        /// <summary>
+        /// 算平均月需求数量
+        /// </summary>
+        /// <param name="planList">发货计划</param>
+        /// <param name="itemGroup"></param>
+        /// <param name="itemNum"></param>
+        /// <param name="month"></param>
+        /// <returns></returns>
+        public decimal CalcAvgDemand(List<MonthlyShipmentPlan> list, string itemNum)
+        {
+            return list.Where(i => i.SAPItemNumber == itemNum).Select(a => a.Qty).Average();
+        }
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="list">补货模型</param>
+        /// <param name="MQty">本月实际出库</param>
+        /// <param name="replenishmentDto">全局参数</param>
+        /// <param name="itemNum">物料编码</param>
+        /// <returns></returns>
+        public decimal CalcAvgOutStock(List<ReplenishmentModel> list, ReplenishmentDto replenishmentDto, decimal MQty, string itemNum)
+        {
+            return (list.Where(i => i.number == itemNum && i.zero_based_seqno > 1 - replenishmentDto.HistoryOutStockMonth && i.zero_based_seqno <= 0).Select(a => a.actual_out_qty.Value).Sum() + MQty) / (replenishmentDto.HistoryOutStockMonth + 1);
+        }
+
+        public double CalcVariance(List<MonthlyShipmentPlan> list, string itemNum)
+        {
+            var avg = CalcAvgDemand(list, itemNum);
+            var nums = list.Where(i => i.SAPItemNumber == itemNum).Select(a => a.Qty);
+            if (nums.Count() <= 1)
+                return 0;
+            return Math.Sqrt(nums.Sum(x => Math.Pow(Convert.ToDouble(x) - Convert.ToDouble(avg), 2)) / (nums.Count() - 1));
+        }
+
+        /// <summary>
+        /// 获取指定日期在为一年中为第几周
+        /// </summary>
+        /// <param name="dt">指定时间</param>
+        /// <reutrn>返回第几周</reutrn>
+        public static int GetWeekOfYear(DateTime dt)
+        {
+
+            System.Globalization.GregorianCalendar gc = new System.Globalization.GregorianCalendar();
+            int weekOfYear = gc.GetWeekOfYear(dt, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday);
+            return weekOfYear;
+        }
+
+        /// <summary>
+        /// 获取指定日期在该月的第几周
+        /// </summary>
+        /// <param name="day"></param>
+        /// <param name="WeekStart">1表示周一至周日为一周,2表示周日至周六为一周</param>
+        /// <returns></returns>
+        public static int WeekOfMonth(DateTime day, int WeekStart)
+        {
+            DateTime FirstofMonth = Convert.ToDateTime(day.Date.Year + "-" + day.Date.Month + "-" + 1);
+
+            int i = (int)FirstofMonth.Date.DayOfWeek;
+            if (i == 0)
+            {
+                i = 7;
+            }
+
+            if (WeekStart == 1)
+            {
+                return (day.Date.Day + i - 2) / 7 + 1;
+            }
+            if (WeekStart == 2)
+            {
+                return (day.Date.Day + i - 1) / 7;
+
+            }
+            return 0;
+        }
+        //获取上周开始时间
+        public static DateTime getPreWeekStartTime()
+        {
+            var weekday = (int)DateTime.Now.DayOfWeek;
+            return Convert.ToDateTime(DateTime.Now.AddDays(-7 - weekday + 1).ToString("yyyy-MM-dd 00:00:00.000"));
+        }
+        //获取上周结束时间
+        public static DateTime getPreWeekEndTime()
+        {
+            int weekday = (int)DateTime.Now.DayOfWeek;
+            return Convert.ToDateTime(DateTime.Now.AddDays(weekday - 7 + 1).ToString("yyyy-MM-dd 23:59:59.000"));
+        }
+        /// <summary>
+        /// 获取上个月开始时间
+        /// </summary>
+        /// <param name="months"></param>
+        /// <returns></returns>
+        public static DateTime getPreMonthStartTime()
+        {
+            return Convert.ToDateTime(DateTime.Now.AddMonths(-1).AddDays(1 - DateTime.Now.Day).ToString("yyyy-MM-dd 00:00:00.000"));
+        }
+        /// <summary>
+        /// 获取上月结束时间
+        /// </summary>
+        /// <param name="months"></param>
+        /// <returns></returns>
+        public static DateTime getPreMonthEndTime()
+        {
+            return Convert.ToDateTime(DateTime.Now.AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd 23:59:59.000"));
+        }
+
+        /// <summary>
+        /// 获取前后某个,整数月开始时间
+        /// </summary>
+        /// <param name="months">正数表示后多少个月的第一天,负数为前多少个月第一天</param>
+        /// <returns></returns>
+        public static DateTime getMonthStartTime(int months)
+        {
+            return getPreMonthStartTime().AddMonths(months + 1);
+        }
+        /// <summary>
+        /// 获取前后某个,整数月结束时间
+        /// </summary>
+        /// <param name="months">正数表示后多少个月的第一天,负数为前多少个月第一天</param>
+        /// <returns></returns>
+        public static DateTime getMonthEndTime(int months)
+        {
+            return getPreMonthEndTime().AddMonths(months + 1);
+        }
     }
 }

+ 198 - 0
MicroServices/Business/Business.Application/SaleForecastManagement/AnnualProductionOutlineAppService.cs

@@ -0,0 +1,198 @@
+using Business.Core.Enum;
+using Business.Core.Utilities;
+using Business.Domain;
+using Business.Dto;
+using Business.EntityFrameworkCore.SqlRepositories;
+using Business.SaleForecast;
+using Business.StructuredDB.SaleFcst;
+using Business.StructuredDB.WMS;
+using NetTopologySuite.Algorithm;
+using RazorEngine;
+using Spire.Pdf.General.Render.Decode.Jpeg2000.j2k.wavelet.synthesis;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Volo.Abp.Application.Dtos;
+using Volo.Abp.Application.Services;
+using Volo.Abp.DependencyInjection;
+using Volo.Abp.Domain.Repositories;
+using Volo.Abp.MultiTenancy;
+using Volo.Abp.Uow;
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
+
+namespace Business.SaleForecastManagement
+{
+    public class AnnualProductionOutlineAppService : ApplicationService, ITransientDependency, IAnnualProductionOutlineAppService
+    {
+        #region 服务
+        /// <summary>
+        /// 工作单元
+        /// </summary>
+        private readonly IUnitOfWorkManager _unitOfWorkManager;
+
+        /// <summary>
+        /// 日志
+        /// </summary>
+        private readonly ICurrentTenant _currentTenant;
+
+        /// <summary>
+        /// 年度销售预测
+        /// </summary>
+        private IRepository<YearDemandManagement, long> _yearDemandManagement;
+
+        /// <summary>
+        /// 年度销售预测历史记录
+        /// </summary>
+        private IRepository<YearDemandManagementHistory, long> _yearDemandManagementHistory;
+
+        /// <summary>
+        /// 年度生产大纲
+        /// </summary>
+        private IRepository<AnnualProductionOutline, long> _annualProductionOutline;
+
+        /// <summary>
+        /// 生产线明细
+        /// </summary>
+        private ISqlRepository<ProdLineDetail> _prodLineDetail;
+
+        /// <summary>
+        /// 标准工艺流程表
+        /// </summary>
+        private ISqlRepository<RoutingOpDetail> _routingOpDetail;
+        /// <summary>
+        /// 库存表
+        /// </summary>
+        private ISqlRepository<LocationDetail> _locationDetail;
+        /// <summary>
+        /// 平台库存表
+        /// </summary>
+        private readonly IRepository<WMS_PlatformInventory, long> _PlatformInventory;
+
+        /// <summary>
+        /// 雪花算法
+        /// </summary>
+        SnowFlake help = new SnowFlake();
+        #endregion
+
+        #region 构造函数
+        /// <summary>
+        /// 构造函数
+        /// </summary>
+        public AnnualProductionOutlineAppService(
+
+            IUnitOfWorkManager unitOfWorkManager,
+            ICurrentTenant currentTenant,
+            IRepository<YearDemandManagement, long> yearDemandManagement,
+            IRepository<AnnualProductionOutline, long> annualProductionOutline,
+            IRepository<YearDemandManagementHistory, long> yearDemandManagementHistory,
+            ISqlRepository<ProdLineDetail> prodLineDetail,
+            IRepository<WMS_PlatformInventory, long> PlatformInventory,
+            ISqlRepository<RoutingOpDetail> routingOpDetail,
+            ISqlRepository<LocationDetail> locationDetail
+            )
+        {
+            _unitOfWorkManager = unitOfWorkManager;
+            _currentTenant = currentTenant;
+            _PlatformInventory = PlatformInventory;
+            _prodLineDetail = prodLineDetail;
+            _routingOpDetail = routingOpDetail;
+            _locationDetail = locationDetail;
+            _yearDemandManagement = yearDemandManagement;
+            _yearDemandManagementHistory = yearDemandManagementHistory;
+            _annualProductionOutline = annualProductionOutline;
+        }
+        #endregion
+        /// <summary>
+        /// 生成年度生产大纲
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        /// <exception cref="NotImplementedException"></exception>
+        public async Task<string> SaveAnnualProductionOutline(InputDto input)
+        {
+            //获取当前导入或修改数据
+            List<YearDemandManagement> yearDemands = _yearDemandManagement.GetListAsync(p => p.Year == input.year && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id && !p.IsDeleted).Result.OrderBy(p => p.OrderNum).ThenBy(o => o.PlanMonth).ToList();
+            //标准工艺路径表
+            List<RoutingOpDetail> routingOps = _routingOpDetail.Select(p => yearDemands.Select(m => m.SAPItemNumber).Contains(p.RoutingCode) && p.Domain == input.factory_id.ToString() && p.IsActive);
+            var routingOpList = routingOps.Where(x => x.Descr == "组装").ToList();
+            //生产线明细表
+            List<ProdLineDetail> prodLines = _prodLineDetail.Select(p => yearDemands.Select(m => m.SAPItemNumber).Contains(p.Part) && p.Domain == input.factory_id.ToString() && p.IsActive && routingOpList.Select(m => m.Op).Contains(p.Op)).OrderBy(x => x.Sequence).ToList();
+            List<LocationDetail> locations = _locationDetail.Select(x => yearDemands.Select(m => m.SAPItemNumber).Contains(x.ItemNum) && x.Domain == input.factory_id.ToString() && x.IsActive).ToList();
+            //平台库存
+            var platformInvList = _PlatformInventory.GetListAsync(a => yearDemands.Select(m => m.SAPItemNumber).Contains(a.SAPItemNumber) && a.tenant_id == input.tenant_id && a.factory_id == input.factory_id).Result;
+            //取上一个月发货出库记录
+            //IEnumerable<ASNBOLShipperDetail> shipList = _ASNBOLShipperDetail.Select(a => a.Domain == input.factory_id.ToString() && a.IsActive && a.shtype == "SH" && a.Typed != "S" && a.RealQty > 0 && planItemList.Contains(a.ContainerItem)).Where(s => s.ShipDate >= getMonthStartTime(-1) && s.ShipDate <= getMonthEndTime(-1));
+            //在制  -- 工单计划中的数量   工单数量-完成数=生产中的在制
+            //年度生产大纲实体
+            List<AnnualProductionOutline> annualProductionOutlines = new List<AnnualProductionOutline>();
+            List<YearDemandManagement> frontYearDemand = new List<YearDemandManagement>();
+            foreach (var item in yearDemands)
+            {
+                var routingOp = routingOps.Where(x => x.RoutingCode == item.SAPItemNumber).ToList();
+                var Assembly = routingOp.Where(x => x.Descr == "组装").FirstOrDefault();
+                var HeatSealing = routingOp.Where(x => x.Descr == "热封").FirstOrDefault();
+                var Packaging = routingOp.Where(x => x.Descr == "包装").FirstOrDefault();
+                var prodLine = prodLines.Where(x => x.Part == item.SAPItemNumber).OrderBy(x => x.Sequence).FirstOrDefault();
+                //不同库位库存数量
+                var locationList = locations.Where(x => x.ItemNum == item.SAPItemNumber).ToList();
+                var platformInvs = platformInvList.Where(x => x.SAPItemNumber == item.SAPItemNumber).ToList();
+                var QtySum = yearDemands.Where(x => x.SAPItemNumber == item.SAPItemNumber).ToList();
+                //排产批量:(AVG(1 - 12月销售预测)/ 100 )=(0.45 = 1 小数向上取整)  *100 = 100
+                var pcpl = Math.Ceiling(QtySum.Sum(p => p.Qty) / QtySum.Count()) * 100;
+                //库存合计 + 在制+已发货
+                var locationSum = (locationList.Count == 0 ? 0 : locationList.Sum(x => x.QtyOnHand)) + (platformInvs.Count == 0 ? 0 : platformInvs.Sum(x => x.InventoryQuantity));
+                //if (annualProductionOutlines.Count > 0)
+                //{
+                //前面N个月的生产数量
+                var frontQtySum = annualProductionOutlines.Sum(x => x.Qty);
+                var num = (locationSum + frontQtySum) - frontYearDemand.Sum(m => m.Qty) - item.Qty / 2;
+                if (num < 0)
+                {
+                    num = pcpl * Math.Ceiling((-(locationSum + frontQtySum)) + frontYearDemand.Sum(m => m.Qty) + item.Qty / 2);
+                }
+                // }
+                //生产数量:3月为例子,(库存和前2月生产数量)-(前2个月销售预测数据)-当月销售预测数据 / 2 < 0  else 排产批量 *((-库存合计数量 + 前2个月销售预测数量 + 当月销售预测数量 / 2)/ 批量排产)
+                //生成年度生产大纲
+                AnnualProductionOutline annualProductionOutline = new AnnualProductionOutline();
+                //TODO:取值
+                annualProductionOutline.Year = item.Year;
+                annualProductionOutline.Area = item.Area;
+                annualProductionOutline.ProdLine = item.ProdLine;
+                annualProductionOutline.ProdRange = item.ProdRange;
+                annualProductionOutline.WorkshopLine = prodLine == null ? "" : prodLine.Line;
+                annualProductionOutline.SAPItemNumber = item.SAPItemNumber;
+                annualProductionOutline.Model = item.Model;
+                annualProductionOutline.Languages = item.Languages;
+                annualProductionOutline.PlanMonth = item.PlanMonth;
+                annualProductionOutline.Qty = num;
+                annualProductionOutline.StandardHours = (Assembly == null ? 0 : Assembly.RunTime) + (HeatSealing == null ? 0 : HeatSealing.RunTime) + (Packaging == null ? 0 : Packaging.RunTime);
+                //组装热封包装工时乘以数量 =单月工时
+                annualProductionOutline.AssemblyHours = Assembly == null ? 0 : Assembly.RunTime * num;
+                annualProductionOutline.HeatSealingHours = HeatSealing == null ? 0 : HeatSealing.RunTime * num;
+                annualProductionOutline.PackagingHours = Packaging == null ? 0 : Packaging.RunTime * num;
+                annualProductionOutline.Totalhours = annualProductionOutline.AssemblyHours + annualProductionOutline.HeatSealingHours + annualProductionOutline.Totalhours;
+                annualProductionOutline.OrderNum = item.OrderNum;
+                annualProductionOutlines.Add(annualProductionOutline);
+                frontYearDemand.Add(item);
+            }
+            //保存数据
+            using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
+            {
+                try
+                {
+                    await _annualProductionOutline.InsertManyAsync(annualProductionOutlines);
+                    await unitOfWork.CompleteAsync();
+                }
+                catch (Exception e)
+                {
+                    unitOfWork.Dispose();
+                    new NLogHelper("AnnualProductionOutlineAppService").WriteLog("SaveAnnualProductionOutline", "【" + input.year + "年" + "】月度需求预测更新失败:" + e.Message, _currentTenant.Id.ToString());
+                    return "NO|" + e.Message;
+                };
+            }
+            return "OK";
+        }
+    }
+}

+ 1 - 9
MicroServices/Business/Business.Application/SaleForecastManagement/MonthlyCapacityLoadAppService.cs

@@ -1,26 +1,18 @@
-using Azure.Identity;
-using Business.Core.Utilities;
+using Business.Core.Utilities;
 using Business.Domain;
 using Business.Dto;
 using Business.EntityFrameworkCore.SqlRepositories;
-using Business.ResourceExamineManagement.Dto;
 using Business.SaleForecast;
 using Business.StructuredDB.WMS;
-using Microsoft.CodeAnalysis.CSharp.Syntax;
-using Spire.Pdf.General.Render.Decode.Jpeg2000.j2k.quantization;
-using Spire.Pdf.General.Render.Decode.Jpeg2000.j2k.roi.encoder;
 using System;
 using System.Collections.Generic;
 using System.Linq;
-using System.Runtime.CompilerServices;
 using System.Threading.Tasks;
-using ThoughtWorks.QRCode.Geom;
 using Volo.Abp.Application.Services;
 using Volo.Abp.DependencyInjection;
 using Volo.Abp.Domain.Repositories;
 using Volo.Abp.MultiTenancy;
 using Volo.Abp.Uow;
-using Volo.Abp.Validation.Localization;
 
 namespace Business.SaleForecastManagement
 {

+ 123 - 0
MicroServices/Business/Business.Domain/StructuredDB/MES/IC/ASNBOLShipperDetail.cs

@@ -0,0 +1,123 @@
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.Domain
+{
+    /// <summary>
+    /// 发货明细表
+    /// </summary>
+    [Comment("发货明细表")]
+    public class ASNBOLShipperDetail
+    {
+        /// <summary>
+        /// 主键
+        /// </summary>
+        [Comment("主键")]
+        [Key]
+        public int RecID { get; set; }
+
+        /// <summary>
+        /// 发货次数
+        /// </summary>
+        [Precision(23, 10)]
+        [Comment("发货次数")]
+        public decimal? RealQty { get; set; }
+
+        /// <summary>
+        /// 发货数量
+        /// </summary>
+        [Precision(23, 10)]
+        [Comment("发货数量")]
+        public decimal? QtyToShip { get; set; }
+
+        /// <summary>
+        /// 单价
+        /// </summary>
+        [Precision(23, 10)]
+        [Comment("单价")]
+        public decimal? Price { get; set; }
+
+        /// <summary>
+        /// 项次,分组用的,不同物料编码
+        /// </summary>
+        [Precision(23, 10)]
+        [Comment("项次")]
+        public int Line { get; set; }
+
+        // RealQty,QtyToShip,Price,Line,ShipDate,ContainerItem
+
+        /// <summary>
+        /// 域名
+        /// </summary>
+        [Comment("域名")]
+        public string Domain { get; set; }
+
+        /// <summary>
+        /// 发货日期
+        /// </summary>
+        [Comment("发货日期")]
+        public DateTime? ShipDate { get; set; }
+
+
+        /// <summary>
+        /// 物料编码
+        /// </summary>
+        [Comment("物料编码")]
+        public string ContainerItem { get; set; }
+
+
+        /// <summary>
+        /// 行号
+        /// </summary>
+        [Comment("行号")]
+        public string? Typed { get; set; }
+
+        /// <summary>
+        /// 类型
+        /// </summary>
+        [Comment("类型")]
+        public string? shtype { get; set; }
+
+        /// <summary>
+        /// 销售渠道(国内国外T1、T2、国科、海王等待定)
+        /// </summary>
+        [Comment("销售渠道")]
+        public string? CustRef { get; set; }
+        
+
+        /// <summary>
+        /// 是否有效:1-有效;0-无效
+        /// </summary>
+        [Comment("是否有效")]
+        public bool IsActive { get; set; }
+
+        /// <summary>
+        /// 创建时间
+        /// </summary>
+        [Comment("创建时间")]
+        public DateTime? CreateTime { get; set; }
+
+        /// <summary>
+        /// 创建人
+        /// </summary>
+        [Comment("创建人")]
+        public string CreateUser { get; set; }
+
+        /// <summary>
+        /// 创建时间
+        /// </summary>
+        [Comment("修改时间")]
+        public DateTime? UpdateTime { get; set; }
+
+        /// <summary>
+        /// 修改人
+        /// </summary>
+        [Comment("修改人")]
+        public string UpdateUser { get; set; }
+    }
+}

+ 78 - 0
MicroServices/Business/Business.Domain/StructuredDB/MES/IC/InvTransHist.cs

@@ -0,0 +1,78 @@
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.Domain
+{
+    /// <summary>
+    /// 进出存记录
+    /// </summary>
+    [Comment("进出存记录")]
+    public class InvTransHist
+    {
+        /// <summary>
+        /// 主键
+        /// </summary>
+        [Comment("主键")]
+        [Key]
+        public int RecID { get; set; }
+
+        /// <summary>
+        /// 域名
+        /// </summary>
+        [Comment("域名")]
+        public string Domain { get; set; }
+
+        /// <summary>
+        /// 类型
+        /// </summary>
+        [Comment("类型")]
+        public string TransType { get; set; }
+
+        /// <summary>
+        /// 物料编号
+        /// </summary>
+        [Comment("物料编号")]
+        public string ItemNum { get; set; }
+
+        /// <summary>
+        /// 库存数量
+        /// </summary>
+        [Comment("库存数量")]
+        public decimal? QtyChange { get; set; }
+
+        /// <summary>
+        /// 是否有效:1-有效;0-无效
+        /// </summary>
+        [Comment("是否有效")]
+        public bool IsActive { get; set; }
+
+        /// <summary>
+        /// 创建时间
+        /// </summary>
+        [Comment("创建时间")]
+        public DateTime? CreateTime { get; set; }
+
+        /// <summary>
+        /// 创建人
+        /// </summary>
+        [Comment("创建人")]
+        public string CreateUser { get; set; }
+
+        /// <summary>
+        /// 创建时间
+        /// </summary>
+        [Comment("修改时间")]
+        public DateTime? UpdateTime { get; set; }
+
+        /// <summary>
+        /// 修改人
+        /// </summary>
+        [Comment("修改人")]
+        public string UpdateUser { get; set; }
+    }
+}

+ 12 - 0
MicroServices/Business/Business.Domain/StructuredDB/MES/IC/ItemMaster.cs

@@ -84,5 +84,17 @@ namespace Business.Domain
         [Comment("是否整包发料")]
         public bool TraceDetail { get; set; }
 
+        /// <summary>
+        /// 供应提前期
+        /// </summary>
+        [Comment("供应提前期")]
+        public int PurLT { get; set; }
+
+        /// <summary>
+        /// 存货周转率
+        /// </summary>
+        [Comment("存货周转率")]
+        public decimal StockTurnOver { get; set; }
+
     }
 }

+ 2 - 2
MicroServices/Business/Business.Domain/StructuredDB/Production/RoutingOpDetail.cs

@@ -27,9 +27,9 @@ namespace Business.Domain
         public string Domain { get; set; }
 
         /// <summary>
-        /// 流程代
+        /// 物料编
         /// </summary>
-        [Comment("流程代码")]
+        [Comment("物料编码")]
         public string RoutingCode { get; set; }
 
         /// <summary>

+ 285 - 0
MicroServices/Business/Business.Domain/StructuredDB/Replenishment/ReplenishmentModel.cs

@@ -0,0 +1,285 @@
+using Business.Core.Attributes;
+using Microsoft.EntityFrameworkCore;
+using Spire.Pdf.General.Render.Decode.Jpeg2000.j2k.roi.encoder;
+using System;
+using System.ComponentModel;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Runtime.Intrinsics.X86;
+using ZstdSharp.Unsafe;
+
+namespace Business.Domain
+{
+    /// <summary>
+    ///补货模型算法表
+    /// </summary>
+    [Comment("补货模型算法表")]
+    [Index(nameof(number), nameof(tenant_id), nameof(fversion),nameof(long_period),nameof(short_period),nameof(isparam), nameof(seqno),nameof(zero_based_seqno), nameof(factory_id), IsUnique = true)]
+    public class ReplenishmentModel : BaseEntity
+    {
+        /// <summary>
+        /// 物料编码
+        /// </summary>
+        [StringLength(80)]
+        [Comment("物料编码")]
+        public string number { get; set; }
+        /// <summary>
+        /// 物料名称
+        /// </summary>
+        [StringLength(200)]
+        [Comment("物料名称")]
+        public string name { get; set; }
+        /// <summary>
+        /// 规格型号
+        /// </summary>
+        [StringLength(200)]
+        [Comment("规格型号")]
+        public string model { get; set; }
+
+        /// <summary>
+        /// 生命周期    
+        /// </summary>
+        [StringLength(50)]
+        public string? lifecycle { get; set; }
+
+        /// <summary>
+        /// 市场    
+        /// </summary>
+        [StringLength(50)]
+        public string? area { get; set; }
+
+        /// <summary>
+        /// 物料属性:0.配置类 1.自制 2.委外加工 3.外购 4.虚拟件
+        /// </summary>
+        [Comment("物料属性")]
+        public int? erp_cls { get; set; }
+
+
+        /// <summary>
+        /// 版本号
+        /// </summary>
+        [StringLength(80)]
+        [Comment("版本号")]
+        public string? fversion { get; set; }
+
+        /// <summary>
+        /// 期初库存
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("期初库存")]
+        public decimal? actual_period_start_instock { get; set; }
+
+        /// <summary>
+        /// 计划发货数量
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("发货计划")]
+        public decimal? plan_out_qty { get; set; }
+
+        /// <summary>
+        /// 实际发货 为空或-1时表示不适用,为0时表示没有发货记录。注意能区分这两种形式
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("实际发货")]
+        public decimal? actual_out_qty { get; set; }
+
+        /// <summary>
+        /// 计划生产
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("计划生产")]
+        public decimal? plan_in { get; set; }
+
+        /// <summary>
+        /// 实际生产
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("实际生产")]
+        public decimal? actual_in { get; set; }
+
+        /// <summary>
+        /// 计划期末库存
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("计划期末库存")]
+        public decimal? plan_period_end_instock { get; set; }
+
+        /// <summary>
+        /// 实际期末库存
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("实际期末库存")]
+        public decimal? actual_period_end_instock { get; set; }
+
+        /// <summary>
+        /// 库存偏差
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("库存偏差")]
+        public decimal? instock_deviation { get; set; }
+
+        /// <summary>
+        /// 年份
+        /// </summary>
+        [Comment("年份")]
+        public int? year { get; set; }
+
+        /// <summary>
+        /// 长周期:年Y月M周W
+        /// </summary>
+        [StringLength(8)]
+        [Comment("长周期")]
+        public string? long_period { get; set; }
+
+        /// <summary>
+        /// 短周期:月M周W日D
+        /// </summary>
+        [StringLength(8)]
+        [Comment("短周期")]
+        public string? short_period { get; set; }
+
+
+        /// <summary>
+        /// 序次号,短在长中间的序次号,在补货模型中,长周期都是年,短周期是月(1~12), 或周(1~53)
+        /// </summary>
+        [Comment("序次号,短在长中间的序次号,在补货模型中,长周期都是年,短周期是月(1~12), 或周(1~53)")]
+        public int? seqno { get; set; }
+
+        /// <summary>
+        /// 计算辅助列,由于月和周是分别的记录,都可以区分开。	当前周期为0,前后到h ~f每个周期末动态修改方便计算使用
+        /// </summary>
+        [Comment("计算辅助列,由于月和周是分别的记录,都可以区分开。当前周期为0,前后到h ~f每个周期末动态修改方便计算使用")]
+        public int? zero_based_seqno { get; set; }
+
+        /// <summary>
+        /// 周期开始日期
+        /// </summary>
+        [Comment("周期开始日期")]
+        public DateTime? period_start_date { get; set; }
+        /// <summary>
+        /// 周期结束日期
+        /// </summary>
+        [Comment("周期结束日期")]
+        public DateTime? period_end_date { get; set; }
+
+
+        /// <summary>
+        /// 月均需求
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("月均需求")]
+        public decimal? monthl_avg_demand { get; set; }
+
+        /// <summary>
+        /// 月均需求标准方差
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("月均需求标准方差")]
+        public decimal? monthl_avg_demand_variance { get; set; }
+
+        /// <summary>
+        /// 月均出库
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("月均出库")]
+        public decimal? monthl_avg_outstock { get; set; }
+
+        /// <summary>
+        /// 供应前置期参数(天)
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("供应前置期参数(天)")]
+        public decimal? supply_leadtime { get; set; }
+
+
+        /// <summary>
+        /// ABC分类
+        /// </summary>
+        [StringLength(8)]
+        [Comment("ABC分类")]
+        public string? abc { get; set; }
+
+        /// <summary>
+        /// FMR分类
+        /// </summary>
+        [StringLength(8)]
+        [Comment("FMR分类")]
+        public string? fmr { get; set; }
+
+        /// <summary>
+        /// Z服务水平参数
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("Z服务水平参数")]
+        public decimal? service_level_pct { get; set; }
+
+        /// <summary>
+        /// 存货周转率
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("存货周转率")]
+        public decimal? stock_turnover { get; set; }
+
+
+        /// <summary>
+        /// 最小包装
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("最小包装")]
+        public decimal? min_pack_qty { get; set; }
+
+        /// <summary>
+        /// 最小批量
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("最小批量")]
+        public decimal? moq { get; set; }
+
+        /// <summary>
+        /// 安全库存
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("安全库存")]
+        public decimal? security_stock { get; set; }
+
+        /// <summary>
+        /// 圆整后供应批量
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("圆整后供应批量")]
+        public decimal? eop { get; set; }
+
+        /// <summary>
+        /// 重新订货点
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("重新订货点")]
+        public decimal? rop_computed { get; set; }
+
+        /// <summary>
+        /// 月均出库最高库存
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("月均出库最高库存")]
+        public decimal? max_stock_level { get; set; }
+
+        /// <summary>
+        /// 修正后重新订货点
+        /// </summary>
+        [Precision(20, 8)]
+        [Comment("修正后重新订货点")]
+        public decimal? rop_revised { get; set; }
+
+        /// <summary>
+        /// 销售/渠道   
+        /// </summary>
+        [Comment("销售/渠道")]
+        public string distributionchannel { get; set; }
+
+        /// <summary>
+        /// 是否是计算参数,默认为否,是的话一月更新一次
+        /// </summary>
+        [Comment("是否是计算参数,默认为否,是的话一月更新一次")]
+        public bool isparam { get; set; }
+    }
+}

+ 97 - 0
MicroServices/Business/Business.Domain/StructuredDB/SaleFcst/AnnualProductionOutline.cs

@@ -0,0 +1,97 @@
+using Business.Domain;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.StructuredDB.SaleFcst
+{
+
+    /// <summary>
+    ///  年度生产大纲    
+    /// </summary>
+    public class AnnualProductionOutline : BaseEntity
+    {
+        /// <summary>
+        /// 年    
+        /// </summary>
+        public int Year { get; set; }
+
+        /// <summary>
+        /// 地区    
+        /// </summary>
+        public string Area { get; set; }
+
+        /// <summary>
+        /// 产品线    
+        /// </summary>
+        public string ProdLine { get; set; }
+
+        /// <summary>
+        /// 产品系列    
+        /// </summary>
+        public string ProdRange { get; set; }
+
+        /// <summary>
+        /// 车间线体    
+        /// </summary>
+        public string WorkshopLine { get; set; }
+
+        /// <summary>
+        /// SAP料号    
+        /// </summary>
+        public string SAPItemNumber { get; set; }
+
+        /// <summary>
+        /// 规格型号    
+        /// </summary>
+        public string Model { get; set; }
+
+        /// <summary>
+        /// 语种    
+        /// </summary>
+        public string Languages { get; set; }
+
+        /// <summary>
+        /// 计划年月    
+        /// </summary>
+        public string PlanMonth { get; set; }
+
+        /// <summary>
+        /// 数量    
+        /// </summary>
+        public decimal Qty { get; set; }
+
+        /// <summary>
+        /// 标准工时    
+        /// </summary>
+        public decimal StandardHours { get; set; }
+
+        /// <summary>
+        /// 组装工时    
+        /// </summary>
+        public decimal AssemblyHours { get; set; }
+
+        /// <summary>
+        /// 热封工时    
+        /// </summary>
+        public decimal HeatSealingHours { get; set; }
+
+        /// <summary>
+        /// 包装工时    
+        /// </summary>
+        public decimal PackagingHours { get; set; }
+
+        /// <summary>
+        /// 工时合计    
+        /// </summary>
+        public decimal Totalhours { get; set; }
+
+        /// <summary>
+        /// 排序编码    
+        /// </summary>
+        public int OrderNum { get; set; }
+
+    }
+}

+ 94 - 0
MicroServices/Business/Business.Domain/StructuredDB/SaleFcst/ProductionMasterPlan.cs

@@ -0,0 +1,94 @@
+using Business.Domain;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.StructuredDB.SaleFcst
+{
+
+    /// <summary>
+    ///  主生产计划    
+    /// </summary>
+    public class ProductionMasterPlan :BaseEntity
+    {
+
+        /// <summary>
+        /// 年    
+        /// </summary>
+        public int Year { get; set; }
+
+        /// <summary>
+        /// 月    
+        /// </summary>
+        public int Month { get; set; }
+
+        /// <summary>
+        /// 产品线    
+        /// </summary>
+        public string ProdLine { get; set; }
+
+        /// <summary>
+        /// 规格型号    
+        /// </summary>
+        public string Model { get; set; }
+
+        /// <summary>
+        /// 计划月份    
+        /// </summary>
+        public string PlanMonth { get; set; }
+
+        /// <summary>
+        /// 类别枚举    
+        /// </summary>
+        public int TypeEnum { get; set; }
+
+        /// <summary>
+        /// 类别名称    
+        /// </summary>
+        public string TypeName { get; set; }
+
+        /// <summary>
+        /// 计划数量    
+        /// </summary>
+        public decimal Qty { get; set; }
+
+        /// <summary>
+        /// 8001库存    
+        /// </summary>
+        public decimal Inventory { get; set; }
+
+        /// <summary>
+        /// 8000库存    
+        /// </summary>
+        public decimal Inventory1 { get; set; }
+
+        /// <summary>
+        /// 5008库存    
+        /// </summary>
+        public decimal Inventory2 { get; set; }
+
+        /// <summary>
+        /// 灭菌中    
+        /// </summary>
+        public decimal DuringSterilization { get; set; }
+
+        /// <summary>
+        /// 在制    
+        /// </summary>
+        public decimal InProduction { get; set; }
+
+        /// <summary>
+        /// 经济批量    
+        /// </summary>
+        public decimal EconomicLotSize { get; set; }
+
+        /// <summary>
+        /// 排序    
+        /// </summary>
+        public int OrderNum { get; set; }
+
+    }
+
+}

+ 40 - 23
MicroServices/Business/Business.Domain/StructuredDB/SaleFcst/YearDemandManagement.cs

@@ -10,64 +10,81 @@ using System.Threading.Tasks;
 namespace Business.Domain
 {
     /// <summary>
-    /// 年度生产需求管理表
+    /// 年度销售预测
     /// </summary>
-    [Comment("年度生产需求管理表")]
-    [Index(nameof(Year), nameof(Area), nameof(ProdLine),nameof(ProdRange), nameof(Line),nameof(Model),nameof(PlanMonth),nameof(tenant_id), nameof(company_id),nameof(factory_id), IsUnique = true)]
-    public class YearDemandManagement:BaseEntity
+    [Comment("年度销售预测")]
+    [Index(nameof(Year), nameof(Area), nameof(ProdLine), nameof(ProdRange), nameof(Line), nameof(Model), nameof(PlanMonth), nameof(tenant_id), nameof(company_id), nameof(factory_id), IsUnique = true)]
+    public class YearDemandManagement : BaseEntity
     {
+
         /// <summary>
-        /// 年
+        /// 年    
         /// </summary>
-        [Comment("年")]
-        public int? Year { get; set; }
+        public int Year { get; set; }
 
         /// <summary>
-        /// 区域
+        /// 地区    
         /// </summary>
-        [Comment("区域")]
         public string Area { get; set; }
 
         /// <summary>
-        /// 产品线
+        /// 产品线    
         /// </summary>
-        [Comment("产品线")]
         public string ProdLine { get; set; }
 
         /// <summary>
-        /// 产品系列
+        /// 产品系列    
         /// </summary>
-        [Comment("产品系列")]
         public string ProdRange { get; set; }
 
         /// <summary>
-        /// 车间线体
+        /// 车间线体    
         /// </summary>
-        [Comment("车间线体")]
         public string Line { get; set; }
 
         /// <summary>
-        /// 规格型号
+        /// 规格型号    
         /// </summary>
-        [Comment("规格型号")]
         public string Model { get; set; }
 
         /// <summary>
-        /// 计划年月
+        /// 计划年月    
         /// </summary>
-        [Comment("计划年月")]
         public string PlanMonth { get; set; }
 
         /// <summary>
-        /// 产品数量
+        /// 数量    
         /// </summary>
-        [Comment("产品数量")]
         public decimal Qty { get; set; }
 
         /// <summary>
-        /// 排序编码
+        /// 排序编码    
         /// </summary>
-        [Comment("排序编码")]
         public int OrderNum { get; set; }
+
+        /// <summary>
+        /// 生命周期    
+        /// </summary>
+        public string LifeCycle { get; set; }
+
+        /// <summary>
+        /// SAP料号    
+        /// </summary>
+        public string SAPItemNumber { get; set; }
+
+        /// <summary>
+        /// 语种    
+        /// </summary>
+        public string Languages { get; set; }
+
+        /// <summary>
+        /// 终端系列销售预测    
+        /// </summary>
+        public decimal TerminalSalesForecast { get; set; }
+
+        /// <summary>
+        /// 规格占比    
+        /// </summary>
+        public string SpecificationsProportion { get; set; }
     }
 }

+ 48 - 28
MicroServices/Business/Business.Domain/StructuredDB/SaleFcst/YearDemandManagementHistory.cs

@@ -10,70 +10,90 @@ using System.Threading.Tasks;
 namespace Business.Domain
 {
     /// <summary>
-    /// 年度生产需求管理历史表
+    /// 年度销售预测历史表
     /// </summary>
-    [Comment("年度生产需求管理表")]
-    [Index(nameof(UpdateMonth),nameof(Year), nameof(Area), nameof(ProdLine),nameof(ProdRange), nameof(Line),nameof(Model),nameof(PlanMonth),nameof(tenant_id), nameof(company_id),nameof(factory_id), IsUnique = true)]
+    [Comment("年度销售预测历史表")]
+    [Index(nameof(UpdateMonth), nameof(Year), nameof(Area), nameof(ProdLine), nameof(ProdRange), nameof(Line), nameof(Model), nameof(PlanMonth), nameof(tenant_id), nameof(company_id), nameof(factory_id), IsUnique = true)]
+
     public class YearDemandManagementHistory : BaseEntity
     {
-        /// <summary>
-        /// 更新年月
-        /// </summary>
-        [Comment("更新年月")]
-        public string UpdateMonth { get; set; }
 
         /// <summary>
-        /// 年
+        /// 年    
         /// </summary>
-        [Comment("年")]
-        public int? Year { get; set; }
+        public int Year { get; set; }
 
         /// <summary>
-        /// 区域
+        /// 地区    
         /// </summary>
-        [Comment("区域")]
         public string Area { get; set; }
 
         /// <summary>
-        /// 产品线
+        /// 产品线    
         /// </summary>
-        [Comment("产品线")]
         public string ProdLine { get; set; }
 
         /// <summary>
-        /// 产品系列
+        /// 产品系列    
         /// </summary>
-        [Comment("产品系列")]
         public string ProdRange { get; set; }
 
         /// <summary>
-        /// 车间线体
+        /// 车间线体    
         /// </summary>
-        [Comment("车间线体")]
         public string Line { get; set; }
 
         /// <summary>
-        /// 规格型号
+        /// 规格型号    
         /// </summary>
-        [Comment("规格型号")]
         public string Model { get; set; }
 
         /// <summary>
-        /// 计划年月
+        /// 计划年月    
         /// </summary>
-        [Comment("计划年月")]
         public string PlanMonth { get; set; }
 
         /// <summary>
-        /// 产品数量
+        /// 数量    
         /// </summary>
-        [Comment("产品数量")]
-        public decimal? Qty { get; set; }
+        public decimal Qty { get; set; }
 
         /// <summary>
-        /// 排序编码
+        /// 版本管理    
+        /// </summary>
+        public string UpdateMonth { get; set; }
+
+        /// <summary>
+        /// 排序编码    
         /// </summary>
-        [Comment("排序编码")]
         public int OrderNum { get; set; }
+
+
+        /// <summary>
+        /// 生命周期   
+        /// </summary>
+        public string LifeCycle { get; set; }
+
+        /// <summary>
+        /// SAP料号    
+        /// </summary>
+        public string SAPItemNumber { get; set; }
+
+        /// <summary>
+        /// 语种   
+        /// </summary>
+        public string Languages { get; set; }
+
+        /// <summary>
+        /// 终端系列销售预测     
+        /// </summary>
+        public decimal TerminalSalesForecast { get; set; }
+
+        /// <summary>
+        /// 规格占比   
+        /// </summary>
+        public string SpecificationsProportion { get; set; }
+
     }
+
 }

+ 5 - 0
MicroServices/Business/Business.Domain/StructuredDB/WMS/WMS_PlatformInventory.cs

@@ -45,5 +45,10 @@ namespace Business.StructuredDB.WMS
         /// </summary>
         [Comment("编码")]
         public string Code { get; set; }
+        /// <summary>
+        /// SAP料号
+        /// </summary>
+        [Comment("SAP料号")]
+        public string SAPItemNumber { get; set; }
     }
 }

+ 7 - 0
MicroServices/Business/Business.EntityFrameworkCore/EntityFrameworkCore/BusinessDbContextModelCreatingExtensions.cs

@@ -283,6 +283,13 @@ namespace Business.EntityFrameworkCore
                 b.ConfigureByConvention();
             });
 
+            builder.Entity<ReplenishmentModel>(b =>
+            {
+                b.ToTable("replenishmentmodel");
+                b.HasIndex(b => new { b.number, b.zero_based_seqno, b.long_period, b.short_period, b.tenant_id, b.company_id, b.factory_id });
+                b.ConfigureByConvention();
+            });
+
             //Code generation...
 
             //添加表名字段名描述属性,请放在最后,会导致NotMap不生效

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

@@ -221,6 +221,16 @@ namespace Business.EntityFrameworkCore
         /// </summary>
         public DbSet<MonthlyShipmentPlanHistory> MonthlyShipmentPlanHistory { get; set; }
 
+        /// <summary>
+        /// 年度生产大纲
+        /// </summary>
+        public DbSet<AnnualProductionOutline> AnnualProductionOutline { get; set; }
+
+        /// <summary>
+        /// 主生产计划
+        /// </summary>
+        public DbSet<ProductionMasterPlan> ProductionMasterPlan { get; set; }
+
         /// <summary>
         /// 整体需求计划表
         /// </summary>
@@ -248,6 +258,12 @@ namespace Business.EntityFrameworkCore
 
         public DbSet<WMS_PlatformSpecificationComparison> WMS_PlatformSpecificationComparison { get; set; }
 
+        public DbSet<ReplenishmentModel> ReplenishmentModel { get; set; }
+
+        public DbSet<ASNBOLShipperDetail> ASNBOLShipperDetail { get; set; }
+
+        public DbSet<InvTransHist> InvTransHist { get; set; }
+
         /// <summary>
         /// SAP库存表
         /// </summary>

+ 38 - 0
MicroServices/Business/Business.HttpApi/Controllers/AnnualProductionOutlineController.cs

@@ -0,0 +1,38 @@
+using Business.Dto;
+using Business.SaleForecast;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Volo.Abp;
+
+namespace Business.Controllers
+{
+    /// <summary>
+    /// 年度生产大纲
+    /// </summary>
+    [RemoteService]
+    [Area("Business")]
+    [Route("api/business/AnnualProductionOutline")]
+    public class AnnualProductionOutlineController
+    {
+        /// <summary>
+        /// 年度生产大纲
+        /// </summary>
+        private readonly IAnnualProductionOutlineAppService _IAnnualProductionOutlineAppService;
+        /// <summary>
+        /// 月度需求分析
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("SaveAnnualProductionOutline")]
+        public Task<string> SaveAnnualProductionOutline(InputDto input)
+        {
+            return _IAnnualProductionOutlineAppService.SaveAnnualProductionOutline(input);
+        }
+
+    }
+}

+ 36 - 0
MicroServices/Business/Business.HttpApi/Controllers/ResourceExamineController.cs

@@ -193,5 +193,41 @@ namespace Business.Controllers
         {
             return _ResourceExamineAppService.SubstituteSave(dto);
         }
+
+        /// <summary>
+        /// BOM关联替代方案
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("BindingSubstitute")]
+        public Task<string> BindingSubstitute(BindingSubstituteDto dto)
+        {
+            return _ResourceExamineAppService.BindingSubstitute(dto);
+        }
+
+        /// <summary>
+        /// 更新补货模型月度参数
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("weekplanparms")]
+        public Task<string> WeekPlanParms(InputDto input)
+        {
+            return _ResourceExamineAppService.WeekPlanParms(input);
+        }
+
+        /// <summary>
+        /// 更新周计划
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("weekplan")]
+        public Task<string> WeekPlan(InputDto input)
+        {
+            return _ResourceExamineAppService.WeekPlan(input);
+        }
     }
 }