hyingbo
6 天以前 e935889261ef38c8eaef31e54cbfc466d63d2ef4
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
package org.jeecg.modules.mdc.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.modules.mdc.constant.MdcConstant;
import org.jeecg.modules.mdc.dto.MdcEquipmentDto;
import org.jeecg.modules.mdc.entity.*;
import org.jeecg.modules.mdc.mapper.MdcHomeMapper;
import org.jeecg.modules.mdc.service.*;
import org.jeecg.modules.mdc.util.DateUtils;
import org.jeecg.modules.mdc.vo.*;
import org.jeecg.modules.system.entity.MdcProduction;
import org.jeecg.modules.system.service.IMdcProductionService;
import org.jeecg.modules.system.service.ISysDictService;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.*;
 
/**
 * @author Lius
 * @date 2024/3/14 9:52
 */
@Service
public class IMdcHomeServiceImpl implements IMdcHomeService {
 
    @Resource
    private IMdcEquipmentService mdcEquipmentService;
 
    @Resource
    private IEquipmentService equipmentService;
 
    @Resource
    private ISysDictService sysDictService;
 
    @Resource
    private IEquipmentWorkLineService equipmentWorkLineService;
 
    @Resource
    private MdcHomeMapper mdcHomeMapper;
 
    @Resource
    private IMdcProductionService mdcProductionService;
 
    @Resource
    private IEquipmentLogService equipmentLogService;
 
    @Resource
    private IMdcFeedbackService mdcFeedbackService;
 
