using Aucma.Scada.Model.domain;
using HighWayIot.Log4net;
using HighWayIot.Repository.service;
using System;
using System.Collections.Generic;
namespace Aucma.Scada.Business
{
///
/// 实时库存业务逻辑
///
public sealed class InventoryInfoBusiness
{
#region 单例实现
private static readonly Lazy lazy = new Lazy(() => new InventoryInfoBusiness());
public static InventoryInfoBusiness Instance
{
get
{
return lazy.Value;
}
}
#endregion
#region 对象引用
private LogHelper logHelper = LogHelper.Instance;
private RegisterServices registerServices = RegisterServices.Instance;
#endregion
#region 接口引用
///
/// 货道信息
///
private IBaseSpaceInfoService _spaceInfoService;
///
/// 货道明细
///
private IBaseSpaceDetailService _spaceDetailService;
#endregion
#region 委托事件
///
/// 刷新货道明细
///
///
public delegate void RefreshSpaceDetails(List taskInfos);
public event RefreshSpaceDetails RefreshSpaceDetailsEvent;
#endregion
private InventoryInfoBusiness()
{
_spaceInfoService = registerServices.GetService();
_spaceDetailService = registerServices.GetService();
}
///
/// 获取货道信息
///
///
///
public List GetSpaceInfos(string storeCode)
{
List spaceInfos = null;
try
{
spaceInfos = _spaceInfoService.GetSpaceInfosByStoreCode(storeCode);
}
catch (Exception ex)
{
logHelper.Error("获取货道信息异常", ex);
}
return spaceInfos;
}
///
/// 修改货道入库标识
///
///
///
public bool UpdateInStoreFlag(string storeCode, string spaceCode)
{
bool result = false;
try
{
BaseSpaceInfo spaceInfo = _spaceInfoService.GetSpaceInfoBySpaceCode(storeCode, spaceCode);
if (spaceInfo != null)
{
spaceInfo.inStoreFlag = spaceInfo.inStoreFlag == 1 ? 2 : 1;
result = _spaceInfoService.UpdateSpaceInfo(spaceInfo);
logHelper.Info($"修改仓库:{storeCode};货道:{spaceCode};入库标识:{spaceInfo.inStoreFlag};修改{(result == true ? "成功" : "失败")}");
}
}
catch (Exception ex)
{
logHelper.Error("修改货道入库标识异常", ex);
}
return result;
}
///
/// 修改货道出库标识
///
///
///
///
public bool UpdateOutStoreFlag(string storeCode, string spaceCode)
{
bool result = false;
try
{
BaseSpaceInfo spaceInfo = _spaceInfoService.GetSpaceInfoBySpaceCode(storeCode, spaceCode);
if (spaceInfo != null)
{
spaceInfo.outStoreFlag = spaceInfo.outStoreFlag == 1 ? 2 : 1;
result = _spaceInfoService.UpdateSpaceInfo(spaceInfo);
logHelper.Info($"修改仓库:{storeCode};货道:{spaceCode};出库标识:{spaceInfo.outStoreFlag};修改{(result == true ? "成功" : "失败")}");
}
}
catch (Exception ex)
{
logHelper.Error("修改货道出库标识异常", ex);
}
return result;
}
///
/// 设置异常货道标识
///
///
///
///
public bool UpdateUnusualFlag(string storeCode, string spaceCode)
{
bool result = false;
try
{
BaseSpaceInfo spaceInfo = _spaceInfoService.GetSpaceInfoBySpaceCode(storeCode, spaceCode);
if (spaceInfo != null)
{
spaceInfo.unusualFlag = spaceInfo.unusualFlag == 1 ? 2 : 1;
result = _spaceInfoService.UpdateSpaceInfo(spaceInfo);
logHelper.Info($"修改仓库:{storeCode};货道:{spaceCode};异常标识:{spaceInfo.unusualFlag};修改{(result == true ? "成功" : "失败")}");
}
}
catch (Exception ex)
{
logHelper.Error("修改异常货道标识", ex);
}
return result;
}
///
/// 修改货道状态
///
///
///
///
public bool UpdateSpaceStatus(string storeCode, string spaceCode)
{
bool result = false;
try
{
BaseSpaceInfo spaceInfo = _spaceInfoService.GetSpaceInfoBySpaceCode(storeCode, spaceCode);
if (spaceInfo != null)
{
spaceInfo.spaceStatus = spaceInfo.spaceStatus == 1 ? 4 : 1;
result = _spaceInfoService.UpdateSpaceInfo(spaceInfo);
logHelper.Info($"修改仓库:{storeCode};货道:{spaceCode};货道状态:{spaceInfo.unusualFlag};修改{(result == true ? "成功" : "失败")}");
}
}
catch (Exception ex)
{
logHelper.Error("修改异常货道标识", ex);
}
return result;
}
///
/// 刷新货道明细
///
///
///
///
public void RefreshBaseSpaceDetails(string storeCode, string spaceCode)
{
List spaceDetails = _spaceDetailService.GetSpaceDetailsBySpaceCode(storeCode, spaceCode);
if (spaceDetails != null)
{
RefreshSpaceDetailsEvent?.Invoke(spaceDetails);
}
}
///
/// 获取货道明细
///
///
///
///
public List GetBaseSpaceDetails(string storeCode, string spaceCode)
{
List spaceDetails = _spaceDetailService.GetSpaceDetailsBySpaceCode(storeCode, spaceCode);
return spaceDetails;
}
}
}