using Aucma.Scada.Model.domain; using HighWayIot.Common; using HighWayIot.Log4net; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; namespace HighWayIot.Repository.service.Impl { public class ExecutePlanInfoServiceImpl : IExecutePlanInfoService { private Repository _scadaRepository = new Repository("scada"); private Repository _mesRepository = new Repository("mes"); private LogHelper logHelper = LogHelper.Instance; private JsonChange jsonChange = JsonChange.Instance; /// /// 通过产线工位获取执行顺序(默认+1) /// /// /// public int GetExecuteOrderByProductLineCode(string productLineCode) { int result = 0; try { Expression> exp = s1 => true; exp = exp.And(x => x.productLineCode == productLineCode); List planInfos = _scadaRepository.GetList(exp); int order = planInfos.OrderByDescending(x => x.executeOrder).First().executeOrder; result = order + 1; } catch (Exception ex) { logHelper.Error("通过产线工位获取执行顺异常", ex); } return result; } /// /// 通过执行计划编号获取执行计划 /// /// /// public ExecutePlanInfo GetExecutePlanInfoByPlanCode(string executePlanCode) { ExecutePlanInfo planInfo = null; try { Expression> exp = s1 => true; exp = exp.And(x => x.executePlanCode == executePlanCode); planInfo = _scadaRepository.GetFirst(exp); logHelper.Info($"根据执行计划编号{executePlanCode};获取到的执行计划信息:{jsonChange.ModeToJson(planInfo)}"); } catch (Exception ex) { logHelper.Error("通过执行计划编号获取执行计划异常", ex); } return planInfo; } /// /// 通过产线工位获取执行计划 /// /// /// public List GetExecutePlanInfosByProductLineCode(string productLineCode) { List planInfos = null; try { Expression> exp = s1 => true; exp = exp.And(x => x.productLineCode == productLineCode); planInfos = _scadaRepository.GetList(exp); logHelper.Info($"根据产线工位编号:{productLineCode};获取到的执行计划信息:{jsonChange.ModeToJson(planInfos)}"); } catch (Exception ex) { logHelper.Error("通过产线工位获取执行计划异常", ex); } return planInfos; } /// /// 通过生产计划编号获取执行计划 /// /// /// public List GetExecutePlanInfosByProductPlanCode(string productPlanCode) { List planInfos = null; try { Expression> exp = s1 => true; exp = exp.And(x => x.productPlanCode == productPlanCode); planInfos = _scadaRepository.GetList(exp); logHelper.Info($"根据生产计划编号:{productPlanCode};获取到的执行计划信息:{jsonChange.ModeToJson(planInfos)}"); } catch (Exception ex) { logHelper.Error("通过生产计划编号获取执行计划异常", ex); } return planInfos; } /// /// 新增执行计划 /// /// /// public bool InsertExecutePlanInfo(ExecutePlanInfo executePlanInfo) { bool result = false; try { result = _scadaRepository.Insert(executePlanInfo); } catch (Exception ex) { logHelper.Error("新增执行计划异常", ex); } return result; } /// /// 修改执行计划 /// /// /// public bool UpdateExecutePlanInfo(ExecutePlanInfo executePlanInfo) { bool result = false; try { result = _scadaRepository.Update(executePlanInfo); } catch (Exception ex) { logHelper.Error("修改执行计划异常", ex); } return result; } /// /// 批量修改执行计划 /// /// /// public bool UpdateRangeExecutePlanInfo(List executePlanInfos) { bool result = false; try { result = _scadaRepository.UpdateRange(executePlanInfos); } catch (Exception ex) { logHelper.Error("修改执行计划异常", ex); } return result; } /// /// 根据执行计划编号删除执行计划 /// /// /// public bool DeleteExecutePlanInfoByPlanCode(string executePlanCode) { bool result = false; try { ExecutePlanInfo planInfo = this.GetExecutePlanInfoByPlanCode(executePlanCode); result = _scadaRepository.Delete(planInfo); } catch (Exception ex) { logHelper.Error("根据执行计划编号删除执行计划异常", ex); } return result; } public List GetStationHourAmount(string stationCode) { List result = null; try { var _db = _mesRepository.Context; result = _db.Queryable().AS("GET_STATION_HOURAMOUNT").Where("PRODUCTLINE_CODE = @stationCode", new { stationCode = stationCode }).ToList(); } catch (Exception ex) { logHelper.Error("获取小时产量数据异常", ex); } return result; } public List GetStationMaterialStats(string stationCode) { List result = null; try { var _db = _mesRepository.Context; result = _db.Queryable().AS("GET_STATION_MATERIALSTATS").Where("PRODUCTLINE_CODE = @stationCode", new { stationCode = stationCode }).ToList(); } catch (Exception ex) { logHelper.Error("获取型号统计数据异常", ex); } return result; } } }