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 Microsoft.Extensions.Hosting; using NPOI.SS.Formula.Functions; using StackExchange.Redis; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection.Emit; using System.Threading.Tasks; namespace Admin.Core.Service { public class BaseOrderInfoServices : BaseServices, IBaseOrderInfoServices { private readonly IBaseRepository _dal; private readonly IPrintOrderInfoRepository _printOrderInfoRepository; private readonly IBaseOrderInfoRepository _baseOrderInfoRepository; private readonly IOrderBomInfoRepository _orderBomInfoRepository; private readonly IBaseRepository baseRepository; List bbinfolist = new List(); public BaseOrderInfoServices(IBaseRepository dal, IPrintOrderInfoRepository printOrderInfoRepository, IOrderBomInfoRepository orderBomInfoRepository, IBaseOrderInfoRepository baseOrderInfoRepository, IBaseRepository baseRepository) { this._dal = dal; base.BaseDal = dal; _orderBomInfoRepository = orderBomInfoRepository; _printOrderInfoRepository = printOrderInfoRepository; _baseOrderInfoRepository = baseOrderInfoRepository; this.baseRepository = baseRepository; } /// /// 获取打印订单信息- /// /// public async Task> QueryPrintInfo() { List list = new List(); List orderList = await _baseOrderInfoRepository.QueryAsync(); List orderBomInfoList = await _orderBomInfoRepository.QueryAsync(); List printOrderInfoList = await _printOrderInfoRepository.QueryAsync(); bbinfolist.Clear(); if (orderList == null) return null; if (orderBomInfoList == null) return null; foreach (BaseOrderInfo order in orderList) { List bbList = RecursionFn(orderBomInfoList, order.MaterialCode); //bomList.ForEach(b => //{ // List bbList = RecursionFn(orderBomInfoList, b.MaterialCode); // if (b.ParentId.IsNotEmptyOrNull() && (b.MaterialName.Contains("箱体") || b.MaterialName.Contains("内胆"))) // { // bbList.ForEach(bb => // { // list.Add(new PrintPlanInfoView() // { // OrderCode = order.OrderCode, // ProductCode = order.MaterialCode, // ProductName = order.MaterialName, // PlanAmount = order.OrderAmount, // MaterialCode = bb.MaterialCode, // MaterialName = bb.MaterialName, // LinerAmount = bb.StandardAmount, // BoxAmount = bb.StandardAmount, // StandardAmount = bb.StandardAmount, // CreateTime = order.CreatedTime // }); // }); // } //}); //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(); } return list; } public async Task> QueryPrintInfo(string query) { List list = new List(); List list2 = new List(); List orderList = await _baseOrderInfoRepository.QueryAsync(); List orderBomInfoList = await _orderBomInfoRepository.QueryAsync(); //List bomInfoList = await _baseBomInfoRepository.QueryAsync(); List 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 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 递归列表 /// /// 递归列表 /// public List RecursionFn(List list, string materialCode) { // 得到子节点列表 List 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 得到子节点列表 /// /// 得到子节点列表 /// /// /// /// public List GetChildList(List list, string materialCode) { List tlist = new List(); IEnumerator it = list.Where(d => d.ParentId == materialCode).GetEnumerator(); while (it.MoveNext()) { OrderBomInfo n = it.Current; if (n.ParentId.IsNotEmptyOrNull()) { if (n.MaterialType == "300" && n.MaterialType == "200") tlist.Add(n); } } return tlist; } #endregion #region 判断是否有子节点 /// /// 判断是否有子节点 /// /// /// /// public bool HasChild(List list, string materialCode) { return IsExist(list, materialCode).Count > 0 ? true : false; } public List IsExist(List list, string materialCode) { List tlist = list.Where(d => d.ParentId == materialCode).ToList(); return tlist; } #endregion } }