196 lines
7.5 KiB
C#
196 lines
7.5 KiB
C#
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
|
||
{
|
||
/// <summary>
|
||
/// 质量GP12统计报表业务模块
|
||
/// </summary>
|
||
[Verify]
|
||
[Route("/mes/qc/gp12/QcGp12ServiceStatistics")]
|
||
public class QcGp12ServiceStatisticsController : BaseController
|
||
{
|
||
/// <summary>
|
||
/// 质量GP12统计报表业务模块接口
|
||
/// </summary>
|
||
private readonly IQcGp12ServiceStatisticsService _QcGp12ServiceStatisticsService;
|
||
|
||
public QcGp12ServiceStatisticsController(
|
||
IQcGp12ServiceStatisticsService QcGp12ServiceStatisticsService
|
||
)
|
||
{
|
||
_QcGp12ServiceStatisticsService = QcGp12ServiceStatisticsService;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询质量GP12统计报表业务模块列表
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("list")]
|
||
[ActionPermissionFilter(Permission = "business:qcgp12servicestatistics:list")]
|
||
public IActionResult QueryQcGp12ServiceStatistics(
|
||
[FromQuery] QcGp12ServiceStatisticsQueryDto parm
|
||
)
|
||
{
|
||
var response = _QcGp12ServiceStatisticsService.GetList(parm);
|
||
return SUCCESS(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询质量GP12统计报表业务模块列表
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
[HttpPost("GetReviseList")]
|
||
[AllowAnonymous]
|
||
public IActionResult GetReviseList([FromBody] QcGp12ServiceStatisticsQueryDto parm)
|
||
{
|
||
var response = _QcGp12ServiceStatisticsService.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<string, object>();
|
||
foreach (var prop in typeof(QcGp12ServiceStatisticsDto).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;
|
||
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<string, object>
|
||
{
|
||
{ "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 { list = resultWithDefects, statistics = statistics, pageList,total=resultWithDefects.Count };
|
||
|
||
return SUCCESS(result);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询质量GP12统计报表业务模块详情
|
||
/// </summary>
|
||
/// <param name="Id"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("{Id}")]
|
||
[ActionPermissionFilter(Permission = "business:qcgp12servicestatistics:query")]
|
||
public IActionResult GetQcGp12ServiceStatistics(string Id)
|
||
{
|
||
var response = _QcGp12ServiceStatisticsService.GetInfo(Id);
|
||
|
||
var info = response.Adapt<QcGp12ServiceStatistics>();
|
||
return SUCCESS(info);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加质量GP12统计报表业务模块
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[ActionPermissionFilter(Permission = "business:qcgp12servicestatistics:add")]
|
||
[Log(Title = "质量GP12统计报表业务模块", BusinessType = BusinessType.INSERT)]
|
||
public IActionResult AddQcGp12ServiceStatistics([FromBody] QcGp12ServiceStatisticsDto parm)
|
||
{
|
||
var modal = parm.Adapt<QcGp12ServiceStatistics>().ToCreate(HttpContext);
|
||
|
||
var response = _QcGp12ServiceStatisticsService.AddQcGp12ServiceStatistics(modal);
|
||
|
||
return SUCCESS(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新质量GP12统计报表业务模块
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPut]
|
||
[ActionPermissionFilter(Permission = "business:qcgp12servicestatistics:edit")]
|
||
[Log(Title = "质量GP12统计报表业务模块", BusinessType = BusinessType.UPDATE)]
|
||
public IActionResult UpdateQcGp12ServiceStatistics(
|
||
[FromBody] QcGp12ServiceStatisticsDto parm
|
||
)
|
||
{
|
||
var modal = parm.Adapt<QcGp12ServiceStatistics>().ToUpdate(HttpContext);
|
||
var response = _QcGp12ServiceStatisticsService.UpdateQcGp12ServiceStatistics(modal);
|
||
|
||
return ToResponse(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除质量GP12统计报表业务模块
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpDelete("{ids}")]
|
||
[ActionPermissionFilter(Permission = "business:qcgp12servicestatistics:delete")]
|
||
[Log(Title = "质量GP12统计报表业务模块", BusinessType = BusinessType.DELETE)]
|
||
public IActionResult DeleteQcGp12ServiceStatistics(string ids)
|
||
{
|
||
int[] idsArr = Tools.SpitIntArrary(ids);
|
||
if (idsArr.Length <= 0)
|
||
{
|
||
return ToResponse(ApiResult.Error($"删除失败Id 不能为空"));
|
||
}
|
||
|
||
var response = _QcGp12ServiceStatisticsService.Delete(idsArr);
|
||
|
||
return ToResponse(response);
|
||
}
|
||
}
|
||
}
|