gaoluyang
9 天以前 cbadfd8e691ab335965202a984db16e55ac8e42c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package cn.iocoder.yudao.module.mes.controller.admin.dv.statistics;
 
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.mes.controller.admin.dv.statistics.vo.MesDvMachineryStatisticsRespVO;
import cn.iocoder.yudao.module.mes.service.dv.statistics.MesDvStatisticsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
 
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
@Tag(name = "管理后台 - MES 设备统计分析")
@RestController
@RequestMapping("/mes/dv/statistics")
@Validated
public class MesDvStatisticsController {
 
    @Resource
    private MesDvStatisticsService statisticsService;
 
    @GetMapping("/machinery")
    @Operation(summary = "设备使用率与故障频次统计", description = "统计区间内累计维修耗时、停机时长、使用率与故障(维修)次数")
    @Parameter(name = "beginDate", description = "开始日期,默认统计区间为近 30 天", example = "2026-10-01")
    @Parameter(name = "endDate", description = "结束日期", example = "2026-10-31")
    @Parameter(name = "machineryId", description = "设备编号,为空则统计全部", example = "1")
    @PreAuthorize("@ss.hasPermission('mes:dv-statistics:query')")
    public CommonResult<List<MesDvMachineryStatisticsRespVO>> getMachineryStatistics(
            @RequestParam(value = "beginDate", required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginDate,
            @RequestParam(value = "endDate", required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate,
            @RequestParam(value = "machineryId", required = false) Long machineryId) {
        LocalDate end = endDate != null ? endDate : LocalDate.now();
        LocalDate begin = beginDate != null ? beginDate : end.minusDays(29);
        return success(statisticsService.getMachineryStatistics(
                begin.atStartOfDay(), end.atTime(LocalTime.MAX), machineryId));
    }
 
}