|
|
|
|
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<ExecutePlanInfo>, IExecutePlanInfoServices
|
|
|
|
|
{
|
|
|
|
|
private readonly IBaseRepository<ExecutePlanInfo> _dal;
|
|
|
|
|
private readonly IProductOrderInfoServices _productOrderInfoServices;
|
|
|
|
|
public ExecutePlanInfoServices(IBaseRepository<ExecutePlanInfo> dal, IProductOrderInfoServices productOrderInfoServices)
|
|
|
|
|
{
|
|
|
|
|
this._dal = dal;
|
|
|
|
|
base.BaseDal = dal;
|
|
|
|
|
_productOrderInfoServices = productOrderInfoServices;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 计划删除
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 计划删除
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="planCode"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<bool> ExecPlanDelete(string id)
|
|
|
|
|
{
|
|
|
|
|
return await _dal.DeleteByIdAsync(id);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 执行计划下移
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 执行计划下移
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="planInfos"></param>
|
|
|
|
|
/// <param name="planCode"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<bool> PlanMoveDown(string id,string station)
|
|
|
|
|
{
|
|
|
|
|
List<ExecutePlanInfo> execPlans = new List<ExecutePlanInfo>();
|
|
|
|
|
var list = await _dal.QueryAsync(d=>d.ProductLineCode.Equals(station));
|
|
|
|
|
List<ExecutePlanInfo> 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 计划上移
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 计划上移
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="planInfos"></param>
|
|
|
|
|
/// <param name="planCode"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="System.NotImplementedException"></exception>
|
|
|
|
|
public async Task<bool> PlanMoveUp(string id, string station)
|
|
|
|
|
{
|
|
|
|
|
List<ExecutePlanInfo> execPlans = new List<ExecutePlanInfo>();
|
|
|
|
|
|
|
|
|
|
var list = await _dal.QueryAsync(d => d.ProductLineCode.Equals(station));
|
|
|
|
|
List<ExecutePlanInfo> 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 计划下达
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 计划下达
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="planCode"></param>
|
|
|
|
|
/// <param name="nowPlanCode"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="System.NotImplementedException"></exception>
|
|
|
|
|
public async Task<ExecutePlanInfo> PlanNextPass(ExecutePlanInfo sm)
|
|
|
|
|
{
|
|
|
|
|
ExecutePlanInfo planInfo = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
List<ExecutePlanInfo> planInfos = new List<ExecutePlanInfo>();
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|