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.

219 lines
9.0 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 保留所有权利。
* CLR版本4.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);
}
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,order) =>
plan.PlanStatus == PlanStatusEnum. &&
(order.DispatchId == 2)
)
.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值使用out MesProductPlanDto productPlanDto
return null;
}
catch (Exception e)
{
productPlanDto = null;
return null;
//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
{
// plan.StationId == _appConfig.stationId &&
var info = base._rep.AsQueryable()
.LeftJoin<MesProductOrder>((plan, order) => plan.ProductOrderId == order.ProductOrderId)
.LeftJoin<BaseMaterialInfo>((plan, order, material) => plan.MaterialId == material.MaterialId)
.Where((plan, order) =>
plan.PlanStatus != PlanStatusEnum. &&
(order.DispatchId ==2))
.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}");
}
}
}
}