|
@@ -8,6 +8,7 @@ using Business.SaleForecast;
|
|
|
using Business.StructuredDB.WMS;
|
|
using Business.StructuredDB.WMS;
|
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
using Spire.Pdf.General.Render.Decode.Jpeg2000.j2k.quantization;
|
|
using Spire.Pdf.General.Render.Decode.Jpeg2000.j2k.quantization;
|
|
|
|
|
+using Spire.Pdf.General.Render.Decode.Jpeg2000.j2k.roi.encoder;
|
|
|
using System;
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
@@ -451,7 +452,7 @@ namespace Business.SaleForecastManagement
|
|
|
var nextMonDFcsts = domesticFcst.Where(p => p.PlanMonth == strN2).ToList();
|
|
var nextMonDFcsts = domesticFcst.Where(p => p.PlanMonth == strN2).ToList();
|
|
|
var nextMonT2Fcsts = T2Fcsts.Where(p => p.PlanMonth == strN2).ToList();
|
|
var nextMonT2Fcsts = T2Fcsts.Where(p => p.PlanMonth == strN2).ToList();
|
|
|
var nextMonMonitors = monitorSettings.Where(p => p.PlanMonth == strN1).ToList();
|
|
var nextMonMonitors = monitorSettings.Where(p => p.PlanMonth == strN1).ToList();
|
|
|
- var replenishs = MonthlyReplenish(input, nextMonPFcsts, nextMonDFcsts, nextMonT2Fcsts, standards, items, holidays, nextMonMonitors);
|
|
|
|
|
|
|
+ var replenishs = MonthlyReplenish(input,strN1, nextMonPFcsts, nextMonDFcsts, nextMonT2Fcsts, standards, items, holidays, nextMonMonitors);
|
|
|
|
|
|
|
|
//保存数据
|
|
//保存数据
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
|
|
using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
|
|
@@ -615,6 +616,7 @@ namespace Business.SaleForecastManagement
|
|
|
/// T1、平台自动补货
|
|
/// T1、平台自动补货
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
/// <param name="input"></param>
|
|
|
|
|
+ /// <param name="strN1">计划补货月份:N+1月</param>
|
|
|
/// <param name="platformFcsts">平台预测</param>
|
|
/// <param name="platformFcsts">平台预测</param>
|
|
|
/// <param name="domesticFcsts">T1预测</param>
|
|
/// <param name="domesticFcsts">T1预测</param>
|
|
|
/// <param name="standards">标准SKU设置</param>
|
|
/// <param name="standards">标准SKU设置</param>
|
|
@@ -622,25 +624,23 @@ namespace Business.SaleForecastManagement
|
|
|
/// <param name="holidays">节假日</param>
|
|
/// <param name="holidays">节假日</param>
|
|
|
/// <param name="monitorSettings">库存监控月份设置</param>
|
|
/// <param name="monitorSettings">库存监控月份设置</param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
- public List<crm_planorder> MonthlyReplenish(InputDto input, List<PlatformFcstCollect> platformFcsts, List<DomesticTerminalFcst> domesticFcsts, List<DomesticTerminalFcst> T2Fcsts, List<StandardItemModelSet> standards, List<ic_item> items, List<HolidayMaster> holidays, List<PlatStockMonitorSetting> monitorSettings)
|
|
|
|
|
|
|
+ public List<crm_planorder> MonthlyReplenish(InputDto input,string strN1, List<PlatformFcstCollect> platformFcsts, List<DomesticTerminalFcst> domesticFcsts, List<DomesticTerminalFcst> T2Fcsts, List<StandardItemModelSet> standards, List<ic_item> items, List<HolidayMaster> holidays, List<PlatStockMonitorSetting> monitorSettings)
|
|
|
{
|
|
{
|
|
|
List<crm_planorder> planorders = new List<crm_planorder>();
|
|
List<crm_planorder> planorders = new List<crm_planorder>();
|
|
|
- //获取T1、平台预测数据中规格型号对应的不同版本的物料编码
|
|
|
|
|
|
|
+ //获取T1中规格型号对应的不同版本的物料编码
|
|
|
var T1Models = domesticFcsts.Select(p => p.Model).Distinct().ToList();
|
|
var T1Models = domesticFcsts.Select(p => p.Model).Distinct().ToList();
|
|
|
- var PModels = platformFcsts.Select(p => p.Model).Distinct().ToList();
|
|
|
|
|
- List<string> models = T1Models;
|
|
|
|
|
- models.AddRange(PModels);
|
|
|
|
|
- models = models.Distinct().ToList();
|
|
|
|
|
- List<SkuVersionSet> skus = _skuVersionSet.GetListAsync(p=>models.Contains(p.Model) && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id).Result;
|
|
|
|
|
|
|
+ List<SkuVersionSet> skus = _skuVersionSet.GetListAsync(p=> T1Models.Contains(p.Model) && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id && !p.IsDeleted).Result;
|
|
|
//获取T1库存
|
|
//获取T1库存
|
|
|
List<string> itemNums = skus.Select(p=>p.ItemNum).Distinct().ToList();
|
|
List<string> itemNums = skus.Select(p=>p.ItemNum).Distinct().ToList();
|
|
|
List<LocationDetail> locationDetails = _locationDetail.Select(p=> itemNums.Contains(p.ItemNum) && p.Domain == input.factory_id.ToString() && p.IsActive);
|
|
List<LocationDetail> locationDetails = _locationDetail.Select(p=> itemNums.Contains(p.ItemNum) && p.Domain == input.factory_id.ToString() && p.IsActive);
|
|
|
|
|
+
|
|
|
//获取临期库存设置
|
|
//获取临期库存设置
|
|
|
- GeneralizedCodeMaster master = _generalizedCodeMaster.Select(p=>p.Domain == input.factory_id.ToString() && p.IsActive && p.Val == "LongPeriodItemPlanMonth").FirstOrDefault();
|
|
|
|
|
|
|
+ GeneralizedCodeMaster master = _generalizedCodeMaster.Select(p => p.Domain == input.factory_id.ToString() && p.IsActive && p.Val == "LongPeriodItemPlanMonth").FirstOrDefault();
|
|
|
int month = master == null ? 0 : Convert.ToInt16(master.UDeci1);
|
|
int month = master == null ? 0 : Convert.ToInt16(master.UDeci1);
|
|
|
DateTime strTime = Convert.ToDateTime(platformFcsts[0].PlanMonth + "-01").AddMonths(month);
|
|
DateTime strTime = Convert.ToDateTime(platformFcsts[0].PlanMonth + "-01").AddMonths(month);
|
|
|
//获取平台库存
|
|
//获取平台库存
|
|
|
- List<WMS_PlatformInventory> pInventories = _platformInventory.GetListAsync(p=> p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id && p.PeriodOfValidity >= strTime).Result;
|
|
|
|
|
|
|
+ var PModels = platformFcsts.Select(p => p.Model).Distinct().ToList();
|
|
|
|
|
+ List<WMS_PlatformInventory> pInventories = _platformInventory.GetListAsync(p=> PModels.Contains(p.SpecificationModel) && p.tenant_id == input.tenant_id && p.company_id == input.company_id && p.factory_id == input.factory_id && p.PeriodOfValidity >= strTime).Result;
|
|
|
|
|
|
|
|
//计算T1补货
|
|
//计算T1补货
|
|
|
foreach (var item in T1Models)
|
|
foreach (var item in T1Models)
|
|
@@ -666,36 +666,176 @@ namespace Business.SaleForecastManagement
|
|
|
packQty = curItem == null ? 1 : (curItem.minpackqty.GetValueOrDefault() == 0.0m ? 1 : curItem.minpackqty.Value);
|
|
packQty = curItem == null ? 1 : (curItem.minpackqty.GetValueOrDefault() == 0.0m ? 1 : curItem.minpackqty.Value);
|
|
|
cycle = curStd.ReplenishCycle;
|
|
cycle = curStd.ReplenishCycle;
|
|
|
}
|
|
}
|
|
|
- //TODO:获取成品库存、在制库存、灭菌库存,参与计算
|
|
|
|
|
//N+1月使用N+2月的再订货点参与计算
|
|
//N+1月使用N+2月的再订货点参与计算
|
|
|
decimal rop = CalcRop(curFcsts[0].PlanMonth + "-01", curFcsts.Sum(p=>p.Qty), packQty, holidays, cycle);
|
|
decimal rop = CalcRop(curFcsts[0].PlanMonth + "-01", curFcsts.Sum(p=>p.Qty), packQty, holidays, cycle);
|
|
|
if(sumQty < rop)
|
|
if(sumQty < rop)
|
|
|
{
|
|
{
|
|
|
planorders.Add(new crm_planorder {
|
|
planorders.Add(new crm_planorder {
|
|
|
- PlanMonth = curFcsts[0].PlanMonth,
|
|
|
|
|
|
|
+ PlanMonth = strN1,
|
|
|
Model = curFcsts[0].Model,
|
|
Model = curFcsts[0].Model,
|
|
|
ItemNum = curStd?.ItemNumber,
|
|
ItemNum = curStd?.ItemNumber,
|
|
|
ProdLine = curFcsts[0].ProdLine,
|
|
ProdLine = curFcsts[0].ProdLine,
|
|
|
ProdType = "",
|
|
ProdType = "",
|
|
|
Qty = rop,
|
|
Qty = rop,
|
|
|
- Type = "计划单-T1直发补货",
|
|
|
|
|
- Source = "系统运算",
|
|
|
|
|
- tenant_id = input.tenant_id,
|
|
|
|
|
- company_id= input.company_id,
|
|
|
|
|
- factory_id= input.factory_id,
|
|
|
|
|
- org_id= input.org_id,
|
|
|
|
|
- create_by= input.create_by,
|
|
|
|
|
- create_by_name= input.create_by_name,
|
|
|
|
|
- create_time = DateTime.Now
|
|
|
|
|
|
|
+ Type = "计划单-T1直发补货"
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- //计算平台补货:海王+国科
|
|
|
|
|
- foreach (var item in PModels)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ //计算平台补货:海王
|
|
|
|
|
+ var hwFcsts = platformFcsts.Where(p => p.Platform == "海王").ToList();
|
|
|
|
|
+ var hwModels = hwFcsts.Select(p=>p.Model).Distinct().ToList();
|
|
|
|
|
+ foreach (var item in hwModels)
|
|
|
{
|
|
{
|
|
|
|
|
+ //获取当前规格型号对应的平台预测数据
|
|
|
|
|
+ var curFcsts = hwFcsts.Where(p => p.Model == item).ToList();
|
|
|
|
|
+ //当前规格型号对应的库存数量
|
|
|
|
|
+ decimal sumQty = 0.00m;
|
|
|
|
|
+ //当前规格型号对应标准SKU的最小包装单位、补货周期
|
|
|
|
|
+ var curStd = standards.FirstOrDefault(p => p.Model == item);
|
|
|
|
|
+ decimal packQty = 1m;//最小包装单位
|
|
|
|
|
+ decimal cycle = 0m;//补货周期
|
|
|
|
|
+ if (curStd != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ var curItem = items.FirstOrDefault(p => p.number == curStd.ItemNumber);
|
|
|
|
|
+ packQty = curItem == null ? 1 : (curItem.minpackqty.GetValueOrDefault() == 0.0m ? 1 : curItem.minpackqty.Value);
|
|
|
|
|
+ cycle = curStd.ReplenishCycle;
|
|
|
|
|
+ }
|
|
|
|
|
+ //T2海王预测数据
|
|
|
|
|
+ var curT2Hws = T2Fcsts.Where(p => p.Model == item && p.TypeEnum == 4).ToList();
|
|
|
|
|
+ //计算Rop:N+1月使用N+2月的再订货点参与计算
|
|
|
|
|
+ decimal rop = CalcRop(curFcsts[0].PlanMonth + "-01", curT2Hws.Sum(p => p.Qty), packQty, holidays, cycle);
|
|
|
|
|
+ //获取海王当前规格型号库存
|
|
|
|
|
+ sumQty = pInventories.Where(p => p.SpecificationModel == item && p.Code == "HW0001").Sum(p=>p.InventoryQuantity);
|
|
|
|
|
+ //获取N+1月的库存监控设置
|
|
|
|
|
+ var curMonitor = monitorSettings.FirstOrDefault(p => p.Platform == "海王" && p.ProdType == curFcsts[0].ProdType);
|
|
|
|
|
+ if (curMonitor == null)
|
|
|
|
|
+ {
|
|
|
|
|
+ new NLogHelper("MonthlyCapacityLoadAppService").WriteLog("DemandAnalysis", "海王未维护产品类型为【"+ curFcsts[0].ProdType + "】的库存监控月份", _currentTenant.Id.ToString());
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ //最小覆盖月份库存
|
|
|
|
|
+ var minQty = rop * curMonitor.MinTimes;
|
|
|
|
|
+ //最大库存月份库存
|
|
|
|
|
+ var maxQty = rop * curMonitor.MaxTimes;
|
|
|
|
|
+ //需补货数量
|
|
|
|
|
+ decimal needQty = 0m;
|
|
|
|
|
+ if (sumQty >= minQty && sumQty < maxQty)//大于等于最低库存覆盖月,小于最高库存覆盖月
|
|
|
|
|
+ {
|
|
|
|
|
+ planorders.Add(new crm_planorder
|
|
|
|
|
+ {
|
|
|
|
|
+ PlanMonth = strN1,
|
|
|
|
|
+ Model = curFcsts[0].Model,
|
|
|
|
|
+ ItemNum = curStd?.ItemNumber,
|
|
|
|
|
+ ProdLine = curT2Hws[0].ProdLine,
|
|
|
|
|
+ ProdType = "",
|
|
|
|
|
+ Qty = maxQty - sumQty,
|
|
|
|
|
+ Type = "计划单-T2平台补货"
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ if (sumQty < minQty)//低于最低库存覆盖月
|
|
|
|
|
+ {
|
|
|
|
|
+ while (sumQty < minQty)
|
|
|
|
|
+ {
|
|
|
|
|
+ sumQty += rop;
|
|
|
|
|
+ needQty += rop;
|
|
|
|
|
+ }
|
|
|
|
|
+ planorders.Add(new crm_planorder
|
|
|
|
|
+ {
|
|
|
|
|
+ PlanMonth = strN1,
|
|
|
|
|
+ Model = curFcsts[0].Model,
|
|
|
|
|
+ ItemNum = curStd?.ItemNumber,
|
|
|
|
|
+ ProdLine = curT2Hws[0].ProdLine,
|
|
|
|
|
+ ProdType = "",
|
|
|
|
|
+ Qty = needQty,
|
|
|
|
|
+ Type = "计划单-T2平台补货"
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ //计算平台补货:国科
|
|
|
|
|
+ var gkFcsts = platformFcsts.Where(p => p.Platform == "国科").ToList();
|
|
|
|
|
+ var gkModels = gkFcsts.Select(p => p.Model).Distinct().ToList();
|
|
|
|
|
+ foreach (var item in gkModels)
|
|
|
|
|
+ {
|
|
|
|
|
+ //获取当前规格型号对应的预测数据
|
|
|
|
|
+ var curFcsts = gkFcsts.Where(p => p.Model == item).ToList();
|
|
|
|
|
+ //当前规格型号对应的库存数量
|
|
|
|
|
+ decimal sumQty = 0.00m;
|
|
|
|
|
+ //当前规格型号对应标准SKU的最小包装单位、补货周期
|
|
|
|
|
+ var curStd = standards.FirstOrDefault(p => p.Model == item);
|
|
|
|
|
+ decimal packQty = 1m;//最小包装单位
|
|
|
|
|
+ decimal cycle = 0m;//补货周期
|
|
|
|
|
+ if (curStd != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ var curItem = items.FirstOrDefault(p => p.number == curStd.ItemNumber);
|
|
|
|
|
+ packQty = curItem == null ? 1 : (curItem.minpackqty.GetValueOrDefault() == 0.0m ? 1 : curItem.minpackqty.Value);
|
|
|
|
|
+ cycle = curStd.ReplenishCycle;
|
|
|
|
|
+ }
|
|
|
|
|
+ //T2国科预测数据
|
|
|
|
|
+ var curT2Gks = T2Fcsts.Where(p => p.Model == item && p.TypeEnum == 5).ToList();
|
|
|
|
|
+ //计算Rop:N+1月使用N+2月的再订货点参与计算
|
|
|
|
|
+ decimal rop = CalcRop(curFcsts[0].PlanMonth + "-01", curT2Gks.Sum(p => p.Qty), packQty, holidays, cycle);
|
|
|
|
|
+ //获取国科当前规格型号库存
|
|
|
|
|
+ sumQty = pInventories.Where(p => p.SpecificationModel == item && p.Code == "GK0001").Sum(p => p.InventoryQuantity);
|
|
|
|
|
+ //获取N+1月的库存监控设置
|
|
|
|
|
+ var curMonitor = monitorSettings.FirstOrDefault(p => p.Platform == "GK0001" && p.ProdType == curFcsts[0].ProdType);
|
|
|
|
|
+ if (curMonitor == null)
|
|
|
|
|
+ {
|
|
|
|
|
+ new NLogHelper("MonthlyCapacityLoadAppService").WriteLog("DemandAnalysis", "国科未维护产品类型为【" + curFcsts[0].ProdType + "】的库存监控月份", _currentTenant.Id.ToString());
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ //最小覆盖月份库存
|
|
|
|
|
+ var minQty = rop * curMonitor.MinTimes;
|
|
|
|
|
+ //最大库存月份库存
|
|
|
|
|
+ var maxQty = rop * curMonitor.MaxTimes;
|
|
|
|
|
+ //需补货数量
|
|
|
|
|
+ decimal needQty = 0m;
|
|
|
|
|
+ if (sumQty >= minQty && sumQty < maxQty)
|
|
|
|
|
+ {
|
|
|
|
|
+ planorders.Add(new crm_planorder
|
|
|
|
|
+ {
|
|
|
|
|
+ PlanMonth = strN1,
|
|
|
|
|
+ Model = curFcsts[0].Model,
|
|
|
|
|
+ ItemNum = curStd?.ItemNumber,
|
|
|
|
|
+ ProdLine = curT2Gks[0].ProdLine,
|
|
|
|
|
+ ProdType = "",
|
|
|
|
|
+ Qty = maxQty - sumQty,
|
|
|
|
|
+ Type = "计划单-T2平台补货"
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ if (sumQty < minQty)
|
|
|
|
|
+ {
|
|
|
|
|
+ while (sumQty < minQty)
|
|
|
|
|
+ {
|
|
|
|
|
+ sumQty += rop;
|
|
|
|
|
+ needQty += rop;
|
|
|
|
|
+ }
|
|
|
|
|
+ planorders.Add(new crm_planorder
|
|
|
|
|
+ {
|
|
|
|
|
+ PlanMonth = strN1,
|
|
|
|
|
+ Model = curFcsts[0].Model,
|
|
|
|
|
+ ItemNum = curStd?.ItemNumber,
|
|
|
|
|
+ ProdLine = curT2Gks[0].ProdLine,
|
|
|
|
|
+ ProdType = "",
|
|
|
|
|
+ Qty = needQty,
|
|
|
|
|
+ Type = "计划单-T2平台补货"
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ planorders.ForEach(p => {
|
|
|
|
|
+ p.Source = "系统运算";
|
|
|
|
|
+ p.tenant_id = input.tenant_id;
|
|
|
|
|
+ p.company_id = input.company_id;
|
|
|
|
|
+ p.factory_id = input.factory_id;
|
|
|
|
|
+ p.org_id = input.org_id;
|
|
|
|
|
+ p.create_by = input.create_by;
|
|
|
|
|
+ p.create_by_name = input.create_by_name;
|
|
|
|
|
+ p.create_time = DateTime.Now;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|