ResourceExamineAppService.cs 6.6 KB

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