zhangherong
2025-05-06 915a2e40175c6390802af1257e57effea5fd02ef
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package org.jeecg.modules.eam.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.eam.constant.EquipmentMaintenanceStatus;
import org.jeecg.modules.eam.constant.EquipmentRepairStatus;
import org.jeecg.modules.eam.entity.EamEquipment;
import org.jeecg.modules.eam.service.IEamEquipmentService;
import org.jeecg.modules.eam.service.IEamInspectionOrderService;
import org.jeecg.modules.eam.service.IEamReportRepairService;
import org.jeecg.modules.eam.service.IEamWeekMaintenanceOrderService;
import org.jeecg.modules.eam.vo.EquipmentInspectionStatistics;
import org.jeecg.modules.eam.vo.EquipmentMaintenanceStatistics;
import org.jeecg.modules.eam.vo.EquipmentRepairStatistics;
import org.jeecg.modules.eam.vo.EquipmentStatusStatistics;
import org.springframework.beans.factory.annotation.Autowired;
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.util.*;
 
@Slf4j
@Api(tags = "设备管理-首页看板接口")
@RestController
@RequestMapping("/eam/dashboard")
public class EamDashboardController {
    @Autowired
    private IEamEquipmentService eamEquipmentService;
    @Autowired
    private IEamReportRepairService reportRepairService;
    @Autowired
    private IEamInspectionOrderService inspectionOrderService;
    @Autowired
    private IEamWeekMaintenanceOrderService weekMaintenanceOrderService;
 
    @ApiOperation(value = "看板接口-维保状态统计", notes = "看板接口-维保状态统计")
    @GetMapping(value = "/equipmentStatusStatistics")
    public Result<?> equipmentStatusStatistics(@RequestParam(required = false, value = "productionId") String productionId) {
        List<EamEquipment> list = eamEquipmentService.queryByProductionId(productionId);
        //初始化返回
        Map<String, EquipmentStatusStatistics> statisticsMap = new HashMap<>();
        statisticsMap.put(EquipmentMaintenanceStatus.NORMAL.name(), new EquipmentStatusStatistics(EquipmentMaintenanceStatus.NORMAL.name(), "正常"));
        statisticsMap.put(EquipmentMaintenanceStatus.UNDER_INSPECTION.name(), new EquipmentStatusStatistics(EquipmentMaintenanceStatus.UNDER_INSPECTION.name(), "点检"));
        statisticsMap.put(EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name(), new EquipmentStatusStatistics(EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name(), "保养"));
        statisticsMap.put(EquipmentRepairStatus.UNDER_REPAIR.name(), new EquipmentStatusStatistics(EquipmentRepairStatus.UNDER_REPAIR.name(), "维修"));
 
        for (EamEquipment entity : list) {
            if (EquipmentMaintenanceStatus.NORMAL.name().equals(entity.getMaintenanceStatus()) && EquipmentMaintenanceStatus.NORMAL.name().equals(entity.getRepairStatus())) {
                //正常状态
                statisticsMap.get(EquipmentMaintenanceStatus.NORMAL.name()).increase();
            } else if (!EquipmentMaintenanceStatus.NORMAL.name().equals(entity.getRepairStatus())) {
                //维修状态
                statisticsMap.get(EquipmentRepairStatus.UNDER_REPAIR.name()).increase();
            } else if (EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name().equals(entity.getMaintenanceStatus()) || EquipmentMaintenanceStatus.WAIT_CONFIRM.name().equals(entity.getMaintenanceStatus())) {
                //保养状态
                statisticsMap.get(EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name()).increase();
            } else {
                statisticsMap.get(EquipmentMaintenanceStatus.UNDER_INSPECTION.name()).increase();
            }
        }
        List<EquipmentStatusStatistics> resultList = new ArrayList<>(statisticsMap.values());
        return Result.ok(resultList);
    }
 
