using Rhea.Common;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using Tiger.IBusiness;
|
using Tiger.IBusiness.MES.WorkAction;
|
using Tiger.Model;
|
using Tiger.Model.Entitys.MES.Position;
|
using Tiger.Model.MES.Yada;
|
|
namespace Tiger.Business.MES.WorkAction
|
{
|
public class PackageInputCheck : IPackageInputCheck
|
{
|
#region Propertys & Variables
|
#region 固定写法,工序中的必要信息
|
public bool IsFinished { get; set; } = false;
|
public IWorkStep CurStep { get; set; }
|
public IPosition CurPosition { get; set; }
|
public MES_WO_NODE_ACT NodeAct { get; set; }
|
public MES_WO_ACTION Setting { get; set; }
|
#endregion
|
public MES_CUST_SN FlowCSN { get; set; }
|
public BAS_LABEL_TEMP Label { get; set; }
|
public List<BAS_LABEL_PV> LabelPV { get; set; }
|
public List<mes_MOPickList> MoPickList { get; set; }
|
public BAS_ITEM_CUST CustInfo { get; set; }
|
#endregion Propertys & Variables
|
|
#region Functions
|
/// <summary>
|
/// 初始化工序行为
|
/// </summary>
|
/// <returns></returns>
|
public void Init(IWorkStep curStep, IPosition position, MES_WO_NODE_ACT nodeAct, MES_WO_ACTION setting)
|
{
|
#region 固定写法,给默认变量赋值
|
CurStep = curStep;
|
CurPosition = position;
|
NodeAct = nodeAct;
|
Setting = setting;
|
#endregion
|
|
//获取打印模板
|
Label = Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(q => q.LABEL_CODE == setting.LABEL_CODE).IncludesAllFirstLayer().First();
|
LabelPV = Biz.Db.Queryable<BAS_LABEL_PV>().ToList();
|
|
//获取当前产品在当前客户的关系
|
CustInfo = Biz.Db.Queryable<BAS_ITEM_CUST>().Where(q => q.ITEM_ID == CurPosition.WorkBatch.WO.ItemInfo.ID && q.CUST_CODE == CurPosition.WorkBatch.WO.CUST_CODE).First();
|
|
CurStep.Message = Biz.L("扫描厂内条码或客户条码");
|
CurStep.Status = StepStatus.Normal;
|
}
|
|
/// <summary>
|
/// 获取行为开始的提示信息
|
/// </summary>
|
/// <returns></returns>
|
public Locale GetBeginMsg()
|
{
|
var msg = new Locale("MES.WorkAction.PackageInputCheck.BeginMsg", CurPosition.CurSN, CurPosition.WorkBatch.WO.ORDER_NO);
|
//var msg = new Locale($"开始检查条码[{0}]是否可以在工单[{1}]投料生产");
|
return msg;
|
}
|
|
/// <summary>
|
/// 尝试开始执行工序行为
|
/// </summary>
|
/// <returns></returns>
|
public ApiAction<SubmitOutput> TryBegin(SubmitInput input)
|
{
|
var action = Submit(input);
|
|
//如果返回成功则认为当前行为可以开始执行,否则返回失败
|
//action.IsSuccessed = true;
|
|
return action;
|
}
|
|
/// <summary>
|
/// 工序行为提交数据
|
/// </summary>
|
/// <returns></returns>
|
public ApiAction<SubmitOutput> Submit(SubmitInput input)
|
{
|
var action = new ApiAction<SubmitOutput>(new SubmitOutput());
|
|
//获取工单备料信息
|
MoPickList = Biz.DataSource["YadaU9C"].Client.Queryable<mes_MOPickList>().Where(q => q.MoDocNo == CurPosition.WorkBatch.WO.ORDER_NO).ToList();
|
|
//只允许单个产品进行客户条码绑定
|
if (CurPosition.CurWipSNs.Count > 1)
|
{
|
CurStep.Message = Biz.L("扫描厂内条码或客户条码");
|
CurStep.Status = StepStatus.Error;
|
action.Data.ShortMsg = new("扫描厂内条码或客户条码", ShortMessage.Types.Error);
|
action.IsSuccessed = false;
|
//action.LocaleMsg = new($"条码[{0}]是包装/载具条码,请重新扫描单个厂内条码进行客户条码绑定");
|
action.LocaleMsg = new("MES.WorkAction.PackageInputCheck.NotProductSN", CurPosition.CurSN);
|
//重置工序操作
|
CurPosition.ResetNode();
|
|
return action;
|
}
|
|
var wipSn = CurPosition.CurWipSNs.First();
|
FlowCSN = Biz.Db.Queryable<MES_CUST_SN>().Where(q => q.FLOW_SN == wipSn.SN || q.CUST_SN == wipSn.SN).First();
|
//找不到生产记录,认为扫描错误
|
if (FlowCSN.IsNullOrEmpty())
|
{
|
CurStep.Message = Biz.L("投料错误");
|
CurStep.Status = StepStatus.Error;
|
action.Data.ShortMsg = new("投料错误", ShortMessage.Types.Failed);
|
action.IsSuccessed = false;
|
//action.LocaleMsg = new($"投料错误,找不到条码[{0}]的生产记录");
|
action.LocaleMsg = new("MES.WorkAction.PackageInputCheck.InputSnError", wipSn.SN);
|
//重置工序操作
|
CurPosition.ResetNode();
|
return action;
|
}
|
else
|
{
|
//厂内条码已绑定
|
if (FlowCSN.IsBound || FlowCSN.IsFlowSn)
|
{
|
//物料料号是当前工单料号或者在工单备料表中,直接结束行为
|
if (FlowCSN.ITEM_CODE == CurPosition.WorkBatch.WO.ITEM_CODE || MoPickList.Any(q => q.Code == FlowCSN.ITEM_CODE))
|
{
|
action = End(input);
|
return action;
|
}
|
else
|
{
|
CurStep.Message = Biz.L("投料错误");
|
CurStep.Status = StepStatus.Error;
|
action.Data.ShortMsg = new("投料错误", ShortMessage.Types.Failed);
|
action.IsSuccessed = false;
|
//action.LocaleMsg = new($"产品(厂内条码[{0}])不适用于当前工单[{1}]的生产");
|
action.LocaleMsg = new("MES.WorkAction.PackageInputCheck.InputSnOrderError", FlowCSN.FLOW_SN, CurPosition.WorkBatch.WO.ORDER_NO);
|
//重置工序操作
|
CurPosition.ResetNode();
|
return action;
|
}
|
}
|
//厂内条码未绑定客户条码
|
else
|
{
|
action.Data.Data = new
|
{
|
NeedPrint = false,
|
NeedScan = false,
|
Label = "",
|
};
|
CurStep.Message = Biz.L("扫描厂内条码");
|
CurStep.Status = StepStatus.Error;
|
action.Data.ShortMsg = new("扫描厂内条码", ShortMessage.Types.Failed);
|
action.IsSuccessed = false;
|
//action.LocaleMsg = new($"客户条码[{0}]未被绑定,请先扫描厂内条码");
|
action.LocaleMsg = new("MES.WorkAction.PackageInputCheck.PleaseScanFlowSn", wipSn.SN);
|
//重置工序操作
|
CurPosition.ResetNode();
|
return action;
|
}
|
|
}
|
|
return action;
|
}
|
/// <summary>
|
/// 结束执行工序行为
|
/// </summary>
|
/// <returns></returns>
|
public ApiAction<SubmitOutput> End(SubmitInput input)
|
{
|
var action = new ApiAction<SubmitOutput>(new SubmitOutput());
|
|
//更新厂内流程码
|
FlowCSN.CUST_CODE = CurPosition.WorkBatch.WO.CUST_CODE;
|
FlowCSN.WORK_ORDER = CurPosition.WorkBatch.WO.ORDER_NO;
|
FlowCSN.ITEM_CODE = CurPosition.WorkBatch.WO.ITEM_CODE;
|
|
//记录行为操作记录
|
var wipActs = new List<MES_WIP_ACT>();
|
var woSns = new List<BIZ_MES_WO_SN>();
|
var snHiss = new List<MES_WIP_HIS>();
|
foreach (var wipSn in CurPosition.CurWipSNs)
|
{
|
//更新在制品信息SN为客户条码
|
wipSn.SN = FlowCSN.CUST_SN;
|
wipSn.FLOW_SN = FlowCSN.FLOW_SN;
|
//更新在制品信息历史得SN为客户条码
|
var his = CurPosition.CurWipSNHiss.First(q => q.WIP_ID == wipSn.ID);
|
his.SN = FlowCSN.CUST_SN;
|
his.FLOW_SN = FlowCSN.FLOW_SN;
|
snHiss.Add(his);
|
//更新工单条码表的
|
var woSn = CurPosition.WorkBatch.WoSNs.First(q => q.WIP_ID == wipSn.ID);
|
woSn.SN = FlowCSN.CUST_SN;
|
woSn.FLOW_SN = FlowCSN.FLOW_SN;
|
woSns.Add(woSn);
|
var wipAct = new MES_WIP_ACT()
|
{
|
AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG,
|
AUTH_PROD = CurPosition.CurLine.LINE_CODE,
|
HIS_ID = CurPosition.CurWipSNHiss.First(q => q.SN == wipSn.SN).ID,
|
WIP_ID = wipSn.ID,
|
SN = wipSn.SN,
|
STATUS = wipSn.STATUS,
|
ITEM_CODE = wipSn.ITEM_CODE,
|
WORK_ORDER = wipSn.WORK_ORDER,
|
BATCH_NO = wipSn.BATCH_NO,
|
ROT_CODE = wipSn.ROT_CODE,
|
NODE_ID = wipSn.NODE_ID,
|
NODE_NAME = wipSn.NODE_NAME,
|
ACT_ID = NodeAct.ID,
|
ACT_NAME = NodeAct.ACT_NAME,
|
FTY_CODE = wipSn.FTY_CODE,
|
WS_CODE = wipSn.WS_CODE,
|
LINE_CODE = wipSn.LINE_CODE,
|
POST_CODE = wipSn.POST_CODE,
|
OPER_CODE = wipSn.OPER_CODE,
|
SEGMENT = wipSn.SEGMENT,
|
FLOW_SN = wipSn.FLOW_SN,
|
TRAY_SN = wipSn.TRAY_SN,
|
INNER_SN = wipSn.INNER_SN,
|
CARTON_SN = wipSn.CARTON_SN,
|
PALLET_SN = wipSn.PALLET_SN,
|
OPERATION_TIME = DateTime.Now,
|
SFTS_CODE = wipSn.SFTS_CODE,
|
SFT_CODE = wipSn.SFT_CODE,
|
PRD_CODE = wipSn.PRD_CODE,
|
ACT_TYPE = NodeAct.ACT_TYPE,
|
ACT_SN = wipSn.SN,
|
ACT_VALUE_1 = Label.LABEL_CODE,
|
ACT_VALUE_2 = Label.Variables.ToJson(),
|
ACT_RESULT = "Y",
|
TRACE_INFO = $"条码[{wipSn.SN}]可以在工单[{wipSn.WORK_ORDER}]投料生产",
|
};
|
wipActs.Add(wipAct);
|
}
|
|
//创建变量克隆对象用于传入DBSubmitAction中保存当前需要暂存的数据值
|
var _wipSns = CurPosition.CurWipSNs.Clone();
|
var _snHiss = snHiss.Clone();
|
var _woSns = woSns.Clone();
|
var _wipActs = wipActs.Clone();
|
var _FlowCSN = FlowCSN.Clone();
|
//保存数据
|
CurStep.DBSubmitAction = () =>
|
{
|
var db = CurPosition.GetCommitDB();
|
db.Storageable(_wipSns, CurPosition.UserCode).ExecuteCommand();
|
db.Storageable(_snHiss, CurPosition.UserCode).ExecuteCommand();
|
db.Storageable(_woSns, CurPosition.UserCode).ExecuteCommand();
|
db.Storageable(_wipActs, CurPosition.UserCode).ExecuteCommand();
|
db.Storageable(_FlowCSN, CurPosition.UserCode).ExecuteCommand();
|
};
|
|
IsFinished = true;
|
CurStep.Message = Biz.L("投料检查成功");
|
CurStep.Status = StepStatus.Finished;
|
action.Data.ShortMsg = new("投料检查成功", ShortMessage.Types.Success);
|
//action.LocaleMsg = new($"条码[{0}]可以在工单[{1}]投入生产");
|
action.LocaleMsg = new("MES.WorkAction.PackageInputCheck.BindingComplete", FlowCSN.FLOW_SN, FlowCSN.WORK_ORDER);
|
return action;
|
}
|
|
#endregion Functions
|
}
|
}
|