ResourceExamineAppService.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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<mes_tech_process> _mes_tech_process;
  43. /// <summary>
  44. /// 工作日历
  45. /// </summary>
  46. private readonly IMongoDB<mes_work_calendar> _mes_work_calendar;
  47. /// <summary>
  48. /// 工作日历明细
  49. /// </summary>
  50. private readonly IMongoDB<mes_work_calendar_list> _mes_work_calendar_list;
  51. /// <summary>
  52. /// 工艺工序关联工位
  53. /// </summary>
  54. private readonly IMongoDB<mes_tech_proc_workshop> _mes_tech_proc_workshop;
  55. /// <summary>
  56. /// 排程占用记录
  57. /// </summary>
  58. private readonly IMongoDB<mes_schedule_occupy> _mes_schedule_occupy;
  59. /// <summary>
  60. /// 物料详情
  61. /// </summary>
  62. private readonly IMongoDB<ic_item> _ic_item;
  63. private IRepository<ic_item, long> _mysql_ic_item;
  64. /// <summary>
  65. /// 物料BOM
  66. /// </summary>
  67. private readonly IMongoDB<ic_bom> _ic_bom;
  68. //private IRepository<ic_bom, long> _mysql_ic_bom;
  69. /// <summary>
  70. /// 物料BOM明细
  71. /// </summary>
  72. private readonly IMongoDB<ic_bom_child> _ic_bom_child;
  73. //private IRepository<ic_bom_child, long> _mysql_ic_bom_child;
  74. /// <summary>
  75. /// 生产工单主表
  76. /// </summary>
  77. private readonly IMongoDB<mes_morder> _mes_morder;
  78. #endregion
  79. /// <summary>
  80. /// 构造函数
  81. /// </summary>
  82. /// <param name="icitem"></param>
  83. /// <param name="icbom"></param>
  84. public ResourceExamineAppService(
  85. IMongoDB<mes_technique> mes_technique,
  86. IMongoDB<ic_item> ic_item,
  87. IMongoDB<ic_bom> ic_bom,
  88. IMongoDB<ic_bom_child> ic_bom_child,
  89. IMongoDB<mes_morder> mes_morder
  90. //IRepository<ic_item, long> mysql_ic_item,
  91. //IRepository<ic_bom, long> mysql_ic_bom,
  92. //IRepository<ic_bom_child, long> mysql_ic_bom_child,
  93. )
  94. {
  95. _mes_technique = mes_technique;
  96. _ic_item = ic_item;
  97. _ic_bom = ic_bom;
  98. _ic_bom_child = ic_bom_child;
  99. _mes_morder = mes_morder;
  100. //_mysql_ic_item = mysql_ic_item;
  101. //_mysql_ic_bom = mysql_ic_bom;
  102. //_mysql_ic_bom_child = mysql_ic_bom_child;
  103. }
  104. /// <summary>
  105. /// 资源检查
  106. /// </summary>
  107. /// <param name="input"></param>
  108. /// <returns></returns>
  109. /// <exception cref="NotImplementedException"></exception>
  110. public async Task<PschedDto> ReceiveResult(SeorderentryDto input)
  111. {
  112. ////多条插入
  113. //List<mes_technique> infos = new List<mes_technique>();
  114. //mes_technique info;
  115. //for (int i = 0; i < 3; i++)
  116. //{
  117. // info = new mes_technique();
  118. // info.GenerateNewId();
  119. // info.tech_name = "多条" + i;
  120. // info.level = i;
  121. // infos.Add(info);
  122. //}
  123. //await _mes_technique.InsertMany(infos);
  124. //var info2 = _mes_technique.GetAll().Result;
  125. //var a = new PschedDto();
  126. //a.count = info2.Count;
  127. //return a;
  128. ////获取数据
  129. //var info1 = await _mes_technique.GetOneByID((long)1732029975067480064);
  130. ////更新数据
  131. //info1.tech_name = "更新***";
  132. //var rlt =await _mes_technique.UpdateOne(info1, info1.Id);
  133. return null;
  134. throw new NotImplementedException();
  135. }
  136. /// <summary>
  137. /// 产能计算
  138. /// </summary>
  139. /// <param name="BomId">Bom主键</param>
  140. /// <param name="Quantity">需要数量</param>
  141. public async Task ProductiveExamine(long? BomId, int Quantity)
  142. {
  143. }
  144. /// <summary>
  145. /// 检查在制工单
  146. /// </summary>
  147. /// <param name="bomNumber">Bom编码</param>
  148. /// <param name="Quantity">需要数量</param>
  149. /// <returns></returns>
  150. public async Task CheckMorder(string bomNumber, decimal? Quantity, DateTime EndDate)
  151. {
  152. if (string.IsNullOrEmpty(bomNumber) || Quantity < 0)
  153. {
  154. //TODO:入参异常;
  155. //throw new NotImplementedException();
  156. }
  157. #region 注释
  158. /* var morderList = _mes_morder.GetAll().Result;
  159. //查询生产工单类型为计划工单并且工单类型为备库工单 并且BOM编码一致数据,订单状态为 初始或下达工单
  160. var morderTypeList = morderList.Where(x => x.work_order_type == "备库工单" && x.morder_type == "计划工单" &&
  161. x.bom_number == bomNumber && (x.morder_state == "初始" || x.morder_state == "下达")).ToList();
  162. //计划数量-需求数量=剩余可用数量 -->使用计划结束时间排序取第一条满足条件工单
  163. // List =>数量满足Quantity && 生成工单结束日期最早
  164. var SatisfyQuantityList = morderTypeList.Where(x => (x.morder_production_number.Value - x.need_number.Value) >= Quantity).
  165. ToList().OrderBy(x => x.moentry_etime).FirstOrDefault();
  166. if (SatisfyQuantityList == null)
  167. {
  168. }
  169. else
  170. {
  171. }*/
  172. #endregion
  173. }
  174. public void BomPretreatment(long? orderid, long? BomId, int Quantity)
  175. {
  176. if (orderid == null)
  177. {
  178. //throw new bu
  179. }
  180. if (BomId == null)
  181. {
  182. //throw new bu
  183. }
  184. //var query = (await _ic_bom.GetQueryableAsync()).WhereIf(true, a => a.bom_id == BomId).ToList();
  185. var help = new SnowFlake();
  186. var bomlist = _ic_bom.GetAll().Result;
  187. var bomchildlist = _ic_bom_child.GetAll().Result;
  188. var icitemlist = _ic_item.GetAll().Result;
  189. List<BomChildExamineDto> returnlist = new List<BomChildExamineDto>();
  190. var dto = new BomChildExamineDto();
  191. dto.bom_id = BomId.Value;
  192. dto.level = 1;
  193. dto.id = help.NextId();
  194. dto.parent_id = help.NextId();
  195. dto.qty = 1;
  196. dto.num = "1";
  197. dto.isbom = 1;
  198. GetBomList(bomlist, bomchildlist, icitemlist, dto, returnlist);
  199. }
  200. public void GetBomList(List<ic_bom> bomlist, List<ic_bom_child> bomchildlist, List<ic_item> icitemlist, BomChildExamineDto dto, List<BomChildExamineDto> returnlist)
  201. {
  202. int level = dto.level++;//初始化定义level层级
  203. var help = new SnowFlake();
  204. var bom = bomlist.WhereIf(true, s => s.Id == dto.bom_id).FirstOrDefault();
  205. var item = icitemlist.WhereIf(true, a => a.Id == bom.icitem_id).FirstOrDefault();
  206. if (bom == null || item == null)
  207. {
  208. }
  209. //var dto = new BomChildExamineDto();
  210. //dto.level = level;
  211. //dto.bom_id = bomId;
  212. //dto.id = help.NextId();
  213. //dto.parent_id = parent_id;
  214. dto.item_id = bom.icitem_id;
  215. dto.item_name = bom.item_name;
  216. dto.item_code = bom.item_number;
  217. dto.model = item.model;
  218. dto.unit = bom.unit;
  219. dto.erp_cls = item.erp_cls;
  220. dto.erp_cls_name = item.erp_cls_name;
  221. //var bdto = ObjectMapper.Map<ic_bom,BomChildExamineDto>(bom);
  222. returnlist.Add(dto);
  223. var childlist = bomchildlist.WhereIf(true, a => a.bom_id == bom.Id).ToList();
  224. int idx = 1;
  225. foreach (var c in childlist)
  226. {
  227. string childNum = dto.num + "." + idx.ToString();
  228. var icitem = icitemlist.WhereIf(true, a => a.Id == c.icitem_id).FirstOrDefault();
  229. //如果此明细查的到BOM信息,则代表此child是一个子BOM。
  230. if (c.is_bom == 1)
  231. {
  232. var childBom = bomlist.WhereIf(true, a => a.icitem_id == c.icitem_id).FirstOrDefault();
  233. if (childBom != null)
  234. {
  235. var cdto = new BomChildExamineDto();
  236. cdto.id = help.NextId();
  237. cdto.level = level;
  238. cdto.parent_id = dto.id;
  239. cdto.qty = c.qty.Value;
  240. cdto.backflush = c.backflush;
  241. cdto.num = childNum;
  242. cdto.isbom = 1;
  243. GetBomList(bomlist, bomchildlist, icitemlist, cdto, returnlist);
  244. }
  245. }
  246. else
  247. {
  248. if (icitem != null)
  249. {
  250. var childDto = new BomChildExamineDto();
  251. childDto.level = level++;
  252. childDto.bom_id = dto.bom_id;
  253. childDto.id = help.NextId();
  254. childDto.parent_id = dto.id;
  255. childDto.item_id = icitem.Id;
  256. childDto.item_name = icitem.name;
  257. childDto.item_code = icitem.number;
  258. childDto.num = childNum;
  259. childDto.model = icitem.model;
  260. childDto.unit = c.unit;
  261. childDto.erp_cls = item.erp_cls;
  262. childDto.erp_cls_name = item.erp_cls_name;
  263. childDto.backflush = c.backflush;
  264. childDto.qty = c.qty.Value;
  265. childDto.isbom = 0;
  266. returnlist.Add(childDto);
  267. }
  268. }
  269. idx++;
  270. }
  271. }
  272. }
  273. }