ResourceExamineAppService.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. using Microsoft.EntityFrameworkCore;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Linq.Dynamic.Core;
  6. using System.Threading.Tasks;
  7. using Volo.Abp.Application.Dtos;
  8. using Volo.Abp.Domain.Repositories;
  9. using Business.Models;
  10. using Microsoft.AspNetCore.Authorization;
  11. using Business.Permissions;
  12. using XCZ;
  13. using Business.ResourceExamineManagement.Dto;
  14. using Bussiness.Model.MES.IC;
  15. using AutoMapper.Internal.Mappers;
  16. using Bussiness.Model.Tech;
  17. using Bussiness.Model.Production;
  18. using Business.Core.MongoDBHelper;
  19. using Business.Core.Utilities;
  20. using Hangfire.Storage.Monitoring;
  21. using Business.BookManagement.Dto;
  22. using Volo.Abp.ObjectMapping;
  23. using Volo.Abp.Application.Services;
  24. using ZstdSharp.Unsafe;
  25. using System.Transactions;
  26. using NUglify.JavaScript.Syntax;
  27. using System.Linq.Expressions;
  28. using XCZ.Extensions;
  29. using System.ComponentModel.Design;
  30. using Volo.Abp.Validation.StringValues;
  31. using System.Runtime.CompilerServices;
  32. using MongoDB.Driver;
  33. namespace Business.ResourceExamineManagement
  34. {
  35. /// <summary>
  36. /// 资源检查
  37. /// </summary>
  38. //[Authorize(BusinessPermissions.ResourceExamine.Default)]
  39. public class ResourceExamineAppService : ApplicationService, IResourceExamineAppService
  40. {
  41. #region 服务
  42. /// <summary>
  43. /// 工艺路径
  44. /// </summary>
  45. private readonly IMongoDB<mes_technique> _mes_technique;
  46. /// <summary>
  47. /// 工序
  48. /// </summary>
  49. private readonly IMongoDB<mes_process> _mes_process;
  50. /// <summary>
  51. /// 工艺关联工序
  52. /// </summary>
  53. private readonly IMongoDB<mes_tech_process> _mes_tech_process;
  54. /// <summary>
  55. /// 工作日历
  56. /// </summary>
  57. private readonly IMongoDB<mes_work_calendar> _mes_work_calendar;
  58. /// <summary>
  59. /// 工作日历明细
  60. /// </summary>
  61. private readonly IMongoDB<mes_work_calendar_list> _mes_work_calendar_list;
  62. /// <summary>
  63. /// 工艺工序关联工位
  64. /// </summary>
  65. private readonly IMongoDB<mes_tech_proc_workshop> _mes_tech_proc_workshop;
  66. /// <summary>
  67. /// 排程占用记录
  68. /// </summary>
  69. private readonly IMongoDB<mes_schedule_occupy> _mes_schedule_occupy;
  70. /// <summary>
  71. /// 物料详情
  72. /// </summary>
  73. private readonly IMongoDB<ic_item> _ic_item;
  74. private IBasicRepository<ic_item, long> _mysql_ic_item;
  75. /// <summary>
  76. /// 物料BOM
  77. /// </summary>
  78. private readonly IMongoDB<ic_bom> _ic_bom;
  79. private IBasicRepository<ic_bom, long> _mysql_ic_bom;
  80. /// <summary>
  81. /// 物料BOM明细
  82. /// </summary>
  83. private readonly IMongoDB<ic_bom_child> _ic_bom_child;
  84. private IBasicRepository<ic_bom_child, long> _mysql_ic_bom_child;
  85. /// <summary>
  86. /// 物料库存表
  87. /// </summary>
  88. private readonly IMongoDB<ic_item_stock> _ic_item_stock;
  89. /// <summary>
  90. /// 生产工单主表
  91. /// </summary>
  92. private readonly IMongoDB<mes_morder> _mes_morder;
  93. /// <summary>
  94. /// 在制工单占用记录表
  95. /// </summary>
  96. private readonly IMongoDB<mes_mooccupy> _mes_mooccupy;
  97. #endregion
  98. /// <summary>
  99. /// 构造函数
  100. /// </summary>
  101. /// <param name="icitem"></param>
  102. /// <param name="icbom"></param>
  103. public ResourceExamineAppService(
  104. IMongoDB<mes_technique> mes_technique,
  105. IMongoDB<mes_process> mes_process,
  106. IMongoDB<mes_tech_process> mes_tech_process,
  107. IMongoDB<mes_tech_proc_workshop> mes_tech_proc_workshop,
  108. IMongoDB<ic_item> ic_item,
  109. IMongoDB<ic_bom> ic_bom,
  110. IMongoDB<ic_bom_child> ic_bom_child,
  111. IMongoDB<ic_item_stock> ic_item_stock,
  112. IMongoDB<mes_morder> mes_morder,
  113. IMongoDB<mes_mooccupy> mes_mooccupy,
  114. IBasicRepository<ic_item, long> mysql_ic_item,
  115. IBasicRepository<ic_bom, long> mysql_ic_bom,
  116. IBasicRepository<ic_bom_child, long> mysql_ic_bom_child
  117. )
  118. {
  119. _mes_technique = mes_technique;
  120. _mes_process = mes_process;
  121. _mes_tech_process = mes_tech_process;
  122. _mes_tech_proc_workshop = mes_tech_proc_workshop;
  123. _ic_item = ic_item;
  124. _ic_bom = ic_bom;
  125. _ic_bom_child = ic_bom_child;
  126. _ic_item_stock = ic_item_stock;
  127. _mes_morder = mes_morder;
  128. _mysql_ic_item = mysql_ic_item;
  129. _mysql_ic_bom = mysql_ic_bom;
  130. _mysql_ic_bom_child = mysql_ic_bom_child;
  131. }
  132. /// <summary>
  133. /// mongoDB示例方法,后期删除
  134. /// </summary>
  135. /// <returns></returns>
  136. public async Task test()
  137. {
  138. //多条插入
  139. List<mes_technique> infos = new List<mes_technique>();
  140. mes_technique info;
  141. for (int i = 0; i < 3; i++)
  142. {
  143. info = new mes_technique();
  144. info.GenerateNewId();
  145. info.tech_name = "多条" + i;
  146. info.level = i;
  147. infos.Add(info);
  148. }
  149. await _mes_technique.InsertMany(infos);
  150. var info2 = _mes_technique.GetAll().Result;
  151. var a = new PschedDto();
  152. a.count = info2.Count;
  153. //获取数据
  154. var info1 = await _mes_technique.GetOneByID((long)1732029975067480064);
  155. //更新数据
  156. info1.tech_name = "更新***";
  157. var rlt = await _mes_technique.UpdateOne(info1, info1.Id);
  158. //根据条件查询数据
  159. Expression<Func<mes_technique, bool>> filter = x => x.Id == (long)1732376973889097728 && x.tech_name == "多条0";
  160. var info3 = await _mes_technique.GetManyByCondition(filter);
  161. }
  162. /// <summary>
  163. /// 资源检查
  164. /// </summary>
  165. /// <param name="input"></param>
  166. /// <returns></returns>
  167. /// <exception cref="NotImplementedException"></exception>
  168. public async Task<PschedDto> ReceiveResult(SeorderentryDto input)
  169. {
  170. //测试代码
  171. //await test();
  172. await ProductiveExamine(1733221167209762816,100,1000);
  173. return null;
  174. throw new NotImplementedException();
  175. }
  176. /// <summary>
  177. /// 产能计算
  178. /// </summary>
  179. /// <param name="tech_id">工艺路径主键</param>
  180. /// <param name="packages">需要生产产品件数</param>
  181. /// <param name="quantity">需要生产数量</param>
  182. public async Task<DateTime> ProductiveExamine(long tech_id, int packages, int quantity)
  183. {
  184. if (packages <=0 ||quantity <= 0)
  185. {
  186. throw new NotImplementedException("产能计算参数有误!");
  187. }
  188. #region 1、数据准备
  189. //1.1、获取工艺路径数据
  190. mes_technique tech = _mes_technique.GetOneByID(tech_id).Result;
  191. //1.2、获取工艺路径关联工序数据
  192. List<mes_tech_process> tech_Processes = _mes_tech_process.GetManyByCondition(x => x.tech_id == tech_id).Result;
  193. //1.3、获取当前工艺路径下的工序数据
  194. FilterDefinition<mes_process> filter = Builders<mes_process>.Filter.In(s => s.Id, tech_Processes.Select(m => m.proc_id).ToList());
  195. List<mes_process> process = _mes_process.GetManyByIds(filter).Result;
  196. //1.3、获取工艺工序关联工位信息
  197. 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());
  198. List<mes_tech_proc_workshop> tech_Proc_Workshops = _mes_tech_proc_workshop.GetManyByIds(filter1).Result;
  199. //1.4、获取工位占用情况
  200. //List<mes_schedule_occupy> schedule_Occupies = _mes_schedule_occupy.GetManyByCondition().Result;
  201. #endregion
  202. #region 计算产能,得到耗时
  203. /*产能计算有两种模式:1-UPH;2-节拍时间
  204. *1、根据工艺路径设置的效率计算层级,来获取参与产能计算的所有工序/子工序
  205. *2、根据当前工序设置的计算模式UPH/节拍时间来计算当前工序生产所需时间T1
  206. *3、当前工序生产所需时间T1*效率系数Rate得到实际的生产所需时间T2(流水线不需要*效率系数)
  207. *4、当前工序实际生产所需时间T2+当前工序前置准备时间得到当前工序生产所需总时间
  208. *5、所有工序生产总时间加起来得到生产所需总时间
  209. */
  210. //1、获取参与计算的所有工序/子工序
  211. var tech_pro_list = tech_Processes.Where(p => p.level == tech.level).ToList();
  212. //生产总时间(分钟)
  213. decimal sumTimes = 0.00m;
  214. //记录按照CT参与计算的工序的父级Id
  215. List<long> exists = new List<long>();
  216. foreach (var item in tech_pro_list)
  217. {
  218. //数据校验
  219. //获取当前工序
  220. var curProcess = process.FirstOrDefault(p => p.Id == item.proc_id);
  221. if (item.type == 1 && item.ct == 0)
  222. {
  223. throw new NotImplementedException(string.Format("工艺[{0}]下的工序[{1}]节拍时间设置有误,请调整!",tech.tech_name, curProcess.proc_name));
  224. }
  225. if (item.type == 2 && item.uph == 0)
  226. {
  227. throw new NotImplementedException(string.Format("工艺[{0}]下的工序[{1}]UPH设置有误,请调整!", tech.tech_name, curProcess.proc_name));
  228. }
  229. if (item.parentprocid != null)//存在父子级关系
  230. {
  231. //判断当前父级是否已经参与过计算
  232. if (exists.Contains(item.parentprocid.Value))
  233. {
  234. continue;
  235. }
  236. //记录父级id
  237. exists.Add(item.parentprocid.Value);
  238. //获取同一父级下的子工序
  239. var childs = tech_Processes.Where(p => p.parentprocid == item.parentprocid).ToList();
  240. decimal maxTime = 0.00m;//记录同一父级下最大耗时
  241. decimal time = 0.00m;
  242. //2、两种计算模式UPH/节拍时间
  243. if (item.type == 2)//UPH(每小时生产个数),取同一父级下最长耗时
  244. {
  245. foreach (var chd in childs)
  246. {
  247. //当前工序消耗时间
  248. time = quantity / item.uph.Value * 60 * item.effect_ratio.Value;
  249. if (time > maxTime)
  250. {
  251. maxTime = time;
  252. }
  253. }
  254. sumTimes += maxTime;
  255. continue;
  256. }
  257. //3、根据节拍时间计算
  258. //sum(CT)
  259. decimal sumCT = childs.Sum(p => p.ct.Value);
  260. //max(CT)
  261. decimal maxCT = childs.OrderByDescending(p => p.ct).FirstOrDefault().ct.Value;
  262. //sum(LT)
  263. decimal sumLT = childs.Sum(p => p.readytime.Value);
  264. //当前流水线消耗时间
  265. sumTimes += (packages - 1) * maxCT + sumCT + sumLT;
  266. }
  267. else{//不存在父子级关系
  268. //2、两种计算模式UPH/节拍时间
  269. if (item.type == 2)//uph
  270. {
  271. //当前工序消耗时间
  272. sumTimes += quantity / item.uph.Value * 60 * item.effect_ratio.Value + item.readytime.Value;
  273. //计算完成,进行下一次循环
  274. continue;
  275. }
  276. //节拍时间:流水线,从流水线最后工序开始计算
  277. if (item.nextprocid != null)
  278. {
  279. //下-工序Id不为null,说明不是流水线最终工序,进行下一次循环
  280. continue;
  281. }
  282. List<mes_tech_process> allProcess = new List<mes_tech_process>();
  283. //递归,获取最终工序的上一工序
  284. GetPreProcess(tech_Processes, item, allProcess);
  285. //sum(CT)
  286. decimal sumCT = allProcess.Sum(p => p.ct.Value);
  287. //max(CT)
  288. decimal maxCT = allProcess.OrderByDescending(p => p.ct).FirstOrDefault().ct.Value;
  289. //sum(LT)
  290. decimal sumLT = allProcess.Sum(p => p.readytime.Value);
  291. //当前流水线消耗时间
  292. sumTimes += (packages - 1) * maxCT + sumCT + sumLT;
  293. }
  294. }
  295. #endregion
  296. return DateTime.Now.AddDays(1).AddMinutes((double)sumTimes);
  297. }
  298. /// <summary>
  299. /// 递归获取工序
  300. /// </summary>
  301. /// <param name="tech_Processes"></param>
  302. /// <param name="item"></param>
  303. /// <returns></returns>
  304. private void GetPreProcess(List<mes_tech_process> tech_Processes, mes_tech_process item, List<mes_tech_process> allProcess)
  305. {
  306. allProcess.Add(item);
  307. //获取上一工序
  308. var preProc = tech_Processes.FirstOrDefault(p => p.nextprocid == item.proc_id);
  309. if (preProc != null) {
  310. GetPreProcess(tech_Processes, preProc, allProcess);
  311. }
  312. }
  313. /// <summary>
  314. /// 检查在制工单
  315. /// </summary>
  316. /// <param name="bomNumber">Bom编码</param>
  317. /// <param name="Quantity">需要数量</param>
  318. /// <param name="EndDate">交付日期</param>
  319. /// <returns></returns>
  320. public async Task<List<mes_morder>> CheckMorder(string bomNumber, decimal? Quantity, DateTime DeliverDate)
  321. {
  322. if (string.IsNullOrEmpty(bomNumber) || Quantity != null)
  323. {
  324. //TODO:入参异常;
  325. throw new NotImplementedException("BOM编码或需求数量不能为空!");
  326. }
  327. //根据Bom编码查询出对应工单并且状态不为完成、关闭,非委外工单。
  328. //TODO:工单类型;
  329. Expression<Func<mes_morder, bool>> filter = x => x.bom_number == bomNumber && (x.morder_state != "完成" || x.morder_state != "关闭"
  330. && x.morder_icitem_type != "相关委外工单") && x.IsDeleted == false;
  331. var morderList = await _mes_morder.GetManyByCondition(filter);
  332. //首先满足需求数量工单其次判断是否满足交付日期、当数量不满足时继续查找最早交付日期订单 工单数量累加。
  333. //工单已被占用后要与占用表关联查询...减去占用量后 剩下生产数量可供下个销售工单使用。
  334. Expression<Func<mes_mooccupy, bool>> mooccupyfilter = x => x.moo_state == 1 && x.IsDeleted == false;
  335. var mes_mooccupyList = await _mes_mooccupy.GetManyByCondition(mooccupyfilter);
  336. //morderList = morderList.Where(x => x.Id.IsIn(mes_mooccupyList.Select(p => p.moo_moid))).ToList();
  337. //当前工单计划日期-1天 小于交付日期 && 计算生产数量-入库数据并且大于需求产品数量。
  338. var morderDataList = morderList.Where(x => x.planner_end_date.Value.AddDays(-1) < DeliverDate &&
  339. (x.morder_production_number - x.inventory_number) > Quantity).ToList();
  340. if (morderDataList.Count > 0)
  341. {
  342. //存在此数据满足当前BOM交付找到最早日期工单,则返回无需后续继续检查。
  343. var morder = morderDataList.OrderByDescending(x => x.planner_end_date).FirstOrDefault();
  344. //生成mes_mooccupy工单占用表数据,代表此工单被某个销售订单已占用。
  345. mes_mooccupy mes_Mooccupy = new mes_mooccupy();
  346. mes_Mooccupy.GenerateNewId();
  347. mes_Mooccupy.moo_id_type = "分配";
  348. mes_Mooccupy.moo_id_billid = 0;//销售订单ID
  349. mes_Mooccupy.fbill_no = "0";//销售订单号
  350. mes_Mooccupy.fentry_id = 0;//销售订单行
  351. mes_Mooccupy.fitem_name = string.Empty;//物料名称
  352. mes_Mooccupy.fitem_number = bomNumber;
  353. mes_Mooccupy.fmodel = string.Empty;//规格型号
  354. mes_Mooccupy.moo_moid = morder.Id;
  355. mes_Mooccupy.moo_mo = morder.morder_no;
  356. mes_Mooccupy.moo_qty = Quantity;
  357. mes_Mooccupy.moo_stime = DateTime.Now;
  358. mes_Mooccupy.moo_etime = DateTime.Now;//日期来源需确定
  359. mes_Mooccupy.moo_state = 1;
  360. mes_Mooccupy.moo_cbr = string.Empty;
  361. //mes_Mooccupy.moo_ctime = ;
  362. mes_Mooccupy.moo_creason = string.Empty;
  363. mes_Mooccupy.tenant_id = 0;
  364. await _mes_mooccupy.InsertOne(mes_Mooccupy);
  365. }
  366. else
  367. {
  368. // 寻找最早日期工单 && 计算生产数量-入库数据并且大于需求产品数量后累加直到满足需求产品数量
  369. var morderListData = morderList.Where(x => x.planner_end_date.Value.AddDays(-1) < DeliverDate).OrderByDescending(x => x.planner_end_date).ToList();
  370. if (morderListData.Count == 0)
  371. {
  372. //TODO:后期处理无在制工单返回内容
  373. throw new NotImplementedException("无可用在制工单!");
  374. }
  375. List<mes_morder> mes_Morders = new List<mes_morder>();
  376. List<mes_mooccupy> mes_Mooccupies = new List<mes_mooccupy>();
  377. decimal? number = Quantity;
  378. foreach (var item in morderListData)
  379. {
  380. //查询出工单已占用总数量
  381. var mes_mooccupy = mes_mooccupyList.Where(x => x.moo_moid == item.Id).ToList();
  382. // 需要数量-(生产计划数量-入库数量-已被占用数量)
  383. number = number - (item.morder_production_number - item.inventory_number - mes_mooccupy.Sum(x => x.moo_qty));
  384. if (number <= 0)
  385. {
  386. mes_Morders.Add(item);
  387. }
  388. else
  389. {
  390. mes_Morders.Add(item);
  391. break;
  392. }
  393. }
  394. //生成mes_mooccupy工单占用表数据,代表多个工单被某个销售订单已占用。
  395. }
  396. return morderList;
  397. #region 注释
  398. /* var morderList = _mes_morder.GetAll().Result;
  399. //查询生产工单类型为计划工单并且工单类型为备库工单 并且BOM编码一致数据,订单状态为 初始或下达工单
  400. var morderTypeList = morderList.Where(x => x.work_order_type == "备库工单" && x.morder_type == "计划工单" &&
  401. x.bom_number == bomNumber && (x.morder_state == "初始" || x.morder_state == "下达")).ToList();
  402. //计划数量-需求数量=剩余可用数量 -->使用计划结束时间排序取第一条满足条件工单
  403. // List =>数量满足Quantity && 生成工单结束日期最早
  404. var SatisfyQuantityList = morderTypeList.Where(x => (x.morder_production_number.Value - x.need_number.Value) >= Quantity).
  405. ToList().OrderBy(x => x.moentry_etime).FirstOrDefault();
  406. if (SatisfyQuantityList == null)
  407. {
  408. }
  409. else
  410. {
  411. }*/
  412. #endregion
  413. }
  414. public void BomPretreatment(long? orderid, long? BomId, int Quantity)
  415. {
  416. if (orderid == null)
  417. {
  418. //throw new bu
  419. }
  420. if (BomId == null)
  421. {
  422. //throw new bu
  423. }
  424. //var query = (await _ic_bom.GetQueryableAsync()).WhereIf(true, a => a.bom_id == BomId).ToList();
  425. var help = new SnowFlake();
  426. var bomlist = _ic_bom.GetAll().Result;
  427. var bomchildlist = _ic_bom_child.GetAll().Result;
  428. var icitemlist = _ic_item.GetAll().Result;
  429. List<BomChildExamineDto> returnlist = new List<BomChildExamineDto>();
  430. var dto = new BomChildExamineDto();
  431. dto.bom_id = BomId.Value;
  432. dto.level = 1;
  433. dto.id = help.NextId();
  434. dto.parent_id = help.NextId();
  435. dto.qty = 1;
  436. dto.num = "1";
  437. dto.isbom = 1;
  438. dto.is_replace = 0;
  439. dto.haveicsubs = 0;
  440. dto.substitute_code = "";
  441. dto.icitem_ids = "";
  442. GetBomList(bomlist, bomchildlist, icitemlist, dto, returnlist);
  443. }
  444. public void GetBomList(List<ic_bom> bomlist, List<ic_bom_child> bomchildlist, List<ic_item> icitemlist, BomChildExamineDto dto, List<BomChildExamineDto> returnlist)
  445. {
  446. int level = dto.level++;//初始化定义level层级
  447. var help = new SnowFlake();
  448. var bom = bomlist.WhereIf(true, s => s.Id == dto.bom_id).FirstOrDefault();
  449. var item = icitemlist.WhereIf(true, a => a.Id == bom.icitem_id).FirstOrDefault();
  450. if (bom == null || item == null)
  451. {
  452. }
  453. //var dto = new BomChildExamineDto();
  454. //dto.level = level;
  455. //dto.bom_id = bomId;
  456. //dto.id = help.NextId();
  457. //dto.parent_id = parent_id;
  458. dto.item_id = bom.icitem_id;
  459. dto.item_name = bom.item_name;
  460. dto.item_code = bom.item_number;
  461. dto.model = item.model;
  462. dto.unit = bom.unit;
  463. dto.erp_cls = item.erp_cls;
  464. dto.erp_cls_name = item.erp_cls_name;
  465. //var bdto = ObjectMapper.Map<ic_bom,BomChildExamineDto>(bom);
  466. returnlist.Add(dto);
  467. var childlist = bomchildlist.WhereIf(true, a => a.bom_id == bom.Id).ToList();
  468. int idx = 1;
  469. foreach (var c in childlist)
  470. {
  471. string childNum = dto.num + "." + idx.ToString();
  472. var icitem = icitemlist.WhereIf(true, a => a.Id == c.icitem_id).FirstOrDefault();
  473. //如果此明细查的到BOM信息,则代表此child是一个子BOM。
  474. if (c.is_bom == 1)
  475. {
  476. var childBom = bomlist.WhereIf(true, a => a.icitem_id == c.icitem_id).FirstOrDefault();
  477. if (childBom != null)
  478. {
  479. var cdto = new BomChildExamineDto();
  480. cdto.id = help.NextId();
  481. cdto.level = level;
  482. cdto.parent_id = dto.id;
  483. cdto.qty = c.qty.Value;
  484. cdto.backflush = c.backflush;
  485. cdto.num = childNum;
  486. cdto.isbom = 1;
  487. cdto.is_replace = c.is_replace;
  488. cdto.haveicsubs = c.haveicsubs;
  489. cdto.substitute_code = c.substitute_code;
  490. cdto.icitem_ids = c.icitem_ids;
  491. GetBomList(bomlist, bomchildlist, icitemlist, cdto, returnlist);
  492. }
  493. }
  494. else
  495. {
  496. if (icitem != null)
  497. {
  498. var childDto = new BomChildExamineDto();
  499. childDto.level = level++;
  500. childDto.bom_id = dto.bom_id;
  501. childDto.id = help.NextId();
  502. childDto.parent_id = dto.id;
  503. childDto.item_id = icitem.Id;
  504. childDto.item_name = icitem.name;
  505. childDto.item_code = icitem.number;
  506. childDto.num = childNum;
  507. childDto.model = icitem.model;
  508. childDto.unit = c.unit;
  509. childDto.erp_cls = item.erp_cls;
  510. childDto.erp_cls_name = item.erp_cls_name;
  511. childDto.backflush = c.backflush;
  512. childDto.qty = c.qty.Value;
  513. childDto.isbom = 0;
  514. childDto.is_replace = c.is_replace;
  515. childDto.haveicsubs = c.haveicsubs;
  516. childDto.substitute_code = c.substitute_code;
  517. childDto.icitem_ids = c.icitem_ids;
  518. returnlist.Add(childDto);
  519. }
  520. }
  521. idx++;
  522. }
  523. }
  524. /// <summary>
  525. /// 计算库存量
  526. /// </summary>
  527. /// <param name="returnlist"></param>
  528. public void BomStock(List<BomChildExamineDto> returnlist)
  529. {
  530. returnlist = returnlist.OrderBy(s => s.num).ToList();
  531. List<long> idlist = new List<long>();
  532. foreach (var item in returnlist)
  533. {
  534. }
  535. }
  536. }
  537. }