using Admin.Core.IRepository; using Admin.Core.IService; using Admin.Core.Model; using Admin.Core.Model.Model_New; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System; using Aucma.Core.PLc; namespace Admin.Core.Service { public class ExecutePlanInfoServices : BaseServices, IExecutePlanInfoServices { private readonly IBaseRepository _dal; private readonly IProductOrderInfoServices _productOrderInfoServices; public ExecutePlanInfoServices(IBaseRepository dal, IProductOrderInfoServices productOrderInfoServices) { this._dal = dal; base.BaseDal = dal; _productOrderInfoServices = productOrderInfoServices; } #region 计划删除 /// /// 计划删除 /// /// /// public async Task ExecPlanDelete(string id) { return await _dal.DeleteByIdAsync(id); } #endregion #region 执行计划下移 /// /// 执行计划下移 /// /// /// /// public async Task PlanMoveDown(string id,string station) { List execPlans = new List(); var list = await _dal.QueryAsync(d=>d.ProductLineCode.Equals(station)); List planInfos = (list.OrderBy(d => d.ExecuteOrder)).ToList(); if (planInfos == null) return false; ExecutePlanInfo planInfo = planInfos.FirstOrDefault(x => x.ObjId == int.Parse(id)); int executeOrder = planInfo.ExecuteOrder; int planIndex = planInfos.IndexOf(planInfo); if (planIndex == 0 && planInfos.Count == 0) return false; if ((planInfos.Count - 1) == planIndex) return false; var lastPlanInfo = planInfos[planIndex + 1]; planInfo.ExecuteOrder = lastPlanInfo.ExecuteOrder; lastPlanInfo.ExecuteOrder = executeOrder; execPlans.Add(planInfo); execPlans.Add(lastPlanInfo); var result = await _dal.UpdateAsync(execPlans); if (result) return true; else return false; } #endregion #region 计划上移 /// /// 计划上移 /// /// /// /// /// public async Task PlanMoveUp(string id, string station) { List execPlans = new List(); var list = await _dal.QueryAsync(d => d.ProductLineCode.Equals(station)); List planInfos = (list.OrderBy(d => d.ExecuteOrder)).ToList(); if (planInfos == null) return false; ExecutePlanInfo planInfo = planInfos.FirstOrDefault(x => x.ObjId == int.Parse(id)); int executeOrder = planInfo.ExecuteOrder; int planIndex = planInfos.IndexOf(planInfo); if (planIndex == 0) return false; var lastPlanInfo = planInfos[planIndex - 1]; planInfo.ExecuteOrder = lastPlanInfo.ExecuteOrder; lastPlanInfo.ExecuteOrder = executeOrder; execPlans.Add(planInfo); execPlans.Add(lastPlanInfo); var result = await _dal.UpdateAsync(execPlans); if (result) return true; else return false; } #endregion #region 计划下达 /// /// 计划下达 /// /// /// /// /// public async Task PlanNextPass(ExecutePlanInfo sm) { ExecutePlanInfo planInfo = null; try { List planInfos = new List(); if (sm != null) { //下传计划到PLC,同时更改计划状态 var rearPanel = PlcHelper.melsecList.FirstOrDefault(d=>d.EquipName.Equals("后板Plc")); if (rearPanel.plc.IsConnected) { rearPanel.plc.WriteString("M100", sm.ProductPlanCode); rearPanel.plc.WriteInt32("M100", sm.PlanAmount); } var box = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("U壳PLC")); if (box.plc.IsConnected) { box.plc.WriteString("M100", sm.ProductPlanCode); box.plc.WriteInt32("M100", sm.PlanAmount); } //将计划写入拆分计划表中 return planInfo; } } catch (Exception ex) { } return planInfo; } #endregion } }