add-完善2楼小包产出逻辑

dev
liuwf 3 months ago
parent 9e19bfe246
commit 1c5b92ca67

@ -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);
}
}

@ -95,7 +95,7 @@ namespace SlnMesnac.Business
BaseRealTask localPlan = _baseRealTaskService.GetExeTask();
localPlan.Status = 2;
sqlSugarClient.AsTenant().GetConnection("local").Updateable(localPlan).ExecuteCommand();
GenerateBarcode(10);
GenerateBarcode(40);
// throw new Exception("事务测试");
sqlSugarClient.AsTenant().CommitTran();
Console.WriteLine("提交事务");
@ -515,6 +515,7 @@ namespace SlnMesnac.Business
record.PrdBarcodeInfo = baseDate + i.ToString("D3"); // 将序号格式化为三位数
record.PrintFlag = "0";
record.CreatTime = DateTime.Now;
record.BindStatus = 0;
list.Add(record);
}
sqlSugarClient.AsTenant().GetConnection("mes").Insertable(list).ExecuteCommand();

@ -78,10 +78,11 @@ namespace SlnMesnac.Model.domain
[SugarColumn(ColumnName = "bind_time")]
public DateTime? BindTime { get; set; }
/// <summary>
/// 绑定状态:0-未绑定1-已绑定2-弃用
/// </summary>
[SugarColumn(ColumnName = "bind_status")]
public int? BindStatus { get; set; }
}

@ -260,6 +260,8 @@ namespace SlnMesnac.Plc.Factory
}
}
/// <summary>
/// 通过PLC地址读取float类型数据
/// </summary>
@ -350,13 +352,37 @@ namespace SlnMesnac.Plc.Factory
OperateResult operateResult = s7.Write(address, (float)value);
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入double数据失败:{operateResult.Message}");
throw new InvalidOperationException($"根据地址:{address};写入Float数据失败:{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入double数据异常{ex.Message}");
throw new InvalidOperationException($"根据地址:{address};写入Float数据异常{ex.Message}");
}
}
/// <summary>
/// 通过PLC地址写入Byte类型数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public override bool writeByteByAddress(string address,int value)
{
try
{
OperateResult operateResult = s7.Write(address,(byte)value);
if (!operateResult.IsSuccess)
{
throw new InvalidOperationException($"根据地址:{address};写入byte数据失败{operateResult.Message}");
}
return operateResult.IsSuccess;
}
catch (Exception ex)
{
throw new InvalidOperationException($"根据地址:{address};写入byte数据异常{ex.Message}");
}
}
}

@ -126,5 +126,13 @@ namespace SlnMesnac.Plc
/// <param name="value"></param>
/// <returns></returns>
public abstract bool writeFloatByAddress(string address, int value);
/// <summary>
/// 通过PLC地址写入Byte类型数据
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public abstract bool writeByteByAddress(string address, int value);
}
}

@ -78,7 +78,7 @@ namespace SlnMesnac.Repository.service.Impl
List<MesPrdBarcodeInfo> list = null;
try
{
string sql = "select * from mes_prd_barcode_info where print_flag ='1' and pallet_info_code is null order by print_time limit 40;";
string sql = "select * from mes_prd_barcode_info where bind_status =0 order by creat_time limit 40;";
list = _rep.Context.Ado.SqlQuery<MesPrdBarcodeInfo>(sql);
return list;
}catch (Exception e)

@ -278,7 +278,7 @@ namespace SlnMesnac.WPF.ViewModel
if (info != null)
{
info.PlanStatus = PlanStatusEnum.;
info.RealBeginTime = DateTime.Now;
info.PlanBeginTime = DateTime.Now;
}
_prodMgmtBusiness.UpdateProdPlan(info);

Loading…
Cancel
Save