diff --git a/ZR.Admin.WebApi/Controllers/mes/echarts/fqc/EchartsFQCController.cs b/ZR.Admin.WebApi/Controllers/mes/echarts/fqc/EchartsFQCController.cs new file mode 100644 index 00000000..e4d220b8 --- /dev/null +++ b/ZR.Admin.WebApi/Controllers/mes/echarts/fqc/EchartsFQCController.cs @@ -0,0 +1,40 @@ +using Microsoft.AspNetCore.Mvc; +using ZR.Model.mes.echarts; +using ZR.Service.MES.echarts.IService; + +namespace ZR.Admin.WebApi.Controllers.mes.echarts +{ + [Route("mes/echarts/fqc")] + public class EchartsFQCController : BaseController + { + private readonly IFQCEchartsService _fQCEchartsService; + + public EchartsFQCController(IFQCEchartsService fQCEchartsService) + { + this._fQCEchartsService = fQCEchartsService; + } + + /// + /// 获取质量Echarts图表 + /// + /// 查询值 + /// QcCommonFqcBoardDto 看板数据 + [HttpPost("getEchartsData")] + public IActionResult GetFQCQualityOptions([FromBody] FQCQualityQuery query) + { + try + { + var result = _fQCEchartsService.GetFQCQualityOptions(query); + if (result == null) + { + return ToResponse(new ApiResult(500, "获取图表数据异常", result)); + } + return ToResponse(new ApiResult(200, "ok", result)); + } + catch (Exception ex) + { + return ToResponse(new ApiResult(500, ex.Message, ex.Message)); + } + } + } +} diff --git a/ZR.Admin.WebApi/Controllers/mes/qc/FQC/QCStatisticsController.cs b/ZR.Admin.WebApi/Controllers/mes/qc/FQC/QCStatisticsController.cs index b750a40d..55a143fa 100644 --- a/ZR.Admin.WebApi/Controllers/mes/qc/FQC/QCStatisticsController.cs +++ b/ZR.Admin.WebApi/Controllers/mes/qc/FQC/QCStatisticsController.cs @@ -113,7 +113,7 @@ namespace ZR.Admin.WebApi.Controllers.mes.qc.FQC "水斑", "脏点", "变形","油珠","脱落","撞伤","其他", "毛刺", "缩印", "擦伤","砂印","流痕","开裂", "流挂", "色漆 缺漆", "清漆缺漆","桔皮","其他", - "脱落擦伤", "清漆漆块", "色漆漆块","发花","亮斑","喷漏",}; + "下件擦伤", "清漆漆块", "色漆漆块","发花","亮斑","喷漏",}; // 标题列位于第几行 int startTitle = 0; if (isShowDetail) diff --git a/ZR.Model/MES/echarts/EchartsDto.cs b/ZR.Model/MES/echarts/EchartsDto.cs new file mode 100644 index 00000000..269c70c8 --- /dev/null +++ b/ZR.Model/MES/echarts/EchartsDto.cs @@ -0,0 +1,120 @@ +using Newtonsoft.Json.Converters; + +namespace ZR.Model.mes.echarts +{ + /// + /// FQC质量报表echarts查询 + /// + public class FQCQualityQuery + { + /// + /// 报表类别 1-首检报表 2-抛光报表 3-包装报表 4-总报表 + /// + public int ReportType { get; set; } + + /// + /// 报表类别 0-工单统计 1-工单统计 2-Top3缺陷数 3-Top10零件合格数 + /// + public int ChartType { get; set; } + + /// + /// 时间类型 0-自定义 1-本月 2-本日 3-本周 4-本季度 5-本年 + /// + public int TimeType { get; set; } + + /// + /// 时间范围 + /// + public DateTime? StartTime { get; set; } + public DateTime? EndTime { get; set; } + + /// + /// 精确零件号查询 + /// + public string Partnumber { get; set; } + + /// + /// 普通零件描述查询 + /// + public string Description { get; set; } + } + + /// + /// echarts 通用Options返回值 + /// + public class EchartsOptions + { + public EchartsTitle Title { get; set; } = null; + public EchartsXAxis XAxis { get; set; } = null; + public EchartsYAxis YAxis { get; set; } = null; + public List Series { get; set; } = new List(); + } + + /// + /// echarts图表标题 + /// + public class EchartsTitle + { + public string Text { get; set; } = string.Empty; + public string SubText { get; set; } = string.Empty; + } + + /// + /// echarts X轴 + /// + public class EchartsXAxis + { + public List Data { get; set; } = new List(); + + // value 数值轴,适用于连续数据 category 类目轴,适用于离散的类目数据 time 时间轴,适用于连续的时序数据 log 对数轴。适用于对数数据 + public string Type { get; set; } = "category"; + } + + /// + /// echarts Y轴 + /// + public class EchartsYAxis + { + public List Data { get; set; } = new List(); + + // value 数值轴,适用于连续数据 category 类目轴,适用于离散的类目数据 time 时间轴,适用于连续的时序数据 log 对数轴。适用于对数数据 + public string Type { get; set; } = "category"; + } + + /// + /// echarts图表series返回值 + /// + public class EchartsSeries + { + /// + /// 标签名称 + /// + public string Name { get; set; } = "category"; + + /// + /// bar-柱状图 line-折线图 EchartsSeriesType enum结构 + /// + public string Type { get; set; } = "bar"; + + /// + /// 参数值 + /// + public List Data { get; set; } = new List(); + } + + /// + /// echarts图表series返回值内容 + /// + public class EchartsSeriesData + { + /// + /// 标签名称 + /// + public string Name { get; set; } = string.Empty; + + /// + /// 参数值 + /// + public decimal Value { get; set; } = new decimal(); + } +} diff --git a/ZR.Service/mes/echarts/FQCEchartsService.cs b/ZR.Service/mes/echarts/FQCEchartsService.cs new file mode 100644 index 00000000..1e06080a --- /dev/null +++ b/ZR.Service/mes/echarts/FQCEchartsService.cs @@ -0,0 +1,213 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using Infrastructure.Attribute; +using Infrastructure.Extensions; +using SqlSugar; +using ZR.Model.mes.echarts; +using ZR.Model.MES.pro; +using ZR.Model.MES.qc; +using ZR.Service.MES.echarts.IService; + +namespace ZR.Service.MES.md +{ + [AppService(ServiceType = typeof(IFQCEchartsService), ServiceLifetime = LifeTime.Transient)] + public class FQCEchartsService : BaseService, IFQCEchartsService + { + public EchartsOptions GetFQCQualityOptions(FQCQualityQuery query) + { + try + { + EchartsOptions echartsOptions = new() { Series = new List() }; + if (query.ChartType == 0) + { + EchartsSeries series = + new() + { + Name = "工单统计", + Type = "bar", + Data = GetWorkOrderNumberSeriesData(query) + }; + echartsOptions.Series.Add(series); + } + if (query.ChartType == 2) + { + EchartsSeries series = + new() + { + Name = "缺陷数", + Type = "pie", + Data = GetDefectTotalSeriesData(query) + }; + echartsOptions.Series.Add(series); + } + return echartsOptions; + } + catch (Exception e) + { + throw new Exception(e.Message); + } + } + + /// + /// 生成X轴数据 + /// + /// + /// + public static List GetXAxisList(FQCQualityQuery query) + { + List list = new(); + int nowYear = DateTime.Now.Year; + int nowMonth = DateTime.Now.Month; + if (query.TimeType == 1) + { + int daysInMonth = DateTime.DaysInMonth(nowYear, nowMonth); + for (int day = 1; day <= daysInMonth; day++) + { + // 创建日期对象 + DateTime date = new(nowYear, nowMonth, day); + // 将日期格式化为字符串 + string dateString = date.ToString("yyyy-MM-dd"); + list.Add(dateString); + } + } + return list; + } + + /// + /// 生成日期数据 + /// + /// + /// + public static List GetDateTimeList(FQCQualityQuery query) + { + int nowYear = DateTime.Now.Year; + int nowMonth = DateTime.Now.Month; + int nowDay = DateTime.Now.Day; + List list = new(); + if (query.TimeType == 0) + { + list.Add(query.StartTime.Value.ToLocalTime()); + list.Add(query.EndTime.Value.ToLocalTime()); + } + else if (query.TimeType == 1) + { + int daysInMonth = DateTime.DaysInMonth(nowYear, nowMonth); + list.Add(new DateTime(nowYear, nowMonth, 1).ToLocalTime()); + list.Add( + new DateTime(nowYear, nowMonth, daysInMonth) + .AddDays(1) + .AddTicks(-1) + .ToLocalTime() + ); + } + else if (query.TimeType == 2) + { + list.Add(new DateTime(nowYear, nowMonth, nowDay).ToLocalTime()); + list.Add( + new DateTime(nowYear, nowMonth, nowDay).AddDays(1).AddTicks(-1).ToLocalTime() + ); + } + else if (query.TimeType == 3) + { + int dayOfWeek = (int)DateTime.Now.DayOfWeek; + DateTime start = DateTime.Now.AddDays(1 - dayOfWeek).Date; + list.Add(start.ToLocalTime()); + list.Add(start.AddDays(7).AddTicks(-1).ToLocalTime()); + } + else if (query.TimeType == 4) + { + int startMonth = (nowMonth - 1) / 3 * 3 + 1; + DateTime start = new DateTime(nowYear, startMonth, 1); + // 计算季度的最后一个月 + int endMonth = start.Month + 2; + int daysInMonth = DateTime.DaysInMonth(nowYear, endMonth); + list.Add(start.ToLocalTime()); + list.Add( + new DateTime(nowYear, endMonth, daysInMonth) + .AddDays(1) + .AddTicks(-1) + .ToLocalTime() + ); + } + else if (query.TimeType == 5) + { + list.Add(new DateTime(nowYear, 1, 1).ToLocalTime()); + list.Add(new DateTime(nowYear, 12, 31).AddDays(1).AddTicks(-1).ToLocalTime()); + } + return list; + } + + /// ======================================= 报表结果 ============================= + + /// + /// 获取工单数echarts图表数据 + /// + /// + /// + public List GetWorkOrderNumberSeriesData(FQCQualityQuery query) + { + List seriesDataList = new(); + List dateTimes = GetDateTimeList(query); + if (query.ReportType == 1) + { + var predicate = Expressionable + .Create() + .And(it => it.StartTime.Value >= dateTimes[0]) + .And(it => it.StartTime.Value <= dateTimes[1]) + .And(it => it.Remark2 == 2) + .ToExpression(); + seriesDataList = Context + .Queryable() + .Where(predicate) + .GroupBy(it => it.StartTime.Value.ToString("yyyy-MM-dd")) + .Select(it => new EchartsSeriesData + { + Name = it.StartTime.Value.ToString("yyyy-MM-dd"), + Value = SqlFunc.AggregateCount(it.Id) + }) + .ToList(); + } + + return seriesDataList; + } + + /// + /// 获取 日期时间内缺陷总数饼图 + /// + /// + /// + public List GetDefectTotalSeriesData(FQCQualityQuery query) + { + List seriesDataList = new(); + List dateTimes = GetDateTimeList(query); + if (query.ReportType == 1) + { + var predicate = Expressionable + .Create() + .And(it => it.StartTime.Value >= dateTimes[0]) + .And(it => it.StartTime.Value <= dateTimes[1]) + .And(it => it.Remark2 == 2) + .ToExpression(); + seriesDataList = Context + .Queryable() + .Where(predicate) + .GroupBy(it => it.FinishedPartNumber + " " + it.ProductDescription) + .Select(it => new EchartsSeriesData + { + Name = it.FinishedPartNumber + " " + it.ProductDescription, + Value = (decimal) + SqlFunc.AggregateSumNoNull( + it.PaoguangTotal + it.DamoTotal + it.BaofeiTotal + ) + }) + .OrderBy(it => it.Value, OrderByType.Desc) + .Take(3) + .ToList(); + } + + return seriesDataList; + } + } +} diff --git a/ZR.Service/mes/echarts/IService/IFQCEchartsService.cs b/ZR.Service/mes/echarts/IService/IFQCEchartsService.cs new file mode 100644 index 00000000..d8a3ac62 --- /dev/null +++ b/ZR.Service/mes/echarts/IService/IFQCEchartsService.cs @@ -0,0 +1,14 @@ +using ZR.Model.mes.echarts; +using ZR.Model.mes.md; + +namespace ZR.Service.MES.echarts.IService +{ + public interface IFQCEchartsService + { + /// + /// 获取质量报表echarts数据图 + /// + /// + EchartsOptions GetFQCQualityOptions(FQCQualityQuery query); + } +}