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/BaseBomInfoServiceImpl.cs

74 lines
2.1 KiB
C#

using Aucma.Scada.Model.domain;
using HighWayIot.Log4net;
using System;
using System.Collections.Generic;
using System.Linq;
namespace HighWayIot.Repository.service.Impl
{
public class BaseBomInfoServiceImpl : IBaseBomInfoService
{
Repository<BaseBomInfo> _bomInfoRepository => new Repository<BaseBomInfo>("mes");
private LogHelper logHelper = LogHelper.Instance;
public List<BaseBomInfo> GetBomInfos()
{
try
{
var info = _bomInfoRepository.GetList();
return info;
}
catch (Exception ex)
{
logHelper.Error("获取BOM集合异常", ex);
return null;
}
}
public BaseBomInfo GetChildenBomInfoByMaterialCode(string materialCode, string materialType)
{
BaseBomInfo bomInfo = null;
try
{
var info = GetChildenByParentId(materialCode);
if (info.Count > 0)
{
bomInfo = info.Where(x => x.materialType == materialType).First();
}
}
catch (Exception ex)
{
logHelper.Error("获取BOM集合异常", ex);
}
return bomInfo;
}
private List<BaseBomInfo> GetChildenByParentId(string parentId, List<BaseBomInfo> result = null)
{
if (result == null)
{
result = new List<BaseBomInfo>();
}
try
{
var info = _bomInfoRepository.GetList(x => x.parentId == parentId);
if (info.Count > 0)
{
foreach (var item in info)
{
result.Add(item);
var childInfos = GetChildenByParentId(item.materialCode, result);
}
}
}
catch (Exception ex)
{
logHelper.Error("获取BOM集合异常", ex);
}
return result;
}
}
}