|
|
@@ -25,6 +25,8 @@ using ZstdSharp.Unsafe;
|
|
|
using System.Transactions;
|
|
|
using NUglify.JavaScript.Syntax;
|
|
|
using System.Linq.Expressions;
|
|
|
+using XCZ.Extensions;
|
|
|
+using System.ComponentModel.Design;
|
|
|
using Volo.Abp.Validation.StringValues;
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
@@ -76,22 +78,27 @@ 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<mes_morder> _mes_morder;
|
|
|
-
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -104,10 +111,11 @@ namespace Business.ResourceExamineManagement
|
|
|
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<mes_morder> mes_morder,
|
|
|
+ IBasicRepository<ic_item, long> mysql_ic_item,
|
|
|
+ IBasicRepository<ic_bom, long> mysql_ic_bom,
|
|
|
+ IBasicRepository<ic_bom_child, long> mysql_ic_bom_child
|
|
|
|
|
|
)
|
|
|
{
|
|
|
@@ -115,10 +123,11 @@ namespace Business.ResourceExamineManagement
|
|
|
_ic_item = ic_item;
|
|
|
_ic_bom = ic_bom;
|
|
|
_ic_bom_child = ic_bom_child;
|
|
|
+ _ic_item_stock = ic_item_stock;
|
|
|
_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>
|
|
|
@@ -328,21 +337,67 @@ namespace Business.ResourceExamineManagement
|
|
|
/// </summary>
|
|
|
/// <param name="bomNumber">Bom编码</param>
|
|
|
/// <param name="Quantity">需要数量</param>
|
|
|
+ /// <param name="EndDate">交付日期</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)
|
|
|
{
|
|
|
- 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);
|
|
|
+ //首先满足需求数量工单其次判断是否满足交付日期、当数量不满足时继续查找最早交付日期订单 工单数量累加。
|
|
|
+
|
|
|
+ //当前工单计划日期-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工单占用表数据,代表此工单被某个销售订单已占用。
|
|
|
+ }
|
|
|
+ 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>();
|
|
|
+ decimal? number = Quantity;
|
|
|
+ foreach (var item in morderListData)
|
|
|
+ {
|
|
|
+ number = number - (item.morder_production_number - item.inventory_number);
|
|
|
+ if (number < 0)
|
|
|
+ {
|
|
|
+ mes_Morders.Add(item);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //生成mes_mooccupy工单占用表数据,代表多个工单被某个销售订单已占用。
|
|
|
+ }
|
|
|
+ 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)
|
|
|
{
|
|
|
|
|
|
@@ -350,8 +405,8 @@ namespace Business.ResourceExamineManagement
|
|
|
else
|
|
|
{
|
|
|
|
|
|
- }
|
|
|
- // List =>数量满足Quantity && 生成工单结束日期最早
|
|
|
+ }*/
|
|
|
+ #endregion
|
|
|
}
|
|
|
|
|
|
public void BomPretreatment(long? orderid, long? BomId, int Quantity)
|
|
|
@@ -379,6 +434,10 @@ 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);
|
|
|
}
|
|
|
|
|
|
@@ -407,6 +466,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();
|
|
|
@@ -430,6 +490,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);
|
|
|
}
|
|
|
}
|
|
|
@@ -453,6 +517,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);
|
|
|
}
|
|
|
}
|
|
|
@@ -461,18 +529,18 @@ namespace Business.ResourceExamineManagement
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void BomSubstitute(List<BomChildExamineDto> returnlist)
|
|
|
+ /// <summary>
|
|
|
+ /// 计算库存量
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="returnlist"></param>
|
|
|
+ public void BomStock(List<BomChildExamineDto> returnlist)
|
|
|
{
|
|
|
returnlist = returnlist.OrderBy(s => s.num).ToList();
|
|
|
-
|
|
|
+
|
|
|
List<long> idlist = new List<long>();
|
|
|
foreach (var item in returnlist)
|
|
|
{
|
|
|
- if (item.num != "1")
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|