add-添加投料后产生40个小包条码,添加分布式事务控制

dev
liuwf 3 months ago
parent 4549a649d1
commit 2daa756b5e

@ -50,15 +50,15 @@ namespace SlnMesnac.Business
private readonly IRealPalletTaskService _realPalletTaskService;
private List<RealPalletTask> _palletTasks;
public PalletStowBusiness(ILogger<BaseBusiness> logger, AppConfig appConfig, List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories, IMesProductPlanService mesProductPlanService, IWmsInstockService msInstockService, IRealPalletTaskService realPalletTaskService, List<RealPalletTask> palletTasks,IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider)
public PalletStowBusiness(ILogger<BaseBusiness> logger, AppConfig appConfig, List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories, IMesProductPlanService mesProductPlanService, IWmsInstockService msInstockService, IRealPalletTaskService realPalletTaskService, IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider)
{
_mesProductPlanService = mesProductPlanService;
_msInstockService = msInstockService;
_realPalletTaskService = realPalletTaskService;
_palletTasks = palletTasks;
}
@ -140,7 +140,7 @@ namespace SlnMesnac.Business
_realPalletTaskService.InsertPalletTask(new RealPalletTask() { PalletCode = epcStr,RecordTime = DateTime.Now });
RefreshPalletTaskListEvent?.Invoke(_palletTasks);
// RefreshPalletTaskListEvent?.Invoke(_palletTasks);
}
catch (Exception e)
@ -154,7 +154,7 @@ namespace SlnMesnac.Business
public void RemovePalletInfo(string palletCode)
{
_realPalletTaskService.RemovePalletTask(palletCode);
RefreshPalletTaskListEvent?.Invoke(_palletTasks);
// RefreshPalletTaskListEvent?.Invoke(_palletTasks);
}
}
}

@ -46,24 +46,20 @@ namespace SlnMesnac.Business
{
private readonly IMesProductPlanService _mesProductPlanService;
private readonly IRealBarCodeTaskService _barCodeTaskService;
private readonly IMesPrdBarCodeService _barCodeTaskService;
private List<RealBarCodeTask> _barCodeTasks;
public ProdCompletionBusiness(ILogger<BaseBusiness> logger, AppConfig appConfig, List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories, IMesProductPlanService mesProductPlanService, IRealBarCodeTaskService barCodeTaskService, List<RealBarCodeTask> barCodeTasks,IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider)
public ProdCompletionBusiness(ILogger<BaseBusiness> logger, AppConfig appConfig, List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories, IMesProductPlanService mesProductPlanService, IMesPrdBarCodeService barCodeTaskService, IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider)
{
_mesProductPlanService = mesProductPlanService;
_barCodeTaskService = barCodeTaskService;
_barCodeTasks = barCodeTasks;
}
/// <summary>
/// 刷新条码队列
/// </summary>
public delegate void RefreshBarCodeTaskList(List<RealBarCodeTask> list);
public event RefreshBarCodeTaskList? RefreshBarCodeTaskListEvent;
public void Init()
{
DeviceOutPutHandle();
@ -103,31 +99,31 @@ namespace SlnMesnac.Business
plc.writeInt16ByAddress(GetPlcAddressByConfigKey("设备产出"), 0);
//生成小包条码
string barCode = $"JYHB{(string.IsNullOrEmpty(productPlanDto.MaterialCode) ? "000000000" : productPlanDto.MaterialCode)}-000001";
if (_barCodeTasks.Count > 0)
{
var info = _barCodeTasks.OrderByDescending(x => x.RecordTime).Where(x=>x.MaterialCode == productPlanDto.MaterialCode);
if(info.Count() > 0)
{
var task = info.FirstOrDefault();
//if (_barCodeTasks.Count > 0)
//{
// var info = _barCodeTasks.OrderByDescending(x => x.RecordTime).Where(x=>x.MaterialCode == productPlanDto.MaterialCode);
// if(info.Count() > 0)
// {
// var task = info.FirstOrDefault();
ExtractNumber(task.BarCode, out int orFlag);
// ExtractNumber(task.BarCode, out int orFlag);
barCode = $"JYHB{(string.IsNullOrEmpty(productPlanDto.MaterialCode) ? "000000000" : productPlanDto.MaterialCode)}-{orFlag.ToString().PadLeft(6,'0')}";
}
}
// barCode = $"JYHB{(string.IsNullOrEmpty(productPlanDto.MaterialCode) ? "000000000" : productPlanDto.MaterialCode)}-{orFlag.ToString().PadLeft(6,'0')}";
// }
//}
RealBarCodeTask barCodeTask = new RealBarCodeTask()
{
BarCode = barCode,
PlanCode = productPlanDto.PlanCode,
MaterialCode = productPlanDto.MaterialCode,
RecordTime = DateTime.Now
};
_barCodeTaskService.InsertBarCodeTask(barCodeTask);
RefreshBarCodeTaskListEvent?.Invoke(_barCodeTasks);
//RealBarCodeTask barCodeTask = new RealBarCodeTask()
//{
// BarCode = barCode,
// PlanCode = productPlanDto.PlanCode,
// MaterialCode = productPlanDto.MaterialCode,
// RecordTime = DateTime.Now
//};
//_barCodeTaskService.InsertBarCodeTask(barCodeTask);
//RefreshBarCodeTaskListEvent?.Invoke(_barCodeTasks);
}
catch (Exception ex)
{
@ -157,11 +153,7 @@ namespace SlnMesnac.Business
}
}
public void RemoveBarCode(string barCode)
{
_barCodeTaskService.RemoveBarCodeTask(barCode);
RefreshBarCodeTaskListEvent?.Invoke(_barCodeTasks );
}
//public void testPenCode()

