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

292 lines
11 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Aucma.Scada.Model.domain;
using HighWayIot.Common;
using HighWayIot.Config;
using HighWayIot.Log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
namespace HighWayIot.Repository.service.Impl
{
public class BaseSpaceInfoServiceImpl : IBaseSpaceInfoService
{
private Repository<BaseSpaceInfo> _mesRepository = new Repository<BaseSpaceInfo>("mes");
private Repository<RealTaskInfo> _realTaskInfoRepository = new Repository<RealTaskInfo>("mes");
private AppConfig appConfig = AppConfig.Instance;
private LogHelper logHelper = LogHelper.Instance;
private JsonChange jsonChange = JsonChange.Instance;
/// <summary>
/// 未使用,入库通过物料类型获取指定货道,如果没有对应类型的货道返回空白类型的货道
/// </summary>
/// <param name="store"></param>
/// <param name="materialType"></param>
/// <returns></returns>
public BaseSpaceInfo InStoreGetSpaceInfoByMaterialType(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 + x.onRouteAmount)); //相同型号、启用状态、库存未满的货道信息
spaceInfos = _mesRepository.GetList(exp);
if (spaceInfos.Count == 0) //没有指定该类型物料的货道信息,需获取空白货道信息进行分配
{
spaceInfos = GetEmptySpaceInfo(store);
}
logHelper.Info($"根据仓库{store};物料:{materialType};获取到的货道信息:{jsonChange.ModeToJson(spaceInfos)}");
spaceInfo = inStoreFilter(spaceInfos);
if (spaceInfo != null)
{
logHelper.Info($"仓库{store};物料:{materialType};匹配的入库货道信息:{jsonChange.ModeToJson(spaceInfo)}");
spaceInfo.materialType = materialType;
}
else
{
logHelper.Info($"仓库{store};物料:{materialType};未匹配到可用货道");
}
}
catch (Exception ex)
{
logHelper.Error("入库通过物料类型获取货道信息异常", ex);
}
return spaceInfo;
}
/// <summary>
/// 入库过滤逻辑
/// </summary>
/// <param name="spaceInfos"></param>
private BaseSpaceInfo inStoreFilter(List<BaseSpaceInfo> spaceInfos)
{
BaseSpaceInfo spaceInfo = null;
if (spaceInfos.Count > 0)
{
//获取库存未满库存最多的货道
spaceInfo = spaceInfos.Where(x => x.spaceCapacity != x.spaceStock).OrderByDescending(x => x.spaceStock).First();
}
else
{
logHelper.Info("入库过滤未获取到匹配的货道信息");
}
return spaceInfo;
}
/// <summary>
/// 获取空货道:未分配物料型号的空白货道
/// </summary>
/// <returns></returns>
public List<BaseSpaceInfo> GetEmptySpaceInfo(string store)
{
List<BaseSpaceInfo> spaceInfos = null;
try
{
Expression<Func<BaseSpaceInfo, bool>> exp = s1 => true;
exp = exp.And(x => x.materialType == null && x.storeCode == store && x.spaceCapacity != x.spaceStock && x.unusualFlag==1);
spaceInfos = _mesRepository.GetList(exp);
if(spaceInfos.Count > 0)
{
spaceInfos.OrderBy(x => x.objId);
}
}
catch (Exception ex)
{
logHelper.Error("获取空货道异常", ex);
}
return spaceInfos;
}
/// <summary>
/// 出库通过物料类型获取指定货道
/// </summary>
/// <param name="store"></param>
/// <param name="materialType"></param>
/// <returns></returns>
public BaseSpaceInfo OutStoreGetSpaceInfoByMaterialCode(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.spaceStock - x.outRouteAmount > 0); //相同型号、启用状态、库存不为空的货道信息
spaceInfos = _mesRepository.GetList(exp);
logHelper.Info($"根据仓库{store};物料:{materialType};获取到的货道信息:{jsonChange.ModeToJson(spaceInfos)}");
spaceInfo = outStoreFilter(spaceInfos);
logHelper.Info($"仓库{store};物料:{materialType};匹配的入库货道信息:{jsonChange.ModeToJson(spaceInfo)}");
}
catch (Exception ex)
{
logHelper.Error("出库通过物料类型获取货道信息异常", ex);
}
return spaceInfo;
}
/// <summary>
/// 出库过滤逻辑
/// </summary>
/// <param name="spaceInfos"></param>
private BaseSpaceInfo outStoreFilter(List<BaseSpaceInfo> spaceInfos)
{
BaseSpaceInfo spaceInfo = null;
if (spaceInfos.Count > 0)
{
//获取库存最少的货道(优先清空货道)
spaceInfo = spaceInfos.Where(x => x.spaceStock > 0).OrderBy(x => x.spaceStock).First();
}
else
{
logHelper.Info("出库过滤未获取到匹配的货道信息");
}
return spaceInfo;
}
/// <summary>
/// 通过货道编号获取货道信息
/// </summary>
/// <param name="store"></param>
/// <param name="spaceCode"></param>
/// <returns></returns>
public BaseSpaceInfo GetSpaceInfoBySpaceCode(string store, string spaceCode)
{
BaseSpaceInfo spaceInfo = null;
try
{
spaceInfo = _mesRepository.GetFirst(x => x.storeCode == store && x.spaceCode == spaceCode);
}
catch (Exception ex)
{
logHelper.Error("通过货道编号获取货道信息异常", ex);
}
return spaceInfo;
}
/// <summary>
/// 通过仓库编号获取货道信息
/// </summary>
/// <param name="storeCode"></param>
/// <returns></returns>
public List<BaseSpaceInfo> GetSpaceInfosByStoreCode(string storeCode)
{
List<BaseSpaceInfo> spaceInfos = null;
try
{
spaceInfos = _mesRepository.GetList(x => x.storeCode == storeCode).ToList();
}
catch (Exception ex)
{
logHelper.Error("获取货道信息异常", ex);
}
return spaceInfos;
}
/// <summary>
/// 更新货道信息
/// </summary>
/// <param name="spaceInfo"></param>
/// <returns></returns>
public bool UpdateSpaceInfo(BaseSpaceInfo spaceInfo)
{
bool result = false;
try
{
result = _mesRepository.Update(spaceInfo);
}
catch (Exception ex)
{
logHelper.Error("更新货道信息异常", ex);
}
return result;
}
/// <summary>
/// 筛选货道的时候,入库不能选择正在出库的货道,也不能选择出过还未出干净货道,出库不能选择正在入库的货道
/// </summary>
/// <param name="storeCode"></param>
/// <param name="materialType"></param>
/// <param name="taskType">找货道任务类型入库1出库2</param>
/// <returns></returns>
public List<BaseSpaceInfo> GetBaseSpaceInfosByMaterialType(string storeCode, string materialType,int taskType)
{
List<BaseSpaceInfo> spaceInfos = null;
try
{
Expression<Func<BaseSpaceInfo, bool>> exp = s1 => true;
if(taskType==1)
{
exp = exp.And(x => x.storeCode == storeCode && x.materialType == materialType && x.spaceStatus == 1 && x.inStoreFlag == 1 && x.unusualFlag==1); //相同型号、启用状态的货道信息
}else if (taskType == 2)
{
exp = exp.And(x => x.storeCode == storeCode && x.materialType == materialType && x.spaceStatus == 1 && x.outStoreFlag==1 && x.spaceStock>0 && x.unusualFlag == 1); //相同型号、启用状态的货道信息
}
spaceInfos = _mesRepository.GetList(exp);
// spaceInfos = FilterSpaceList(spaceInfos,taskType);
if (taskType==1 && ( spaceInfos==null || spaceInfos.Count == 0)) //入库任务没有指定该类型物料的货道信息,需获取空白货道信息进行分配
{
spaceInfos = GetEmptySpaceInfo(storeCode);
}
logHelper.Info($"根据仓库{storeCode};物料:{materialType};获取到的货道信息:{jsonChange.ModeToJson(spaceInfos)}");
}
catch (Exception ex)
{
logHelper.Error("获取货道信息异常", ex);
}
return spaceInfos;
}
/// <summary>
/// 入库过滤掉有出库任务的货道或者是出过货的货道20240315
/// 出库过滤掉有入库任务的货道
/// </summary>
/// <param name="spaceInfos"></param>
/// <returns></returns>
public List<BaseSpaceInfo> FilterSpaceList(List<BaseSpaceInfo> spaceInfos,int taskType)
{
try
{
if (taskType == 1) // 入库找货道
{
List<RealTaskInfo> taskList = _realTaskInfoRepository.GetList(x => x.storeCode == appConfig.foamStoreCode && x.taskType == 2);
List<BaseSpaceInfo> filteredBaseSpaceInfos = spaceInfos.Where(s => !taskList.Any(r => r.spaceCode == s.spaceCode)).ToList();
return filteredBaseSpaceInfos;
}else if (taskType == 2) // 出库找货道
{
List<RealTaskInfo> taskList = _realTaskInfoRepository.GetList(x => x.storeCode == appConfig.foamStoreCode && x.taskType == 1);
List<BaseSpaceInfo> filteredBaseSpaceInfos = spaceInfos.Where(s => !taskList.Any(r => r.spaceCode == s.spaceCode)).ToList();
return filteredBaseSpaceInfos;
}
}
catch (Exception ex)
{
logHelper.Info("FilterOutSpaceList异常"+ex.Message.ToString());
}
return null;
}
}
}