|
|
@@ -35,6 +35,7 @@ using System.ComponentModel.Design;
|
|
|
using Volo.Abp.Validation.StringValues;
|
|
|
using System.Runtime.CompilerServices;
|
|
|
using MongoDB.Driver;
|
|
|
+using Volo.Abp.Validation.Localization;
|
|
|
|
|
|
namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
@@ -81,6 +82,11 @@ namespace Business.ResourceExamineManagement
|
|
|
/// </summary>
|
|
|
private readonly IMongoDB<mes_schedule_occupy> _mes_schedule_occupy;
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 物料占用记录
|
|
|
+ /// </summary>
|
|
|
+ private readonly IMongoDB<ic_item_stockoccupy> _ic_item_stockoccupy;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 物料详情
|
|
|
/// </summary>
|
|
|
@@ -158,6 +164,7 @@ namespace Business.ResourceExamineManagement
|
|
|
//IMongoDB<ic_substitute_all_dtl> ic_substitute_all_dtl,
|
|
|
IMongoDB<mes_morder> mes_morder,
|
|
|
IMongoDB<mes_mooccupy> mes_mooccupy,
|
|
|
+ IMongoDB<ic_item_stockoccupy> ic_item_stockoccupy,
|
|
|
IRepository<ic_item, long> mysql_ic_item,
|
|
|
IRepository<ic_bom, long> mysql_ic_bom,
|
|
|
IRepository<ic_bom_child, long> mysql_ic_bom_child,
|
|
|
@@ -179,6 +186,8 @@ namespace Business.ResourceExamineManagement
|
|
|
//_ic_substitute_all = ic_substitute_all;
|
|
|
//_ic_substitute_all_dtl = ic_substitute_all_dtl;
|
|
|
_mes_morder = mes_morder;
|
|
|
+ _mes_mooccupy = mes_mooccupy;
|
|
|
+ _ic_item_stockoccupy = ic_item_stockoccupy;
|
|
|
_mysql_ic_item = mysql_ic_item;
|
|
|
_mysql_ic_bom = mysql_ic_bom;
|
|
|
_mysql_ic_bom_child = mysql_ic_bom_child;
|
|
|
@@ -228,24 +237,31 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
public async Task<PschedDto> ReceiveResult(SeorderentryDto input)
|
|
|
{
|
|
|
- //测试代码
|
|
|
- //await test();
|
|
|
- //同步数据测试方法
|
|
|
- //await SyncData();
|
|
|
-
|
|
|
- await ProductiveExamine(1733221167209762816, 100);
|
|
|
+ //数据库快照-同步mysql库数据到mongoDB中
|
|
|
+ await SyncData();
|
|
|
+ //生成当前计算bangid
|
|
|
+ //SnowFlake snow = new SnowFlake();
|
|
|
+ //long bangid = snow.NextId();
|
|
|
+
|
|
|
+ ////产能检查
|
|
|
+ //await ProductiveExamine(1733221167209762816, 100);
|
|
|
return null;
|
|
|
throw new NotImplementedException();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 同步数据
|
|
|
+ /// 数据库快照
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public async Task SyncData()
|
|
|
{
|
|
|
- var query = _mysql_mes_technique.GetQueryableAsync().Result.ToListAsync().Result;
|
|
|
- await _mes_technique.InsertMany(query);
|
|
|
+ //var query = _mysql_mes_technique.GetQueryableAsync().Result.ToListAsync().Result;
|
|
|
+ //await _mes_technique.InsertMany(query);
|
|
|
+ var dt1 = DateTime.Now;
|
|
|
+ var query = _mysql_ic_bom_child.GetQueryableAsync().Result.ToListAsync().Result;
|
|
|
+ await _ic_bom_child.InsertMany(query);
|
|
|
+ var dt2 = DateTime.Now;
|
|
|
+ var c = 3;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -273,105 +289,40 @@ namespace Business.ResourceExamineManagement
|
|
|
//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 = await _mes_tech_proc_workshop.GetManyByIds(filter1);
|
|
|
-
|
|
|
- //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)
|
|
|
+ decimal sumTimes = 0.00m;//总耗时(分钟)
|
|
|
+ //工序需要等待时间记录
|
|
|
+ List<StartTimeDto> starts = new List<StartTimeDto>();
|
|
|
+ //1、获取工艺路径下的第一层级工序
|
|
|
+ List<mes_tech_process> fistChilds = tech_Processes.Where(p => p.parentprocid == tech_id).OrderBy(m => m.Id).ToList();
|
|
|
+ if (fistChilds.Count == 0)
|
|
|
{
|
|
|
- //数据校验
|
|
|
- //获取当前工序
|
|
|
- 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)//存在父子级关系
|
|
|
+ throw new NotImplementedException("当前工艺路径没有配置工序,请调整!");
|
|
|
+ }
|
|
|
+ decimal curTakeTime = 0.00m;//当前工序耗时(分钟)
|
|
|
+ //添加第一个工序需要等待时间记录
|
|
|
+ StartTimeDto dto;
|
|
|
+ foreach (var chd in fistChilds)
|
|
|
+ {
|
|
|
+ dto = new StartTimeDto();
|
|
|
+ if (chd.nextprocid == 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)
|
|
|
- {
|
|
|
- //当前工序消耗时间:件数*单位数量/uph*60*效率系数+前置准备时间
|
|
|
- time = packages * chd.upp.Value / chd.uph.Value * 60 * chd.effect_ratio.Value + chd.readytime.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;
|
|
|
+ //计算最后一个工序耗时
|
|
|
+ curTakeTime = CalcTakeTime(chd, packages);
|
|
|
}
|
|
|
else
|
|
|
- {//不存在父子级关系
|
|
|
- //2、两种计算模式UPH/节拍时间
|
|
|
- if (item.type == 2)//uph
|
|
|
- {
|
|
|
- //当前工序消耗时间:件数*单位数量/uph*60*效率系数+前置准备时间
|
|
|
- sumTimes += packages * item.upp.Value / 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;
|
|
|
+ {
|
|
|
+ curTakeTime = CalcTakeTime(chd, chd.lq.Value);
|
|
|
}
|
|
|
+ sumTimes += curTakeTime;
|
|
|
+ //添加耗时记录
|
|
|
+ dto.tech_id = tech_id;
|
|
|
+ dto.proc_id = chd.proc_id;
|
|
|
+ dto.nextproc_id = chd.nextprocid;
|
|
|
+ dto.wait_time = curTakeTime;
|
|
|
+ starts.Add(dto);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
@@ -379,32 +330,91 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 递归获取工序
|
|
|
+ /// 计算当前工序前置准备时间
|
|
|
/// </summary>
|
|
|
- /// <param name="tech_Processes"></param>
|
|
|
- /// <param name="item"></param>
|
|
|
+ /// <param name="proc"></param>
|
|
|
+ /// <param name="quantity">LeadQuantity to Start Next</param>
|
|
|
/// <returns></returns>
|
|
|
- private void GetPreProcess(List<mes_tech_process> tech_Processes, mes_tech_process item, List<mes_tech_process> allProcess)
|
|
|
+ private decimal CalcTakeTime(mes_tech_process proc, decimal quantity)
|
|
|
{
|
|
|
- allProcess.Add(item);
|
|
|
- //获取上一工序
|
|
|
- var preProc = tech_Processes.FirstOrDefault(p => p.nextprocid == item.proc_id);
|
|
|
- if (preProc != null)
|
|
|
+ decimal takeTime = 0.00m;//当前工序前置准备时间(分钟)
|
|
|
+ if (proc.wctype == 1)//人工型:数量/uph(一小时生产数量)*60(小时转换为分钟)/wsinuse(工位数)
|
|
|
{
|
|
|
- GetPreProcess(tech_Processes, preProc, allProcess);
|
|
|
+ takeTime = quantity / proc.uph.Value * 60 / proc.wsinuse.Value;
|
|
|
+ return takeTime;
|
|
|
}
|
|
|
+ else if (proc.wctype == 2)//流水线型:数量*ct(生产一件所需时间)
|
|
|
+ {
|
|
|
+ takeTime = quantity * proc.ct.Value;
|
|
|
+ return takeTime;
|
|
|
+ }
|
|
|
+ else if (proc.wctype == 3)//设备型:向上取整(数量/一次可加工数量)*ct(老化一次所需时间)
|
|
|
+ {
|
|
|
+ takeTime = Math.Ceiling(quantity / proc.upe.Value) * proc.ct.Value;
|
|
|
+ return takeTime;
|
|
|
+ }
|
|
|
+ return takeTime;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 生成主工单
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="BomNumber">Bom编码</param>
|
|
|
+ /// <param name="Quantity">需要数量</param>
|
|
|
+ /// <param name="DeliverDate">交付日期</param>
|
|
|
+ /// <param name="OrderId">销售订单ID</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task GenerateMorder(string BomNumber, decimal? Quantity, DateTime DeliverDate, long OrderId)
|
|
|
+ {
|
|
|
+ //需要生成的物料,需要生产的数量,对应销售订单。
|
|
|
|
|
|
+ //1.库存、在制工单检查完成后 当前BOM需要自制时 产生工单。
|
|
|
|
|
|
+ //2.每一个销售订单行对应一个工单。
|
|
|
|
|
|
+ if (string.IsNullOrEmpty(BomNumber) || Quantity == null)
|
|
|
+ {
|
|
|
+ //TODO: 参数异常 直接返回
|
|
|
+ }
|
|
|
+ //获取销售订单信息
|
|
|
+ //var seorder = await _crm_seorder.FindAsync(x => x.Id == OrderId);
|
|
|
+ var seorderentry = await _crm_seorderentry.FindAsync(x => x.seorder_id == OrderId);
|
|
|
+
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 检查成品库存
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="OrderId">销售订单ID</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task<bool> CheckFinishedProductInventory(long OrderId)
|
|
|
+ {
|
|
|
+ //获取销售订单信息
|
|
|
+ var seorder = await _crm_seorder.FindAsync(x => x.Id == OrderId);
|
|
|
+ //获取销售订单子表
|
|
|
+ var seorderentry = await _crm_seorderentry.FindAsync(x => x.seorder_id == OrderId);
|
|
|
+ if (string.IsNullOrEmpty(seorderentry.bom_number))
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Expression<Func<ic_item_stock, bool>> filter = x => x.icitem_id == long.Parse(seorderentry.bom_number);
|
|
|
+ var ic_Item_Stocks = await _ic_item_stock.GetManyByCondition(filter);
|
|
|
+
|
|
|
+ if (seorderentry.qty <= ic_Item_Stocks.Sum(x => x.sqty))
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 检查在制工单
|
|
|
/// </summary>
|
|
|
/// <param name="bomNumber">Bom编码</param>
|
|
|
/// <param name="Quantity">需要数量</param>
|
|
|
- /// <param name="EndDate">交付日期</param>
|
|
|
+ /// <param name="DeliverDate">交付日期</param>
|
|
|
/// <param name="OrderId">销售订单ID</param>
|
|
|
/// <returns></returns>
|
|
|
public async Task<List<mes_morder>> CheckMorder(string bomNumber, decimal? Quantity, DateTime DeliverDate, long OrderId)
|
|
|
@@ -420,9 +430,10 @@ namespace Business.ResourceExamineManagement
|
|
|
&& x.morder_icitem_type != "相关委外工单") && x.IsDeleted == false;
|
|
|
var morderList = await _mes_morder.GetManyByCondition(filter);
|
|
|
|
|
|
- //TODO:获取销售订单信息
|
|
|
+ //获取销售订单信息
|
|
|
//var seorder = await _crm_seorder.FindAsync(x => x.Id == OrderId);
|
|
|
var seorderentry = await _crm_seorderentry.FindAsync(x => x.seorder_id == OrderId);
|
|
|
+ //获取物料详情
|
|
|
var mysql_ic_item = await _mysql_ic_item.FindAsync(x => x.number == bomNumber);
|
|
|
|
|
|
//工单已被占用后要与占用表关联查询...减去占用量后 剩下生产数量可供下个销售工单使用。
|
|
|
@@ -466,25 +477,6 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
}
|
|
|
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)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- }*/
|
|
|
- #endregion
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 拼接工单占用表
|
|
|
@@ -521,7 +513,7 @@ namespace Business.ResourceExamineManagement
|
|
|
mes_Mooccupy.moo_cbr = string.Empty;
|
|
|
//mes_Mooccupy.moo_ctime = ;
|
|
|
mes_Mooccupy.moo_creason = string.Empty;
|
|
|
- mes_Mooccupy.tenant_id = 0;
|
|
|
+ mes_Mooccupy.tenant_id = 0;//TODO:企业ID =集团 或公司ID
|
|
|
return mes_Mooccupy;
|
|
|
}
|
|
|
/// <summary>
|
|
|
@@ -571,7 +563,7 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <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 type)
|
|
|
+ public void GetBomList(List<ic_bom> bomlist, List<ic_bom_child> bomchildlist, List<ic_item> icitemlist, BomChildExamineDto dto, List<BomChildExamineDto> returnlist, int type)
|
|
|
{
|
|
|
int level = dto.level++;//初始化定义level层级
|
|
|
var help = new SnowFlake();
|
|
|
@@ -689,7 +681,7 @@ namespace Business.ResourceExamineManagement
|
|
|
foreach (var dtl in sadl)
|
|
|
{
|
|
|
//递归将替代关系组装出来。
|
|
|
- SubstitutePretreatment(sl, sal, dtl, item, returnlist, icitemlist, bomlist, bomchildlist,type);
|
|
|
+ SubstitutePretreatment(sl, sal, dtl, item, returnlist, icitemlist, bomlist, bomchildlist, type);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -708,12 +700,12 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <param name="icitemlist"></param>
|
|
|
/// <param name="bomlist"></param>
|
|
|
/// <param name="bomchildlist"></param>
|
|
|
- public void SubstitutePretreatment(ic_substitute sl, ic_substitute_all sal, ic_substitute_all_dtl dtl,BomChildExamineDto toDto,List<BomChildExamineDto> returnlist, List<ic_item> icitemlist, List<ic_bom> bomlist, List<ic_bom_child> bomchildlist,int type)
|
|
|
+ public void SubstitutePretreatment(ic_substitute sl, ic_substitute_all sal, ic_substitute_all_dtl dtl, BomChildExamineDto toDto, List<BomChildExamineDto> returnlist, List<ic_item> icitemlist, List<ic_bom> bomlist, List<ic_bom_child> bomchildlist, int type)
|
|
|
{
|
|
|
//循环生成dtl层级dto,明细
|
|
|
//如果dtl对应的icitem是BOM,还需要向下继续展开。
|
|
|
var help = new SnowFlake();
|
|
|
-
|
|
|
+
|
|
|
//List<BomChildExamineDto> returnlist = new List<BomChildExamineDto>();
|
|
|
var dto = new BomChildExamineDto();
|
|
|
var bom = bomlist.WhereIf(true, s => s.icitem_id == dtl.icitem_id).FirstOrDefault();
|
|
|
@@ -746,7 +738,7 @@ namespace Business.ResourceExamineManagement
|
|
|
if (bom != null)
|
|
|
{
|
|
|
dto.bom_id = bom.Id;
|
|
|
-
|
|
|
+
|
|
|
dto.qty = dtl.replace_amount.Value;
|
|
|
dto.isbom = 1;
|
|
|
dto.is_replace = 0;
|
|
|
@@ -755,7 +747,8 @@ namespace Business.ResourceExamineManagement
|
|
|
dto.icitem_ids = "";
|
|
|
GetBomList(bomlist, bomchildlist, icitemlist, dto, returnlist, type);
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
dto.bom_id = null;
|
|
|
dto.isbom = 0;
|
|
|
returnlist.Add(dto);
|
|
|
@@ -763,27 +756,31 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 计算库存量
|
|
|
+ /// 计算物料库存量
|
|
|
/// </summary>
|
|
|
/// <param name="returnlist"></param>
|
|
|
- public void BomStock(List<BomChildExamineDto> returnlist, long factoryid)
|
|
|
+ public void BomStock(List<BomChildExamineDto> returnlist, long bangid, long orderid, long orderentryid, 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>();
|
|
|
+ FilterDefinition<ic_item_stock> filter = Builders<ic_item_stock>.Filter.In(s => s.icitem_id, returnlist.Select(c => c.item_id).ToList());
|
|
|
+ var stocklist = _ic_item_stock.GetManyByIds(filter).Result;
|
|
|
+ //取当前订单的物料库存占用记录
|
|
|
+ var occupylist = _ic_item_stockoccupy.GetManyByCondition(p => p.bang_id == bangid && p.order_id == orderid).Result;
|
|
|
+ //计算剩余库存
|
|
|
foreach (var item in returnlist)
|
|
|
{
|
|
|
- if (item.erp_cls != 4)//虚拟件不计算
|
|
|
+ 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仓储信息
|
|
|
+ continue;
|
|
|
}
|
|
|
+ //非虚拟件
|
|
|
+ //当前物料的库存数量
|
|
|
+ decimal stockQty = stocklist.Where(s => s.icitem_id == item.item_id).Sum(p => p.sqty.GetValueOrDefault());
|
|
|
+ //获取当前订单其他订单行当前物料的占用数量
|
|
|
+ decimal otherStockQty = occupylist.Where(s => s.icitem_id == item.item_id).Sum(p => p.quantity);
|
|
|
+ //当前订单行物料库存情况
|
|
|
+ item.sqty = stockQty - otherStockQty;
|
|
|
}
|
|
|
}
|
|
|
}
|