@ -60,6 +60,8 @@ namespace SlnMesnac.Business
public readonly IBasePalletInfoService _basePalletInfoService;
public readonly IMesPrdBarCodeService _mesPrdBarCodeService;
public readonly IBaseRealTaskService _baseRealTaskService;
public readonly IWmsOutStockService _wmsOutStockService;
@ -67,26 +69,47 @@ namespace SlnMesnac.Business
private readonly ConfigInfoBusiness _configInfoBusiness;
private List<RealPalletTask> _palletTasks;
private ISqlSugarClient sqlSugarClient;
private DebugConfig debugConfig = DebugConfig.Instance;
public ProdMgmtBusiness(ISqlSugarClient _sqlSugarClient, IWmsOutStockService wmsOutStockService, ILogger<ProdMgmtBusiness> logger, AppConfig appConfig, List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories, IMesProductPlanService mesProductPlanService, IBasePalletInfoService basePalletInfoService, IBaseRealTaskService baseRealTaskService, List<RealPalletTask> palletTasks, IServiceProvider serviceProvider, ConfigInfoBusiness configInfoBusiness) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider)
public ProdMgmtBusiness(ISqlSugarClient _sqlSugarClient, IWmsOutStockService wmsOutStockService, ILogger<ProdMgmtBusiness> logger, AppConfig appConfig, List<PlcAbsractFactory> plcFactories, List<RfidAbsractFactory> rfidFactories, IMesProductPlanService mesProductPlanService, IBasePalletInfoService basePalletInfoService, IBaseRealTaskService baseRealTaskService, IServiceProvider serviceProvider, ConfigInfoBusiness configInfoBusiness) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider)
{
sqlSugarClient = _sqlSugarClient;
_wmsOutStockService = wmsOutStockService;
_mesProductPlanService = mesProductPlanService;
_basePalletInfoService = basePalletInfoService;
_baseRealTaskService = baseRealTaskService;
_palletTasks = palletTasks;
_configInfoBusiness =configInfoBusiness;
// testTran();
_mesPrdBarCodeService = serviceProvider.GetRequiredService<IMesPrdBarCodeService>();
_configInfoBusiness = configInfoBusiness;
}
public async void testTran()
public void TestTran()
{
try
{
sqlSugarClient.AsTenant().BeginTran();
BaseRealTask localPlan = _baseRealTaskService.GetExeTask();
localPlan.Status = 2;
sqlSugarClient.AsTenant().GetConnection("local").Updateable(localPlan).ExecuteCommand();
GenerateBarcode(10);
// throw new Exception("事务测试");
sqlSugarClient.AsTenant().CommitTran();
Console.WriteLine("提交事务");
}
catch (Exception ex)
{
sqlSugarClient.AsTenant().RollbackTran();
Console.WriteLine(ex.Message);
}
}
private async void testRFID()
{
//TcpClient tcpClient = new TcpClient();
//var waitClient = tcpClient.CreateWaitingClient(new WaitingOptions()
@ -350,38 +373,40 @@ namespace SlnMesnac.Business
//}
#endregion
if (prodPlan != null)
{
// 下发翻转信号
plc.writeBoolByAddress(GetPlcAddressByConfigKey("设备投料"), true);
Thread.Sleep(300);
plc.writeBoolByAddress(GetPlcAddressByConfigKey("设备投料"), false);
sqlSugarClient.AsTenant().BeginTran();
//1.完成本地计划
if (localPlan != null)
{
localPlan.Status = 2;
localPlan.UpdateTime = DateTime.Now;
sqlSugarClient.AsTenant().GetConnection("local").Updateable(localPlan).ExecuteCommand();
}
//2.生成小包条码
GenerateBarcode(40);
//3.清空投料系统运行时间
BaseConfigInfo configInfo = _configInfoBusiness.GetConfigInfos().Where(x => x.ConfigKey == "拆包机系统运行时长").FirstOrDefault();
configInfo.ConfigValue = "0";
_configInfoBusiness.UpdateConfigInfo(configInfo);
sqlSugarClient.AsTenant().CommitTran();
}
}
catch (Exception e)
{
_logger.LogInformation($"投料校验异常:{e.Message}");
sqlSugarClient.AsTenant().RollbackTran();
_logger.LogInformation($"投料流程异常:{e.Message}");
Thread.Sleep(5000);
continue;
// TODO修改成传入本地计划查询出的mes计划
// result = MatPutInValidTriggerEvent(2, prodPlan, string.Empty, $"投料校验异常:{e.Message},是否继续投料");
}
if (prodPlan != null)
{
// 下发翻转信号
plc.writeBoolByAddress(GetPlcAddressByConfigKey("设备投料"), true);
Thread.Sleep(300);
plc.writeBoolByAddress(GetPlcAddressByConfigKey("设备投料"), false);
#region 清空投料系统运行时间
BaseConfigInfo configInfo = _configInfoBusiness.GetConfigInfos().Where(x => x.ConfigKey == "拆包机系统运行时长").FirstOrDefault();
configInfo.ConfigValue = "0";
_configInfoBusiness.UpdateConfigInfo(configInfo);
#endregion
//在小包2楼绑定托盘时完成计划
// PutInResutlHandle(prodPlan, result);
// 完成本地计划
if (localPlan != null)
{
localPlan.Status = 2;
localPlan.UpdateTime = DateTime.Now;
_baseRealTaskService.Update(localPlan);
}
}
Thread.Sleep(3000);
@ -474,6 +499,28 @@ namespace SlnMesnac.Business
return result;
}
/// <summary>
/// 投料后产生小包条码存储到数据库等待绑定
/// </summary>
private void GenerateBarcode(int amount)
{
List<MesPrdBarcodeInfo> list = new List<MesPrdBarcodeInfo>();
string baseDate = DateTime.Now.ToString("yyyyMMddHHmm"); // 当前日期和时间到分钟
for (int i = 1; i <= amount; i++)
{
MesPrdBarcodeInfo record = new MesPrdBarcodeInfo();
record = new MesPrdBarcodeInfo();
record.PrdBarcodeInfo = baseDate + i.ToString("D3"); // 将序号格式化为三位数
record.PrintFlag = "0";
record.CreatTime = DateTime.Now;
list.Add(record);
}
sqlSugarClient.AsTenant().GetConnection("mes").Insertable(list).ExecuteCommand();
}
/// <summary>
/// 更新生产计划
/// </summary>

