|
|
@@ -23,6 +23,18 @@ using Volo.Abp.ObjectMapping;
|
|
|
using Volo.Abp.Application.Services;
|
|
|
using ZstdSharp.Unsafe;
|
|
|
using System.Transactions;
|
|
|
+using NUglify.JavaScript.Syntax;
|
|
|
+using System.Linq.Expressions;
|
|
|
+using XCZ.Extensions;
|
|
|
+using System.ComponentModel;
|
|
|
+using System.Reflection.Emit;
|
|
|
+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
|
|
|
{
|
|
|
@@ -38,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>
|
|
|
@@ -67,22 +84,54 @@ namespace Business.ResourceExamineManagement
|
|
|
/// 物料详情
|
|
|
/// </summary>
|
|
|
private readonly IMongoDB<ic_item> _ic_item;
|
|
|
- //private IRepository<ic_item, long> _mysql_ic_item;
|
|
|
+ private IBasicRepository<ic_item, long> _mysql_ic_item;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 物料BOM
|
|
|
/// </summary>
|
|
|
private readonly IMongoDB<ic_bom> _ic_bom;
|
|
|
- //private IRepository<ic_bom, long> _mysql_ic_bom;
|
|
|
+ private IBasicRepository<ic_bom, long> _mysql_ic_bom;
|
|
|
/// <summary>
|
|
|
/// 物料BOM明细
|
|
|
/// </summary>
|
|
|
private readonly IMongoDB<ic_bom_child> _ic_bom_child;
|
|
|
- //private IRepository<ic_bom_child, long> _mysql_ic_bom_child;
|
|
|
+ private IBasicRepository<ic_bom_child, long> _mysql_ic_bom_child;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 物料库存表
|
|
|
+ /// </summary>
|
|
|
+ private readonly IMongoDB<ic_item_stock> _ic_item_stock;
|
|
|
+ /// <summary>
|
|
|
+ /// 物料质检表
|
|
|
+ /// </summary>
|
|
|
+ private readonly IMongoDB<ic_check> _ic_check;
|
|
|
+ /// <summary>
|
|
|
+ /// 替代群组
|
|
|
+ /// </summary>
|
|
|
+ private readonly IMongoDB<ic_substitute> _ic_substitute;
|
|
|
+ /// <summary>
|
|
|
+ /// 替代群组
|
|
|
+ /// </summary>
|
|
|
+ private readonly IMongoDB<ic_substitute_all> _ic_substitute_all;
|
|
|
+ /// <summary>
|
|
|
+ /// 替代群组
|
|
|
+ /// </summary>
|
|
|
+ private readonly IMongoDB<ic_substitute_all_dtl> _ic_substitute_all_dtl;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 生产工单主表
|
|
|
/// </summary>
|
|
|
private readonly IMongoDB<mes_morder> _mes_morder;
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 在制工单占用记录表
|
|
|
+ /// </summary>
|
|
|
+ private readonly IMongoDB<mes_mooccupy> _mes_mooccupy;
|
|
|
+ /// <summary>
|
|
|
+ /// 销售工单
|
|
|
+ /// </summary>
|
|
|
+ private readonly IMongoDB<crm_seorder> _crm_seorder;
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -92,24 +141,76 @@ 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,
|
|
|
- IMongoDB<mes_morder> mes_morder
|
|
|
- //IRepository<ic_item, long> mysql_ic_item,
|
|
|
- //IRepository<ic_bom, long> mysql_ic_bom,
|
|
|
- //IRepository<ic_bom_child, long> mysql_ic_bom_child,
|
|
|
+ IMongoDB<ic_item_stock> ic_item_stock,
|
|
|
+ IMongoDB<ic_check> ic_check,
|
|
|
+ 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_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
|
|
|
|
|
|
)
|
|
|
{
|
|
|
_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;
|
|
|
+ _ic_item_stock = ic_item_stock;
|
|
|
+ _ic_check = ic_check;
|
|
|
+ _ic_substitute = ic_substitute;
|
|
|
+ _ic_substitute_all = ic_substitute_all;
|
|
|
+ _ic_substitute_all_dtl = ic_substitute_all_dtl;
|
|
|
_mes_morder = mes_morder;
|
|
|
- //_mysql_ic_item = mysql_ic_item;
|
|
|
- //_mysql_ic_bom = mysql_ic_bom;
|
|
|
- //_mysql_ic_bom_child = mysql_ic_bom_child;
|
|
|
+ _mysql_ic_item = mysql_ic_item;
|
|
|
+ _mysql_ic_bom = mysql_ic_bom;
|
|
|
+ _mysql_ic_bom_child = mysql_ic_bom_child;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// mongoDB示例方法,后期删除
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task test()
|
|
|
+ {
|
|
|
+ //多条插入
|
|
|
+ List<mes_technique> infos = new List<mes_technique>();
|
|
|
+ mes_technique info;
|
|
|
+ for (int i = 0; i < 3; i++)
|
|
|
+ {
|
|
|
+ info = new mes_technique();
|
|
|
+ info.GenerateNewId();
|
|
|
+ info.tech_name = "多条" + i;
|
|
|
+ info.level = i;
|
|
|
+ infos.Add(info);
|
|
|
+ }
|
|
|
+ await _mes_technique.InsertMany(infos);
|
|
|
+
|
|
|
+ var info2 = _mes_technique.GetAll().Result;
|
|
|
+ var a = new PschedDto();
|
|
|
+ a.count = info2.Count;
|
|
|
+
|
|
|
+ //获取数据
|
|
|
+ var info1 = await _mes_technique.GetOneByID((long)1732029975067480064);
|
|
|
+
|
|
|
+ //更新数据
|
|
|
+ info1.tech_name = "更新***";
|
|
|
+ var rlt = await _mes_technique.UpdateOne(info1, info1.Id);
|
|
|
+
|
|
|
+ //根据条件查询数据
|
|
|
+ Expression<Func<mes_technique, bool>> filter = x => x.Id == (long)1732376973889097728 && x.tech_name == "多条0";
|
|
|
+ var info3 = await _mes_technique.GetManyByCondition(filter);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -120,30 +221,9 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
public async Task<PschedDto> ReceiveResult(SeorderentryDto input)
|
|
|
{
|
|
|
- ////多条插入
|
|
|
- //List<mes_technique> infos = new List<mes_technique>();
|
|
|
- //mes_technique info;
|
|
|
- //for (int i = 0; i < 3; i++)
|
|
|
- //{
|
|
|
- // info = new mes_technique();
|
|
|
- // info.GenerateNewId();
|
|
|
- // info.tech_name = "多条" + i;
|
|
|
- // info.level = i;
|
|
|
- // infos.Add(info);
|
|
|
- //}
|
|
|
- //await _mes_technique.InsertMany(infos);
|
|
|
-
|
|
|
- //var info2 = _mes_technique.GetAll().Result;
|
|
|
- //var a = new PschedDto();
|
|
|
- //a.count = info2.Count;
|
|
|
- //return a;
|
|
|
-
|
|
|
- ////获取数据
|
|
|
- //var info1 = await _mes_technique.GetOneByID((long)1732029975067480064);
|
|
|
-
|
|
|
- ////更新数据
|
|
|
- //info1.tech_name = "更新***";
|
|
|
- //var rlt =await _mes_technique.UpdateOne(info1, info1.Id);
|
|
|
+ //测试代码
|
|
|
+ //await test();
|
|
|
+ await ProductiveExamine(1733221167209762816, 100, 1000);
|
|
|
return null;
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
@@ -154,32 +234,269 @@ 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>
|
|
|
/// <param name="bomNumber">Bom编码</param>
|
|
|
/// <param name="Quantity">需要数量</param>
|
|
|
+ /// <param name="EndDate">交付日期</param>
|
|
|
+ /// <param name="OrderId">销售订单ID</param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task CheckMorder(string bomNumber, decimal? Quantity, DateTime EndDate)
|
|
|
+ public async Task<List<mes_morder>> CheckMorder(string bomNumber, decimal? Quantity, DateTime DeliverDate, long OrderId)
|
|
|
{
|
|
|
- if (string.IsNullOrEmpty(bomNumber) || Quantity < 0)
|
|
|
+ if (string.IsNullOrEmpty(bomNumber) || Quantity != null)
|
|
|
{
|
|
|
//TODO:入参异常;
|
|
|
- //throw new NotImplementedException();
|
|
|
+ throw new NotImplementedException("BOM编码或需求数量不能为空!");
|
|
|
}
|
|
|
- var morderList = _mes_morder.GetAll().Result;
|
|
|
- var morderTypeList = morderList.Where(x => x.work_order_type == "备库工单" && x.morder_type == "计划工单" && x.bom_number == bomNumber && (x.morder_state == "初始" || x.morder_state == "下达")).ToList();
|
|
|
-
|
|
|
- //查询生产工单类型为计划工单并且工单类型为备库工单 并且BOM编码一致数据
|
|
|
- // 订单状态为 初始或下达工单
|
|
|
- var SatisfyQuantityList = morderTypeList.Where(x => x.morder_production_number >= Quantity).
|
|
|
- ToList().OrderBy(x => x.moentry_sys_etime).FirstOrDefault();
|
|
|
+ //根据Bom编码查询出对应工单并且状态不为完成、关闭,非委外工单。
|
|
|
+ //TODO:工单类型;
|
|
|
+ Expression<Func<mes_morder, bool>> filter = x => x.bom_number == bomNumber && (x.morder_state != "完成" || x.morder_state != "关闭"
|
|
|
+ && x.morder_icitem_type != "相关委外工单") && x.IsDeleted == false;
|
|
|
+ var morderList = await _mes_morder.GetManyByCondition(filter);
|
|
|
+
|
|
|
+ //TODO:获取销售订单信息
|
|
|
+
|
|
|
+ //工单已被占用后要与占用表关联查询...减去占用量后 剩下生产数量可供下个销售工单使用。
|
|
|
+ Expression<Func<mes_mooccupy, bool>> mooccupyfilter = x => x.moo_state == 1 && x.IsDeleted == false;
|
|
|
+ var mes_mooccupyList = await _mes_mooccupy.GetManyByCondition(mooccupyfilter);
|
|
|
+
|
|
|
+ //首先满足需求数量工单其次判断是否满足交付日期、当数量不满足时继续查找最早交付日期订单 工单数量累加。
|
|
|
+ //当前工单计划日期-1天 小于交付日期 && 计算生产数量-入库数据并且大于需求产品数量。
|
|
|
+ var morderDataList = morderList.Where(x => x.planner_end_date.Value.AddDays(-1) < DeliverDate &&
|
|
|
+ (x.morder_production_number - x.inventory_number) > Quantity).ToList();
|
|
|
+ if (morderDataList.Count > 0)
|
|
|
+ {
|
|
|
+ //存在此数据满足当前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
|
|
|
+ {
|
|
|
+ // 寻找最早日期工单 && 计算生产数量-入库数据并且大于需求产品数量后累加直到满足需求产品数量
|
|
|
+ var morderListData = morderList.Where(x => x.planner_end_date.Value.AddDays(-1) < DeliverDate).OrderByDescending(x => x.planner_end_date).ToList();
|
|
|
+ if (morderListData.Count == 0)
|
|
|
+ {
|
|
|
+ //TODO:后期处理无在制工单返回内容
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ //查询出工单已占用总数量
|
|
|
+ var mes_mooccupy = mes_mooccupyList.Where(x => x.moo_moid == item.Id).ToList();
|
|
|
+ //生成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 = item.Id;
|
|
|
+ mes_Mooccupy.moo_mo = item.morder_no;
|
|
|
+ //占用量=生产计划数量-入库数量-已被占用数量
|
|
|
+ mes_Mooccupy.moo_qty = item.morder_production_number - item.inventory_number - mes_mooccupy.Sum(x => x.moo_qty);
|
|
|
+ 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;
|
|
|
+ mes_Mooccupies.Add(mes_Mooccupy);
|
|
|
+ //需求数量-占用量后小于或等于0 停止循环占用工单
|
|
|
+ if (number - mes_Mooccupy.moo_qty <= 0)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return morderList;
|
|
|
+ #region 注释
|
|
|
+ /* var morderList = _mes_morder.GetAll().Result;
|
|
|
+ //查询生产工单类型为计划工单并且工单类型为备库工单 并且BOM编码一致数据,订单状态为 初始或下达工单
|
|
|
+ var morderTypeList = morderList.Where(x => x.work_order_type == "备库工单" && x.morder_type == "计划工单" &&
|
|
|
+ x.bom_number == bomNumber && (x.morder_state == "初始" || x.morder_state == "下达")).ToList();
|
|
|
+
|
|
|
+ //计划数量-需求数量=剩余可用数量 -->使用计划结束时间排序取第一条满足条件工单
|
|
|
+ // List =>数量满足Quantity && 生成工单结束日期最早
|
|
|
+ var SatisfyQuantityList = morderTypeList.Where(x => (x.morder_production_number.Value - x.need_number.Value) >= Quantity).
|
|
|
+ ToList().OrderBy(x => x.moentry_etime).FirstOrDefault();
|
|
|
if (SatisfyQuantityList == null)
|
|
|
{
|
|
|
|
|
|
@@ -187,10 +504,15 @@ namespace Business.ResourceExamineManagement
|
|
|
else
|
|
|
{
|
|
|
|
|
|
- }
|
|
|
- // List =>数量满足Quantity && 生成工单结束日期最早
|
|
|
+ }*/
|
|
|
+ #endregion
|
|
|
}
|
|
|
-
|
|
|
+ /// <summary>
|
|
|
+ /// BOM预处理
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="orderid"></param>
|
|
|
+ /// <param name="BomId"></param>
|
|
|
+ /// <param name="Quantity"></param>
|
|
|
public void BomPretreatment(long? orderid, long? BomId, int Quantity)
|
|
|
{
|
|
|
if (orderid == null)
|
|
|
@@ -216,10 +538,21 @@ namespace Business.ResourceExamineManagement
|
|
|
dto.qty = 1;
|
|
|
dto.num = "1";
|
|
|
dto.isbom = 1;
|
|
|
+ dto.is_replace = 0;
|
|
|
+ dto.haveicsubs = 0;
|
|
|
+ dto.substitute_code = "";
|
|
|
+ dto.icitem_ids = "";
|
|
|
GetBomList(bomlist, bomchildlist, icitemlist, dto, returnlist);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /// <summary>
|
|
|
+ /// BOM预处理层级组装
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="bomlist"></param>
|
|
|
+ /// <param name="bomchildlist"></param>
|
|
|
+ /// <param name="icitemlist"></param>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <param name="returnlist"></param>
|
|
|
public void GetBomList(List<ic_bom> bomlist, List<ic_bom_child> bomchildlist, List<ic_item> icitemlist, BomChildExamineDto dto, List<BomChildExamineDto> returnlist)
|
|
|
{
|
|
|
int level = dto.level++;//初始化定义level层级
|
|
|
@@ -244,6 +577,7 @@ namespace Business.ResourceExamineManagement
|
|
|
dto.erp_cls = item.erp_cls;
|
|
|
dto.erp_cls_name = item.erp_cls_name;
|
|
|
|
|
|
+
|
|
|
//var bdto = ObjectMapper.Map<ic_bom,BomChildExamineDto>(bom);
|
|
|
returnlist.Add(dto);
|
|
|
var childlist = bomchildlist.WhereIf(true, a => a.bom_id == bom.Id).ToList();
|
|
|
@@ -267,6 +601,10 @@ namespace Business.ResourceExamineManagement
|
|
|
cdto.backflush = c.backflush;
|
|
|
cdto.num = childNum;
|
|
|
cdto.isbom = 1;
|
|
|
+ cdto.is_replace = c.is_replace;
|
|
|
+ cdto.haveicsubs = c.haveicsubs;
|
|
|
+ cdto.substitute_code = c.substitute_code;
|
|
|
+ cdto.icitem_ids = c.icitem_ids;
|
|
|
GetBomList(bomlist, bomchildlist, icitemlist, cdto, returnlist);
|
|
|
}
|
|
|
}
|
|
|
@@ -290,6 +628,10 @@ namespace Business.ResourceExamineManagement
|
|
|
childDto.backflush = c.backflush;
|
|
|
childDto.qty = c.qty.Value;
|
|
|
childDto.isbom = 0;
|
|
|
+ childDto.is_replace = c.is_replace;
|
|
|
+ childDto.haveicsubs = c.haveicsubs;
|
|
|
+ childDto.substitute_code = c.substitute_code;
|
|
|
+ childDto.icitem_ids = c.icitem_ids;
|
|
|
returnlist.Add(childDto);
|
|
|
}
|
|
|
}
|
|
|
@@ -299,16 +641,117 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void BomSubstitute(List<BomChildExamineDto> returnlist)
|
|
|
+ /// <summary>
|
|
|
+ /// BOM替代关系预处理
|
|
|
+ /// </summary>
|
|
|
+ public void BomSubstitute(List<BomChildExamineDto> returnlist, List<ic_item> icitemlist)
|
|
|
+ {
|
|
|
+ var sublist = _ic_substitute.GetManyByCondition(s => s.substitute_code.IsIn(returnlist.Select(c => c.substitute_code))).Result.ToList();
|
|
|
+ var suballlist = _ic_substitute_all.GetManyByCondition(s => s.substitute_id.IsIn(sublist.Select(c => c.Id))).Result.ToList();
|
|
|
+ var subdtllist = _ic_substitute_all_dtl.GetManyByCondition(s => s.substitute_allid.IsIn(suballlist.Select(c => c.Id))).Result.ToList();
|
|
|
+
|
|
|
+ List<long> dicIds = new List<long>();
|
|
|
+ var help = new SnowFlake();
|
|
|
+ //除顶级外,其他层级关系全带出来。生成平铺
|
|
|
+ foreach (var item in returnlist)
|
|
|
+ {
|
|
|
+ //最顶级、虚拟件
|
|
|
+ if (item.level != 1 && item.erp_cls != 4)
|
|
|
+ {
|
|
|
+ //有替代关系
|
|
|
+ if (item.haveicsubs == 1)
|
|
|
+ {
|
|
|
+ /*//群组替代
|
|
|
+ if (item.is_replace == 1)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrEmpty(item.icitem_ids))
|
|
|
+ {
|
|
|
+ var ids = item.icitem_ids.Split(',');
|
|
|
+ foreach (var i in ids)
|
|
|
+ {
|
|
|
+ long id = 0;
|
|
|
+ if (long.TryParse(i, out id))
|
|
|
+ {
|
|
|
+ dicIds.Add(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+
|
|
|
+ var sl = sublist.Find(s => s.substitute_code == item.substitute_code);
|
|
|
+ if (sl != null)
|
|
|
+ {
|
|
|
+ var sall = suballlist.Where(s => s.substitute_id == sl.Id).ToList();
|
|
|
+ foreach (var sal in sall)
|
|
|
+ {
|
|
|
+ var sadl = subdtllist.Where(s => s.substitute_allid == sal.Id).ToList();
|
|
|
+ foreach (var dtl in sadl)
|
|
|
+ {
|
|
|
+ SubstitutePretreatment(sal, dtl, item, returnlist, icitemlist);
|
|
|
+ //var sitem = icitemlist.Find(s => s.Id == dtl.icitem_id);
|
|
|
+ //if (sitem != null)
|
|
|
+ //{
|
|
|
+ // var childDto = new BomChildExamineDto();
|
|
|
+ // childDto.level = item.level;
|
|
|
+ // childDto.bom_id = item.bom_id;
|
|
|
+ // childDto.id = help.NextId();
|
|
|
+ // childDto.parent_id = item.parent_id;
|
|
|
+ // childDto.item_id = sitem.Id;
|
|
|
+ // childDto.item_name = sitem.name;
|
|
|
+ // childDto.item_code = sitem.number;
|
|
|
+ // childDto.num = item.num;
|
|
|
+ // childDto.model = sitem.model;
|
|
|
+ // childDto.unit = sitem.unit;
|
|
|
+ // childDto.erp_cls = sitem.erp_cls;
|
|
|
+ // childDto.erp_cls_name = sitem.erp_cls_name;
|
|
|
+ // childDto.backflush = item.backflush;
|
|
|
+ // childDto.replace_amount = dtl.use_amount.Value;
|
|
|
+ // childDto.replace_amount = dtl.replace_amount.Value;
|
|
|
+
|
|
|
+ // childDto.isbom = 0;
|
|
|
+ // childDto.is_replace = c.is_replace;
|
|
|
+ // childDto.haveicsubs = c.haveicsubs;
|
|
|
+ // childDto.substitute_code = c.substitute_code;
|
|
|
+ // childDto.icitem_ids = c.icitem_ids;
|
|
|
+ // returnlist.Add(childDto);
|
|
|
+ //}
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SubstitutePretreatment(ic_substitute_all sal, ic_substitute_all_dtl dtl, BomChildExamineDto toDto, List<BomChildExamineDto> returnlist, List<ic_item> icitemlist)
|
|
|
+ {
|
|
|
+ //生成sal层级dto,是toDto的替代关系,类似R6-K50的BOM的层级1.1.1
|
|
|
+ //循环生成dtl层级dto,明细
|
|
|
+ //如果dtl对应的icitem是BOM,还需要向下继续展开。
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 计算库存量
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="returnlist"></param>
|
|
|
+ public void BomStock(List<BomChildExamineDto> returnlist, long factoryid)
|
|
|
{
|
|
|
returnlist = returnlist.OrderBy(s => s.num).ToList();
|
|
|
-
|
|
|
+ //取物料库存记录
|
|
|
+ var stocklist = _ic_item_stock.GetManyByCondition(s => s.icitem_id.IsIn(returnlist.Select(c => c.item_id)) && s.factory_id == factoryid).Result;
|
|
|
+ //取当前物料质检记录
|
|
|
+ //var checklist = _ic_check.GetManyByCondition(s => s.icitem_id.IsIn(returnlist.Select(c => c.item_id)) && s.istest.GetValueOrDefault() != 1).Result.ToList();
|
|
|
List<long> idlist = new List<long>();
|
|
|
foreach (var item in returnlist)
|
|
|
{
|
|
|
- if (item.num != "1")
|
|
|
+ if (item.erp_cls != 4)//虚拟件不计算
|
|
|
{
|
|
|
-
|
|
|
+ var sl = stocklist.Where(s => s.icitem_id == item.item_id).ToList();
|
|
|
+ //库存=物料库存+VMI库存+质检未入库。
|
|
|
+ item.sqty = sl.Sum(s => s.sqty).GetValueOrDefault();
|
|
|
+ //质检记录没加入,暂时不考虑。
|
|
|
+ //VMI仓储信息
|
|
|
}
|
|
|
}
|
|
|
}
|