using Microsoft.AspNetCore.Mvc; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Model.Business; using ZR.Model.Dto; using ZR.Service.Business.IBusinessService; //创建时间:2025-01-02 namespace ZR.Admin.WebApi.Controllers { /// /// 质量BackEnd统计报表业务模块 /// [Verify] [Route("/mes/qc/BackEnd/QcBackEndServiceStatistics")] public class QcBackEndServiceStatisticsController : BaseController { /// /// 质量BackEnd统计报表业务模块接口 /// private readonly IQcBackEndServiceStatisticsService _QcBackEndServiceStatisticsService; public QcBackEndServiceStatisticsController( IQcBackEndServiceStatisticsService QcBackEndServiceStatisticsService ) { _QcBackEndServiceStatisticsService = QcBackEndServiceStatisticsService; } /// /// 查询质量BackEnd统计报表业务模块列表 /// /// /// [HttpGet("list")] public IActionResult QueryQcBackEndServiceStatistics( [FromQuery] QcBackEndServiceStatisticsQueryDto parm ) { var response = _QcBackEndServiceStatisticsService.GetList(parm); return SUCCESS(response); } /// /// 查询质量BackEnd统计报表业务模块列表 /// /// /// [HttpPost("GetReviseList")] [AllowAnonymous] public IActionResult GetReviseList([FromBody] QcBackEndServiceStatisticsQueryDto parm) { var response = _QcBackEndServiceStatisticsService.GetReviseList(parm); // 初始化统计数据 int totalRequireNumber = 0; int totalQualifiedNumber = 0; int totalPolishNumber = 0; int totalDamoNumber = 0; int totalBaofeiNumber = 0; int totalListCount = 0; // 将动态属性转换为字典并合并到主对象中,并计算统计数据 var resultWithDefects = response .Select(item => { var itemDict = new Dictionary(); foreach (var prop in typeof(QcBackEndServiceStatisticsDto).GetProperties()) { itemDict[prop.Name] = prop.GetValue(item); } // 添加动态属性 foreach (var dynamicProp in item.DynamicProperties) { itemDict[dynamicProp.Key] = dynamicProp.Value; } // 累加统计数据 totalRequireNumber += Convert.ToInt32(item.RequireNumber); totalQualifiedNumber += Convert.ToInt32(item.QualifiedNumber); totalPolishNumber += Convert.ToInt32(item.PolishNumber); totalDamoNumber += Convert.ToInt32(item.DamoNumber); totalBaofeiNumber += Convert.ToInt32(item.BaofeiNumber); totalListCount += 1; // 移除不要的属性 itemDict["DynamicProperties"] = null; itemDict["GroupDefectJson"] = ""; return itemDict; }) .ToList(); // 数据除三 totalRequireNumber = totalRequireNumber / 3; totalQualifiedNumber = totalQualifiedNumber / 3; totalPolishNumber = totalPolishNumber / 3; totalDamoNumber = totalDamoNumber / 3; totalBaofeiNumber = totalBaofeiNumber / 3; totalListCount = totalListCount / 3; // 计算合格率 double qualifiedRate = 0.0; if (totalRequireNumber > 0) { qualifiedRate = (double)totalQualifiedNumber / totalRequireNumber * 100; } else { qualifiedRate = 0.0; } // 创建统计数据字典 var statistics = new Dictionary { { "TotalRequireNumber", totalRequireNumber }, { "TotalQualifiedNumber", totalQualifiedNumber }, { "QualifiedRate", $"{qualifiedRate:F1}%" }, { "TotalPolishNumber", totalPolishNumber }, { "TotalDamoNumber", totalDamoNumber }, { "TotalBaofeiNumber", totalBaofeiNumber }, { "TotalListCount", totalListCount } }; // 创建分页结果 var pageList = resultWithDefects.Skip((parm.PageNum - 1) * parm.PageSize).Take(parm.PageSize).ToList(); // 返回包含数据和统计数据的对象 var result = new { statistics = statistics, pageList ,total = resultWithDefects.Count }; return SUCCESS(result); } /// /// 查询质量BackEnd统计报表业务模块详情 /// /// /// [HttpGet("{Id}")] public IActionResult GetQcBackEndServiceStatistics(string Id) { var response = _QcBackEndServiceStatisticsService.GetInfo(Id); var info = response.Adapt(); return SUCCESS(info); } /// /// 添加质量BackEnd统计报表业务模块 /// /// [HttpPost] [Log(Title = "质量BackEnd统计报表业务模块", BusinessType = BusinessType.INSERT)] public IActionResult AddQcBackEndServiceStatistics([FromBody] QcBackEndServiceStatisticsDto parm) { var modal = parm.Adapt().ToCreate(HttpContext); var response = _QcBackEndServiceStatisticsService.AddQcBackEndServiceStatistics(modal); return SUCCESS(response); } /// /// 更新质量BackEnd统计报表业务模块 /// /// [HttpPut] [Log(Title = "质量BackEnd统计报表业务模块", BusinessType = BusinessType.UPDATE)] public IActionResult UpdateQcBackEndServiceStatistics( [FromBody] QcBackEndServiceStatisticsDto parm ) { var modal = parm.Adapt().ToUpdate(HttpContext); var response = _QcBackEndServiceStatisticsService.UpdateQcBackEndServiceStatistics(modal); return ToResponse(response); } /// /// 删除质量BackEnd统计报表业务模块 /// /// [HttpDelete("{ids}")] [Log(Title = "质量BackEnd统计报表业务模块", BusinessType = BusinessType.DELETE)] public IActionResult DeleteQcBackEndServiceStatistics(string ids) { int[] idsArr = Tools.SpitIntArrary(ids); if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } var response = _QcBackEndServiceStatisticsService.Delete(idsArr); return ToResponse(response); } } }