change-修改泡前库入库,定时器改为while循环

dev
liuwf 1 year ago
parent a4b22bb300
commit e85bbf706e

@ -24,7 +24,8 @@ namespace Admin.Core.Repository
Db.Deleteable(realTask).ExecuteCommand(); Db.Deleteable(realTask).ExecuteCommand();
Db.Updateable(baseSpaceInfo).ExecuteCommand(); Db.Updateable(baseSpaceInfo).ExecuteCommand();
Db.Insertable(store).ExecuteCommand(); Db.Insertable(store).ExecuteCommand();
Db.Insertable(baseDetail).ExecuteCommand(); // 不控制出库,没必要添加货道明细
// Db.Insertable(baseDetail).ExecuteCommand();
Db.Ado.CommitTran(); Db.Ado.CommitTran();
return true; return true;
} }

@ -83,11 +83,6 @@ namespace Aucma.Core.BoxFoam.Business
#endregion #endregion
/// <summary>
/// 入库出库完成信号定时器
/// </summary>
System.Timers.Timer timer = new System.Timers.Timer(1000);
private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(InStoreBusiness)); private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(InStoreBusiness));
private readonly IBaseSpaceInfoServices? _baseSpaceInfoServices = App.ServiceProvider.GetService<IBaseSpaceInfoServices>(); private readonly IBaseSpaceInfoServices? _baseSpaceInfoServices = App.ServiceProvider.GetService<IBaseSpaceInfoServices>();
private readonly IRealTaskInfoServices? _realTaskInfoService = App.ServiceProvider.GetService<IRealTaskInfoServices>(); private readonly IRealTaskInfoServices? _realTaskInfoService = App.ServiceProvider.GetService<IRealTaskInfoServices>();
@ -111,42 +106,22 @@ namespace Aucma.Core.BoxFoam.Business
public void init() public void init()
{ {
allSpaces = _baseSpaceInfoServices.Query(x => x.StoreCode == storeCode); allSpaces = _baseSpaceInfoServices.Query(x => x.StoreCode == storeCode);
foreach (var space in allSpaces) foreach (var space in allSpaces)
{ {
spaceAddresses.Add(spaceConfig.GetSpaceAddress(storeCode, space.SpaceCode)); spaceAddresses.Add(spaceConfig.GetSpaceAddress(storeCode, space.SpaceCode));
} }
Task.Run(() =>
{ //实时监测入库任务下发和入库任务完成
Thread.Sleep(5000); StartPassDownAndRealInstoreFinish();
// test();
// 获取任务下发plc
// StartPassDown();
// InStore("B23600083025024860011");
});
// startTimer();
} }
public async void test()
{
// InStoreFinish("PB01_001");
}
/// <summary>
/// 入库出库完成信号定时器
/// </summary>
public void startTimer()
{
timer.Elapsed += new System.Timers.ElapsedEventHandler(RealInstoreFinish); //到达时间的时候执行事件;
timer.AutoReset = true;//设置是执行一次false还是一直执行(true)
timer.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它
timer.Start();//timer.Start()的内部原理还是设置timer.Enabled = true;
}
/// <summary> /// <summary>
/// 定时器实时监测入库出库完成信号 /// 定时器实时监测入库出库完成信号
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public void RealInstoreFinish(object? sender, ElapsedEventArgs e) public void RealInstoreFinish()
{ {
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("泡前库Plc")); var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("泡前库Plc"));
if (obj != null && obj.plc.IsConnected) if (obj != null && obj.plc.IsConnected)
@ -163,25 +138,37 @@ namespace Aucma.Core.BoxFoam.Business
if (obj.plc.ReadInt16(spaceAddress.outStoreFinish) == 1) if (obj.plc.ReadInt16(spaceAddress.outStoreFinish) == 1)
{ {
obj.plc.WriteInt16(spaceAddress.outStoreFinish, "0"); obj.plc.WriteInt16(spaceAddress.outStoreFinish, "0");
// 减货道明细 // 系统不控制出库,暂时未使用出库完成信号
} }
} }
} }
} }
/// <summary>
public async void StartPassDown() ///实时监测入库任务下发和入库任务完成
/// </summary>
public async void StartPassDownAndRealInstoreFinish()
{ {
Task.Run(() => Task.Run(() =>
{ {
Thread.Sleep(3000);
while (true) while (true)
{ {
PassDown(); PassDown();
Thread.Sleep(200000); Thread.Sleep(1000);
} }
}); });
Task.Run(() =>
{
Thread.Sleep(3000);
while (true)
{
RealInstoreFinish();
Thread.Sleep(1000);
}
});
} }
@ -523,104 +510,7 @@ namespace Aucma.Core.BoxFoam.Business
} }
} }
//#region 监测PLC在途数量变化完成入库任务
///// <summary>
///// 读取箱壳已下发任务的货道信息读取后将货道编号及在途数量写入Dictionary进行比较在途数减少则入库完成
///// </summary>
//private void RealReadPlcSpace()
//{
// if (TaskInfos != null)
// {
// List<string> spaceCodes = TaskInfos.Select(x => x.SpaceCode).Distinct().ToList();
// for (int i = 0; i < spaceCodes.Count; i++)
// {
// string spaceCode = spaceCodes[i];
// BaseSpaceInfo spaceInfo = new BaseSpaceInfo() { StoreCode = storeCode, SpaceCode = spaceCode };
// spaceInfo = ReadSpaceInfoByPlc(spaceInfo);
// if (KeyValuePairs.ContainsKey(spaceInfo.SpaceCode))
// {
// KeyValuePairs.TryGetValue(spaceInfo.SpaceCode, out int value);
// //判断前次读取的数据和当前数据,如果前次数据大于当前数据则代表入库完成,然后筛选任务中对应货道的首个任务进行完成
// //如果前次数据不大于当前数据则更新字典中存放的数据
// if (value > spaceInfo.OnRouteAmount)
// {
// //筛选任务
// var list = TaskInfos.Where(x => x.SpaceCode == spaceInfo.SpaceCode).ToList();
// if (list.Count > 0)
// {
// RealTaskInfo taskInfo = list.OrderBy(x => x.CreateTime).First();
// InStoreFinish(taskInfo.TaskCode);
// TaskInfos.Remove(taskInfo);
// }
// KeyValuePairs.Remove(spaceInfo.SpaceCode);
// }
// else
// {
// KeyValuePairs[spaceInfo.SpaceCode] = spaceInfo.OnRouteAmount;
// }
// }
// else
// {
// KeyValuePairs.Add(spaceInfo.SpaceCode, spaceInfo.OnRouteAmount);
// }
// }
// }
//}
//#endregion
/// <summary>
/// 读取泡后入库完成
/// </summary>
//private void ReadShellFinish_InStore(string taskCode)
//{
// lock (string.Empty)
// {
// bool isFlag = true;
// var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("泡前库Plc"));
// try
// {
// Task.Run(() =>
// {
// if (obj != null && obj.plc.IsConnected)
// {
// do
// {
// //读取PLC入库任务完成
// if (obj.plc.ReadInt16("D220") == 1)
// {
// obj.plc.WriteInt16("D220", "0");
// FoamTaskFeedback(taskCode);
// isFlag = false;
// }
// Thread.Sleep(1000);
// } while (isFlag);
// }
// else
// {
// logHelper.Info("PLC未连接");
// }
// });
// }
// catch (Exception ex)
// {
// logHelper.Error("读取泡后入库完成异常", ex);
// }
// }
//}
/// <summary> /// <summary>
/// 泡前库执行反馈 /// 泡前库执行反馈
/// </summary> /// </summary>
@ -664,7 +554,7 @@ namespace Aucma.Core.BoxFoam.Business
await _baseSpaceInfoServices.UpdateSpaceInfo(spaceInfo); await _baseSpaceInfoServices.UpdateSpaceInfo(spaceInfo);
#region 添加货道明细 #region 添加货道明细 不控制出库,暂时未添加明细
BaseSpaceDetail spaceDetail = new BaseSpaceDetail(); BaseSpaceDetail spaceDetail = new BaseSpaceDetail();
spaceDetail.MaterialType = taskInfo.MaterialType; spaceDetail.MaterialType = taskInfo.MaterialType;
spaceDetail.MaterialCode = taskInfo.MaterialCode; spaceDetail.MaterialCode = taskInfo.MaterialCode;

Loading…
Cancel
Save