ResourceExamineAppService.cs 12 KB

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