|
|
@@ -30,6 +30,7 @@ using Microsoft.EntityFrameworkCore;
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
using System.Collections;
|
|
|
using MongoDB.Driver.Linq;
|
|
|
+using System.Reflection;
|
|
|
|
|
|
namespace Business.Replenishment
|
|
|
{
|
|
|
@@ -105,7 +106,8 @@ namespace Business.Replenishment
|
|
|
private readonly ISqlRepository<ScheduleResultOpMaster> _scheduleResultOpMaster;
|
|
|
private readonly IRepository<ProductionMasterPlan, long> _productionMasterPlan;
|
|
|
private readonly IRepository<ReplenishmentWeekPlan, long> _replenishmentWeekPlan;
|
|
|
-
|
|
|
+ private readonly IRepository<b_examine_result, long> _mysql_examine_result;
|
|
|
+ private readonly IRepository<b_bom_child_examine, long> _mysql_bom_child_examine;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 年度销售预测
|
|
|
@@ -236,8 +238,8 @@ namespace Business.Replenishment
|
|
|
ISqlRepository<SAPInv> SAPInv,
|
|
|
IRepository<srm_purchase, long> srmPurchase,
|
|
|
ISqlRepository<MonthlyShipmentPlan> monthlyShipmentPlan,
|
|
|
- ISqlRepository<GeneralizedCodeMaster> generalizedCodeMaster,
|
|
|
- ISqlRepository<rf_serialnumber> rf_serialnumber,
|
|
|
+ ISqlRepository<GeneralizedCodeMaster> generalizedCodeMaster,
|
|
|
+ ISqlRepository<rf_serialnumber> rf_serialnumber,
|
|
|
ISqlRepository<LocationDetail> locationDetail,
|
|
|
IRepository<mo_ic_item, long> ic_item,
|
|
|
IRepository<ic_item, long> mysql_ic_item,
|
|
|
@@ -299,8 +301,9 @@ namespace Business.Replenishment
|
|
|
IRepository<MonthlyProdCapacityDtl, long> monthlyProdCapacityDtl,
|
|
|
IRepository<crm_planorder, long> crm_planorder,
|
|
|
IRepository<WMS_PlatformInventory, long> platformInventory,
|
|
|
- IRepository<ReplenishmentWeekPlan,long> replenishmentWeekPlan,
|
|
|
-
|
|
|
+ IRepository<ReplenishmentWeekPlan, long> replenishmentWeekPlan,
|
|
|
+ IRepository<b_examine_result, long> mysql_examine_result,
|
|
|
+ IRepository<b_bom_child_examine, long> mysql_bom_child_examine,
|
|
|
|
|
|
SerialNumberAppService serialNumberAppService,
|
|
|
PretreatmentAppService pretreatmentAppService,
|
|
|
@@ -374,6 +377,8 @@ namespace Business.Replenishment
|
|
|
_scheduleResultOpMaster = scheduleResultOpMaster;
|
|
|
_productionMasterPlan=productionMasterPlan;
|
|
|
_replenishmentWeekPlan=replenishmentWeekPlan;
|
|
|
+ _mysql_examine_result = mysql_examine_result;
|
|
|
+ _mysql_bom_child_examine= mysql_bom_child_examine;
|
|
|
|
|
|
_PlatformInventory = PlatformInventory;
|
|
|
_workOrdRouting = workOrdRouting;
|
|
|
@@ -908,14 +913,6 @@ namespace Business.Replenishment
|
|
|
{
|
|
|
//1.获取补货模型全局参数
|
|
|
ReplenishmentDto replenishmentDto = GetROPParam(input.factory_id.ToString());
|
|
|
-
|
|
|
- //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")}";
|
|
|
@@ -924,20 +921,21 @@ namespace Business.Replenishment
|
|
|
List<string> planItemList = planList?.Select(a => a.SAPItemNumber).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 bomList = _ic_bom.GetListAsync(a => planItemList.Contains(a.item_number) && !a.IsDeleted && a.factory_id == input.factory_id).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;
|
|
|
-
|
|
|
+ var monthPlan = _productionMasterPlan.GetListAsync(a => planItemList.Contains(a.ItemNumber) && !a.IsDeleted && a.factory_id == input.factory_id).Result;
|
|
|
//获取补货模型前H周期和未来F个周期的数据
|
|
|
var ropModelList = _replenishmentROP.GetListAsync(a => a.zero_based_seqno >= -1 * replenishmentDto.HistoryOutStockMonth && a.zero_based_seqno <= replenishmentDto.SaleFcstMonth && planItemList.Contains(a.number)).Result;
|
|
|
planList = planList.OrderBy(a => a.OrderNum).ToList();
|
|
|
List<mes_morder> moList = new List<mes_morder>();
|
|
|
List<mes_moentry> moentryList = new List<mes_moentry>();
|
|
|
- long? bang_id = help.NextId();
|
|
|
+ List<ReplenishmentWeekPlan> weekPlan = new List<ReplenishmentWeekPlan>();
|
|
|
+ long bang_id = help.NextId();
|
|
|
DateTime currentTime = DateTime.Now;
|
|
|
int week = Convert.ToInt32(currentTime.DayOfWeek);
|
|
|
week = week == 0 ? 7 : week;
|
|
|
|
|
|
- var list = _serialNumberAppService.GetBillNo(input.factory_id.ToString(), "MPO", 1, "", 1);
|
|
|
+ int count = planList.Count * 12;
|
|
|
+ var list = _serialNumberAppService.GetBillNo(input.factory_id.ToString(), "MPO", count, "", 1);
|
|
|
+ var nbrlistDto = _serialNumberAppService.GetBillNo(input.factory_id.ToString(), "M5", count, "", 1);
|
|
|
int j = 0;
|
|
|
for (int i=0;i<12;i++)
|
|
|
{
|
|
|
@@ -945,6 +943,7 @@ namespace Business.Replenishment
|
|
|
{
|
|
|
var ic_item = itemList.Find(x => x.number == a.SAPItemNumber);
|
|
|
var itemrop= ropModelList.Find(x=>x.number == a.SAPItemNumber);
|
|
|
+ var monthPlanItem = monthPlan.Find(x => x.ItemNumber == a.SAPItemNumber);
|
|
|
if (ic_item?.erp_cls == 1)
|
|
|
{
|
|
|
var bom = bomList.Find(b => b.item_number == a.SAPItemNumber);
|
|
|
@@ -968,6 +967,7 @@ namespace Business.Replenishment
|
|
|
mes_Morder.product_name = ic_item.name;
|
|
|
mes_Morder.morder_date = DateTime.Now.Date.AddDays(1);
|
|
|
//成品半成品取周一开始 + 取供应提前期为结束时间
|
|
|
+ mes_Morder.moentry_stime = currentTime.AddDays(1 - week + 7 * (i + 1));
|
|
|
mes_Morder.moentry_sys_etime = currentTime.AddDays(1 - week + 7*(i+1)+ Convert.ToDouble(itemrop.supply_leadtime));
|
|
|
//mes_Morder.morder_fstate = "计划";
|
|
|
//TODO:目前没有取值位置
|
|
|
@@ -1000,6 +1000,42 @@ namespace Business.Replenishment
|
|
|
mes_Moentry.bang_id = bang_id;
|
|
|
moList.Add(mes_Morder);
|
|
|
moentryList.Add(mes_Moentry);
|
|
|
+
|
|
|
+ ReplenishmentWeekPlan weekItem = new ReplenishmentWeekPlan();
|
|
|
+ weekItem.GenerateNewId(help.NextId());
|
|
|
+ weekItem.Priority = 1;
|
|
|
+ weekItem.Area = itemrop.area;
|
|
|
+ weekItem.PlanStartDate = mes_Morder.moentry_stime.Value;
|
|
|
+ weekItem.Week =$"WK{GetWeekOfYear(mes_Morder.moentry_stime.Value).ToString("00")}";
|
|
|
+ weekItem.OrderNO = list[j].NbrResult;
|
|
|
+ weekItem.ProductionOrder = nbrlistDto[j].NbrResult;
|
|
|
+ weekItem.SAPOrderNO = "";
|
|
|
+ weekItem.OrderType = "量产";
|
|
|
+ weekItem.ProductionBatch = "";
|
|
|
+ weekItem.ProductionStatus = "";
|
|
|
+ weekItem.ProdLine =a.ProdLine;
|
|
|
+ weekItem.ProdRange =a.ProdRange;
|
|
|
+ weekItem.Line = monthPlanItem.WorkshopLine;
|
|
|
+ weekItem.ItemNumber =a.SAPItemNumber;
|
|
|
+ weekItem.Model =a.Model;
|
|
|
+ weekItem.Languages =a.Languages;
|
|
|
+ weekItem.Qty = mes_Morder.morder_production_number.Value;
|
|
|
+ weekItem.ItemStatus = "";
|
|
|
+ weekItem.PlanKittingDate = DateTime.Now;
|
|
|
+ if(itemrop.area=="国内")
|
|
|
+ {
|
|
|
+ weekItem.SterilizationDate = mes_Morder.moentry_sys_etime.Value.AddDays(8);
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ weekItem.SterilizationDate = mes_Morder.moentry_sys_etime.Value.AddDays(15);
|
|
|
+ }
|
|
|
+
|
|
|
+ weekItem.InStockDate = mes_Morder.moentry_sys_etime;
|
|
|
+ weekItem.AssembleHours = 0;
|
|
|
+ weekItem.HeatSealHours = 0;
|
|
|
+ weekItem.PackageHours = 0;
|
|
|
+ weekItem.TotalHours = 0;
|
|
|
+ weekPlan.Add(weekItem);
|
|
|
j++;
|
|
|
}
|
|
|
});
|
|
|
@@ -1007,52 +1043,42 @@ namespace Business.Replenishment
|
|
|
await _mysql_mes_morder.InsertManyAsync(moList);
|
|
|
await _mysql_mes_moentry.InsertManyAsync(moentryList);
|
|
|
|
|
|
- await PlanOrderResourceCheck(moList, moentryList, input);
|
|
|
-
|
|
|
- var nbrlistDto = _serialNumberAppService.GetBillNo(input.factory_id.ToString(),"M5", moList.Count, "", 1);
|
|
|
- List<ReplenishmentWeekPlan> weekPlan = new List<ReplenishmentWeekPlan>();
|
|
|
- int k = 0;
|
|
|
- for (int i = 0; i < 12; i++)
|
|
|
+ await PlanOrderResourceCheck(moList, moentryList, bang_id, input);
|
|
|
+ List<RoutingOpDetail> routingOps = _routingOpDetail.Select(p => planItemList.Contains(p.RoutingCode) && p.Domain == input.factory_id.ToString() && p.IsActive);
|
|
|
+ var examine_resultList= _mysql_examine_result.GetListAsync(a=>a.bangid == bang_id).Result;
|
|
|
+ weekPlan.ForEach(a =>
|
|
|
{
|
|
|
- planList.ForEach(a =>
|
|
|
+ var moItem = examine_resultList.Find(b => b.morder_no == a.OrderNO);
|
|
|
+ var routingOp = routingOps.Where(x => x.RoutingCode == a.ItemNumber).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();
|
|
|
+ if (moItem!=null && moItem.kitting_times<a.PlanStartDate)
|
|
|
+ {
|
|
|
+ a.ItemStatus = "齐套";
|
|
|
+ a.PlanKittingDate = moItem.kitting_times;
|
|
|
+ a.AssembleHours = Assembly == null ? 0 : Assembly.RunTime * a.Qty;
|
|
|
+ a.HeatSealHours = HeatSealing == null ? 0 : HeatSealing.RunTime * a.Qty;
|
|
|
+ a.PackageHours = Packaging == null ? 0 : Packaging.RunTime * a.Qty;
|
|
|
+ a.TotalHours = a.AssembleHours + a.HeatSealHours + a.PackageHours;
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- var ic_item = itemList.Find(x => x.number == a.SAPItemNumber);
|
|
|
- var itemrop = ropModelList.Find(x => x.number == a.SAPItemNumber);
|
|
|
- if (ic_item?.erp_cls == 1)
|
|
|
- {
|
|
|
- var bom = bomList.Find(b => b.item_number == a.SAPItemNumber);
|
|
|
- ReplenishmentWeekPlan week = new ReplenishmentWeekPlan();
|
|
|
- week.GenerateNewId(help.NextId());
|
|
|
- week.Priority = 1;
|
|
|
- week.Area = itemrop.area;
|
|
|
- week.PlanStartDate = DateTime.Now;
|
|
|
- week.Week = "";
|
|
|
- week.OrderNO = "";
|
|
|
- week.ProductionOrder = nbrlistDto[k].NbrResult;
|
|
|
- week.SAPOrderNO = "";
|
|
|
- week.OrderType = "";
|
|
|
- week.ProductionBatch = "";
|
|
|
- week.ProductionStatus = "";
|
|
|
- week.ProdLine = "";
|
|
|
- week.ProdRange = "";
|
|
|
- week.Line = "";
|
|
|
- week.ItemNumber = "";
|
|
|
- week.Model = "";
|
|
|
- week.Languages = "";
|
|
|
- week.Qty =0;
|
|
|
- week.ItemStatus = "";
|
|
|
- week.PlanKittingDate =DateTime.Now;
|
|
|
- week.SterilizationDate = DateTime.Now;
|
|
|
- week.InStockDate = DateTime.Now;
|
|
|
- week.AssembleHours = 0;
|
|
|
- week.HeatSealHours = 0;
|
|
|
- week.PackageHours = 0;
|
|
|
- week.TotalHours = 0;
|
|
|
- weekPlan.Add(week);
|
|
|
- j++;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+ a.ItemStatus = "欠料";
|
|
|
+ a.PlanKittingDate = moItem.kitting_times;
|
|
|
+ a.AssembleHours = Assembly == null ? 0 : Assembly.RunTime * a.Qty;
|
|
|
+ a.HeatSealHours = HeatSealing == null ? 0 : HeatSealing.RunTime * a.Qty;
|
|
|
+ a.PackageHours = Packaging == null ? 0 : Packaging.RunTime * a.Qty;
|
|
|
+ a.TotalHours = a.AssembleHours + a.HeatSealHours + a.PackageHours;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ await _replenishmentWeekPlan.InsertManyAsync(weekPlan);
|
|
|
+ //TODO:优先级排序
|
|
|
+
|
|
|
return "OK";
|
|
|
}
|
|
|
|
|
|
@@ -1280,7 +1306,7 @@ namespace Business.Replenishment
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<string> PlanOrderResourceCheck(List<mes_morder> Mes_Morders, List<mes_moentry> moentryList, InputDto input)
|
|
|
+ public async Task<string> PlanOrderResourceCheck(List<mes_morder> Mes_Morders, List<mes_moentry> moentryList,long bangid, InputDto input)
|
|
|
{
|
|
|
//先排除锁定期内的工单 //优先级排序
|
|
|
var sysSet = _generalizedCodeMaster.Select(s => s.FldName == "SystemConfig" && s.Val == "WorkOrderLockPeriod" && s.Domain == input.company_id.ToString()).ToList();
|
|
|
@@ -1352,7 +1378,7 @@ namespace Business.Replenishment
|
|
|
_scheduleResultOpMaster.Delete(s => monolist.Contains(s.WorkOrd));
|
|
|
}
|
|
|
//只走计划工单
|
|
|
- var rtn = await OrderKittingCheck(Mes_Morders, moentryList, true);
|
|
|
+ var rtn = await OrderKittingCheck(Mes_Morders, moentryList, bangid, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -1402,7 +1428,7 @@ namespace Business.Replenishment
|
|
|
/// 工单检查物料齐套
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
- public async Task<PschedDto> OrderKittingCheck(List<mes_morder> mo_Mes_Morders, List<mes_moentry> moentryList, bool planCheck = false)
|
|
|
+ public async Task<PschedDto> OrderKittingCheck(List<mes_morder> mo_Mes_Morders, List<mes_moentry> moentryList,long bangid, bool planCheck = false)
|
|
|
{
|
|
|
//资源检查结果
|
|
|
PschedDto rtn = new PschedDto();
|
|
|
@@ -1419,8 +1445,6 @@ namespace Business.Replenishment
|
|
|
param.factoryId = input.factoryId;
|
|
|
param.checkflag = false;
|
|
|
param.checkPlan = planCheck;
|
|
|
- //生成当前计算bangid
|
|
|
- long bangid = help.NextId();
|
|
|
|
|
|
/*List<mo_mes_morder> mo_Mes_Morders = _mes_morder.GetManyByCondition(x => x.start_time > DateTime
|
|
|
.Now.Date.AddDays(1) && x.start_time < DateTime
|
|
|
@@ -2268,6 +2292,7 @@ namespace Business.Replenishment
|
|
|
List<mes_morder> moList=new List<mes_morder>();
|
|
|
List<mes_moentry> moentryList = new List<mes_moentry>();
|
|
|
var list = _serialNumberAppService.GetBillNo(input.factory_id.ToString(), "MPO", productList.Count(), "", 1);
|
|
|
+ long bangid = help.NextId();
|
|
|
for (int i = 0;i< productList.Count();i++)
|
|
|
{
|
|
|
var ic_item = planList.Find(x => x.number == productList[i].SAPItemNumber);
|
|
|
@@ -2325,7 +2350,7 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
await _mysql_mes_morder.InsertManyAsync(moList);
|
|
|
await _mysql_mes_moentry.InsertManyAsync(moentryList);
|
|
|
- await PlanOrderResourceCheck(moList,moentryList,input);
|
|
|
+ await PlanOrderResourceCheck(moList,moentryList, bangid,input);
|
|
|
return "OK";
|
|
|
}
|
|
|
|