|
|
@@ -1,4 +1,3 @@
|
|
|
-using Amazon.Runtime.Internal.Util;
|
|
|
using Business.Core.Enum;
|
|
|
using Business.Core.Utilities;
|
|
|
using Business.Domain;
|
|
|
@@ -8,39 +7,26 @@ using Business.EntityFrameworkCore;
|
|
|
using Business.EntityFrameworkCore.SqlRepositories;
|
|
|
using Business.PriorityManagement;
|
|
|
using Business.Replenishment;
|
|
|
-using Business.ReplenishmentManagement;
|
|
|
using Business.ResourceExamineManagement.Dto;
|
|
|
using Business.StructuredDB.MES.IC;
|
|
|
using Business.StructuredDB.Replenishment;
|
|
|
using Business.StructuredDB.SaleFcst;
|
|
|
using Business.StructuredDB.WMS;
|
|
|
-using DnsClient;
|
|
|
using EFCore.BulkExtensions;
|
|
|
-using IdentityModel.Client;
|
|
|
-using Microsoft.AspNetCore.DataProtection.Repositories;
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
-using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
|
using MongoDB.Driver;
|
|
|
using MongoDB.Driver.Linq;
|
|
|
using Newtonsoft.Json;
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
-using Org.BouncyCastle.Crypto.Generators;
|
|
|
-using Org.BouncyCastle.Ocsp;
|
|
|
-using Org.BouncyCastle.Utilities;
|
|
|
-using RazorEngine.Compilation.ImpromptuInterface.Optimization;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
-using System.ComponentModel.Design;
|
|
|
using System.Linq;
|
|
|
using System.Linq.Dynamic.Core;
|
|
|
using System.Threading.Tasks;
|
|
|
using Volo.Abp.Application.Services;
|
|
|
using Volo.Abp.DependencyInjection;
|
|
|
using Volo.Abp.Domain.Repositories;
|
|
|
-using Volo.Abp.EntityFrameworkCore;
|
|
|
-using Volo.Abp.Json.SystemTextJson;
|
|
|
using Volo.Abp.MultiTenancy;
|
|
|
-using Volo.Abp.ObjectMapping;
|
|
|
using Volo.Abp.Uow;
|
|
|
|
|
|
namespace Business.ResourceExamineManagement
|
|
|
@@ -346,6 +332,7 @@ namespace Business.ResourceExamineManagement
|
|
|
private ISqlRepository<ItemMaster> _itemMaster;
|
|
|
private ISqlRepository<NbrMaster> _nbrMaster;
|
|
|
private ISqlRepository<NbrDetail> _nbrDetail;
|
|
|
+ private ISqlRepository<srm_polist_ds> _srm_polist_ds;
|
|
|
private ISqlRepository<PurOrdMaster> _purOrdMaster;
|
|
|
private ISqlRepository<PurOrdDetail> _purOrdDetail;
|
|
|
private ISqlRepository<ItemPackMaster> _itemPackMaster;
|
|
|
@@ -405,28 +392,28 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <param name="icitem"></param>
|
|
|
/// <param name="icbom"></param>
|
|
|
public ResourceExamineAppService(
|
|
|
- IRepository<mo_mes_technique,long> mes_technique,
|
|
|
- IRepository<mo_mes_process,long> mes_process,
|
|
|
- IRepository<mo_mes_tech_process,long> mes_tech_process,
|
|
|
- IRepository<mo_mes_tech_proc_workshop,long> mes_tech_proc_workshop,
|
|
|
- IRepository<mo_ic_item,long> ic_item,
|
|
|
- IRepository<mo_ic_bom,long> ic_bom,
|
|
|
- IRepository<mo_ic_bom_child,long> ic_bom_child,
|
|
|
- IRepository<mo_ic_item_stock,long> ic_item_stock,
|
|
|
- IRepository<mo_mes_oorder,long> mes_oorder,
|
|
|
- IRepository<mo_srm_pr_main,long> srm_pr_main,
|
|
|
- IRepository<mo_srm_po_main,long> srm_po_main,
|
|
|
- IRepository<mo_srm_po_list,long> srm_po_list,
|
|
|
- IRepository<mo_srm_po_occupy,long> srm_po_occupy,
|
|
|
- IRepository<mo_srm_purchase,long> srm_purchase,
|
|
|
- IRepository<mo_ic_substitute,long> ic_substitute,
|
|
|
- IRepository<mo_ic_substitute_group,long> ic_substitute_group,
|
|
|
- IRepository<mo_ic_substitute_group_detail,long> ic_substitute_group_detail,
|
|
|
- IRepository<mo_mes_morder,long> mes_morder,
|
|
|
- IRepository<mo_mes_moentry,long> mes_moentry,
|
|
|
- IRepository<mo_mes_mooccupy,long> mes_mooccupy,
|
|
|
- IRepository<mo_ic_item_stockoccupy,long> ic_item_stockoccupy,
|
|
|
- IRepository<mo_srm_supplier,long> srm_supplier,
|
|
|
+ IRepository<mo_mes_technique, long> mes_technique,
|
|
|
+ IRepository<mo_mes_process, long> mes_process,
|
|
|
+ IRepository<mo_mes_tech_process, long> mes_tech_process,
|
|
|
+ IRepository<mo_mes_tech_proc_workshop, long> mes_tech_proc_workshop,
|
|
|
+ IRepository<mo_ic_item, long> ic_item,
|
|
|
+ IRepository<mo_ic_bom, long> ic_bom,
|
|
|
+ IRepository<mo_ic_bom_child, long> ic_bom_child,
|
|
|
+ IRepository<mo_ic_item_stock, long> ic_item_stock,
|
|
|
+ IRepository<mo_mes_oorder, long> mes_oorder,
|
|
|
+ IRepository<mo_srm_pr_main, long> srm_pr_main,
|
|
|
+ IRepository<mo_srm_po_main, long> srm_po_main,
|
|
|
+ IRepository<mo_srm_po_list, long> srm_po_list,
|
|
|
+ IRepository<mo_srm_po_occupy, long> srm_po_occupy,
|
|
|
+ IRepository<mo_srm_purchase, long> srm_purchase,
|
|
|
+ IRepository<mo_ic_substitute, long> ic_substitute,
|
|
|
+ IRepository<mo_ic_substitute_group, long> ic_substitute_group,
|
|
|
+ IRepository<mo_ic_substitute_group_detail, long> ic_substitute_group_detail,
|
|
|
+ IRepository<mo_mes_morder, long> mes_morder,
|
|
|
+ IRepository<mo_mes_moentry, long> mes_moentry,
|
|
|
+ IRepository<mo_mes_mooccupy, long> mes_mooccupy,
|
|
|
+ IRepository<mo_ic_item_stockoccupy, long> ic_item_stockoccupy,
|
|
|
+ IRepository<mo_srm_supplier, long> srm_supplier,
|
|
|
IRepository<ic_item, long> mysql_ic_item,
|
|
|
IRepository<ic_demandschedule, long> mysql_ic_demandschedule,
|
|
|
IRepository<ic_bom, long> mysql_ic_bom,
|
|
|
@@ -478,6 +465,7 @@ namespace Business.ResourceExamineManagement
|
|
|
ISqlRepository<WorkOrdDetail> workOrdDetail,
|
|
|
ISqlRepository<NbrMaster> nbrMaster,
|
|
|
ISqlRepository<NbrDetail> nbrDetail,
|
|
|
+ ISqlRepository<srm_polist_ds> srmpolistds,
|
|
|
ISqlRepository<PurOrdMaster> purOrdMaster,
|
|
|
ISqlRepository<PurOrdDetail> purOrdDetail,
|
|
|
PriorityAppService priorityAppService,
|
|
|
@@ -584,6 +572,7 @@ namespace Business.ResourceExamineManagement
|
|
|
_itemMaster = itemMaster;
|
|
|
_nbrMaster = nbrMaster;
|
|
|
_nbrDetail = nbrDetail;
|
|
|
+ _srm_polist_ds = srmpolistds;
|
|
|
_purOrdMaster = purOrdMaster;
|
|
|
_purOrdDetail= purOrdDetail;
|
|
|
_priorityAppService = priorityAppService;
|
|
|
@@ -5652,30 +5641,81 @@ namespace Business.ResourceExamineManagement
|
|
|
DateTime endTime = Convert.ToDateTime(DateTime.Now.AddDays(adddays+21+6).ToString("yyyy-MM-dd 23:59:59.999"));
|
|
|
var workords=_workOrdMaster.Select(a => a.OrdDate >= beginTime && a.OrdDate <= endTime && a.Domain == domain);
|
|
|
var workordList = workords.Select(x => x.WorkOrd).Distinct().ToList();
|
|
|
- var workExamineResult=_businessBangDbContext.b_examine_result.Where(a => workordList.Contains(a.morder_no)).GroupBy(i => i.morder_no).Select(g => new
|
|
|
+ var workExamineResult=_businessBangDbContext.b_examine_result.Where(a => workordList.Contains(a.morder_no) && a.factory_id.ToString()==domain).GroupBy(i => i.morder_no).Select(g => new
|
|
|
{
|
|
|
workOrd = g.Key,
|
|
|
examineId = g.Max(row => row.Id)
|
|
|
- });
|
|
|
+ }).ToList();
|
|
|
//需要测试工单没有做资源检查会不会报错
|
|
|
var examineIds = workExamineResult.Select(s => s.examineId).ToList();
|
|
|
var examines=_mysql_bom_child_examine.GetListAsync(a => examineIds.Contains(a.examine_id.Value) && a.erp_cls==3 && a.lack_qty>0 && a.factory_id.ToString() == domain).Result;
|
|
|
- //var pickBills = _nbrDetail.Select(a => workordList.Contains(a.WorkOrd) && a.Type.ToUpper()="SM" && a.Domain == domain);
|
|
|
+ var pickBills = _nbrDetail.Select(a => workordList.Contains(a.WorkOrd) && a.Type.ToUpper()=="SM" && a.Domain == domain);
|
|
|
+ var dsList=_srm_polist_ds.Select(a => a.requestdate <= endTime && a.domain==domain);
|
|
|
+ var itemList = _itemMaster.Select(a => examines.Select(e=>e.item_number).Distinct().ToList().Contains(a.ItemNum) && a.Domain == domain);
|
|
|
+ var itemListStock = _SAPInv.Select(a => examines.Select(e => e.item_number).Distinct().ToList().Contains(a.MATNR) && (a.LGORT=="1000" || a.LGORT == "1001" || a.LGORT == "5007" || a.LGORT == "5008") && a.WERKS == domain);
|
|
|
+ List<ic_demandschedule> ds = new List<ic_demandschedule>();
|
|
|
for(int i=0;i<4;i++)
|
|
|
{
|
|
|
var itemBegin = beginTime.AddDays(i*7);
|
|
|
- var itemEnd = endTime.AddDays(7 * i-28);
|
|
|
+ var itemEnd = endTime.AddDays(7 * i-21);
|
|
|
var workItem = workords.Where(a => a.OrdDate >= itemBegin && a.OrdDate <= itemEnd).ToList();
|
|
|
- if(workItem.Count>0)
|
|
|
+ List<DemandscheduleDto> itemQty = new List<DemandscheduleDto>();
|
|
|
+ if (workItem.Count>0)
|
|
|
{
|
|
|
- var examids=workExamineResult.Where(a => workItem.Select(x => x.WorkOrd).ToList().Contains(a.workOrd)).Select(s => s.examineId);
|
|
|
- //examines.Where()
|
|
|
foreach (var item in workItem)
|
|
|
{
|
|
|
- //workExamineResult.
|
|
|
+ var examids = workExamineResult.First(a => item.WorkOrd==a.workOrd);
|
|
|
+ if(examids!=null && examids.examineId>0)
|
|
|
+ {
|
|
|
+ var itemLackList=examines.Where(a => a.examine_id == examids.examineId).ToList();
|
|
|
+ itemLackList?.ForEach(a =>
|
|
|
+ {
|
|
|
+ if(itemQty.Any(s=>s.ItemNum==a.item_number))
|
|
|
+ {
|
|
|
+ itemQty.Find(s=>s.ItemNum==a.item_number).LackQty+= a.lack_qty.GetValueOrDefault();
|
|
|
+ itemQty.Find(s => s.ItemNum == a.item_number).NeedQty += a.needCount.GetValueOrDefault();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DemandscheduleDto demandscheduleDto = new DemandscheduleDto() { ItemNum = a.item_number,LackQty= a.lack_qty.GetValueOrDefault(),NeedQty = a.needCount.GetValueOrDefault()};
|
|
|
+ itemQty.Add(demandscheduleDto);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ var requestdate = workItem.Min(a => a.OrdDate);
|
|
|
+ if(itemQty.Count>0)
|
|
|
+ {
|
|
|
+ foreach (var d in itemQty)
|
|
|
+ {
|
|
|
+ var itemNum=itemList.Find(a => a.ItemNum == d.ItemNum);
|
|
|
+ ic_demandschedule itemds = new ic_demandschedule();
|
|
|
+ itemds.GenerateNewId(help.NextId());
|
|
|
+ itemds.itemnum =d.ItemNum;
|
|
|
+ itemds.fversion = itemNum.Rev;
|
|
|
+ itemds.drawing = itemNum.Drawing;
|
|
|
+ itemds.requestdate = requestdate.GetValueOrDefault();
|
|
|
+ itemds.arrivaldate = requestdate.GetValueOrDefault().AddDays(-1).AddDays(-itemNum.InsLT).AddDays(-(int)Math.Ceiling(itemNum.MFGMTTR));
|
|
|
+ itemds.shortqty =d.LackQty;
|
|
|
+ itemds.mesqty =d.NeedQty- pickBills.Where(a=> workItem.Select(s=>s.WorkOrd).Contains(a.WorkOrd) && a.ItemNum== d.ItemNum).Sum(q=>q.QtyRec);
|
|
|
+ itemds.locqty = itemListStock.Where(a=>a.MATNR==d.ItemNum).Sum(a=>a.LABST+a.INSME);
|
|
|
+ //累计在途数量
|
|
|
+ itemds.sechedqty = dsList.Where(a => a.requestdate<itemds.arrivaldate).Sum(a=>a.schedqty-a.sentqty);
|
|
|
+ itemds.tosechedqty = itemds.locqty+itemds.sechedqty-itemds.mesqty;
|
|
|
+ itemds.status = "";
|
|
|
+ itemds.remarks = "";
|
|
|
+ itemds.tenant_id = examines[0].tenant_id;
|
|
|
+ itemds.company_id = examines[0].company_id;
|
|
|
+ itemds.factory_id = examines[0].factory_id;
|
|
|
+ itemds.create_time = DateTime.Now;
|
|
|
+ itemds.update_time= DateTime.Now;
|
|
|
+ ds.Add(itemds);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ await _businessDbContext.BulkInsertAsync(ds);
|
|
|
return "ok";
|
|
|
}
|
|
|
catch (Exception e)
|