| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- using Business.Core.MongoDBHelper;
- using Business.ResourceExamineManagement.Dto;
- using Bussiness.Model.Production;
- using Bussiness.Model.Tech;
- using Bussiness.MongoModel.Production;
- using Bussiness.MongoModel.Tech;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Volo.Abp.Application.Services;
- using Volo.Abp.Domain.Repositories;
- namespace Business.ResourceExamineManagement
- {
- /// <summary>
- /// 产能检查
- /// </summary>
- public class ProductExamineAppService: ApplicationService
- {
- #region 服务
- /// <summary>
- /// 工艺路径
- /// </summary>
- public List<mo_mes_technique> techs = new List<mo_mes_technique>();
- /// <summary>
- /// 工艺关联工序
- /// </summary>
- public List<mo_mes_tech_process> tech_Processes = new List<mo_mes_tech_process>();
- /// <summary>
- /// 工序
- /// </summary>
- public List<mo_mes_process> process = new List<mo_mes_process>();
- /// <summary>
- /// 工艺工序关联工位
- /// </summary>
- public List<mo_mes_tech_proc_workshop> tech_Proc_Workshops = new List<mo_mes_tech_proc_workshop>();
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- public ProductExamineAppService()
- {
- }
- /// <summary>
- /// 产能计算
- /// </summary>
- /// <param name="packages">件数</param>
- /// <returns>生产时长</returns>
- public decimal ProductiveExamine(ProdExamineParamDto param)
- {
- if (param.packages <= 0)
- {
- throw new NotImplementedException("产能计算参数有误!");
- }
- //过滤数据
- //1.1、获取工艺路径数据
- mo_mes_technique curTech = techs.FirstOrDefault(p => p.bom == param.bom_number && p.bomver == param.version);
- if (curTech == null)
- {
- throw new NotImplementedException("工艺路径不存在,请调整!");
- }
- //1.2、获取工艺关联工序数据
- List<mo_mes_tech_process> curTechProcess = tech_Processes.Where(p => p.tech_id == curTech.mysql_id).ToList();
- if (curTechProcess.Count == 0)
- {
- throw new NotImplementedException("当前工艺路径没有配置工序,请调整!");
- }
- //1.3、获取工序数据
- List<mo_mes_process> curProcess = process.Where(p => curTechProcess.Select(m => m.proc_id).Contains(p.mysql_id)).ToList();
- if (curProcess.Count == 0)
- {
- throw new NotImplementedException("工序数据不存在,请调整!");
- }
- //1.4、获取工位数据
- List<mo_mes_tech_proc_workshop> curWorkShops = tech_Proc_Workshops.Where(p=> curTechProcess.Select(m=>m.mysql_id).Contains(p.tech_proc_id)).ToList(); ;
- //2、获取工艺路径下的第一层级工序:目前只考虑第一层级
- List<mo_mes_tech_process> fistLevels = curTechProcess.Where(p => p.parentprocid == curTech.mysql_id).ToList();
- if (fistLevels.Count == 0)
- {
- throw new NotImplementedException("当前工艺路径没有配置工序,请调整!");
- }
- //工艺预处理
- List<TechProcDto> teches = TechProcPretreatment(fistLevels,param.packages);
- decimal sumTimes = teches.OrderByDescending(p => p.sumTimes).First().sumTimes;
- return sumTimes;
- }
- /// <summary>
- /// 工序预处理,按照多分支生成多条单独的工艺路径
- /// </summary>
- /// <param name="proc">当前工序</param>
- /// <param name="processes">工艺关联工序list</param>
- /// <param name="packages">生产件数</param>
- /// <returns></returns>
- private List<TechProcDto> TechProcPretreatment(List<mo_mes_tech_process> processes,int packages)
- {
- //工艺路径预处理dto
- List<TechProcDto> techProcDtos = new List<TechProcDto>();
- TechProcDto dto;
- //获取下一步工序id
- List<long> nextProcIds = processes.Where(p=>p.nextprocid != null).Select(p => p.nextprocid.GetValueOrDefault()).ToList();
- //获取起点工序
- var startProcs = processes.Where(p => !nextProcIds.Contains(p.proc_id)).ToList();
- //递归处理工序返回值
- List<mo_mes_tech_process> rtnList;
- for (int i = 0; i < startProcs.Count; i++)
- {
- dto = new TechProcDto();
- rtnList = new List<mo_mes_tech_process>();
- GetNextProc(startProcs[i], processes, rtnList);
- dto.serialno = i + 1;
- dto.processes = rtnList;
- //dto.details = CalcTakeTimeByLq(rtnList, packages);//通过Lq计算
- dto.details = CalcTakeTimeByLqt(rtnList, packages);//通过Lqt计算
- dto.sumTimes = dto.details.Sum(p=>p.wait_time);
- techProcDtos.Add(dto);
- }
- return techProcDtos;
- }
- /// <summary>
- /// 递归:根据起始工序,获取后续工序
- /// </summary>
- /// <param name="proc"></param>
- /// <param name="processes"></param>
- /// <param name="rtnList"></param>
- private void GetNextProc(mo_mes_tech_process proc, List<mo_mes_tech_process> processes, List<mo_mes_tech_process> rtnList)
- {
- rtnList.Add(proc);
- //下一工序id为null,终止
- if (proc?.nextprocid == null)
- {
- return;
- }
- //获取下一个工序
- var nextProc = processes.FirstOrDefault(p=>p.proc_id == proc.nextprocid);
- if (nextProc == null)
- {
- return;
- }
- GetNextProc(nextProc, processes, rtnList);
- }
- /// <summary>
- /// 通过Lq计算工艺耗时
- /// </summary>
- /// <param name="Processes"></param>
- /// <param name="packages"></param>
- /// <returns></returns>
- private List<StartTimeDto> CalcTakeTimeByLq(List<mo_mes_tech_process> Processes, int packages)
- {
- //工序需要等待时间记录
- List<StartTimeDto> starts = new List<StartTimeDto>();
- StartTimeDto dto;
- foreach (var chd in Processes)
- {
- dto = new StartTimeDto();
- if (chd.nextprocid == null)//最后一个工序
- {
- //计算最后一个工序耗时
- dto = CalcProcTakeTimeByLq(chd, packages, packages);
- }
- else
- {
- dto = CalcProcTakeTimeByLq(chd, chd.lq.GetValueOrDefault(), packages);
- }
- //添加记录
- starts.Add(dto);
- }
- return starts;
- }
- /// <summary>
- /// 通过Lq计算当前工序前置准备时间
- /// </summary>
- /// <param name="proc"></param>
- /// <param name="quantity">LeadQuantity to Start Next</param>
- /// <param name="packages">件数</param>
- /// <returns></returns>
- private StartTimeDto CalcProcTakeTimeByLq(mo_mes_tech_process proc, decimal quantity, int packages)
- {
- //记录当前工序耗时
- StartTimeDto dto = new StartTimeDto();
- //添加耗时记录
- dto.tech_id = proc.tech_id;
- dto.proc_id = proc.proc_id;
- dto.nextproc_id = proc.nextprocid;
- if (proc.wctype == 1)//人工型:数量/uph(一小时生产数量)*60(小时转换为分钟)/wsinuse(工位数)
- {
- if ( proc.uph.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0)
- {
- throw new NotImplementedException("当前工序uph或wsinuse参数配置错误,请调整!");
- }
- dto.wait_time = quantity / proc.uph.GetValueOrDefault() * 60 / proc.wsinuse.GetValueOrDefault();
- dto.take_time = packages / proc.uph.GetValueOrDefault() * 60 / proc.wsinuse.GetValueOrDefault();
- }
- else if (proc.wctype == 2)//流水线型:数量*ct(生产一件所需时间)/wsinuse(工位数)
- {
- if (proc.ct.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0)
- {
- throw new NotImplementedException("当前工序ct或wsinuse参数配置错误,请调整!");
- }
- dto.wait_time = quantity * proc.ct.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault();
- dto.take_time = packages * proc.ct.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault();
- }
- else if (proc.wctype == 3)//设备型:向上取整(数量/一次可加工数量/wsinuse(工位数))*ct(老化一次所需时间)
- {
- if (proc.upe.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0|| proc.ct.GetValueOrDefault() == 0)
- {
- throw new NotImplementedException("当前工序upe或ct或wsinuse参数配置错误,请调整!");
- }
- dto.wait_time = Math.Ceiling(quantity / proc.upe.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault()) * proc.ct.GetValueOrDefault();
- dto.take_time = Math.Ceiling(packages / proc.upe.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault()) * proc.ct.GetValueOrDefault();
- }
- return dto;
- }
- /// <summary>
- /// 通过Lqt计算工艺耗时
- /// </summary>
- /// <param name="Processes"></param>
- /// <param name="packages"></param>
- /// <returns></returns>
- private List<StartTimeDto> CalcTakeTimeByLqt(List<mo_mes_tech_process> Processes, int packages)
- {
- //工序需要等待时间记录
- List<StartTimeDto> starts = new List<StartTimeDto>();
- StartTimeDto dto;
- foreach (var chd in Processes)
- {
- dto = new StartTimeDto();
- //添加耗时记录
- dto.tech_id = chd.tech_id;
- dto.proc_id = chd.proc_id;
- dto.nextproc_id = chd.nextprocid;
- //计算当前工序生产耗时
- dto.take_time = CalcProcTakeTime(chd, packages);
- if (chd.nextprocid == null)//最后一个工序
- {
- dto.wait_time = dto.take_time;
- }
- else
- {
- dto.wait_time = chd.lqt.Value;
- }
- //添加记录
- starts.Add(dto);
- }
- return starts;
- }
- /// <summary>
- /// 计算当前工序生产时间
- /// </summary>
- /// <param name="proc"></param>
- /// <param name="packages">件数</param>
- /// <returns></returns>
- private decimal CalcProcTakeTime(mo_mes_tech_process proc, int packages)
- {
- //当前工序生产时间
- decimal takeTiem = 0.00m;
- if (proc.wctype == 1)//人工型:数量/uph(一小时生产数量)*60(小时转换为分钟)/wsinuse(工位数)
- {
- if (proc.uph.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0)
- {
- throw new NotImplementedException("当前工序uph或wsinuse参数配置错误,请调整!");
- }
- takeTiem = packages / proc.uph.GetValueOrDefault() * 60 / proc.wsinuse.GetValueOrDefault();
- }
- else if (proc.wctype == 2)//流水线型:数量*ct(生产一件所需时间)/wsinuse(工位数)
- {
- if (proc.ct.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0)
- {
- throw new NotImplementedException("当前工序ct或wsinuse参数配置错误,请调整!");
- }
- takeTiem = packages * proc.ct.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault();
- }
- else if (proc.wctype == 3)//设备型:向上取整(数量/一次可加工数量/wsinuse(工位数))*ct(老化一次所需时间)
- {
- if (proc.upe.GetValueOrDefault() == 0 || proc.wsinuse.GetValueOrDefault() == 0 || proc.ct.GetValueOrDefault() == 0)
- {
- throw new NotImplementedException("当前工序upe或ct或wsinuse参数配置错误,请调整!");
- }
- takeTiem = Math.Ceiling(packages / proc.upe.GetValueOrDefault() / proc.wsinuse.GetValueOrDefault()) * proc.ct.GetValueOrDefault();
- }
- return takeTiem;
- }
- }
- }
|