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.

83 lines
2.6 KiB
C#

using Admin.Core.IRepository;
using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Model.Model_New;
using log4net;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.IdentityModel.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Admin.Core.Service
{
public class BaseBomInfoServices : BaseServices<BaseBomInfo>, IBaseBomInfoServices
{
private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(BaseBomInfoServices));
private readonly IBaseRepository<BaseBomInfo> _dal;
public BaseBomInfoServices(IBaseRepository<BaseBomInfo> dal)
{
this._dal = dal;
base.BaseDal = dal;
}
public async Task<BaseBomInfo> GetBomInfoByMaterialCode(string materialCode)
{
BaseBomInfo bomInfo = null;
try
{
bomInfo = await _dal.FirstAsync(x => x.MaterialCode == materialCode);
}
catch (Exception ex)
{
logHelper.Error("根据物料编号获取BOM信息异常", ex);
}
return bomInfo;
}
public async Task<BaseBomInfo> GetChildenBomInfoByMaterialCode(string materialCode, string materialType)
{
BaseBomInfo bomInfo = null;
try
{
var info =await GetChildenByParentId(materialCode);
if (info.Count > 0)
{
bomInfo = info.FirstOrDefault(x => x.MaterialType == materialType);
}
}
catch (Exception ex)
{
logHelper.Error("获取BOM集合异常", ex);
}
return bomInfo;
}
private async Task<List<BaseBomInfo>> GetChildenByParentId(string parentId, List<BaseBomInfo> result = null)
{
if (result == null)
{
result = new List<BaseBomInfo>();
}
try
{
var info =await _dal.QueryAsync(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;
}
}
}