ProductExamineAppService.cs 13 KB

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