|
|
|
@ -52,6 +52,8 @@ namespace SlnMesnac.Business
|
|
|
|
|
public class ProdCompletionBusiness : BaseBusiness
|
|
|
|
|
{
|
|
|
|
|
private FJ500Comm.FJ500SP fj500s = new FJ500Comm.FJ500SP();
|
|
|
|
|
//喷码机喷码失败或者设备状态检查重试次数
|
|
|
|
|
private int PmTryAmount = 0;
|
|
|
|
|
private readonly IMesProductPlanService _mesProductPlanService;
|
|
|
|
|
private readonly IMesProductOrderService _mesProductOrderService;
|
|
|
|
|
private readonly IMesPrdBarCodeService _barCodeTaskService;
|
|
|
|
@ -59,11 +61,13 @@ namespace SlnMesnac.Business
|
|
|
|
|
private readonly IMesBaseBarcodeInfoService _mesBaseBarcodeInfoService;
|
|
|
|
|
public readonly IMesPrdBarCodeService _mesPrdBarCodeService;
|
|
|
|
|
private readonly IRealPalletTaskService _realPalletTaskService;
|
|
|
|
|
|
|
|
|
|
private readonly UdpServer udpServer;
|
|
|
|
|
private DebugConfig debugConfig = DebugConfig.Instance;
|
|
|
|
|
private ISqlSugarClient sqlSugarClient;
|
|
|
|
|
|
|
|
|
|
public ProdCompletionBusiness(ISqlSugarClient _sqlSugarClient, ILogger<BaseBusiness> logger, AppConfig appConfig, List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories, IMesProductPlanService mesProductPlanService, IMesPrdBarCodeService barCodeTaskService, IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
udpServer = serviceProvider.GetRequiredService<UdpServer>();
|
|
|
|
|
UdpServer.ReceivedPMCodeEvent += PmCodeHandler;
|
|
|
|
|
sqlSugarClient = _sqlSugarClient;
|
|
|
|
|
_mesProductPlanService = mesProductPlanService;
|
|
|
|
@ -74,16 +78,16 @@ namespace SlnMesnac.Business
|
|
|
|
|
_mesProductOrderService = serviceProvider.GetRequiredService<IMesProductOrderService>();
|
|
|
|
|
_baseMaterialInfoService = serviceProvider.GetRequiredService<IBaseMaterialInfoService>();
|
|
|
|
|
Init();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void test()
|
|
|
|
|
{
|
|
|
|
|
// MesProductPlanDetail? mesProductPlanDetail = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<MesProductPlanDetail>().First(x => x.PlanCode == "20240724144533JL001");
|
|
|
|
|
string epc = "A123456";
|
|
|
|
|
_mesProductPlanService.GetStartedProdPlan(out MesProductPlanDto productPlanDto);
|
|
|
|
|
string bigCode = GenerateBigBarcode(productPlanDto, epc);
|
|
|
|
|
// BindingBarCode(bigCode, epc);
|
|
|
|
|
// MesProductPlanDetail? mesProductPlanDetail = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<MesProductPlanDetail>().First(x => x.PlanCode == "20240724144533JL001");
|
|
|
|
|
// string epc = "A123456";
|
|
|
|
|
//_mesProductPlanService.GetStartedProdPlan(out MesProductPlanDto productPlanDto);
|
|
|
|
|
// string bigCode = GenerateBigBarcode(productPlanDto, epc);
|
|
|
|
|
// BindingBarCode(bigCode, epc);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -94,7 +98,7 @@ namespace SlnMesnac.Business
|
|
|
|
|
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
await EmptyPalletHandle();
|
|
|
|
|
await EmptyPalletHandle();
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
Task.Run(() =>
|
|
|
|
@ -102,8 +106,40 @@ namespace SlnMesnac.Business
|
|
|
|
|
DeviceOutPutHandle();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//喷码机设备状态检查
|
|
|
|
|
checkPmStatus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 喷码机设备相关通讯
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 喷码机状态检查
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void checkPmStatus()
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//发送检查状态指令
|
|
|
|
|
// udpServer.SendMessage(fj500s.CheckState());
|
|
|
|
|
// Thread.Sleep(1000 * 5);
|
|
|
|
|
// 重新发送带喷印条码,保证始终有条码
|
|
|
|
|
SendFirstPmCode();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError("checkStatus异常:" + ex.Message);
|
|
|
|
|
}
|
|
|
|
|
Thread.Sleep(1000 * 30);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 喷码机返回信息解析处理
|
|
|
|
|
/// 1.传输完成及喷码完成
|
|
|
|
@ -112,37 +148,91 @@ namespace SlnMesnac.Business
|
|
|
|
|
/// <param name="str"></param>
|
|
|
|
|
private void PmCodeHandler(string str)
|
|
|
|
|
{
|
|
|
|
|
//设备状态30s一次
|
|
|
|
|
if (str.Substring(0, 4) == "0A0C")
|
|
|
|
|
{
|
|
|
|
|
//推送最新需要打印条码,防止无可打印条码
|
|
|
|
|
|
|
|
|
|
var result = fj500s.GetState(str);
|
|
|
|
|
if (result == "0E")
|
|
|
|
|
{ // 喷码机设备故障,todo 推送报警
|
|
|
|
|
_logger.LogError("喷码机设备故障,待推送报警");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // 传输完成及喷码完成结果
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int LastTryAmount = PmTryAmount;
|
|
|
|
|
var result = fj500s.GetAck(str);
|
|
|
|
|
if(result == "00")
|
|
|
|
|
if (result == "00")
|
|
|
|
|
{
|
|
|
|
|
// 发送数据成功
|
|
|
|
|
_logger.LogInformation("====================收到喷码机发送数据成功");
|
|
|
|
|
PmTryAmount = 0;
|
|
|
|
|
}
|
|
|
|
|
else if(result =="0E")
|
|
|
|
|
else if (result == "0E")
|
|
|
|
|
{
|
|
|
|
|
// 发送数据失败,重新发送,超过10次失败推送报警
|
|
|
|
|
}else if(result == "0F")
|
|
|
|
|
// 喷码机设备故障
|
|
|
|
|
_logger.LogError($"====================收到喷码机设备状态检查故障或者喷印失败预警,喷码机重试次数:{PmTryAmount}");
|
|
|
|
|
PmTryAmount++;
|
|
|
|
|
|
|
|
|
|
if (PmTryAmount <= 30)
|
|
|
|
|
{
|
|
|
|
|
//重新发送
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(1000 * 5);
|
|
|
|
|
SendFirstPmCode();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError("====================超过30次,推送报警");
|
|
|
|
|
AddAlarm(WarnStatusEnum.喷码机设备状态检查故障或者喷印失败预警超过30次);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (result == "0F")
|
|
|
|
|
{
|
|
|
|
|
//打印完成,更新当前打印条码信息,并推送下一条信息
|
|
|
|
|
_logger.LogInformation("====================收到喷码机打印完成,推送下一条待打印条码");
|
|
|
|
|
updatePrdBarcodeInfo();
|
|
|
|
|
SendFirstPmCode();
|
|
|
|
|
_logger.LogInformation("====================推送下一条待打印条码成功");
|
|
|
|
|
PmTryAmount = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (LastTryAmount>0 && PmTryAmount==0)
|
|
|
|
|
{ // 报警消除
|
|
|
|
|
_logger.LogInformation("喷码机报警消除");
|
|
|
|
|
deleteAlarm(WarnStatusEnum.喷码机设备状态检查故障或者喷印失败预警超过30次);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError("PmCodeHandler喷码机回复信息解析处理异常:" + ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取数据库最早未喷印未绑定条码
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void SendFirstPmCode()
|
|
|
|
|
{
|
|
|
|
|
MesPrdBarcodeInfo mesPrdBarcodeInfo = _barCodeTaskService.Query(x => x.PrintFlag == "0" && x.BindStatus == 0).OrderBy(x => x.PrdBarcodeId).FirstOrDefault();
|
|
|
|
|
if(mesPrdBarcodeInfo != null)
|
|
|
|
|
{
|
|
|
|
|
udpServer.SendMessage(mesPrdBarcodeInfo.PrdBarcodeInfo);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError("可喷码数不足,请检查原因");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 喷印完成更新条码
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void updatePrdBarcodeInfo()
|
|
|
|
|
{
|
|
|
|
|
MesPrdBarcodeInfo mesPrdBarcodeInfo = _barCodeTaskService.Query(x => x.PrintFlag == "0" && x.BindStatus == 0).OrderBy(x => x.PrdBarcodeId).FirstOrDefault();
|
|
|
|
|
mesPrdBarcodeInfo.PrintFlag = "1";
|
|
|
|
|
mesPrdBarcodeInfo.PrintTime = DateTime.Now;
|
|
|
|
|
_barCodeTaskService.Update(mesPrdBarcodeInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设备产出逻辑处理
|
|
|
|
|
/// </summary>
|
|
|
|
@ -162,18 +252,18 @@ namespace SlnMesnac.Business
|
|
|
|
|
Thread.Sleep(3000);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// plc.writeStringByAddress(GetPlcAddressByConfigKey("2楼码垛出口RFID条码地址"), "JYHB01010125", 12);
|
|
|
|
|
// plc.writeStringByAddress(GetPlcAddressByConfigKey("2楼码垛出口RFID条码地址"), "JYHB01010125", 12);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!plc.readBoolByAddress(GetPlcAddressByConfigKey("2楼小包出口到位信号")))
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("等待小包出口信号触发......");
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string rfid = plc.readStringByAddress(GetPlcAddressByConfigKey("2楼码垛出口RFID条码地址"),12).Replace("\0","");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string rfid = plc.readStringByAddress(GetPlcAddressByConfigKey("2楼码垛出口RFID条码地址"), 12).Replace("\0", "");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(rfid))
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("小包出口已经有RFID了,无需再读");
|
|
|
|
@ -202,6 +292,7 @@ namespace SlnMesnac.Business
|
|
|
|
|
_logger.LogError("小包出口到位信号触发,读取RFID失败超过5次......");
|
|
|
|
|
if (!string.IsNullOrEmpty(virtualEpc))
|
|
|
|
|
{
|
|
|
|
|
//TODU 虚拟托盘号需要在系统存储
|
|
|
|
|
epcStr = virtualEpc;
|
|
|
|
|
_logger.LogError("小包出口到位信号触发,读取RFID失败超过5次,生成虚拟托盘号:" + virtualEpc);
|
|
|
|
|
}
|
|
|
|
@ -219,8 +310,15 @@ namespace SlnMesnac.Business
|
|
|
|
|
_mesProductPlanService.GetStartedProdPlan(out MesProductPlanDto productPlanDto);
|
|
|
|
|
if (productPlanDto == null)
|
|
|
|
|
{
|
|
|
|
|
//TODO:没有计划的话,处理方式待定
|
|
|
|
|
throw new ArgumentException($"未获取到正在执行的生产计划");
|
|
|
|
|
|
|
|
|
|
//throw new ArgumentException($"未获取到正在执行的生产计划");
|
|
|
|
|
|
|
|
|
|
//无计划时,按照无计划订单处理,MaterialId可修改,在配置文件
|
|
|
|
|
productPlanDto = new MesProductPlanDto();
|
|
|
|
|
productPlanDto.PlanCode = "0";
|
|
|
|
|
productPlanDto.MaterialId = long.Parse(debugConfig.MaterialId);
|
|
|
|
|
productPlanDto.SaleOrderId = 0;
|
|
|
|
|
productPlanDto.SaleorderCode = "0";
|
|
|
|
|
}
|
|
|
|
|
#region 开启事务
|
|
|
|
|
sqlSugarClient.AsTenant().BeginTran();
|
|
|
|
@ -230,17 +328,17 @@ namespace SlnMesnac.Business
|
|
|
|
|
BindingBarCode(bigCode, epcStr, productPlanDto);
|
|
|
|
|
//3.更新mes_product_plan及mes_product_order表,更新已生产数量
|
|
|
|
|
UpdatePlanInfoAndOrder(productPlanDto);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 删除正在使用的数据库托盘号
|
|
|
|
|
List<RealPalletTask> realPalletList = _realPalletTaskService.Query(x => x.PalletCode == epcStr);
|
|
|
|
|
if (realPalletList != null && realPalletList.Count>0)
|
|
|
|
|
if (realPalletList != null && realPalletList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Deleteable(realPalletList).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
// 写入PLC RFID号供调度使用
|
|
|
|
|
plc.writeStringByAddress(GetPlcAddressByConfigKey("2楼码垛出口RFID条码地址"), epcStr,12);
|
|
|
|
|
// plc.writeByteByAddress(GetPlcAddressByConfigKey("2楼小包出口到位信号"), 2);
|
|
|
|
|
plc.writeStringByAddress(GetPlcAddressByConfigKey("2楼码垛出口RFID条码地址"), epcStr, 12);
|
|
|
|
|
// plc.writeByteByAddress(GetPlcAddressByConfigKey("2楼小包出口到位信号"), 2);
|
|
|
|
|
readRfidAmount = 0;
|
|
|
|
|
sqlSugarClient.AsTenant().CommitTran();
|
|
|
|
|
#endregion
|
|
|
|
@ -255,83 +353,7 @@ namespace SlnMesnac.Business
|
|
|
|
|
Thread.Sleep(1000 * 5);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 推送报警,并生成虚拟托盘号暂时使用,虚拟托盘号储存到报警信息,人工处理可以将虚拟托盘号替换为正常托盘号
|
|
|
|
|
/// <return> 返回生产的虚拟托盘号
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string NoReadRFIDAlarm()
|
|
|
|
|
{
|
|
|
|
|
string epcStr;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
epcStr = "TEMP" + DateTime.Now.ToString("MMddHHmm");
|
|
|
|
|
sqlSugarClient.AsTenant().BeginTran();
|
|
|
|
|
|
|
|
|
|
// 有报警,找出该设备的报警记录,如果没有报警记录或者报警记录已结束,则新增报警记录
|
|
|
|
|
int warnRuleId = int.Parse(WarnStatusEnum.小包出口读取RFID失败5次.GetDescription());
|
|
|
|
|
DmsRecordAlarmTime? dmsRecordAlarmTime = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmTime>().First(x => x.AlarmRuleId == warnRuleId);
|
|
|
|
|
if (dmsRecordAlarmTime == null)
|
|
|
|
|
{
|
|
|
|
|
DmsBaseAlarmRule dmsBaseAlarmRule = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsBaseAlarmRule>().First(x => x.AlarmRuleId == warnRuleId);
|
|
|
|
|
|
|
|
|
|
dmsRecordAlarmTime = new DmsRecordAlarmTime();
|
|
|
|
|
dmsRecordAlarmTime.DeviceId = dmsBaseAlarmRule.DeviceId;
|
|
|
|
|
dmsRecordAlarmTime.AlarmRuleId = warnRuleId;
|
|
|
|
|
dmsRecordAlarmTime.AlarmBeginTime = DateTime.Now;
|
|
|
|
|
dmsRecordAlarmTime.ContinueTime = dmsBaseAlarmRule.ContinueTime;
|
|
|
|
|
dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason;
|
|
|
|
|
dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason;
|
|
|
|
|
dmsRecordAlarmTime.AlarmData = WarnStatusEnum.小包出口读取RFID失败5次.ToString();
|
|
|
|
|
dmsRecordAlarmTime.HandleSuggest = dmsBaseAlarmRule.HandleSuggest + ";;虚拟托盘号为:" + epcStr;
|
|
|
|
|
dmsRecordAlarmTime.CreateBy = "SlnMesnac";
|
|
|
|
|
dmsRecordAlarmTime.CreateTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
DmsRecordAlarmInfo dmsRecordAlarmInfo = new DmsRecordAlarmInfo();
|
|
|
|
|
dmsRecordAlarmInfo.DeviceId = dmsBaseAlarmRule.DeviceId;
|
|
|
|
|
dmsRecordAlarmInfo.AlarmRuleId = warnRuleId;
|
|
|
|
|
dmsRecordAlarmInfo.AlarmBeginTime = DateTime.Now;
|
|
|
|
|
dmsRecordAlarmInfo.AlarmStatus = "0";
|
|
|
|
|
dmsRecordAlarmInfo.NoticeStatus = "0";
|
|
|
|
|
dmsRecordAlarmInfo.ContinueTime = dmsBaseAlarmRule.ContinueTime;
|
|
|
|
|
dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason;
|
|
|
|
|
dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason;
|
|
|
|
|
dmsRecordAlarmInfo.AlarmData = WarnStatusEnum.小包出口读取RFID失败5次.ToString();
|
|
|
|
|
dmsRecordAlarmInfo.HandleSuggest = dmsBaseAlarmRule.HandleSuggest + ";;虚拟托盘号为:" + epcStr;
|
|
|
|
|
dmsRecordAlarmInfo.CreateBy = "SlnMesnac";
|
|
|
|
|
dmsRecordAlarmInfo.CreateTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Insertable(dmsRecordAlarmTime).ExecuteCommand();
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Insertable(dmsRecordAlarmInfo).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
dmsRecordAlarmTime.UpdateTime = DateTime.Now;
|
|
|
|
|
dmsRecordAlarmTime.UpdateBy = "SlnMesnac";
|
|
|
|
|
DmsRecordAlarmInfo dmsRecordAlarmInfo = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmInfo>().First(x => x.AlarmRuleId == warnRuleId);
|
|
|
|
|
if (dmsRecordAlarmInfo != null)
|
|
|
|
|
{
|
|
|
|
|
dmsRecordAlarmInfo.UpdateTime = DateTime.Now;
|
|
|
|
|
dmsRecordAlarmInfo.UpdateBy = "SlnMesnac";
|
|
|
|
|
}
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmTime).ExecuteCommand();
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmInfo).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sqlSugarClient.AsTenant().CommitTran();
|
|
|
|
|
return epcStr;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
sqlSugarClient.AsTenant().RollbackTran();
|
|
|
|
|
_logger.LogError($"NoReadRFIDAlarm异常:{ex.Message}");
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生成大条码插入mes_barcode_info;
|
|
|
|
|
/// </summary>
|
|
|
|
@ -357,8 +379,8 @@ namespace SlnMesnac.Business
|
|
|
|
|
mesBaseBarcodeInfo.productionDate = DateTime.Now;
|
|
|
|
|
mesBaseBarcodeInfo.acceptedDate = DateTime.Now;
|
|
|
|
|
mesBaseBarcodeInfo.planCode = productPlanDto.PlanCode;
|
|
|
|
|
MesProductPlanDetail? mesProductPlanDetail = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<MesProductPlanDetail>().First(x=>x.PlanCode== productPlanDto.PlanCode);
|
|
|
|
|
if(mesProductPlanDetail != null)
|
|
|
|
|
MesProductPlanDetail? mesProductPlanDetail = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<MesProductPlanDetail>().First(x => x.PlanCode == productPlanDto.PlanCode);
|
|
|
|
|
if (mesProductPlanDetail != null)
|
|
|
|
|
{
|
|
|
|
|
mesBaseBarcodeInfo.planDetailCode = mesProductPlanDetail.PlanDetailCode;
|
|
|
|
|
}
|
|
|
|
@ -395,8 +417,8 @@ namespace SlnMesnac.Business
|
|
|
|
|
|
|
|
|
|
if (list.Where(x => x.PrintFlag == "1").ToList().Count < 40)
|
|
|
|
|
{
|
|
|
|
|
// TODO推送低级别报警
|
|
|
|
|
PrintLessThan40Alarm();
|
|
|
|
|
// 推送低级别报警
|
|
|
|
|
AddAlarm(WarnStatusEnum.托盘绑定时已喷码数不足40);
|
|
|
|
|
}
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
@ -415,7 +437,7 @@ namespace SlnMesnac.Business
|
|
|
|
|
palletInfo.MaterialId = productPlanDto.MaterialId;
|
|
|
|
|
}
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(palletInfo).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdatePlanInfoAndOrder(MesProductPlanDto productPlanDto)
|
|
|
|
@ -423,12 +445,14 @@ namespace SlnMesnac.Business
|
|
|
|
|
MesProductPlan productPlan = _mesProductPlanService.Query(x => x.PlanCode == productPlanDto.PlanCode).FirstOrDefault();
|
|
|
|
|
if (productPlan == null)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("未找到该生产计划!");
|
|
|
|
|
_logger.LogInformation("未找到该生产计划对应的生产工单!,按照无工单处理,无需更新计划");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
MesProductOrder productOrder = _mesProductOrderService.Query(x => x.ProductOrderId == productPlan.ProductOrderId).FirstOrDefault();
|
|
|
|
|
if (productPlan == null)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("未找到该生产计划对应的生产工单!");
|
|
|
|
|
_logger.LogInformation("未找到该生产计划对应的生产工单!,按照无工单处理,无需更新计划");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#region 更新生产计划
|
|
|
|
|
if (productPlan.CompleteAmount == 0)
|
|
|
|
@ -468,18 +492,20 @@ namespace SlnMesnac.Business
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 报警
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 小包产出绑定托盘,小包喷码数量小于40低级别报警
|
|
|
|
|
/// <return> 返回生产的虚拟托盘号
|
|
|
|
|
///
|
|
|
|
|
/// 插入报警
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void PrintLessThan40Alarm()
|
|
|
|
|
private void AddAlarm(WarnStatusEnum warnStatusEnum)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
sqlSugarClient.AsTenant().BeginTran();
|
|
|
|
|
|
|
|
|
|
// 有报警,找出该设备的报警记录,如果没有报警记录或者报警记录已结束,则新增报警记录
|
|
|
|
|
int warnRuleId = int.Parse(WarnStatusEnum.托盘绑定时已喷码数不足40.GetDescription());
|
|
|
|
|
int warnRuleId = int.Parse(warnStatusEnum.GetDescription());
|
|
|
|
|
DmsRecordAlarmTime? dmsRecordAlarmTime = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmTime>().First(x => x.AlarmRuleId == warnRuleId);
|
|
|
|
|
if (dmsRecordAlarmTime == null)
|
|
|
|
|
{
|
|
|
|
@ -492,7 +518,7 @@ namespace SlnMesnac.Business
|
|
|
|
|
dmsRecordAlarmTime.ContinueTime = dmsBaseAlarmRule.ContinueTime;
|
|
|
|
|
dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason;
|
|
|
|
|
dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason;
|
|
|
|
|
dmsRecordAlarmTime.AlarmData = WarnStatusEnum.托盘绑定时已喷码数不足40.ToString();
|
|
|
|
|
dmsRecordAlarmTime.AlarmData = warnStatusEnum.ToString();
|
|
|
|
|
dmsRecordAlarmTime.HandleSuggest = dmsBaseAlarmRule.HandleSuggest;
|
|
|
|
|
dmsRecordAlarmTime.CreateBy = "SlnMesnac";
|
|
|
|
|
dmsRecordAlarmTime.CreateTime = DateTime.Now;
|
|
|
|
@ -506,7 +532,7 @@ namespace SlnMesnac.Business
|
|
|
|
|
dmsRecordAlarmInfo.ContinueTime = dmsBaseAlarmRule.ContinueTime;
|
|
|
|
|
dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason;
|
|
|
|
|
dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason;
|
|
|
|
|
dmsRecordAlarmInfo.AlarmData = WarnStatusEnum.托盘绑定时已喷码数不足40.ToString();
|
|
|
|
|
dmsRecordAlarmInfo.AlarmData = warnStatusEnum.ToString();
|
|
|
|
|
dmsRecordAlarmInfo.HandleSuggest = dmsBaseAlarmRule.HandleSuggest;
|
|
|
|
|
dmsRecordAlarmInfo.CreateBy = "SlnMesnac";
|
|
|
|
|
dmsRecordAlarmInfo.CreateTime = DateTime.Now;
|
|
|
|
@ -536,12 +562,118 @@ namespace SlnMesnac.Business
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
sqlSugarClient.AsTenant().RollbackTran();
|
|
|
|
|
_logger.LogError($"PrintLessThan40Alarm异常:{ex.Message}");
|
|
|
|
|
_logger.LogError($"插入或者更新报错信息异常{warnStatusEnum.ToString()} ==>:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 消除报警
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <exception cref="InvalidOperationException"></exception>
|
|
|
|
|
private void deleteAlarm(WarnStatusEnum warnStatusEnum)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
DmsRecordAlarmTime? dmsRecordAlarmTime = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmTime>().First(x => x.AlarmRuleId == long.Parse(warnStatusEnum.GetDescription()));
|
|
|
|
|
if (dmsRecordAlarmTime != null)
|
|
|
|
|
{
|
|
|
|
|
sqlSugarClient.AsTenant().BeginTran();
|
|
|
|
|
DmsRecordAlarmInfo dmsRecordAlarmInfo = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmInfo>().First(x => x.AlarmRuleId == dmsRecordAlarmTime.AlarmRuleId && x.AlarmStatus == "0");
|
|
|
|
|
if (dmsRecordAlarmInfo != null)
|
|
|
|
|
{
|
|
|
|
|
dmsRecordAlarmInfo.AlarmEndTime = DateTime.Now;
|
|
|
|
|
dmsRecordAlarmInfo.AlarmStatus = "2";
|
|
|
|
|
dmsRecordAlarmInfo.UpdateTime = DateTime.Now;
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmInfo).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Deleteable(dmsRecordAlarmTime).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
sqlSugarClient.AsTenant().CommitTran();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 推送报警,并生成虚拟托盘号暂时使用,虚拟托盘号储存到报警信息,人工处理可以将虚拟托盘号替换为正常托盘号
|
|
|
|
|
/// <return> 返回生产的虚拟托盘号
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string NoReadRFIDAlarm()
|
|
|
|
|
{
|
|
|
|
|
string epcStr;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
epcStr = "TEMP" + DateTime.Now.ToString("MMddHHmm");
|
|
|
|
|
sqlSugarClient.AsTenant().BeginTran();
|
|
|
|
|
|
|
|
|
|
// 有报警,找出该设备的报警记录,如果没有报警记录或者报警记录已结束,则新增报警记录
|
|
|
|
|
int warnRuleId = int.Parse(WarnStatusEnum.小包出口读取RFID失败5次.GetDescription());
|
|
|
|
|
DmsRecordAlarmTime? dmsRecordAlarmTime = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmTime>().First(x => x.AlarmRuleId == warnRuleId);
|
|
|
|
|
if (dmsRecordAlarmTime == null)
|
|
|
|
|
{
|
|
|
|
|
DmsBaseAlarmRule dmsBaseAlarmRule = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsBaseAlarmRule>().First(x => x.AlarmRuleId == warnRuleId);
|
|
|
|
|
|
|
|
|
|
dmsRecordAlarmTime = new DmsRecordAlarmTime();
|
|
|
|
|
dmsRecordAlarmTime.DeviceId = dmsBaseAlarmRule.DeviceId;
|
|
|
|
|
dmsRecordAlarmTime.AlarmRuleId = warnRuleId;
|
|
|
|
|
dmsRecordAlarmTime.AlarmBeginTime = DateTime.Now;
|
|
|
|
|
dmsRecordAlarmTime.ContinueTime = dmsBaseAlarmRule.ContinueTime;
|
|
|
|
|
dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason;
|
|
|
|
|
dmsRecordAlarmTime.AlarmReason = dmsBaseAlarmRule.AlarmReason;
|
|
|
|
|
dmsRecordAlarmTime.AlarmData = WarnStatusEnum.小包出口读取RFID失败5次.ToString();
|
|
|
|
|
dmsRecordAlarmTime.HandleSuggest = dmsBaseAlarmRule.HandleSuggest + ";;虚拟托盘号为:" + epcStr;
|
|
|
|
|
dmsRecordAlarmTime.CreateBy = "SlnMesnac";
|
|
|
|
|
dmsRecordAlarmTime.CreateTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
DmsRecordAlarmInfo dmsRecordAlarmInfo = new DmsRecordAlarmInfo();
|
|
|
|
|
dmsRecordAlarmInfo.DeviceId = dmsBaseAlarmRule.DeviceId;
|
|
|
|
|
dmsRecordAlarmInfo.AlarmRuleId = warnRuleId;
|
|
|
|
|
dmsRecordAlarmInfo.AlarmBeginTime = DateTime.Now;
|
|
|
|
|
dmsRecordAlarmInfo.AlarmStatus = "0";
|
|
|
|
|
dmsRecordAlarmInfo.NoticeStatus = "0";
|
|
|
|
|
dmsRecordAlarmInfo.ContinueTime = dmsBaseAlarmRule.ContinueTime;
|
|
|
|
|
dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason;
|
|
|
|
|
dmsRecordAlarmInfo.AlarmReason = dmsBaseAlarmRule.AlarmReason;
|
|
|
|
|
dmsRecordAlarmInfo.AlarmData = WarnStatusEnum.小包出口读取RFID失败5次.ToString();
|
|
|
|
|
dmsRecordAlarmInfo.HandleSuggest = dmsBaseAlarmRule.HandleSuggest + ";;虚拟托盘号为:" + epcStr;
|
|
|
|
|
dmsRecordAlarmInfo.CreateBy = "SlnMesnac";
|
|
|
|
|
dmsRecordAlarmInfo.CreateTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Insertable(dmsRecordAlarmTime).ExecuteCommand();
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Insertable(dmsRecordAlarmInfo).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
dmsRecordAlarmTime.UpdateTime = DateTime.Now;
|
|
|
|
|
dmsRecordAlarmTime.UpdateBy = "SlnMesnac";
|
|
|
|
|
DmsRecordAlarmInfo dmsRecordAlarmInfo = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<DmsRecordAlarmInfo>().First(x => x.AlarmRuleId == warnRuleId);
|
|
|
|
|
if (dmsRecordAlarmInfo != null)
|
|
|
|
|
{
|
|
|
|
|
dmsRecordAlarmInfo.UpdateTime = DateTime.Now;
|
|
|
|
|
dmsRecordAlarmInfo.UpdateBy = "SlnMesnac";
|
|
|
|
|
}
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmTime).ExecuteCommand();
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(dmsRecordAlarmInfo).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sqlSugarClient.AsTenant().CommitTran();
|
|
|
|
|
return epcStr;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
sqlSugarClient.AsTenant().RollbackTran();
|
|
|
|
|
_logger.LogError($"NoReadRFIDAlarm异常:{ex.Message}");
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 空托盘进入码垛位,读取RFID备用
|
|
|
|
|
/// </summary>
|
|
|
|
|