diff --git a/Admin.Core.Common/Config/IniHelper.cs b/Admin.Core.Common/Config/IniHelper.cs
new file mode 100644
index 00000000..0a87deaf
--- /dev/null
+++ b/Admin.Core.Common/Config/IniHelper.cs
@@ -0,0 +1,105 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Admin.Core.Common.Config
+{
+ public class IniHelper
+ {
+ public string path;
+
+ public IniHelper(string INIPath)
+ {
+ path = INIPath;
+ }
+
+ [DllImport("kernel32")]
+ private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
+
+ [DllImport("kernel32")]
+ private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
+
+
+ [DllImport("kernel32")]
+ private static extern int GetPrivateProfileString(string section, string key, string defVal, Byte[] retVal, int size, string filePath);
+
+ [DllImport("kernel32", EntryPoint = "GetPrivateProfileString")]
+ private static extern uint GetPrivateProfileStringA(string section, string key, string def, Byte[] retVal, int size, string filePath);
+
+ ///
+ /// 写INI文件
+ ///
+ ///
+ ///
+ ///
+ public void IniWriteValue(string Section, string Key, string Value)
+ {
+
+ WritePrivateProfileString(Section, Key, Value, this.path);
+ }
+
+ ///
+ /// 读取INI文件
+ ///
+ ///
+ ///
+ ///
+ public string IniReadValue(string Section, string Key)
+ {
+ StringBuilder temp = new StringBuilder(255);
+ int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
+ //return temp.ToString();
+
+ string str = temp.ToString();
+
+ return str;
+ }
+ public byte[] IniReadValues(string section, string key)
+ {
+ byte[] temp = new byte[255];
+ int i = GetPrivateProfileString(section, key, "", temp, 255, this.path);
+ return temp;
+
+ }
+
+
+ ///
+ /// 删除ini文件下所有段落
+ ///
+ public void ClearAllSection()
+ {
+ IniWriteValue(null, null, null);
+ }
+ ///
+ /// 删除ini文件下personal段落下的所有键
+ ///
+ ///
+ public void ClearSection(string Section)
+ {
+ IniWriteValue(Section, null, null);
+ }
+
+ public List ReadKeys(String SectionName)
+ {
+ return ReadKeys(SectionName, this.path);
+ }
+
+ public List ReadKeys(string SectionName, string iniFilename)
+ {
+ List result = new List();
+ Byte[] buf = new Byte[65536];
+ uint len = GetPrivateProfileStringA(SectionName, null, null, buf, buf.Length, iniFilename);
+ int j = 0;
+ for (int i = 0; i < len; i++)
+ if (buf[i] == 0)
+ {
+ result.Add(Encoding.Default.GetString(buf, j, i - j));
+ j = i + 1;
+ }
+ return result;
+ }
+ }
+}
diff --git a/Admin.Core.Common/Config/PlcSpaceConfig.cs b/Admin.Core.Common/Config/PlcSpaceConfig.cs
new file mode 100644
index 00000000..d418ff19
--- /dev/null
+++ b/Admin.Core.Common/Config/PlcSpaceConfig.cs
@@ -0,0 +1,60 @@
+using Microsoft.AspNetCore.Http.Extensions;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+namespace Admin.Core.Common.Config
+{
+ public sealed class PlcSpaceConfig
+ {
+ private static IniHelper iniHelper = new IniHelper(System.Environment.CurrentDirectory + "/config/PlcSpace.Ini");
+
+ //private static IniHelper iniHelper = new IniHelper("E:/桌面/澳柯玛MES项目/程序设计/Aucma.Scada/Aucma.Scada.UI/bin/Debug/config/PlcSpace.Ini");
+
+ private static readonly Lazy lazy = new Lazy(() => new PlcSpaceConfig());
+ public static PlcSpaceConfig Instance
+ {
+ get
+ {
+ return lazy.Value;
+ }
+ }
+
+ private PlcSpaceConfig()
+ {
+
+ }
+
+
+ public SpaceAddress GetSpaceAddress(string storeCode, string spaceCode)
+ {
+ SpaceAddress spaceAddress = new SpaceAddress();
+ spaceAddress.onStore = iniHelper.IniReadValue($"{storeCode}_{spaceCode}", "在库数量");
+ spaceAddress.onRoute = iniHelper.IniReadValue($"{storeCode}_{spaceCode}", "在途数量");
+ spaceAddress.isFull = iniHelper.IniReadValue($"{storeCode}_{spaceCode}", "是否已满");
+ spaceAddress.spaceStatus = iniHelper.IniReadValue($"{storeCode}_{spaceCode}", "货道状态");
+ spaceAddress.storeStatus = iniHelper.IniReadValue($"{storeCode}_{spaceCode}", "仓库状态");
+ spaceAddress.alarmInfo = iniHelper.IniReadValue($"{storeCode}_{spaceCode}", "报警信息");
+ spaceAddress.outStoreFinish = iniHelper.IniReadValue($"{storeCode}_{spaceCode}", "出库完成");
+ return spaceAddress;
+ }
+ }
+
+ public class SpaceAddress
+ {
+ public string onStore { get; set; }
+
+ public string onRoute { get; set; }
+
+ public string isFull { get; set; }
+
+ public string spaceStatus { get; set; }
+
+ public string storeStatus { get; set; }
+
+ public string alarmInfo { get; set; }
+
+ public string outStoreFinish { get; set; }
+ }
+}
diff --git a/Admin.Core.IService/IService_New/IBaseSpaceInfoServices.cs b/Admin.Core.IService/IService_New/IBaseSpaceInfoServices.cs
index a3351030..bb8c0bab 100644
--- a/Admin.Core.IService/IService_New/IBaseSpaceInfoServices.cs
+++ b/Admin.Core.IService/IService_New/IBaseSpaceInfoServices.cs
@@ -16,7 +16,7 @@ namespace Admin.Core.IService
///
///
///
- Task InStoreGetSpaceInfoByMaterialType(string store, string materialType);
+ Task> InStoreGetSpaceInfoByMaterialType(string store, string materialType);
///
/// 出库通过物料类型获取指定货道
diff --git a/Admin.Core.Service/Service_New/BaseSpaceInfoServices.cs b/Admin.Core.Service/Service_New/BaseSpaceInfoServices.cs
index ceee6925..a12444d1 100644
--- a/Admin.Core.Service/Service_New/BaseSpaceInfoServices.cs
+++ b/Admin.Core.Service/Service_New/BaseSpaceInfoServices.cs
@@ -35,6 +35,8 @@ namespace Admin.Core.Service
_baseBomInfoRepository = baseBomInfoRepository;
}
+
+
#region 入库通过物料类型获取指定货道,如果没有对应类型的货道返回空白类型的货道
///
/// 入库通过物料类型获取指定货道,如果没有对应类型的货道返回空白类型的货道
@@ -42,30 +44,27 @@ namespace Admin.Core.Service
/// 物料条码
/// 货道类型
/// 获取合适货道
- public async Task InStoreGetSpaceInfoByMaterialType(string store, string materialType)
+ public async Task> InStoreGetSpaceInfoByMaterialType(string store, string materialType)
{
- BaseSpaceInfo spaceInfo = null;
- List spaceInfos;
+
+ List spaceInfos = null;
try
{
- //Expression> exp = s1 => true;
- //exp = exp.And(x => x.StoreCode == store && x.MaterialType == materialType && x.SpaceStatus == 1 && x.SpaceCapacity != (x.SpaceStock + x.OnRouteAmount)); //相同型号、启用状态、库存未满的货道信息
-
- spaceInfos = await _baseSpaceInfoRepository.QueryAsync(x => x.StoreCode == store && x.MaterialType == materialType && x.SpaceStatus == 1 && x.SpaceCapacity != (x.SpaceStock + x.OnRouteAmount));
+ spaceInfos = await _baseSpaceInfoRepository.QueryAsync(x => x.StoreCode == store && x.MaterialType == materialType && x.SpaceStatus == 1);
if (spaceInfos.Count == 0) //没有指定该类型物料的货道信息,需获取空白货道信息进行分配
spaceInfos = await GetEmptySpaceInfo(store);
logHelper.Info($"根据仓库{store};物料:{materialType};获取到的货道信息:{spaceInfos.ToJson()}");
- spaceInfo = InStoreFilter(spaceInfos);
- logHelper.Info($"仓库{store};物料:{materialType};匹配的入库货道信息:{spaceInfo.ToJson()}");
+ //spaceInfo = InStoreFilter(spaceInfos);
+ //logHelper.Info($"仓库{store};物料:{materialType};匹配的入库货道信息:{spaceInfo.ToJson()}");
- spaceInfo.MaterialType = materialType;
+ //spaceInfo.MaterialType = materialType;
}
catch (Exception ex)
{
logHelper.Error("入库通过物料类型获取货道信息异常", ex);
}
- return spaceInfo;
+ return spaceInfos;
}
#endregion
@@ -283,8 +282,6 @@ namespace Admin.Core.Service
List spaceInfos = null;
try
{
- Expression> exp = s1 => true;
- exp = exp.And(x => x.MaterialType == null && x.StoreCode == store && x.SpaceCapacity != x.SpaceStock);
spaceInfos =await _dal.QueryAsync(x => x.MaterialType == null && x.StoreCode == store && x.SpaceCapacity != x.SpaceStock);
}
catch (Exception ex)
diff --git a/Admin.Core.Tasks/QuartzNet/Jobs/Job_BoxFoamInStoreTask_Quartz.cs b/Admin.Core.Tasks/QuartzNet/Jobs/Job_BoxFoamInStoreTask_Quartz.cs
index 094b22c4..d2c7e581 100644
--- a/Admin.Core.Tasks/QuartzNet/Jobs/Job_BoxFoamInStoreTask_Quartz.cs
+++ b/Admin.Core.Tasks/QuartzNet/Jobs/Job_BoxFoamInStoreTask_Quartz.cs
@@ -9,6 +9,13 @@ using Admin.Core.Model;
using Admin.Core.Common;
using System.Linq;
using StackExchange.Profiling.Internal;
+using System.Collections.Generic;
+using Admin.Core.Common.Config;
+using Aucma.Core.PLc;
+using Admin.Core.Model.Model_New;
+using System.Threading;
+using Consul;
+using NetTaste;
///
/// 泡前库入库任务逻辑处理
@@ -65,11 +72,16 @@ namespace Admin.Core.Tasks
private readonly IRecordInStoreServices _recordInstoreServices;
private readonly IBaseStoreInfoServices _baseStoreInfoServices;
private readonly IBaseSpaceDetailServices _baseSpaceDetailServices;
-
+ // 过点数据表,物料完成记录MaterialCompletion
+ private readonly IMaterialCompletionServices _iMaterialCompletionServices;
+ private readonly IPrintBarCodeServices _printBarCodeServices;
+ private PlcSpaceConfig spaceConfig = PlcSpaceConfig.Instance;
+ private readonly IBaseBomInfoServices _baseBomInfoServices;
public Job_BoxFoamInStoreTask_Quartz(ISysTasksQzService SysTasksQzService, ISysJobLogService sysJobLogService,
IBaseSpaceInfoServices baseSpaceInfoServices, IRealTaskInfoServices realTaskInfoService,
IProductPlanInfoServices productPlanInfoServices, IRecordInStoreServices recordInstoreServices,
- IBaseStoreInfoServices baseStoreInfoServices, IBaseSpaceDetailServices IBaseSpaceDetailServices)
+ IBaseStoreInfoServices baseStoreInfoServices, IBaseSpaceDetailServices IBaseSpaceDetailServices,
+ IMaterialCompletionServices IMaterialCompletionServices, IPrintBarCodeServices IPrintBarCodeServices, IBaseBomInfoServices IBaseBomInfoServices)
{
_SysTasksQzService = SysTasksQzService;
_sysJobLogService = sysJobLogService;
@@ -79,27 +91,80 @@ namespace Admin.Core.Tasks
_recordInstoreServices = recordInstoreServices;
_baseStoreInfoServices = baseStoreInfoServices;
_baseSpaceDetailServices = IBaseSpaceDetailServices;
+ _iMaterialCompletionServices = IMaterialCompletionServices;
+ _printBarCodeServices = IPrintBarCodeServices;
+ _baseBomInfoServices = IBaseBomInfoServices;
}
public async Task Execute(IJobExecutionContext context)
{
- await ExecuteJob(context, async () => await Run(context));
+ await ExecuteJob(context, async () => await PassDown(context));
await ExecuteJob(context, async () => await PlcRealRun(context));
}
- public async Task Run(IJobExecutionContext context)
+ public async Task PlcRealRun(IJobExecutionContext context)
{
string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code
- await InStore(storeCode, "B20231082080029650001");
+ await MaterialEnterStore(storeCode);
}
- public async Task PlcRealRun(IJobExecutionContext context)
+
+ private SemaphoreSlim semaphore = new SemaphoreSlim(0);
+ ///
+ /// 获取入库任务下发plc
+ ///
+ ///
+ ///
+ public async Task PassDown(IJobExecutionContext context)
{
string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code
- await MaterialEnterStore(storeCode);
+ RealTaskInfo taskInfo = await GetAwaitSendTask(storeCode);
+ if (taskInfo != null)
+ {
+ logHelper.Info($"下发泡后入库任务:{taskInfo.TaskCode};仓库{taskInfo.StoreCode};货道:{taskInfo.SpaceCode}");
+ if (SendFoamTask_InStore(taskInfo))
+ {
+ logHelper.Info($"泡后入库任务:{taskInfo.TaskCode};下发成功,等待PLC执行反馈");
+ taskInfo.TaskStatus = 2;
+ await _realTaskInfoService.UpdateAsync(taskInfo);
+ RefreshInStoreTaskEvent?.Invoke(taskInfo);//刷新datagrid 列表
+ semaphore.Wait(); //一直堵塞直到信号量释放
+ logHelper.Info($"泡后入库任务:{taskInfo.TaskCode};执行完成");
+ // 刷新入库任务列表
+ }
+ else
+ {
+ logHelper.Info($"泡后入库任务:{taskInfo.TaskCode};下发失败,请排除PLC连接");
+ }
+
+ }
+ else
+ {
+ logHelper.Info("未获取到需要下发的泡后入库任务");
+ }
+ }
+ ///
+ /// 获取待执行的入库任务
+ ///
+ ///
+ ///
+ private async Task GetAwaitSendTask(string storeCode)
+ {
+ RealTaskInfo taskInfo = null;
+
+ try
+ {
+ var tasks =await _realTaskInfoService.QueryAsync(x => x.StoreCode == storeCode && x.TaskType == 1 && x.TaskStatus == 1);
+ taskInfo = tasks.OrderBy(x => x.CreateTime).FirstOrDefault();
+ }
+ catch (Exception ex)
+ {
+ logHelper.Info("获取待执行的入库任务异常", ex);
+ }
+ return taskInfo;
}
#region 入库
///
- /// 入库
+ /// 入库,扫码器委托触发
///
/// 仓库编号
/// 物料条码
@@ -118,23 +183,31 @@ namespace Admin.Core.Tasks
return;
}
string materialType = SubString(materialBarCode);//截取中间物料条码
- var spaceInfo =await _baseSpaceInfoServices.InStoreGetSpaceInfoByMaterialType(storeCode, materialType);
+
+ BaseSpaceInfo spaceInfo =await GetSpaceInfoByMaterialType(storeCode, materialType);
if (spaceInfo != null)
{
logHelper.Info($"匹配货道:{spaceInfo.ToJson()}");
- var list= await _productPlanInfoServices.QueryAsync(d => d.MaterialCode == materialType);
- if (list.Count()==0) return;
- var obj = list.FirstOrDefault();
- var repeatList = await _recordInstoreServices.QueryAsync(d => d.BarCodeCode.Equals(materialBarCode));
- if (repeatList.Count() > 0)
+
+ string message = $"箱体码[{materialBarCode}], 入{spaceInfo.SpaceName},入库中....";
+ PrintBarCode print = await _printBarCodeServices.FirstAsync(x => x.MaterialBarcode == materialBarCode);
+ RefreshScanMateriaCodeEvent?.Invoke(materialBarCode, materialType, print.MaterialName, spaceInfo.SpaceName, message); //刷新界面扫码信息
+ var result =await CreateInStoreTask(spaceInfo, materialBarCode); //创建入库任务
+ if (result)
{
- logHelper.Error($"任务创建记录条码重复异常:{obj.ToJson()}");
- LogDelegateEvent?.Invoke($"物料条码[{materialBarCode}],任务创建失败,该条码任务记录中已存在,请检查!");
- return;
+ #region 更新过点数据
+ MaterialCompletion completion = new MaterialCompletion();
+ completion.OrderCode = print.OrderCode;
+ completion.MaterialBarcode = materialBarCode;
+ completion.MaterialCode = print.MaterialCode;
+ completion.MaterialName = print.MaterialName;
+ completion.StationName = "1003";
+ completion.CompleteDate = DateTime.Now;
+ await _iMaterialCompletionServices.AddAsync(completion);
+ #endregion
+
+ await _baseSpaceInfoServices.UpdateSpaceInfo(spaceInfo);
}
- string message = $"物料[{obj.MaterialName}], 入{spaceInfo.SpaceName},入库中....";
- RefreshScanMateriaCodeEvent?.Invoke(materialBarCode, obj.MaterialCode, obj.MaterialName, spaceInfo.SpaceName, message); //刷新界面扫码信息
- CreateInStoreTask(spaceInfo, materialBarCode); //创建入库任务
}
else
{
@@ -146,18 +219,17 @@ namespace Admin.Core.Tasks
logHelper.Error($"入库业务异常:{ex}");
}
}
- #endregion
#region 创建入库任务
///
/// 创建入库任务
///
///
- private async void CreateInStoreTask(BaseSpaceInfo spaceInfo, string materialCode)
+ private async Task CreateInStoreTask(BaseSpaceInfo spaceInfo, string materialCode)
{
+ bool result = false;
try
{
- string storeCode = Appsettings.app("StoreInfo", "StoreCode");//泡前库code
//生成入库任务依次下发至PLC
RealTaskInfo realTaskInfo = new RealTaskInfo();
realTaskInfo.TaskType = 1;
@@ -170,44 +242,102 @@ namespace Admin.Core.Tasks
realTaskInfo.PlanAmount = 1;
realTaskInfo.TaskStatus = 1; //任务状态:1 - 待执行;2 - 执行中;3 - 完成
realTaskInfo.CreateTime = DateTime.Now;
- var taskList = await _realTaskInfoService.QueryAsync(d => d.MaterialCode.Equals(materialCode) && d.StoreCode == storeCode);
- if (taskList.Count() > 0) return;
-
- int result = await _realTaskInfoService.AddAsync(realTaskInfo);
- if (result > 0)
+ int flag = await _realTaskInfoService.AddAsync(realTaskInfo);
+ if (flag > 0)
{
logHelper.Info("入库任务创建成功");
RefreshInStoreTaskEvent?.Invoke(realTaskInfo);//刷新datagrid 列表
+ result = true;
}
else
{
logHelper.Info("入库任务创建失败");
+ result = false;
}
}
catch (Exception ex)
{
logHelper.Info($"入库任务创建异常:{ex.Message}");
+ result = false;
}
+ return result;
}
#endregion
- #region 截取物料编码
- public string SubString(string barCode)
+
+ /// 通过PLC读取货道信息(在途数量、在库数量、货道状态)
+ ///
+ ///
+ ///
+ ///
+ private async Task GetSpaceInfoByMaterialType(string storeCode, string materialType)
{
+ BaseSpaceInfo result = null;
try
{
- string materialCode = barCode.Substring(7, 10);
- return materialCode;
+ // List info = _spaceInfoService.GetBaseSpaceInfosByMaterialType(storeCode, materialType);
+ List info = await _baseSpaceInfoServices.InStoreGetSpaceInfoByMaterialType(storeCode, materialType);
+ if (info != null)
+ {
+ if (info.Count > 0)
+ {
+ foreach (BaseSpaceInfo item in info)
+ {
+ var spaceInfo = ReadSpaceInfoByPlc(item);
+ item.SpaceStock = spaceInfo.SpaceStock;
+ item.OnRouteAmount = spaceInfo.OnRouteAmount;
+ item.SpaceStatus = spaceInfo.SpaceStatus;
+ }
+
+ result = info.Where(x => x.SpaceStatus == 1 && x.SpaceStock > 0 ? x.SpaceCapacity > (x.SpaceStock + x.OnRouteAmount) : 1 == 1).OrderByDescending(x => x.SpaceStock).OrderBy(x => x.SpaceCode).First();
+
+ }
+ }
}
catch (Exception ex)
{
- logHelper.Info($"截取物料条码失败:{ex.Message}");
- return string.Empty;
+ logHelper.Info("货道信息读取异常", ex);
+ }
+
+ return result;
+ }
+
+ ///
+ /// 通过PLC获取货道信息
+ ///
+ ///
+ ///
+ public BaseSpaceInfo ReadSpaceInfoByPlc(BaseSpaceInfo spaceInfo)
+ {
+ var spaceAddress = spaceConfig.GetSpaceAddress(spaceInfo.StoreCode, spaceInfo.SpaceCode);
+ var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("发泡Plc"));
+ if (obj != null && obj.plc.IsConnected)
+ {
+ spaceInfo.SpaceStock = obj.plc.ReadInt32(spaceAddress.onStore);
+ spaceInfo.OnRouteAmount = obj.plc.ReadInt32(spaceAddress.onRoute);
+ spaceInfo.SpaceStatus = obj.plc.ReadInt32(spaceAddress.spaceStatus);
}
+ return spaceInfo;
}
+
+
#endregion
+ #region 截取物料编码
+ public string SubString(string barCode)
+ {
+ string result = string.Empty;
+ if (!string.IsNullOrEmpty(barCode))
+ {
+ result = barCode.Substring(2, 10);
+ }
+
+ return result;
+ }
+ #endregion
+
+
#region PLC 任务处理表
///
/// PLC 任务处理表
@@ -299,5 +429,223 @@ namespace Admin.Core.Tasks
}
#endregion
+
+
+ #region 泡前入库任务下发处理
+ public bool SendFoamTask_InStore(RealTaskInfo taskInfo)
+ {
+ bool result = false;
+ try
+ {
+ var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("发泡Plc"));
+ if (obj != null && obj.plc.IsConnected)
+ {
+ //写入货道号
+ obj.plc.WriteString("D110", taskInfo.SpaceCode);
+ //写入应答字
+ obj.plc.WriteInt16("D112", "1");
+ //写入任务号
+ obj.plc.WriteInt16("D114", taskInfo.TaskCode);
+ //写入完成后读取应答字进行复位
+ ReadShellAnswer_InStore(taskInfo.TaskCode);
+ result = true;
+ }
+ else
+ {
+ logHelper.Info($"仓库{taskInfo.StoreCode};PLC未连接");
+ }
+ }
+ catch (Exception ex)
+ {
+ logHelper.Error("泡后入库任务下发异常", ex);
+ }
+ return result;
+ }
+
+ ///
+ /// 读取泡后入库应答
+ ///
+ private void ReadShellAnswer_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应答字为2时,上位机清空写入的入库内容
+ if (obj.plc.ReadInt16("D112") == 2)
+ {
+ //写入货道号
+ obj.plc.WriteString("D110", string.Empty);
+ //写入应答字
+ obj.plc.WriteInt16("D112", "0");
+ //写入任务号
+ obj.plc.WriteInt16("D114", string.Empty);
+ isFlag = false;
+
+ ReadShellFinish_InStore(taskCode);
+ }
+
+ Thread.Sleep(1000);
+ } while (isFlag);
+ }
+ else
+ {
+ logHelper.Info("PLC未连接");
+ }
+ });
+ }
+ catch (Exception ex)
+ {
+ logHelper.Error("读取泡后入库应答字异常", ex);
+ }
+ }
+ }
+
+ ///
+ /// 读取泡后入库完成
+ ///
+ 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);
+ }
+ }
+ }
+
+
+ ///
+ /// 泡前库执行反馈
+ ///
+ private void FoamTaskFeedback(string taskCode)
+ {
+
+ logHelper.Info("泡后执行完成,自动释放信号量");
+ InStoreFinish(taskCode);
+ semaphore.Release();
+ }
+ #endregion
+
+ ///
+ /// 入库完成
+ ///
+ ///
+ ///
+ ///
+ private async void InStoreFinish(string taskCode)
+ {
+ try
+ {
+ string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code
+ RealTaskInfo taskInfo = await _realTaskInfoService.FirstAsync(x => x.StoreCode == storeCode && x.TaskCode==taskCode);
+ if (taskInfo != null)
+ {
+ BaseSpaceInfo spaceInfo =await _baseSpaceInfoServices.GetSpaceInfoBySpaceCode(taskInfo.StoreCode, taskInfo.SpaceCode);
+ if (spaceInfo != null)
+ {
+ spaceInfo.MaterialType = taskInfo.MaterialType;
+
+ //读取PLC获取货道信息:存放数量、在途数量,
+ #region Add By wenjy 2023-10-30 13:44:00 通过PLC获取货道信息
+ var item = ReadSpaceInfoByPlc(spaceInfo);
+ spaceInfo.SpaceStock = item.SpaceStock;
+ spaceInfo.OnRouteAmount = item.OnRouteAmount;
+ spaceInfo.SpaceStatus = item.SpaceStatus;
+ #endregion
+
+ await _baseSpaceInfoServices.UpdateSpaceInfo(spaceInfo);
+
+ #region 添加货道明细
+ BaseSpaceDetail spaceDetail = new BaseSpaceDetail();
+ spaceDetail.MaterialType = taskInfo.MaterialType;
+ spaceDetail.MaterialCode = taskInfo.MaterialCode;
+ spaceDetail.MaterialName = await GetMaterialName(taskInfo.MaterialType);
+ spaceDetail.StoreCode = spaceInfo.StoreCode;
+ spaceDetail.SpaceCode = spaceInfo.SpaceCode;
+ spaceDetail.MaterialAmount = 1;
+ await _baseSpaceDetailServices.InsertSpaceDetail(spaceDetail);
+ #endregion
+
+ #region 添加入库记录
+ RecordInStore recordInstore = new RecordInStore();
+ recordInstore.StoreCode = taskInfo.StoreCode;
+ recordInstore.SpaceCode = taskInfo.SpaceCode;
+ recordInstore.MaterialCode = taskInfo.MaterialCode;
+ recordInstore.MaterialType = taskInfo.MaterialType;
+ recordInstore.MaterialName = await GetMaterialName(taskInfo.MaterialType);
+ recordInstore.InStoreAmount = 1;
+ recordInstore.InStoreTime = DateTime.Now;
+ recordInstore.BarCodeCode = taskInfo.MaterialCode;
+ bool result = await _recordInstoreServices.SaveRecordToDb(recordInstore, taskInfo, spaceInfo, spaceDetail);
+ #endregion
+
+ }
+ //清除任务信息
+ await _realTaskInfoService.DeleteTaskInfo(taskCode, storeCode);
+ }
+
+ }
+ catch (Exception ex)
+ {
+ logHelper.Info("入库完成逻辑处理异常", ex);
+ }
+ }
+
+ ///
+ /// 通过BOM获取物料名称
+ ///
+ ///
+ ///
+ public async Task GetMaterialName(string materialType)
+ {
+ string materialName = string.Empty;
+ BaseBomInfo info =await _baseBomInfoServices.GetBomInfoByMaterialCode(materialType);
+ if (info != null)
+ {
+ materialName = info.MaterialName;
+ }
+ return materialName;
+ }
+
+
}
+
}
+
diff --git a/Aucma.Core.Tasks/CommTask/Job_BoxFoamInStoreTaskTask.cs b/Aucma.Core.Tasks/CommTask/Job_BoxFoamInStoreTaskTask.cs
index 1130e767..64a1b6a8 100644
--- a/Aucma.Core.Tasks/CommTask/Job_BoxFoamInStoreTaskTask.cs
+++ b/Aucma.Core.Tasks/CommTask/Job_BoxFoamInStoreTaskTask.cs
@@ -76,7 +76,7 @@ namespace Aucma.Core.Tasks
public async Task InStoreRun()
{
string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code
- await InStore(storeCode, "B20231082080029650001");
+ // await InStore(storeCode, "B20231082080029650001");
}
public async Task OuteRun()
{
@@ -84,56 +84,56 @@ namespace Aucma.Core.Tasks
await MaterialEnterStore(storeCode);
}
- #region 入库
- ///
- /// 入库
- ///
- /// 仓库编号
- /// 物料条码
- private async Task InStore(string storeCode, string materialBarCode)
- {
- try
- {
- if (string.IsNullOrEmpty(storeCode)) return;
- if (string.IsNullOrEmpty(materialBarCode)) return;
+ //#region 入库
+ /////
+ ///// 入库
+ /////
+ ///// 仓库编号
+ ///// 物料条码
+ //private async Task InStore(string storeCode, string materialBarCode)
+ //{
+ // try
+ // {
+ // if (string.IsNullOrEmpty(storeCode)) return;
+ // if (string.IsNullOrEmpty(materialBarCode)) return;
- logHelper.Info($"扫码成功,物料条码:{materialBarCode}");
- var taskList = await _realTaskInfoService.QueryAsync(d => d.MaterialCode.Equals(materialBarCode) && d.StoreCode == storeCode);
- if (taskList.Count() >0)
- {
- LogDelegateEvent?.Invoke($"物料条码[{materialBarCode}],任务创建失败,该物料入库任务已存在!");
- return;
- }
- string materialType = SubString(materialBarCode);//截取中间物料条码
- var spaceInfo =await _baseSpaceInfoServices.InStoreGetSpaceInfoByMaterialType(storeCode, materialType);
- if (spaceInfo != null)
- {
- //logHelper.Info($"匹配货道:{spaceInfo.ToJson()}");
- var list= await _productPlanInfoServices.QueryAsync(d => d.MaterialCode == materialType);
- if (list.Count()==0) return;
- var obj = list.FirstOrDefault();
- var repeatList = await _recordInstoreServices.QueryAsync(d => d.BarCodeCode.Equals(materialBarCode));
- if (repeatList.Count() > 0)
- {
- //logHelper.Error($"任务创建记录条码重复异常:{obj.ToJson()}");
- LogDelegateEvent?.Invoke($"物料条码[{materialBarCode}],任务创建失败,该条码任务记录中已存在,请检查!");
- return;
- }
- string message = $"物料[{obj.MaterialName}], 入{spaceInfo.SpaceName},入库中....";
- RefreshScanMateriaCodeEvent?.Invoke(materialBarCode, obj.MaterialCode, obj.MaterialName, spaceInfo.SpaceName, message); //刷新界面扫码信息
- CreateInStoreTask(spaceInfo, materialBarCode); //创建入库任务
- }
- else
- {
- //报警停线
- }
- }
- catch (Exception ex)
- {
- logHelper.Error($"入库业务异常:{ex}");
- }
- }
- #endregion
+ // logHelper.Info($"扫码成功,物料条码:{materialBarCode}");
+ // var taskList = await _realTaskInfoService.QueryAsync(d => d.MaterialCode.Equals(materialBarCode) && d.StoreCode == storeCode);
+ // if (taskList.Count() >0)
+ // {
+ // LogDelegateEvent?.Invoke($"物料条码[{materialBarCode}],任务创建失败,该物料入库任务已存在!");
+ // return;
+ // }
+ // string materialType = SubString(materialBarCode);//截取中间物料条码
+ // var spaceInfo =await _baseSpaceInfoServices.InStoreGetSpaceInfoByMaterialType(storeCode, materialType);
+ // if (spaceInfo != null)
+ // {
+ // //logHelper.Info($"匹配货道:{spaceInfo.ToJson()}");
+ // var list= await _productPlanInfoServices.QueryAsync(d => d.MaterialCode == materialType);
+ // if (list.Count()==0) return;
+ // var obj = list.FirstOrDefault();
+ // var repeatList = await _recordInstoreServices.QueryAsync(d => d.BarCodeCode.Equals(materialBarCode));
+ // if (repeatList.Count() > 0)
+ // {
+ // //logHelper.Error($"任务创建记录条码重复异常:{obj.ToJson()}");
+ // LogDelegateEvent?.Invoke($"物料条码[{materialBarCode}],任务创建失败,该条码任务记录中已存在,请检查!");
+ // return;
+ // }
+ // string message = $"物料[{obj.MaterialName}], 入{spaceInfo.SpaceName},入库中....";
+ // RefreshScanMateriaCodeEvent?.Invoke(materialBarCode, obj.MaterialCode, obj.MaterialName, spaceInfo.SpaceName, message); //刷新界面扫码信息
+ // CreateInStoreTask(spaceInfo, materialBarCode); //创建入库任务
+ // }
+ // else
+ // {
+ // //报警停线
+ // }
+ // }
+ // catch (Exception ex)
+ // {
+ // logHelper.Error($"入库业务异常:{ex}");
+ // }
+ //}
+ //#endregion
#region 创建入库任务
///