|
|
@@ -40,6 +40,10 @@ namespace Business.ResourceExamineManagement
|
|
|
/// 销售订单明细
|
|
|
/// </summary>
|
|
|
private readonly IRepository<crm_seorderentry, long> _mysql_crm_seorderentry;
|
|
|
+ /// <summary>
|
|
|
+ /// 产能检查
|
|
|
+ /// </summary>
|
|
|
+ private readonly ProductExamineAppService _productExamineAppService;
|
|
|
|
|
|
#endregion
|
|
|
#region 构造函数
|
|
|
@@ -53,7 +57,8 @@ namespace Business.ResourceExamineManagement
|
|
|
IMongoDB<mes_moentry> mes_moentry,
|
|
|
IMongoDB<mes_mooccupy> mes_mooccupy,
|
|
|
IRepository<crm_seorder, long> mysql_crm_seorder,
|
|
|
- IRepository<crm_seorderentry, long> mysql_crm_seorderentry
|
|
|
+ IRepository<crm_seorderentry, long> mysql_crm_seorderentry,
|
|
|
+ ProductExamineAppService productExamineAppService
|
|
|
)
|
|
|
{
|
|
|
|
|
|
@@ -62,6 +67,7 @@ namespace Business.ResourceExamineManagement
|
|
|
_mes_mooccupy = mes_mooccupy;
|
|
|
_mysql_crm_seorder = mysql_crm_seorder;
|
|
|
_mysql_crm_seorderentry = mysql_crm_seorderentry;
|
|
|
+ _productExamineAppService = productExamineAppService;
|
|
|
|
|
|
}
|
|
|
#endregion
|
|
|
@@ -170,7 +176,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <param name="DeliverDate">交付日期</param>
|
|
|
/// <param name="seorderentry_id">销售订单子表ID</param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<List<mes_mooccupy>> CheckMorder(string bomNumber, decimal? Quantity, DateTime DeliverDate, crm_seorderentry seorderentry, ic_item ic_Item)
|
|
|
+ public async Task<List<mes_mooccupy>> CheckMorder(string bomNumber, decimal? Quantity, DateTime DeliverDate, crm_seorderentry seorderentry, ic_item ic_Item, string version)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(bomNumber) || Quantity == null)
|
|
|
{
|
|
|
@@ -183,7 +189,6 @@ namespace Business.ResourceExamineManagement
|
|
|
//var seorderentry = await _mysql_crm_seorderentry.FindAsync(x => x.Id == seorderentry_id);
|
|
|
//根据Bom编码查询出对应工单并且状态不为完成、关闭,非委外工单。
|
|
|
//TODO:工单类型;
|
|
|
- //TODO:占用时间是使用生产工单开始结束日期、还是系统建议开始结束时间。
|
|
|
var morderList = await _mes_morder.GetManyByCondition(x => x.bom_number == bomNumber && (x.morder_state != "完成" || x.morder_state != "关闭"
|
|
|
&& x.morder_icitem_type != "相关委外工单") && !x.IsDeleted && x.tenant_id == seorderentry.tenant_id);
|
|
|
|
|
|
@@ -196,40 +201,79 @@ namespace Business.ResourceExamineManagement
|
|
|
|
|
|
//首先满足需求数量工单其次判断是否满足交付日期、当数量不满足时继续查找最早交付日期订单 工单数量累加。
|
|
|
//当前工单计划日期-1天 小于交付日期 && 计算生产数量-入库数据并且大于需求产品数量。
|
|
|
- var morderDataList = morderList.Where(x => x.moentry_sys_etime.Value.AddDays(-1) < DeliverDate &&
|
|
|
+ var morderDataList = morderList.Where(x => x.moentry_sys_etime.GetValueOrDefault().AddDays(-1) < DeliverDate &&
|
|
|
(x.morder_production_number - x.inventory_number) > Quantity).OrderByDescending(x => x.planner_end_date).ToList();
|
|
|
List<mes_mooccupy> mes_Mooccupies = new List<mes_mooccupy>();
|
|
|
//当数量或日期不满足的时候,寻找最早日期的工单
|
|
|
if (morderDataList.Count == 0)
|
|
|
{
|
|
|
- morderDataList = morderList.Where(x => x.moentry_sys_etime.Value.AddDays(-1) < DeliverDate).OrderByDescending(x => x.planner_end_date).ToList();
|
|
|
+ morderDataList = morderList.Where(x => x.moentry_sys_etime.GetValueOrDefault().AddDays(-1) < DeliverDate).OrderByDescending(x => x.planner_end_date).ToList();
|
|
|
}
|
|
|
//存在此数据满足当前BOM交付找到最早日期工单,则返回无需后续继续检查。
|
|
|
foreach (var item in morderDataList)
|
|
|
{
|
|
|
//查询当前工单是否存在占用情况
|
|
|
var mooccupies = mes_mooccupyList.Where(x => x.moo_moid == item.Id).ToList();
|
|
|
- if (mooccupies.Count > 0)
|
|
|
+ //已占用数据
|
|
|
+ var Sumqty = mooccupies.Count > 0 ? mooccupies.Sum(x => x.moo_qty) : 0.00m;
|
|
|
+ //判断此工单剩余可占用数量
|
|
|
+ if (item.morder_production_number - item.inventory_number - Sumqty > 0)
|
|
|
{
|
|
|
- var Sumqty = mooccupies.Count > 0 ? mooccupies.Sum(x => x.moo_qty) : 0.00m;
|
|
|
- //判断此工单剩余可占用数量
|
|
|
- if (item.morder_production_number - item.inventory_number - Sumqty > 0)
|
|
|
+ #region 注释
|
|
|
+ //if (Sumqty > 0 || item.inventory_number > 0)
|
|
|
+ //{
|
|
|
+ // ProdExamineParamDto prodExamine = new ProdExamineParamDto()
|
|
|
+ // {
|
|
|
+ // bom_number = item.bom_number,
|
|
|
+ // version = version,
|
|
|
+ // packages = (int)(item.inventory_number + Sumqty).GetValueOrDefault(),
|
|
|
+ // tenantId = item.tenant_id,
|
|
|
+ // factoryId = item.factory_id.GetValueOrDefault()
|
|
|
+
|
|
|
+ // };
|
|
|
+ // //获取入库和已占用的数据的生产时长
|
|
|
+ // var ProductiveDate = _productExamineAppService.ProductiveExamine(prodExamine);
|
|
|
+ // var Day = ProductiveDate.Result / (60 * 10);
|
|
|
+ // //工单被完全占用结束日期为工单结束时间
|
|
|
+ // if (Quantity - (item.morder_production_number - item.inventory_number - Sumqty) == 0)
|
|
|
+ // {
|
|
|
+
|
|
|
+ // var date = item.moentry_sys_stime.GetValueOrDefault().AddDays((double)Day);
|
|
|
+ // var endDate = item.moentry_sys_etime;
|
|
|
+ // }
|
|
|
+ // //工单未被完成占用计算结束日期
|
|
|
+ // else if (item.morder_production_number - item.inventory_number - Sumqty - Quantity > 0)
|
|
|
+ // {
|
|
|
+ // var date = item.moentry_sys_stime.GetValueOrDefault().AddDays((double)Day);
|
|
|
+ // ProdExamineParamDto EndprodExamine = new ProdExamineParamDto()
|
|
|
+ // {
|
|
|
+ // bom_number = item.bom_number,
|
|
|
+ // version = version,
|
|
|
+ // packages = (int)Quantity.GetValueOrDefault(),
|
|
|
+ // tenantId = item.tenant_id,
|
|
|
+ // factoryId = item.factory_id.GetValueOrDefault()
|
|
|
+
|
|
|
+ // };
|
|
|
+ // var EndProductiveDate = _productExamineAppService.ProductiveExamine(EndprodExamine);
|
|
|
+ // var EndDay = ProductiveDate.Result / (60 * 10);
|
|
|
+ // var endDate = date.AddDays((double)EndDay);
|
|
|
+ // }
|
|
|
+
|
|
|
+ //}
|
|
|
+
|
|
|
+ #endregion
|
|
|
+ var Sum = item.morder_production_number - item.inventory_number - Sumqty;
|
|
|
+ //剩余需要数量= 需要数量 -(计划数量 - 入库数量 - 已占用量)
|
|
|
+ Quantity = Quantity - (item.morder_production_number - item.inventory_number - Sumqty);
|
|
|
+ var mes_Mooccupy = GetMooccupies(seorderentry, ic_Item, item, Sum);
|
|
|
+ mes_Mooccupies.Add(mes_Mooccupy);
|
|
|
+ //当剩余需要数量大于0则继续寻找可占用工单,已满足需要数量停止循环查找
|
|
|
+ if (Quantity <= 0)
|
|
|
{
|
|
|
- var Sum = item.morder_production_number - item.inventory_number - Sumqty;
|
|
|
- //剩余需要数量= 需要数量 -(计划数量 - 入库数量 - 已占用量)
|
|
|
- Quantity = Quantity - (item.morder_production_number - item.inventory_number - Sumqty);
|
|
|
- //当剩余需要数量大于0则继续寻找可占用工单,已满足需要数量停止循环查找
|
|
|
- if (Quantity > 0)
|
|
|
- {
|
|
|
- var mes_Mooccupy = GetMooccupies(seorderentry, ic_Item, item, Sum);
|
|
|
- mes_Mooccupies.Add(mes_Mooccupy);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
await _mes_mooccupy.InsertMany(mes_Mooccupies);
|
|
|
#region 注释
|
|
|
@@ -333,7 +377,7 @@ namespace Business.ResourceExamineManagement
|
|
|
//生成mes_mooccupy工单占用表数据,代表多个工单被某个销售订单已占用。
|
|
|
mes_mooccupy mes_Mooccupy = new mes_mooccupy();
|
|
|
mes_Mooccupy.GenerateNewId();
|
|
|
- mes_Mooccupy.moo_id_type = "分配";
|
|
|
+ mes_Mooccupy.moo_id_type = "资源检查";
|
|
|
mes_Mooccupy.moo_id_billid = seorderentry.seorder_id;//销售订单ID
|
|
|
mes_Mooccupy.fbill_no = seorderentry.bill_no;//销售订单号
|
|
|
mes_Mooccupy.fentry_id = seorderentry.entry_seq.Value;//销售订单行
|