using Admin.Core.Common; using Admin.Core.IRepository; using Admin.Core.IService; using Admin.Core.Model; using Admin.Core.Model.Model_New; using log4net; using Microsoft.IdentityModel.Logging; using StackExchange.Profiling.Internal; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; namespace Admin.Core.Service { public class ProductPlanInfoServices : BaseServices, IProductPlanInfoServices { private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(ProductPlanInfoServices)); private readonly IBaseRepository _dal; private readonly IBaseOrderInfoRepository _baseOrderInfoRepository; public ProductPlanInfoServices(IBaseRepository dal, IBaseOrderInfoRepository baseOrderInfoRepository) { this._dal = dal; base.BaseDal = dal; _baseOrderInfoRepository = baseOrderInfoRepository; } #region 查询计划执行信息 /// /// 查询计划执行信息 /// /// public async Task> QueryPlanInfo(string station) { List planList = await _dal.QueryAsync(d => d.ProductLineCode == station); var list = (from p in planList select new PlanMaintenanceView { PlanCode = p.PlanCode, OrderCode = p.OrderCode, MaterialCode = p.MaterialCode, MaterialName = p.MaterialName, PlanAmount = p.PlanAmount, ResidueAmount = p.PlanAmount - p.CompleteAmount }).ToList(); return list; } #endregion #region 通过计划编号获取计划信息 /// /// 通过计划编号获取计划信息 /// /// /// public async Task GetProductPlanByPlanCode(string planCode) { ProductPlanInfo planInfo = null; try { //Expression> exp = s1 => true; //exp = exp.And(x => x.PlanCode == planCode); //var info = await _dal.QueryAsync(exp); var info = _dal.Query(x=>x.PlanCode == planCode); if (info != null) { planInfo = info.OrderBy(x => x.CreatedTime).First(); } //logHelper.Info($"根据计划编号{planCode};获取到的计划信息:{planInfo.ToJson()}"); } catch (Exception ex) { logHelper.Error("通过计划编号获取计划信息异常", ex); } return planInfo; } #endregion #region 通过产线工位获取生产计划 /// /// 通过产线工位获取生产计划 /// /// /// public async Task> GetProductPlanInfosByProductLineCode(string productLineCode) { List planInfos = null; try { Expression> exp = s1 => true; exp = exp.And(x => x.ProductLineCode == productLineCode); planInfos = await _dal.QueryAsync(exp); logHelper.Info($"根据产线工位编号:{productLineCode};获取到的计划信息:{planInfos.ToJson()}"); } catch (Exception ex) { logHelper.Error("通过产线工位获取生产计划异常", ex); } return planInfos; } #endregion #region 添加生产计划 /// /// 添加生产计划 /// /// /// public async Task InsertProductPlanInfo(ProductPlanInfo productPlanInfo) { bool result = false; try { int r = await _dal.AddAsync(productPlanInfo); if (r > 0) result = true; } catch (Exception ex) { logHelper.Error("添加生产计划异常", ex); } return result; } #endregion #region 修改生产计划 /// /// 修改生产计划 /// /// /// public async Task UpdateProductPlanInfo(ProductPlanInfo productPlanInfo) { bool result = false; try { result = await _dal.UpdateAsync(productPlanInfo); } catch (Exception ex) { logHelper.Error("修改生产计划异常", ex); } return result; } #endregion } }