|
|
@@ -52,6 +52,7 @@ using Microsoft.EntityFrameworkCore.Migrations.Operations;
|
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
using System.Diagnostics;
|
|
|
using Newtonsoft.Json;
|
|
|
+using Bussiness.Model.Dto.ResExamin;
|
|
|
|
|
|
namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
@@ -64,44 +65,6 @@ namespace Business.ResourceExamineManagement
|
|
|
#region 服务
|
|
|
SnowFlake help = new SnowFlake();
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 工艺路径
|
|
|
- /// </summary>
|
|
|
- private readonly IMongoDB<mes_technique> _mes_technique;
|
|
|
- private IRepository<mes_technique, long> _mysql_mes_technique;
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 工序
|
|
|
- /// </summary>
|
|
|
- private readonly IMongoDB<mes_process> _mes_process;
|
|
|
- private IRepository<mes_process, long> _mysql_mes_process;
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 工艺关联工序
|
|
|
- /// </summary>
|
|
|
- private readonly IMongoDB<mes_tech_process> _mes_tech_process;
|
|
|
- private IRepository<mes_tech_process, long> _mysql_mes_tech_process;
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 工作日历
|
|
|
- /// </summary>
|
|
|
- private readonly IMongoDB<mes_work_calendar> _mes_work_calendar;
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 工作日历明细
|
|
|
- /// </summary>
|
|
|
- private readonly IMongoDB<mes_work_calendar_list> _mes_work_calendar_list;
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 工艺工序关联工位
|
|
|
- /// </summary>
|
|
|
- private readonly IMongoDB<mes_tech_proc_workshop> _mes_tech_proc_workshop;
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 排程占用记录
|
|
|
- /// </summary>
|
|
|
- private readonly IMongoDB<mes_schedule_occupy> _mes_schedule_occupy;
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// 物料占用记录
|
|
|
/// </summary>
|
|
|
@@ -236,6 +199,11 @@ namespace Business.ResourceExamineManagement
|
|
|
/// 资源检查入参
|
|
|
/// </summary>
|
|
|
private readonly SeorderentryDto param = new SeorderentryDto();
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 产能检查
|
|
|
+ /// </summary>
|
|
|
+ private readonly ProductExamineAppService _productExamineAppService;
|
|
|
#endregion
|
|
|
|
|
|
#region 构造函数
|
|
|
@@ -245,10 +213,6 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <param name="icitem"></param>
|
|
|
/// <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,
|
|
|
@@ -290,13 +254,10 @@ namespace Business.ResourceExamineManagement
|
|
|
IRepository<srm_po_list, long> mysql_srm_po_list,
|
|
|
IRepository<srm_po_occupy, long> mysql_srm_po_occupy,
|
|
|
IRepository<ic_item_pur, long> mysql_ic_item_pur,
|
|
|
- IRepository<ic_plan, long> mysql_ic_plan
|
|
|
+ IRepository<ic_plan, long> mysql_ic_plan,
|
|
|
+ ProductExamineAppService productExamineAppService
|
|
|
)
|
|
|
{
|
|
|
- _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;
|
|
|
@@ -324,7 +285,6 @@ namespace Business.ResourceExamineManagement
|
|
|
_mysql_ic_bom_child = mysql_ic_bom_child;
|
|
|
_mysql_crm_seorder = mysql_crm_seorder;
|
|
|
_mysql_crm_seorderentry = mysql_crm_seorderentry;
|
|
|
- _mysql_mes_technique = mysql_mes_technique;
|
|
|
_mysql_ic_item_stock = mysql_ic_item_stock;
|
|
|
_mysql_ic_factory_details = mysql_ic_factory_details;
|
|
|
_mysql_mes_oorder = mysql_mes_oorder;
|
|
|
@@ -332,13 +292,12 @@ namespace Business.ResourceExamineManagement
|
|
|
_mysql_mes_mooccupy = mysql_mes_mooccupy;
|
|
|
_mysql_mes_morder = mysql_mes_morder;
|
|
|
_mysql_mes_moentry = mysql_mes_moentry;
|
|
|
- _mysql_mes_process = mysql_mes_process;
|
|
|
- _mysql_mes_tech_process = mysql_mes_tech_process;
|
|
|
_mysql_srm_po_main = mysql_srm_po_main;
|
|
|
_mysql_srm_po_list = mysql_srm_po_list;
|
|
|
_mysql_srm_po_occupy = mysql_srm_po_occupy;
|
|
|
_mysql_ic_item_pur = mysql_ic_item_pur;
|
|
|
_mysql_ic_plan = mysql_ic_plan;
|
|
|
+ _productExamineAppService = productExamineAppService;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
@@ -570,211 +529,6 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 产能计算
|
|
|
- /// </summary>
|
|
|
- /// <param name="bom_number">bom编号</param>
|
|
|
- /// <param name="version">版本号</param>
|
|
|
- /// <param name="packages">需要生产产品件数</param>
|
|
|
- /// <returns>生产时长</returns>
|
|
|
- public async Task<decimal> ProductiveExamine(string bom_number, string version, int packages)
|
|
|
- {
|
|
|
- if (packages <= 0)
|
|
|
- {
|
|
|
- throw new NotImplementedException("产能计算参数有误!");
|
|
|
- }
|
|
|
- #region 1、数据准备
|
|
|
- //1.1、获取工艺路径数据
|
|
|
- mes_technique tech = _mes_technique.Find(p => p.bom == bom_number && p.bomver == version && p.tenant_id == param.tenantId && p.factory_id == param.factoryId && !p.IsDeleted).Result.FirstOrDefault();
|
|
|
- if (tech == null)
|
|
|
- {
|
|
|
- throw new NotImplementedException("请先配置工艺路径!");
|
|
|
- }
|
|
|
-
|
|
|
- //1.2、获取工艺路径关联工序数据
|
|
|
- List<mes_tech_process> tech_Processes = await _mes_tech_process.GetManyByCondition(p => p.tech_id == tech.Id && p.tenant_id == param.tenantId && p.factory_id == param.factoryId && !p.IsDeleted);
|
|
|
- if (tech_Processes.Count == 0)
|
|
|
- {
|
|
|
- throw new NotImplementedException("请先配置工序!");
|
|
|
- }
|
|
|
-
|
|
|
- //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.Value).ToList();
|
|
|
- List<mes_process> process = await _mes_process.GetManyByCondition(p => procIds.Contains(p.Id) && p.tenant_id == param.tenantId && p.factory_id == param.factoryId && !p.IsDeleted);
|
|
|
-
|
|
|
- //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.Value) && p.tenant_id == param.tenantId && p.factory_id == param.factoryId && !p.IsDeleted);
|
|
|
- #endregion
|
|
|
-
|
|
|
- //1、获取工艺路径下的第一层级工序
|
|
|
- List<mes_tech_process> fistChilds = tech_Processes.Where(p => p.parentprocid == tech.Id).ToList();
|
|
|
- if (fistChilds.Count == 0)
|
|
|
- {
|
|
|
- throw new NotImplementedException("当前工艺路径没有配置工序,请调整!");
|
|
|
- }
|
|
|
- List<mes_tech_process> sortChilds = new List<mes_tech_process>();
|
|
|
- //添加最后一个工序
|
|
|
- var last = fistChilds.FirstOrDefault(p => p.nextprocid == null);
|
|
|
- if (last == null)
|
|
|
- {
|
|
|
- throw new NotImplementedException("当前工艺路径没有配置最终工序,请调整!");
|
|
|
- }
|
|
|
- sortChilds.Add(last);
|
|
|
- //递归按工序先后顺序排序
|
|
|
- SortProcess(fistChilds, last.proc_id.Value, sortChilds);
|
|
|
- //总耗时(分钟)
|
|
|
- //decimal sumTimes = CalcTakeTimeByLq(sortChilds, packages);//通过Lq计算
|
|
|
- decimal sumTimes = CalcTakeTimeByLqt(sortChilds, packages);//通过Lqt计算
|
|
|
- return sumTimes;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 递归:工序按照先后顺序排序-暂时不考虑两个分支合并到一个分支的情况
|
|
|
- /// </summary>
|
|
|
- /// <param name="Processes"></param>
|
|
|
- /// <param name="processId"></param>
|
|
|
- /// <param name="sortProcesses"></param>
|
|
|
- private void SortProcess(List<mes_tech_process> Processes, long processId, List<mes_tech_process> sortProcesses)
|
|
|
- {
|
|
|
- var curProcess = Processes.Where(p => p.nextprocid == processId).FirstOrDefault();
|
|
|
- if (curProcess != null)
|
|
|
- {
|
|
|
- sortProcesses.AddFirst(curProcess);
|
|
|
- SortProcess(Processes, curProcess.proc_id.Value, sortProcesses);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 通过Lq计算工艺耗时
|
|
|
- /// </summary>
|
|
|
- /// <param name="Processes"></param>
|
|
|
- /// <param name="packages"></param>
|
|
|
- /// <returns></returns>
|
|
|
- private decimal CalcTakeTimeByLq(List<mes_tech_process> Processes, int packages)
|
|
|
- {
|
|
|
- decimal sumTimes = 0.00m;//总耗时(分钟)
|
|
|
- //工序需要等待时间记录
|
|
|
- List<StartTimeDto> starts = new List<StartTimeDto>();
|
|
|
- StartTimeDto dto;
|
|
|
- foreach (var chd in Processes)
|
|
|
- {
|
|
|
- dto = new StartTimeDto();
|
|
|
- if (chd.nextprocid == null)//最后一个工序
|
|
|
- {
|
|
|
- //计算最后一个工序耗时
|
|
|
- dto = CalcProcTakeTimeByLq(chd, packages, packages);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- dto = CalcProcTakeTimeByLq(chd, chd.lq.Value, packages);
|
|
|
- }
|
|
|
- sumTimes += dto.wait_time;
|
|
|
- //添加记录
|
|
|
- starts.Add(dto);
|
|
|
- }
|
|
|
- return sumTimes;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 通过Lq计算当前工序前置准备时间
|
|
|
- /// </summary>
|
|
|
- /// <param name="proc"></param>
|
|
|
- /// <param name="quantity">LeadQuantity to Start Next</param>
|
|
|
- /// <param name="packages">件数</param>
|
|
|
- /// <returns></returns>
|
|
|
- private StartTimeDto CalcProcTakeTimeByLq(mes_tech_process proc, decimal quantity, int packages)
|
|
|
- {
|
|
|
- //记录当前工序耗时
|
|
|
- StartTimeDto dto = new StartTimeDto();
|
|
|
- //添加耗时记录
|
|
|
- dto.tech_id = proc.tech_id.Value;
|
|
|
- dto.proc_id = proc.proc_id.Value;
|
|
|
- dto.nextproc_id = proc.nextprocid;
|
|
|
- if (proc.wctype == 1)//人工型:数量/uph(一小时生产数量)*60(小时转换为分钟)/wsinuse(工位数)
|
|
|
- {
|
|
|
- dto.wait_time = quantity / proc.uph.Value * 60 / proc.wsinuse.Value;
|
|
|
- dto.take_time = packages / proc.uph.Value * 60 / proc.wsinuse.Value;
|
|
|
- }
|
|
|
- else if (proc.wctype == 2)//流水线型:数量*ct(生产一件所需时间)/wsinuse(工位数)
|
|
|
- {
|
|
|
- dto.wait_time = quantity * proc.ct.Value / proc.wsinuse.Value;
|
|
|
- dto.take_time = packages * proc.ct.Value / proc.wsinuse.Value;
|
|
|
- }
|
|
|
- else if (proc.wctype == 3)//设备型:向上取整(数量/一次可加工数量/wsinuse(工位数))*ct(老化一次所需时间)
|
|
|
- {
|
|
|
- dto.wait_time = Math.Ceiling(quantity / proc.upe.Value / proc.wsinuse.Value) * proc.ct.Value;
|
|
|
- dto.take_time = Math.Ceiling(packages / proc.upe.Value / proc.wsinuse.Value) * proc.ct.Value;
|
|
|
- }
|
|
|
- return dto;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 通过Lqt计算工艺耗时
|
|
|
- /// </summary>
|
|
|
- /// <param name="Processes"></param>
|
|
|
- /// <param name="packages"></param>
|
|
|
- /// <returns></returns>
|
|
|
- private decimal CalcTakeTimeByLqt(List<mes_tech_process> Processes, int packages)
|
|
|
- {
|
|
|
- //总耗时
|
|
|
- decimal sumTimes = 0;
|
|
|
- //工序需要等待时间记录
|
|
|
- List<StartTimeDto> starts = new List<StartTimeDto>();
|
|
|
- StartTimeDto dto;
|
|
|
- foreach (var chd in Processes)
|
|
|
- {
|
|
|
- dto = new StartTimeDto();
|
|
|
- //添加耗时记录
|
|
|
- dto.tech_id = chd.tech_id.Value;
|
|
|
- dto.proc_id = chd.proc_id.Value;
|
|
|
- dto.nextproc_id = chd.nextprocid;
|
|
|
-
|
|
|
- //计算当前工序生产耗时
|
|
|
- dto.take_time = CalcProcTakeTime(chd, packages);
|
|
|
- if (chd.nextprocid == null)//最后一个工序
|
|
|
- {
|
|
|
- dto.wait_time = dto.take_time;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- dto.wait_time = chd.lqt.Value;
|
|
|
- }
|
|
|
- sumTimes += dto.wait_time;
|
|
|
- //添加记录
|
|
|
- starts.Add(dto);
|
|
|
- }
|
|
|
- return sumTimes;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 计算当前工序生产时间
|
|
|
- /// </summary>
|
|
|
- /// <param name="proc"></param>
|
|
|
- /// <param name="packages">件数</param>
|
|
|
- /// <returns></returns>
|
|
|
- private decimal CalcProcTakeTime(mes_tech_process proc, int packages)
|
|
|
- {
|
|
|
- //当前工序生产时间
|
|
|
- decimal takeTiem = 0.00m;
|
|
|
-
|
|
|
- if (proc.wctype == 1)//人工型:数量/uph(一小时生产数量)*60(小时转换为分钟)/wsinuse(工位数)
|
|
|
- {
|
|
|
- takeTiem = packages / proc.uph.Value * 60 / proc.wsinuse.Value;
|
|
|
- }
|
|
|
- else if (proc.wctype == 2)//流水线型:数量*ct(生产一件所需时间)/wsinuse(工位数)
|
|
|
- {
|
|
|
- takeTiem = packages * proc.ct.Value / proc.wsinuse.Value;
|
|
|
- }
|
|
|
- else if (proc.wctype == 3)//设备型:向上取整(数量/一次可加工数量/wsinuse(工位数))*ct(老化一次所需时间)
|
|
|
- {
|
|
|
- takeTiem = Math.Ceiling(packages / proc.upe.Value / proc.wsinuse.Value) * proc.ct.Value;
|
|
|
- }
|
|
|
- return takeTiem;
|
|
|
- }
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// 生成工单
|
|
|
/// </summary>
|
|
|
@@ -1385,7 +1139,17 @@ namespace Business.ResourceExamineManagement
|
|
|
mes_Morders.moentry_sys_stime = returnlist[0].kitting_time;
|
|
|
if (!string.IsNullOrEmpty(mes_Morders.bom_number))
|
|
|
{
|
|
|
- var ProductiveDate = ProductiveExamine(mes_Morders.bom_number, returnlist[0].version, (int)mes_Morders.morder_production_number.Value);
|
|
|
+ //var ProductiveDate = ProductiveExamine(mes_Morders.bom_number, returnlist[0].version, (int)mes_Morders.morder_production_number.Value);
|
|
|
+ ProdExamineParamDto prodExamine = new ProdExamineParamDto()
|
|
|
+ {
|
|
|
+ bom_number = mes_Morders.bom_number,
|
|
|
+ version = returnlist[0].version,
|
|
|
+ packages = (int)mes_Morders.morder_production_number.Value,
|
|
|
+ tenantId = param.tenantId,
|
|
|
+ factoryId = param.factoryId
|
|
|
+
|
|
|
+ };
|
|
|
+ var ProductiveDate = _productExamineAppService.ProductiveExamine(prodExamine);
|
|
|
//系统建议完工日期为 开工日期+产能检查时间=完工日期
|
|
|
var Day = ProductiveDate.Result / (60 * 10); //返回的分钟除以十个小时得出工作天数;
|
|
|
mes_Morders.moentry_sys_etime = returnlist[0].kitting_time.Value.AddDays((double)Day);
|
|
|
@@ -1447,7 +1211,17 @@ namespace Business.ResourceExamineManagement
|
|
|
if (item.erp_cls == 1)
|
|
|
{
|
|
|
//走自制
|
|
|
- var minute = ProductiveExamine(item.bom_number, "1.0", item.lack_qty.GetInt());
|
|
|
+ //var minute = ProductiveExamine(item.bom_number, "1.0", item.lack_qty.GetInt());
|
|
|
+ ProdExamineParamDto prodExamine = new ProdExamineParamDto()
|
|
|
+ {
|
|
|
+ bom_number = item.bom_number,
|
|
|
+ version = "1.0",
|
|
|
+ packages = item.lack_qty.GetInt(),
|
|
|
+ tenantId = param.tenantId,
|
|
|
+ factoryId = param.factoryId
|
|
|
+
|
|
|
+ };
|
|
|
+ var minute = _productExamineAppService.ProductiveExamine(prodExamine);
|
|
|
//var ProductiveDate = ProductiveExamine(BomNumber, (int)(Quantity.Value));
|
|
|
//系统建议完工日期为 开工日期+产能检查时间=完工日期
|
|
|
var Day = minute.Result / (60 * 10); //返回的分钟除以十个小时得出工作天数;
|
|
|
@@ -1655,7 +1429,17 @@ namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
slt.make_qty = slt.lack_qty;
|
|
|
//走自制
|
|
|
- var minute = ProductiveExamine(item.bom_number, "1.0", item.lack_qty.GetInt());
|
|
|
+ //var minute = ProductiveExamine(item.bom_number, "1.0", item.lack_qty.GetInt());
|
|
|
+ ProdExamineParamDto prodExamine = new ProdExamineParamDto()
|
|
|
+ {
|
|
|
+ bom_number = item.bom_number,
|
|
|
+ version = "1.0",
|
|
|
+ packages = item.lack_qty.GetInt(),
|
|
|
+ tenantId = param.tenantId,
|
|
|
+ factoryId = param.factoryId
|
|
|
+
|
|
|
+ };
|
|
|
+ var minute = _productExamineAppService.ProductiveExamine(prodExamine);
|
|
|
//系统建议完工日期为 开工日期+产能检查时间=完工日期
|
|
|
var Day = minute.Result / (60 * 10); //返回的分钟除以十个小时得出工作天数;
|
|
|
slt.kitting_time = slt.kitting_time.Value.AddDays((double)Day);
|