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);
|
}
|