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.

210 lines
8.8 KiB
C#

using SlnMesnac.Config;
using SlnMesnac.Model.domain;
using SlnMesnac.Model.dto;
using SlnMesnac.Model.enums;
using SlnMesnac.Repository.service.@base;
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.Repository.service.Impl
* f47ba8ea-bac5-40cb-ab9a-a8f59d782594
*
* WenJY
* wenjy@mesnac.com
* 2024-04-07 16:57:36
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Repository.service.Impl
{
public class MesProductPlanServiceImpl : BaseServiceImpl<MesProductPlan>, IMesProductPlanService
{
private AppConfig _appConfig;
public MesProductPlanServiceImpl(Repository<MesProductPlan> rep, AppConfig appConfig):base(rep)
{
_appConfig = appConfig;
}
/// <summary>
/// 获取MES生产计划
/// </summary>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public List<MesProductPlan> GetMesProductPlans()
{
try
{
return base._rep.GetList(x => x.StationId == _appConfig.stationId && x.PlanStatus != PlanStatusEnum.);
}
catch (Exception ex)
{
throw new InvalidOperationException($"获取MES生产计划异常{ex.Message}");
}
}
/// <summary>
/// 根据计划编号获取生产计划
/// </summary>
/// <param name="planCode"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public MesProductPlan GetProdPlanByPlanCode(string planCode)
{
try
{
return base._rep.GetFirst(x => x.PlanCode == planCode && x.StationId == _appConfig.stationId);
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据计划编号获取生产计划异常:{ex.Message}");
}
}
/// <summary>
/// 获取已开始的第一条生产计划
/// </summary>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public MesProductPlan GetStartedProdPlan(out MesProductPlanDto productPlanDto)
{
try
{
productPlanDto = base._rep.AsQueryable()
.LeftJoin<MesProductOrder>((plan, order) => plan.ProductOrderId == order.ProductOrderId)
.LeftJoin<BaseMaterialInfo>((plan, order, material) => plan.MaterialId == material.MaterialId)
.Where(plan => plan.StationId == _appConfig.stationId && plan.PlanStatus == PlanStatusEnum.)
.Select((plan, order, material) => new MesProductPlanDto
{
PlanId = plan.PlanId,
PlanCode = plan.PlanCode,
MaterialId = plan.MaterialId,
PlanAmount = plan.PlanAmount,
CompleteAmount = plan.CompleteAmount,
PlanBeginTime = plan.PlanBeginTime,
PlanEndTime = plan.PlanEndTime,
RealBeginTime = plan.RealBeginTime,
RealEndTime = plan.RealEndTime,
PlanStatus = plan.PlanStatus,
OrderCode = order.OrderCode,
SaleOrderId = order.SaleOrderId,
SaleorderCode = order.SaleorderCode,
SaleorderLinenumber = order.SaleorderLinenumber,
ProjectNo = order.ProjectNo,
MaterialName = material.MaterialName,
MaterialCategories = material.MaterialCategories,
MaterialSubclass = material.MaterialSubclass,
MaterialTypeId = material.MaterialTypeId,
BatchFlag = material.BatchFlag,
MaterialUnit = material.MaterialUnit,
MaterialUnitId = material.MaterialUnitId,
}).First();
return base._rep.GetFirst(x => x.StationId == _appConfig.stationId && x.PlanStatus == PlanStatusEnum.);
}
catch (Exception e)
{
throw new InvalidOperationException($"获取已开始的第一条生产计划异常:{e.Message}");
}
}
/// <summary>
/// 根据订单编号获取生产计划
/// </summary>
/// <param name="orderId"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public List<MesProductPlan> GetProdPlansByOrderCode(int orderId)
{
try
{
return base._rep.GetList(x => x.ProductOrderId == orderId && x.StationId == _appConfig.stationId);
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据订单编号获取生产计划异常:{ex.Message}");
}
}
/// <summary>
/// 更新计划信息
/// </summary>
/// <param name="prodPlan"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public bool UpdateProdPlan(MesProductPlan prodPlan)
{
try
{
return base._rep.Update(prodPlan);
}
catch (Exception ex)
{
throw new InvalidOperationException($"更新计划信息异常:{ex.Message}");
}
}
/// <summary>
/// 获取MES计划详细信息
/// </summary>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public List<MesProductPlanDto> GetPlanDtos()
{
try
{
var info = base._rep.AsQueryable()
.LeftJoin<MesProductOrder>((plan, order) => plan.ProductOrderId == order.ProductOrderId)
.LeftJoin<BaseMaterialInfo>((plan, order, material) => plan.MaterialId == material.MaterialId)
.Where(plan => plan.StationId == _appConfig.stationId && plan.PlanStatus != PlanStatusEnum.)
.Select((plan, order, material) => new MesProductPlanDto
{
PlanId = plan.PlanId,
PlanCode = plan.PlanCode,
MaterialId = plan.MaterialId,
PlanAmount = plan.PlanAmount,
CompleteAmount = plan.CompleteAmount,
PlanBeginTime = plan.PlanBeginTime,
PlanEndTime = plan.PlanEndTime,
RealBeginTime = plan.RealBeginTime,
RealEndTime = plan.RealEndTime,
PlanStatus = plan.PlanStatus,
OrderCode = order.OrderCode,
SaleOrderId = order.SaleOrderId,
SaleorderCode = order.SaleorderCode,
SaleorderLinenumber = order.SaleorderLinenumber,
ProjectNo = order.ProjectNo,
MaterialName = material.MaterialName,
MaterialCategories = material.MaterialCategories,
MaterialSubclass = material.MaterialSubclass,
MaterialTypeId = material.MaterialTypeId,
BatchFlag = material.BatchFlag,
MaterialUnit = material.MaterialUnit,
MaterialUnitId = material.MaterialUnitId,
}).ToList();
return info;
}catch(Exception ex)
{
throw new InvalidOperationException($"获取MES计划详细信息异常:{ex.Message}");
}
}
}
}