|
|
|
|
using Aucma.Scada.Model.domain;
|
|
|
|
|
using HighWayIot.Config;
|
|
|
|
|
using HighWayIot.Log4net;
|
|
|
|
|
using HighWayIot.Repository.service;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Aucma.Scada.Business
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 组装计划业务逻辑
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class AssemblyPlanBusiness
|
|
|
|
|
{
|
|
|
|
|
#region 单例实现
|
|
|
|
|
private static readonly Lazy<AssemblyPlanBusiness> lazy = new Lazy<AssemblyPlanBusiness>(() => new AssemblyPlanBusiness());
|
|
|
|
|
public static AssemblyPlanBusiness Instance
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return lazy.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 对象引用
|
|
|
|
|
|
|
|
|
|
private LogHelper logHelper = LogHelper.Instance;
|
|
|
|
|
|
|
|
|
|
private AppConfig appConfig = AppConfig.Instance;
|
|
|
|
|
|
|
|
|
|
private RegisterServices registerServices = RegisterServices.Instance;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 接口引用
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生产计划
|
|
|
|
|
/// </summary>
|
|
|
|
|
private IProductPlanInfoService _productPlanInfoService;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 执行计划
|
|
|
|
|
/// </summary>
|
|
|
|
|
private IExecutePlanInfoService _executePlanInfoService;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// BOM信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
private IBaseBomInfoService _bomInfoService;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 货道明细
|
|
|
|
|
/// </summary>
|
|
|
|
|
private IBaseSpaceDetailService _spaceDetailService;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 委托事件
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 刷新执行计划
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="taskInfos"></param>
|
|
|
|
|
public delegate void RefreshExecutePlanInfo(List<ExecutePlanInfo> executePlanInfos);
|
|
|
|
|
public event RefreshExecutePlanInfo RefreshExecutePlanInfoEvent;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下传执行计划
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="planInfo"></param>
|
|
|
|
|
public delegate void NextPassExecutePlanInfo(ExecutePlanInfo planInfo);
|
|
|
|
|
public event NextPassExecutePlanInfo NextPassExecutePlanInfoEvent;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private AssemblyPlanBusiness()
|
|
|
|
|
{
|
|
|
|
|
_productPlanInfoService = registerServices.GetService<IProductPlanInfoService>();
|
|
|
|
|
_executePlanInfoService = registerServices.GetService<IExecutePlanInfoService>();
|
|
|
|
|
_bomInfoService = registerServices.GetService<IBaseBomInfoService>();
|
|
|
|
|
_spaceDetailService = registerServices.GetService<IBaseSpaceDetailService>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据产线工位编号获取生产计划
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="productLineCode"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<ProductPlanInfo> GetProductPlanInfosByProductLineCode(string orderCode)
|
|
|
|
|
{
|
|
|
|
|
List<ProductPlanInfo> productPlanInfos = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
productPlanInfos = _productPlanInfoService.GetProductPlanInfosByProductLineCode(appConfig.stationCode);
|
|
|
|
|
|
|
|
|
|
if(productPlanInfos.Count>0 )
|
|
|
|
|
{
|
|
|
|
|
if(!string.IsNullOrEmpty(orderCode))
|
|
|
|
|
{
|
|
|
|
|
productPlanInfos = productPlanInfos.Where(x=>x.orderCode.Contains(orderCode)).ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error("根据产线工位编号获取生产计划异常", ex);
|
|
|
|
|
}
|
|
|
|
|
return productPlanInfos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据产线工位编号获取执行计划
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<ExecutePlanInfo> GetEexecutePlanInfosByProductLineCode()
|
|
|
|
|
{
|
|
|
|
|
List<ExecutePlanInfo> planInfos = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
planInfos = _executePlanInfoService.GetExecutePlanInfosByProductLineCode(appConfig.stationCode).OrderBy(x => x.executeOrder).ToList();
|
|
|
|
|
if (planInfos != null)
|
|
|
|
|
{
|
|
|
|
|
//for(int i = 0; i < planInfos.Count; i++)
|
|
|
|
|
//{
|
|
|
|
|
// planInfos[i].executeOrder = i + 1;
|
|
|
|
|
//}
|
|
|
|
|
//_executePlanInfoService.UpdateRangeExecutePlanInfo(planInfos);
|
|
|
|
|
planInfos = planInfos.Where(x => x.executeStatus != 3).ToList();
|
|
|
|
|
RefreshExecutePlanInfoEvent?.Invoke(planInfos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error("根据产线工位编号获取执行计划异常", ex);
|
|
|
|
|
}
|
|
|
|
|
return planInfos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 判断库存
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="planInfo">生产计划</param>
|
|
|
|
|
/// <param name="transmitAmount">下达数量</param>
|
|
|
|
|
/// <param name="materialType">BOM类型</param>
|
|
|
|
|
/// <param name="storeCode"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool JudgmentStock(ProductPlanInfo planInfo,int transmitAmount, string materialType,string storeCode)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// var shellBomInfo = _bomInfoService.GetChildenBomInfoByMaterialCode(planInfo.materialCode, materialType);
|
|
|
|
|
var shellBomInfo = _bomInfoService.GetBomInfoByMaterialCode(planInfo.materialCode);
|
|
|
|
|
if (shellBomInfo != null)
|
|
|
|
|
{
|
|
|
|
|
materialType = shellBomInfo.materialCode;
|
|
|
|
|
|
|
|
|
|
List<BaseSpaceDetail> spaceDetails = _spaceDetailService.GetSpaceDetailsByMaterialType(storeCode, materialType);
|
|
|
|
|
|
|
|
|
|
if (spaceDetails.Count >= transmitAmount)
|
|
|
|
|
{
|
|
|
|
|
result = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error("计划下达判断库存异常", ex);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据生产计划下达执行计划
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="productPlanCode"></param>
|
|
|
|
|
/// <param name="transmitAmount"></param>
|
|
|
|
|
public bool PlanTransmitByProductPlan(string productPlanCode, int transmitAmount)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var productPlanInfo = _productPlanInfoService.GetProductPlanByPlanCode(productPlanCode);
|
|
|
|
|
if (productPlanInfo != null)
|
|
|
|
|
{
|
|
|
|
|
ExecutePlanInfo executePlanInfo = new ExecutePlanInfo();
|
|
|
|
|
executePlanInfo.executePlanCode = System.Guid.NewGuid().ToString("N");
|
|
|
|
|
executePlanInfo.productPlanCode = productPlanInfo.planCode;
|
|
|
|
|
executePlanInfo.productLineCode = productPlanInfo.productLineCode;
|
|
|
|
|
executePlanInfo.orderCode = productPlanInfo.orderCode;
|
|
|
|
|
executePlanInfo.materialCode = productPlanInfo.materialCode;
|
|
|
|
|
executePlanInfo.materialName = productPlanInfo.materialName;
|
|
|
|
|
executePlanInfo.executeOrder = _executePlanInfoService.GetExecuteOrderByProductLineCode(appConfig.stationCode);
|
|
|
|
|
executePlanInfo.executeStatus = 1;
|
|
|
|
|
executePlanInfo.planAmount = transmitAmount;
|
|
|
|
|
executePlanInfo.createdTime = DateTime.Now;
|
|
|
|
|
result = _executePlanInfoService.InsertExecutePlanInfo(executePlanInfo);
|
|
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
GetEexecutePlanInfosByProductLineCode();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error("根据生产计划下达执行计划异常", ex);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 执行计划上移
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="executePlanCode"></param>
|
|
|
|
|
public void ExecutePlanInfo_MoveUp(List<ExecutePlanInfo> executePlanInfos, string executePlanCode)
|
|
|
|
|
{
|
|
|
|
|
List<ExecutePlanInfo> executePlans = new List<ExecutePlanInfo>();
|
|
|
|
|
if (executePlanInfos != null)
|
|
|
|
|
{
|
|
|
|
|
ExecutePlanInfo planInfo = executePlanInfos.Where(x => x.executePlanCode == executePlanCode).First();
|
|
|
|
|
int executeOrder = planInfo.executeOrder;
|
|
|
|
|
int planIndex = executePlanInfos.IndexOf(planInfo);
|
|
|
|
|
if (planIndex != -1 && planIndex != 0)
|
|
|
|
|
{
|
|
|
|
|
var lastPlanInfo = executePlanInfos[planIndex - 1];
|
|
|
|
|
planInfo.executeOrder = lastPlanInfo.executeOrder;
|
|
|
|
|
lastPlanInfo.executeOrder = executeOrder;
|
|
|
|
|
executePlans.Add(planInfo);
|
|
|
|
|
executePlans.Add(lastPlanInfo);
|
|
|
|
|
var result = _executePlanInfoService.UpdateRangeExecutePlanInfo(executePlans);
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
GetEexecutePlanInfosByProductLineCode();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 执行计划下移
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="executePlanCode"></param>
|
|
|
|
|
public void ExecutePlanInfo_MoveDown(List<ExecutePlanInfo> executePlanInfos, string executePlanCode)
|
|
|
|
|
{
|
|
|
|
|
List<ExecutePlanInfo> executePlans = new List<ExecutePlanInfo>();
|
|
|
|
|
if (executePlanInfos != null)
|
|
|
|
|
{
|
|
|
|
|
ExecutePlanInfo planInfo = executePlanInfos.Where(x => x.executePlanCode == executePlanCode).First();
|
|
|
|
|
int executeOrder = planInfo.executeOrder;
|
|
|
|
|
int planIndex = executePlanInfos.IndexOf(planInfo);
|
|
|
|
|
if (planIndex != executePlanInfos.Count - 1)
|
|
|
|
|
{
|
|
|
|
|
var lastPlanInfo = executePlanInfos[planIndex + 1];
|
|
|
|
|
planInfo.executeOrder = lastPlanInfo.executeOrder;
|
|
|
|
|
lastPlanInfo.executeOrder = executeOrder;
|
|
|
|
|
executePlans.Add(planInfo);
|
|
|
|
|
executePlans.Add(lastPlanInfo);
|
|
|
|
|
var result = _executePlanInfoService.UpdateRangeExecutePlanInfo(executePlans);
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
GetEexecutePlanInfosByProductLineCode();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据执行计划编号删除执行计划
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="planCode"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool ExecutePlanInfo_Delete(string planCode)
|
|
|
|
|
{
|
|
|
|
|
bool result = _executePlanInfoService.DeleteExecutePlanInfoByPlanCode(planCode);
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
GetEexecutePlanInfosByProductLineCode();
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下传计划
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="planCode"></param>
|
|
|
|
|
public ExecutePlanInfo ExecutePlanInfo_NextPass(string planCode, string nowPlanCode)
|
|
|
|
|
{
|
|
|
|
|
ExecutePlanInfo planInfo = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
List<ExecutePlanInfo> planInfos = new List<ExecutePlanInfo>();
|
|
|
|
|
if (!string.IsNullOrEmpty(nowPlanCode))
|
|
|
|
|
{
|
|
|
|
|
ExecutePlanInfo nowPlanInfo = _executePlanInfoService.GetExecutePlanInfoByPlanCode(nowPlanCode);
|
|
|
|
|
if (nowPlanInfo != null)
|
|
|
|
|
{
|
|
|
|
|
nowPlanInfo.executeStatus = 1;
|
|
|
|
|
planInfos.Add(nowPlanInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取执行计划
|
|
|
|
|
planInfo = _executePlanInfoService.GetExecutePlanInfoByPlanCode(planCode);
|
|
|
|
|
if (planInfo != null)
|
|
|
|
|
{
|
|
|
|
|
//传给出库
|
|
|
|
|
NextPassExecutePlanInfoEvent?.Invoke(planInfo);
|
|
|
|
|
|
|
|
|
|
planInfo.executeStatus = 2;
|
|
|
|
|
planInfo.beginTime = DateTime.Now;
|
|
|
|
|
planInfos.Add(planInfo);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logHelper.Info($"执行计划下传失败,执行计划编号:{planCode}未获取到执行计划");
|
|
|
|
|
return planInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (planInfos.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var result = _executePlanInfoService.UpdateRangeExecutePlanInfo(planInfos);
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
GetEexecutePlanInfosByProductLineCode();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logHelper.Error("计划下传异常", ex);
|
|
|
|
|
}
|
|
|
|
|
return planInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取小时产量
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<dynamic> GetHourAmount()
|
|
|
|
|
{
|
|
|
|
|
return _executePlanInfoService.GetStationHourAmount(appConfig.stationCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取物料型号统计
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<dynamic> GetMaterialStats()
|
|
|
|
|
{
|
|
|
|
|
return _executePlanInfoService.GetStationMaterialStats(appConfig.stationCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|