using Aucma.Scada.Model.domain; using HighWayIot.Common; using HighWayIot.Log4net; using System; using System.Collections.Generic; using System.Linq.Expressions; namespace HighWayIot.Repository.service.Impl { public class ProductPlanInfoServiceImpl : IProductPlanInfoService { private Repository _mesRepository = new Repository("mes"); private LogHelper logHelper = LogHelper.Instance; private JsonChange jsonChange = JsonChange.Instance; /// ///通过订单号和工位查询工单号 /// public string GetPlanCode(string orderCode, string station) { var aa = _mesRepository.GetList(); var plan = _mesRepository.GetFirst(x => x.orderCode == orderCode && x.productLineCode == station); if (plan == null) { return ""; } else { return plan.planCode; } } /// /// 通过计划编号获取计划信息 /// /// /// public ProductPlanInfo GetProductPlanByPlanCode(string planCode) { ProductPlanInfo planInfo = null; try { Expression> exp = s1 => true; exp = exp.And(x => x.planCode == planCode); planInfo = _mesRepository.GetFirst(exp); logHelper.Info($"根据计划编号{planCode};获取到的计划信息:{jsonChange.ModeToJson(planInfo)}"); } catch (Exception ex) { logHelper.Error("通过计划编号获取计划信息异常", ex); } return planInfo; } /// /// 通过产线工位获取生产计划 /// /// /// public List GetProductPlanInfosByProductLineCode(string productLineCode) { List planInfos = null; try { Expression> exp = s1 => true; exp = exp.And(x => x.productLineCode == productLineCode && x.endTime == null); planInfos = _mesRepository.GetList(exp); logHelper.Info($"根据产线工位编号:{productLineCode};获取到的计划信息:{jsonChange.ModeToJson(planInfos)}"); } catch (Exception ex) { logHelper.Error("通过产线工位获取生产计划异常", ex); } return planInfos; } /// /// 添加生产计划 /// /// /// public bool InsertProductPlanInfo(ProductPlanInfo productPlanInfo) { bool result = false; try { result = _mesRepository.Insert(productPlanInfo); } catch (Exception ex) { logHelper.Error("添加生产计划异常", ex); } return result; } /// /// 修改生产计划 /// /// /// public bool UpdateProductPlanInfo(ProductPlanInfo productPlanInfo) { bool result = false; try { Expression> columns = x => new ProductPlanInfo { completeAmount = productPlanInfo.completeAmount, beginTime = productPlanInfo.beginTime, endTime = productPlanInfo.endTime }; result = _mesRepository.Update(columns, x => x.objId == productPlanInfo.objId); // string sql = $@"UPDATE PRODUCT_PLANINFO SET COMPLETE_AMOUNT= '{productPlanInfo.completeAmount}',BEGIN_TIME= '{productPlanInfo.beginTime}',END_TIME= '{productPlanInfo.endTime}' WHERE OBJ_ID={productPlanInfo.objId} "; // _mesRepository._db().Ado.SqlQuery(sql); // result = _mesRepository.Update(productPlanInfo); } catch (Exception ex) { logHelper.Error("修改生产计划异常", ex); } return result; } /// /// 通过物料编码和工位找到生产计划 /// /// /// public ProductPlanInfo GetProductPlanInfosByMaterialCode(string materialCode) { ProductPlanInfo planInfo = null; try { Expression> exp = s1 => true; exp = exp.And(x => x.materialCode == materialCode && x.productLineCode == "1006" && x.endTime == null); planInfo = _mesRepository.GetFirst(exp); logHelper.Info($"根据物料编码{materialCode};获取到的计划信息:{jsonChange.ModeToJson(planInfo)}"); } catch (Exception ex) { logHelper.Error("通过计划编号获取计划信息异常", ex); } return planInfo; } } }