|
|
@@ -49,6 +49,7 @@ using Microsoft.EntityFrameworkCore.Diagnostics;
|
|
|
using Hangfire.Server;
|
|
|
using WkHtmlToPdfDotNet;
|
|
|
using Microsoft.EntityFrameworkCore.Migrations.Operations;
|
|
|
+using Microsoft.AspNetCore.SignalR;
|
|
|
|
|
|
namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
@@ -253,9 +254,9 @@ namespace Business.ResourceExamineManagement
|
|
|
IMongoDB<srm_po_occupy> srm_po_occupy,
|
|
|
IMongoDB<ic_item_pur> ic_item_pur,
|
|
|
IMongoDB<ic_plan> ic_plan,
|
|
|
- //IMongoDB<ic_substitute> ic_substitute,
|
|
|
- //IMongoDB<ic_substitute_all> ic_substitute_all,
|
|
|
- //IMongoDB<ic_substitute_all_dtl> ic_substitute_all_dtl,
|
|
|
+ IMongoDB<ic_substitute> ic_substitute,
|
|
|
+ IMongoDB<ic_substitute_all> ic_substitute_all,
|
|
|
+ IMongoDB<ic_substitute_all_dtl> ic_substitute_all_dtl,
|
|
|
IMongoDB<mes_morder> mes_morder,
|
|
|
IMongoDB<mes_moentry> mes_moentry,
|
|
|
IMongoDB<mes_mooccupy> mes_mooccupy,
|
|
|
@@ -298,12 +299,12 @@ namespace Business.ResourceExamineManagement
|
|
|
_srm_po_list = srm_po_list;
|
|
|
_crm_seorder = crm_seorder;
|
|
|
_crm_seorderentry = crm_seorderentry;
|
|
|
- _srm_po_occupy = srm_po_occupy;
|
|
|
- _ic_item_pur = ic_item_pur;
|
|
|
- _ic_plan = ic_plan;
|
|
|
- //_ic_substitute = ic_substitute;
|
|
|
- //_ic_substitute_all = ic_substitute_all;
|
|
|
- //_ic_substitute_all_dtl = ic_substitute_all_dtl;
|
|
|
+ _srm_po_occupy= srm_po_occupy;
|
|
|
+ _ic_item_pur= ic_item_pur;
|
|
|
+ _ic_plan= ic_plan;
|
|
|
+ _ic_substitute = ic_substitute;
|
|
|
+ _ic_substitute_all = ic_substitute_all;
|
|
|
+ _ic_substitute_all_dtl = ic_substitute_all_dtl;
|
|
|
_mes_morder = mes_morder;
|
|
|
_mes_moentry = mes_moentry;
|
|
|
_mes_mooccupy = mes_mooccupy;
|
|
|
@@ -410,6 +411,24 @@ namespace Business.ResourceExamineManagement
|
|
|
input.tenantId = 102;
|
|
|
input.factoryId = 10201;
|
|
|
|
|
|
+ #region
|
|
|
+ var bomlist = _ic_bom.GetAll().Result;
|
|
|
+ var bomchildlist = _ic_bom_child.GetAll().Result;
|
|
|
+ var icitemlist = _ic_item.GetAll().Result;
|
|
|
+ foreach (var o in sentrys)
|
|
|
+ {
|
|
|
+ //bom层级组装
|
|
|
+ var getBomList = BomPretreatment(o.Id, 160162, o.qty.GetInt(), bomlist, bomchildlist, icitemlist);
|
|
|
+ //bom替代关系组装
|
|
|
+ BomSubstitute(getBomList, bomlist, bomchildlist, icitemlist);
|
|
|
+ //库存初始化
|
|
|
+ BomStock(getBomList, bangid, input.factoryId);
|
|
|
+ //
|
|
|
+ calcTest(getBomList, bangid, o.Id, o.qty.Value);
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
//数据准备
|
|
|
//await SaveChangesCompletedEventData()
|
|
|
|
|
|
@@ -634,12 +653,12 @@ namespace Business.ResourceExamineManagement
|
|
|
//1.3、获取当前工艺路径下的工序数据
|
|
|
//FilterDefinition<mes_process> filter = Builders<mes_process>.Filter.In(s => s.Id, tech_Processes.Select(m => m.proc_id).ToList());
|
|
|
//List<mes_process> process = await _mes_process.GetManyByIds(filter);
|
|
|
- List<long> procIds = tech_Processes.Select(m => m.proc_id).ToList();
|
|
|
+ List<long> procIds = tech_Processes.Select(m => m.proc_id.Value).ToList();
|
|
|
List<mes_process> process = await _mes_process.GetManyByCondition(p => procIds.Contains(p.Id) && p.IsDeleted == false);
|
|
|
|
|
|
//1.3、获取工艺工序关联工位信息
|
|
|
List<long> techProcIds = tech_Processes.Select(m => m.Id).ToList();
|
|
|
- List<mes_tech_proc_workshop> tech_Proc_Workshops = await _mes_tech_proc_workshop.GetManyByCondition(p => techProcIds.Contains(p.tech_proc_id) && p.IsDeleted == false);
|
|
|
+ List<mes_tech_proc_workshop> tech_Proc_Workshops = await _mes_tech_proc_workshop.GetManyByCondition(p => techProcIds.Contains(p.tech_proc_id.Value) && p.IsDeleted == false);
|
|
|
#endregion
|
|
|
|
|
|
#region 计算产能,得到耗时
|
|
|
@@ -676,7 +695,7 @@ namespace Business.ResourceExamineManagement
|
|
|
sumTimes += curTakeTime;
|
|
|
//添加耗时记录
|
|
|
dto.tech_id = tech.Id;
|
|
|
- dto.proc_id = chd.proc_id;
|
|
|
+ dto.proc_id = chd.proc_id.Value;
|
|
|
dto.nextproc_id = chd.nextprocid;
|
|
|
dto.wait_time = curTakeTime;
|
|
|
starts.Add(dto);
|
|
|
@@ -737,7 +756,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <param name="DeliverDate">交付日期</param>
|
|
|
/// <param name="seorderentry_id">销售订单子表ID</param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task GenerateMorder(crm_seorderentry seorderentry)
|
|
|
+ public async Task GenerateMorder(crm_seorderentry seorderentry, decimal? Quantity)
|
|
|
{
|
|
|
//1.库存、在制工单检查完成后 当前BOM需要自制时 产生工单。
|
|
|
|
|
|
@@ -751,6 +770,8 @@ namespace Business.ResourceExamineManagement
|
|
|
|
|
|
var ic_bom = _ic_bom.GetManyByCondition(x => x.bom_number == seorderentry.bom_number).Result.FirstOrDefault();
|
|
|
|
|
|
+ var Number = seorderentry.qty - Quantity;
|
|
|
+
|
|
|
mes_morder mes_Morder = new mes_morder();
|
|
|
mes_Morder.GenerateNewId();
|
|
|
mes_Morder.morder_type = "销售工单";
|
|
|
@@ -765,7 +786,7 @@ namespace Business.ResourceExamineManagement
|
|
|
//根绝系统配置参数 取最早或者最晚开始日期
|
|
|
var StartDate = DateTime.Now.Date.AddDays(3);
|
|
|
mes_Morder.moentry_sys_stime = StartDate;
|
|
|
- var ProductiveDate = ProductiveExamine(ic_bom.bom_number, (int)(seorderentry.qty.Value));
|
|
|
+ var ProductiveDate = ProductiveExamine(ic_bom.bom_number, (int)(Number.Value));
|
|
|
//系统建议完工日期为 开工日期+产能检查时间=完工日期
|
|
|
var Day = ProductiveDate.Result / (60 * 10); //返回的分钟除以十个小时得出工作天数;
|
|
|
mes_Morder.moentry_sys_etime = StartDate.AddDays((double)Day);
|
|
|
@@ -788,8 +809,8 @@ namespace Business.ResourceExamineManagement
|
|
|
mes_Morder.picking_qty = 0;
|
|
|
//TODO:可删除主表字段
|
|
|
mes_Morder.unit = seorderentry.unit;
|
|
|
- mes_Morder.morder_production_number = seorderentry.qty;
|
|
|
- mes_Morder.need_number = seorderentry.qty;
|
|
|
+ mes_Morder.morder_production_number = Number;
|
|
|
+ mes_Morder.need_number = Number;
|
|
|
mes_Morder.remaining_number = 0;
|
|
|
//生成工单子表数据
|
|
|
mes_moentry mes_Moentry = new mes_moentry();
|
|
|
@@ -800,8 +821,8 @@ namespace Business.ResourceExamineManagement
|
|
|
mes_Moentry.fbill_no = seorderentry.bill_no;
|
|
|
mes_Moentry.fentry_id = seorderentry.entry_seq.Value;
|
|
|
mes_Moentry.unit = seorderentry.unit;
|
|
|
- mes_Moentry.morder_production_number = seorderentry.qty;
|
|
|
- mes_Moentry.need_number = seorderentry.qty;
|
|
|
+ mes_Moentry.morder_production_number = Number;
|
|
|
+ mes_Moentry.need_number = Number;
|
|
|
mes_Moentry.remaining_number = 0;
|
|
|
mes_Moentry.factory_id = seorderentry.factory_id;
|
|
|
//using (TransactionScope scope = new TransactionScope())
|
|
|
@@ -952,7 +973,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <param name="orderid"></param>
|
|
|
/// <param name="BomId"></param>
|
|
|
/// <param name="Quantity"></param>
|
|
|
- public void BomPretreatment(long? orderid, long? BomId, int Quantity)
|
|
|
+ public List<BomChildExamineDto> BomPretreatment(long? orderid, long? BomId, int Quantity, List<ic_bom> bomlist, List<ic_bom_child> bomchildlist, List<ic_item> icitemlist)
|
|
|
{
|
|
|
if (orderid == null)
|
|
|
{
|
|
|
@@ -965,9 +986,7 @@ namespace Business.ResourceExamineManagement
|
|
|
|
|
|
//var query = (await _ic_bom.GetQueryableAsync()).WhereIf(true, a => a.bom_id == BomId).ToList();
|
|
|
var help = new SnowFlake();
|
|
|
- var bomlist = _ic_bom.GetAll().Result;
|
|
|
- var bomchildlist = _ic_bom_child.GetAll().Result;
|
|
|
- var icitemlist = _ic_item.GetAll().Result;
|
|
|
+
|
|
|
List<BomChildExamineDto> returnlist = new List<BomChildExamineDto>();
|
|
|
var dto = new BomChildExamineDto();
|
|
|
dto.bom_id = BomId.Value;
|
|
|
@@ -983,6 +1002,7 @@ namespace Business.ResourceExamineManagement
|
|
|
dto.icitem_ids = "";
|
|
|
int type = 0;
|
|
|
GetBomList(bomlist, bomchildlist, icitemlist, dto, returnlist, type);
|
|
|
+ return returnlist;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -1211,7 +1231,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// 计算物料库存量
|
|
|
/// </summary>
|
|
|
/// <param name="returnlist"></param>
|
|
|
- public void BomStock(List<BomChildExamineDto> returnlist, long bangid, long orderid, long orderentryid, long factoryid)
|
|
|
+ public void BomStock(List<BomChildExamineDto> returnlist, long bangid, long factoryid)
|
|
|
{
|
|
|
returnlist = returnlist.OrderBy(s => s.num).ToList();
|
|
|
//获取当前工厂下物料库存数据
|
|
|
@@ -1237,8 +1257,8 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void calcTest(List<BomChildExamineDto> returnlist, long bangid, long orderid, decimal count)
|
|
|
+ //计算库存
|
|
|
+ public void calcTest(List<BomChildExamineDto> returnlist, long bangid, long orderid,decimal count)
|
|
|
{
|
|
|
//占用情况
|
|
|
List<ic_item_stockoccupy> sklist = new List<ic_item_stockoccupy>();
|
|
|
@@ -1342,22 +1362,22 @@ namespace Business.ResourceExamineManagement
|
|
|
case 0://整批
|
|
|
WholeBatchCheck(sublist, returnlist, sklist, select);
|
|
|
//如果都需要采购的情况下,则默认使用优先级最高的
|
|
|
- WholeBatch(sublist, returnlist, sklist, select, bangid, parent);
|
|
|
+ WholeBatch(item,sublist, returnlist, sklist, select, bangid, parent);
|
|
|
break;
|
|
|
case 1://混用
|
|
|
- MixedUse(sublist, returnlist, sklist, bangid, parent);
|
|
|
+ MixedUse(item,sublist, returnlist, sklist, bangid, parent);
|
|
|
break;
|
|
|
case 2://整批加混用
|
|
|
WholeBatchCheck(sublist, returnlist, sklist, select);
|
|
|
if (select.Count() == 0)
|
|
|
{
|
|
|
//走混用
|
|
|
- MixedUse(sublist, returnlist, sklist, bangid, parent);
|
|
|
+ MixedUse(item,sublist, returnlist, sklist, bangid, parent);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//走整批
|
|
|
- WholeBatch(sublist, returnlist, sklist, select, bangid, parent);
|
|
|
+ WholeBatch(item,sublist, returnlist, sklist, select, bangid, parent);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
@@ -1389,15 +1409,21 @@ namespace Business.ResourceExamineManagement
|
|
|
idx = 99;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
//整批占用
|
|
|
- public void WholeBatch(List<BomChildExamineDto> sublist, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sklist, List<BomChildExamineDto> select, long bangid, BomChildExamineDto parent)
|
|
|
- {
|
|
|
+ public void WholeBatch(BomChildExamineDto item, List<BomChildExamineDto> sublist, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sklist, List<BomChildExamineDto> select, long bangid, BomChildExamineDto parent) {
|
|
|
if (select.Count() == 0)
|
|
|
{
|
|
|
//如果为空,则默认使用优先级为0的集合作为替代关系
|
|
|
- select = sublist.Where(s => s.substitute_all_num == 0).ToList();
|
|
|
+ if (item.substitute_mode == 0)
|
|
|
+ {
|
|
|
+ //替代
|
|
|
+ select = sublist.Where(s => s.type == 0).ToList();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //取代
|
|
|
+ select = sublist.Where(s => s.substitute_all_num == 0).ToList();
|
|
|
+ }
|
|
|
select.ForEach(s => { s.is_use = true; });
|
|
|
}
|
|
|
//占用库存
|
|
|
@@ -1445,8 +1471,7 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
|
|
|
//混用占用数据
|
|
|
- public void MixedUse(List<BomChildExamineDto> sublist, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sklist, long bangid, BomChildExamineDto parent)
|
|
|
- {
|
|
|
+ public void MixedUse(BomChildExamineDto item, List<BomChildExamineDto> sublist, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sklist, long bangid, BomChildExamineDto parent) {
|
|
|
|
|
|
decimal parent_lack = 0;
|
|
|
if (parent != null)
|
|
|
@@ -1500,6 +1525,41 @@ namespace Business.ResourceExamineManagement
|
|
|
idx++;
|
|
|
}
|
|
|
}
|
|
|
+ if (parent_lack > 0)
|
|
|
+ {
|
|
|
+ var select = new List<BomChildExamineDto>();
|
|
|
+ if (item.substitute_mode == 0)
|
|
|
+ {
|
|
|
+ //替代
|
|
|
+ select = sublist.Where(s => s.type == 0).ToList();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //取代
|
|
|
+ select = sublist.Where(s => s.substitute_all_num == 0).ToList();
|
|
|
+ }
|
|
|
+ //对select执行采购
|
|
|
+ foreach (var sct in select)
|
|
|
+ {
|
|
|
+ //找到当前物料的占用记录
|
|
|
+ var itemSockoccupy = sklist.Where(s => s.icitem_id == sct.item_id).ToList();
|
|
|
+ var num = parent_lack * sct.qty - itemSockoccupy.Sum(m => m.quantity);
|
|
|
+ if (sct.erp_cls == 1)
|
|
|
+ {
|
|
|
+ //自制
|
|
|
+ //GenerateMorder()
|
|
|
+ }
|
|
|
+ else if (sct.erp_cls == 2)
|
|
|
+ {
|
|
|
+ //委外
|
|
|
+ //CreateMesOOder(returnlist,)
|
|
|
+ }
|
|
|
+ else if (sct.erp_cls == 3)
|
|
|
+ {
|
|
|
+ //外购
|
|
|
+ //CreateSRMPR(returnlist,)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1861,7 +1921,7 @@ namespace Business.ResourceExamineManagement
|
|
|
private async Task<List<ICItemDateDto>> CheckOnOrder(List<BomChildExamineDto> returnlist, long tenantId, long factoryid, DateTime deliveryDate, long bangid)
|
|
|
{
|
|
|
//ToDo:企业Id,数据状态过滤以及isdeleted
|
|
|
- var po_list = _srm_po_list.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id) && p.tenant_id == tenantId && p.factory_id == factoryid && p.rarrdate >= DateTime.Now && p.rarrdate < deliveryDate && !p.IsDeleted).Result;
|
|
|
+ var po_list = _srm_po_list.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id.Value) && p.tenant_id == tenantId && p.factory_id == factoryid && p.rarrdate >= DateTime.Now && p.rarrdate < deliveryDate && !p.IsDeleted).Result;
|
|
|
var itemlist = new List<ICItemDateDto>();//需要生成采购申请单的物料信息
|
|
|
var leadTimeList = GetLeadTime(returnlist, tenantId, factoryid);//提前期列表
|
|
|
var supplierList = GetSupplier(returnlist, tenantId, factoryid);//供应商列表
|
|
|
@@ -1877,15 +1937,15 @@ namespace Business.ResourceExamineManagement
|
|
|
//外购生成采购申请单
|
|
|
if (item.erp_cls == 3)
|
|
|
{
|
|
|
- DateTime lastTime=CreateSRMPR(item, tenantId, factoryid, bangid,2, leadTimeList, supplierList, planList,deliveryDate);
|
|
|
+ DateTime lastTime = CreateSRMPR(item, tenantId, factoryid, bangid, 2, leadTimeList, supplierList, planList, deliveryDate);
|
|
|
itemlist.Add(new ICItemDateDto { item_id = item.item_id, dateTime = lastTime });
|
|
|
}
|
|
|
else if (item.erp_cls == 2)
|
|
|
{
|
|
|
//委外生成委外采购申请单和委外工单
|
|
|
- DateTime lastTime=CreateSRMPR(item, tenantId, factoryid, bangid,1, leadTimeList, supplierList, planList,deliveryDate);
|
|
|
- CreateMesOOder(item, tenantId, factoryid, bangid, leadTimeList, supplierList,deliveryDate);
|
|
|
- itemlist.Add(new ICItemDateDto { item_id = item.item_id, dateTime = lastTime});
|
|
|
+ DateTime lastTime = CreateSRMPR(item, tenantId, factoryid, bangid, 1, leadTimeList, supplierList, planList, deliveryDate);
|
|
|
+ CreateMesOOder(item, tenantId, factoryid, bangid, leadTimeList, supplierList, deliveryDate);
|
|
|
+ itemlist.Add(new ICItemDateDto { item_id = item.item_id, dateTime = lastTime });
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
@@ -1896,7 +1956,7 @@ namespace Business.ResourceExamineManagement
|
|
|
if (itemPOQty + itemPO[i].qty - itemPO[i].esqty >= item.lack_qty)
|
|
|
{
|
|
|
//在途满足,写占用表
|
|
|
- itemlist.Add(new ICItemDateDto { item_id = itemPO[i].icitem_id, dateTime = itemPO[i].rarrdate });
|
|
|
+ itemlist.Add(new ICItemDateDto { item_id = itemPO[i].icitem_id.Value, dateTime = itemPO[i].rarrdate });
|
|
|
srm_po_occupy po_Occupy = new srm_po_occupy();
|
|
|
po_Occupy.GenerateNewId();
|
|
|
po_Occupy.polist_id = itemPO[i].po_id;//采购订单id
|
|
|
@@ -1950,7 +2010,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// </summary>
|
|
|
/// <param name="returnlist"></param>
|
|
|
/// <param name="factoryid"></param>
|
|
|
- private DateTime CreateMesOOder(BomChildExamineDto returnlist, long tenantId, long factoryid, long bangId, List<ICItemLeadTimeDto> iCItemLeadTimes,List<ic_item_pur> supplierList,DateTime deliveryDate)
|
|
|
+ private DateTime CreateMesOOder(BomChildExamineDto returnlist, long tenantId, long factoryid, long bangId, List<ICItemLeadTimeDto> iCItemLeadTimes, List<ic_item_pur> supplierList, DateTime deliveryDate)
|
|
|
{
|
|
|
mes_oorder oOrder = new mes_oorder();
|
|
|
oOrder.GenerateNewId();
|
|
|
@@ -2004,7 +2064,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <param name="returnlist"></param>
|
|
|
/// <param name="factoryid"></param>
|
|
|
/// <param name="orderType">1委外采购申请单,2采购申请单</param>
|
|
|
- private DateTime CreateSRMPR(BomChildExamineDto returnlist, long tenantId, long factoryid,long bangId, int orderType,List<ICItemLeadTimeDto> iCItemLeadTimes, List<ic_item_pur> supplierList, List<ic_plan> planList,DateTime deliveryDate)
|
|
|
+ private DateTime CreateSRMPR(BomChildExamineDto returnlist, long tenantId, long factoryid, long bangId, int orderType, List<ICItemLeadTimeDto> iCItemLeadTimes, List<ic_item_pur> supplierList, List<ic_plan> planList, DateTime deliveryDate)
|
|
|
{
|
|
|
var leadTime = iCItemLeadTimes.Find(x => x.item_id == returnlist.item_id);
|
|
|
var supplier = supplierList.Find(x => x.icitem_id == returnlist.item_id);//默认取第一个供应商
|