Lius
2024-08-27 b617244a82d48a779fa5e5db010bf1981f137a8c
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
package org.jeecg.modules.screen.service.impl;
 
import org.jeecg.modules.mdc.entity.MdcEquipmentMonitor;
import org.jeecg.modules.screen.dto.MdcProductDayscheduleDto;
import org.jeecg.modules.screen.mapper.MdcSubLargeScreenMapper;
import org.jeecg.modules.screen.service.MdcSubLargeScreenService;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author Lius
 * @date 2024/8/26 15:01
 */
@Service
public class MdcSubLargeScreenServiceImpl implements MdcSubLargeScreenService {
 
    @Resource
    private MdcSubLargeScreenMapper mdcSubLargeScreenMapper;
 
    private final String today = LocalDate.now().toString();
 
    /**
     * 当日生产计划
     *
     * @param productionId
     * @return
     */
    @Override
    public List<MdcProductDayscheduleDto> todayProductionProgress(String productionId) {
        List<MdcProductDayscheduleDto> mdcProductDayscheduleDtos = new ArrayList<>();
        mdcProductDayscheduleDtos = mdcSubLargeScreenMapper.todayProductionProgress(productionId, today);
        if (mdcProductDayscheduleDtos != null && !mdcProductDayscheduleDtos.isEmpty()) {
            for (MdcProductDayscheduleDto mdcProductDayscheduleDto : mdcProductDayscheduleDtos) {
                if (mdcProductDayscheduleDto.getCompletionCount() != 0) {
                    mdcProductDayscheduleDto.setPassRate(new BigDecimal(mdcProductDayscheduleDto.getQualifiedCount()).divide(new BigDecimal(mdcProductDayscheduleDto.getCompletionCount()), 0, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
                }
            }
        }
        return mdcProductDayscheduleDtos;
    }
 
    /**
     * 设备实时状态
     *
     * @param productionId
     * @return
     */
    @Override
    public List<MdcEquipmentMonitor> equipmentStatus(String productionId) {
        List<MdcEquipmentMonitor> result = mdcSubLargeScreenMapper.checkStatusFromEquipmentIds(productionId);
        if (result != null && !result.isEmpty()) {
            for (MdcEquipmentMonitor mdcEquipmentMonitor : result) {
                if (mdcEquipmentMonitor.getOporation() != null) {
                    switch (mdcEquipmentMonitor.getOporation()) {
                        case 1:
                        case 2:
                            mdcEquipmentMonitor.setOporationDict("待机");
                            break;
                        case 3:
                            mdcEquipmentMonitor.setOporationDict("运行");
                            break;
                        case 22:
                            mdcEquipmentMonitor.setOporationDict("报警");
                            break;
                        default:
                            mdcEquipmentMonitor.setOporationDict("关机");
                            break;
                    }
                } else {
                    mdcEquipmentMonitor.setOporationDict("关机");
                    mdcEquipmentMonitor.setOporation(0);
                }
            }
        }
        return result;
    }
}