ResourceExamineAppService.cs 8.5 KB

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