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

155 lines
5.4 KiB
C#

using Aucma.Scada.Model.domain;
using HighWayIot.Common;
using HighWayIot.Log4net;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
namespace HighWayIot.Repository.service.Impl
{
public class ProductPlanInfoServiceImpl : IProductPlanInfoService
{
private Repository<ProductPlanInfo> _mesRepository = new Repository<ProductPlanInfo>("mes");
private LogHelper logHelper = LogHelper.Instance;
private JsonChange jsonChange = JsonChange.Instance;
///<summary>
///通过订单号和工位查询工单号
/// </summary>
public string GetPlanCode(string orderCode, string station)
{
var aa = _mesRepository.GetList();
var plan = _mesRepository.GetFirst(x => x.orderCode == orderCode && x.productLineCode == station);
if(plan == null)
{
return "";
}
else
{
return plan.planCode;
}
}
/// <summary>
/// 通过计划编号获取计划信息
/// </summary>
/// <param name="planCode"></param>
/// <returns></returns>
public ProductPlanInfo GetProductPlanByPlanCode(string planCode)
{
ProductPlanInfo planInfo = null;
try
{
Expression<Func<ProductPlanInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.planCode == planCode);
planInfo = _mesRepository.GetFirst(exp);
logHelper.Info($"根据计划编号{planCode};获取到的计划信息:{jsonChange.ModeToJson(planInfo)}");
}
catch (Exception ex)
{
logHelper.Error("通过计划编号获取计划信息异常", ex);
}
return planInfo;
}
/// <summary>
/// 通过产线工位获取生产计划
/// </summary>
/// <param name="productLineCode"></param>
/// <returns></returns>
public List<ProductPlanInfo> GetProductPlanInfosByProductLineCode(string productLineCode)
{
List<ProductPlanInfo> planInfos = null;
try
{
Expression<Func<ProductPlanInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.productLineCode == productLineCode && x.endTime==null);
planInfos = _mesRepository.GetList(exp);
logHelper.Info($"根据产线工位编号:{productLineCode};获取到的计划信息:{jsonChange.ModeToJson(planInfos)}");
}
catch (Exception ex)
{
logHelper.Error("通过产线工位获取生产计划异常", ex);
}
return planInfos;
}
/// <summary>
/// 添加生产计划
/// </summary>
/// <param name="productPlanInfo"></param>
/// <returns></returns>
public bool InsertProductPlanInfo(ProductPlanInfo productPlanInfo)
{
bool result = false;
try
{
result = _mesRepository.Insert(productPlanInfo);
}
catch (Exception ex)
{
logHelper.Error("添加生产计划异常", ex);
}
return result;
}
/// <summary>
/// 修改生产计划
/// </summary>
/// <param name="productPlanInfo"></param>
/// <returns></returns>
public bool UpdateProductPlanInfo(ProductPlanInfo productPlanInfo)
{
bool result = false;
try
{
Expression<Func<ProductPlanInfo, ProductPlanInfo>> columns = x => new ProductPlanInfo { completeAmount = productPlanInfo.completeAmount,beginTime = productPlanInfo.beginTime,endTime = productPlanInfo.endTime };
result= _mesRepository.Update(columns, x => x.objId == productPlanInfo.objId);
// string sql = $@"UPDATE PRODUCT_PLANINFO SET COMPLETE_AMOUNT= '{productPlanInfo.completeAmount}',BEGIN_TIME= '{productPlanInfo.beginTime}',END_TIME= '{productPlanInfo.endTime}' WHERE OBJ_ID={productPlanInfo.objId} ";
// _mesRepository._db().Ado.SqlQuery(sql);
// result = _mesRepository.Update(productPlanInfo);
}
catch (Exception ex)
{
logHelper.Error("修改生产计划异常", ex);
}
return result;
}
/// <summary>
/// 通过物料编码和工位找到生产计划
/// </summary>
/// <param name="productLineCode"></param>
/// <returns></returns>
public ProductPlanInfo GetProductPlanInfosByMaterialCode(string materialCode)
{
ProductPlanInfo planInfo = null;
try
{
Expression<Func<ProductPlanInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.materialCode == materialCode && x.productLineCode=="1006" && x.endTime==null);
planInfo = _mesRepository.GetFirst(exp);
logHelper.Info($"根据物料编码{materialCode};获取到的计划信息:{jsonChange.ModeToJson(planInfo)}");
}
catch (Exception ex)
{
logHelper.Error("通过计划编号获取计划信息异常", ex);
}
return planInfo;
}
}
}