|
|
@@ -40,6 +40,8 @@ using Business.PriorityManagement;
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
using Business.Dto;
|
|
|
using NetTopologySuite.Simplify;
|
|
|
+using System.Transactions;
|
|
|
+using Spire.Pdf.General.Render.Decode.Jpeg2000.j2k.codestream;
|
|
|
|
|
|
namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
@@ -686,71 +688,140 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
//计算订单行的建议交期(产能/物料)
|
|
|
CalcSuggestDate(sentrys, kittingTimes);
|
|
|
-
|
|
|
- await _mysql_crm_seorderentry.UpdateManyAsync(sentrys);
|
|
|
-
|
|
|
//批量保存 后期考虑子工单
|
|
|
+ List<mes_morder> moderlist = new List<mes_morder>();
|
|
|
+ List<WorkOrdMaster> workOrds = new List<WorkOrdMaster>();
|
|
|
+ List<WorkOrdRouting> workOrdRoutings = new List<WorkOrdRouting>();
|
|
|
+ List<WorkOrdDetail> workOrdDetails = new List<WorkOrdDetail>();
|
|
|
if (_CalcBomViewAppService.mordersInsertList.Any())
|
|
|
{
|
|
|
_CalcBomViewAppService.mordersInsertList.ForEach(s => { s.tenant_id = param.tenantId; s.factory_id = param.factoryId; });
|
|
|
- await _mes_morder.InsertMany(_CalcBomViewAppService.mordersInsertList);
|
|
|
- var mesorders = ObjectMapper.Map<List<mo_mes_morder>, List<mes_morder>>(_CalcBomViewAppService.mordersInsertList);
|
|
|
- _businessDbContext.BulkInsert(mesorders);
|
|
|
+ moderlist = ObjectMapper.Map<List<mo_mes_morder>, List<mes_morder>>(_CalcBomViewAppService.mordersInsertList);
|
|
|
rtn.mordersList = _CalcBomViewAppService.mordersInsertList;
|
|
|
+
|
|
|
+ List<RoutingOpDetail> allRoutings = _routingOpDetail.Select(p => moderlist.Select(m => m.product_code).Contains(p.RoutingCode));
|
|
|
//同步工单
|
|
|
- CreateWorkOrdDates(mesorders);
|
|
|
- }
|
|
|
- if (_CalcBomViewAppService.mooccupyAllInsertList.Any())
|
|
|
- {
|
|
|
- _CalcBomViewAppService.mooccupyAllInsertList.ForEach(s => { s.tenant_id = param.tenantId; s.factory_id = param.factoryId; });
|
|
|
- await _mes_mooccupy.InsertMany(_CalcBomViewAppService.mooccupyAllInsertList);
|
|
|
- rtn.mooccupyAllList = _CalcBomViewAppService.mooccupyAllInsertList;
|
|
|
- }
|
|
|
- if (_CalcBomViewAppService.moentriesInsertList.Any())
|
|
|
- {
|
|
|
- _CalcBomViewAppService.moentriesInsertList.ForEach(s => { s.tenant_id = param.tenantId; s.factory_id = param.factoryId; });
|
|
|
- await _mes_moentry.InsertMany(_CalcBomViewAppService.moentriesInsertList);
|
|
|
- var mesmoentrys = ObjectMapper.Map<List<mo_mes_moentry>, List<mes_moentry>>(_CalcBomViewAppService.moentriesInsertList);
|
|
|
- _businessDbContext.BulkInsert(mesmoentrys);
|
|
|
- }
|
|
|
- if (_CalcBomViewAppService.orderList.Any())
|
|
|
- {
|
|
|
- _CalcBomViewAppService.orderList.ForEach(s => { s.tenant_id = param.tenantId; s.factory_id = param.factoryId; });
|
|
|
- await _mes_oorder.InsertMany(_CalcBomViewAppService.orderList);
|
|
|
- var ooders = ObjectMapper.Map<List<mo_mes_oorder>, List<mes_oorder>>(_CalcBomViewAppService.orderList);
|
|
|
- _businessDbContext.BulkInsert(ooders);
|
|
|
- rtn.order_list = _CalcBomViewAppService.orderList;
|
|
|
+ CreateWorkOrdDates(moderlist, allRoutings, workOrds, workOrdRoutings, workOrdDetails);
|
|
|
}
|
|
|
- if (sklist.Any())
|
|
|
- {
|
|
|
- sklist.ForEach(s => { s.id = help.NextId(); s.tenant_id = param.tenantId; s.factory_id = param.factoryId; });
|
|
|
- await _ic_item_stockoccupy.InsertMany(sklist);
|
|
|
- }
|
|
|
- if (_CalcBomViewAppService.srm_Po_OccupiesInsert.Any())
|
|
|
+
|
|
|
+ using (TransactionScope scope = new TransactionScope())
|
|
|
{
|
|
|
- _CalcBomViewAppService.srm_Po_OccupiesInsert.ForEach(s => { s.tenant_id = param.tenantId; s.factory_id = param.factoryId; });
|
|
|
- await _srm_po_occupy.InsertMany(_CalcBomViewAppService.srm_Po_OccupiesInsert);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await _mysql_crm_seorderentry.UpdateManyAsync(sentrys);
|
|
|
+ //批量保存 后期考虑子工单
|
|
|
+ if (moderlist.Any())
|
|
|
+ {
|
|
|
+ await _mes_morder.InsertMany(_CalcBomViewAppService.mordersInsertList);
|
|
|
+ _businessDbContext.BulkInsert(moderlist);
|
|
|
+ if (workOrds.Any())
|
|
|
+ {
|
|
|
+ _workOrdMaster.Insert(workOrds);
|
|
|
+ }
|
|
|
+ if (workOrdRoutings.Any())
|
|
|
+ {
|
|
|
+ _workOrdRouting.Insert(workOrdRoutings);
|
|
|
+ }
|
|
|
+ if (workOrdDetails.Any())
|
|
|
+ {
|
|
|
+ _workOrdDetail.Insert(workOrdDetails);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (_CalcBomViewAppService.mooccupyAllInsertList.Any())
|
|
|
+ {
|
|
|
+ _CalcBomViewAppService.mooccupyAllInsertList.ForEach(s => { s.tenant_id = param.tenantId; s.factory_id = param.factoryId; });
|
|
|
+ await _mes_mooccupy.InsertMany(_CalcBomViewAppService.mooccupyAllInsertList);
|
|
|
+ rtn.mooccupyAllList = _CalcBomViewAppService.mooccupyAllInsertList;
|
|
|
+ }
|
|
|
+ if (_CalcBomViewAppService.moentriesInsertList.Any())
|
|
|
+ {
|
|
|
+ _CalcBomViewAppService.moentriesInsertList.ForEach(s => { s.tenant_id = param.tenantId; s.factory_id = param.factoryId; });
|
|
|
+ await _mes_moentry.InsertMany(_CalcBomViewAppService.moentriesInsertList);
|
|
|
+ var mesmoentrys = ObjectMapper.Map<List<mo_mes_moentry>, List<mes_moentry>>(_CalcBomViewAppService.moentriesInsertList);
|
|
|
+ _businessDbContext.BulkInsert(mesmoentrys);
|
|
|
+ }
|
|
|
+ if (_CalcBomViewAppService.orderList.Any())
|
|
|
+ {
|
|
|
+ _CalcBomViewAppService.orderList.ForEach(s => { s.tenant_id = param.tenantId; s.factory_id = param.factoryId; });
|
|
|
+ await _mes_oorder.InsertMany(_CalcBomViewAppService.orderList);
|
|
|
+ var ooders = ObjectMapper.Map<List<mo_mes_oorder>, List<mes_oorder>>(_CalcBomViewAppService.orderList);
|
|
|
+ _businessDbContext.BulkInsert(ooders);
|
|
|
+ rtn.order_list = _CalcBomViewAppService.orderList;
|
|
|
+ }
|
|
|
+ if (sklist.Any())
|
|
|
+ {
|
|
|
+ sklist.ForEach(s => { s.id = help.NextId(); s.tenant_id = param.tenantId; s.factory_id = param.factoryId; });
|
|
|
+ await _ic_item_stockoccupy.InsertMany(sklist);
|
|
|
+ }
|
|
|
+ if (_CalcBomViewAppService.srm_Po_OccupiesInsert.Any())
|
|
|
+ {
|
|
|
+ _CalcBomViewAppService.srm_Po_OccupiesInsert.ForEach(s => { s.tenant_id = param.tenantId; s.factory_id = param.factoryId; });
|
|
|
+ await _srm_po_occupy.InsertMany(_CalcBomViewAppService.srm_Po_OccupiesInsert);
|
|
|
+ }
|
|
|
+ scope.Complete();
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ scope.Dispose();
|
|
|
+ new NLogHelper("ResourceExamineAppService").WriteLog("ReceiveResult", "资源检查工单相关数据更新失败:" + e.Message, _currentTenant.Id.ToString());
|
|
|
+ return e.Message;
|
|
|
+ }
|
|
|
}
|
|
|
+ List<mo_srm_pr_main> prmainlist = new List<mo_srm_pr_main>();
|
|
|
if (_CalcBomViewAppService.SRMPRDtoList.Any())
|
|
|
{
|
|
|
List<List<mo_srm_pr_main>> prlist = _CalcBomViewAppService.SRMPRDtoList.Where(f => f.srm_Pr_Main != null).Select(s => s.srm_Pr_Main).ToList();
|
|
|
List<mo_srm_pr_main> list = new List<mo_srm_pr_main>();
|
|
|
+
|
|
|
foreach (var pr in prlist)
|
|
|
{
|
|
|
foreach (var item in pr)
|
|
|
{
|
|
|
list.Add(item);
|
|
|
+ prmainlist.Add(item);
|
|
|
}
|
|
|
}
|
|
|
if (list.Any())
|
|
|
+ rtn.srm_pr_list = _CalcBomViewAppService.SRMPRDtoList;
|
|
|
+ }
|
|
|
+ var itemsupplierList = _srm_supplier.Find(a => prmainlist.Select(i => i.pr_purchaseid).Contains(a.mysql_id) && a.tenant_id == input.tenantId && a.factory_id == input.factoryId).Result;
|
|
|
+ if (prmainlist.Any())
|
|
|
+ {
|
|
|
+ var pr_mainlist = ObjectMapper.Map<List<mo_srm_pr_main>, List<srm_pr_main>>(prmainlist);
|
|
|
+ PoActionListDto poaction = new PoActionListDto();
|
|
|
+
|
|
|
+ AutoCreatePOFromPR(prmainlist, bangid, icitemlist, itemsupplierList, poaction);
|
|
|
+ using (TransactionScope scope = new TransactionScope())
|
|
|
{
|
|
|
- await _srm_pr_main.InsertMany(list);
|
|
|
- var pr_mainlist = ObjectMapper.Map<List<mo_srm_pr_main>, List<srm_pr_main>>(list);
|
|
|
- _businessDbContext.BulkInsert(pr_mainlist);
|
|
|
- AutoCreatePOFromPR(list, bangid, input);
|
|
|
+ try {
|
|
|
+ await _srm_pr_main.InsertMany(prmainlist);
|
|
|
+ _businessDbContext.BulkInsert(pr_mainlist);
|
|
|
+ if (poaction.mopoMain.Any())
|
|
|
+ {
|
|
|
+ await _srm_po_main.InsertMany(poaction.mopoMain);
|
|
|
+ }
|
|
|
+ if (poaction.mopolist.Any())
|
|
|
+ {
|
|
|
+ await _srm_po_list.InsertMany(poaction.mopolist);
|
|
|
+ }
|
|
|
+ if (poaction.poMain.Any())
|
|
|
+ {
|
|
|
+ _businessDbContext.BulkInsert(poaction.poMain);
|
|
|
+ }
|
|
|
+ if (poaction.polist.Any())
|
|
|
+ {
|
|
|
+ _businessDbContext.BulkInsert(poaction.polist);
|
|
|
+ }
|
|
|
+ scope.Complete();
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ scope.Dispose();
|
|
|
+ new NLogHelper("ResourceExamineAppService").WriteLog("ReceiveResult", "资源检查PR/PO相关数据更新失败:" + e.Message, _currentTenant.Id.ToString());
|
|
|
+ return e.Message;
|
|
|
+ }
|
|
|
}
|
|
|
- rtn.srm_pr_list = _CalcBomViewAppService.SRMPRDtoList;
|
|
|
}
|
|
|
+
|
|
|
rtn.examines = examines;
|
|
|
rtn.item_stockoccupy_list = sklist;
|
|
|
|
|
|
@@ -847,34 +918,48 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- if (examineList.Any())
|
|
|
- {
|
|
|
- _businessBangDbContext.BulkInsert(examineList);
|
|
|
- }
|
|
|
- if (bomExamineList.Any())
|
|
|
+ using (TransactionScope scope = new TransactionScope())
|
|
|
{
|
|
|
- _businessBangDbContext.BulkInsert(bomExamineList.OrderBy(s => s.num_order).ToList());
|
|
|
- }
|
|
|
- if (mooccupyList.Any())
|
|
|
- {
|
|
|
- _businessBangDbContext.BulkInsert(mooccupyList);
|
|
|
- }
|
|
|
- if (moorderList.Any())
|
|
|
- {
|
|
|
- _businessBangDbContext.BulkInsert(moorderList);
|
|
|
- }
|
|
|
- if (ooderList.Any())
|
|
|
- {
|
|
|
- _businessBangDbContext.BulkInsert(ooderList);
|
|
|
- }
|
|
|
- if (purchaseList.Any())
|
|
|
- {
|
|
|
- _businessBangDbContext.BulkInsert(purchaseList);
|
|
|
- }
|
|
|
- if (purchaseoccupyList.Any())
|
|
|
- {
|
|
|
- _businessBangDbContext.BulkInsert(purchaseoccupyList);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (examineList.Any())
|
|
|
+ {
|
|
|
+ _businessBangDbContext.BulkInsert(examineList);
|
|
|
+ }
|
|
|
+ if (bomExamineList.Any())
|
|
|
+ {
|
|
|
+ _businessBangDbContext.BulkInsert(bomExamineList.OrderBy(s => s.num_order).ToList());
|
|
|
+ }
|
|
|
+ if (mooccupyList.Any())
|
|
|
+ {
|
|
|
+ _businessBangDbContext.BulkInsert(mooccupyList);
|
|
|
+ }
|
|
|
+ if (moorderList.Any())
|
|
|
+ {
|
|
|
+ _businessBangDbContext.BulkInsert(moorderList);
|
|
|
+ }
|
|
|
+ if (ooderList.Any())
|
|
|
+ {
|
|
|
+ _businessBangDbContext.BulkInsert(ooderList);
|
|
|
+ }
|
|
|
+ if (purchaseList.Any())
|
|
|
+ {
|
|
|
+ _businessBangDbContext.BulkInsert(purchaseList);
|
|
|
+ }
|
|
|
+ if (purchaseoccupyList.Any())
|
|
|
+ {
|
|
|
+ _businessBangDbContext.BulkInsert(purchaseoccupyList);
|
|
|
+ }
|
|
|
+ scope.Complete();
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ new NLogHelper("ResourceExamineAppService").WriteLog("ReceiveResult", "资源检查计算结果相关数据更新失败:" + e.Message, _currentTenant.Id.ToString());
|
|
|
+ scope.Dispose();
|
|
|
+ return e.Message;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
//清空快照数据
|
|
|
await ClearSnapShot(bangid);
|
|
|
//return JsonConvert.SerializeObject(rtn);
|
|
|
@@ -1196,25 +1281,25 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
return isSameWeek;
|
|
|
}
|
|
|
- private void AutoCreatePOFromPR(List<mo_srm_pr_main> list, long bangid, ResourceCheckInputDto input)
|
|
|
+ private void AutoCreatePOFromPR(List<mo_srm_pr_main> list, long bangid, List<mo_ic_item> icitemlist, List<mo_srm_supplier> itemsupplierList, PoActionListDto poaction)
|
|
|
{
|
|
|
var zcPr = list.Where(a => a.pr_billno.StartsWith("PR")).ToList();
|
|
|
if (zcPr.Any())
|
|
|
{
|
|
|
- AutoCreateZCPOFromPR(zcPr, bangid, input);
|
|
|
+ AutoCreateZCPOFromPR(zcPr, bangid, icitemlist, itemsupplierList, poaction);
|
|
|
}
|
|
|
|
|
|
var wwPr = list.Where(a => a.pr_billno.StartsWith("WWPR")).ToList();
|
|
|
if (wwPr.Any())
|
|
|
{
|
|
|
- AutoCreateWWPOFromPR(wwPr, bangid, input);
|
|
|
+ AutoCreateWWPOFromPR(wwPr, bangid, icitemlist, itemsupplierList, poaction);
|
|
|
}
|
|
|
}
|
|
|
- private void AutoCreateZCPOFromPR(List<mo_srm_pr_main> list, long bangid, ResourceCheckInputDto input)
|
|
|
+ private void AutoCreateZCPOFromPR(List<mo_srm_pr_main> list, long bangid, List<mo_ic_item> itemList, List<mo_srm_supplier> itemsupplierList, PoActionListDto poaction)
|
|
|
{
|
|
|
List<mo_srm_po_main> polist = new List<mo_srm_po_main>();
|
|
|
List<mo_srm_po_list> podetaillist = new List<mo_srm_po_list>();
|
|
|
- var itemList = _ic_item.Find(a => a.tenant_id == input.tenantId && a.factory_id == input.factoryId).Result;
|
|
|
+ //var itemList = _ic_item.Find(a => a.tenant_id == input.tenantId && a.factory_id == input.factoryId).Result;
|
|
|
//将PR按供应商和物料和日期(一周内)进行合并,生成PO
|
|
|
//1.按照供应商、需求日期排序
|
|
|
//2.判断是不是同一个供应商,不是的话就新建一个PO;是的话判断是不是同一周,不是的话就新建一个PO,是的话判断有没有相同物料,有的话合并物料数量价格,没有的话新建一条明细
|
|
|
@@ -1225,7 +1310,7 @@ namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
if (item.pr_purchaseid != supplierId)
|
|
|
{
|
|
|
- var itemsupplier = _srm_supplier.Find(a => a.mysql_id == item.pr_purchaseid && a.tenant_id == input.tenantId && a.factory_id == input.factoryId).Result;
|
|
|
+ var itemsupplier = itemsupplierList.Find(a => a.mysql_id == item.pr_purchaseid && a.tenant_id == param.tenantId && a.factory_id == param.factoryId);
|
|
|
//新建一个PO
|
|
|
mo_srm_po_main po_Main = new mo_srm_po_main();
|
|
|
po_Main.id = help.NextId();
|
|
|
@@ -1245,16 +1330,16 @@ namespace Business.ResourceExamineManagement
|
|
|
po_Main.supplier_id = item.pr_purchaseid;
|
|
|
po_Main.supplier_name = item.pr_purchasename;
|
|
|
po_Main.supplier_no = item.pr_purchasenumber;
|
|
|
- po_Main.contact = itemsupplier is null? itemsupplier?.FirstOrDefault().contact:"";
|
|
|
- po_Main.suppliertelephone = itemsupplier is null ? itemsupplier?.FirstOrDefault().telephone:"";
|
|
|
+ po_Main.contact = itemsupplier is null ? "" : itemsupplier.contact;
|
|
|
+ po_Main.suppliertelephone = itemsupplier is null ? "" : itemsupplier.telephone;
|
|
|
po_Main.deliveryaddress = "";
|
|
|
- po_Main.supplierdddress = itemsupplier is null ? itemsupplier?.FirstOrDefault().supplier_address:"";
|
|
|
+ po_Main.supplierdddress = itemsupplier is null ? "" : itemsupplier.supplier_address;
|
|
|
po_Main.confirmstate = 1;
|
|
|
po_Main.logisticsstate = 0;
|
|
|
po_Main.financialstate = 0;
|
|
|
po_Main.create_time = DateTime.Now;
|
|
|
- po_Main.factory_id = input.factoryId;
|
|
|
- po_Main.tenant_id = input.tenantId;
|
|
|
+ po_Main.factory_id = param.factoryId;
|
|
|
+ po_Main.tenant_id = param.tenantId;
|
|
|
po_Main.bang_id = bangid;
|
|
|
po_Main.po_delivery = 1;
|
|
|
polist.Add(po_Main);
|
|
|
@@ -1284,8 +1369,8 @@ namespace Business.ResourceExamineManagement
|
|
|
podetail.rnumber = 0;
|
|
|
podetail.currencytype = item.currencytype;
|
|
|
podetail.create_time = DateTime.Now;
|
|
|
- podetail.factory_id = input.factoryId;
|
|
|
- podetail.tenant_id = input.tenantId;
|
|
|
+ podetail.factory_id = param.factoryId;
|
|
|
+ podetail.tenant_id = param.tenantId;
|
|
|
podetail.bang_id = bangid;
|
|
|
podetail.stock_id = 1;
|
|
|
podetaillist.Add(podetail);
|
|
|
@@ -1339,8 +1424,8 @@ namespace Business.ResourceExamineManagement
|
|
|
podetail.rnumber = 0;
|
|
|
podetail.currencytype = item.currencytype;
|
|
|
podetail.create_time = DateTime.Now;
|
|
|
- podetail.factory_id = input.factoryId;
|
|
|
- podetail.tenant_id = input.tenantId;
|
|
|
+ podetail.factory_id = param.factoryId;
|
|
|
+ podetail.tenant_id = param.tenantId;
|
|
|
podetail.bang_id = bangid;
|
|
|
podetaillist.Add(podetail);
|
|
|
podetail.stock_id = 1;
|
|
|
@@ -1351,7 +1436,7 @@ namespace Business.ResourceExamineManagement
|
|
|
else
|
|
|
{
|
|
|
//不在同一周需要新建一张PO
|
|
|
- var itemsupplier = _srm_supplier.Find(a => a.mysql_id == item.pr_purchaseid && a.tenant_id == input.tenantId && a.factory_id == input.factoryId).Result;
|
|
|
+ var itemsupplier = itemsupplierList.Find(a => a.mysql_id == item.pr_purchaseid && a.tenant_id == param.tenantId && a.factory_id == param.factoryId);
|
|
|
//新建一个PO单
|
|
|
mo_srm_po_main po_Main = new mo_srm_po_main();
|
|
|
po_Main.id = help.NextId();
|
|
|
@@ -1371,16 +1456,16 @@ namespace Business.ResourceExamineManagement
|
|
|
po_Main.supplier_id = item.pr_purchaseid;
|
|
|
po_Main.supplier_name = item.pr_purchasename;
|
|
|
po_Main.supplier_no = item.pr_purchasenumber;
|
|
|
- po_Main.contact = itemsupplier is null ? itemsupplier?.FirstOrDefault().contact:"";
|
|
|
- po_Main.suppliertelephone = itemsupplier is null ? itemsupplier?.FirstOrDefault().telephone:"";
|
|
|
+ po_Main.contact = itemsupplier is null ? "" : itemsupplier.contact;
|
|
|
+ po_Main.suppliertelephone = itemsupplier is null ? "" : itemsupplier.telephone;
|
|
|
po_Main.deliveryaddress = "";
|
|
|
- po_Main.supplierdddress = itemsupplier is null ? itemsupplier?.FirstOrDefault().supplier_address:"";
|
|
|
+ po_Main.supplierdddress = itemsupplier is null ? "" : itemsupplier.supplier_address;
|
|
|
po_Main.confirmstate = 1;
|
|
|
po_Main.logisticsstate = 0;
|
|
|
po_Main.financialstate = 0;
|
|
|
po_Main.create_time = DateTime.Now;
|
|
|
- po_Main.factory_id = input.factoryId;
|
|
|
- po_Main.tenant_id = input.tenantId;
|
|
|
+ po_Main.factory_id = param.factoryId;
|
|
|
+ po_Main.tenant_id = param.tenantId;
|
|
|
po_Main.bang_id = bangid;
|
|
|
po_Main.po_delivery = 1;
|
|
|
polist.Add(po_Main);
|
|
|
@@ -1410,8 +1495,8 @@ namespace Business.ResourceExamineManagement
|
|
|
podetail.rnumber = 0;
|
|
|
podetail.currencytype = item.currencytype;
|
|
|
podetail.create_time = DateTime.Now;
|
|
|
- podetail.factory_id = input.factoryId;
|
|
|
- podetail.tenant_id = input.tenantId;
|
|
|
+ podetail.factory_id = param.factoryId;
|
|
|
+ podetail.tenant_id = param.tenantId;
|
|
|
podetail.bang_id = bangid;
|
|
|
podetail.stock_id = 1;
|
|
|
podetaillist.Add(podetail);
|
|
|
@@ -1421,18 +1506,20 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- _srm_po_main.InsertMany(polist);
|
|
|
- _srm_po_list.InsertMany(podetaillist);
|
|
|
+
|
|
|
List<srm_po_main> po_mainlist = ObjectMapper.Map<List<mo_srm_po_main>, List<srm_po_main>>(polist);
|
|
|
- _businessDbContext.BulkInsert(po_mainlist);
|
|
|
var po_listlist = ObjectMapper.Map<List<mo_srm_po_list>, List<srm_po_list>>(podetaillist);
|
|
|
- _businessDbContext.BulkInsert(po_listlist);
|
|
|
+
|
|
|
+ poaction.poMain.AddRange(po_mainlist);
|
|
|
+ poaction.polist.AddRange(po_listlist);
|
|
|
+ poaction.mopoMain.AddRange(polist);
|
|
|
+ poaction.mopolist.AddRange(podetaillist);
|
|
|
}
|
|
|
- private void AutoCreateWWPOFromPR(List<mo_srm_pr_main> list, long bangid, ResourceCheckInputDto input)
|
|
|
+ private void AutoCreateWWPOFromPR(List<mo_srm_pr_main> list, long bangid, List<mo_ic_item> itemList, List<mo_srm_supplier> itemsupplierList, PoActionListDto poaction)
|
|
|
{
|
|
|
List<mo_srm_po_main> polist = new List<mo_srm_po_main>();
|
|
|
List<mo_srm_po_list> podetaillist = new List<mo_srm_po_list>();
|
|
|
- var itemList = _ic_item.Find(a => a.tenant_id == input.tenantId && a.factory_id == input.factoryId).Result;
|
|
|
+ //var itemList = _ic_item.Find(a => a.tenant_id == input.tenantId && a.factory_id == input.factoryId).Result;
|
|
|
//将PR按供应商和物料和日期(一周内)进行合并,生成PO
|
|
|
//1.按照供应商、需求日期排序
|
|
|
//2.判断是不是同一个供应商,不是的话就新建一个PO;是的话判断是不是同一周,不是的话就新建一个PO,是的话判断有没有相同物料,有的话合并物料数量价格,没有的话新建一条明细
|
|
|
@@ -1443,7 +1530,7 @@ namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
if (item.pr_purchaseid != supplierId)
|
|
|
{
|
|
|
- var itemsupplier = _srm_supplier.Find(a => a.mysql_id == item.pr_purchaseid && a.tenant_id == input.tenantId && a.factory_id == input.factoryId).Result;
|
|
|
+ var itemsupplier = itemsupplierList.Find(a => a.mysql_id == item.pr_purchaseid && a.tenant_id == param.tenantId && a.factory_id == param.factoryId);
|
|
|
//新建一个PO
|
|
|
mo_srm_po_main po_Main = new mo_srm_po_main();
|
|
|
po_Main.id = help.NextId();
|
|
|
@@ -1463,16 +1550,16 @@ namespace Business.ResourceExamineManagement
|
|
|
po_Main.supplier_id = item.pr_purchaseid;
|
|
|
po_Main.supplier_name = item.pr_purchasename;
|
|
|
po_Main.supplier_no = item.pr_purchasenumber;
|
|
|
- po_Main.contact = itemsupplier is null ? itemsupplier?.FirstOrDefault().contact:"";
|
|
|
- po_Main.suppliertelephone = itemsupplier is null ? itemsupplier?.FirstOrDefault().telephone:"";
|
|
|
+ po_Main.contact = itemsupplier is null ? "" : itemsupplier.contact;
|
|
|
+ po_Main.suppliertelephone = itemsupplier is null ? "" : itemsupplier.telephone;
|
|
|
po_Main.deliveryaddress = "";
|
|
|
- po_Main.supplierdddress = itemsupplier is null ? itemsupplier?.FirstOrDefault().supplier_address:"";
|
|
|
+ po_Main.supplierdddress = itemsupplier is null ? "" : itemsupplier.supplier_address;
|
|
|
po_Main.confirmstate = 1;
|
|
|
po_Main.logisticsstate = 0;
|
|
|
po_Main.financialstate = 0;
|
|
|
po_Main.create_time = DateTime.Now;
|
|
|
- po_Main.factory_id = input.factoryId;
|
|
|
- po_Main.tenant_id = input.tenantId;
|
|
|
+ po_Main.factory_id = param.factoryId;
|
|
|
+ po_Main.tenant_id = param.tenantId;
|
|
|
po_Main.bang_id = bangid;
|
|
|
po_Main.po_delivery = 1;
|
|
|
polist.Add(po_Main);
|
|
|
@@ -1502,8 +1589,8 @@ namespace Business.ResourceExamineManagement
|
|
|
podetail.rnumber = 0;
|
|
|
podetail.currencytype = item.currencytype;
|
|
|
podetail.create_time = DateTime.Now;
|
|
|
- podetail.factory_id = input.factoryId;
|
|
|
- podetail.tenant_id = input.tenantId;
|
|
|
+ podetail.factory_id = param.factoryId;
|
|
|
+ podetail.tenant_id = param.tenantId;
|
|
|
podetail.bang_id = bangid;
|
|
|
podetail.stock_id = 1;
|
|
|
podetaillist.Add(podetail);
|
|
|
@@ -1557,8 +1644,8 @@ namespace Business.ResourceExamineManagement
|
|
|
podetail.rnumber = 0;
|
|
|
podetail.currencytype = item.currencytype;
|
|
|
podetail.create_time = DateTime.Now;
|
|
|
- podetail.factory_id = input.factoryId;
|
|
|
- podetail.tenant_id = input.tenantId;
|
|
|
+ podetail.factory_id = param.factoryId;
|
|
|
+ podetail.tenant_id = param.tenantId;
|
|
|
podetail.bang_id = bangid;
|
|
|
podetail.stock_id = 1;
|
|
|
podetaillist.Add(podetail);
|
|
|
@@ -1569,7 +1656,7 @@ namespace Business.ResourceExamineManagement
|
|
|
else
|
|
|
{
|
|
|
//不在同一周需要新建一张PO
|
|
|
- var itemsupplier = _srm_supplier.Find(a => a.mysql_id == item.pr_purchaseid && a.tenant_id == input.tenantId && a.factory_id == input.factoryId).Result;
|
|
|
+ var itemsupplier = itemsupplierList.Find(a => a.mysql_id == item.pr_purchaseid && a.tenant_id == param.tenantId && a.factory_id == param.factoryId);
|
|
|
//新建一个PO单
|
|
|
mo_srm_po_main po_Main = new mo_srm_po_main();
|
|
|
po_Main.id = help.NextId();
|
|
|
@@ -1589,16 +1676,16 @@ namespace Business.ResourceExamineManagement
|
|
|
po_Main.supplier_id = item.pr_purchaseid;
|
|
|
po_Main.supplier_name = item.pr_purchasename;
|
|
|
po_Main.supplier_no = item.pr_purchasenumber;
|
|
|
- po_Main.contact = itemsupplier is null ? itemsupplier?.FirstOrDefault().contact:"";
|
|
|
- po_Main.suppliertelephone = itemsupplier is null ? itemsupplier?.FirstOrDefault().telephone:"";
|
|
|
+ po_Main.contact = itemsupplier is null ? "" : itemsupplier.contact;
|
|
|
+ po_Main.suppliertelephone = itemsupplier is null ? "" : itemsupplier.telephone;
|
|
|
po_Main.deliveryaddress = "";
|
|
|
- po_Main.supplierdddress = itemsupplier is null ? itemsupplier?.FirstOrDefault().supplier_address:"";
|
|
|
+ po_Main.supplierdddress = itemsupplier is null ? "" : itemsupplier.supplier_address;
|
|
|
po_Main.confirmstate = 1;
|
|
|
po_Main.logisticsstate = 0;
|
|
|
po_Main.financialstate = 0;
|
|
|
po_Main.create_time = DateTime.Now;
|
|
|
- po_Main.factory_id = input.factoryId;
|
|
|
- po_Main.tenant_id = input.tenantId;
|
|
|
+ po_Main.factory_id = param.factoryId;
|
|
|
+ po_Main.tenant_id = param.tenantId;
|
|
|
po_Main.bang_id = bangid;
|
|
|
po_Main.po_delivery = 1;
|
|
|
polist.Add(po_Main);
|
|
|
@@ -1628,8 +1715,8 @@ namespace Business.ResourceExamineManagement
|
|
|
podetail.rnumber = 0;
|
|
|
podetail.currencytype = item.currencytype;
|
|
|
podetail.create_time = DateTime.Now;
|
|
|
- podetail.factory_id = input.factoryId;
|
|
|
- podetail.tenant_id = input.tenantId;
|
|
|
+ podetail.factory_id = param.factoryId;
|
|
|
+ podetail.tenant_id = param.tenantId;
|
|
|
podetail.bang_id = bangid;
|
|
|
podetail.stock_id = 1;
|
|
|
podetaillist.Add(podetail);
|
|
|
@@ -1639,12 +1726,14 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- _srm_po_main.InsertMany(polist);
|
|
|
- _srm_po_list.InsertMany(podetaillist);
|
|
|
+
|
|
|
List<srm_po_main> po_mainlist = ObjectMapper.Map<List<mo_srm_po_main>, List<srm_po_main>>(polist);
|
|
|
- _businessDbContext.BulkInsert(po_mainlist);
|
|
|
var po_listlist = ObjectMapper.Map<List<mo_srm_po_list>, List<srm_po_list>>(podetaillist);
|
|
|
- _businessDbContext.BulkInsert(po_listlist);
|
|
|
+
|
|
|
+ poaction.poMain.AddRange(po_mainlist);
|
|
|
+ poaction.polist.AddRange(po_listlist);
|
|
|
+ poaction.mopoMain.AddRange(polist);
|
|
|
+ poaction.mopolist.AddRange(podetaillist);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -2437,19 +2526,14 @@ namespace Business.ResourceExamineManagement
|
|
|
/// 同步工单等相关数据
|
|
|
/// </summary>
|
|
|
/// <param name="morders"></param>
|
|
|
- public void CreateWorkOrdDates(List<mes_morder> morders)
|
|
|
+ /// <param name="allRoutings">工艺路线数据</param>
|
|
|
+ public void CreateWorkOrdDates(List<mes_morder> morders, List<RoutingOpDetail> allRoutings, List<WorkOrdMaster> workOrds, List<WorkOrdRouting> workOrdRoutings, List<WorkOrdDetail> workOrdDetails)
|
|
|
{
|
|
|
- //获取工艺路线数据:product_code=物料编码
|
|
|
- List<RoutingOpDetail> allRoutings = _routingOpDetail.Select(p => morders.Select(m => m.product_code).Contains(p.RoutingCode));
|
|
|
-
|
|
|
//工单主表
|
|
|
- List<WorkOrdMaster> workOrds = new List<WorkOrdMaster>();
|
|
|
WorkOrdMaster workOrd;
|
|
|
//工单工艺路线表
|
|
|
- List<WorkOrdRouting> workOrdRoutings = new List<WorkOrdRouting>();
|
|
|
WorkOrdRouting woRouting;
|
|
|
//工单物料表
|
|
|
- List<WorkOrdDetail> workOrdDetails = new List<WorkOrdDetail>();
|
|
|
WorkOrdDetail woDetail;
|
|
|
foreach (var item in morders)
|
|
|
{
|
|
|
@@ -2506,9 +2590,6 @@ namespace Business.ResourceExamineManagement
|
|
|
workOrdDetails.Add(woDetail);
|
|
|
}
|
|
|
}
|
|
|
- _workOrdMaster.Insert(workOrds);
|
|
|
- _workOrdRouting.Insert(workOrdRoutings);
|
|
|
- _workOrdDetail.Insert(workOrdDetails);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -2569,7 +2650,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// </summary>
|
|
|
/// <param name="sentrys"></param>
|
|
|
/// <param name="kittingTimes"></param>
|
|
|
- public async void CalcSuggestDate(List<crm_seorderentry> sentrys, List<KittingTimeDto> kittingTimes)
|
|
|
+ public void CalcSuggestDate(List<crm_seorderentry> sentrys, List<KittingTimeDto> kittingTimes)
|
|
|
{
|
|
|
//获取排产记录
|
|
|
List<string> itemNums = sentrys.Select(p=>p.item_number).Distinct().ToList();
|
|
|
@@ -2587,8 +2668,7 @@ namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
- sentrys = _productExamineAppService.CalcSuggestTime(sentrys, kittingTimes);
|
|
|
- await _mysql_crm_seorderentry.UpdateManyAsync(sentrys);
|
|
|
+ _productExamineAppService.CalcSuggestTime(sentrys, kittingTimes);
|
|
|
}
|
|
|
}
|
|
|
}
|