|
|
@@ -51,6 +51,7 @@ using WkHtmlToPdfDotNet;
|
|
|
using Microsoft.EntityFrameworkCore.Migrations.Operations;
|
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
using System.Diagnostics;
|
|
|
+using Newtonsoft.Json;
|
|
|
|
|
|
namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
@@ -230,6 +231,7 @@ namespace Business.ResourceExamineManagement
|
|
|
private readonly IRepository<mes_moentry, long> _mysql_mes_moentry;
|
|
|
#endregion
|
|
|
|
|
|
+ #region 构造函数
|
|
|
/// <summary>
|
|
|
/// 构造函数
|
|
|
/// </summary>
|
|
|
@@ -331,6 +333,7 @@ namespace Business.ResourceExamineManagement
|
|
|
_mysql_ic_item_pur = mysql_ic_item_pur;
|
|
|
_mysql_ic_plan = mysql_ic_plan;
|
|
|
}
|
|
|
+ #endregion
|
|
|
|
|
|
/// <summary>
|
|
|
/// mongoDB示例方法,后期删除
|
|
|
@@ -419,7 +422,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
- public async Task<PschedDto> ReceiveResult(SeorderentryDto input)
|
|
|
+ public async Task<string> ReceiveResult(SeorderentryDto input)
|
|
|
{
|
|
|
//资源检查结果
|
|
|
PschedDto rtn = new PschedDto();
|
|
|
@@ -436,7 +439,7 @@ namespace Business.ResourceExamineManagement
|
|
|
throw new NotImplementedException("订单数据不存在!");
|
|
|
}
|
|
|
//获取订单行数据
|
|
|
- List<crm_seorderentry> sentrys = _mysql_crm_seorderentry.GetListAsync(p => p.tenant_id == input.tenantId && p.factory_id == input.factoryId && p.seorder_id == input.sorderId && p.IsDeleted == false).Result;
|
|
|
+ List<crm_seorderentry> sentrys =await _mysql_crm_seorderentry.GetListAsync(p => p.tenant_id == input.tenantId && p.factory_id == input.factoryId && p.seorder_id == input.sorderId && p.IsDeleted == false);
|
|
|
|
|
|
//数据库快照-同步mysql库数据到mongoDB中
|
|
|
//await SyncData(input.tenantId, input.factoryId, bangid);
|
|
|
@@ -444,17 +447,19 @@ namespace Business.ResourceExamineManagement
|
|
|
//资源检查结果list
|
|
|
List<ExamineResult> examines = new List<ExamineResult>();
|
|
|
ExamineResult dtl;
|
|
|
- #region
|
|
|
+
|
|
|
List<ic_bom> bomlist = new List<ic_bom>();
|
|
|
List<ic_bom_child> bomchildlist = new List<ic_bom_child>();
|
|
|
List<ic_item> icitemlist = new List<ic_item>();
|
|
|
-
|
|
|
- //var bomlist = _ic_bom.GetAll().Result;
|
|
|
- //var bomchildlist = _ic_bom_child.GetAll().Result;
|
|
|
- //var icitemlist = _ic_item.GetAll().Result;
|
|
|
+
|
|
|
+ //通过订单行获取物料BOM数据
|
|
|
+ FilterDefinition<ic_bom> filter = Builders<ic_bom>.Filter.In(s => s.bom_number, sentrys.Select(m => m.bom_number).ToList());
|
|
|
+ List<ic_bom> boms = _ic_bom.GetManyByIds(filter).Result.Where(p=>p.factory_id == input.factoryId && p.tenant_id == input.tenantId && !p.IsDeleted).ToList();
|
|
|
+ //计算产品提前期
|
|
|
+ List<ICItemLeadTimeDto> leadTimes = GetLeadTime(boms.Select(p=>p.icitem_id).ToList(), input.tenantId, input.factoryId);
|
|
|
foreach (var o in sentrys)
|
|
|
{
|
|
|
- var childBom = _ic_bom.GetManyByCondition(p => p.bom_number == o.bom_number).Result.FirstOrDefault();
|
|
|
+ var childBom = boms.Where(p => p.bom_number == o.bom_number).FirstOrDefault();
|
|
|
GetMongoDb(childBom, bomlist, bomchildlist, icitemlist);
|
|
|
|
|
|
//工单资源检查信息
|
|
|
@@ -473,8 +478,9 @@ namespace Business.ResourceExamineManagement
|
|
|
calcTest(getBomList, bangid, o.Id, o.qty.Value, input, o.plan_date);
|
|
|
|
|
|
//TODO:最晚开始时间
|
|
|
- //最晚开工时间=订单行客户要求交期-采购提前期-质检提前期-入库提前期-发料提前期
|
|
|
- dtl.latest_times = o.plan_date.GetValueOrDefault().AddDays(-2 - 3 - 4 - 5);
|
|
|
+ var curFacDtl = leadTimes.FirstOrDefault(p=>p.item_id == childBom.icitem_id);
|
|
|
+ //最晚开工时间=订单行客户要求交期-运输提前期-库存提前期-生产提前期-下单提前期
|
|
|
+ dtl.latest_times = o.plan_date.GetValueOrDefault().AddDays(-Convert.ToDouble(curFacDtl?.transportation_leadtime.GetValueOrDefault() + curFacDtl?.stock_leadtime.GetValueOrDefault() + curFacDtl?.production_leadtime.GetValueOrDefault() + curFacDtl?.order_leadtime.GetValueOrDefault()));
|
|
|
//物料齐套时间
|
|
|
dtl.kitting_times = getBomList.Where(p => p.is_use).OrderByDescending(m => m.kitting_time).First().kitting_time.GetValueOrDefault();
|
|
|
//替代关系展开list
|
|
|
@@ -484,10 +490,9 @@ namespace Business.ResourceExamineManagement
|
|
|
//生成工单 TODO:0=产品数量
|
|
|
//GenerateMorder(o, 0);
|
|
|
}
|
|
|
- #endregion
|
|
|
//订单行资源检查明细list
|
|
|
rtn.examines = examines;
|
|
|
- return rtn;
|
|
|
+ return JsonConvert.SerializeObject(rtn);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 测试使用新增销售订单数据
|
|
|
@@ -1405,7 +1410,7 @@ namespace Business.ResourceExamineManagement
|
|
|
itemStockoccupyDto.icitem_id = item.item_id;
|
|
|
itemStockoccupyDto.quantity = item.sqty;
|
|
|
sklist.Add(itemStockoccupyDto);
|
|
|
- var leadTimeList = GetLeadTime(new List<BomChildExamineDto> { item }, input.tenantId, input.factoryId);//提前期列表
|
|
|
+ var leadTimeList = GetLeadTime(new List<long> { item.item_id }, input.tenantId, input.factoryId);//提前期列表
|
|
|
var supplierList = GetSupplier(new List<BomChildExamineDto> { item }, input.tenantId, input.factoryId);//供应商列表
|
|
|
var planList = GetICPlan(new List<BomChildExamineDto> { item }, input.tenantId, input.factoryId);//plan列表
|
|
|
item.kitting_time = CreateSRMPR(item, input.tenantId, input.factoryId, bangid, item.erp_cls, leadTimeList, supplierList, planList, plan_date.Value);
|
|
|
@@ -1556,7 +1561,7 @@ namespace Business.ResourceExamineManagement
|
|
|
else if (slt.erp_cls == 2 || slt.erp_cls == 3)
|
|
|
{ //生成采购订单
|
|
|
//slt.purchase_qty = slt.lack_qty;
|
|
|
- var leadTimeList = GetLeadTime(new List<BomChildExamineDto> { slt }, input.tenantId, input.factoryId);//提前期列表
|
|
|
+ var leadTimeList = GetLeadTime(new List<long> { slt.item_id }, input.tenantId, input.factoryId);//提前期列表
|
|
|
var supplierList = GetSupplier(new List<BomChildExamineDto> { slt }, input.tenantId, input.factoryId);//供应商列表
|
|
|
var planList = GetICPlan(new List<BomChildExamineDto> { slt }, input.tenantId, input.factoryId);//plan列表
|
|
|
|
|
|
@@ -1664,7 +1669,7 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
else if (sct.erp_cls == 2 || sct.erp_cls == 3)
|
|
|
{
|
|
|
- var leadTimeList = GetLeadTime(new List<BomChildExamineDto> { sct }, input.tenantId, input.factoryId);//提前期列表
|
|
|
+ var leadTimeList = GetLeadTime(new List<long> { sct.item_id }, input.tenantId, input.factoryId);//提前期列表
|
|
|
var supplierList = GetSupplier(new List<BomChildExamineDto> { sct }, input.tenantId, input.factoryId);//供应商列表
|
|
|
var planList = GetICPlan(new List<BomChildExamineDto> { sct }, input.tenantId, input.factoryId);//plan列表
|
|
|
sct.kitting_time = CreateSRMPR(sct, input.tenantId, input.factoryId, bangid, sct.erp_cls, leadTimeList, supplierList, planList, plan_date.Value);
|
|
|
@@ -2003,12 +2008,18 @@ namespace Business.ResourceExamineManagement
|
|
|
}*/
|
|
|
#endregion
|
|
|
|
|
|
- //根据物料id获取物料4个提前期
|
|
|
- private List<ICItemLeadTimeDto> GetLeadTime(List<BomChildExamineDto> returnlist, long tenantId, long factoryid)
|
|
|
+ /// <summary>
|
|
|
+ /// 根据物料id获取物料4个提前期
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="icItemIds">物料id</param>
|
|
|
+ /// <param name="tenantId">企业id</param>
|
|
|
+ /// <param name="factoryid">工厂id</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private List<ICItemLeadTimeDto> GetLeadTime(List<long> icItemIds, long tenantId, long factoryid)
|
|
|
{
|
|
|
//ToDo:企业Id
|
|
|
ProjectionDefinitionBuilder<ic_factory_details> project = new ProjectionDefinitionBuilder<ic_factory_details>();
|
|
|
- return _ic_factory_details.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id) && p.factory_id == factoryid && p.tenant_id == tenantId && !p.IsDeleted,
|
|
|
+ return _ic_factory_details.Find(p => icItemIds.Contains(p.icitem_id) && p.factory_id == factoryid && p.tenant_id == tenantId && !p.IsDeleted,
|
|
|
project.Include(p => p.icitem_id).Include(p => p.production_leadtime).Include(p => p.stock_leadtime).Include(p => p.transportation_leadtime).Include(p => p.order_leadtime)).Result.
|
|
|
Select(x => new ICItemLeadTimeDto { item_id = x.icitem_id, transportation_leadtime = x.transportation_leadtime, stock_leadtime = x.stock_leadtime, production_leadtime = x.production_leadtime, order_leadtime = x.order_leadtime }).AsQueryable<ICItemLeadTimeDto>().ToList();
|
|
|
}
|
|
|
@@ -2039,7 +2050,7 @@ namespace Business.ResourceExamineManagement
|
|
|
//ToDo:企业Id,数据状态过滤以及isdeleted
|
|
|
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 leadTimeList = GetLeadTime(returnlist.Select(p=>p.item_id).ToList(), tenantId, factoryid);//提前期列表
|
|
|
var supplierList = GetSupplier(returnlist, tenantId, factoryid);//供应商列表
|
|
|
var planList = GetICPlan(returnlist, tenantId, factoryid);//plan列表
|
|
|
foreach (var item in returnlist)
|