ProductExamineAppService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. using Business.Core.MongoDBHelper;
  2. using Business.ResourceExamineManagement.Dto;
  3. using Bussiness.Model.Production;
  4. using Bussiness.Model.Tech;
  5. using Bussiness.MongoModel.Production;
  6. using Bussiness.MongoModel.Tech;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Volo.Abp.Application.Services;
  13. using Volo.Abp.Domain.Repositories;
  14. namespace Business.ResourceExamineManagement
  15. {
  16. /// <summary>
  17. /// 产能检查
  18. /// </summary>
  19. public class ProductExamineAppService: ApplicationService
  20. {
  21. #region 服务
  22. /// <summary>
  23. /// 工艺路径
  24. /// </summary>
  25. public mo_mes_technique tech = new mo_mes_technique();
  26. /// <summary>
  27. /// 工艺关联工序
  28. /// </summary>
  29. public List<mo_mes_tech_process> tech_Processes = new List<mo_mes_tech_process>();
  30. /// <summary>
  31. /// 工序
  32. /// </summary>
  33. public List<mo_mes_process> process = new List<mo_mes_process>();
  34. /// <summary>
  35. /// 工艺工序关联工位
  36. /// </summary>
  37. public List<mo_mes_tech_proc_workshop> tech_Proc_Workshops = new List<mo_mes_tech_proc_workshop>();
  38. #endregion
  39. /// <summary>
  40. /// 构造函数
  41. /// </summary>
  42. public ProductExamineAppService()
  43. {
  44. }
  45. /// <summary>
  46. /// 产能计算
  47. /// </summary>
  48. /// <param name="packages">件数</param>
  49. /// <returns>生产时长</returns>
  50. public decimal ProductiveExamine(int packages)
  51. {
  52. if (packages <= 0)
  53. {
  54. throw new NotImplementedException("产能计算参数有误!");
  55. }
  56. //1、获取工艺路径下的第一层级工序:目前只考虑第一层级
  57. List<mo_mes_tech_process> fistLevels = tech_Processes.Where(p => p.parentprocid == tech.mysql_id).ToList();
  58. if (fistLevels.Count == 0)
  59. {
  60. throw new NotImplementedException("当前工艺路径没有配置工序,请调整!");
  61. }
  62. //工艺预处理
  63. List<TechProcDto> teches = TechProcPretreatment(fistLevels,packages);
  64. decimal sumTimes = teches.OrderByDescending(p => p.sumTimes).First().sumTimes;
  65. return sumTimes;
  66. }
  67. /// <summary>
  68. /// 工序预处理,按照多分支生成多条单独的工艺路径
  69. /// </summary>
  70. /// <param name="proc">当前工序</param>
  71. /// <param name="processes">工艺关联工序list</param>
  72. /// <param name="packages">生产件数</param>
  73. /// <returns></returns>
  74. private List<TechProcDto> TechProcPretreatment(List<mo_mes_tech_process> processes,int packages)
  75. {
  76. //工艺路径预处理dto
  77. List<TechProcDto> techProcDtos = new List<TechProcDto>();
  78. TechProcDto dto;
  79. //获取下一步工序id
  80. List<long> nextProcIds = processes.Where(p=>p.nextprocid != null).Select(p => p.nextprocid.GetValueOrDefault()).ToList();
  81. //获取起点工序
  82. var startProcs = processes.Where(p => !nextProcIds.Contains(p.proc_id.GetValueOrDefault())).ToList();
  83. //递归处理工序返回值
  84. List<mo_mes_tech_process> rtnList;
  85. for (int i = 0; i < startProcs.Count; i++)
  86. {
  87. dto = new TechProcDto();
  88. rtnList = new List<mo_mes_tech_process>();
  89. GetNextProc(startProcs[i], processes, rtnList);
  90. dto.serialno = i + 1;
  91. dto.processes = rtnList;
  92. //dto.details = CalcTakeTimeByLq(rtnList, packages);//通过Lq计算
  93. dto.details = CalcTakeTimeByLqt(rtnList, packages);//通过Lqt计算
  94. dto.sumTimes = dto.details.Sum(p=>p.wait_time);
  95. techProcDtos.Add(dto);
  96. }
  97. return techProcDtos;
  98. }
  99. /// <summary>
  100. /// 递归:根据起始工序,获取后续工序
  101. /// </summary>
  102. /// <param name="proc"></param>
  103. /// <param name="processes"></param>
  104. /// <param name="rtnList"></param>
  105. private void GetNextProc(mo_mes_tech_process proc, List<mo_mes_tech_process> processes, List<mo_mes_tech_process> rtnList)
  106. {
  107. rtnList.Add(proc);
  108. //下一工序id为null,终止
  109. if (proc?.nextprocid == null)
  110. {
  111. return;
  112. }
  113. //获取下一个工序
  114. var nextProc = processes.FirstOrDefault(p=>p.proc_id == proc.nextprocid);
  115. if (nextProc == null)
  116. {
  117. return;
  118. }
  119. GetNextProc(nextProc, processes, rtnList);
  120. }
  121. /// <summary>
  122. /// 通过Lq计算工艺耗时
  123. /// </summary>
  124. /// <param name="Processes"></param>
  125. /// <param name="packages"></param>
  126. /// <returns></returns>
  127. private List<StartTimeDto> CalcTakeTimeByLq(List<mo_mes_tech_process> Processes, int packages)
  128. {
  129. //工序需要等待时间记录
  130. List<StartTimeDto> starts = new List<StartTimeDto>();
  131. StartTimeDto dto;
  132. foreach (var chd in Processes)
  133. {
  134. dto = new StartTimeDto();
  135. if (chd.nextprocid == null)//最后一个工序
  136. {
  137. //计算最后一个工序耗时
  138. dto = CalcProcTakeTimeByLq(chd, packages, packages);
  139. }
  140. else
  141. {
  142. dto = CalcProcTakeTimeByLq(chd, chd.lq.GetValueOrDefault(), packages);
  143. }
  144. //添加记录
  145. starts.Add(dto);
  146. }
  147. return starts;
  148. }
  149. /// <summary>
  150. /// 通过Lq计算当前工序前置准备时间
  151. /// </summary>
  152. /// <param name="proc"></param>
  153. /// <param name="quantity">LeadQuantity to Start Next</param>
  154. /// <param name="packages">件数</param>
  155. /// <returns></returns>
  156. private StartTimeDto CalcProcTakeTimeByLq(mo_mes_tech_process proc, decimal quantity, int packages)
  157. {
  158. //记录当前工序耗时
  159. StartTimeDto dto = new StartTimeDto();
  160. //添加耗时记录
  161. dto.tech_id = proc.tech_id.GetValueOrDefault();
  162. dto.proc_id = proc.proc_id.GetValueOrDefault();
  163. dto.nextproc_id = proc.nextprocid;
  164. if (proc.wctype == 1)//人工型:数量/uph(一小时生产数量)*60(小时转换为分钟)/wsinuse(工位数)
  165. {
  166. if ( proc.uph.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0)
  167. {
  168. throw new NotImplementedException("当前工序uph或wsinuse参数配置错误,请调整!");
  169. }
  170. dto.wait_time = quantity / proc.uph.GetValueOrDefault() * 60 / proc.wsinuse.GetValueOrDefault();
  171. dto.take_time = packages / proc.uph.GetValueOrDefault() * 60 / proc.wsinuse.GetValueOrDefault();
  172. }
  173. else if (proc.wctype == 2)//流水线型:数量*ct(生产一件所需时间)/wsinuse(工位数)
  174. {
  175. if (proc.ct.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0)
  176. {
  177. throw new NotImplementedException("当前工序ct或wsinuse参数配置错误,请调整!");
  178. }
  179. dto.wait_time = quantity * proc.ct.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault();
  180. dto.take_time = packages * proc.ct.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault();
  181. }
  182. else if (proc.wctype == 3)//设备型:向上取整(数量/一次可加工数量/wsinuse(工位数))*ct(老化一次所需时间)
  183. {
  184. if (proc.upe.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0|| proc.ct.GetValueOrDefault() == 0)
  185. {
  186. throw new NotImplementedException("当前工序upe或ct或wsinuse参数配置错误,请调整!");
  187. }
  188. dto.wait_time = Math.Ceiling(quantity / proc.upe.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault()) * proc.ct.GetValueOrDefault();
  189. dto.take_time = Math.Ceiling(packages / proc.upe.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault()) * proc.ct.GetValueOrDefault();
  190. }
  191. return dto;
  192. }
  193. /// <summary>
  194. /// 通过Lqt计算工艺耗时
  195. /// </summary>
  196. /// <param name="Processes"></param>
  197. /// <param name="packages"></param>
  198. /// <returns></returns>
  199. private List<StartTimeDto> CalcTakeTimeByLqt(List<mo_mes_tech_process> Processes, int packages)
  200. {
  201. //工序需要等待时间记录
  202. List<StartTimeDto> starts = new List<StartTimeDto>();
  203. StartTimeDto dto;
  204. foreach (var chd in Processes)
  205. {
  206. dto = new StartTimeDto();
  207. //添加耗时记录
  208. dto.tech_id = chd.tech_id.GetValueOrDefault();
  209. dto.proc_id = chd.proc_id.GetValueOrDefault();
  210. dto.nextproc_id = chd.nextprocid;
  211. //计算当前工序生产耗时
  212. dto.take_time = CalcProcTakeTime(chd, packages);
  213. if (chd.nextprocid == null)//最后一个工序
  214. {
  215. dto.wait_time = dto.take_time;
  216. }
  217. else
  218. {
  219. dto.wait_time = chd.lqt.Value;
  220. }
  221. //添加记录
  222. starts.Add(dto);
  223. }
  224. return starts;
  225. }
  226. /// <summary>
  227. /// 计算当前工序生产时间
  228. /// </summary>
  229. /// <param name="proc"></param>
  230. /// <param name="packages">件数</param>
  231. /// <returns></returns>
  232. private decimal CalcProcTakeTime(mo_mes_tech_process proc, int packages)
  233. {
  234. //当前工序生产时间
  235. decimal takeTiem = 0.00m;
  236. if (proc.wctype == 1)//人工型:数量/uph(一小时生产数量)*60(小时转换为分钟)/wsinuse(工位数)
  237. {
  238. if (proc.uph.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0)
  239. {
  240. throw new NotImplementedException("当前工序uph或wsinuse参数配置错误,请调整!");
  241. }
  242. takeTiem = packages / proc.uph.GetValueOrDefault() * 60 / proc.wsinuse.GetValueOrDefault();
  243. }
  244. else if (proc.wctype == 2)//流水线型:数量*ct(生产一件所需时间)/wsinuse(工位数)
  245. {
  246. if (proc.ct.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0)
  247. {
  248. throw new NotImplementedException("当前工序ct或wsinuse参数配置错误,请调整!");
  249. }
  250. takeTiem = packages * proc.ct.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault();
  251. }
  252. else if (proc.wctype == 3)//设备型:向上取整(数量/一次可加工数量/wsinuse(工位数))*ct(老化一次所需时间)
  253. {
  254. if (proc.upe.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0 || proc.ct.GetValueOrDefault() == 0)
  255. {
  256. throw new NotImplementedException("当前工序upe或ct或wsinuse参数配置错误,请调整!");
  257. }
  258. takeTiem = Math.Ceiling(packages / proc.upe.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault()) * proc.ct.GetValueOrDefault();
  259. }
  260. return takeTiem;
  261. }
  262. }
  263. }