ResourceExamineAppService.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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<mes_tech_process> _mes_tech_process;
  42. /// <summary>
  43. /// 工作日历
  44. /// </summary>
  45. private readonly IMongoDB<mes_work_calendar> _mes_work_calendar;
  46. /// <summary>
  47. /// 工作日历明细
  48. /// </summary>
  49. private readonly IMongoDB<mes_work_calendar_list> _mes_work_calendar_list;
  50. /// <summary>
  51. /// 工艺工序关联工位
  52. /// </summary>
  53. private readonly IMongoDB<mes_tech_proc_workshop> _mes_tech_proc_workshop;
  54. /// <summary>
  55. /// 排程占用记录
  56. /// </summary>
  57. private readonly IMongoDB<mes_schedule_occupy> _mes_schedule_occupy;
  58. /// <summary>
  59. /// 物料详情
  60. /// </summary>
  61. private readonly IMongoDB<ic_item> _ic_item;
  62. /// <summary>
  63. /// 物料BOM
  64. /// </summary>
  65. private readonly IMongoDB<ic_bom> _ic_bom;
  66. /// <summary>
  67. /// 物料BOM明细
  68. /// </summary>
  69. private readonly IMongoDB<ic_bom_child> _ic_bom_child;
  70. #endregion
  71. /// <summary>
  72. /// 构造函数
  73. /// </summary>
  74. /// <param name="icitem"></param>
  75. /// <param name="icbom"></param>
  76. public ResourceExamineAppService(
  77. IMongoDB<mes_technique> mes_technique,
  78. IMongoDB<ic_item> ic_item,
  79. IMongoDB<ic_bom> ic_bom,
  80. IMongoDB<ic_bom_child> ic_bom_child
  81. )
  82. {
  83. _mes_technique = mes_technique;
  84. _ic_item = ic_item;
  85. _ic_bom = ic_bom;
  86. _ic_bom_child = ic_bom_child;
  87. }
  88. /// <summary>
  89. /// 资源检查
  90. /// </summary>
  91. /// <param name="input"></param>
  92. /// <returns></returns>
  93. /// <exception cref="NotImplementedException"></exception>
  94. public async Task<PschedDto> ReceiveResult(SeorderentryDto input)
  95. {
  96. ////多条插入
  97. //List<mes_technique> infos = new List<mes_technique>();
  98. //mes_technique info;
  99. //for (int i = 0; i < 3; i++)
  100. //{
  101. // info = new mes_technique();
  102. // info.GenerateNewId();
  103. // info.tech_name = "多条"+i;
  104. // info.level = i;
  105. // infos.Add(info);
  106. //}
  107. //await _mes_technique.InsertMany(infos);
  108. ////获取数据
  109. //var info1 = await _mes_technique.GetOneByID((long)1732029975067480064);
  110. ////更新数据
  111. //info1.tech_name = "更新777";
  112. //await _mes_technique.UpdateOne(info1, info1.Id);
  113. throw new NotImplementedException();
  114. }
  115. /// <summary>
  116. /// 产能计算
  117. /// </summary>
  118. /// <param name="BomId">Bom主键</param>
  119. /// <param name="Quantity">需要数量</param>
  120. public async Task ProductiveExamine(long? BomId, int Quantity)
  121. {
  122. }
  123. /// <summary>
  124. /// 检查在制工单
  125. /// </summary>
  126. /// <param name="bomNumber">Bom编码</param>
  127. /// <param name="Quantity">需要数量</param>
  128. /// <returns></returns>
  129. public async Task CheckMorder(string bomNumber, int Quantity)
  130. {
  131. if (string.IsNullOrEmpty(bomNumber) || Quantity < 0)
  132. {
  133. //TODO:入参异常;
  134. //throw new NotImplementedException();
  135. }
  136. //查询生产工单类型为计划工单并且工单类型为备库工单 并且BOM编码一致数据
  137. // 订单状态为 初始或下达工单
  138. // List =>数量满足Quantity && 生成工单结束日期最早
  139. }
  140. public async Task BomPretreatmentAsync(long? orderid, long? BomId, int Quantity)
  141. {
  142. if (orderid == null)
  143. {
  144. //throw new bu
  145. }
  146. if (BomId == null)
  147. {
  148. //throw new bu
  149. }
  150. //var query = (await _ic_bom.GetQueryableAsync()).WhereIf(true, a => a.bom_id == BomId).ToList();
  151. //var help = new SnowFlake();
  152. //var id = help.NextId();
  153. var level = 0;
  154. var bomlist = _ic_bom.GetAll();
  155. var bomchildlist = _ic_bom_child.GetAll();
  156. var icitemlist = _ic_item.GetAll();
  157. //GetBomListAsync();
  158. }
  159. 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)
  160. {
  161. int level = le++;//初始化定义level层级
  162. var help = new SnowFlake();
  163. var bom = bomlist.WhereIf(true, s => s.bom_id == bomId).FirstOrDefault();
  164. if (bom == null)
  165. {
  166. }
  167. var dto = new BomChildExamineDto();
  168. dto.level = level;
  169. dto.bom_id = bomId;
  170. dto.id = help.NextId();
  171. dto.parent_id = parent_id;
  172. dto.item_id = bom.icitem_id;
  173. dto.item_name = bom.item_name;
  174. dto.item_code = bom.item_number;
  175. //var bdto = ObjectMapper.Map<ic_bom,BomChildExamineDto>(bom);
  176. returnlist.Add(dto);
  177. var childlist = bomchildlist.WhereIf(true, a => a.bom_id == bom.bom_id).ToList();
  178. foreach (var c in childlist)
  179. {
  180. var icitem = icitemlist.WhereIf(true, a => a.icitem_id == c.icitem_id).FirstOrDefault();
  181. //如果此明细查的到BOM信息,则代表此child是一个子BOM。
  182. if (c.is_bom == 1)
  183. {
  184. var childBom = bomlist.WhereIf(true, a => a.icitem_id == c.icitem_id).FirstOrDefault();
  185. if (childBom != null)
  186. {
  187. GetBomList(bomlist, bomchildlist, icitemlist, childBom.bom_id, returnlist, dto.id, level);
  188. }
  189. }
  190. else
  191. {
  192. if (icitem != null)
  193. {
  194. var childDto = new BomChildExamineDto();
  195. childDto.level = level++;
  196. childDto.bom_id = bomId;
  197. childDto.id = help.NextId();
  198. childDto.parent_id = parent_id;
  199. childDto.item_id = icitem.icitem_id;
  200. childDto.item_name = icitem.name;
  201. childDto.item_code = icitem.number;
  202. returnlist.Add(childDto);
  203. }
  204. }
  205. }
  206. }
  207. }
  208. }