@ -64,10 +64,8 @@ namespace SlnMesnac.Business.@base
private IServiceProvider _serviceProvider;
#region 本地缓存信息
private List<RealPalletTask> palletTasks;
private List<RealBarCodeTask> barCodeTasks;
private List<BaseConfigInfo> baseConfigInfos;
@ -93,9 +91,7 @@ namespace SlnMesnac.Business.@base
{
baseConfigInfos = scope.ServiceProvider.GetRequiredService<List<BaseConfigInfo>>();
palletTasks = scope.ServiceProvider.GetRequiredService<List<RealPalletTask>>();
barCodeTasks = scope.ServiceProvider.GetRequiredService<List<RealBarCodeTask>>();
}
}
@ -219,50 +215,7 @@ namespace SlnMesnac.Business.@base
}
/// <summary>
/// 通过托盘队列获取托盘信息
/// </summary>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public string GetPalletInfoByTask()
{
try
{
if (palletTasks.Count == 0)
{
throw new ArgumentNullException("通过托盘队列获取托盘信息异常:托盘队列为空");
}
return palletTasks.OrderBy(x=>x.RecordTime).First().PalletCode;
}
catch (Exception ex)
{
throw new InvalidOperationException($"通过托盘队列获取托盘信息异常:{ex.Message}");
}
}
/// <summary>
/// 通过条码队列获取条码信息
/// </summary>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public string GetBarCodeByTask()
{
try
{
if (barCodeTasks.Count == 0)
{
throw new ArgumentNullException("通过条码队列获取条码信息异常:托盘队列为空");
}
return barCodeTasks.OrderBy(x => x.RecordTime).First().BarCode;
}
catch (Exception ex)
{
throw new InvalidOperationException($"通过条码队列获取条码信息异常:{ex.Message}");
}
}
/// <summary>
/// 根据configKey获取PLC地址
/// </summary>

