cuilei
7 天以前 767ba5a54ca5597de816015f387981776b928f7b
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
package org.jeecg.modules.eam.controller;
 
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.TranslateDictTextUtils;
import org.jeecg.modules.eam.constant.*;
import org.jeecg.modules.eam.entity.*;
import org.jeecg.modules.eam.request.EamInspectionOrderQuery;
import org.jeecg.modules.eam.request.EamReportRepairQuery;
import org.jeecg.modules.eam.request.EamWeekMaintenanceQuery;
import org.jeecg.modules.eam.service.*;
import org.jeecg.modules.eam.vo.*;
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 javax.annotation.Resource;
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;
    @Resource
    private ObjectMapper objectMapper;
    @Resource
    private TranslateDictTextUtils translateDictTextUtils;
    @Autowired
    private IEamRepairOrderService repairOrderService;
 
 
    @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);
    }
 
    @ApiOperation(value = "维修看板-维修状态统计", notes = "维修看板-维修状态统计")
    @GetMapping(value = "/repairStatusStatistics")
    public Result<?> repairStatusStatistics() {
        EquipmentRepairStatusStatistics statistics = reportRepairService.repairStatusStatistics();
        return Result.OK(statistics);
    }
 
    @ApiOperation(value = "维修看板-维修列表", notes = "维修看板-维修列表")
    @GetMapping(value = "/repairList")
    public Result<?> repairList() {
        List<EquipmentRepairListVO> list = reportRepairService.repairList();
        if (CollectionUtil.isEmpty(list)) {
            return Result.ok(Collections.emptyList());
        }
        List<JSONObject> items = new ArrayList<>();
        try {
            for (EquipmentRepairListVO vo : list) {
                String json = objectMapper.writeValueAsString(vo);
                JSONObject item = JSONObject.parseObject(json, Feature.OrderedField);
                translateDictTextUtils.translateField("reportOperator", vo.getReportOperator(), item, "sys_user,realname,username");
                translateDictTextUtils.translateField("repairOperator", vo.getRepairOperator(), item, "sys_user,realname,username");
                translateDictTextUtils.translateField("reportStatus", vo.getReportStatus(), item, "report_repair_status");
                translateDictTextUtils.translateField("orgId", vo.getOrgId(), item, "mdc_production,production_name,id");
                items.add(item);
            }
            return Result.OK(items);
        } catch (Exception e) {
            return Result.error("数据转译失败!");
        }
    }
 
    @ApiOperation(value = "维修看板-维修工排名", notes = "维修看板-维修工排名")
    @GetMapping(value = "/repairmanRanking")
    public Result<?> repairmanRanking() {
        LocalDate today = LocalDate.now();
        LocalDate end = today.plusDays(1);
        LocalDate start = today.minusDays(30);
        //只取前7名
        List<RepairmanRankingVO> list = repairOrderService.repairmanRanking(start.toString(), end.toString());
        if (CollectionUtil.isEmpty(list)) {
            return Result.ok(Collections.emptyList());
        }
        if (list.size() > 7) {
            list = list.subList(0, 7);
        }
        List<JSONObject> items = new ArrayList<>();
        try {
            for (RepairmanRankingVO vo : list) {
                String json = objectMapper.writeValueAsString(vo);
                JSONObject item = JSONObject.parseObject(json, Feature.OrderedField);
                translateDictTextUtils.translateField("repairer", vo.getRepairer(), item, "sys_user,realname,username");
                items.add(item);
            }
            return Result.OK(items);
        } catch (Exception e) {
            return Result.error("数据转译失败!");
        }
    }
 
    @ApiOperation(value = "维修看板-故障类型统计", notes = "维修看板-故障类型统计")
    @GetMapping(value = "/faultTypeStatistics")
    public Result<?> faultTypeStatistics() {
        //统计今年来故障分类情况
        LocalDate today = LocalDate.now();
        LocalDate end = today.plusDays(1);
        //今年第一天
        LocalDate start = today.withDayOfYear(1);
        // 统计个数
        List<FaultTypeStatisticsVO> list = reportRepairService.faultTypeStatistics(start.toString(), end.toString());
        if (CollectionUtil.isEmpty(list)) {
            return Result.ok(Collections.emptyList());
        }
        List<JSONObject> items = new ArrayList<>();
        try {
            for (FaultTypeStatisticsVO vo : list) {
                String json = objectMapper.writeValueAsString(vo);
                JSONObject item = JSONObject.parseObject(json, Feature.OrderedField);
                translateDictTextUtils.translateField("faultType", vo.getFaultType(), item, "fault_reason_category");
                if (item.get("faultType" + CommonConstant.DICT_TEXT_SUFFIX) != null) {
                    items.add(item);
                }
            }
            return Result.OK(items);
        } catch (Exception e) {
            return Result.error("数据转译失败!");
        }
    }
 
    @ApiOperation(value = "H5首页-待执行工单数量统计", notes = "H5首页-待执行工单数量统计")
    @GetMapping(value = "/pendingExecOrderCountBySelf")
    public Result<?> pendingExecOrderCountBySelf() {
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        Map<String, Integer> countMap = CollectionUtil.newHashMap();
        if (user == null) {
            return Result.ok(countMap);
        }
        String post = user.getPost();
 
        if (BusinessCodeConst.PCR0001.equals(post)) {
            //是操作工,查询可领取的点检、周保工单
            Page<EamInspectionOrder> inspectionOrderPage = new Page<>(1, 99999999);
            EamInspectionOrderQuery inspectionOrderQuery = new EamInspectionOrderQuery();
            inspectionOrderQuery.setInspectionStatus(InspectionStatus.WAIT_INSPECTION.name());
            List<EamInspectionOrder> unReceivedInspectionOrderList = inspectionOrderService.queryPageList(inspectionOrderPage, inspectionOrderQuery).getRecords();
 
            Page<EamWeekMaintenanceOrder> maintenanceOrderPage = new Page<>(1, 99999999);
            EamWeekMaintenanceQuery weekMaintenanceQuery = new EamWeekMaintenanceQuery();
            weekMaintenanceQuery.setMaintenanceStatus(WeekMaintenanceStatusEnum.WAIT_MAINTENANCE.name());
            List<EamWeekMaintenanceOrder> unReceivedMaintenanceOrderList = weekMaintenanceOrderService.queryPageList(maintenanceOrderPage, weekMaintenanceQuery).getRecords();
            countMap.put("unExecInspectionOrderCount", unReceivedInspectionOrderList.size());
            countMap.put("unExecMaintenanceOrderCount", unReceivedMaintenanceOrderList.size());
            countMap.put("unExecRepairOrderCount", 0);
        } else if (BusinessCodeConst.PCR0002.equals(post)) {
            //是维修工,查询可领取的报修单
            Page<EamReportRepair> maintenanceOrderPage = new Page<>(1, 99999999);
            EamReportRepairQuery reportRepairQuery = new EamReportRepairQuery();
            reportRepairQuery.setReportStatus(EquipmentRepairStatus.WAIT_REPAIR.name());
            List<EamReportRepair> unReceivedOrderList = reportRepairService.pageList(maintenanceOrderPage, reportRepairQuery).getRecords();
 
            countMap.put("unExecInspectionOrderCount", 0);
            countMap.put("unExecMaintenanceOrderCount", 0);
            countMap.put("unExecRepairOrderCount", unReceivedOrderList.size());
        } else {
            countMap.put("unExecInspectionOrderCount", 0);
            countMap.put("unExecMaintenanceOrderCount", 0);
            countMap.put("unExecRepairOrderCount", 0);
        }
        return Result.OK(countMap);
    }
}