|
|
@@ -32,6 +32,9 @@ using NUglify.Helpers;
|
|
|
using Microsoft.AspNetCore.SignalR.Protocol;
|
|
|
using XCZ.Extensions;
|
|
|
using System.ComponentModel.Design;
|
|
|
+using Volo.Abp.Validation.StringValues;
|
|
|
+using System.Runtime.CompilerServices;
|
|
|
+using MongoDB.Driver;
|
|
|
|
|
|
namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
@@ -47,6 +50,11 @@ namespace Business.ResourceExamineManagement
|
|
|
/// </summary>
|
|
|
private readonly IMongoDB<mes_technique> _mes_technique;
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 工序
|
|
|
+ /// </summary>
|
|
|
+ private readonly IMongoDB<mes_process> _mes_process;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 工艺关联工序
|
|
|
/// </summary>
|
|
|
@@ -113,6 +121,10 @@ namespace Business.ResourceExamineManagement
|
|
|
/// 生产工单主表
|
|
|
/// </summary>
|
|
|
private readonly IMongoDB<mes_morder> _mes_morder;
|
|
|
+ /// <summary>
|
|
|
+ /// 在制工单占用记录表
|
|
|
+ /// </summary>
|
|
|
+ private readonly IMongoDB<mes_mooccupy> _mes_mooccupy;
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -122,6 +134,9 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <param name="icbom"></param>
|
|
|
public ResourceExamineAppService(
|
|
|
IMongoDB<mes_technique> mes_technique,
|
|
|
+ IMongoDB<mes_process> mes_process,
|
|
|
+ IMongoDB<mes_tech_process> mes_tech_process,
|
|
|
+ IMongoDB<mes_tech_proc_workshop> mes_tech_proc_workshop,
|
|
|
IMongoDB<ic_item> ic_item,
|
|
|
IMongoDB<ic_bom> ic_bom,
|
|
|
IMongoDB<ic_bom_child> ic_bom_child,
|
|
|
@@ -131,6 +146,7 @@ namespace Business.ResourceExamineManagement
|
|
|
IMongoDB<ic_substitute_all> ic_substitute_all,
|
|
|
IMongoDB<ic_substitute_all_dtl> ic_substitute_all_dtl,
|
|
|
IMongoDB<mes_morder> mes_morder,
|
|
|
+ IMongoDB<mes_mooccupy> mes_mooccupy,
|
|
|
IBasicRepository<ic_item, long> mysql_ic_item,
|
|
|
IBasicRepository<ic_bom, long> mysql_ic_bom,
|
|
|
IBasicRepository<ic_bom_child, long> mysql_ic_bom_child
|
|
|
@@ -138,6 +154,9 @@ namespace Business.ResourceExamineManagement
|
|
|
)
|
|
|
{
|
|
|
_mes_technique = mes_technique;
|
|
|
+ _mes_process = mes_process;
|
|
|
+ _mes_tech_process = mes_tech_process;
|
|
|
+ _mes_tech_proc_workshop = mes_tech_proc_workshop;
|
|
|
_ic_item = ic_item;
|
|
|
_ic_bom = ic_bom;
|
|
|
_ic_bom_child = ic_bom_child;
|
|
|
@@ -195,6 +214,9 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
public async Task<PschedDto> ReceiveResult(SeorderentryDto input)
|
|
|
{
|
|
|
+ //测试代码
|
|
|
+ //await test();
|
|
|
+ await ProductiveExamine(1733221167209762816,100,1000);
|
|
|
return null;
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
@@ -205,12 +227,153 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <summary>
|
|
|
/// 产能计算
|
|
|
/// </summary>
|
|
|
- /// <param name="BomId">Bom主键</param>
|
|
|
- /// <param name="Quantity">需要数量</param>
|
|
|
- public async Task ProductiveExamine(long? BomId, int Quantity)
|
|
|
+ /// <param name="tech_id">工艺路径主键</param>
|
|
|
+ /// <param name="packages">需要生产产品件数</param>
|
|
|
+ /// <param name="quantity">需要生产数量</param>
|
|
|
+ public async Task<DateTime> ProductiveExamine(long tech_id, int packages, int quantity)
|
|
|
{
|
|
|
+ if (packages <=0 ||quantity <= 0)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException("产能计算参数有误!");
|
|
|
+ }
|
|
|
+ #region 1、数据准备
|
|
|
+ //1.1、获取工艺路径数据
|
|
|
+ mes_technique tech = _mes_technique.GetOneByID(tech_id).Result;
|
|
|
+
|
|
|
+ //1.2、获取工艺路径关联工序数据
|
|
|
+ List<mes_tech_process> tech_Processes = _mes_tech_process.GetManyByCondition(x => x.tech_id == tech_id).Result;
|
|
|
+
|
|
|
+ //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 = _mes_process.GetManyByIds(filter).Result;
|
|
|
+
|
|
|
+ //1.3、获取工艺工序关联工位信息
|
|
|
+ FilterDefinition<mes_tech_proc_workshop> filter1 = Builders<mes_tech_proc_workshop>.Filter.In(s => s.tech_proc_id, tech_Processes.Select(m => m.Id).ToList());
|
|
|
+ List<mes_tech_proc_workshop> tech_Proc_Workshops = _mes_tech_proc_workshop.GetManyByIds(filter1).Result;
|
|
|
+
|
|
|
+ //1.4、获取工位占用情况
|
|
|
+ //List<mes_schedule_occupy> schedule_Occupies = _mes_schedule_occupy.GetManyByCondition().Result;
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 计算产能,得到耗时
|
|
|
+ /*产能计算有两种模式:1-UPH;2-节拍时间
|
|
|
+ *1、根据工艺路径设置的效率计算层级,来获取参与产能计算的所有工序/子工序
|
|
|
+ *2、根据当前工序设置的计算模式UPH/节拍时间来计算当前工序生产所需时间T1
|
|
|
+ *3、当前工序生产所需时间T1*效率系数Rate得到实际的生产所需时间T2(流水线不需要*效率系数)
|
|
|
+ *4、当前工序实际生产所需时间T2+当前工序前置准备时间得到当前工序生产所需总时间
|
|
|
+ *5、所有工序生产总时间加起来得到生产所需总时间
|
|
|
+ */
|
|
|
+ //1、获取参与计算的所有工序/子工序
|
|
|
+ var tech_pro_list = tech_Processes.Where(p => p.level == tech.level).ToList();
|
|
|
+ //生产总时间(分钟)
|
|
|
+ decimal sumTimes = 0.00m;
|
|
|
+ //记录按照CT参与计算的工序的父级Id
|
|
|
+ List<long> exists = new List<long>();
|
|
|
+ foreach (var item in tech_pro_list)
|
|
|
+ {
|
|
|
+ //数据校验
|
|
|
+ //获取当前工序
|
|
|
+ var curProcess = process.FirstOrDefault(p => p.Id == item.proc_id);
|
|
|
+ if (item.type == 1 && item.ct == 0)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException(string.Format("工艺[{0}]下的工序[{1}]节拍时间设置有误,请调整!",tech.tech_name, curProcess.proc_name));
|
|
|
+ }
|
|
|
+ if (item.type == 2 && item.uph == 0)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException(string.Format("工艺[{0}]下的工序[{1}]UPH设置有误,请调整!", tech.tech_name, curProcess.proc_name));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item.parentprocid != null)//存在父子级关系
|
|
|
+ {
|
|
|
+ //判断当前父级是否已经参与过计算
|
|
|
+ if (exists.Contains(item.parentprocid.Value))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //记录父级id
|
|
|
+ exists.Add(item.parentprocid.Value);
|
|
|
+ //获取同一父级下的子工序
|
|
|
+ var childs = tech_Processes.Where(p => p.parentprocid == item.parentprocid).ToList();
|
|
|
+ decimal maxTime = 0.00m;//记录同一父级下最大耗时
|
|
|
+ decimal time = 0.00m;
|
|
|
+ //2、两种计算模式UPH/节拍时间
|
|
|
+ if (item.type == 2)//UPH(每小时生产个数),取同一父级下最长耗时
|
|
|
+ {
|
|
|
+ foreach (var chd in childs)
|
|
|
+ {
|
|
|
+ //当前工序消耗时间
|
|
|
+ time = quantity / item.uph.Value * 60 * item.effect_ratio.Value;
|
|
|
+ if (time > maxTime)
|
|
|
+ {
|
|
|
+ maxTime = time;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sumTimes += maxTime;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //3、根据节拍时间计算
|
|
|
+ //sum(CT)
|
|
|
+ decimal sumCT = childs.Sum(p => p.ct.Value);
|
|
|
+ //max(CT)
|
|
|
+ decimal maxCT = childs.OrderByDescending(p => p.ct).FirstOrDefault().ct.Value;
|
|
|
+ //sum(LT)
|
|
|
+ decimal sumLT = childs.Sum(p => p.readytime.Value);
|
|
|
+ //当前流水线消耗时间
|
|
|
+ sumTimes += (packages - 1) * maxCT + sumCT + sumLT;
|
|
|
+ }
|
|
|
+ else{//不存在父子级关系
|
|
|
+ //2、两种计算模式UPH/节拍时间
|
|
|
+ if (item.type == 2)//uph
|
|
|
+ {
|
|
|
+ //当前工序消耗时间
|
|
|
+ sumTimes += quantity / item.uph.Value * 60 * item.effect_ratio.Value + item.readytime.Value;
|
|
|
+ //计算完成,进行下一次循环
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //节拍时间:流水线,从流水线最后工序开始计算
|
|
|
+ if (item.nextprocid != null)
|
|
|
+ {
|
|
|
+ //下-工序Id不为null,说明不是流水线最终工序,进行下一次循环
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<mes_tech_process> allProcess = new List<mes_tech_process>();
|
|
|
+ //递归,获取最终工序的上一工序
|
|
|
+ GetPreProcess(tech_Processes, item, allProcess);
|
|
|
+ //sum(CT)
|
|
|
+ decimal sumCT = allProcess.Sum(p => p.ct.Value);
|
|
|
+ //max(CT)
|
|
|
+ decimal maxCT = allProcess.OrderByDescending(p => p.ct).FirstOrDefault().ct.Value;
|
|
|
+ //sum(LT)
|
|
|
+ decimal sumLT = allProcess.Sum(p => p.readytime.Value);
|
|
|
+ //当前流水线消耗时间
|
|
|
+ sumTimes += (packages - 1) * maxCT + sumCT + sumLT;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ return DateTime.Now.AddDays(1).AddMinutes((double)sumTimes);
|
|
|
+ }
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 递归获取工序
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="tech_Processes"></param>
|
|
|
+ /// <param name="item"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private void GetPreProcess(List<mes_tech_process> tech_Processes, mes_tech_process item, List<mes_tech_process> allProcess)
|
|
|
+ {
|
|
|
+ allProcess.Add(item);
|
|
|
+ //获取上一工序
|
|
|
+ var preProc = tech_Processes.FirstOrDefault(p => p.nextprocid == item.proc_id);
|
|
|
+ if (preProc != null) {
|
|
|
+ GetPreProcess(tech_Processes, preProc, allProcess);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 检查在制工单
|
|
|
/// </summary>
|
|
|
@@ -232,6 +395,11 @@ namespace Business.ResourceExamineManagement
|
|
|
var morderList = await _mes_morder.GetManyByCondition(filter);
|
|
|
//首先满足需求数量工单其次判断是否满足交付日期、当数量不满足时继续查找最早交付日期订单 工单数量累加。
|
|
|
|
|
|
+ //工单已被占用后要与占用表关联查询...减去占用量后 剩下生产数量可供下个销售工单使用。
|
|
|
+ Expression<Func<mes_mooccupy, bool>> mooccupyfilter = x => x.moo_state == 1 && x.IsDeleted == false;
|
|
|
+ var mes_mooccupyList = await _mes_mooccupy.GetManyByCondition(mooccupyfilter);
|
|
|
+ //morderList = morderList.Where(x => x.Id.IsIn(mes_mooccupyList.Select(p => p.moo_moid))).ToList();
|
|
|
+
|
|
|
//当前工单计划日期-1天 小于交付日期 && 计算生产数量-入库数据并且大于需求产品数量。
|
|
|
var morderDataList = morderList.Where(x => x.planner_end_date.Value.AddDays(-1) < DeliverDate &&
|
|
|
(x.morder_production_number - x.inventory_number) > Quantity).ToList();
|
|
|
@@ -239,7 +407,28 @@ namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
//存在此数据满足当前BOM交付找到最早日期工单,则返回无需后续继续检查。
|
|
|
var morder = morderDataList.OrderByDescending(x => x.planner_end_date).FirstOrDefault();
|
|
|
+
|
|
|
//生成mes_mooccupy工单占用表数据,代表此工单被某个销售订单已占用。
|
|
|
+ mes_mooccupy mes_Mooccupy = new mes_mooccupy();
|
|
|
+ mes_Mooccupy.GenerateNewId();
|
|
|
+ mes_Mooccupy.moo_id_type = "分配";
|
|
|
+ mes_Mooccupy.moo_id_billid = 0;//销售订单ID
|
|
|
+ mes_Mooccupy.fbill_no = "0";//销售订单号
|
|
|
+ mes_Mooccupy.fentry_id = 0;//销售订单行
|
|
|
+ mes_Mooccupy.fitem_name = string.Empty;//物料名称
|
|
|
+ mes_Mooccupy.fitem_number = bomNumber;
|
|
|
+ mes_Mooccupy.fmodel = string.Empty;//规格型号
|
|
|
+ mes_Mooccupy.moo_moid = morder.Id;
|
|
|
+ mes_Mooccupy.moo_mo = morder.morder_no;
|
|
|
+ mes_Mooccupy.moo_qty = Quantity;
|
|
|
+ mes_Mooccupy.moo_stime = DateTime.Now;
|
|
|
+ mes_Mooccupy.moo_etime = DateTime.Now;//日期来源需确定
|
|
|
+ mes_Mooccupy.moo_state = 1;
|
|
|
+ mes_Mooccupy.moo_cbr = string.Empty;
|
|
|
+ //mes_Mooccupy.moo_ctime = ;
|
|
|
+ mes_Mooccupy.moo_creason = string.Empty;
|
|
|
+ mes_Mooccupy.tenant_id = 0;
|
|
|
+ await _mes_mooccupy.InsertOne(mes_Mooccupy);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -251,16 +440,21 @@ namespace Business.ResourceExamineManagement
|
|
|
throw new NotImplementedException("无可用在制工单!");
|
|
|
}
|
|
|
List<mes_morder> mes_Morders = new List<mes_morder>();
|
|
|
+ List<mes_mooccupy> mes_Mooccupies = new List<mes_mooccupy>();
|
|
|
decimal? number = Quantity;
|
|
|
foreach (var item in morderListData)
|
|
|
{
|
|
|
- number = number - (item.morder_production_number - item.inventory_number);
|
|
|
- if (number < 0)
|
|
|
+ //查询出工单已占用总数量
|
|
|
+ var mes_mooccupy = mes_mooccupyList.Where(x => x.moo_moid == item.Id).ToList();
|
|
|
+ // 需要数量-(生产计划数量-入库数量-已被占用数量)
|
|
|
+ number = number - (item.morder_production_number - item.inventory_number - mes_mooccupy.Sum(x => x.moo_qty));
|
|
|
+ if (number <= 0)
|
|
|
{
|
|
|
mes_Morders.Add(item);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ mes_Morders.Add(item);
|
|
|
break;
|
|
|
}
|
|
|
}
|