using Infrastructure.Attribute; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ZR.Model.mes.md; using ZR.Model.MES.op.ZR.Model.mes.md; using ZR.Service.MES.md.IService; using ZR.Service; using ZR.Service.MES.op.IService; using ZR.Model.MES.op.DTO; using Microsoft.AspNetCore.Http.HttpResults; using Org.BouncyCastle.Asn1.Esf; using ZR.Model.MES.qc; using SqlSugar; using ZR.Model.mes.pro; using static System.Runtime.InteropServices.JavaScript.JSType; using System.Drawing; using Newtonsoft.Json; 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); } } }