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/ExecutePlanInfoServices.cs

409 lines
14 KiB
C#

using Admin.Core.IRepository;
1 year ago
using Admin.Core.IService;
using Admin.Core.Model;
1 year ago
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System;
using Aucma.Core.PLc;
1 year ago
using Admin.Core.Common;
using log4net;
using SqlSugar;
using System.Linq.Expressions;
using StackExchange.Profiling.Internal;
1 year ago
using Admin.Core.Model.ViewModels;
namespace Admin.Core.Service
{
1 year ago
public class ExecutePlanInfoServices : BaseServices<ExecutePlanInfo>, IExecutePlanInfoServices
{
1 year ago
private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(ExecutePlanInfoServices));
1 year ago
private readonly IBaseRepository<ExecutePlanInfo> _dal;
1 year ago
private readonly IExecutePlanInfoRepository _executePlanInfoRepository;
1 year ago
private readonly IProductOrderInfoServices _productOrderInfoServices;
1 year ago
private readonly IProductPlanInfoServices _productPlanInfoServices;
public ExecutePlanInfoServices(IBaseRepository<ExecutePlanInfo> dal, IProductOrderInfoServices productOrderInfoServices,
IProductPlanInfoServices productPlanInfoServices, IExecutePlanInfoRepository executePlanInfoRepository)
{
this._dal = dal;
base.BaseDal = dal;
1 year ago
_productOrderInfoServices = productOrderInfoServices;
1 year ago
_productPlanInfoServices = productPlanInfoServices;
_executePlanInfoRepository = executePlanInfoRepository;
}
1 year ago
#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();
1 year ago
if (planInfos.Count()==0) return false;
1 year ago
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();
1 year ago
if (planInfos.Count()==0) return false;
1 year ago
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;
1 year ago
}
}
catch (Exception ex)
{
1 year ago
logHelper.Error(ex);
1 year ago
}
return planInfo;
}
#endregion
1 year ago
/// <summary>
/// 通过产线工位获取执行顺序(默认+1
/// </summary>
/// <param name="productLineCode"></param>
/// <returns></returns>
public async Task<int> GetExecuteOrderByProductLineCode(string productLineCode)
{
int result = 0;
try
{
Expression<Func<ExecutePlanInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.ProductLineCode == productLineCode);
List<ExecutePlanInfo> planInfos =await _dal.QueryAsync(exp);
int order = planInfos.OrderByDescending(x => x.ExecuteOrder).First().ExecuteOrder;
result = order + 1;
}
catch (Exception ex)
{
logHelper.Error("通过产线工位获取执行顺异常", ex);
}
return result;
}
/// <summary>
/// 通过执行计划编号获取执行计划
/// </summary>
/// <param name="executePlanCode"></param>
/// <returns></returns>
public async Task<ExecutePlanInfo> GetExecutePlanInfoByPlanCodeAsync(string executePlanCode)
{
ExecutePlanInfo planInfo = null;
try
{
Expression<Func<ExecutePlanInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.ExecutePlanCode == executePlanCode);
planInfo = await _dal.FirstAsync(exp);
logHelper.Info($"根据执行计划编号{executePlanCode};获取到的执行计划信息:{planInfo.ToJson()}");
}
catch (Exception ex)
{
logHelper.Error("通过执行计划编号获取执行计划异常", ex);
}
return planInfo;
}
/// <summary>
/// 通过产线工位获取执行计划
/// </summary>
/// <param name="productLineCode"></param>
/// <returns></returns>
public async Task<List<ExecutePlanInfo>> GetExecutePlanInfosByProductLineCode(string productLineCode)
{
List<ExecutePlanInfo> planInfos = null;
try
{
Expression<Func<ExecutePlanInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.ProductLineCode == productLineCode);
planInfos =await _dal.QueryAsync(exp);
logHelper.Info($"根据产线工位编号:{productLineCode};获取到的执行计划信息:{planInfos.ToJson}");
}
catch (Exception ex)
{
logHelper.Error("通过产线工位获取执行计划异常", ex);
}
return planInfos;
}
/// <summary>
/// 通过生产计划编号获取执行计划
/// </summary>
/// <param name="productPlanCode"></param>
/// <returns></returns>
public async Task<List<ExecutePlanInfo>> GetExecutePlanInfosByProductPlanCode(string productPlanCode)
{
List<ExecutePlanInfo> planInfos = null;
try
{
Expression<Func<ExecutePlanInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.ProductPlanCode == productPlanCode);
planInfos =await _dal.QueryAsync(exp);
logHelper.Info($"根据生产计划编号:{productPlanCode};获取到的执行计划信息:{planInfos.ToJson()}");
}
catch (Exception ex)
{
logHelper.Error("通过生产计划编号获取执行计划异常", ex);
}
return planInfos;
}
/// <summary>
/// 新增执行计划
/// </summary>
/// <param name="executePlanInfo"></param>
/// <returns></returns>
public async Task<bool> InsertExecutePlanInfo(ExecutePlanInfo executePlanInfo)
{
bool result = false;
try
{
int r =await _dal.AddAsync(executePlanInfo);
if (r > 0) result = true;
}
catch (Exception ex)
{
logHelper.Error("新增执行计划异常", ex);
}
return result;
}
/// <summary>
/// 修改执行计划
/// </summary>
/// <param name="executePlanInfo"></param>
/// <returns></returns>
public async Task<bool> UpdateExecutePlanInfo(ExecutePlanInfo executePlanInfo)
{
bool result = false;
try
{
result =await _dal.UpdateAsync(executePlanInfo);
}
catch (Exception ex)
{
logHelper.Error("修改执行计划异常", ex);
}
return result;
}
/// <summary>
/// 批量修改执行计划
/// </summary>
/// <param name="executePlanInfos"></param>
/// <returns></returns>
public async Task<bool> UpdateRangeExecutePlanInfo(List<ExecutePlanInfo> executePlanInfos)
{
bool result = false;
try
{
result =await _dal.UpdateAsync(executePlanInfos);
}
catch (Exception ex)
{
logHelper.Error("修改执行计划异常", ex);
}
return result;
}
/// <summary>
/// 根据执行计划编号删除执行计划
/// </summary>
/// <param name="executePlanCode"></param>
/// <returns></returns>
public async Task<bool> DeleteExecutePlanInfoByPlanCode(string executePlanCode)
{
bool result = false;
try
{
ExecutePlanInfo planInfo =await this.GetExecutePlanInfoByPlanCodeAsync(executePlanCode);
result =await _dal.DeleteAsync(planInfo);
}
catch (Exception ex)
{
logHelper.Error("根据执行计划编号删除执行计划异常", ex);
}
return result;
}
public async Task<List<dynamic>> GetStationHourAmount(string stationCode)
{
List<dynamic> result = null;
try
{
result =await _executePlanInfoRepository.GetStationHourAmount(stationCode);
}
catch (Exception ex)
{
logHelper.Error("获取小时产量数据异常", ex);
}
return result;
}
public async Task<List<dynamic>> GetStationMaterialStats(string stationCode)
{
List<dynamic> result = null;
try
{
result = await _executePlanInfoRepository.GetStationMaterialStats(stationCode);
}
catch (Exception ex)
{
logHelper.Error("获取型号统计数据异常", ex);
}
return result;
}
/// <summary>
/// 通过执行计划编号获取执行计划
/// </summary>
/// <param name="executePlanCode"></param>
/// <returns></returns>
public async Task<ExecutePlanInfo> GetExecutePlanInfoByPlanCode(string executePlanCode)
{
ExecutePlanInfo planInfos = null;
try
{
Expression<Func<ExecutePlanInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.ProductPlanCode == executePlanCode);
planInfos = await _executePlanInfoRepository.FirstAsync(exp);
logHelper.Info($"根据生产计划编号:{executePlanCode};获取到的执行计划信息:{planInfos.ToJson()}");
}
catch (Exception ex)
{
logHelper.Error("通过生产计划编号获取执行计划异常", ex);
}
return planInfos;
}
/// <summary>
/// 获取钣金生产小时数
/// </summary>
/// <param name="stationCode"></param>
/// <returns></returns>
public async Task<List<dynamic>> GetStationSheetMetalHourAmountAsync(string stationCode)
{
return await _executePlanInfoRepository.GetStationSheetMetalHourAmountAsync(stationCode);
}
1 year ago
public List<dynamic> GetStationSheetMetalStats(string stationCode)
{
return _executePlanInfoRepository.GetStationSheetMetalStats(stationCode);
}
1 year ago
public List<SheetMetalDataView> QuerySheetMetalData(string stationCode)
{
return _executePlanInfoRepository.QuerySheetMetalData(stationCode);
}
}
}