using Admin.Core.IService;
using Admin.Core.Model;
using Aucma.Scada.UI.ViewModel;
using log4net;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Aucma.Scada.UI
{
///
/// 实时库存业务逻辑
///
public class InventoryInfoBusiness
{
#region 单例实现
//private static readonly InventoryInfoBusiness lazy = new InventoryInfoBusiness();
//public static InventoryInfoBusiness Instance
//{
// get
// {
// return lazy;
// }
//}
#endregion
#region 对象引用
private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(InventoryInfoBusiness));
#endregion
#region 接口引用
///
/// 货道信息
///
private IBaseSpaceInfoServices _spaceInfoService;
///
/// 货道明细
///
private IBaseSpaceDetailServices _spaceDetailService;
private IBaseBomInfoServices _bomInfoService;
#endregion
#region 委托事件
///
/// 刷新货道明细
///
///
public delegate void RefreshSpaceDetails(List taskInfos);
public event RefreshSpaceDetails RefreshSpaceDetailsEvent;
#endregion
public InventoryInfoBusiness()
{
_spaceInfoService = App.ServiceProvider.GetService();
_spaceDetailService = App.ServiceProvider.GetService();
_bomInfoService = App.ServiceProvider.GetService();
}
///
/// 获取货道信息
///
///
///
public async Task> GetSpaceInfos(string storeCode)
{
List spaceInfos = null;
try
{
spaceInfos =(await _spaceInfoService.GetSpaceInfosByStoreCode(storeCode)).OrderBy(x => x.ObjId).ToList();
}
catch (Exception ex)
{
logHelper.Error("获取货道信息异常", ex);
}
return spaceInfos;
}
///
/// 修改货道入库标识
///
///
///
public async Task UpdateInStoreFlag(string storeCode, string spaceCode)
{
bool result = false;
try
{
BaseSpaceInfo spaceInfo =await _spaceInfoService.GetSpaceInfoBySpaceCode(storeCode, spaceCode);
if (spaceInfo != null)
{
spaceInfo.InStoreFlag = spaceInfo.InStoreFlag == 1 ? 2 : 1;
result =await _spaceInfoService.UpdateSpaceInfo(spaceInfo);
logHelper.Info($"修改仓库:{storeCode};货道:{spaceCode};入库标识:{spaceInfo.InStoreFlag};修改{(result == true ? "成功" : "失败")}");
}
}
catch (Exception ex)
{
logHelper.Error("修改货道入库标识异常", ex);
}
return result;
}
///
/// 修改货道出库标识
///
///
///
///
public async Task UpdateOutStoreFlag(string storeCode, string spaceCode)
{
bool result = false;
try
{
BaseSpaceInfo spaceInfo =await _spaceInfoService.GetSpaceInfoBySpaceCode(storeCode, spaceCode);
if (spaceInfo != null)
{
spaceInfo.OutStoreFlag = spaceInfo.OutStoreFlag == 1 ? 2 : 1;
result =await _spaceInfoService.UpdateSpaceInfo(spaceInfo);
logHelper.Info($"修改仓库:{storeCode};货道:{spaceCode};出库标识:{spaceInfo.OutStoreFlag};修改{(result == true ? "成功" : "失败")}");
}
}
catch (Exception ex)
{
logHelper.Error("修改货道出库标识异常", ex);
}
return result;
}
///
/// 修改异常货道标识
///
///
///
///
public async Task UpdateUnusualFlag(string storeCode, string spaceCode)
{
bool result = false;
try
{
BaseSpaceInfo spaceInfo =await _spaceInfoService.GetSpaceInfoBySpaceCode(storeCode, spaceCode);
if (spaceInfo != null)
{
spaceInfo.UnusualFlag = spaceInfo.UnusualFlag == 1 ? 2 : 1;
result =await _spaceInfoService.UpdateSpaceInfo(spaceInfo);
logHelper.Info($"修改仓库:{storeCode};货道:{spaceCode};异常标识:{spaceInfo.UnusualFlag};修改{(result == true ? "成功" : "失败")}");
}
}
catch (Exception ex)
{
logHelper.Error("修改异常货道标识", ex);
}
return result;
}
///
/// 修改货道状态
///
///
///
///
public async Task UpdateSpaceStatus(string storeCode, string spaceCode)
{
bool result = false;
try
{
BaseSpaceInfo spaceInfo =await _spaceInfoService.GetSpaceInfoBySpaceCode(storeCode, spaceCode);
if (spaceInfo != null)
{
spaceInfo.SpaceStatus = spaceInfo.SpaceStatus == 1 ? 2 : 1;
result =await _spaceInfoService.UpdateSpaceInfo(spaceInfo);
logHelper.Info($"修改仓库:{storeCode};货道:{spaceCode};货道状态:{spaceInfo.UnusualFlag};修改{(result == true ? "成功" : "失败")}");
}
}
catch (Exception ex)
{
logHelper.Error("修改异常货道标识", ex);
}
return result;
}
///
/// 刷新货道明细
///
///
///
///
public async void RefreshBaseSpaceDetails(string storeCode, string spaceCode)
{
List spaceDetails =await _spaceDetailService.GetSpaceDetailsBySpaceCode(storeCode, spaceCode);
if (spaceDetails != null)
{
RefreshSpaceDetailsEvent?.Invoke(spaceDetails);
}
}
///
/// 获取货道明细
///
///
///
///
public async Task> GetBaseSpaceDetails(string storeCode, string spaceCode)
{
List spaceDetails =await _spaceDetailService.GetSpaceDetailsBySpaceCode(storeCode, spaceCode);
return spaceDetails;
}
}
}