From 9c916d58e81cdc21b5d76d533133005bc854e92c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E6=B1=9F=E6=B5=B7?= <18360817963@163.com> Date: Thu, 27 Mar 2025 15:17:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A8=E9=87=8F=E5=A4=A7=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SmartScreen/Quality/QualityController.cs | 6 - .../Quality/QualitySmartController.cs | 63 ++++++++ .../Quality/Dto/QualityScreenHeadDto.cs | 15 ++ .../Quality/Dto/QualitySmartScreenDto.cs | 17 +++ DOAN.Model/MES/SmartScreen/Quality/Quality.cs | 12 -- .../Quality/IService/IQualityService.cs | 12 -- .../Quality/IService/IQualitySmartService.cs | 19 +++ .../Quality/QualitySmartService.cs | 142 ++++++++++++++++++ 8 files changed, 256 insertions(+), 30 deletions(-) delete mode 100644 DOAN.Admin.WebApi/Controllers/MES/SmartScreen/Quality/QualityController.cs create mode 100644 DOAN.Admin.WebApi/Controllers/MES/SmartScreen/Quality/QualitySmartController.cs create mode 100644 DOAN.Model/MES/SmartScreen/Quality/Dto/QualityScreenHeadDto.cs create mode 100644 DOAN.Model/MES/SmartScreen/Quality/Dto/QualitySmartScreenDto.cs delete mode 100644 DOAN.Model/MES/SmartScreen/Quality/Quality.cs delete mode 100644 DOAN.Service/MES/SmartScreen/Quality/IService/IQualityService.cs create mode 100644 DOAN.Service/MES/SmartScreen/Quality/IService/IQualitySmartService.cs create mode 100644 DOAN.Service/MES/SmartScreen/Quality/QualitySmartService.cs diff --git a/DOAN.Admin.WebApi/Controllers/MES/SmartScreen/Quality/QualityController.cs b/DOAN.Admin.WebApi/Controllers/MES/SmartScreen/Quality/QualityController.cs deleted file mode 100644 index 68c9f59..0000000 --- a/DOAN.Admin.WebApi/Controllers/MES/SmartScreen/Quality/QualityController.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace DOAN.Admin.WebApi.Controllers.MES.SmartScreen.Quality -{ - public class QualityController - { - } -} diff --git a/DOAN.Admin.WebApi/Controllers/MES/SmartScreen/Quality/QualitySmartController.cs b/DOAN.Admin.WebApi/Controllers/MES/SmartScreen/Quality/QualitySmartController.cs new file mode 100644 index 0000000..96f0b29 --- /dev/null +++ b/DOAN.Admin.WebApi/Controllers/MES/SmartScreen/Quality/QualitySmartController.cs @@ -0,0 +1,63 @@ +using DOAN.Admin.WebApi.Filters; +using DOAN.Service.MES.SmartScreen.Order; +using DOAN.Service.MES.SmartScreen.Order.IService; +using DOAN.Service.MES.SmartScreen.Quality.IService; +using Microsoft.AspNetCore.Mvc; + +namespace DOAN.Admin.WebApi.Controllers.MES.SmartScreen.Quality +{ + /// + /// 质量大屏 + /// + [Verify] + [Route("mes/qualityManagement/QualitySmart")] + public class QualitySmartController : BaseController + { + /// + /// 质量大屏接口 + /// + private readonly IQualitySmartService _QualitySmartService; + + public QualitySmartController(IQualitySmartService QualitySmartService) + { + _QualitySmartService = QualitySmartService; + } + + + /// + /// 查询质量大屏头信息 + /// + /// + [HttpGet("GetQualityScreenHead")] + public IActionResult GetQualityScreenHead() + { + + var response = _QualitySmartService.GetQualityScreenHead(); + return SUCCESS(response); + } + + /// + /// 按周获取质量大屏数据 + /// + /// + [HttpGet("GetQualitySmartScreenForWeek")] + public IActionResult GetQualitySmartScreenForWeek() + { + + var response = _QualitySmartService.GetQualitySmartScreenForWeek(); + return SUCCESS(response); + } + + /// + /// 按月获取质量大屏数据 + /// + /// + [HttpGet("GetQualitySmartScreenForMonth")] + public IActionResult GetQualitySmartScreenForMonth() + { + + var response = _QualitySmartService.GetQualitySmartScreenForMonth(); + return SUCCESS(response); + } + } +} diff --git a/DOAN.Model/MES/SmartScreen/Quality/Dto/QualityScreenHeadDto.cs b/DOAN.Model/MES/SmartScreen/Quality/Dto/QualityScreenHeadDto.cs new file mode 100644 index 0000000..309b01f --- /dev/null +++ b/DOAN.Model/MES/SmartScreen/Quality/Dto/QualityScreenHeadDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DOAN.Model.MES.SmartScreen.Quality.Dto +{ + public class QualityScreenHeadDto + { + public int? MonthFQC { get; set; } + + public int? WeekFQC { get; set; } + } +} diff --git a/DOAN.Model/MES/SmartScreen/Quality/Dto/QualitySmartScreenDto.cs b/DOAN.Model/MES/SmartScreen/Quality/Dto/QualitySmartScreenDto.cs new file mode 100644 index 0000000..26f8ae2 --- /dev/null +++ b/DOAN.Model/MES/SmartScreen/Quality/Dto/QualitySmartScreenDto.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DOAN.Model.MES.SmartScreen.Quality.Dto +{ + public class QualitySmartScreenDto + { + public string StoveCode { get; set; } + + public string DefectName { get; set; } + + public int? Number { get; set; } + } +} diff --git a/DOAN.Model/MES/SmartScreen/Quality/Quality.cs b/DOAN.Model/MES/SmartScreen/Quality/Quality.cs deleted file mode 100644 index a98b055..0000000 --- a/DOAN.Model/MES/SmartScreen/Quality/Quality.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DOAN.Model.MES.SmartScreen.Quality -{ - internal class Quality - { - } -} diff --git a/DOAN.Service/MES/SmartScreen/Quality/IService/IQualityService.cs b/DOAN.Service/MES/SmartScreen/Quality/IService/IQualityService.cs deleted file mode 100644 index 272b29e..0000000 --- a/DOAN.Service/MES/SmartScreen/Quality/IService/IQualityService.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DOAN.Service.MES.SmartScreen.Quality.IService -{ - internal class IQualityService - { - } -} diff --git a/DOAN.Service/MES/SmartScreen/Quality/IService/IQualitySmartService.cs b/DOAN.Service/MES/SmartScreen/Quality/IService/IQualitySmartService.cs new file mode 100644 index 0000000..80e42a1 --- /dev/null +++ b/DOAN.Service/MES/SmartScreen/Quality/IService/IQualitySmartService.cs @@ -0,0 +1,19 @@ +using DOAN.Model.MES.order; +using DOAN.Model.MES.quality.FQC; +using DOAN.Model.MES.SmartScreen.Quality.Dto; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DOAN.Service.MES.SmartScreen.Quality.IService +{ + public interface IQualitySmartService : IBaseService + { + QualityScreenHeadDto GetQualityScreenHead(); + + List GetQualitySmartScreenForWeek(); + List GetQualitySmartScreenForMonth(); + } +} diff --git a/DOAN.Service/MES/SmartScreen/Quality/QualitySmartService.cs b/DOAN.Service/MES/SmartScreen/Quality/QualitySmartService.cs new file mode 100644 index 0000000..08dd682 --- /dev/null +++ b/DOAN.Service/MES/SmartScreen/Quality/QualitySmartService.cs @@ -0,0 +1,142 @@ +using DOAN.Model.MES.order; +using DOAN.Model.MES.product; +using DOAN.Model.MES.quality.FQC; +using DOAN.Model.MES.SmartScreen.Quality.Dto; +using DOAN.Service.MES.SmartScreen.Order.IService; +using DOAN.Service.MES.SmartScreen.Quality.IService; +using Infrastructure.Attribute; +using NPOI.SS.Formula.Functions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DOAN.Service.MES.SmartScreen.Quality +{ + /// + /// 质量大屏Service业务层处理 + /// + [AppService(ServiceType = typeof(IQualitySmartService), ServiceLifetime = LifeTime.Transient)] + public class QualitySmartService : BaseService, IQualitySmartService + { + public QualityScreenHeadDto GetQualityScreenHead() + { + QualityScreenHeadDto qualityScreenHeadDto = new QualityScreenHeadDto(); + // 当前日期 + DateTime now = DateTime.Now; + // 当前月份的第一天 00:00:00 + DateTime firstDayOfMonth = new DateTime(now.Year, now.Month, 1); + // 当前月份的最后一天 23:59:59 + DateTime lastDayOfMonth = new DateTime(now.Year, now.Month, 1) + .AddMonths(1) + .AddSeconds(-1); + // 计算本周周一(第一天) + int daysUntilMonday = ((int)now.DayOfWeek - (int)DayOfWeek.Monday + 7) % 7; + DateTime startOfWeek = now.AddDays(-daysUntilMonday); + // 计算本周周日(最后一天)23:59:59 + DateTime endOfWeek = startOfWeek.AddDays(6).Date + .AddHours(23) + .AddMinutes(59) + .AddSeconds(59); + var response = Queryable().ToList(); + + qualityScreenHeadDto.MonthFQC = response.Where(o => o.CheckDatetime >= firstDayOfMonth && o.CheckDatetime <= lastDayOfMonth).Sum(o=>o.Number); + qualityScreenHeadDto.WeekFQC= response.Where(o => o.CheckDatetime >= startOfWeek && o.CheckDatetime <= endOfWeek).Sum(o => o.Number); + return qualityScreenHeadDto; + } + + public List GetQualitySmartScreenForWeek() + { + // 获取当前日期 + DateTime now = DateTime.Now; + + // 计算本周周一(第一天) + int daysUntilMonday = ((int)now.DayOfWeek - (int)DayOfWeek.Monday + 7) % 7; + DateTime startOfWeek = now.AddDays(-daysUntilMonday); + + // 计算本周周日(最后一天)23:59:59 + DateTime endOfWeek = startOfWeek.AddDays(6).Date + .AddHours(23) + .AddMinutes(59) + .AddSeconds(59); + + // 查询本周的质量缺陷数据 + var defectQuery = Queryable() + .Where(o => o.CheckDatetime >= startOfWeek && o.CheckDatetime <= endOfWeek); + + // 获取有缺陷的工单列表 + List defectWorkorders = defectQuery + .Select(o => o.Workorder) + .Distinct() + .ToList(); + + if (defectWorkorders.Count == 0) + { + return new List(); + } + + // 查询相关工单信息 + var workorderQuery = Context.Queryable() + .Where(o => defectWorkorders.Contains(o.Workorder)); + + // 使用 SqlSugar 进行联表查询和分组统计 + var result = defectQuery + .InnerJoin((defect, work) => defect.Workorder == work.Workorder) + .GroupBy((defect, work) => new { work.StoveCode, defect.DefectName }) + .Select((defect, work) => new QualitySmartScreenDto + { + StoveCode = work.StoveCode, + DefectName = defect.DefectName, + Number = SqlFunc.AggregateSum(defect.Number) + }) + .ToList(); + + return result; + } + + public List GetQualitySmartScreenForMonth() + { + // 获取当前日期 + DateTime now = DateTime.Now; + // 当前月份的第一天 00:00:00 + DateTime firstDayOfMonth = new DateTime(now.Year, now.Month, 1); + // 当前月份的最后一天 23:59:59 + DateTime lastDayOfMonth = new DateTime(now.Year, now.Month, 1) + .AddMonths(1) + .AddSeconds(-1); + // 查询本周的质量缺陷数据 + var defectQuery = Queryable() + .Where(o => o.CheckDatetime >= firstDayOfMonth && o.CheckDatetime <= lastDayOfMonth); + + // 获取有缺陷的工单列表 + List defectWorkorders = defectQuery + .Select(o => o.Workorder) + .Distinct() + .ToList(); + + if (defectWorkorders.Count == 0) + { + return new List(); + } + + // 查询相关工单信息 + var workorderQuery = Context.Queryable() + .Where(o => defectWorkorders.Contains(o.Workorder)); + + // 使用 SqlSugar 进行联表查询和分组统计 + var result = defectQuery + .InnerJoin((defect, work) => defect.Workorder == work.Workorder) + .GroupBy((defect, work) => new { work.StoveCode, defect.DefectName }) + .Select((defect, work) => new QualitySmartScreenDto + { + StoveCode = work.StoveCode, + DefectName = defect.DefectName, + Number = SqlFunc.AggregateSum(defect.Number) + }) + .ToList(); + + return result; + } + } +}