ProductExamineAppService.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 List<mo_mes_technique> techs = new List<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(ProdExamineParamDto param)
  51. {
  52. if (param.packages <= 0)
  53. {
  54. throw new NotImplementedException("产能计算参数有误!");
  55. }
  56. //过滤数据
  57. //1.1、获取工艺路径数据
  58. mo_mes_technique curTech = techs.FirstOrDefault(p => p.bom == param.bom_number && p.bomver == param.version);
  59. if (curTech == null)
  60. {
  61. throw new NotImplementedException("工艺路径不存在,请调整!");
  62. }
  63. //1.2、获取工艺关联工序数据
  64. List<mo_mes_tech_process> curTechProcess = tech_Processes.Where(p => p.tech_id == curTech.mysql_id).ToList();
  65. if (curTechProcess.Count == 0)
  66. {
  67. throw new NotImplementedException("当前工艺路径没有配置工序,请调整!");
  68. }
  69. //1.3、获取工序数据
  70. List<mo_mes_process> curProcess = process.Where(p => curTechProcess.Select(m => m.proc_id).Contains(p.mysql_id)).ToList();
  71. if (curProcess.Count == 0)
  72. {
  73. throw new NotImplementedException("工序数据不存在,请调整!");
  74. }
  75. //1.4、获取工位数据
  76. List<mo_mes_tech_proc_workshop> curWorkShops = tech_Proc_Workshops.Where(p=> curTechProcess.Select(m=>m.mysql_id).Contains(p.tech_proc_id)).ToList(); ;
  77. //2、获取工艺路径下的第一层级工序:目前只考虑第一层级
  78. List<mo_mes_tech_process> fistLevels = curTechProcess.Where(p => p.parentprocid == curTech.mysql_id).ToList();
  79. if (fistLevels.Count == 0)
  80. {
  81. throw new NotImplementedException("当前工艺路径没有配置工序,请调整!");
  82. }
  83. //工艺预处理
  84. List<TechProcDto> teches = TechProcPretreatment(fistLevels,param.packages);
  85. decimal sumTimes = teches.OrderByDescending(p => p.sumTimes).First().sumTimes;
  86. return sumTimes;
  87. }
  88. /// <summary>
  89. /// 工序预处理,按照多分支生成多条单独的工艺路径
  90. /// </summary>
  91. /// <param name="proc">当前工序</param>
  92. /// <param name="processes">工艺关联工序list</param>
  93. /// <param name="packages">生产件数</param>
  94. /// <returns></returns>
  95. private List<TechProcDto> TechProcPretreatment(List<mo_mes_tech_process> processes,int packages)
  96. {
  97. //工艺路径预处理dto
  98. List<TechProcDto> techProcDtos = new List<TechProcDto>();
  99. TechProcDto dto;
  100. //获取下一步工序id
  101. List<long> nextProcIds = processes.Where(p=>p.nextprocid != null).Select(p => p.nextprocid.GetValueOrDefault()).ToList();
  102. //获取起点工序
  103. var startProcs = processes.Where(p => !nextProcIds.Contains(p.proc_id)).ToList();
  104. //递归处理工序返回值
  105. List<mo_mes_tech_process> rtnList;
  106. for (int i = 0; i < startProcs.Count; i++)
  107. {
  108. dto = new TechProcDto();
  109. rtnList = new List<mo_mes_tech_process>();
  110. GetNextProc(startProcs[i], processes, rtnList);
  111. dto.serialno = i + 1;
  112. dto.processes = rtnList;
  113. //dto.details = CalcTakeTimeByLq(rtnList, packages);//通过Lq计算
  114. dto.details = CalcTakeTimeByLqt(rtnList, packages);//通过Lqt计算
  115. dto.sumTimes = dto.details.Sum(p=>p.wait_time);
  116. techProcDtos.Add(dto);
  117. }
  118. return techProcDtos;
  119. }
  120. /// <summary>
  121. /// 递归:根据起始工序,获取后续工序
  122. /// </summary>
  123. /// <param name="proc"></param>
  124. /// <param name="processes"></param>
  125. /// <param name="rtnList"></param>
  126. private void GetNextProc(mo_mes_tech_process proc, List<mo_mes_tech_process> processes, List<mo_mes_tech_process> rtnList)
  127. {
  128. rtnList.Add(proc);
  129. //下一工序id为null,终止
  130. if (proc?.nextprocid == null)
  131. {
  132. return;
  133. }
  134. //获取下一个工序
  135. var nextProc = processes.FirstOrDefault(p=>p.proc_id == proc.nextprocid);
  136. if (nextProc == null)
  137. {
  138. return;
  139. }
  140. GetNextProc(nextProc, processes, rtnList);
  141. }
  142. /// <summary>
  143. /// 通过Lq计算工艺耗时
  144. /// </summary>
  145. /// <param name="Processes"></param>
  146. /// <param name="packages"></param>
  147. /// <returns></returns>
  148. private List<StartTimeDto> CalcTakeTimeByLq(List<mo_mes_tech_process> Processes, int packages)
  149. {
  150. //工序需要等待时间记录
  151. List<StartTimeDto> starts = new List<StartTimeDto>();
  152. StartTimeDto dto;
  153. foreach (var chd in Processes)
  154. {
  155. dto = new StartTimeDto();
  156. if (chd.nextprocid == null)//最后一个工序
  157. {
  158. //计算最后一个工序耗时
  159. dto = CalcProcTakeTimeByLq(chd, packages, packages);
  160. }
  161. else
  162. {
  163. dto = CalcProcTakeTimeByLq(chd, chd.lq.GetValueOrDefault(), packages);
  164. }
  165. //添加记录
  166. starts.Add(dto);
  167. }
  168. return starts;
  169. }
  170. /// <summary>
  171. /// 通过Lq计算当前工序前置准备时间
  172. /// </summary>
  173. /// <param name="proc"></param>
  174. /// <param name="quantity">LeadQuantity to Start Next</param>
  175. /// <param name="packages">件数</param>
  176. /// <returns></returns>
  177. private StartTimeDto CalcProcTakeTimeByLq(mo_mes_tech_process proc, decimal quantity, int packages)
  178. {
  179. //记录当前工序耗时
  180. StartTimeDto dto = new StartTimeDto();
  181. //添加耗时记录
  182. dto.tech_id = proc.tech_id;
  183. dto.proc_id = proc.proc_id;
  184. dto.nextproc_id = proc.nextprocid;
  185. if (proc.wctype == 1)//人工型:数量/uph(一小时生产数量)*60(小时转换为分钟)/wsinuse(工位数)
  186. {
  187. if ( proc.uph.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0)
  188. {
  189. throw new NotImplementedException("当前工序uph或wsinuse参数配置错误,请调整!");
  190. }
  191. dto.wait_time = quantity / proc.uph.GetValueOrDefault() * 60 / proc.wsinuse.GetValueOrDefault();
  192. dto.take_time = packages / proc.uph.GetValueOrDefault() * 60 / proc.wsinuse.GetValueOrDefault();
  193. }
  194. else if (proc.wctype == 2)//流水线型:数量*ct(生产一件所需时间)/wsinuse(工位数)
  195. {
  196. if (proc.ct.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0)
  197. {
  198. throw new NotImplementedException("当前工序ct或wsinuse参数配置错误,请调整!");
  199. }
  200. dto.wait_time = quantity * proc.ct.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault();
  201. dto.take_time = packages * proc.ct.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault();
  202. }
  203. else if (proc.wctype == 3)//设备型:向上取整(数量/一次可加工数量/wsinuse(工位数))*ct(老化一次所需时间)
  204. {
  205. if (proc.upe.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0|| proc.ct.GetValueOrDefault() == 0)
  206. {
  207. throw new NotImplementedException("当前工序upe或ct或wsinuse参数配置错误,请调整!");
  208. }
  209. dto.wait_time = Math.Ceiling(quantity / proc.upe.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault()) * proc.ct.GetValueOrDefault();
  210. dto.take_time = Math.Ceiling(packages / proc.upe.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault()) * proc.ct.GetValueOrDefault();
  211. }
  212. return dto;
  213. }
  214. /// <summary>
  215. /// 通过Lqt计算工艺耗时
  216. /// </summary>
  217. /// <param name="Processes"></param>
  218. /// <param name="packages"></param>
  219. /// <returns></returns>
  220. private List<StartTimeDto> CalcTakeTimeByLqt(List<mo_mes_tech_process> Processes, int packages)
  221. {
  222. //工序需要等待时间记录
  223. List<StartTimeDto> starts = new List<StartTimeDto>();
  224. StartTimeDto dto;
  225. foreach (var chd in Processes)
  226. {
  227. dto = new StartTimeDto();
  228. //添加耗时记录
  229. dto.tech_id = chd.tech_id;
  230. dto.proc_id = chd.proc_id;
  231. dto.nextproc_id = chd.nextprocid;
  232. //计算当前工序生产耗时
  233. dto.take_time = CalcProcTakeTime(chd, packages);
  234. if (chd.nextprocid == null)//最后一个工序
  235. {
  236. dto.wait_time = dto.take_time;
  237. }
  238. else
  239. {
  240. dto.wait_time = chd.lqt.Value;
  241. }
  242. //添加记录
  243. starts.Add(dto);
  244. }
  245. return starts;
  246. }
  247. /// <summary>
  248. /// 计算当前工序生产时间
  249. /// </summary>
  250. /// <param name="proc"></param>
  251. /// <param name="packages">件数</param>
  252. /// <returns></returns>
  253. private decimal CalcProcTakeTime(mo_mes_tech_process proc, int packages)
  254. {
  255. //当前工序生产时间
  256. decimal takeTiem = 0.00m;
  257. if (proc.wctype == 1)//人工型:数量/uph(一小时生产数量)*60(小时转换为分钟)/wsinuse(工位数)
  258. {
  259. if (proc.uph.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0)
  260. {
  261. throw new NotImplementedException("当前工序uph或wsinuse参数配置错误,请调整!");
  262. }
  263. takeTiem = packages / proc.uph.GetValueOrDefault() * 60 / proc.wsinuse.GetValueOrDefault();
  264. }
  265. else if (proc.wctype == 2)//流水线型:数量*ct(生产一件所需时间)/wsinuse(工位数)
  266. {
  267. if (proc.ct.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0)
  268. {
  269. throw new NotImplementedException("当前工序ct或wsinuse参数配置错误,请调整!");
  270. }
  271. takeTiem = packages * proc.ct.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault();
  272. }
  273. else if (proc.wctype == 3)//设备型:向上取整(数量/一次可加工数量/wsinuse(工位数))*ct(老化一次所需时间)
  274. {
  275. if (proc.upe.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0 || proc.ct.GetValueOrDefault() == 0)
  276. {
  277. throw new NotImplementedException("当前工序upe或ct或wsinuse参数配置错误,请调整!");
  278. }
  279. takeTiem = Math.Ceiling(packages / proc.upe.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault()) * proc.ct.GetValueOrDefault();
  280. }
  281. return takeTiem;
  282. }
  283. }
  284. }