@ -83,25 +83,8 @@ namespace SlnMesnac.Extensions
return info;
});
//缓存托盘队列
services.AddSingleton<List<RealPalletTask>>(x =>
{
var service = x.GetService<IRealPalletTaskService>();
var info = service.Query();
return info;
});
//缓存条码队列
services.AddSingleton<List<RealBarCodeTask>>(x =>
{
var service = x.GetService<IRealBarCodeTaskService>();
var info = service.Query();
return info;
});
}
}
}

@ -126,18 +126,18 @@ namespace SlnMesnac.WPF.Page
RefreshMagNet();
RefreshSpiral();
RefreshHot();
RefreshUnPack();
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
BagsAmountTxt.Text = _configInfoBusiness.GetConfigInfos().FirstOrDefault(x => x.ConfigKey == "包装袋余量").ConfigValue;
}));
RefreshUnPack();
}
else
{
_logger.LogError($"设备监听启动失败PLC连接失败!");
Thread.Sleep(1000 * 30);
}
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
BagsAmountTxt.Text = _configInfoBusiness.GetConfigInfos().FirstOrDefault(x => x.ConfigKey == "包装袋余量").ConfigValue;
}));
}
catch (Exception ex)
{
@ -161,48 +161,53 @@ namespace SlnMesnac.WPF.Page
{
try
{
float cacheWeigh = plc.readFloatByAddress(baseBusiness.GetPlcAddressByConfigKey("缓存区重量"));
recipeManageCache.BufferWeight = cacheWeigh;
if (recipeManageCache.RecipeMode == "自动模式")
if (plc != null)
{
bool unPackStatus1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机系统运行状态"));
bool signal2 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1状态"));
bool signal3 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2状态"));
int signal1_1 = plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机螺旋状态"));
if (signal1_1 == 1 && signal2 && signal3 && unPackStatus1) // 1.设备都已经启动
float cacheWeigh = plc.readFloatByAddress(baseBusiness.GetPlcAddressByConfigKey("缓存区重量"));
recipeManageCache.BufferWeight = cacheWeigh;
if (recipeManageCache.RecipeMode == "自动模式")
{
// 1.判断缓存区重量是否满足配方要求
RecipeManage targetRecipe = null;
int result = JudgeCacheWeighIsOk(cacheWeigh, out targetRecipe);
switch (result)
bool unPackStatus1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机系统运行状态"));
bool signal2 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1状态"));
bool signal3 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2状态"));
int signal1_1 = plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机螺旋状态"));
if (signal1_1 == 1 && signal2 && signal3 && unPackStatus1) // 1.设备都已经启动
{
case -1:
// TODO添加报警记录推送
break;
case 0: break;
case 1:
// 高切低
HighToLowSpeed(targetRecipe);
break;
case 2:
// 低切高
LowToHighSpeed(targetRecipe);
break;
default: break;
}
// 1.判断缓存区重量是否满足配方要求
RecipeManage targetRecipe = null;
int result = JudgeCacheWeighIsOk(cacheWeigh, out targetRecipe);
switch (result)
{
case -1:
// TODO添加报警记录推送
break;
case 0: break;
case 1:
// 高切低
HighToLowSpeed(targetRecipe);
break;
case 2:
// 低切高
LowToHighSpeed(targetRecipe);
break;
default: break;
}
}
}
}
Thread.Sleep(1000 * 10);
}
catch (Exception ex)
{
_logger.LogError($"监测缓存区重量动态调整配方频率StartAdjustRecipe异常:{ex.Message}");
}
Thread.Sleep(1000 * 10);
}
});
}

