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/Admin.Core.Service/Service_New/BaseOrderInfoServices.cs

216 lines
9.1 KiB
C#

using Admin.Core.Common;
using Admin.Core.IRepository;
using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Model.Model_New;
using Admin.Core.Model.ViewModels;
using NPOI.SS.Formula.Functions;
using StackExchange.Redis;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Threading.Tasks;
namespace Admin.Core.Service
{
public class BaseOrderInfoServices : BaseServices<BaseOrderInfo>, IBaseOrderInfoServices
{
private readonly IBaseRepository<BaseOrderInfo> _dal;
private readonly IPrintOrderInfoRepository _printOrderInfoRepository;
private readonly IBaseOrderInfoRepository _baseOrderInfoRepository;
private readonly IBaseBomInfoRepository _baseBomInfoRepository;
private readonly IOrderBomInfoRepository _orderBomInfoRepository;
List<OrderBomInfo> bbinfolist=new List<OrderBomInfo>();
public BaseOrderInfoServices(IBaseRepository<BaseOrderInfo> dal,IBaseBomInfoRepository baseBomInfoRepository,
IBaseOrderInfoRepository baseOrderInfoRepository, IPrintOrderInfoRepository printOrderInfoRepository,
IOrderBomInfoRepository orderBomInfoRepository)
{
this._dal = dal;
base.BaseDal = dal;
_baseBomInfoRepository = baseBomInfoRepository;
_baseOrderInfoRepository = baseOrderInfoRepository;
_printOrderInfoRepository = printOrderInfoRepository;
_orderBomInfoRepository = orderBomInfoRepository;
}
/// <summary>
/// 获取打印订单信息-
/// </summary>
/// <returns></returns>
public async Task<List<PrintPlanInfoView>> QueryPrintInfo()
{
List<PrintPlanInfoView> list= new List<PrintPlanInfoView>();
List<BaseOrderInfo> orderList = await _baseOrderInfoRepository.QueryAsync();
List<OrderBomInfo> orderBomInfoList = await _orderBomInfoRepository.QueryAsync();
//List<BaseBomInfo> bomInfoList = await _baseBomInfoRepository.QueryAsync();
List<PrintOrderInfo> printOrderInfoList = await _printOrderInfoRepository.QueryAsync();
bbinfolist.Clear();
foreach (BaseOrderInfo order in orderList)
{
var bomList = await _orderBomInfoRepository.QueryAsync(d => d.ParentId.Equals(order.MaterialCode));
if (bomList != null)
{
bomList.ForEach(b =>
{
List<OrderBomInfo> bbList = RecursionFn(orderBomInfoList, b.MaterialCode);
if (b.ParentId.IsNotEmptyOrNull())
{
PrintPlanInfoView view = new PrintPlanInfoView();
view.OrderCode = order.OrderCode;
view.ProductCode = order.MaterialCode;
view.ProductName = order.MaterialName;
view.PlanAmount = order.OrderAmount;
view.MaterialCode = b.MaterialCode;
view.MaterialName = b.MaterialName;
view.StandardAmount = b.StandardAmount;
view.CreateTime = order.CreatedTime;
list.Add(view);
}
});
}
}
//var list = (from order in orderList
// join b in orderBomInfoList
// on order.MaterialCode equals b.ParentId
// select new PrintPlanInfoView
// {
// OrderCode = order.OrderCode,
// ProductCode = order.MaterialCode,
// ProductName = order.MaterialName,
// PlanAmount = order.OrderAmount,
// MaterialCode = b.MaterialCode,
// MaterialName = b.MaterialName,
// StandardAmount = b.StandardAmount,
// CreateTime = order.CreatedTime
// }).ToList();
list.ForEach(b =>
{
PrintOrderInfo info = printOrderInfoList.FirstOrDefault(d => d.OrderCode == b.OrderCode);
if (info != null)
{
b.LinerAmount = info.LinerAmount;
b.BoxAmount = info.BoxAmount;
}
});
return list;
}
public async Task<List<PrintPlanInfoView>> QueryPrintInfo(string query){
List<PrintPlanInfoView> list = new List<PrintPlanInfoView>();
List<PrintPlanInfoView> list2 = new List<PrintPlanInfoView>();
List<BaseOrderInfo> orderList = await _baseOrderInfoRepository.QueryAsync();
List<OrderBomInfo> orderBomInfoList = await _orderBomInfoRepository.QueryAsync();
//List<BaseBomInfo> bomInfoList = await _baseBomInfoRepository.QueryAsync();
List<PrintOrderInfo> printOrderInfoList = await _printOrderInfoRepository.QueryAsync();
bbinfolist.Clear();
list2.Clear();
foreach (BaseOrderInfo order in orderList)
{
var bomList = await _orderBomInfoRepository.QueryAsync(d => d.ParentId.Equals(order.MaterialCode));
if (bomList != null)
{
bomList.ForEach(b =>
{
List<OrderBomInfo> bbList = RecursionFn(orderBomInfoList, b.MaterialCode);
if (b.ParentId.IsNotEmptyOrNull())
{
PrintPlanInfoView view = new PrintPlanInfoView();
view.OrderCode = order.OrderCode;
view.ProductCode = order.MaterialCode;
view.ProductName = order.MaterialName;
view.PlanAmount = order.OrderAmount;
view.MaterialCode = b.MaterialCode;
view.MaterialName = b.MaterialName;
view.StandardAmount = b.StandardAmount;
view.CreateTime = order.CreatedTime;
list.Add(view);
}
});
}
}
var printList= list.Where(d=>d.MaterialName.Contains(query));
list.ForEach(b =>
{
PrintOrderInfo info = printOrderInfoList.FirstOrDefault(d => d.OrderCode == b.OrderCode);
if (info != null)
{
PrintPlanInfoView view = new PrintPlanInfoView();
b.LinerAmount = info.LinerAmount;
b.BoxAmount = info.BoxAmount;
b.MaterialCode = string.Empty;
b.MaterialName = string.Empty;
b.StandardAmount = 0;
list2.Add(view);
}
});
list2.Distinct();
return list2;
}
#region 递归列表
/// <summary>
/// 递归列表
/// </summary>
public List<OrderBomInfo> RecursionFn(List<OrderBomInfo> list, string materialCode)
{
// 得到子节点列表
List<OrderBomInfo> childList = GetChildList(list, materialCode);
childList.ForEach(c => bbinfolist.Add(c));
foreach (var tChild in childList)
{
if (HasChild(list, tChild.MaterialCode))
{
RecursionFn(list, tChild.MaterialCode);
}
}
return bbinfolist;
}
#endregion
#region 得到子节点列表
/// <summary>
/// 得到子节点列表
/// </summary>
/// <param name="list"></param>
/// <param name="t"></param>
/// <returns></returns>
public List<OrderBomInfo> GetChildList(List<OrderBomInfo> list, string materialCode)
{
List<OrderBomInfo> tlist = new List<OrderBomInfo>();
IEnumerator<OrderBomInfo> it = list.Where(d => d.ParentId == materialCode).GetEnumerator();
while (it.MoveNext())
{
OrderBomInfo n = it.Current;
if (n.ParentId.IsNotEmptyOrNull())
{
tlist.Add(n);
}
}
return tlist;
}
#endregion
#region 判断是否有子节点
/// <summary>
/// 判断是否有子节点
/// </summary>
/// <param name="list"></param>
/// <param name="t"></param>
/// <returns></returns>
public bool HasChild(List<OrderBomInfo> list, string materialCode)
{
return IsExist(list, materialCode).Count > 0 ? true : false;
}
public List<OrderBomInfo> IsExist(List<OrderBomInfo> list, string materialCode)
{
List<OrderBomInfo> tlist = list.Where(d => d.ParentId == materialCode).ToList();
return tlist;
}
#endregion
}
}