|
|
|
@ -11,6 +11,7 @@ using SlnMesnac.Rfid;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
@ -49,6 +50,7 @@ namespace SlnMesnac.Business
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private readonly IMesProductPlanService _mesProductPlanService;
|
|
|
|
|
private readonly IMesProductOrderService _mesProductOrderService;
|
|
|
|
|
private readonly IMesPrdBarCodeService _barCodeTaskService;
|
|
|
|
|
private readonly IMesBaseBarcodeInfoService _mesBaseBarcodeInfoService;
|
|
|
|
|
public readonly IMesPrdBarCodeService _mesPrdBarCodeService;
|
|
|
|
@ -64,7 +66,7 @@ namespace SlnMesnac.Business
|
|
|
|
|
_realPalletTaskService = serviceProvider.GetRequiredService<IRealPalletTaskService>();
|
|
|
|
|
_mesBaseBarcodeInfoService = serviceProvider.GetRequiredService<IMesBaseBarcodeInfoService>();
|
|
|
|
|
_mesPrdBarCodeService = serviceProvider.GetRequiredService<IMesPrdBarCodeService>();
|
|
|
|
|
|
|
|
|
|
_mesProductOrderService = serviceProvider.GetRequiredService<IMesProductOrderService>();
|
|
|
|
|
Init();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -113,7 +115,7 @@ namespace SlnMesnac.Business
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!plc.readBoolByAddress(GetPlcAddressByConfigKey("2楼码垛出口到位信号")))
|
|
|
|
|
if (plc.readByteByAddress(GetPlcAddressByConfigKey("2楼小包出口到位信号"))!=1)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("等待小包出口信号触发......");
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
@ -150,21 +152,27 @@ namespace SlnMesnac.Business
|
|
|
|
|
//TODO:没有计划的话,处理方式待定
|
|
|
|
|
throw new ArgumentException($"未获取到正在执行的生产计划");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 开启事务
|
|
|
|
|
sqlSugarClient.AsTenant().BeginTran();
|
|
|
|
|
//1.生成大条码插入mes_barcode_info;
|
|
|
|
|
string bigCode =GenerateBigBarcode(productPlanDto, epcStr);
|
|
|
|
|
//2.40个小条码及大条码绑定托盘号,小条码绑定大条码
|
|
|
|
|
BindingBarCode(bigCode,epcStr);
|
|
|
|
|
//3.更新mes_product_plan及mes_product_order表,更新已生产数量
|
|
|
|
|
UpdatePlanInfoAndOrder(productPlanDto);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 删除正在使用的数据库托盘号
|
|
|
|
|
RealPalletTask realPallet = _realPalletTaskService.Query(x => x.PalletCode == epcStr).FirstOrDefault();
|
|
|
|
|
if (realPallet != null)
|
|
|
|
|
{
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Deleteable(realPallet).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
// 写入PLC RFID号供调度使用
|
|
|
|
|
plc.writeStringByAddress(GetPlcAddressByConfigKey("2楼码垛出口RFID条码地址"), epcStr);
|
|
|
|
|
plc.writeByteByAddress(GetPlcAddressByConfigKey("2楼小包出口到位信号"),2);
|
|
|
|
|
readRfidAmount = 0;
|
|
|
|
|
sqlSugarClient.AsTenant().CommitTran();
|
|
|
|
|
|
|
|
|
|
plc.writeBoolByAddress(GetPlcAddressByConfigKey("2楼码垛出口到位信号"), false);
|
|
|
|
|
readRfidAmount = 0;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
@ -172,6 +180,8 @@ namespace SlnMesnac.Business
|
|
|
|
|
// TODO:推送报警
|
|
|
|
|
_logger.LogError($"DeviceOutPutHandle异常:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(1000 * 5);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -210,6 +220,7 @@ namespace SlnMesnac.Business
|
|
|
|
|
mesBaseBarcodeInfo.updateTime = DateTime.Now;
|
|
|
|
|
mesBaseBarcodeInfo.completeFlag = "1";
|
|
|
|
|
mesBaseBarcodeInfo.singleFlag = "0";
|
|
|
|
|
// 改成spec
|
|
|
|
|
mesBaseBarcodeInfo.barcodeSpec = productPlanDto.MaterialName;
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Insertable(mesBaseBarcodeInfo).ExecuteCommand();
|
|
|
|
|
return bigBarcode;
|
|
|
|
@ -225,26 +236,72 @@ namespace SlnMesnac.Business
|
|
|
|
|
List<MesPrdBarcodeInfo> list = _mesPrdBarCodeService.GetUseBarCodeList();
|
|
|
|
|
if(list==null || list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("托盘未找到可以绑定的小条码");
|
|
|
|
|
}else if(list.Count > 40)
|
|
|
|
|
throw new InvalidOperationException("托盘未找到可以绑定的小条码");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (list.Where(x => x.PrintFlag == "1").ToList().Count < 40)
|
|
|
|
|
{
|
|
|
|
|
list = list.Take(40).ToList();
|
|
|
|
|
// TODO推送低级别报警
|
|
|
|
|
}
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
item.PalletInfoCode = epcStr;
|
|
|
|
|
item.MesBarcodeInfo = bigBarcode;
|
|
|
|
|
item.BindTime = DateTime.Now;
|
|
|
|
|
item.BindStatus = 1;
|
|
|
|
|
}
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(list).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdatePlanInfoAndOrder(MesProductPlanDto productPlanDto)
|
|
|
|
|
{
|
|
|
|
|
MesProductPlan productPlan = _mesProductPlanService.Query(x => x.PlanCode == productPlanDto.PlanCode).FirstOrDefault();
|
|
|
|
|
if(productPlan == null)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("未找到该生产计划!");
|
|
|
|
|
}
|
|
|
|
|
MesProductOrder productOrder = _mesProductOrderService.Query(x => x.ProductOrderId == productPlan.ProductOrderId).FirstOrDefault();
|
|
|
|
|
if (productPlan == null)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("未找到该生产计划对应的生产工单!");
|
|
|
|
|
}
|
|
|
|
|
#region 更新生产计划
|
|
|
|
|
if (productPlan.CompleteAmount == 0)
|
|
|
|
|
{
|
|
|
|
|
productPlan.RealBeginTime = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
productPlan.CompleteAmount++;
|
|
|
|
|
if(productPlan.CompleteAmount == productPlan.PlanAmount)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
productPlan.RealEndTime = DateTime.Now;
|
|
|
|
|
productPlan.PlanStatus = Model.enums.PlanStatusEnum.已完成;
|
|
|
|
|
}
|
|
|
|
|
productPlan.UpdateTime = DateTime.Now;
|
|
|
|
|
productPlan.UpdateBy = "SlnMesnac";
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(productPlan).ExecuteCommand();
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 更新生产工单
|
|
|
|
|
|
|
|
|
|
if (productOrder.CompleteAmount == 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
productOrder.RealBeginTime = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
productOrder.CompleteAmount++;
|
|
|
|
|
if(productOrder.CompleteAmount== productOrder.PlanAmount)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
productOrder.RealEndTime = DateTime.Now;
|
|
|
|
|
productOrder.OrderStatus = "2";
|
|
|
|
|
}
|
|
|
|
|
productOrder.UpdateTime = DateTime.Now;
|
|
|
|
|
productOrder.UpdateBy = "SlnMesnac";
|
|
|
|
|
sqlSugarClient.AsTenant().GetConnection("mes").Updateable(productOrder).ExecuteCommand();
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -303,7 +360,7 @@ namespace SlnMesnac.Business
|
|
|
|
|
{
|
|
|
|
|
RefreshMessage($"空托盘进入码垛位处理异常:{e.Message}");
|
|
|
|
|
}
|
|
|
|
|
Thread.Sleep(5000);
|
|
|
|
|
Thread.Sleep(1000*5);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|