@ -49,18 +49,17 @@ namespace SlnMesnac.WPF.ViewModel
DeletePalletCommand = new RelayCommand<string>(DeletePallet);
DeleteBarCodeCommand = new RelayCommand<string> (DeleteBarCode);
// DeleteBarCodeCommand = new RelayCommand<string> (DeleteBarCode);
var palletTask = App.ServiceProvider.GetService<List<RealPalletTask>>();
RefreshPalletTaskDataGrid(palletTask);
_palletStowBusiness.RefreshPalletTaskListEvent += RefreshPalletTaskDataGrid;
var barCodeTasks = App.ServiceProvider.GetService<List<RealBarCodeTask>>();
RefreshBarCodeTaskDataGrid(barCodeTasks);
_prodCompletionBusiness.RefreshBarCodeTaskListEvent += RefreshBarCodeTaskDataGrid;
}
#region 参数定义
@ -79,9 +78,9 @@ namespace SlnMesnac.WPF.ViewModel
/// <summary>
/// 条码队列DataGrid
/// </summary>
private ObservableCollection<RealBarCodeTask> barCodeTaskDataGrid;
private ObservableCollection<MesPrdBarcodeInfo> barCodeTaskDataGrid;
public ObservableCollection<RealBarCodeTask> BarCodeTaskDataGrid
public ObservableCollection<MesPrdBarcodeInfo> BarCodeTaskDataGrid
{
get { return barCodeTaskDataGrid; }
set { barCodeTaskDataGrid = value; RaisePropertyChanged(() => BarCodeTaskDataGrid); }
@ -110,18 +109,18 @@ namespace SlnMesnac.WPF.ViewModel
}
}
/// <summary>
/// 刷新条码队列信息
/// </summary>
/// <param name="barCodeTasks"></param>
private void RefreshBarCodeTaskDataGrid(List<RealBarCodeTask> barCodeTasks)
{
BarCodeTaskDataGrid = new ObservableCollection<RealBarCodeTask>();
foreach (var task in barCodeTasks)
{
BarCodeTaskDataGrid.Add(task);
}
}
///// <summary>
///// 刷新条码队列信息
///// </summary>
///// <param name="barCodeTasks"></param>
//private void RefreshBarCodeTaskDataGrid(List<RealBarCodeTask> barCodeTasks)
//{
// BarCodeTaskDataGrid = new ObservableCollection<RealBarCodeTask>();
// foreach (var task in barCodeTasks)
// {
// BarCodeTaskDataGrid.Add(task);
// }
//}
/// <summary>
/// 移除托盘队列信息
@ -132,13 +131,13 @@ namespace SlnMesnac.WPF.ViewModel
_palletStowBusiness.RemovePalletInfo(palletCode);
}
/// <summary>
/// 移除小包条码队列信息
/// </summary>
/// <param name="barCode"></param>
private void DeleteBarCode(string barCode)
{
_prodCompletionBusiness.RemoveBarCode(barCode);
}
///// <summary>
///// 移除小包条码队列信息
///// </summary>
///// <param name="barCode"></param>
//private void DeleteBarCode(string barCode)
//{
// _prodCompletionBusiness.RemoveBarCode(barCode);
//}
}
}

Loading…
Cancel
Save