using Admin.Core.IRepository; using Admin.Core.IService; using System.Threading.Tasks; using System.Collections.Generic; using System.Linq; using System; using Admin.Core.Model.Model_New; namespace Admin.Core.Service { public class SmTaskExecutionServices : BaseServices, ISmTaskExecutionServices { private readonly IBaseRepository _dal; public SmTaskExecutionServices(IBaseRepository dal) { this._dal = dal; base.BaseDal = dal; } #region 计划删除 /// /// 计划删除 /// /// /// /// public async Task PlanDelete(string id) { var list = await _dal.QueryAsync(d => d.ObjId == int.Parse(id)); var model = list.FirstOrDefault(); return await _dal.DeleteAsync(model); } #endregion #region 执行计划下移 /// /// 执行计划下移 /// /// /// /// /// public async Task PlanMoveDown(string id) { List execPlans = new List(); var list = await _dal.QueryAsync(); List planInfos = (list.OrderBy(d => d.TaskSort)).ToList(); if (planInfos == null) return false; SmTaskExecution planInfo = planInfos.FirstOrDefault(x => x.ObjId == int.Parse(id)); int executeOrder = planInfo.TaskSort; 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.TaskSort = lastPlanInfo.TaskSort; lastPlanInfo.TaskSort = 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) { List execPlans = new List(); var list = await _dal.QueryAsync(); List planInfos = (list.OrderBy(d => d.TaskSort)).ToList(); if (planInfos == null) return false; SmTaskExecution planInfo = planInfos.FirstOrDefault(x => x.ObjId == int.Parse(id)); int executeOrder = planInfo.TaskSort; int planIndex = planInfos.IndexOf(planInfo); if (planIndex == 0) return false; var lastPlanInfo = planInfos[planIndex - 1]; planInfo.TaskSort = lastPlanInfo.TaskSort; lastPlanInfo.TaskSort = 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(SmTaskExecution sm) { SmTaskExecution planInfo = null; try { List planInfos = new List(); if (sm!=null) { //下传计划到PLC,同时更改计划状态 } await Task.CompletedTask; return null; } catch (Exception ex) { } return planInfo; } #endregion } }