using Microsoft.Extensions.Logging; using SlnMesnac.Common; using SlnMesnac.Model.domain; using SlnMesnac.Repository.service.@base; using System; using System.Collections.Generic; using System.ComponentModel.Design; using System.Linq; using System.Linq.Expressions; using System.Text; namespace SlnMesnac.Repository.service.Impl { public class ProdPlanInfoServiceImpl : BaseServiceImpl, ProdPlanInfoService { private ILogger _logger; public ProdPlanInfoServiceImpl(Repository repository, ILogger logger) : base(repository) { _logger = logger; } /// /// 通过订单编号、工单编号、物料码获取工单信息 /// /// /// /// /// public List GetRecordStaffAttendancesByConditions(string? orderCode, string? planCode, string? materialCode, string? stationCode, string? planStatus) { var query = _rep.Context.Queryable() .LeftJoin((ppi, ppei) => ppi.PlanCode == ppei.SeqNo) .WhereIF(!string.IsNullOrEmpty(orderCode), (ppi, ppei) => ppi.OrderCode == orderCode) .WhereIF(!string.IsNullOrEmpty(planCode), (ppi, ppei) => ppi.PlanCode == planCode) .WhereIF(!string.IsNullOrEmpty(materialCode), (ppi, ppei) => ppi.MaterialCode == materialCode) .WhereIF(!string.IsNullOrEmpty(stationCode), (ppi, ppei) => ppi.StationCode == stationCode) .WhereIF(!string.IsNullOrEmpty(planStatus), (ppi, ppei) => ppi.PlanStatus == planStatus || ppi.PlanStatus == "4") .Select((ppi, ppei) => new ProdPLanInfo { ObjId = ppi.ObjId, PlanCode = ppi.PlanCode, OrderCode = ppi.OrderCode, MaterialCode = ppi.MaterialCode, MaterialName = ppi.MaterialName, StationCode = ppi.StationCode, TeamCode = ppi.TeamCode, PlanAmount = ppi.PlanAmount, CompleteAmount = ppi.CompleteAmount, BeginTime = ppi.BeginTime, EndTime = ppi.EndTime, CompFlag = ppi.CompFlag, CreatedBy = ppi.CreatedBy, CreatedTime = ppi.CreatedTime, UpdatedBy = ppi.UpdatedBy, UpdatedTime = ppi.UpdatedTime, DeviceCode = ppi.DeviceCode, PlanBeginTime = ppi.PlanBeginTime, PlanEndTime = ppi.PlanEndTime, PlanStatus = ppi.PlanStatus, Classes = ppi.Classes, ProcessCode = ppi.ProcessCode, ImportFlag = ppi.ImportFlag, WorkingHours = ppei.WorkingHours }); List planInfoList = query.ToList(); return planInfoList; } /// /// 通过订单编号、工单编号、物料码获取工单信息 /// /// /// /// /// public List GetPlanInfoByConditions(string? orderCode, string? planCode, string? materialCode, string? stationCode, string? planStatus) { List recordStaffAttendances = new List(); List planInfoList = _rep.AsQueryable().WhereIF(!string.IsNullOrEmpty(orderCode), x => x.OrderCode == orderCode) .WhereIF(!string.IsNullOrEmpty(planCode), x => x.PlanCode == planCode) .WhereIF(!string.IsNullOrEmpty(materialCode), x => x.MaterialCode == materialCode) .WhereIF(!string.IsNullOrEmpty(stationCode), x => x.StationCode == stationCode) .WhereIF(!string.IsNullOrEmpty(planStatus), x => x.PlanStatus == planStatus) .OrderByDescending(x => x.ObjId) .ToList(); return planInfoList; } public List GetRecordStaffAttendances() { List pLanInfos = null; try { pLanInfos = base._rep.GetList(); pLanInfos.Reverse(); } catch (Exception ex) { _logger.LogError($"获取员工打卡信息异常{ex.Message}"); } return pLanInfos; } /// /// 根据工单号获取此工单 /// /// /// /// public ProdPLanInfo GetProdPLanInfoByOrderCode(string stationCode, string orderCode) { ProdPLanInfo prodPLan = new ProdPLanInfo(); try {//只显示未执行的 prodPLan = _rep.GetFirst(x => x.OrderCode == orderCode && x.StationCode == stationCode); //&& (x.PlanStatus == "0" || x.PlanStatus == "4") } catch (Exception ex) { _logger.LogError($"根据工单号获取此工单异常{ex.Message}"); } return prodPLan; } /// /// 更新工单状态 /// /// /// /// /// /// /// public bool UpdatePlanStatus(string orderCode, string stationCode, string deviceCode, string processCode, string status) { bool result = false; try { var planInfo = _rep.GetFirst(x => x.OrderCode == orderCode && x.StationCode == stationCode && x.DeviceCode == deviceCode && x.ProcessCode == processCode && x.PlanStatus == "0"); if (planInfo != null) { planInfo.PlanStatus = status; result = _rep.Update(planInfo); } } catch (Exception ex) { _logger.LogError($"修改计划状态异常:{ex.Message}"); } return result; } } }