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 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, IBaseOrderInfoServices { private readonly IBaseRepository _dal; private readonly IPrintOrderInfoRepository _printOrderInfoRepository; private readonly IBaseOrderInfoRepository _baseOrderInfoRepository; private readonly IBaseBomInfoRepository _baseBomInfoRepository; List bbinfolist=new List(); public BaseOrderInfoServices(IBaseRepository dal,IBaseBomInfoRepository baseBomInfoRepository, IBaseOrderInfoRepository baseOrderInfoRepository, IPrintOrderInfoRepository printOrderInfoRepository) { this._dal = dal; base.BaseDal = dal; _baseBomInfoRepository = baseBomInfoRepository; _baseOrderInfoRepository = baseOrderInfoRepository; _printOrderInfoRepository = printOrderInfoRepository; } /// /// 获取打印订单信息 /// /// public async Task> QueryPrintInfo() { List list = new List(); List orderList = await _baseOrderInfoRepository.QueryAsync(); List bomInfoList = await _baseBomInfoRepository.QueryAsync(); List printOrderInfoList = await _printOrderInfoRepository.QueryAsync(); bbinfolist.Clear(); foreach (BaseOrderInfo order in orderList) { var bom = bomInfoList.FirstOrDefault(d=>d.BomCode.Equals(order.MaterialCode)); if (bom!=null) { if (bom.BomCode == bom.MaterialCode) { PrintPlanInfoView view = new PrintPlanInfoView(); view.OrderCode = order.OrderCode; view.ProductCode = order.MaterialCode; view.ProductName = order.MaterialName; view.PlanAmount = order.OrderAmount; view.MaterialCode = bom.MaterialCode; view.MaterialName = bom.MaterialName; view.StandardAmount = bom.StandardAmount; view.CreateTime = order.CreatedTime; list.Add(view); } else { List bbList = RecursionFn(bomInfoList, bom.MaterialCode); if (bbList != null) { bbList.ForEach(b => { if (b.BomCode.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); } }); } } } } 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; } #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.GetEnumerator(); //while (it.MoveNext()) //{ // BaseBomInfo n = it.Current; // if (n.BomCode.IsNotEmptyOrNull() && n.BomCode == t.MaterialCode) // { // tlist.Add(n); // } //} foreach (var item in list.Where(d=>d.BomCode== materialCode)) { if (item.MaterialCode.IsNotEmptyOrNull()) { tlist.Add(item); } } 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.BomCode == materialCode&& d.BomCode!= d.MaterialCode).ToList(); return tlist; } #endregion } }