liulb@mesnac.com 1 year ago
commit 2a94c4d4c6

@ -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);
/// <summary>
/// 写INI文件
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <param name="Value"></param>
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.path);
}
/// <summary>
/// 读取INI文件
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 删除ini文件下所有段落
/// </summary>
public void ClearAllSection()
{
IniWriteValue(null, null, null);
}
/// <summary>
/// 删除ini文件下personal段落下的所有键
/// </summary>
/// <param name="Section"></param>
public void ClearSection(string Section)
{
IniWriteValue(Section, null, null);
}
public List<string> ReadKeys(String SectionName)
{
return ReadKeys(SectionName, this.path);
}
public List<string> ReadKeys(string SectionName, string iniFilename)
{
List<string> result = new List<string>();
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;
}
}
}

@ -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<PlcSpaceConfig> lazy = new Lazy<PlcSpaceConfig>(() => 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; }
}
}

@ -16,7 +16,7 @@ namespace Admin.Core.IService
/// <param name="store"></param> /// <param name="store"></param>
/// <param name="materialType"></param> /// <param name="materialType"></param>
/// <returns></returns> /// <returns></returns>
Task<BaseSpaceInfo> InStoreGetSpaceInfoByMaterialType(string store, string materialType); Task<List<BaseSpaceInfo>> InStoreGetSpaceInfoByMaterialType(string store, string materialType);
/// <summary> /// <summary>
/// 出库通过物料类型获取指定货道 /// 出库通过物料类型获取指定货道

@ -35,6 +35,8 @@ namespace Admin.Core.Service
_baseBomInfoRepository = baseBomInfoRepository; _baseBomInfoRepository = baseBomInfoRepository;
} }
#region 入库通过物料类型获取指定货道,如果没有对应类型的货道返回空白类型的货道 #region 入库通过物料类型获取指定货道,如果没有对应类型的货道返回空白类型的货道
/// <summary> /// <summary>
/// 入库通过物料类型获取指定货道,如果没有对应类型的货道返回空白类型的货道 /// 入库通过物料类型获取指定货道,如果没有对应类型的货道返回空白类型的货道
@ -42,30 +44,27 @@ namespace Admin.Core.Service
/// <param name="store">物料条码</param> /// <param name="store">物料条码</param>
/// <param name="materialType">货道类型</param> /// <param name="materialType">货道类型</param>
/// <returns>获取合适货道</returns> /// <returns>获取合适货道</returns>
public async Task<BaseSpaceInfo> InStoreGetSpaceInfoByMaterialType(string store, string materialType) public async Task<List<BaseSpaceInfo>> InStoreGetSpaceInfoByMaterialType(string store, string materialType)
{ {
BaseSpaceInfo spaceInfo = null;
List<BaseSpaceInfo> spaceInfos; List<BaseSpaceInfo> spaceInfos = null;
try try
{ {
//Expression<Func<BaseSpaceInfo, bool>> exp = s1 => true; spaceInfos = await _baseSpaceInfoRepository.QueryAsync(x => x.StoreCode == store && x.MaterialType == materialType && x.SpaceStatus == 1);
//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));
if (spaceInfos.Count == 0) //没有指定该类型物料的货道信息,需获取空白货道信息进行分配 if (spaceInfos.Count == 0) //没有指定该类型物料的货道信息,需获取空白货道信息进行分配
spaceInfos = await GetEmptySpaceInfo(store); spaceInfos = await GetEmptySpaceInfo(store);
logHelper.Info($"根据仓库{store};物料:{materialType};获取到的货道信息:{spaceInfos.ToJson()}"); logHelper.Info($"根据仓库{store};物料:{materialType};获取到的货道信息:{spaceInfos.ToJson()}");
spaceInfo = InStoreFilter(spaceInfos); //spaceInfo = InStoreFilter(spaceInfos);
logHelper.Info($"仓库{store};物料:{materialType};匹配的入库货道信息:{spaceInfo.ToJson()}"); //logHelper.Info($"仓库{store};物料:{materialType};匹配的入库货道信息:{spaceInfo.ToJson()}");
spaceInfo.MaterialType = materialType; //spaceInfo.MaterialType = materialType;
} }
catch (Exception ex) catch (Exception ex)
{ {
logHelper.Error("入库通过物料类型获取货道信息异常", ex); logHelper.Error("入库通过物料类型获取货道信息异常", ex);
} }
return spaceInfo; return spaceInfos;
} }
#endregion #endregion
@ -283,8 +282,6 @@ namespace Admin.Core.Service
List<BaseSpaceInfo> spaceInfos = null; List<BaseSpaceInfo> spaceInfos = null;
try try
{ {
Expression<Func<BaseSpaceInfo, bool>> 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); spaceInfos =await _dal.QueryAsync(x => x.MaterialType == null && x.StoreCode == store && x.SpaceCapacity != x.SpaceStock);
} }
catch (Exception ex) catch (Exception ex)

