|
|
using HighWayIot.Log4net;
|
|
|
using HighWayIot.Repository.domain;
|
|
|
using HighWayIot.Repository.service;
|
|
|
using HighWayIot.Repository.service.Impl;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace Aucma.Scada.Business
|
|
|
{
|
|
|
public class InStoreBusiness
|
|
|
{
|
|
|
private static readonly Lazy<InStoreBusiness> lazy = new Lazy<InStoreBusiness>(() => new InStoreBusiness());
|
|
|
public static InStoreBusiness Instance
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return lazy.Value;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private LogHelper logHelper = LogHelper.Instance;
|
|
|
|
|
|
private IBaseSpaceInfoService _spaceInfoService = new BaseSpaceInfoServiceImpl();
|
|
|
|
|
|
private IRealTaskInfoService _taskInfoService = new RealTaskInfoServiceImpl();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 初始化入库任务
|
|
|
/// </summary>
|
|
|
/// <param name="message"></param>
|
|
|
public delegate void RefreshInStoreTask(RealTaskInfo taskInfos);
|
|
|
public event RefreshInStoreTask RefreshInStoreTaskEvent;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 扫码信息刷新
|
|
|
/// </summary>
|
|
|
/// <param name="materialCode"></param>
|
|
|
/// <param name="materialName"></param>
|
|
|
/// <param name="spaceName"></param>
|
|
|
/// <param name="materialType"></param>
|
|
|
public delegate void RefreshScanMateriaCode(string materialCode,string materialName,string spaceName,string materialType);
|
|
|
public event RefreshScanMateriaCode RefreshScanMateriaCodeEvent;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 日志信息刷新
|
|
|
/// </summary>
|
|
|
/// <param name="message"></param>
|
|
|
public delegate void RefreshLogMessage(string message);
|
|
|
public event RefreshLogMessage RefreshLogMessageEvent;
|
|
|
|
|
|
public InStoreBusiness()
|
|
|
{
|
|
|
//System.Timers.Timer timer = new System.Timers.Timer(interval: 3000);
|
|
|
//timer.Elapsed += (sender, e) => HandleTimer();
|
|
|
//timer.Start();
|
|
|
}
|
|
|
|
|
|
private void HandleTimer()
|
|
|
{
|
|
|
InStore("X-001", "SC232");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 入库
|
|
|
/// </summary>
|
|
|
/// <param name="storeCode"></param>
|
|
|
/// <param name="materialType"></param>
|
|
|
private void InStore(string storeCode, string materialCode)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
PrintLogInfoMessage($"扫码成功,物料码:{materialCode}");
|
|
|
string materialType = materialCode;
|
|
|
var spaceInfo = _spaceInfoService.InStoreGetSpaceInfoByMaterialType(storeCode, materialType);
|
|
|
if (spaceInfo != null)
|
|
|
{
|
|
|
PrintLogInfoMessage($"匹配货道:{spaceInfo.spaceName}");
|
|
|
RefreshScanMateriaCodeEvent?.Invoke(materialCode, materialType, spaceInfo.spaceName, storeCode); //刷新界面扫码信息
|
|
|
CreateInStoreTask(spaceInfo, materialCode); //创建入库任务
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//报警停线
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
PrintLogErrorMessage("入库业务异常", ex);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 创建入库任务
|
|
|
/// </summary>
|
|
|
/// <param name="spaceInfo"></param>
|
|
|
private void CreateInStoreTask(BaseSpaceInfo spaceInfo, string materialCode)
|
|
|
{
|
|
|
//生成入库任务依次下发至PLC
|
|
|
RealTaskInfo realTaskInfo = new RealTaskInfo();
|
|
|
realTaskInfo.taskType = 1;
|
|
|
realTaskInfo.taskCode = System.Guid.NewGuid().ToString("N").Substring(0,6);
|
|
|
realTaskInfo.storeCode = spaceInfo.storeCode;
|
|
|
realTaskInfo.spaceCode = spaceInfo.spaceCode;
|
|
|
realTaskInfo.materialType = spaceInfo.materialType;
|
|
|
realTaskInfo.materialCode = System.Guid.NewGuid().ToString("N").Substring(0, 6); ;
|
|
|
realTaskInfo.planAmount = 1;
|
|
|
realTaskInfo.taskStatus = 1;
|
|
|
realTaskInfo.createTime = DateTime.Now;
|
|
|
bool result = _taskInfoService.AddTaskInfo(realTaskInfo);
|
|
|
if (result)
|
|
|
{
|
|
|
PrintLogInfoMessage("入库任务创建成功");
|
|
|
|
|
|
RefreshInStoreTaskEvent?.Invoke(realTaskInfo);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
PrintLogInfoMessage("入库任务创建失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 入库完成
|
|
|
/// </summary>
|
|
|
/// <param name="storeCode"></param>
|
|
|
/// <param name="spaceCode"></param>
|
|
|
/// <param name="materialType"></param>
|
|
|
private void InStoreFinish(string taskCode)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
var taskInfo = _taskInfoService.GetTaskInfoByTaskCode(taskCode);
|
|
|
if (taskInfo != null)
|
|
|
{
|
|
|
var spaceInfo = _spaceInfoService.GetSpaceInfoBySpaceCode(taskInfo.storeCode, taskInfo.spaceCode);
|
|
|
|
|
|
if (spaceInfo != null)
|
|
|
{
|
|
|
//读取PLC获取货道信息:存放数量、在途数量
|
|
|
spaceInfo.materialType = taskInfo.materialType;
|
|
|
_spaceInfoService.UpdateSpaceInfo(spaceInfo);
|
|
|
|
|
|
}
|
|
|
//清除任务信息
|
|
|
_taskInfoService.DeleteTaskInfo(taskCode);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
PrintLogErrorMessage("入库完成逻辑处理异常", ex);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 日志输出,界面刷新同时记录文件
|
|
|
/// </summary>
|
|
|
/// <param name="message"></param>
|
|
|
private void PrintLogInfoMessage(string message)
|
|
|
{
|
|
|
RefreshLogMessageEvent?.Invoke(message);
|
|
|
logHelper.Info(message);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 异常日志输出
|
|
|
/// </summary>
|
|
|
/// <param name="message"></param>
|
|
|
/// <param name="ex"></param>
|
|
|
private void PrintLogErrorMessage(string message, Exception ex = null)
|
|
|
{
|
|
|
RefreshLogMessageEvent?.Invoke(message);
|
|
|
logHelper.Error(message, ex);
|
|
|
}
|
|
|
}
|
|
|
}
|