using Infrastructure.Attribute; using SqlSugar; using System; using ZR.Model.MES.op.DTO; using ZR.Model.MES.op.ZR.Model.mes.md; using ZR.Model.MES.pro; using ZR.Model.MES.qc; using ZR.Model.MES.qu; using ZR.Service.MES.op.IService; namespace ZR.Service.MES.op { [AppService(ServiceType = typeof(IOperationService), ServiceLifetime = LifeTime.Transient)] public class OperationService : BaseService, IOperationService { public List GetAllData(string workshopID) { decimal myDecimal = 123.456789m; string formattedDecimal = myDecimal.ToString("0.00"); // 保留两位小数 List OpStatisticsDTOList = new List(); List OpStatisticsList = Queryable().Where(it => it.WorkshopId == workshopID).ToList(); foreach (var OpStatistics in OpStatisticsList) { OpStatisticsDTO opStatisticsDTO = new OpStatisticsDTO(); opStatisticsDTO.WorkshopId = OpStatistics.WorkshopId; opStatisticsDTO.WorkshopName = OpStatistics.WorkshopName; opStatisticsDTO.ProductDate = OpStatistics.ProductDate; opStatisticsDTO.PlanNum = OpStatistics.PlanNum; opStatisticsDTO.ProductedNum = OpStatistics.ProductedNum; decimal num1 = (decimal)OpStatistics.ProductedNum / (decimal)OpStatistics.PlanNum * 100; opStatisticsDTO.ProductProgressRate = (int)num1; opStatisticsDTO.GoodproductsNum = OpStatistics.GoodproductsNum; opStatisticsDTO.DefectiveProductsNum = OpStatistics.DefectiveProductsNum; decimal num2 = (decimal)OpStatistics.DefectiveProductsNum / (decimal)(OpStatistics.GoodproductsNum + OpStatistics.DefectiveProductsNum); opStatisticsDTO.QualityRate = num2.ToString("f2"); opStatisticsDTO.ProductStarttime = OpStatistics.ProductStarttime; opStatisticsDTO.ProductEndtime = OpStatistics.ProductEndtime; if (DateTime.Now > opStatisticsDTO.ProductStarttime && DateTime.Now < opStatisticsDTO.ProductEndtime) { opStatisticsDTO.isProducting = true; } else { opStatisticsDTO.isProducting = false; } opStatisticsDTO.numSort = OpStatisticsList.IndexOf(OpStatistics); opStatisticsDTO.LineId = OpStatistics.LineId; opStatisticsDTO.LineName = OpStatistics.LineName; opStatisticsDTO.ProductEndtime = OpStatistics.ProductEndtime; OpStatisticsDTOList.Add(opStatisticsDTO); } return OpStatisticsDTOList; } /// /// 质量统计分析表和工单关联一下 /// /// /// /// /// /// /// /// public (List, int) GueryQualityStatistics(string workorderid, int pageNum, int pageSize, int year = -1, int week = -1, int date = -1) { var predicate = Expressionable.Create() .AndIF(year > 0, p => p.Year == year) .AndIF(week > 0, p => p.Week == week) .AndIF(date > 0, p => p.Date == date) .ToExpression(); var predicate2 = Expressionable.Create() .AndIF(!string.IsNullOrEmpty(workorderid), q => q.FkWorkorderId == workorderid) .ToExpression(); int totalCount = 0; var query5 = Context.Queryable() .LeftJoin((q, p) => q.FkWorkorderId == p.Id) .Where(predicate2) .Select((q, p) => new QcFqcDTO { Year = p.Year, Week = p.Week, Date = p.Date, Id = q.Id, FkWorkorderId = q.FkWorkorderId, ProductName = q.ProductName, Color = q.Color, Require = q.Require, LeftRight = q.LeftRight, Team = q.Team, QualifiedNum01 = q.QualifiedNum01, DefectNum01 = q.DefectNum01, PolishNum01 = q.PolishNum01, ScrapNum01 = q.ScrapNum01, QualifiedNum02 = q.QualifiedNum02, PolishNum02 = q.PolishNum02, ScrapNum02 = q.ScrapNum02, QualifiedNum03 = q.QualifiedNum03, PolishNum03 = q.PolishNum03, ScrapNum03 = q.ScrapNum03, FirstgoodNum = q.FirstgoodNum, FirstgoodRate = q.FirstgoodRate, FinalgoodRate = q.FinalgoodRate, FinalgoodNum = q.FinalgoodNum, }).MergeTable(); List QcFqcDTOList = query5.Where(predicate).ToPageList(pageNum, pageSize, ref totalCount); return (QcFqcDTOList, totalCount); } /// /// 获取工单 缺陷详细信息 /// /// /// /// public List QueryDetailsOfDetection(string fkWorkorderId, int order) { List detailsList = null; switch (order) { case 1: // 首检抛光数量 detailsList = Context.Queryable().LeftJoin((f, i) => SqlFunc.ToInt32(f.FKInpectionId) == i.Id).Where(f => SqlFunc.Like(f.FKInpectionId, "_1_")).Where(f => f.FKWorkorderId == fkWorkorderId) .Select((f, i) => new DetailsOfDetectionDTO { InspectionName = i.InspectionName, Counter = (int)f.Counter, }).ToList(); break; case 2: // 首检打磨数量 detailsList = Context.Queryable().LeftJoin((f, i) => SqlFunc.ToInt32(f.FKInpectionId) == i.Id).Where(f => SqlFunc.Like(f.FKInpectionId, "_2_")) .Select((f, i) => new DetailsOfDetectionDTO { InspectionName = i.InspectionName, Counter = (int)f.Counter, }).ToList(); break; case 3: // 首检报废数量 detailsList = Context.Queryable().LeftJoin((f, i) => SqlFunc.ToInt32(f.FKInpectionId) == i.Id).Where(f => SqlFunc.Like(f.FKInpectionId, "_3_")) .Select((f, i) => new DetailsOfDetectionDTO { InspectionName = i.InspectionName, Counter = (int)f.Counter, }).ToList(); break; case 4: // 二检打磨数量 detailsList = Context.Queryable().LeftJoin((f, i) => SqlFunc.ToInt32(f.FkInpectionId) == i.Id).Where(f => SqlFunc.Like(f.FkInpectionId, "_2_")) .Select((f, i) => new DetailsOfDetectionDTO { InspectionName = i.InspectionName, Counter = (int)f.Counter, }).ToList(); break; case 5: // 二检报废数量 detailsList = Context.Queryable().LeftJoin((f, i) => SqlFunc.ToInt32(f.FkInpectionId) == i.Id).Where(f => SqlFunc.Like(f.FkInpectionId, "_3_")) .Select((f, i) => new DetailsOfDetectionDTO { InspectionName = i.InspectionName, Counter = (int)f.Counter, }).ToList(); break; case 6: // 三检打磨数量 detailsList = Context.Queryable().LeftJoin((f, i) => SqlFunc.ToInt32(f.FkInpectionId) == i.Id).Where(f => SqlFunc.Like(f.FkInpectionId, "_2_")) .Select((f, i) => new DetailsOfDetectionDTO { InspectionName = i.InspectionName, Counter = (int)f.Counter, }).ToList(); break; case 7: // 三检报废数量 detailsList = Context.Queryable().LeftJoin((f, i) => SqlFunc.ToInt32(f.FkInpectionId) == i.Id).Where(f => SqlFunc.Like(f.FkInpectionId, "_3_")) .Select((f, i) => new DetailsOfDetectionDTO { InspectionName = i.InspectionName, Counter = (int)f.Counter, }).ToList(); break; default: break; } return detailsList; } } }