ResourceExamineAppService.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. namespace Business.ResourceExamineManagement
  26. {
  27. /// <summary>
  28. /// 资源检查
  29. /// </summary>
  30. //[Authorize(BusinessPermissions.ResourceExamine.Default)]
  31. public class ResourceExamineAppService : ApplicationService, IResourceExamineAppService
  32. {
  33. #region 服务
  34. /// <summary>
  35. /// 工艺路径
  36. /// </summary>
  37. private readonly IMongoDB<mes_technique> _mes_technique;
  38. /// <summary>
  39. /// 物料详情
  40. /// </summary>
  41. private readonly IMongoDB<ic_item> _ic_item;
  42. /// <summary>
  43. /// 物料BOM
  44. /// </summary>
  45. private readonly IMongoDB<ic_bom> _ic_bom;
  46. /// <summary>
  47. /// 物料BOM明细
  48. /// </summary>
  49. private readonly IMongoDB<ic_bom_child> _ic_bom_child;
  50. /// <summary>
  51. /// 生产工单主表
  52. /// </summary>
  53. private readonly IMongoDB<mes_morder> _mes_morder;
  54. #endregion
  55. /// <summary>
  56. /// 构造函数
  57. /// </summary>
  58. /// <param name="icitem"></param>
  59. /// <param name="icbom"></param>
  60. public ResourceExamineAppService(
  61. IMongoDB<mes_technique> mes_technique,
  62. IMongoDB<ic_item> ic_item,
  63. IMongoDB<ic_bom> ic_bom,
  64. IMongoDB<ic_bom_child> ic_bom_child,
  65. IMongoDB<mes_morder> mes_morder
  66. )
  67. {
  68. _mes_technique = mes_technique;
  69. _ic_item = ic_item;
  70. _ic_bom = ic_bom;
  71. _ic_bom_child = ic_bom_child;
  72. _mes_morder = mes_morder;
  73. }
  74. /// <summary>
  75. /// 资源检查
  76. /// </summary>
  77. /// <param name="input"></param>
  78. /// <returns></returns>
  79. /// <exception cref="NotImplementedException"></exception>
  80. public async Task<PschedDto> ReceiveResult(SeorderentryDto input)
  81. {
  82. mes_technique info = new mes_technique() { };
  83. SnowFlake snow = new SnowFlake();
  84. info.Id = snow.NextId();
  85. info.tech_name = "ceshi4444";
  86. info.level = 4;
  87. await _mes_technique.InsertOne(info);
  88. throw new NotImplementedException();
  89. }
  90. /// <summary>
  91. /// 产能计算
  92. /// </summary>
  93. /// <param name="BomId">Bom主键</param>
  94. /// <param name="Quantity">需要数量</param>
  95. public async Task ProductiveExamine(long? BomId, int Quantity)
  96. {
  97. }
  98. /// <summary>
  99. /// 检查在制工单
  100. /// </summary>
  101. /// <param name="bomNumber">Bom编码</param>
  102. /// <param name="Quantity">需要数量</param>
  103. /// <returns></returns>
  104. public async Task CheckMorder(string bomNumber, int Quantity)
  105. {
  106. if (string.IsNullOrEmpty(bomNumber) || Quantity < 0)
  107. {
  108. //TODO:入参异常;
  109. //throw new NotImplementedException();
  110. }
  111. //var morderList = _mes_morder.(a => a.Id == ObjectId.Parse(id)).ToList().FirstOrDefault();
  112. //查询生产工单类型为计划工单并且工单类型为备库工单 并且BOM编码一致数据
  113. // 订单状态为 初始或下达工单
  114. // List =>数量满足Quantity && 生成工单结束日期最早
  115. }
  116. public async Task BomPretreatmentAsync(long? orderid, long? BomId, int Quantity)
  117. {
  118. if (orderid == null)
  119. {
  120. //throw new bu
  121. }
  122. if (BomId == null)
  123. {
  124. //throw new bu
  125. }
  126. //var query = (await _ic_bom.GetQueryableAsync()).WhereIf(true, a => a.bom_id == BomId).ToList();
  127. //var help = new SnowFlake();
  128. //var id = help.NextId();
  129. var level = 0;
  130. var bomlist = _ic_bom.GetAll().Result;
  131. var bomchildlist = _ic_bom_child.GetAll().Result;
  132. var icitemlist = _ic_item.GetAll().Result;
  133. //GetBomListAsync();
  134. }
  135. public void GetBomList(List<ic_bom> bomlist, List<ic_bom_child> bomchildlist, List<ic_item> icitemlist, long bomId, List<BomChildExamineDto> returnlist, long? parent_id, int le)
  136. {
  137. int level = le++;//初始化定义level层级
  138. var help = new SnowFlake();
  139. var bom = bomlist.WhereIf(true, s => s.bom_id == bomId).FirstOrDefault();
  140. if (bom == null)
  141. {
  142. }
  143. var dto = new BomChildExamineDto();
  144. dto.level = level;
  145. dto.bom_id = bomId;
  146. dto.id = help.NextId();
  147. dto.parent_id = parent_id;
  148. dto.item_id = bom.icitem_id;
  149. dto.item_name = bom.item_name;
  150. dto.item_code = bom.item_number;
  151. //var bdto = ObjectMapper.Map<ic_bom,BomChildExamineDto>(bom);
  152. returnlist.Add(dto);
  153. var childlist = bomchildlist.WhereIf(true, a => a.bom_id == bom.bom_id).ToList();
  154. foreach (var c in childlist)
  155. {
  156. var icitem = icitemlist.WhereIf(true, a => a.icitem_id == c.icitem_id).FirstOrDefault();
  157. //如果此明细查的到BOM信息,则代表此child是一个子BOM。
  158. if (c.is_bom == 1)
  159. {
  160. var childBom = bomlist.WhereIf(true, a => a.icitem_id == c.icitem_id).FirstOrDefault();
  161. if (childBom != null)
  162. {
  163. GetBomList(bomlist, bomchildlist, icitemlist, childBom.bom_id, returnlist, dto.id, level);
  164. }
  165. }
  166. else
  167. {
  168. if (icitem != null)
  169. {
  170. var childDto = new BomChildExamineDto();
  171. childDto.level = level++;
  172. childDto.bom_id = bomId;
  173. childDto.id = help.NextId();
  174. childDto.parent_id = parent_id;
  175. childDto.item_id = icitem.icitem_id;
  176. childDto.item_name = icitem.name;
  177. childDto.item_code = icitem.number;
  178. returnlist.Add(childDto);
  179. }
  180. }
  181. }
  182. }
  183. }
  184. }