You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AUCMA_SCADA/Admin.Core.Service/Service_New/SmTaskExecutionServices.cs

139 lines
4.6 KiB
C#

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<SmTaskExecution>, ISmTaskExecutionServices
{
private readonly IBaseRepository<SmTaskExecution> _dal;
public SmTaskExecutionServices(IBaseRepository<SmTaskExecution> dal)
{
this._dal = dal;
base.BaseDal = dal;
}
#region 计划删除
/// <summary>
/// 计划删除
/// </summary>
/// <param name="planCode"></param>
/// <returns></returns>
/// <exception cref="System.NotImplementedException"></exception>
public async Task<bool> 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 执行计划下移
/// <summary>
/// 执行计划下移
/// </summary>
/// <param name="planInfos"></param>
/// <param name="planCode"></param>
/// <returns></returns>
/// <exception cref="System.NotImplementedException"></exception>
public async Task<bool> PlanMoveDown(string id)
{
List<SmTaskExecution> execPlans = new List<SmTaskExecution>();
var list = await _dal.QueryAsync();
List<SmTaskExecution> 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 计划上移
/// <summary>
/// 计划上移
/// </summary>
/// <param name="planInfos"></param>
/// <param name="planCode"></param>
/// <returns></returns>
/// <exception cref="System.NotImplementedException"></exception>
public async Task<bool> PlanMoveUp(string id)
{
List<SmTaskExecution> execPlans = new List<SmTaskExecution>();
var list = await _dal.QueryAsync();
List<SmTaskExecution> 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 计划下达
/// <summary>
/// 计划下达
/// </summary>
/// <param name="planCode"></param>
/// <param name="nowPlanCode"></param>
/// <returns></returns>
/// <exception cref="System.NotImplementedException"></exception>
public async Task<SmTaskExecution> PlanNextPass(SmTaskExecution sm)
{
SmTaskExecution planInfo = null;
try
{
List<SmTaskExecution> planInfos = new List<SmTaskExecution>();
if (sm!=null)
{
//下传计划到PLC,同时更改计划状态
}
await Task.CompletedTask;
return null;
}
catch (Exception ex)
{
}
return planInfo;
}
#endregion
}
}