    @ApiOperation(value = "看板接口-维修统计", notes = "看板接口-维修统计")
    @GetMapping(value = "/equipmentRepairStatistics")
    public Result<?> equipmentRepairStatistics(@RequestParam(required = false, value = "productionId") String productionId) {
        //统计结束日期
        LocalDate today = LocalDate.now();
        LocalDate localDate = today.minusMonths(5);
        //统计开始日期
        LocalDate firstOfMonth = DateUtils.getFirstOfMonth(localDate);
 
        //初始化返回值
        Map<String, EquipmentRepairStatistics> statisticsMap = new HashMap<>();
        List<String> monthsBetween = DateUtils.getMonthsBetween(firstOfMonth, today);
        monthsBetween.forEach(month -> {
            statisticsMap.put(month, new EquipmentRepairStatistics(month));
        });
 
        List<EquipmentRepairStatistics> list = reportRepairService.equipmentRepairStatistics(productionId, firstOfMonth, today);
        for (EquipmentRepairStatistics statistics : list) {
            if (statisticsMap.containsKey(statistics.getMonthStr())) {
                statisticsMap.put(statistics.getMonthStr(), statistics);
            }
        }
        List<EquipmentRepairStatistics> resultList = new ArrayList<>(statisticsMap.values());
        //排序
        resultList.sort(Comparator.comparing(EquipmentRepairStatistics::getMonthStr));
        return Result.ok(resultList);
    }
 
    @ApiOperation(value = "看板接口-点检统计", notes = "看板接口-点检统计")
    @GetMapping(value = "/equipmentInspectionStatistics")
    public Result<?> equipmentInspectionStatistics(@RequestParam(required = false, value = "productionId") String productionId) {
        //统计结束日期
        LocalDate today = LocalDate.now();
        LocalDate localDate = today.minusMonths(5);
        //统计开始日期
        LocalDate firstOfMonth = DateUtils.getFirstOfMonth(localDate);
 
        //初始化返回值
        Map<String, EquipmentInspectionStatistics> statisticsMap = new HashMap<>();
        List<String> monthsBetween = DateUtils.getMonthsBetween(firstOfMonth, today);
        monthsBetween.forEach(month -> {
            statisticsMap.put(month, new EquipmentInspectionStatistics(month));
        });
 
        List<EquipmentInspectionStatistics> list = inspectionOrderService.equipmentInspectionStatistics(productionId, firstOfMonth, today);
        for (EquipmentInspectionStatistics statistics : list) {
            if (statisticsMap.containsKey(statistics.getMonthStr())) {
                statisticsMap.put(statistics.getMonthStr(), statistics);
            }
        }
        List<EquipmentInspectionStatistics> resultList = new ArrayList<>(statisticsMap.values());
        //排序
        resultList.sort(Comparator.comparing(EquipmentInspectionStatistics::getMonthStr));
        return Result.ok(resultList);
    }
 
    @ApiOperation(value = "看板接口-周保统计", notes = "看板接口-周保统计")
    @GetMapping(value = "/equipmentMaintenanceStatistics")
    public Result<?> equipmentMaintenanceStatistics(@RequestParam(required = false, value = "productionId") String productionId) {
        //统计结束日期
        LocalDate today = LocalDate.now();
        LocalDate localDate = today.minusMonths(5);
        //统计开始日期
        LocalDate firstOfMonth = DateUtils.getFirstOfMonth(localDate);
 
        //初始化返回值
        Map<String, EquipmentMaintenanceStatistics> statisticsMap = new HashMap<>();
        List<String> monthsBetween = DateUtils.getMonthsBetween(firstOfMonth, today);
        monthsBetween.forEach(month -> {
            statisticsMap.put(month, new EquipmentMaintenanceStatistics(month));
        });
 
        List<EquipmentMaintenanceStatistics> list = weekMaintenanceOrderService.equipmentMaintenanceStatistics(productionId, firstOfMonth, today);
        for (EquipmentMaintenanceStatistics statistics : list) {
            if (statisticsMap.containsKey(statistics.getMonthStr())) {
                statisticsMap.put(statistics.getMonthStr(), statistics);
            }
        }
        List<EquipmentMaintenanceStatistics> resultList = new ArrayList<>(statisticsMap.values());
        //排序
        resultList.sort(Comparator.comparing(EquipmentMaintenanceStatistics::getMonthStr));
        return Result.ok(resultList);
    }
}