|
|
@@ -4662,7 +4662,7 @@ namespace Business.Replenishment
|
|
|
/// 工单检查物料齐套
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
- public async Task<PschedDto> OrderKittingCheck(List<mes_morder> mo_Mes_Morders, List<mes_moentry> moentryList,long bangid,string analogCalcVersion, bool isChangePriority, bool planCheck = false)
|
|
|
+ public async Task<PschedDto> OrderKittingCheck(List<mes_morder> mo_Mes_Morders, List<mes_moentry> moentryList,long bangid,string analogCalcVersion, bool isChangePriority, bool planCheck = false,bool IsWeekPlan=false)
|
|
|
{
|
|
|
//资源检查结果
|
|
|
PschedDto rtn = new PschedDto();
|
|
|
@@ -4732,7 +4732,37 @@ namespace Business.Replenishment
|
|
|
AutoCreateBomBill(param.company_id.ToString(), autoCreates);
|
|
|
pretreatments = _mysql_b_bom_pretreatment.GetListAsync(s => boms.Select(c => c.mysql_id).ToList().Contains(s.sourceid)).Result;
|
|
|
}
|
|
|
- AsyncItemStockFromWMS(pretreatments);
|
|
|
+ List<string> itemNums = new List<string>();
|
|
|
+ //计算需求
|
|
|
+ List<AlignmentCalcDto> AlignmentCalcList = new List<AlignmentCalcDto>();
|
|
|
+ if (IsWeekPlan)
|
|
|
+ {
|
|
|
+ var nbrList = _nbrMaster.Select(x => x.Domain == param.factoryId.ToString() && (x.Type == "SM" || x.Type == "Z07") && x.Status.ToUpper() != "C").ToList();
|
|
|
+ if (nbrList.Any())
|
|
|
+ {
|
|
|
+ var nbrDtlList = _nbrDetail.Select(x => nbrList.Select(c => c.RecID).Contains(x.NbrRecID) && x.Status.ToUpper() != "C").ToList();
|
|
|
+ if (nbrDtlList.Any())
|
|
|
+ {
|
|
|
+ nbrDtlList.ForEach(x => {
|
|
|
+ if (x.QtyOrd - x.QtyRec > 0)
|
|
|
+ {
|
|
|
+ var dto = AlignmentCalcList.Find(s => s.ItemNum == x.ItemNum);
|
|
|
+ if (dto == null)
|
|
|
+ {
|
|
|
+ dto = new AlignmentCalcDto();
|
|
|
+ dto.ItemNum = x.ItemNum;
|
|
|
+ AlignmentCalcList.Add(dto);
|
|
|
+ }
|
|
|
+ dto.NeedQty += x.QtyOrd - x.QtyRec;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ itemNums.AddRange(AlignmentCalcList.Select(x => x.ItemNum));
|
|
|
+ }
|
|
|
+ var pretreatList = pretreatments.Select(x => x.item_number).Distinct().ToList();
|
|
|
+ itemNums.AddRange(pretreatList);
|
|
|
+ AsyncItemStockFromWMS(itemNums);
|
|
|
|
|
|
//数据库快照-同步mysql库数据到mongoDB中
|
|
|
await DbSnapShot(input.company_id, input.factoryId, bangid, pretreatments, analogCalcVersion);
|
|
|
@@ -4919,18 +4949,71 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //获取工单数据
|
|
|
- var workOrdMasters = _workOrdMaster.Select(p => mo_Mes_Morders.Select(c => c.morder_no).Contains(p.WorkOrd));
|
|
|
- workOrdMasters.ForEach(s => {
|
|
|
- var mo = mo_Mes_Morders.Find(m => m.morder_no == s.WorkOrd);
|
|
|
- if (mo != null)
|
|
|
+
|
|
|
+ if (IsWeekPlan)
|
|
|
+ {
|
|
|
+ foreach (var exami in examines)
|
|
|
{
|
|
|
- //锁定期
|
|
|
- s.OrdDate = mo.moentry_sys_stime;
|
|
|
- s.DueDate = mo.moentry_sys_stime;
|
|
|
+ exami.BomChildExamineList.ForEach(x =>
|
|
|
+ {
|
|
|
+ if ((x.erp_cls == 2 || x.erp_cls == 3) && x.is_use)
|
|
|
+ {
|
|
|
+ var dto = AlignmentCalcList.Find(s => s.ItemNum == x.item_number);
|
|
|
+ if (dto == null)
|
|
|
+ {
|
|
|
+ dto = new AlignmentCalcDto();
|
|
|
+ dto.ItemNum = x.item_number;
|
|
|
+ AlignmentCalcList.Add(dto);
|
|
|
+ }
|
|
|
+ dto.NeedQty += x.needCount;
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
+ var ic_items = _mysql_ic_item.GetListAsync(x => AlignmentCalcList.Select(c => c.ItemNum).Contains(x.number)).Result;
|
|
|
+ //库存
|
|
|
+ var dbitemstockList = _mysql_ic_item_stock.GetListAsync(a => AlignmentCalcList.Select(x => x.ItemNum).Contains(a.icitem_number) && a.factory_id == param.factoryId).Result;
|
|
|
+ //获取PR和PO
|
|
|
+ var DBprmainList = _mysql_srm_pr_main.GetListAsync(x => x.factory_id == param.factoryId && x.state != 0 && x.state != 4 && string.IsNullOrEmpty(x.analogcalcversion) == true && ic_items.Select(a => a.Id).Contains(x.icitem_id.GetValueOrDefault())).Result;
|
|
|
+ //PO、DO
|
|
|
+ var purordmstList = _PurOrdMaster.Select(x => string.IsNullOrEmpty(x.Status) && x.Status.ToUpper() != "C").ToList();
|
|
|
+ var purorddtlList = new List<PurOrdDetail>();
|
|
|
+ if (purordmstList.Any())
|
|
|
+ {
|
|
|
+ purorddtlList = _PurOrdDetail.Select(x => purordmstList.Select(a => a.PurOrd).Contains(x.PurOrd) && x.QtyOrded - x.RctQty > 0 && string.IsNullOrEmpty(x.Status) && x.Status.ToUpper() != "C").ToList();
|
|
|
+ }
|
|
|
+ AlignmentCalcList.ForEach(x =>
|
|
|
+ {
|
|
|
+ var stock = dbitemstockList.Find(c => c.icitem_number == x.ItemNum);
|
|
|
+ if (stock != null)
|
|
|
+ {
|
|
|
+ x.InventoryQty += stock.sqty.GetValueOrDefault();
|
|
|
+ }
|
|
|
+ if (DBprmainList.Any() || prmainlist.Any())
|
|
|
+ {
|
|
|
+ var icitem = ic_items.Find(a => a.number == x.ItemNum);
|
|
|
+ if (icitem != null)
|
|
|
+ {
|
|
|
+ x.ProcureQty += DBprmainList.Where(a => a.icitem_id == icitem.Id).Sum(c => c.pr_aqty.GetValueOrDefault());
|
|
|
+ x.ProcureQty += prmainlist.Where(a => a.icitem_id == icitem.Id).Sum(c => c.pr_aqty.GetValueOrDefault());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (purorddtlList.Any())
|
|
|
+ {
|
|
|
+ x.ProcureQty += purorddtlList.Where(a => a.ItemNum == x.ItemNum).Sum(c => c.QtyOrded - c.RctQty);
|
|
|
+ }
|
|
|
+ //差异数量=工单需求总数-库存数量-PR、PO采购在途数量
|
|
|
+ x.DifferenceQty = x.NeedQty - x.InventoryQty - x.ProcureQty;
|
|
|
+ });
|
|
|
+ //需要增加PR的集合
|
|
|
+ var prAddList = AlignmentCalcList.Where(x => x.DifferenceQty > 0).ToList();
|
|
|
+ //需要减少PR的集合
|
|
|
+ var prDelList = AlignmentCalcList.Where(x => x.DifferenceQty < 0).ToList();
|
|
|
+ var dbPurchaseList = _srm_purchase.GetListAsync(x => AlignmentCalcList.Select(c => c.ItemNum).Contains(x.number)).Result;
|
|
|
+ //获取需要新增的PR
|
|
|
+
|
|
|
+ //数据库需要减少的PR集合
|
|
|
+ }
|
|
|
|
|
|
- });
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
|
|
|
{
|
|
|
try
|
|
|
@@ -6211,12 +6294,12 @@ namespace Business.Replenishment
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- public void AsyncItemStockFromWMS(List<b_bom_pretreatment> bom_Pretreatments)
|
|
|
+ public void AsyncItemStockFromWMS(List<string> itemList)
|
|
|
{
|
|
|
//产品编码
|
|
|
- var itemList = bom_Pretreatments.Select(a => a.item_number).Distinct().ToList();
|
|
|
+ //var itemList = bom_Pretreatments.Select(a => a.item_number).Distinct().ToList();
|
|
|
List<string> itemChildList = new List<string>();
|
|
|
- itemChildList.AddRange(itemList);
|
|
|
+ itemChildList.AddRange(itemList.Distinct());
|
|
|
if (!itemChildList.Any())
|
|
|
{
|
|
|
return;
|