y_ys79
2024-01-05 e5840972b6b17ec03bfc1069a9cacfe0cef189c6
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
package com.qianwen.mdc.controller;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qianwen.mdc.mapper.MdcMachineAccountMapper;
import com.qianwen.mdc.mapper.MachineMapper;
import com.qianwen.mdc.mapper.MdcMachineTypesMapper;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
/**
 * @author: tianmingqiang
 * @date: 2019/10/13 22:15
 * @description: MdcMachineController
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/status", method = RequestMethod.POST)
public class MdcMachineStatusController {
    @RequestMapping(value = "/monitor", method = RequestMethod.POST)
    public JSONObject statusMonitor() {
        JSONObject jsonResult = new JSONObject();
        jsonResult.put("result", "SUCCESS");
 
        List<Map<String, Object>> machineStatuses = mdcMachineMapper.selectStatusMonitor();
        JSONArray jsonArray = new JSONArray();
        jsonResult.put("statusList", jsonArray);
        int statusSize = machineStatuses.size();
        if (statusSize > 0) {
            int runCount = 0;
            int idleCount = 0;
            int alarmCount = 0;
            int stopCount = 0;
            int twoShift = 0;
            int twoShiftTotal = 0;
            int threeShift = 0;
            int threeShiftTotal = 0;
            List<Integer> typesIdList = new ArrayList<>();
            for (Map<String, Object> machineStatus : machineStatuses) {
                String name = (String) machineStatus.get("name");
                String cncSystem = (String) machineStatus.get("cncSystem");
                String status = (String) machineStatus.get("status");
                Integer position = (Integer) machineStatus.get("position");
                String progName = (String) machineStatus.get("progName");
                String cycleCount = (String) machineStatus.get("cycleCount");
                String cycleTime = (String) machineStatus.get("cycleTime");
                Integer feedRate = (Integer) machineStatus.get("feedRate");
                String section = (String) machineStatus.get("section");
                if (feedRate == null) {
                    feedRate = 0;
                }
                Integer spindleSpeed = (Integer) machineStatus.get("spindleSpeed");
                if (spindleSpeed == null) {
                    spindleSpeed = 0;
                }
                Integer spindleOverride = (Integer) machineStatus.get("spindleOverride");
                if (spindleOverride == null) {
                    spindleOverride = 0;
                }
                Integer shiftType = (Integer) machineStatus.get("shiftType");
 
                Integer typesId = (Integer) machineStatus.get("typesId");
                String mdcType = (String) machineStatus.get("mdcType");
                BigDecimal mdcRate = (BigDecimal) machineStatus.get("mdcRate");
                BigDecimal mdcTypeRate = (BigDecimal) machineStatus.get("mdcTypeRate");
//                List<String> machineTypes = mdcMachineAccountMapper.selectSameTypes(typesId, name);
//                MdcMachineTypes machineTypes = mdcMachineTypesMapper.selectByPrimaryKey(typesId);
 
                JSONObject item = new JSONObject();
                jsonArray.add(item);
                item.put("name", name);
                item.put("cncSystem", cncSystem);
                item.put("status", status);
                item.put("position", String.valueOf(position));
                item.put("progName", progName);
                item.put("cycleCount", cycleCount);
                item.put("cycleTime", cycleTime);
                item.put("feedRate", String.valueOf(feedRate));
                item.put("spindleSpeed", String.valueOf(spindleSpeed));
                item.put("spindleOverride", String.valueOf(spindleOverride));
                item.put("section", section);
//                item.put("mdcType", machineTypes.toString());
                item.put("mdcType", mdcType);
                if (mdcRate == null) {
                    item.put("mdcRate", "0.00");
                } else {
                    item.put("mdcRate", String.format("%5.2f", mdcRate.floatValue()));
                }
                if (mdcTypeRate == null) {
                    item.put("mdcTypeRate", "0.00");
                } else {
                    item.put("mdcTypeRate", String.format("%5.2f", mdcTypeRate.floatValue()));
                }
//                item.put("mdcTypeRate", Float.parseFloat(cycleTime) * 100 / (24 * 3600));
//                item.put("mdcRate", Float.parseFloat(cycleTime) * 100 / (24 * 3600));
 
                switch (shiftType) {
                    case 1:
                        break;
                    case 2:
                        twoShiftTotal++;
                        break;
                    case 3:
                        twoShiftTotal++;
                        threeShiftTotal++;
                        break;
                    default:
                        break;
                }
                switch (status) {
                    case "RUN":
                        runCount++;
                        if (shiftType == 2) {
                            twoShift++;
                        } else if (shiftType == 3) {
                            twoShift++;
                            threeShift++;
                        }
                        break;
                    case "IDLE":
                        idleCount++;
                        if (shiftType == 2) {
                            twoShift++;
                        } else if (shiftType == 3) {
                            twoShift++;
                            threeShift++;
                        }
                        break;
                    case "ALARM":
                        alarmCount++;
                        if (shiftType == 2) {
                            twoShift++;
                        } else if (shiftType == 3) {
                            twoShift++;
                            threeShift++;
                        }
                        break;
                    case "STOP":
                        stopCount++;
                        break;
                    default:
                        break;
                }
            }
 
            float bootRate = 1 - ((float) stopCount / statusSize);
            jsonResult.put("bootRate", String.format("%5.2f", bootRate * 100));
 
            float alarmRate = (float) alarmCount / statusSize;
            jsonResult.put("alarmRate", String.format("%5.2f", alarmRate * 100));
 
            float cutRate = (float) runCount / statusSize;
            jsonResult.put("cutRate", String.format("%5.2f", cutRate * 100));
 
            float twoShiftRate = 0.00f;
            if (twoShiftTotal != 0) {
                twoShiftRate = (float) twoShift/twoShiftTotal;
            }
            jsonResult.put("twoShiftRate", String.format("%5.2f", twoShiftRate * 100));
 
            float threeShiftRate = 0.00f;
            if (threeShiftTotal != 0) {
                threeShiftRate = (float) threeShift/threeShiftTotal;
            }
            jsonResult.put("threeShiftRate", String.format("%5.2f", threeShiftRate * 100));
        } else {
            jsonResult.put("bootRate", "0.00");
            jsonResult.put("alarmRate", "0.00");
            jsonResult.put("cutRate", "0.00");
            jsonResult.put("twoShiftRate", "0.00");
            jsonResult.put("threeShiftRate", "0.00");
        }
 
        return jsonResult;
    }
 
    @Autowired
    private MachineMapper mdcMachineMapper;
    @Autowired
    private MdcMachineAccountMapper mdcMachineAccountMapper;
    @Autowired
    private MdcMachineTypesMapper mdcMachineTypesMapper;
 
    public static final Logger logger = LoggerFactory.getLogger(MdcMachineStatusController.class);
}