|
|
@@ -62,6 +62,8 @@ namespace Business.ResourceExamineManagement
|
|
|
public class ResourceExamineAppService : ApplicationService, IResourceExamineAppService
|
|
|
{
|
|
|
#region 服务
|
|
|
+ SnowFlake help = new SnowFlake();
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 工艺路径
|
|
|
/// </summary>
|
|
|
@@ -469,14 +471,13 @@ namespace Business.ResourceExamineManagement
|
|
|
dtl.earliest_times = DateTime.Now.Date.AddDays(3);
|
|
|
|
|
|
//bom层级组装
|
|
|
- var getBomList = BomPretreatment(o.Id, 160162, o.qty.GetInt(), bomlist, bomchildlist, icitemlist);
|
|
|
+ var getBomList = BomPretreatment(o.Id, childBom.Id, o.qty.GetInt(), bomlist, bomchildlist, icitemlist);
|
|
|
//bom替代关系组装
|
|
|
BomSubstitute(getBomList, bomlist, bomchildlist, icitemlist);
|
|
|
//库存初始化
|
|
|
BomStock(getBomList, bangid, input.factoryId);
|
|
|
//计算
|
|
|
calcTest(getBomList, bangid, o.Id, o.qty.Value, input, o.plan_date);
|
|
|
-
|
|
|
//TODO:最晚开始时间
|
|
|
var curFacDtl = leadTimes.FirstOrDefault(p => p.item_id == childBom.icitem_id);
|
|
|
//最晚开工时间=订单行客户要求交期-运输提前期-库存提前期-生产提前期-下单提前期
|
|
|
@@ -1051,7 +1052,7 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
List<BomChildExamineDto> returnlist = new List<BomChildExamineDto>();
|
|
|
//var query = (await _ic_bom.GetQueryableAsync()).WhereIf(true, a => a.bom_id == BomId).ToList();
|
|
|
- var help = new SnowFlake();
|
|
|
+
|
|
|
var bom = bomlist.Find(s => s.Id == BomId);
|
|
|
if (bom == null)
|
|
|
{
|
|
|
@@ -1062,8 +1063,8 @@ namespace Business.ResourceExamineManagement
|
|
|
dto.item_id = bom.icitem_id;
|
|
|
dto.bom_id = BomId.Value;
|
|
|
dto.level = 1;
|
|
|
- dto.id = Guid.NewGuid();
|
|
|
- dto.parent_id = Guid.NewGuid();
|
|
|
+ dto.id = help.NextId();
|
|
|
+ dto.parent_id = help.NextId();
|
|
|
dto.qty = 1;
|
|
|
dto.num = "1";
|
|
|
dto.isbom = 1;
|
|
|
@@ -1087,7 +1088,6 @@ namespace Business.ResourceExamineManagement
|
|
|
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 + 1;//初始化定义level层级
|
|
|
- var help = new SnowFlake();
|
|
|
|
|
|
var bom = bomlist.Where(s => s.Id == dto.bom_id).FirstOrDefault();
|
|
|
ic_item item = new ic_item();
|
|
|
@@ -1126,7 +1126,7 @@ namespace Business.ResourceExamineManagement
|
|
|
if (childBom != null)
|
|
|
{
|
|
|
var cdto = new BomChildExamineDto();
|
|
|
- cdto.id = Guid.NewGuid();
|
|
|
+ cdto.id = help.NextId();
|
|
|
cdto.level = level;
|
|
|
cdto.parent_id = dto.id;
|
|
|
cdto.bom_child_id = c.Id;
|
|
|
@@ -1149,10 +1149,10 @@ namespace Business.ResourceExamineManagement
|
|
|
if (icitem != null)
|
|
|
{
|
|
|
var childDto = new BomChildExamineDto();
|
|
|
- childDto.level = level++;
|
|
|
+ childDto.level = level;
|
|
|
childDto.bom_id = dto.bom_id;
|
|
|
childDto.bom_child_id = c.Id;
|
|
|
- childDto.id = Guid.NewGuid();
|
|
|
+ childDto.id = help.NextId();
|
|
|
childDto.parent_id = dto.id;
|
|
|
childDto.item_id = icitem.Id;
|
|
|
childDto.item_name = icitem.name;
|
|
|
@@ -1194,7 +1194,6 @@ namespace Business.ResourceExamineManagement
|
|
|
var subdtllist = _ic_substitute_all_dtl.GetManyByCondition(p => suballidlist.Contains(p.substitute_allid) && p.IsDeleted == false).Result;
|
|
|
|
|
|
List<long> childidList = new List<long>();
|
|
|
- var help = new SnowFlake();
|
|
|
int type = 1;
|
|
|
List<BomChildExamineDto> addlist = new List<BomChildExamineDto>();
|
|
|
|
|
|
@@ -1267,7 +1266,6 @@ namespace Business.ResourceExamineManagement
|
|
|
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对应的icitem是BOM,还需要向下继续展开。
|
|
|
- var help = new SnowFlake();
|
|
|
|
|
|
//List<BomChildExamineDto> returnlist = new List<BomChildExamineDto>();
|
|
|
var dto = new BomChildExamineDto();
|
|
|
@@ -1277,7 +1275,7 @@ namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
- dto.id = Guid.NewGuid();
|
|
|
+ dto.id = help.NextId();
|
|
|
dto.level = toDto.level;
|
|
|
dto.parent_id = toDto.parent_id;
|
|
|
dto.item_id = icitem.Id;
|
|
|
@@ -1350,7 +1348,15 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //计算库存
|
|
|
+ /// <summary>
|
|
|
+ /// 替代关系计算
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="returnlist"></param>
|
|
|
+ /// <param name="bangid"></param>
|
|
|
+ /// <param name="orderid"></param>
|
|
|
+ /// <param name="count"></param>
|
|
|
+ /// <param name="input"></param>
|
|
|
+ /// <param name="plan_date"></param>
|
|
|
public void calcTest(List<BomChildExamineDto> returnlist, long bangid, long orderid, decimal count, SeorderentryDto input, DateTime
|
|
|
? plan_date)
|
|
|
{
|
|
|
@@ -1400,18 +1406,19 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ //直接占用库存,缺料就生成采购
|
|
|
+ ic_item_stockoccupy itemStockoccupyDto = new ic_item_stockoccupy();
|
|
|
+ itemStockoccupyDto.bang_id = bangid;
|
|
|
+ itemStockoccupyDto.icitem_id = item.item_id;
|
|
|
+ itemStockoccupyDto.quantity = item.sqty;
|
|
|
+ sklist.Add(itemStockoccupyDto);
|
|
|
+ item.is_use = true;
|
|
|
if (item.erp_cls == 1)
|
|
|
{
|
|
|
//走自制
|
|
|
}
|
|
|
else if (item.erp_cls == 2 || item.erp_cls == 3)
|
|
|
{
|
|
|
- //直接占用库存,缺料就生成采购
|
|
|
- ic_item_stockoccupy itemStockoccupyDto = new ic_item_stockoccupy();
|
|
|
- itemStockoccupyDto.bang_id = bangid;
|
|
|
- itemStockoccupyDto.icitem_id = item.item_id;
|
|
|
- itemStockoccupyDto.quantity = item.sqty;
|
|
|
- sklist.Add(itemStockoccupyDto);
|
|
|
var leadTimeList = GetLeadTime(new List<long> { item.item_id }, input.tenantId, input.factoryId);//提前期列表
|
|
|
var supplierList = GetSupplier(new List<BomChildExamineDto> { item }, input.tenantId, input.factoryId);//供应商列表
|
|
|
var planList = GetICPlan(new List<BomChildExamineDto> { item }, input.tenantId, input.factoryId);//plan列表
|
|
|
@@ -1427,7 +1434,12 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
|
|
|
|
|
|
- //平铺每个物料需要总数
|
|
|
+ /// <summary>
|
|
|
+ /// 平铺计算物料情况
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="returnlist"></param>
|
|
|
+ /// <param name="item"></param>
|
|
|
+ /// <param name="count"></param>
|
|
|
public void CaclMaterialShortage(List<BomChildExamineDto> returnlist, BomChildExamineDto item, decimal count)
|
|
|
{
|
|
|
var parent = returnlist.Find(s => s.id == item.parent_id);
|
|
|
@@ -1450,6 +1462,12 @@ namespace Business.ResourceExamineManagement
|
|
|
}*/
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 根据占用情况重新计算占用
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="item"></param>
|
|
|
+ /// <param name="returnlist"></param>
|
|
|
+ /// <param name="sklist"></param>
|
|
|
public void RecalculationStock(BomChildExamineDto item, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sklist)
|
|
|
{
|
|
|
//再计算一边占用情况,这里根据父级产品额缺料量*当前子料的使用数量-子料库存量。得出当前子物料的缺料数量
|
|
|
@@ -1461,6 +1479,15 @@ namespace Business.ResourceExamineManagement
|
|
|
item.stock_state = item.lack_qty > 0 ? 0 : 1;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 根据替代策略计算
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="item"></param>
|
|
|
+ /// <param name="returnlist"></param>
|
|
|
+ /// <param name="bangid"></param>
|
|
|
+ /// <param name="sklist"></param>
|
|
|
+ /// <param name="input"></param>
|
|
|
+ /// <param name="plan_date"></param>
|
|
|
public void CalcStrategy(BomChildExamineDto item, List<BomChildExamineDto> returnlist, long bangid, List<ic_item_stockoccupy> sklist, SeorderentryDto input, DateTime
|
|
|
? plan_date)
|
|
|
{
|
|
|
@@ -1493,7 +1520,13 @@ namespace Business.ResourceExamineManagement
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- //整批判断
|
|
|
+ /// <summary>
|
|
|
+ /// 整批计算
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sublist"></param>
|
|
|
+ /// <param name="returnlist"></param>
|
|
|
+ /// <param name="sklist"></param>
|
|
|
+ /// <param name="select"></param>
|
|
|
public void WholeBatchCheck(List<BomChildExamineDto> sublist, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sklist, List<BomChildExamineDto> select)
|
|
|
{
|
|
|
for (int idx = 0; idx < 99; idx++)
|
|
|
@@ -1521,7 +1554,18 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //整批占用
|
|
|
+ /// <summary>
|
|
|
+ /// 整批占用
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="item"></param>
|
|
|
+ /// <param name="sublist"></param>
|
|
|
+ /// <param name="returnlist"></param>
|
|
|
+ /// <param name="sklist"></param>
|
|
|
+ /// <param name="select"></param>
|
|
|
+ /// <param name="bangid"></param>
|
|
|
+ /// <param name="parent"></param>
|
|
|
+ /// <param name="input"></param>
|
|
|
+ /// <param name="plan_date"></param>
|
|
|
public void WholeBatch(BomChildExamineDto item, List<BomChildExamineDto> sublist, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sklist, List<BomChildExamineDto> select, long bangid, BomChildExamineDto parent, SeorderentryDto input, DateTime
|
|
|
? plan_date)
|
|
|
{
|
|
|
@@ -1546,6 +1590,7 @@ namespace Business.ResourceExamineManagement
|
|
|
ic_item_stockoccupy itemStockoccupyDto = new ic_item_stockoccupy();
|
|
|
itemStockoccupyDto.bang_id = bangid;
|
|
|
itemStockoccupyDto.icitem_id = slt.item_id;
|
|
|
+ slt.is_use = true;
|
|
|
if (slt.lack_qty > 0)
|
|
|
{
|
|
|
|
|
|
@@ -1588,7 +1633,17 @@ namespace Business.ResourceExamineManagement
|
|
|
|
|
|
}
|
|
|
|
|
|
- //混用占用数据
|
|
|
+ /// <summary>
|
|
|
+ /// 混用占用
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="item"></param>
|
|
|
+ /// <param name="sublist"></param>
|
|
|
+ /// <param name="returnlist"></param>
|
|
|
+ /// <param name="sklist"></param>
|
|
|
+ /// <param name="bangid"></param>
|
|
|
+ /// <param name="parent"></param>
|
|
|
+ /// <param name="input"></param>
|
|
|
+ /// <param name="plan_date"></param>
|
|
|
public void MixedUse(BomChildExamineDto item, List<BomChildExamineDto> sublist, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sklist, long bangid, BomChildExamineDto parent, SeorderentryDto input, DateTime
|
|
|
? plan_date)
|
|
|
{
|
|
|
@@ -1637,10 +1692,12 @@ namespace Business.ResourceExamineManagement
|
|
|
//根据混用逻辑,去占用物料
|
|
|
foreach (var zy in list)
|
|
|
{
|
|
|
+ zy.is_use = true;
|
|
|
ic_item_stockoccupy itemStockoccupyDto = new ic_item_stockoccupy();
|
|
|
itemStockoccupyDto.bang_id = bangid;
|
|
|
itemStockoccupyDto.icitem_id = zy.item_id;
|
|
|
itemStockoccupyDto.quantity = use_p_num * zy.qty; ;
|
|
|
+ sklist.Add(itemStockoccupyDto);
|
|
|
}
|
|
|
idx++;
|
|
|
}
|
|
|
@@ -1685,7 +1742,13 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /// <summary>
|
|
|
+ /// 可制占用计算---暂时未用
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="item"></param>
|
|
|
+ /// <param name="returnlist"></param>
|
|
|
+ /// <param name="bangid"></param>
|
|
|
+ /// <param name="kznun"></param>
|
|
|
public void Sockoccupy(BomChildExamineDto item, List<BomChildExamineDto> returnlist, long bangid, decimal kznun)
|
|
|
{
|
|
|
ic_item_stockoccupy itemStockoccupyDto = new ic_item_stockoccupy();
|
|
|
@@ -1720,7 +1783,13 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //计算物料是否缺料
|
|
|
+ /// <summary>
|
|
|
+ /// 计算物料是否缺料
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="parent"></param>
|
|
|
+ /// <param name="bzlist"></param>
|
|
|
+ /// <param name="returnlist"></param>
|
|
|
+ /// <param name="sockoccupyList"></param>
|
|
|
public void calcTest2(BomChildExamineDto parent, List<BomChildExamineDto> bzlist, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sockoccupyList)
|
|
|
{
|
|
|
//从第二级开始循环
|
|
|
@@ -1757,7 +1826,7 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 计算
|
|
|
+ /// 递归计算物料信息
|
|
|
/// </summary>
|
|
|
/// <param name="sublist"></param>
|
|
|
public void MaterialCalc(List<BomChildExamineDto> sublist, List<BomChildExamineDto> returnlist, List<ic_item_stockoccupy> sockoccupyList)
|
|
|
@@ -1827,7 +1896,11 @@ namespace Business.ResourceExamineManagement
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //根据每个物料来实时计算占用情况
|
|
|
+ /// <summary>
|
|
|
+ /// 根据每个物料来实时计算占用情况
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="item"></param>
|
|
|
+ /// <param name="sockoccupyList"></param>
|
|
|
public void Calczykc(BomChildExamineDto item, List<ic_item_stockoccupy> sockoccupyList)
|
|
|
{
|
|
|
//找到当前物料的占用记录
|
|
|
@@ -2019,7 +2092,6 @@ namespace Business.ResourceExamineManagement
|
|
|
/// <returns></returns>
|
|
|
private List<ICItemLeadTimeDto> GetLeadTime(List<long> icItemIds, long tenantId, long factoryid)
|
|
|
{
|
|
|
- //ToDo:企业Id
|
|
|
ProjectionDefinitionBuilder<ic_factory_details> project = new ProjectionDefinitionBuilder<ic_factory_details>();
|
|
|
return _ic_factory_details.Find(p => icItemIds.Contains(p.icitem_id) && p.factory_id == factoryid && p.tenant_id == tenantId && !p.IsDeleted,
|
|
|
project.Include(p => p.icitem_id).Include(p => p.production_leadtime).Include(p => p.stock_leadtime).Include(p => p.transportation_leadtime).Include(p => p.order_leadtime)).Result.
|
|
|
@@ -2029,7 +2101,6 @@ namespace Business.ResourceExamineManagement
|
|
|
//根据物料id获取物料供应商
|
|
|
private List<ic_item_pur> GetSupplier(List<BomChildExamineDto> returnlist, long tenantId, long factoryid)
|
|
|
{
|
|
|
- //ToDo:企业Id
|
|
|
return _ic_item_pur.Find(p => returnlist.Select(x => x.item_id).Contains(p.icitem_id) && p.tenant_id == tenantId && p.factory_id == factoryid && !p.IsDeleted).Result;
|
|
|
}
|
|
|
|
|
|
@@ -2197,7 +2268,11 @@ namespace Business.ResourceExamineManagement
|
|
|
{
|
|
|
var leadTime = iCItemLeadTimes.Find(x => x.item_id == returnlist.item_id);
|
|
|
var supplier = supplierList.Find(x => x.icitem_id == returnlist.item_id);//默认取第一个供应商
|
|
|
- var plan = planList.Find(x => x.icitem_id == returnlist.item_id);//
|
|
|
+ var plan = planList.Find(x => x.icitem_id == returnlist.item_id);
|
|
|
+ if(leadTime==null || supplier==null || plan==null)
|
|
|
+ {
|
|
|
+ throw new NotImplementedException("未找到物料ic_factory_details或ic_item_pur或ic_plan信息!");
|
|
|
+ }
|
|
|
srm_pr_main srm_Pr = new srm_pr_main();
|
|
|
srm_Pr.GenerateNewId();
|
|
|
srm_Pr.pr_billno = getOrderNum("PR");//pr单号
|