    /**
     * 设备运行状态统计
     */
    @Override
    public List<MdcCommonVo> getEquipmentStatusStatistics(String userId, String key) {
        List<MdcCommonVo> result = new ArrayList<>();
        MdcCommonVo mdcCommonVo1 = new MdcCommonVo();
        mdcCommonVo1.setName("关机");
        mdcCommonVo1.setValue("0");
        result.add(mdcCommonVo1);
        MdcCommonVo mdcCommonVo2 = new MdcCommonVo();
        mdcCommonVo2.setName("报警");
        mdcCommonVo2.setValue("0");
        result.add(mdcCommonVo2);
        MdcCommonVo mdcCommonVo3 = new MdcCommonVo();
        mdcCommonVo3.setName("待机");
        mdcCommonVo3.setValue("0");
        result.add(mdcCommonVo3);
        MdcCommonVo mdcCommonVo4 = new MdcCommonVo();
        mdcCommonVo4.setName("运行");
        mdcCommonVo4.setValue("0");
        result.add(mdcCommonVo4);
        MdcEquipmentStatusVo mdcEquipmentStatusVo = new MdcEquipmentStatusVo();
        if (StringUtils.isBlank(key)) {
            return result;
        }
        List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, key);
        if (equipmentIdList == null || equipmentIdList.isEmpty()) {
            return result;
        }
//        List<EquipmentLog> logList = equipmentLogService.getEquipmentStatusList(equipmentIdList);
        List<Equipment> equipmentList = equipmentService.list(new LambdaQueryWrapper<Equipment>().in(Equipment::getEquipmentid, equipmentIdList));
        if (equipmentList != null && !equipmentList.isEmpty()) {
            for (Equipment equipment : equipmentList) {
                if (equipment.getOporation() != null) {
                    switch (equipment.getOporation()) {
                        case 1:
                        case 2:
                            mdcEquipmentStatusVo.setWaitCount(mdcEquipmentStatusVo.getWaitCount() + 1);
                            break;
                        case 3:
                            mdcEquipmentStatusVo.setRunCount(mdcEquipmentStatusVo.getRunCount() + 1);
                            break;
                        case 22:
                            mdcEquipmentStatusVo.setAlarmCount(mdcEquipmentStatusVo.getAlarmCount() + 1);
                            break;
                        default:
                            mdcEquipmentStatusVo.setCloseCount(mdcEquipmentStatusVo.getCloseCount() + 1);
                            break;
                    }
                } else {
                    mdcEquipmentStatusVo.setCloseCount(mdcEquipmentStatusVo.getCloseCount() + 1);
                }
            }
        }
        result.clear();
        MdcCommonVo mdcCommonVo5 = new MdcCommonVo();
        mdcCommonVo5.setName("关机");
        mdcCommonVo5.setValue(mdcEquipmentStatusVo.getCloseCount().toString());
        result.add(mdcCommonVo5);
        MdcCommonVo mdcCommonVo6 = new MdcCommonVo();
        mdcCommonVo6.setName("报警");
        mdcCommonVo6.setValue(mdcEquipmentStatusVo.getAlarmCount().toString());
        result.add(mdcCommonVo6);
        MdcCommonVo mdcCommonVo7 = new MdcCommonVo();
        mdcCommonVo7.setName("待机");
        mdcCommonVo7.setValue(mdcEquipmentStatusVo.getWaitCount().toString());
        result.add(mdcCommonVo7);
        MdcCommonVo mdcCommonVo8 = new MdcCommonVo();
        mdcCommonVo8.setName("运行");
        mdcCommonVo8.setValue(mdcEquipmentStatusVo.getRunCount().toString());
        result.add(mdcCommonVo8);
        return result;
    }
 
    /**
     * 设备利用率统计
     */
    @Override
    public List<MdcCommonVo> getEquipmentUtilizationStatistics(String userId, String key) {
        List<MdcCommonVo> result = new ArrayList<>();
        //获取公司或厂区二级信息
        List<MdcProduction> mdcProductionList = mdcHomeMapper.getProductionByPid(userId, key);
        if (mdcProductionList != null && !mdcProductionList.isEmpty()) {
            for (MdcProduction mdcProduction : mdcProductionList) {
                MdcCommonVo mdcCommonVo = new MdcCommonVo();
                mdcCommonVo.setName(mdcProduction.getProductionName());
                mdcCommonVo.setProductionCode(mdcProduction.getProductionCode());
                mdcCommonVo.setProductionId(mdcProduction.getId());
                //获取此层级下设备
                List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcProduction.getId());
                if (equipmentIdList == null || equipmentIdList.isEmpty()) {
                    mdcCommonVo.setValue("0");
                } else {
                    String date = DateUtils.format(DateUtils.toDate(LocalDate.now().plusDays(-1).toString(), DateUtils.STR_DATE), DateUtils.STRDATE);
                    BigDecimal processCount = mdcHomeMapper.getProcessCount(equipmentIdList, date);
                    if (processCount == null || processCount.compareTo(BigDecimal.ZERO) == 0) {
                        mdcCommonVo.setValue("0");
                    } else {
                        mdcCommonVo.setValue(processCount.divide(new BigDecimal("86400").multiply(new BigDecimal(equipmentIdList.size())), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP).toString());
                    }
                }
                result.add(mdcCommonVo);
            }
        }
        if (!result.isEmpty()) {
            result.sort(Comparator.comparing(MdcCommonVo::getValue).reversed());
        }
        return result;
    }
 
    /**
     * 设备OEE统计
     */
    @Override
    public List<MdcCommonVo> getEquipmentOeeStatistics(String userId, String key) {
        List<MdcCommonVo> result = new ArrayList<>();
        //获取公司或厂区二级信息
        List<MdcProduction> mdcProductionList = mdcHomeMapper.getProductionByPid(userId, key);
        if (mdcProductionList != null && !mdcProductionList.isEmpty()) {
            for (MdcProduction mdcProduction : mdcProductionList) {
                MdcCommonVo mdcCommonVo = new MdcCommonVo();
                mdcCommonVo.setName(mdcProduction.getProductionName());
                mdcCommonVo.setProductionCode(mdcProduction.getProductionCode());
                mdcCommonVo.setProductionId(mdcProduction.getId());
                //获取此层级下设备
                List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcProduction.getId());
                if (equipmentIdList == null || equipmentIdList.isEmpty()) {
                    mdcCommonVo.setValue("0");
                } else {
                    String date = DateUtils.format(DateUtils.toDate(LocalDate.now().plusMonths(-1).toString(), DateUtils.STR_DATE), DateUtils.STR_YEAR_MONTH);
                    BigDecimal oee = mdcHomeMapper.getOeeByDate(equipmentIdList, date);
                    if (oee == null || oee.compareTo(BigDecimal.ZERO) == 0) {
                        mdcCommonVo.setValue("0");
                    } else {
                        mdcCommonVo.setValue(oee.divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP).toString());
                    }
                }
                result.add(mdcCommonVo);
            }
        }
        return result;
    }
 
    /**
     * 设备OEE和利用率统计柱状图
     */
    @Override
    public Map<String, Object> getEquipmentMonthStatistics(String userId, String key) {
        List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, key);
        Map<String, Object> result = new HashMap<>();
        Date end = DateUtils.toDate(LocalDate.now().plusMonths(-1).toString(), DateUtils.STR_DATE);
        Date start = DateUtils.toDate(LocalDate.now().plusMonths(-12).toString(), DateUtils.STR_DATE);
        List<String> monthBetween = DateUtils.getMonthBetween(start, end);
        List<String> dateList = new ArrayList<>();
        List<MdcCommonVo> utilizationList = new ArrayList<>();
        List<MdcCommonVo> oeeList = new ArrayList<>();
        for (String month : monthBetween) {
            //日期集合
            String name = month.substring(month.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "月";
            dateList.add(name);
            //利用率和oee
            MdcCommonVo mdcCommonUtilizationVo = new MdcCommonVo();
            mdcCommonUtilizationVo.setName(name);
            MdcCommonVo mdcCommonOeeVo = new MdcCommonVo();
            mdcCommonOeeVo.setName(name);
            if (equipmentIdList == null || equipmentIdList.isEmpty()) {
                mdcCommonUtilizationVo.setValue("0");
                mdcCommonOeeVo.setValue("0");
            } else {
                //利用率
                Map<String, Object> resultMap = mdcHomeMapper.getUtilizationByMonth(equipmentIdList, month.replace("-", ""));
                if (resultMap != null && resultMap.get("processLong") != null) {
                    BigDecimal processLong = BigDecimal.valueOf((Double) resultMap.get("processLong"));
                    BigDecimal processDay = new BigDecimal((Integer) resultMap.get("processDay"));
                    if (processLong.compareTo(BigDecimal.ZERO) == 0) {
                        mdcCommonUtilizationVo.setValue("0");
                    } else {
                        mdcCommonUtilizationVo.setValue(processLong.divide(processDay.multiply(new BigDecimal("86400")), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP).toString());
                    }
                } else {
                    mdcCommonUtilizationVo.setValue("0");
                }
 
                //OEE
                BigDecimal oee = mdcHomeMapper.getOeeByDate(equipmentIdList, month);
                if (oee == null || oee.compareTo(BigDecimal.ZERO) == 0) {
                    mdcCommonOeeVo.setValue("0");
                } else {
                    mdcCommonOeeVo.setValue(oee.divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP).toString());
                }
            }
            utilizationList.add(mdcCommonUtilizationVo);
            oeeList.add(mdcCommonOeeVo);
        }
        result.put("dateList", dateList);
        result.put("utilizationList", utilizationList);
        result.put("oeeList", oeeList);
        return result;
    }
 
    /**
     * 工段级前七天利用率折线图
     */
    @Override
    public Map<String, Object> getEquipmentDayUtilizationStatistics(String userId, String key) {
        Map<String, Object> result = new HashMap<>();
        List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, key);
        //获取前七天日期集合
        String start = DateUtils.format(DateUtils.toDate(LocalDate.now().plusDays(-7).toString(), DateUtils.STR_DATE), DateUtils.STRDATE);
        String end = DateUtils.format(DateUtils.toDate(LocalDate.now().plusDays(-1).toString(), DateUtils.STR_DATE), DateUtils.STRDATE);
        if (equipmentIdList != null && !equipmentIdList.isEmpty()) {
            List<MdcEquipment> mdcEquipmentList = mdcEquipmentService.list(new LambdaQueryWrapper<MdcEquipment>().in(MdcEquipment::getEquipmentId, equipmentIdList));
            result.put("mdcEquipmentList", mdcEquipmentList);
            List<MdcEquipmentStatisticalInfo> mdcEquipmentStatisticalInfoList = mdcHomeMapper.getEquipmentSevenUtilizationStatistics(equipmentIdList, start, end);
            List<EquipmentDayUtilizationVo> dataList = new ArrayList<>();
            if (mdcEquipmentStatisticalInfoList != null && !mdcEquipmentStatisticalInfoList.isEmpty()) {
                for (MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo : mdcEquipmentStatisticalInfoList) {
                    EquipmentDayUtilizationVo equipmentDayUtilizationVo = new EquipmentDayUtilizationVo();
                    equipmentDayUtilizationVo.setEquipmentId(mdcEquipmentStatisticalInfo.getEquipmentId());
                    equipmentDayUtilizationVo.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).divide(new BigDecimal(mdcEquipmentStatisticalInfoList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP));
                    if (BigDecimal.ZERO.compareTo(mdcEquipmentStatisticalInfo.getOpenLong()) == -1) {
                        equipmentDayUtilizationVo.setOpenRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(mdcEquipmentStatisticalInfo.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
                        equipmentDayUtilizationVo.setStartRate(mdcEquipmentStatisticalInfo.getOpenLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).divide(new BigDecimal(mdcEquipmentStatisticalInfoList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP));
                    }
                    dataList.add(equipmentDayUtilizationVo);
                }
            }
            result.put("dataList", dataList);
        }
        /*List<String> dayBetween = DateUtils.getDatesStringList2(start, end);
        List<String> dateList = new ArrayList<>();
        List<EquipmentDayUtilizationVo> dataList = new ArrayList<>();
        for (String date : dayBetween) {
            EquipmentDayUtilizationVo equipmentDayUtilizationVo = new EquipmentDayUtilizationVo();
            String item = date.substring(4);
            if (item.startsWith("0")) {
                item = item.substring(1);
                String sub = item.substring(1);
                if (sub.startsWith("0")) {
                    item = item.substring(0, 1) + "月" + sub.substring(1) + "日";
                } else {
                    item = item.substring(0, 1) + "月" + item.substring(1) + "日";
                }
            } else {
                String sub = item.substring(2);
                if (sub.startsWith("0")) {
                    item = item.substring(0, 2) + "月" + sub.substring(2) + "日";
                } else {
                    item = item.substring(0, 2) + "月" + item.substring(2) + "日";
                }
            }
            dateList.add(item);
            equipmentDayUtilizationVo.setDate(item);
            if (equipmentIdList != null && !equipmentIdList.isEmpty()) {
                //获取前七天利用率数据
                List<MdcEquipmentStatisticalInfo> mdcEquipmentStatisticalInfos = mdcHomeMapper.getEquipmentDayUtilizationStatistics(equipmentIdList, dayBetween);
                if (mdcEquipmentStatisticalInfos != null && !mdcEquipmentStatisticalInfos.isEmpty()) {
                    for (MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo : mdcEquipmentStatisticalInfos) {
                        if (mdcEquipmentStatisticalInfo.getTheDate().equals(date)) {
                            equipmentDayUtilizationVo.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP));
                            if (BigDecimal.ZERO.compareTo(mdcEquipmentStatisticalInfo.getOpenLong()) == -1) {
                                equipmentDayUtilizationVo.setOpenRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(mdcEquipmentStatisticalInfo.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
                                equipmentDayUtilizationVo.setStartRate(mdcEquipmentStatisticalInfo.getOpenLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP));
                            }
                        }
                    }
                } else {
                    dataList.add(equipmentDayUtilizationVo);
                }
            } else {
                dataList.add(equipmentDayUtilizationVo);
            }
        }
        result.put("dateList", dateList);
        result.put("dataList", dataList);*/
        return result;
    }
 
    /**
     * 查询设备上月OEE
     */
    @Override
    public List<MdcOverallEquipmentEfficiency> getEquipmentOEEMonthStatistics(String userId, String key) {
        List<MdcOverallEquipmentEfficiency> result = new ArrayList<>();
        List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, key);
        if (equipmentIdList != null && !equipmentIdList.isEmpty()) {
            String validDate = DateUtils.format(DateUtils.toDate(LocalDate.now().plusMonths(-1).toString(), DateUtils.STR_DATE), DateUtils.STR_YEAR_MONTH);
            result = mdcHomeMapper.getEquipmentOEEMonthStatistics(validDate, equipmentIdList);
        }
        return result;
    }
 
    /**
     * 工段级设备效率
     */
    @Override
    public MdcHomeEfficiencyVo getEquipmentEfficiencyStatistics(String userId, String key) {
        MdcHomeEfficiencyVo result = new MdcHomeEfficiencyVo();
        result.setProductionId(key);
        MdcProduction mdcProduction = mdcProductionService.getById(key);
        result.setProductionName(mdcProduction.getProductionName());
        List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, key);
        if (equipmentIdList != null && !equipmentIdList.isEmpty()) {
            // 获取利用率数据
            String date = DateUtils.format(DateUtils.toDate(LocalDate.now().plusDays(-1).toString(), DateUtils.STR_DATE), DateUtils.STRDATE);
            MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo = mdcHomeMapper.getUtilizationByDay(equipmentIdList, date);
            if (mdcEquipmentStatisticalInfo != null) {
                result.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP));
                if (BigDecimal.ZERO.compareTo(mdcEquipmentStatisticalInfo.getOpenLong()) == -1) {
                    result.setOpenRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(mdcEquipmentStatisticalInfo.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
                    result.setStartRate(mdcEquipmentStatisticalInfo.getOpenLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP));
                }
            }
            //获取OEE数据
            String month = DateUtils.format(DateUtils.toDate(LocalDate.now().plusMonths(-1).toString(), DateUtils.STR_DATE), DateUtils.STR_YEAR_MONTH);
            BigDecimal oee = mdcHomeMapper.getOeeByDate(equipmentIdList, month);
            if (oee == null || oee.compareTo(BigDecimal.ZERO) == 0) {
                result.setOverallEquipmentEfficiency(BigDecimal.ZERO);
            } else {
                result.setOverallEquipmentEfficiency(oee.divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
            }
        }
        return result;
    }
 
    /**
     * 设备级效率统计
     */
    @Override
    public MdcHomeEfficiencyVo getEquipmentLevelEfficiencyStatistics(String equipmentId) {
        MdcEquipment mdcEquipment = mdcEquipmentService.getOne(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, equipmentId));
        if (mdcEquipment == null) {
            return null;
        }
        MdcHomeEfficiencyVo result = new MdcHomeEfficiencyVo();
        String date = DateUtils.format(DateUtils.toDate(LocalDate.now().plusDays(-1).toString(), DateUtils.STR_DATE), DateUtils.STRDATE);
        MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo = mdcHomeMapper.getUtilizationByDay(Arrays.asList(equipmentId.split(",")), date);
        if (mdcEquipmentStatisticalInfo != null) {
            result.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP));
            if (BigDecimal.ZERO.compareTo(mdcEquipmentStatisticalInfo.getOpenLong()) == -1) {
                result.setOpenRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(mdcEquipmentStatisticalInfo.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
                result.setStartRate(mdcEquipmentStatisticalInfo.getOpenLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP));
            }
        }
        //获取OEE数据
        String month = DateUtils.format(DateUtils.toDate(LocalDate.now().plusMonths(-1).toString(), DateUtils.STR_DATE), DateUtils.STR_YEAR_MONTH);
        BigDecimal oee = mdcHomeMapper.getOeeByDate(Arrays.asList(equipmentId.split(",")), month);
        if (oee == null || oee.compareTo(BigDecimal.ZERO) == 0) {
            result.setOverallEquipmentEfficiency(BigDecimal.ZERO);
        } else {
            result.setOverallEquipmentEfficiency(oee.multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
        }
        return result;
    }
 
    /**
     * 设备级整年度利用率
     */
    @Override
    public Map<String, Object> getEquipmentAnnualEfficiencyStatistics(String equipmentId) {
        MdcEquipment mdcEquipment = mdcEquipmentService.getOne(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, equipmentId));
        if (mdcEquipment == null) {
            return null;
        }
        Map<String, Object> result = new HashMap<>();
        Date end = DateUtils.toDate(LocalDate.now().plusMonths(-1).toString(), DateUtils.STR_DATE);
        Date start = DateUtils.toDate(LocalDate.now().plusMonths(-12).toString(), DateUtils.STR_DATE);
        List<String> monthBetween = DateUtils.getMonthBetween(start, end);
        List<String> dateList = new ArrayList<>();
        List<MdcHomeEquipmentVo> dataList = new ArrayList<>();
        for (String month : monthBetween) {
            String name = month.substring(month.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "月";
            dateList.add(name);
            //利用率和oee
            MdcHomeEquipmentVo mdcHomeEquipmentVo = new MdcHomeEquipmentVo();
            mdcHomeEquipmentVo.setMonth(name);
            //利用率
            Map<String, Object> resultMap = mdcHomeMapper.getUtilizationByMonth(Arrays.asList(equipmentId.split(",")), month.replace("-", ""));
            if (resultMap != null && resultMap.get("processLong") != null) {
                BigDecimal processLong = BigDecimal.valueOf((Double) resultMap.get("processLong"));
                BigDecimal openLong = BigDecimal.valueOf((Double) resultMap.get("openLong"));
                BigDecimal processDay = new BigDecimal((Integer) resultMap.get("processDay"));
                if (BigDecimal.ZERO.compareTo(processLong) == -1) {
                    mdcHomeEquipmentVo.setUtilizationRate(processLong.divide(processDay.multiply(new BigDecimal("86400")), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
                    if (BigDecimal.ZERO.compareTo(openLong) == -1) {
                        mdcHomeEquipmentVo.setStartRate(openLong.divide(new BigDecimal("86400"), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP));
                        mdcHomeEquipmentVo.setOpenRate(processDay.divide(openLong, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
                    }
                }
            }
 
            //OEE
            BigDecimal oee = mdcHomeMapper.getOeeByDate(Arrays.asList(equipmentId.split(",")), month);
            if (oee != null && !(oee.compareTo(BigDecimal.ZERO) == 0)) {
                mdcHomeEquipmentVo.setOverallEquipmentEfficiency(oee.multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
            }
            dataList.add(mdcHomeEquipmentVo);
        }
        result.put("dateList", dateList);
        result.put("dataList", dataList);
        return result;
    }
 
    /**
     * 设备级设备列表
     */
    @Override
    public List<MdcEquipment> getEquipmentList(String key) {
        return mdcHomeMapper.getEquipmentList(key);
    }
 
    @Override
    public MdcEquipmentDto getEquipmentDetails(String equipmentId) {
        MdcEquipment mdcEquipment = mdcEquipmentService.getOne(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, equipmentId));
        List<DictModel> dictModelList = sysDictService.queryEnableDictItemsByCode(MdcConstant.SERIA_TYPE);
        if (dictModelList != null && !dictModelList.isEmpty()) {
            for (DictModel dictModel : dictModelList) {
                if (dictModel.getValue().equals(mdcEquipment.getDriveType())) {
                    return null;
                }
            }
        }
        String saveTableName = mdcEquipment.getSaveTableName();
        MdcEquipmentDto dto = equipmentWorkLineService.getMacingDataList(saveTableName);
        if (dto != null) {
            if ("LSV2".equals(mdcEquipment.getDriveType())) {
                dto.setSpindlebeilv(dto.getSFeed());
                dto.setFeedbeilv(dto.getFFeed());
                dto.setRapidfeed(dto.getRapidfeed());
                dto.setNCVersion(dto.getNCVersion());
                dto.setTNCVersion(dto.getTNCVersion());
                dto.setOPTVersion(dto.getOPTVersion());
                dto.setPLCVersion(dto.getPLCVersion());
            }
            // 查询设备状态
            EquipmentLog equipmentLog = equipmentLogService.selectEquipmentOporation(mdcEquipment.getEquipmentId());
            Integer oporation = equipmentLog.getOporation();
            if (oporation == 22) {
                dto.setALRMstate(equipmentLog.getAlarm());
            } else {
                dto.setALRMstate("无");
            }
        } else {
            return null;
        }
        return dto;
    }
 
    @Override
    public List<MdcFeedback> getFeedbackList(String key) {
        return mdcFeedbackService.getFeedbackList(key);
    }
}