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/HighWayIot.Repository/service/Impl/ExecutePlanInfoServiceImpl.cs

200 lines
6.4 KiB
C#

using Aucma.Scada.Model.domain;
using HighWayIot.Common;
using HighWayIot.Log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
namespace HighWayIot.Repository.service.Impl
{
public class ExecutePlanInfoServiceImpl : IExecutePlanInfoService
{
private Repository<ExecutePlanInfo> _mesRepository = new Repository<ExecutePlanInfo>("scada");
private LogHelper logHelper = LogHelper.Instance;
private JsonChange jsonChange = JsonChange.Instance;
/// <summary>
/// 通过产线工位获取执行顺序(默认+1
/// </summary>
/// <param name="productLineCode"></param>
/// <returns></returns>
public 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 = _mesRepository.GetList(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 ExecutePlanInfo GetExecutePlanInfoByPlanCode(string executePlanCode)
{
ExecutePlanInfo planInfo = null;
try
{
Expression<Func<ExecutePlanInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.executePlanCode == executePlanCode);
planInfo = _mesRepository.GetFirst(exp);
logHelper.Info($"根据执行计划编号{executePlanCode};获取到的执行计划信息:{jsonChange.ModeToJson(planInfo)}");
}
catch (Exception ex)
{
logHelper.Error("通过执行计划编号获取执行计划异常", ex);
}
return planInfo;
}
/// <summary>
/// 通过产线工位获取执行计划
/// </summary>
/// <param name="productLineCode"></param>
/// <returns></returns>
public 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 = _mesRepository.GetList(exp);
logHelper.Info($"根据产线工位编号:{productLineCode};获取到的执行计划信息:{jsonChange.ModeToJson(planInfos)}");
}
catch (Exception ex)
{
logHelper.Error("通过产线工位获取执行计划异常", ex);
}
return planInfos;
}
/// <summary>
/// 通过生产计划编号获取执行计划
/// </summary>
/// <param name="productPlanCode"></param>
/// <returns></returns>
public 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 = _mesRepository.GetList(exp);
logHelper.Info($"根据生产计划编号:{productPlanCode};获取到的执行计划信息:{jsonChange.ModeToJson(planInfos)}");
}
catch (Exception ex)
{
logHelper.Error("通过生产计划编号获取执行计划异常", ex);
}
return planInfos;
}
/// <summary>
/// 新增执行计划
/// </summary>
/// <param name="executePlanInfo"></param>
/// <returns></returns>
public bool InsertExecutePlanInfo(ExecutePlanInfo executePlanInfo)
{
bool result = false;
try
{
result = _mesRepository.Insert(executePlanInfo);
}
catch (Exception ex)
{
logHelper.Error("新增执行计划异常", ex);
}
return result;
}
/// <summary>
/// 修改执行计划
/// </summary>
/// <param name="executePlanInfo"></param>
/// <returns></returns>
public bool UpdateExecutePlanInfo(ExecutePlanInfo executePlanInfo)
{
bool result = false;
try
{
result = _mesRepository.Update(executePlanInfo);
}
catch (Exception ex)
{
logHelper.Error("修改执行计划异常", ex);
}
return result;
}
/// <summary>
/// 批量修改执行计划
/// </summary>
/// <param name="executePlanInfos"></param>
/// <returns></returns>
public bool UpdateRangeExecutePlanInfo(List<ExecutePlanInfo> executePlanInfos)
{
bool result = false;
try
{
result = _mesRepository.UpdateRange(executePlanInfos);
}
catch (Exception ex)
{
logHelper.Error("修改执行计划异常", ex);
}
return result;
}
/// <summary>
/// 根据执行计划编号删除执行计划
/// </summary>
/// <param name="executePlanCode"></param>
/// <returns></returns>
public bool DeleteExecutePlanInfoByPlanCode(string executePlanCode)
{
bool result = false;
try
{
ExecutePlanInfo planInfo = this.GetExecutePlanInfoByPlanCode(executePlanCode);
result = _mesRepository.Delete(planInfo);
}
catch (Exception ex)
{
logHelper.Error("根据执行计划编号删除执行计划异常", ex);
}
return result;
}
}
}