@ -9,6 +9,13 @@ using Admin.Core.Model;
using Admin.Core.Common; using Admin.Core.Common;
using System.Linq; using System.Linq;
using StackExchange.Profiling.Internal; 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;
/// <summary> /// <summary>
/// 泡前库入库任务逻辑处理 /// 泡前库入库任务逻辑处理
@ -65,11 +72,16 @@ namespace Admin.Core.Tasks
private readonly IRecordInStoreServices _recordInstoreServices; private readonly IRecordInStoreServices _recordInstoreServices;
private readonly IBaseStoreInfoServices _baseStoreInfoServices; private readonly IBaseStoreInfoServices _baseStoreInfoServices;
private readonly IBaseSpaceDetailServices _baseSpaceDetailServices; 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, public Job_BoxFoamInStoreTask_Quartz(ISysTasksQzService SysTasksQzService, ISysJobLogService sysJobLogService,
IBaseSpaceInfoServices baseSpaceInfoServices, IRealTaskInfoServices realTaskInfoService, IBaseSpaceInfoServices baseSpaceInfoServices, IRealTaskInfoServices realTaskInfoService,
IProductPlanInfoServices productPlanInfoServices, IRecordInStoreServices recordInstoreServices, IProductPlanInfoServices productPlanInfoServices, IRecordInStoreServices recordInstoreServices,
IBaseStoreInfoServices baseStoreInfoServices, IBaseSpaceDetailServices IBaseSpaceDetailServices) IBaseStoreInfoServices baseStoreInfoServices, IBaseSpaceDetailServices IBaseSpaceDetailServices,
IMaterialCompletionServices IMaterialCompletionServices, IPrintBarCodeServices IPrintBarCodeServices, IBaseBomInfoServices IBaseBomInfoServices)
{ {
_SysTasksQzService = SysTasksQzService; _SysTasksQzService = SysTasksQzService;
_sysJobLogService = sysJobLogService; _sysJobLogService = sysJobLogService;
@ -79,27 +91,80 @@ namespace Admin.Core.Tasks
_recordInstoreServices = recordInstoreServices; _recordInstoreServices = recordInstoreServices;
_baseStoreInfoServices = baseStoreInfoServices; _baseStoreInfoServices = baseStoreInfoServices;
_baseSpaceDetailServices = IBaseSpaceDetailServices; _baseSpaceDetailServices = IBaseSpaceDetailServices;
_iMaterialCompletionServices = IMaterialCompletionServices;
_printBarCodeServices = IPrintBarCodeServices;
_baseBomInfoServices = IBaseBomInfoServices;
} }
public async Task Execute(IJobExecutionContext context) 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)); 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 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);
/// <summary>
/// 获取入库任务下发plc
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public async Task PassDown(IJobExecutionContext context)
{ {
string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code 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("未获取到需要下发的泡后入库任务");
}
}
/// <summary>
/// 获取待执行的入库任务
/// </summary>
/// <param name="storeCode"></param>
/// <returns></returns>
private async Task<RealTaskInfo> 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 入库 #region 入库
/// <summary> /// <summary>
/// 入库 /// 入库,扫码器委托触发
/// </summary> /// </summary>
/// <param name="storeCode">仓库编号</param> /// <param name="storeCode">仓库编号</param>
/// <param name="materialCode">物料条码</param> /// <param name="materialCode">物料条码</param>
@ -118,23 +183,31 @@ namespace Admin.Core.Tasks
return; return;
} }
string materialType = SubString(materialBarCode);//截取中间物料条码 string materialType = SubString(materialBarCode);//截取中间物料条码
var spaceInfo =await _baseSpaceInfoServices.InStoreGetSpaceInfoByMaterialType(storeCode, materialType);
BaseSpaceInfo spaceInfo =await GetSpaceInfoByMaterialType(storeCode, materialType);
if (spaceInfo != null) if (spaceInfo != null)
{ {
logHelper.Info($"匹配货道:{spaceInfo.ToJson()}"); logHelper.Info($"匹配货道:{spaceInfo.ToJson()}");
var list= await _productPlanInfoServices.QueryAsync(d => d.MaterialCode == materialType);
if (list.Count()==0) return; string message = $"箱体码[{materialBarCode}], 入{spaceInfo.SpaceName},入库中....";
var obj = list.FirstOrDefault(); PrintBarCode print = await _printBarCodeServices.FirstAsync(x => x.MaterialBarcode == materialBarCode);
var repeatList = await _recordInstoreServices.QueryAsync(d => d.BarCodeCode.Equals(materialBarCode)); RefreshScanMateriaCodeEvent?.Invoke(materialBarCode, materialType, print.MaterialName, spaceInfo.SpaceName, message); //刷新界面扫码信息
if (repeatList.Count() > 0) var result =await CreateInStoreTask(spaceInfo, materialBarCode); //创建入库任务
if (result)
{ {
logHelper.Error($"任务创建记录条码重复异常:{obj.ToJson()}"); #region 更新过点数据
LogDelegateEvent?.Invoke($"物料条码[{materialBarCode}],任务创建失败,该条码任务记录中已存在,请检查!"); MaterialCompletion completion = new MaterialCompletion();
return; 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 else
{ {
@ -146,18 +219,17 @@ namespace Admin.Core.Tasks
logHelper.Error($"入库业务异常:{ex}"); logHelper.Error($"入库业务异常:{ex}");
} }
} }
#endregion
#region 创建入库任务 #region 创建入库任务
/// <summary> /// <summary>
/// 创建入库任务 /// 创建入库任务
/// </summary> /// </summary>
/// <param name="spaceInfo"></param> /// <param name="spaceInfo"></param>
private async void CreateInStoreTask(BaseSpaceInfo spaceInfo, string materialCode) private async Task<bool> CreateInStoreTask(BaseSpaceInfo spaceInfo, string materialCode)
{ {
bool result = false;
try try
{ {
string storeCode = Appsettings.app("StoreInfo", "StoreCode");//泡前库code
//生成入库任务依次下发至PLC //生成入库任务依次下发至PLC
RealTaskInfo realTaskInfo = new RealTaskInfo(); RealTaskInfo realTaskInfo = new RealTaskInfo();
realTaskInfo.TaskType = 1; realTaskInfo.TaskType = 1;
@ -170,44 +242,102 @@ namespace Admin.Core.Tasks
realTaskInfo.PlanAmount = 1; realTaskInfo.PlanAmount = 1;
realTaskInfo.TaskStatus = 1; //任务状态1 - 待执行2 - 执行中3 - 完成 realTaskInfo.TaskStatus = 1; //任务状态1 - 待执行2 - 执行中3 - 完成
realTaskInfo.CreateTime = DateTime.Now; realTaskInfo.CreateTime = DateTime.Now;
var taskList = await _realTaskInfoService.QueryAsync(d => d.MaterialCode.Equals(materialCode) && d.StoreCode == storeCode); int flag = await _realTaskInfoService.AddAsync(realTaskInfo);
if (taskList.Count() > 0) return; if (flag > 0)
int result = await _realTaskInfoService.AddAsync(realTaskInfo);
if (result > 0)
{ {
logHelper.Info("入库任务创建成功"); logHelper.Info("入库任务创建成功");
RefreshInStoreTaskEvent?.Invoke(realTaskInfo);//刷新datagrid 列表 RefreshInStoreTaskEvent?.Invoke(realTaskInfo);//刷新datagrid 列表
result = true;
} }
else else
{ {
logHelper.Info("入库任务创建失败"); logHelper.Info("入库任务创建失败");
result = false;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
logHelper.Info($"入库任务创建异常:{ex.Message}"); logHelper.Info($"入库任务创建异常:{ex.Message}");
result = false;
} }
return result;
} }
#endregion #endregion
#region 截取物料编码
public string SubString(string barCode) /// 通过PLC读取货道信息在途数量、在库数量、货道状态)
/// </summary>
/// <param name="storeCode"></param>
/// <param name="materialType"></param>
/// <returns></returns>
private async Task<BaseSpaceInfo> GetSpaceInfoByMaterialType(string storeCode, string materialType)
{ {
BaseSpaceInfo result = null;
try try
{ {
string materialCode = barCode.Substring(7, 10); // List<BaseSpaceInfo> info = _spaceInfoService.GetBaseSpaceInfosByMaterialType(storeCode, materialType);
return materialCode; List<BaseSpaceInfo> 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) catch (Exception ex)
{ {
logHelper.Info($"截取物料条码失败:{ex.Message}"); logHelper.Info("货道信息读取异常", ex);
return string.Empty; }
return result;
}
/// <summary>
/// 通过PLC获取货道信息
/// </summary>
/// <param name="spaceInfo"></param>
/// <returns></returns>
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 #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 任务处理表 #region PLC 任务处理表
/// <summary> /// <summary>
/// PLC 任务处理表 /// PLC 任务处理表
@ -299,5 +429,223 @@ namespace Admin.Core.Tasks
} }
#endregion #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;
}
/// <summary>
/// 读取泡后入库应答
/// </summary>
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);
}
}
}
/// <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>
private void FoamTaskFeedback(string taskCode)
{
logHelper.Info("泡后执行完成,自动释放信号量");
InStoreFinish(taskCode);
semaphore.Release();
}
#endregion
/// <summary>
/// 入库完成
/// </summary>
/// <param name="storeCode"></param>
/// <param name="spaceCode"></param>
/// <param name="materialType"></param>
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);
}
}
/// <summary>
/// 通过BOM获取物料名称
/// </summary>
/// <param name="materialType"></param>
/// <returns></returns>
public async Task<string> GetMaterialName(string materialType)
{
string materialName = string.Empty;
BaseBomInfo info =await _baseBomInfoServices.GetBomInfoByMaterialCode(materialType);
if (info != null)
{
materialName = info.MaterialName;
}
return materialName;
}
} }
} }

