|
|
@@ -16,6 +16,7 @@ using EFCore.BulkExtensions;
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
using MongoDB.Driver;
|
|
|
using MongoDB.Driver.Linq;
|
|
|
+using Newtonsoft.Json;
|
|
|
using System;
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
@@ -3163,9 +3164,7 @@ namespace Business.Replenishment
|
|
|
weekPlan[i].ProductionOrder = morder_noList[i].NbrResult;
|
|
|
weekPlan[i].OrderNO = OrderNOList[i].NbrResult;
|
|
|
}
|
|
|
- await PlanOrderResourceCheck(moList.OrderBy(a=>a.moentry_sys_stime).ToList(), moentryList, bang_id,"",false,false);
|
|
|
-
|
|
|
- var examine_resultList = _mysql_examine_result.GetListAsync(a => a.bangid == bang_id).Result;
|
|
|
+
|
|
|
await _businessDbContext.BulkInsertAsync(moList);
|
|
|
await _businessDbContext.BulkInsertAsync(moentryList);
|
|
|
|
|
|
@@ -3175,16 +3174,14 @@ namespace Business.Replenishment
|
|
|
List<WorkOrdDetail> workOrdDetails = new List<WorkOrdDetail>();
|
|
|
if (moList.Any())
|
|
|
{
|
|
|
- moList.ForEach(s => { s.create_time = DateTime.Now; });
|
|
|
- List<b_bom_child_examine> childExamineList = _mysql_bom_child_examine.GetListAsync(c => examine_resultList.Select(x => x.Id).Contains(c.examine_id.GetValueOrDefault())).Result;
|
|
|
//同步工单
|
|
|
- CreateWorkOrdDates(moList, routingOps, workOrdSave, workOrdRoutingSave, workOrdDetails, examine_resultList, childExamineList);
|
|
|
+ CreateWorkOrdDates(moList, routingOps, workOrdSave, workOrdRoutingSave, workOrdDetails, new List<b_examine_result>(), new List<b_bom_child_examine>());
|
|
|
}
|
|
|
|
|
|
if (workOrdSave.Any())
|
|
|
{
|
|
|
- workOrdSave = CalcPriority(workOrdSave, input.factory_id.ToString());
|
|
|
_businessDbContext.BulkInsert(workOrdSave);
|
|
|
+ CalcPriority(input.factory_id.ToString());
|
|
|
}
|
|
|
var DBworkOrdList = _workOrdMaster.Select(a => workOrdSave.Count > 0 && a.Domain == workOrdSave[0].Domain && workOrdSave.Select(c => c.WorkOrd).Contains(a.WorkOrd));
|
|
|
if (workOrdRoutingSave.Any())
|
|
|
@@ -3203,6 +3200,9 @@ namespace Business.Replenishment
|
|
|
});
|
|
|
_businessDbContext.BulkInsert(workOrdDetails);
|
|
|
}
|
|
|
+ await PlanOrderResourceCheck(moList.OrderBy(a => a.moentry_sys_stime).ToList(), moentryList, bang_id, "", false, false);
|
|
|
+
|
|
|
+ var examine_resultList = _mysql_examine_result.GetListAsync(a => a.bangid == bang_id).Result;
|
|
|
|
|
|
weekPlan.ForEach(a =>
|
|
|
{
|
|
|
@@ -3234,11 +3234,6 @@ namespace Business.Replenishment
|
|
|
a.PackageHours = Packaging == null ? 0 : Packaging.RunTime * a.Qty;
|
|
|
a.TotalHours = a.AssembleHours + a.HeatSealHours + a.PackageHours;
|
|
|
}
|
|
|
- var workOrd = workOrdSave.Find(b => b.WorkOrd == a.ProductionOrder);
|
|
|
- if (workOrd != null)
|
|
|
- {
|
|
|
- a.Priority = workOrd.Priority;
|
|
|
- }
|
|
|
}
|
|
|
});
|
|
|
await _businessDbContext.BulkInsertAsync(weekPlan);
|
|
|
@@ -3327,30 +3322,20 @@ namespace Business.Replenishment
|
|
|
await _businessDbContext.BulkInsertAsync(moList);
|
|
|
await _businessDbContext.BulkInsertAsync(moentryList);
|
|
|
|
|
|
- //2024/01/10:卫亮工单需求对齐采购需求,取所有未下达的工单做资源检查
|
|
|
- var moListCheck=_mysql_mes_morder.GetListAsync(a=>(a.morder_state==MorderEnum.Initial_state|| string.IsNullOrEmpty(a.morder_state)) && a.factory_id == input.factory_id).Result;
|
|
|
- var moEntryListCheck = _mysql_mes_moentry.GetListAsync(a => moListCheck.Select(b=>b.morder_no).ToList().Contains(a.moentry_mono) && a.factory_id == input.factory_id).Result;
|
|
|
-
|
|
|
- await PlanOrderResourceCheck(moListCheck.OrderBy(a => a.moentry_sys_stime).ToList(), moEntryListCheck, bang_id, "",false,true);
|
|
|
-
|
|
|
- var examine_resultList = _mysql_examine_result.GetListAsync(a => a.bangid == bang_id).Result;
|
|
|
-
|
|
|
-
|
|
|
//批量保存 后期考虑子工单
|
|
|
List<WorkOrdMaster> workOrdSave = new List<WorkOrdMaster>();
|
|
|
List<WorkOrdRouting> workOrdRoutingSave = new List<WorkOrdRouting>();
|
|
|
List<WorkOrdDetail> workOrdDetails = new List<WorkOrdDetail>();
|
|
|
if (moList.Any())
|
|
|
{
|
|
|
- List<b_bom_child_examine> childExamineList = _mysql_bom_child_examine.GetListAsync(c => examine_resultList.Select(x => x.Id).Contains(c.examine_id.GetValueOrDefault())).Result;
|
|
|
//同步工单
|
|
|
- CreateWorkOrdDates(moList, routingOps, workOrdSave, workOrdRoutingSave, workOrdDetails, examine_resultList, childExamineList);
|
|
|
+ CreateWorkOrdDates(moList, routingOps, workOrdSave, workOrdRoutingSave, workOrdDetails, new List<b_examine_result>(), new List<b_bom_child_examine>());
|
|
|
}
|
|
|
|
|
|
if (workOrdSave.Any())
|
|
|
{
|
|
|
- workOrdSave = CalcPriority(workOrdSave, input.factory_id.ToString());
|
|
|
_businessDbContext.BulkInsert(workOrdSave);
|
|
|
+ CalcPriority(input.factory_id.ToString());
|
|
|
}
|
|
|
var DBworkOrdList = _workOrdMaster.Select(a => workOrdSave.Count > 0 && a.Domain == workOrdSave[0].Domain && workOrdSave.Select(c => c.WorkOrd).Contains(a.WorkOrd));
|
|
|
if (workOrdRoutingSave.Any())
|
|
|
@@ -3370,6 +3355,14 @@ namespace Business.Replenishment
|
|
|
_businessDbContext.BulkInsert(workOrdDetails);
|
|
|
}
|
|
|
|
|
|
+ //2024/01/10:卫亮工单需求对齐采购需求,取所有未下达的工单做资源检查
|
|
|
+ var moListCheck=_mysql_mes_morder.GetListAsync(a=>(a.morder_state==MorderEnum.Initial_state|| string.IsNullOrEmpty(a.morder_state)) && a.factory_id == input.factory_id).Result;
|
|
|
+ var moEntryListCheck = _mysql_mes_moentry.GetListAsync(a => moListCheck.Select(b=>b.morder_no).ToList().Contains(a.moentry_mono) && a.factory_id == input.factory_id).Result;
|
|
|
+
|
|
|
+ await PlanOrderResourceCheck(moListCheck.OrderBy(a => a.moentry_sys_stime).ToList(), moEntryListCheck, bang_id, "",false,true);
|
|
|
+
|
|
|
+ var examine_resultList = _mysql_examine_result.GetListAsync(a => a.bangid == bang_id).Result;
|
|
|
+
|
|
|
var weekplanList = _replenishmentWeekPlan.GetListAsync(a => moListCheck.Select(b=>b.morder_no).ToList().Contains(a.ProductionOrder) && a.IsReplenishmentModel=="N" && a.factory_id == input.factory_id).Result;
|
|
|
|
|
|
weekplanList.ForEach(a =>
|
|
|
@@ -3400,11 +3393,6 @@ namespace Business.Replenishment
|
|
|
a.PackageHours = Packaging == null ? 0 : Packaging.RunTime * a.Qty;
|
|
|
a.TotalHours = a.AssembleHours + a.HeatSealHours + a.PackageHours;
|
|
|
}
|
|
|
- var workOrd = workOrdSave.Find(b => b.WorkOrd == a.ProductionOrder);
|
|
|
- if (workOrd != null)
|
|
|
- {
|
|
|
- a.Priority = workOrd.Priority;
|
|
|
- }
|
|
|
});
|
|
|
await _businessDbContext.BulkUpdateAsync(weekplanList);
|
|
|
return "OK";
|
|
|
@@ -4405,6 +4393,20 @@ namespace Business.Replenishment
|
|
|
return orderedList;
|
|
|
}
|
|
|
|
|
|
+ //所有未下达的工单按照日期排序计算优先级
|
|
|
+ public void CalcPriority(string domain)
|
|
|
+ {
|
|
|
+ var works = _workOrdMaster.Select(a =>(string.IsNullOrEmpty(a.Status) || a.Status.ToUpper()=="P") && a.Domain == domain && a.IsActive);
|
|
|
+ works = works.OrderBy(a => a.OrdDate).ToList();
|
|
|
+ decimal Priority = 1.0m;
|
|
|
+ for (int i = 0; i < works.Count; i++)
|
|
|
+ {
|
|
|
+ works[i].Priority = Priority;
|
|
|
+ Priority = Priority + 1.0m;
|
|
|
+ }
|
|
|
+ _businessDbContext.BulkUpdate(works);
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 手动调整优先级
|
|
|
/// </summary>
|
|
|
@@ -4430,9 +4432,14 @@ namespace Business.Replenishment
|
|
|
long factoryid=Convert.ToInt64(factory_id);
|
|
|
long companyid=Convert.ToInt64(company_id);
|
|
|
var weekPlan=_replenishmentWeekPlan.FindAsync(a => a.Id == id && a.tenant_id == tenantid && a.factory_id == factoryid && a.company_id == companyid).Result;
|
|
|
- var isExistSamePriority = _replenishmentWeekPlan.GetListAsync(a => a.Id != id && a.Week == weekPlan.Week && a.Priority == newpriority).Result;
|
|
|
- if(isExistSamePriority.Any())
|
|
|
- return "优先级重复,请重新调整。";
|
|
|
+ //周计划没有生成周工单的不校验优先级重复
|
|
|
+ if(weekPlan!=null && !string.IsNullOrEmpty(weekPlan.ProductionOrder))
|
|
|
+ {
|
|
|
+ var isExistSamePriority = _workOrdMaster.Select(a => a.WorkOrd !=weekPlan.ProductionOrder && (string.IsNullOrEmpty(a.Status) || a.Status.ToUpper()=="P") && a.Priority == newpriority);
|
|
|
+ if (isExistSamePriority.Any())
|
|
|
+ return "优先级重复,请重新调整。";
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
weekPlan.Priority= newpriority;
|
|
|
weekPlan.Qty= newqty;
|
|
|
@@ -4607,6 +4614,12 @@ namespace Business.Replenishment
|
|
|
//{
|
|
|
// _businessDbContext.BulkDelete(dellist);
|
|
|
//}
|
|
|
+ //清理工单占用
|
|
|
+ List<mes_mooccupy> mooccupy = await _mysql_mes_mooccupy.GetListAsync(s => Mes_Morders.Select(c => c.Id).Contains(s.moo_id.GetValueOrDefault()));
|
|
|
+ if (mooccupy.Any())
|
|
|
+ {
|
|
|
+ _businessDbContext.BulkDelete(mooccupy);
|
|
|
+ }
|
|
|
//清理掉库存占用
|
|
|
var itemstockoccupy = _mysql_ic_item_stockoccupy.GetListAsync(s => monolist.Contains(s.morder_mo)).Result;
|
|
|
if (itemstockoccupy.Any())
|
|
|
@@ -4750,10 +4763,17 @@ namespace Business.Replenishment
|
|
|
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();
|
|
|
+ var locationRange = _configurationItem.Select(x => x.FldName == "MRPLocationRange" && x.Domain == param.factoryId.ToString()).FirstOrDefault();
|
|
|
+ List<string> locationList = new List<string> { "1000", "1001", "5008", "8000", "8001" };
|
|
|
+ if (locationRange != null && locationRange.Val != null)
|
|
|
+ {
|
|
|
+ locationList = locationRange.Val.SplitToArray(",").ToList();
|
|
|
+ }
|
|
|
+ List<string> nbrType = new List<string> { "SM", "OA", "IA"};
|
|
|
+ var nbrList = _nbrMaster.Select(x => x.Domain == param.factoryId.ToString() && nbrType.Contains(x.Type) && 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();
|
|
|
+ var nbrDtlList = _nbrDetail.Select(x => nbrList.Select(c => c.RecID).Contains(x.NbrRecID) && locationList.Contains(x.LocationFrom) && x.Status.ToUpper() != "C").ToList();
|
|
|
if (nbrDtlList.Any())
|
|
|
{
|
|
|
nbrDtlList.ForEach(x => {
|
|
|
@@ -4771,6 +4791,29 @@ namespace Business.Replenishment
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
+ //退料单逻辑相反
|
|
|
+ var wodNbrList = _nbrMaster.Select(x => x.Domain == param.factoryId.ToString() && x.Type == "WOD" && x.Status.ToUpper() != "C").ToList();
|
|
|
+ if (wodNbrList.Any())
|
|
|
+ {
|
|
|
+ //WOD是退料
|
|
|
+ var wodNbrDtlList = _nbrDetail.Select(x => wodNbrList.Select(c => c.RecID).Contains(x.NbrRecID) && locationList.Contains(x.LocationTo) && x.Status.ToUpper() != "C").ToList();
|
|
|
+ if (wodNbrDtlList.Any())
|
|
|
+ {
|
|
|
+ wodNbrDtlList.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();
|
|
|
@@ -4895,11 +4938,10 @@ namespace Business.Replenishment
|
|
|
//暂时屏蔽重新生成工单物料明细
|
|
|
List<WorkOrdDetail> mainWorkOrdDetails = new List<WorkOrdDetail>();
|
|
|
List<WorkOrdDetail> delWorkOrddetails = new List<WorkOrdDetail>();
|
|
|
- if (isChangePriority)
|
|
|
- {
|
|
|
+
|
|
|
//成品虚拟件对应关系
|
|
|
var productOpList = _productStructureOp.Select(x => mo_Mes_Morders.Select(c => c.product_code).Contains(x.ProductItem) && x.Domain == param.factoryId.ToString());
|
|
|
- var workOrds = CalcPriority(mo_Mes_Morders.Select(p => p.morder_no).ToList(), param.factoryId.ToString());
|
|
|
+ var workOrds = _workOrdMaster.Select(a => mo_Mes_Morders.Select(p => p.morder_no).ToList().Contains(a.WorkOrd) && a.Domain == param.factoryId.ToString() && a.IsActive);
|
|
|
delWorkOrddetails = _workOrdDetail.Select(x => workOrds.Select(c => c.RecID).Contains((int)x.WorkOrdMasterRecID) && x.Domain == param.factoryId.ToString());
|
|
|
foreach (var workord in mo_Mes_Morders)
|
|
|
{
|
|
|
@@ -4961,7 +5003,7 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
List<srm_pr_main> updatPrList = new List<srm_pr_main>();
|
|
|
List<srm_pr_main> deletePrList = new List<srm_pr_main>();
|
|
|
@@ -5051,7 +5093,8 @@ namespace Business.Replenishment
|
|
|
}
|
|
|
}
|
|
|
//数据库需要减少的PR集合
|
|
|
- CalcPrDel(prDelList, dbPurchaseList, ic_items, DBprmainList.Where(x=>x.state==1).ToList(), updatPrList, deletePrList);//只取新增状态的PR,可以做删除或者修改
|
|
|
+ CalcPrDel(prDelList, dbPurchaseList, ic_items, DBprmainList.Where(x=>x.state==1).ToList(), updatPrList, deletePrList, prmainlist);//只取新增状态的PR,可以做删除或者修改
|
|
|
+ new NLogHelper("AlignmentCalcList").WriteLog("AlignmentCalcList", JsonConvert.SerializeObject(AlignmentCalcList), _currentTenant.Id.ToString());
|
|
|
}
|
|
|
|
|
|
using (var unitOfWork = _unitOfWorkManager.Begin(false, true))
|
|
|
@@ -5078,8 +5121,8 @@ namespace Business.Replenishment
|
|
|
if (workOrdSave.Any())
|
|
|
{
|
|
|
workOrdSave.ForEach(a => { a.AnalogCalcVersion = analogCalcVersion; });
|
|
|
- workOrdSave = CalcPriority(workOrdSave, input.factoryId.ToString());
|
|
|
_businessDbContext.BulkInsert(workOrdSave);
|
|
|
+ CalcPriority(input.factoryId.ToString());
|
|
|
}
|
|
|
var DBworkOrdList = _workOrdMaster.Select(a => workOrdSave.Count > 0 && a.Domain == workOrdSave[0].Domain && workOrdSave.Select(c => c.WorkOrd).Contains(a.WorkOrd));
|
|
|
if (workOrdRoutingSave.Any())
|
|
|
@@ -5124,16 +5167,13 @@ namespace Business.Replenishment
|
|
|
srmpooccupyInsert.ForEach(x => { x.GenerateNewId(help.NextId()); });
|
|
|
_businessDbContext.BulkInsert(srmpooccupyInsert);
|
|
|
}
|
|
|
- if(isChangePriority)
|
|
|
+ if (delWorkOrddetails.Any())
|
|
|
{
|
|
|
- if (delWorkOrddetails.Any())
|
|
|
- {
|
|
|
- _businessDbContext.BulkDelete(delWorkOrddetails);
|
|
|
- }
|
|
|
- if (mainWorkOrdDetails.Any())
|
|
|
- {
|
|
|
- _businessDbContext.BulkInsert(mainWorkOrdDetails);
|
|
|
- }
|
|
|
+ _businessDbContext.BulkDelete(delWorkOrddetails);
|
|
|
+ }
|
|
|
+ if (mainWorkOrdDetails.Any())
|
|
|
+ {
|
|
|
+ _businessDbContext.BulkInsert(mainWorkOrdDetails);
|
|
|
}
|
|
|
if (IsWeekPlan)
|
|
|
{
|
|
|
@@ -5167,7 +5207,7 @@ namespace Business.Replenishment
|
|
|
return rtn;
|
|
|
}
|
|
|
|
|
|
- public void CalcPrDel(List<AlignmentCalcDto> prDelList,List<srm_purchase> purchase,List<ic_item> ic_items, List<srm_pr_main> dbPrlist, List<srm_pr_main> updatPrList, List<srm_pr_main> deletePrList)
|
|
|
+ public void CalcPrDel(List<AlignmentCalcDto> prDelList,List<srm_purchase> purchase,List<ic_item> ic_items, List<srm_pr_main> dbPrlist, List<srm_pr_main> updatPrList, List<srm_pr_main> deletePrList,List<mo_srm_pr_main> prmainlist)
|
|
|
{
|
|
|
prDelList.ForEach(dto => {
|
|
|
var itemPurList = purchase.Where(x => x.number == dto.ItemNum).ToList();
|
|
|
@@ -5177,6 +5217,33 @@ namespace Business.Replenishment
|
|
|
itemPurList.ForEach(c => {
|
|
|
//当前供应商需减少数量
|
|
|
decimal qty = Math.Floor(Math.Abs(dto.DifferenceQty) * c.quota_rate.GetValueOrDefault() / 100);
|
|
|
+ var MoItemSupplierList = prmainlist.Where(x => x.icitem_id == icitem.Id && x.pr_purchaseid == c.supplier_id).OrderByDescending(f => f.pr_sarrive_date).ToList();
|
|
|
+ if (MoItemSupplierList.Any())
|
|
|
+ {
|
|
|
+ foreach (var moPr in MoItemSupplierList)
|
|
|
+ {
|
|
|
+ if (moPr.pr_aqty > qty)//一个PR够减
|
|
|
+ {
|
|
|
+ moPr.pr_aqty = moPr.pr_aqty - qty;
|
|
|
+ moPr.pr_rqty = moPr.pr_aqty;
|
|
|
+ moPr.pr_sqty = moPr.pr_aqty;
|
|
|
+ dto.updateQty += qty;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else if (moPr.pr_aqty == qty)//一个PR够减
|
|
|
+ {
|
|
|
+ dto.deleteQty += qty;
|
|
|
+ prmainlist.Remove(moPr);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dto.deleteQty += moPr.pr_aqty.GetValueOrDefault();
|
|
|
+ qty -= moPr.pr_aqty.GetValueOrDefault();
|
|
|
+ prmainlist.Remove(moPr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
//当前物料当前供应商的在途采购申请
|
|
|
var itemSupplierList = dbPrlist.Where(x => x.icitem_id == icitem.Id && x.pr_purchaseid == c.supplier_id).OrderByDescending(f => f.pr_sarrive_date).ToList();
|
|
|
if (itemSupplierList.Any())
|
|
|
@@ -5186,6 +5253,8 @@ namespace Business.Replenishment
|
|
|
if (itemPr.pr_aqty > qty)//一个PR够减
|
|
|
{
|
|
|
itemPr.pr_aqty = itemPr.pr_aqty - qty;
|
|
|
+ itemPr.pr_rqty = itemPr.pr_aqty;
|
|
|
+ itemPr.pr_sqty = itemPr.pr_aqty;
|
|
|
updatPrList.Add(itemPr);
|
|
|
dto.updatePrlist.Add(itemPr);
|
|
|
dto.updateQty = qty;
|