|
|
@@ -125,6 +125,11 @@ namespace Business.ResourceExamineManagement
|
|
|
/// 在制工单占用记录表
|
|
|
/// </summary>
|
|
|
private readonly IMongoDB<mes_mooccupy> _mes_mooccupy;
|
|
|
+ /// <summary>
|
|
|
+ /// 销售工单
|
|
|
+ /// </summary>
|
|
|
+ private readonly IMongoDB<crm_seorder> _crm_seorder;
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -216,7 +221,7 @@ namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
//测试代码
|
|
|
//await test();
|
|
|
- await ProductiveExamine(1733221167209762816,100,1000);
|
|
|
+ await ProductiveExamine(1733221167209762816, 100, 1000);
|
|
|
return null;
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
@@ -232,7 +237,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <param name="quantity">需要生产数量</param>
|
|
|
public async Task<DateTime> ProductiveExamine(long tech_id, int packages, int quantity)
|
|
|
{
|
|
|
- if (packages <=0 ||quantity <= 0)
|
|
|
+ if (packages <= 0 || quantity <= 0)
|
|
|
{
|
|
|
throw new NotImplementedException("产能计算参数有误!");
|
|
|
}
|
|
|
@@ -276,7 +281,7 @@ namespace Business.ResourceExamineManagement
|
|
|
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));
|
|
|
+ throw new NotImplementedException(string.Format("工艺[{0}]下的工序[{1}]节拍时间设置有误,请调整!", tech.tech_name, curProcess.proc_name));
|
|
|
}
|
|
|
if (item.type == 2 && item.uph == 0)
|
|
|
{
|
|
|
@@ -321,7 +326,8 @@ namespace Business.ResourceExamineManagement
|
|
|
//当前流水线消耗时间
|
|
|
sumTimes += (packages - 1) * maxCT + sumCT + sumLT;
|
|
|
}
|
|
|
- else{//不存在父子级关系
|
|
|
+ else
|
|
|
+ {//不存在父子级关系
|
|
|
//2、两种计算模式UPH/节拍时间
|
|
|
if (item.type == 2)//uph
|
|
|
{
|
|
|
@@ -365,8 +371,9 @@ namespace Business.ResourceExamineManagement
|
|
|
allProcess.Add(item);
|
|
|
//获取上一工序
|
|
|
var preProc = tech_Processes.FirstOrDefault(p => p.nextprocid == item.proc_id);
|
|
|
- if (preProc != null) {
|
|
|
- GetPreProcess(tech_Processes, preProc, allProcess);
|
|
|
+ if (preProc != null)
|
|
|
+ {
|
|
|
+ GetPreProcess(tech_Processes, preProc, allProcess);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -380,8 +387,9 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <param name="bomNumber">Bom编码</param>
|
|
|
/// <param name="Quantity">需要数量</param>
|
|
|
/// <param name="EndDate">交付日期</param>
|
|
|
+ /// <param name="OrderId">销售订单ID</param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<List<mes_morder>> CheckMorder(string bomNumber, decimal? Quantity, DateTime DeliverDate)
|
|
|
+ public async Task<List<mes_morder>> CheckMorder(string bomNumber, decimal? Quantity, DateTime DeliverDate, long OrderId)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(bomNumber) || Quantity != null)
|
|
|
{
|
|
|
@@ -393,13 +401,14 @@ namespace Business.ResourceExamineManagement
|
|
|
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);
|
|
|
- //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();
|
|
|
@@ -446,19 +455,34 @@ namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
//查询出工单已占用总数量
|
|
|
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_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)
|
|
|
{
|
|
|
- mes_Morders.Add(item);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- //生成mes_mooccupy工单占用表数据,代表多个工单被某个销售订单已占用。
|
|
|
}
|
|
|
return morderList;
|
|
|
#region 注释
|
|
|
@@ -621,7 +645,7 @@ namespace Business.ResourceExamineManagement
|
|
|
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 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>();
|
|
|
@@ -630,7 +654,7 @@ namespace Business.ResourceExamineManagement
|
|
|
foreach (var item in returnlist)
|
|
|
{
|
|
|
//最顶级、虚拟件
|
|
|
- if (item.level != 1 && item.erp_cls!=4)
|
|
|
+ if (item.level != 1 && item.erp_cls != 4)
|
|
|
{
|
|
|
//有替代关系
|
|
|
if (item.haveicsubs == 1)
|
|
|
@@ -658,7 +682,7 @@ namespace Business.ResourceExamineManagement
|
|
|
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();
|
|
|
+ var sadl = subdtllist.Where(s => s.substitute_allid == sal.Id).ToList();
|
|
|
foreach (var dtl in sadl)
|
|
|
{
|
|
|
SubstitutePretreatment(sal, dtl, item, returnlist, icitemlist);
|
|
|
@@ -698,7 +722,7 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void SubstitutePretreatment(ic_substitute_all sal, ic_substitute_all_dtl dtl,BomChildExamineDto toDto,List<BomChildExamineDto> returnlist, List<ic_item> icitemlist)
|
|
|
+ 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,明细
|
|
|
@@ -709,7 +733,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// 计算库存量
|
|
|
/// </summary>
|
|
|
/// <param name="returnlist"></param>
|
|
|
- public void BomStock(List<BomChildExamineDto> returnlist,long factoryid)
|
|
|
+ public void BomStock(List<BomChildExamineDto> returnlist, long factoryid)
|
|
|
{
|
|
|
returnlist = returnlist.OrderBy(s => s.num).ToList();
|
|
|
//取物料库存记录
|