@ -76,7 +76,7 @@ namespace Aucma.Core.Tasks
public async Task InStoreRun() public async Task InStoreRun()
{ {
string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code
await InStore(storeCode, "B20231082080029650001"); // await InStore(storeCode, "B20231082080029650001");
} }
public async Task OuteRun() public async Task OuteRun()
{ {
@ -84,56 +84,56 @@ namespace Aucma.Core.Tasks
await MaterialEnterStore(storeCode); await MaterialEnterStore(storeCode);
} }
#region 入库 //#region 入库
/// <summary> ///// <summary>
/// 入库 ///// 入库
/// </summary> ///// </summary>
/// <param name="storeCode">仓库编号</param> ///// <param name="storeCode">仓库编号</param>
/// <param name="materialCode">物料条码</param> ///// <param name="materialCode">物料条码</param>
private async Task InStore(string storeCode, string materialBarCode) //private async Task InStore(string storeCode, string materialBarCode)
{ //{
try // try
{ // {
if (string.IsNullOrEmpty(storeCode)) return; // if (string.IsNullOrEmpty(storeCode)) return;
if (string.IsNullOrEmpty(materialBarCode)) return; // if (string.IsNullOrEmpty(materialBarCode)) return;
logHelper.Info($"扫码成功,物料条码:{materialBarCode}"); // logHelper.Info($"扫码成功,物料条码:{materialBarCode}");
var taskList = await _realTaskInfoService.QueryAsync(d => d.MaterialCode.Equals(materialBarCode) && d.StoreCode == storeCode); // var taskList = await _realTaskInfoService.QueryAsync(d => d.MaterialCode.Equals(materialBarCode) && d.StoreCode == storeCode);
if (taskList.Count() >0) // if (taskList.Count() >0)
{ // {
LogDelegateEvent?.Invoke($"物料条码[{materialBarCode}],任务创建失败,该物料入库任务已存在!"); // LogDelegateEvent?.Invoke($"物料条码[{materialBarCode}],任务创建失败,该物料入库任务已存在!");
return; // return;
} // }
string materialType = SubString(materialBarCode);//截取中间物料条码 // string materialType = SubString(materialBarCode);//截取中间物料条码
var spaceInfo =await _baseSpaceInfoServices.InStoreGetSpaceInfoByMaterialType(storeCode, materialType); // var spaceInfo =await _baseSpaceInfoServices.InStoreGetSpaceInfoByMaterialType(storeCode, materialType);
if (spaceInfo != null) // if (spaceInfo != null)
{ // {
//logHelper.Info($"匹配货道:{spaceInfo.ToJson()}"); // //logHelper.Info($"匹配货道:{spaceInfo.ToJson()}");
var list= await _productPlanInfoServices.QueryAsync(d => d.MaterialCode == materialType); // var list= await _productPlanInfoServices.QueryAsync(d => d.MaterialCode == materialType);
if (list.Count()==0) return; // if (list.Count()==0) return;
var obj = list.FirstOrDefault(); // var obj = list.FirstOrDefault();
var repeatList = await _recordInstoreServices.QueryAsync(d => d.BarCodeCode.Equals(materialBarCode)); // var repeatList = await _recordInstoreServices.QueryAsync(d => d.BarCodeCode.Equals(materialBarCode));
if (repeatList.Count() > 0) // if (repeatList.Count() > 0)
{ // {
//logHelper.Error($"任务创建记录条码重复异常:{obj.ToJson()}"); // //logHelper.Error($"任务创建记录条码重复异常:{obj.ToJson()}");
LogDelegateEvent?.Invoke($"物料条码[{materialBarCode}],任务创建失败,该条码任务记录中已存在,请检查!"); // LogDelegateEvent?.Invoke($"物料条码[{materialBarCode}],任务创建失败,该条码任务记录中已存在,请检查!");
return; // return;
} // }
string message = $"物料[{obj.MaterialName}], 入{spaceInfo.SpaceName},入库中...."; // string message = $"物料[{obj.MaterialName}], 入{spaceInfo.SpaceName},入库中....";
RefreshScanMateriaCodeEvent?.Invoke(materialBarCode, obj.MaterialCode, obj.MaterialName, spaceInfo.SpaceName, message); //刷新界面扫码信息 // RefreshScanMateriaCodeEvent?.Invoke(materialBarCode, obj.MaterialCode, obj.MaterialName, spaceInfo.SpaceName, message); //刷新界面扫码信息
CreateInStoreTask(spaceInfo, materialBarCode); //创建入库任务 // CreateInStoreTask(spaceInfo, materialBarCode); //创建入库任务
} // }
else // else
{ // {
//报警停线 // //报警停线
} // }
} // }
catch (Exception ex) // catch (Exception ex)
{ // {
logHelper.Error($"入库业务异常:{ex}"); // logHelper.Error($"入库业务异常:{ex}");
} // }
} //}
#endregion //#endregion
#region 创建入库任务 #region 创建入库任务
/// <summary> /// <summary>

Loading…
Cancel
Save