Compare commits
2
Commits
19fb191c3d
...
3059befcf5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3059befcf5 | ||
|
|
38cd47410c |
@@ -1,14 +1,114 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Service.Interface;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace WebAPI.Controllers
|
namespace WebAPI.Controllers
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 统计报表
|
/// 统计报表(设备统计/维护报表/维修报表)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/inspection/report")]
|
[Route("api/inspection/report")]
|
||||||
public class StatisticsReportController : ControllerBase
|
public class StatisticsReportController : ControllerBase
|
||||||
{
|
{
|
||||||
// TODO: 实现 统计报表 相关接口
|
private readonly IStatisticsReportService _statisticsReportService;
|
||||||
|
|
||||||
|
public StatisticsReportController(IStatisticsReportService statisticsReportService)
|
||||||
|
{
|
||||||
|
_statisticsReportService = statisticsReportService;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region 设备统计报表
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备统计概览(总数/在用/闲置/报废等)
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("device/statistics")]
|
||||||
|
public async Task<IActionResult> GetDeviceStatistics()
|
||||||
|
{
|
||||||
|
return Ok(await _statisticsReportService.GetDeviceStatisticsAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 按分类统计设备数量
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("device/category")]
|
||||||
|
public async Task<IActionResult> GetCategoryStatistics()
|
||||||
|
{
|
||||||
|
return Ok(await _statisticsReportService.GetCategoryStatisticsAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 按部门统计设备数量
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("device/department")]
|
||||||
|
public async Task<IActionResult> GetDepartmentStatistics()
|
||||||
|
{
|
||||||
|
return Ok(await _statisticsReportService.GetDepartmentStatisticsAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 设备维护报表
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备维护统计(校准/保养及时率、超期数量等)
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("maintenance/statistics")]
|
||||||
|
public async Task<IActionResult> GetMaintenanceStatistics()
|
||||||
|
{
|
||||||
|
return Ok(await _statisticsReportService.GetMaintenanceStatisticsAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维护超期设备明细
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("maintenance/overdue")]
|
||||||
|
public async Task<IActionResult> GetMaintenanceOverdueDetails()
|
||||||
|
{
|
||||||
|
return Ok(await _statisticsReportService.GetMaintenanceOverdueDetailsAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 维修类报表
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修统计概览
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("repair/statistics")]
|
||||||
|
public async Task<IActionResult> GetRepairStatistics()
|
||||||
|
{
|
||||||
|
return Ok(await _statisticsReportService.GetRepairStatisticsAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 故障类型分布
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("repair/fault-type")]
|
||||||
|
public async Task<IActionResult> GetFaultTypeDistribution()
|
||||||
|
{
|
||||||
|
return Ok(await _statisticsReportService.GetFaultTypeDistributionAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修工时分析
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("repair/hours-analysis")]
|
||||||
|
public async Task<IActionResult> GetRepairHoursAnalysis()
|
||||||
|
{
|
||||||
|
return Ok(await _statisticsReportService.GetRepairHoursAnalysisAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修记录明细列表
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("repair/records")]
|
||||||
|
public async Task<IActionResult> GetRepairRecordDetails()
|
||||||
|
{
|
||||||
|
return Ok(await _statisticsReportService.GetRepairRecordDetailsAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,212 @@
|
|||||||
|
namespace Model.Dto.Inspection
|
||||||
|
{
|
||||||
|
#region 设备统计报表
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备统计概览
|
||||||
|
/// </summary>
|
||||||
|
public class DeviceStatisticsDto
|
||||||
|
{
|
||||||
|
/// <summary>设备总数</summary>
|
||||||
|
public int Total { get; set; }
|
||||||
|
|
||||||
|
/// <summary>在用数量</summary>
|
||||||
|
public int InUse { get; set; }
|
||||||
|
|
||||||
|
/// <summary>闲置数量</summary>
|
||||||
|
public int Idle { get; set; }
|
||||||
|
|
||||||
|
/// <summary>报废数量(已处置+待处置)</summary>
|
||||||
|
public int Scrapped { get; set; }
|
||||||
|
|
||||||
|
/// <summary>维修中数量</summary>
|
||||||
|
public int Repairing { get; set; }
|
||||||
|
|
||||||
|
/// <summary>已停用数量</summary>
|
||||||
|
public int Suspended { get; set; }
|
||||||
|
|
||||||
|
/// <summary>其他数量(待验收/已借出/入库)</summary>
|
||||||
|
public int Other { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 按分类统计
|
||||||
|
/// </summary>
|
||||||
|
public class CategoryStatisticsDto
|
||||||
|
{
|
||||||
|
/// <summary>分类名称</summary>
|
||||||
|
public string? CategoryName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>设备数量</summary>
|
||||||
|
public int Count { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 按部门统计
|
||||||
|
/// </summary>
|
||||||
|
public class DepartmentStatisticsDto
|
||||||
|
{
|
||||||
|
/// <summary>部门名称</summary>
|
||||||
|
public string? Department { get; set; }
|
||||||
|
|
||||||
|
/// <summary>设备数量</summary>
|
||||||
|
public int Count { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 设备维护报表
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备维护统计
|
||||||
|
/// </summary>
|
||||||
|
public class MaintenanceStatisticsDto
|
||||||
|
{
|
||||||
|
/// <summary>设备总数</summary>
|
||||||
|
public int Total { get; set; }
|
||||||
|
|
||||||
|
/// <summary>校准正常数量</summary>
|
||||||
|
public int CalibrationNormal { get; set; }
|
||||||
|
|
||||||
|
/// <summary>校准超期数量</summary>
|
||||||
|
public int CalibrationOverdue { get; set; }
|
||||||
|
|
||||||
|
/// <summary>保养正常数量</summary>
|
||||||
|
public int MaintenanceNormal { get; set; }
|
||||||
|
|
||||||
|
/// <summary>保养超期数量</summary>
|
||||||
|
public int MaintenanceOverdue { get; set; }
|
||||||
|
|
||||||
|
/// <summary>校准及时率(%)</summary>
|
||||||
|
public decimal CalibrationTimelyRate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>保养及时率(%)</summary>
|
||||||
|
public decimal MaintenanceTimelyRate { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维护超期设备明细
|
||||||
|
/// </summary>
|
||||||
|
public class MaintenanceOverdueDetailDto
|
||||||
|
{
|
||||||
|
/// <summary>设备编号</summary>
|
||||||
|
public string? EquipmentCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>设备名称</summary>
|
||||||
|
public string? EquipmentName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>部门</summary>
|
||||||
|
public string? Department { get; set; }
|
||||||
|
|
||||||
|
/// <summary>超期类型(校准超期/保养超期)</summary>
|
||||||
|
public string? OverdueType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>到期日期</summary>
|
||||||
|
public DateTime? ExpireDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>超期天数</summary>
|
||||||
|
public int OverdueDays { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 维修类报表
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修统计概览
|
||||||
|
/// </summary>
|
||||||
|
public class RepairStatisticsDto
|
||||||
|
{
|
||||||
|
/// <summary>维修记录总数</summary>
|
||||||
|
public int Total { get; set; }
|
||||||
|
|
||||||
|
/// <summary>已完成数量</summary>
|
||||||
|
public int Completed { get; set; }
|
||||||
|
|
||||||
|
/// <summary>维修中数量</summary>
|
||||||
|
public int InProgress { get; set; }
|
||||||
|
|
||||||
|
/// <summary>待维修数量</summary>
|
||||||
|
public int Pending { get; set; }
|
||||||
|
|
||||||
|
/// <summary>平均维修工时(小时)</summary>
|
||||||
|
public decimal AvgRepairHours { get; set; }
|
||||||
|
|
||||||
|
/// <summary>总维修工时(小时)</summary>
|
||||||
|
public decimal TotalRepairHours { get; set; }
|
||||||
|
|
||||||
|
/// <summary>总维修费用(元)</summary>
|
||||||
|
public decimal TotalRepairCost { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 故障类型分布
|
||||||
|
/// </summary>
|
||||||
|
public class FaultTypeDistributionDto
|
||||||
|
{
|
||||||
|
/// <summary>故障类型</summary>
|
||||||
|
public string? FaultType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>数量</summary>
|
||||||
|
public int Count { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修工时分析
|
||||||
|
/// </summary>
|
||||||
|
public class RepairHoursAnalysisDto
|
||||||
|
{
|
||||||
|
/// <summary>故障类型</summary>
|
||||||
|
public string? FaultType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>平均工时(小时)</summary>
|
||||||
|
public decimal AvgHours { get; set; }
|
||||||
|
|
||||||
|
/// <summary>最大工时(小时)</summary>
|
||||||
|
public decimal MaxHours { get; set; }
|
||||||
|
|
||||||
|
/// <summary>最小工时(小时)</summary>
|
||||||
|
public decimal MinHours { get; set; }
|
||||||
|
|
||||||
|
/// <summary>记录数</summary>
|
||||||
|
public int Count { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修记录明细
|
||||||
|
/// </summary>
|
||||||
|
public class RepairRecordDetailDto
|
||||||
|
{
|
||||||
|
/// <summary>设备编号</summary>
|
||||||
|
public string? EquipmentCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>设备名称</summary>
|
||||||
|
public string? EquipmentName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>故障类型</summary>
|
||||||
|
public string? FaultType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>故障描述</summary>
|
||||||
|
public string? FaultDescription { get; set; }
|
||||||
|
|
||||||
|
/// <summary>报修日期</summary>
|
||||||
|
public DateTime? ReportDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>维修完成日期</summary>
|
||||||
|
public DateTime? RepairEndDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>维修工时</summary>
|
||||||
|
public decimal? RepairHours { get; set; }
|
||||||
|
|
||||||
|
/// <summary>维修人员</summary>
|
||||||
|
public string? RepairPerson { get; set; }
|
||||||
|
|
||||||
|
/// <summary>维修费用</summary>
|
||||||
|
public decimal? RepairCost { get; set; }
|
||||||
|
|
||||||
|
/// <summary>维修状态</summary>
|
||||||
|
public string? RepairStatus { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace Model.Entity.Inspection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 设备维修记录
|
||||||
|
/// </summary>
|
||||||
|
public class RepairRecordEntity : BaseEntity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 设备Id(关联 EquipmentEntity.Id)
|
||||||
|
/// </summary>
|
||||||
|
public long EquipmentId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备编号(冗余便于展示)
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 50, IsNullable = true)]
|
||||||
|
public string? EquipmentCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备名称(冗余便于展示)
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 100, IsNullable = true)]
|
||||||
|
public string? EquipmentName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 故障类型(机械故障/电气故障/软件故障/传感器故障/其他)
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 50, IsNullable = true)]
|
||||||
|
public string? FaultType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 故障描述
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDataType = "text", IsNullable = true)]
|
||||||
|
public string? FaultDescription { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 报修日期
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? ReportDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修开始日期
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public DateTime? RepairStartDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修完成日期
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public DateTime? RepairEndDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修工时(小时)
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(IsNullable = true)]
|
||||||
|
public decimal? RepairHours { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修人员
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 50, IsNullable = true)]
|
||||||
|
public string? RepairPerson { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修费用(元)
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(DecimalDigits = 2, Length = 18, IsNullable = true)]
|
||||||
|
public decimal? RepairCost { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修状态(待维修/维修中/已完成)
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 20, IsNullable = true)]
|
||||||
|
public string? RepairStatus { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修结果描述
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDataType = "text", IsNullable = true)]
|
||||||
|
public string? RepairResult { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 备注
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(Length = 500, IsNullable = true)]
|
||||||
|
public string? Remark { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,14 @@
|
|||||||
|
using Model;
|
||||||
|
using Model.Dto.Inspection;
|
||||||
|
using Model.Entity.Asset;
|
||||||
|
using Model.Entity.Inspection;
|
||||||
|
using ORM;
|
||||||
using Service.Interface;
|
using Service.Interface;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Service.Implement
|
namespace Service.Implement
|
||||||
{
|
{
|
||||||
@@ -7,6 +17,326 @@ namespace Service.Implement
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class StatisticsReportService : IStatisticsReportService
|
public class StatisticsReportService : IStatisticsReportService
|
||||||
{
|
{
|
||||||
// TODO: 实现 统计报表 相关方法
|
#region 设备统计报表
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备统计概览(总数/在用/闲置/报废等)
|
||||||
|
/// </summary>
|
||||||
|
public async Task<Result<DeviceStatisticsDto>> GetDeviceStatisticsAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var query = SqlSugarContext.DbContext.Queryable<EquipmentEntity>()
|
||||||
|
.Where(x => x.IsDel == 0);
|
||||||
|
|
||||||
|
var all = await query.ToListAsync();
|
||||||
|
var total = all.Count;
|
||||||
|
|
||||||
|
var dto = new DeviceStatisticsDto
|
||||||
|
{
|
||||||
|
Total = total,
|
||||||
|
InUse = all.Count(x => x.Status == EquipmentStatusEnum.InUse),
|
||||||
|
Idle = all.Count(x => x.Status == EquipmentStatusEnum.Idle),
|
||||||
|
Scrapped = all.Count(x => x.Status == EquipmentStatusEnum.Disposed || x.Status == EquipmentStatusEnum.PendingDisposal),
|
||||||
|
Repairing = all.Count(x => x.Status == EquipmentStatusEnum.Repairing),
|
||||||
|
Suspended = all.Count(x => x.Status == EquipmentStatusEnum.Suspended),
|
||||||
|
Other = all.Count(x =>
|
||||||
|
x.Status != EquipmentStatusEnum.InUse &&
|
||||||
|
x.Status != EquipmentStatusEnum.Idle &&
|
||||||
|
x.Status != EquipmentStatusEnum.Disposed &&
|
||||||
|
x.Status != EquipmentStatusEnum.PendingDisposal &&
|
||||||
|
x.Status != EquipmentStatusEnum.Repairing &&
|
||||||
|
x.Status != EquipmentStatusEnum.Suspended)
|
||||||
|
};
|
||||||
|
|
||||||
|
return Result<DeviceStatisticsDto>.Success(dto);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result<DeviceStatisticsDto>.Error("查询设备统计失败", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 按分类统计设备数量
|
||||||
|
/// </summary>
|
||||||
|
public async Task<Result<List<CategoryStatisticsDto>>> GetCategoryStatisticsAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = await SqlSugarContext.DbContext.Queryable<EquipmentEntity>()
|
||||||
|
.LeftJoin<EquipmentCategoryEntity>((e, c) => e.CategoryId == c.Id)
|
||||||
|
.Where((e, c) => e.IsDel == 0)
|
||||||
|
.GroupBy((e, c) => new { c.Name })
|
||||||
|
.Select((e, c) => new CategoryStatisticsDto
|
||||||
|
{
|
||||||
|
CategoryName = c.Name,
|
||||||
|
Count = SqlFunc.AggregateCount(e.Id)
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return Result<List<CategoryStatisticsDto>>.Success(list);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result<List<CategoryStatisticsDto>>.Error("查询分类统计失败", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 按部门统计设备数量
|
||||||
|
/// </summary>
|
||||||
|
public async Task<Result<List<DepartmentStatisticsDto>>> GetDepartmentStatisticsAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = await SqlSugarContext.DbContext.Queryable<EquipmentEntity>()
|
||||||
|
.Where(x => x.IsDel == 0)
|
||||||
|
.GroupBy(x => x.Department)
|
||||||
|
.Select(x => new DepartmentStatisticsDto
|
||||||
|
{
|
||||||
|
Department = x.Department,
|
||||||
|
Count = SqlFunc.AggregateCount(x.Id)
|
||||||
|
})
|
||||||
|
.OrderByDescending(x => x.Count)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return Result<List<DepartmentStatisticsDto>>.Success(list);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result<List<DepartmentStatisticsDto>>.Error("查询部门统计失败", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 设备维护报表
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备维护统计(校准/保养及时率、超期数量等)
|
||||||
|
/// </summary>
|
||||||
|
public async Task<Result<MaintenanceStatisticsDto>> GetMaintenanceStatisticsAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var all = await SqlSugarContext.DbContext.Queryable<EquipmentEntity>()
|
||||||
|
.Where(x => x.IsDel == 0)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var total = all.Count;
|
||||||
|
var calNormal = all.Count(x => x.CalibrationStatus == ComplianceStatusEnum.Normal);
|
||||||
|
var calOverdue = all.Count(x => x.CalibrationStatus == ComplianceStatusEnum.Overdue);
|
||||||
|
var maintNormal = all.Count(x => x.MaintenanceStatus == ComplianceStatusEnum.Normal);
|
||||||
|
var maintOverdue = all.Count(x => x.MaintenanceStatus == ComplianceStatusEnum.Overdue);
|
||||||
|
|
||||||
|
var dto = new MaintenanceStatisticsDto
|
||||||
|
{
|
||||||
|
Total = total,
|
||||||
|
CalibrationNormal = calNormal,
|
||||||
|
CalibrationOverdue = calOverdue,
|
||||||
|
MaintenanceNormal = maintNormal,
|
||||||
|
MaintenanceOverdue = maintOverdue,
|
||||||
|
CalibrationTimelyRate = total > 0 ? Math.Round((decimal)calNormal / total * 100, 1) : 0,
|
||||||
|
MaintenanceTimelyRate = total > 0 ? Math.Round((decimal)maintNormal / total * 100, 1) : 0
|
||||||
|
};
|
||||||
|
|
||||||
|
return Result<MaintenanceStatisticsDto>.Success(dto);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result<MaintenanceStatisticsDto>.Error("查询维护统计失败", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维护超期设备明细
|
||||||
|
/// </summary>
|
||||||
|
public async Task<Result<List<MaintenanceOverdueDetailDto>>> GetMaintenanceOverdueDetailsAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var now = DateTime.Now;
|
||||||
|
var list = await SqlSugarContext.DbContext.Queryable<EquipmentEntity>()
|
||||||
|
.Where(x => x.IsDel == 0 &&
|
||||||
|
(x.CalibrationStatus == ComplianceStatusEnum.Overdue ||
|
||||||
|
x.MaintenanceStatus == ComplianceStatusEnum.Overdue))
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var details = new List<MaintenanceOverdueDetailDto>();
|
||||||
|
foreach (var eq in list)
|
||||||
|
{
|
||||||
|
if (eq.CalibrationStatus == ComplianceStatusEnum.Overdue && eq.NextCalibrationDate.HasValue)
|
||||||
|
{
|
||||||
|
var days = (int)(now - eq.NextCalibrationDate.Value).TotalDays;
|
||||||
|
details.Add(new MaintenanceOverdueDetailDto
|
||||||
|
{
|
||||||
|
EquipmentCode = eq.Code,
|
||||||
|
EquipmentName = eq.Name,
|
||||||
|
Department = eq.Department,
|
||||||
|
OverdueType = "校准超期",
|
||||||
|
ExpireDate = eq.NextCalibrationDate,
|
||||||
|
OverdueDays = days > 0 ? days : 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (eq.MaintenanceStatus == ComplianceStatusEnum.Overdue && eq.NextMaintenanceDate.HasValue)
|
||||||
|
{
|
||||||
|
var days = (int)(now - eq.NextMaintenanceDate.Value).TotalDays;
|
||||||
|
details.Add(new MaintenanceOverdueDetailDto
|
||||||
|
{
|
||||||
|
EquipmentCode = eq.Code,
|
||||||
|
EquipmentName = eq.Name,
|
||||||
|
Department = eq.Department,
|
||||||
|
OverdueType = "保养超期",
|
||||||
|
ExpireDate = eq.NextMaintenanceDate,
|
||||||
|
OverdueDays = days > 0 ? days : 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result<List<MaintenanceOverdueDetailDto>>.Success(details);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result<List<MaintenanceOverdueDetailDto>>.Error("查询维护超期明细失败", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 维修类报表
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修统计概览
|
||||||
|
/// </summary>
|
||||||
|
public async Task<Result<RepairStatisticsDto>> GetRepairStatisticsAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var all = await SqlSugarContext.DbContext.Queryable<RepairRecordEntity>()
|
||||||
|
.Where(x => x.IsDel == 0)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var total = all.Count;
|
||||||
|
var completed = all.Count(x => x.RepairStatus == "已完成");
|
||||||
|
var inProgress = all.Count(x => x.RepairStatus == "维修中");
|
||||||
|
var pending = all.Count(x => x.RepairStatus == "待维修");
|
||||||
|
|
||||||
|
var totalHours = all.Where(x => x.RepairHours.HasValue).Sum(x => x.RepairHours ?? 0);
|
||||||
|
var completedWithHours = all.Where(x => x.RepairHours.HasValue && x.RepairStatus == "已完成").ToList();
|
||||||
|
var avgHours = completedWithHours.Count > 0
|
||||||
|
? Math.Round(completedWithHours.Sum(x => x.RepairHours ?? 0) / completedWithHours.Count, 1)
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
var totalCost = all.Where(x => x.RepairCost.HasValue).Sum(x => x.RepairCost ?? 0);
|
||||||
|
|
||||||
|
var dto = new RepairStatisticsDto
|
||||||
|
{
|
||||||
|
Total = total,
|
||||||
|
Completed = completed,
|
||||||
|
InProgress = inProgress,
|
||||||
|
Pending = pending,
|
||||||
|
AvgRepairHours = avgHours,
|
||||||
|
TotalRepairHours = totalHours,
|
||||||
|
TotalRepairCost = totalCost
|
||||||
|
};
|
||||||
|
|
||||||
|
return Result<RepairStatisticsDto>.Success(dto);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result<RepairStatisticsDto>.Error("查询维修统计失败", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 故障类型分布
|
||||||
|
/// </summary>
|
||||||
|
public async Task<Result<List<FaultTypeDistributionDto>>> GetFaultTypeDistributionAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = await SqlSugarContext.DbContext.Queryable<RepairRecordEntity>()
|
||||||
|
.Where(x => x.IsDel == 0)
|
||||||
|
.GroupBy(x => x.FaultType)
|
||||||
|
.Select(x => new FaultTypeDistributionDto
|
||||||
|
{
|
||||||
|
FaultType = x.FaultType,
|
||||||
|
Count = SqlFunc.AggregateCount(x.Id)
|
||||||
|
})
|
||||||
|
.OrderByDescending(x => x.Count)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return Result<List<FaultTypeDistributionDto>>.Success(list);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result<List<FaultTypeDistributionDto>>.Error("查询故障类型分布失败", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修工时分析
|
||||||
|
/// </summary>
|
||||||
|
public async Task<Result<List<RepairHoursAnalysisDto>>> GetRepairHoursAnalysisAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = await SqlSugarContext.DbContext.Queryable<RepairRecordEntity>()
|
||||||
|
.Where(x => x.IsDel == 0 && x.RepairHours.HasValue)
|
||||||
|
.GroupBy(x => x.FaultType)
|
||||||
|
.Select(x => new RepairHoursAnalysisDto
|
||||||
|
{
|
||||||
|
FaultType = x.FaultType,
|
||||||
|
AvgHours = SqlFunc.AggregateAvg(x.RepairHours) ?? 0,
|
||||||
|
MaxHours = SqlFunc.AggregateMax(x.RepairHours) ?? 0,
|
||||||
|
MinHours = SqlFunc.AggregateMin(x.RepairHours) ?? 0,
|
||||||
|
Count = SqlFunc.AggregateCount(x.Id)
|
||||||
|
})
|
||||||
|
.OrderByDescending(x => x.AvgHours)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return Result<List<RepairHoursAnalysisDto>>.Success(list);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result<List<RepairHoursAnalysisDto>>.Error("查询维修工时分析失败", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修记录明细列表
|
||||||
|
/// </summary>
|
||||||
|
public async Task<Result<List<RepairRecordDetailDto>>> GetRepairRecordDetailsAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = await SqlSugarContext.DbContext.Queryable<RepairRecordEntity>()
|
||||||
|
.Where(x => x.IsDel == 0)
|
||||||
|
.OrderByDescending(x => x.CreateTime)
|
||||||
|
.Select(x => new RepairRecordDetailDto
|
||||||
|
{
|
||||||
|
EquipmentCode = x.EquipmentCode,
|
||||||
|
EquipmentName = x.EquipmentName,
|
||||||
|
FaultType = x.FaultType,
|
||||||
|
FaultDescription = x.FaultDescription,
|
||||||
|
ReportDate = x.ReportDate,
|
||||||
|
RepairEndDate = x.RepairEndDate,
|
||||||
|
RepairHours = x.RepairHours,
|
||||||
|
RepairPerson = x.RepairPerson,
|
||||||
|
RepairCost = x.RepairCost,
|
||||||
|
RepairStatus = x.RepairStatus
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return Result<List<RepairRecordDetailDto>>.Success(list);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Result<List<RepairRecordDetailDto>>.Error("查询维修记录明细失败", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
using Model;
|
||||||
|
using Model.Dto.Inspection;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Service.Interface
|
namespace Service.Interface
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -5,6 +10,49 @@ namespace Service.Interface
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IStatisticsReportService
|
public interface IStatisticsReportService
|
||||||
{
|
{
|
||||||
// TODO: 定义 统计报表 相关方法
|
/// <summary>
|
||||||
|
/// 设备统计概览(总数/在用/闲置/报废等)
|
||||||
|
/// </summary>
|
||||||
|
Task<Result<DeviceStatisticsDto>> GetDeviceStatisticsAsync();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 按分类统计设备数量
|
||||||
|
/// </summary>
|
||||||
|
Task<Result<List<CategoryStatisticsDto>>> GetCategoryStatisticsAsync();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 按部门统计设备数量
|
||||||
|
/// </summary>
|
||||||
|
Task<Result<List<DepartmentStatisticsDto>>> GetDepartmentStatisticsAsync();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设备维护统计(校准/保养及时率、超期数量等)
|
||||||
|
/// </summary>
|
||||||
|
Task<Result<MaintenanceStatisticsDto>> GetMaintenanceStatisticsAsync();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维护超期设备明细
|
||||||
|
/// </summary>
|
||||||
|
Task<Result<List<MaintenanceOverdueDetailDto>>> GetMaintenanceOverdueDetailsAsync();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修统计概览
|
||||||
|
/// </summary>
|
||||||
|
Task<Result<RepairStatisticsDto>> GetRepairStatisticsAsync();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 故障类型分布
|
||||||
|
/// </summary>
|
||||||
|
Task<Result<List<FaultTypeDistributionDto>>> GetFaultTypeDistributionAsync();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修工时分析
|
||||||
|
/// </summary>
|
||||||
|
Task<Result<List<RepairHoursAnalysisDto>>> GetRepairHoursAnalysisAsync();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 维修记录明细列表
|
||||||
|
/// </summary>
|
||||||
|
Task<Result<List<RepairRecordDetailDto>>> GetRepairRecordDetailsAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user