You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Aucma.Scada/HighWayIot.Repository/service/Impl/BaseSpaceInfoServiceImpl.cs

124 lines
4.5 KiB
C#

using HighWayIot.Common;
using HighWayIot.Log4net;
using HighWayIot.Repository.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace HighWayIot.Repository.service.Impl
{
public class BaseSpaceInfoServiceImpl : IBaseSpaceInfoService
{
private Repository<BaseSpaceInfo> _mesRepository = new Repository<BaseSpaceInfo>("mes");
private LogHelper logHelper = LogHelper.Instance;
private JsonChange jsonChange = JsonChange.Instance;
/// <summary>
/// 通过物料类型获取指定货道,如果没有对应类型的货道返回空白类型的货道
/// </summary>
/// <param name="store"></param>
/// <param name="materialType"></param>
/// <returns></returns>
public BaseSpaceInfo GetSpaceInfoByMaterialType(string store, string materialType)
{
BaseSpaceInfo spaceInfo = null;
List<BaseSpaceInfo> spaceInfos;
try
{
Expression<Func<BaseSpaceInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.storeCode == store && x.materialType == materialType && x.spaceStatus == 1 && x.spaceCapacity != x.spaceStock); //相同型号、启用状态、库存未满的货道信息
spaceInfos = _mesRepository.GetList(exp);
if(spaceInfos.Count == 0) //没有指定该类型物料的货道信息,需获取空白货道信息进行分配
{
spaceInfos = GetEmptySpaceInfo();
}
logHelper.Info($"根据仓库{store};物料:{materialType};获取到的货道信息:{jsonChange.ModeToJson(spaceInfos)}");
spaceInfo = inStoreFilter(spaceInfos);
logHelper.Info($"仓库{store};物料:{materialType};匹配的入库货道信息:{jsonChange.ModeToJson(spaceInfo)}");
}
catch(Exception ex)
{
logHelper.Error("通过物料类型获取货道信息异常",ex);
}
return spaceInfo;
}
/// <summary>
/// 更新货道信息
/// </summary>
/// <param name="spaceInfo"></param>
/// <returns></returns>
public bool UpdateSpaceInf(BaseSpaceInfo spaceInfo)
{
bool result = false;
try
{
result = _mesRepository.Update(spaceInfo);
}catch(Exception ex)
{
logHelper.Error("更新货道信息异常", ex);
}
return result;
}
/// <summary>
/// 入库过滤逻辑
/// </summary>
/// <param name="spaceInfos"></param>
private BaseSpaceInfo inStoreFilter(List<BaseSpaceInfo> spaceInfos)
{
BaseSpaceInfo spaceInfo = null;
if(spaceInfos != null)
{
//spaceInfos = spaceInfos.Where(x => x.spaceCapacity != x.spaceStock).ToList(); //获取库存未满的货道
//if(spaceInfos != null)
//{
// spaceInfo = spaceInfos.OrderByDescending(x => x.spaceStock).First(); //获取库存最多的货道
//}
//获取库存未满库存最多的货道
spaceInfo = spaceInfos.Where(x => x.spaceCapacity != x.spaceStock).OrderByDescending(x => x.spaceStock).First();
}
else
{
logHelper.Info("未获取到匹配的货道信息");
}
return spaceInfo;
}
/// <summary>
/// 出库过滤逻辑
/// </summary>
/// <param name="spaceInfos"></param>
private void outStoreFilter(List<BaseSpaceInfo> spaceInfos)
{
}
/// <summary>
/// 获取空货道:未分配物料型号的空白货道
/// </summary>
/// <returns></returns>
private List<BaseSpaceInfo> GetEmptySpaceInfo()
{
List<BaseSpaceInfo> spaceInfos = null;
try
{
Expression<Func<BaseSpaceInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.materialType == null && x.spaceCapacity != x.spaceStock);
spaceInfos = _mesRepository.GetList(exp);
}catch(Exception ex)
{
logHelper.Error("获取空货道异常", ex);
}
return spaceInfos;
}
}
}