Commit 5533f4dc zshaohui

抛送出料口设备信息和心跳到中控

1 个父辈 68f6a5ae
......@@ -56,7 +56,7 @@ public class KafkaService {
/**
* 设备状态发送
* 料仓---设备状态
*/
@Scheduled(fixedRate = 1000 * 60 * 1)
public void setMachineStatus() {
......@@ -156,7 +156,7 @@ public class KafkaService {
/**
* 心跳数据发送
* 料仓--心跳数据
*/
@Scheduled(fixedRate = 1000 * 60 * 5)
public void setHeartbeat() {
......@@ -201,9 +201,103 @@ public class KafkaService {
/**
* MachineParameter发送
*/
@Scheduled(fixedRate = 1000 * 60 * 5)
public void setMachineParameter() {
log.info("MachineParameter开始发送");
List<String> machineIdList = getMachineIdList();
for (String machineId : machineIdList) {
List<String> storageIdList = new ArrayList<>();
int totalCount = 0;
int usedCount = 0;
int emptyCount = 0;
List<Storage> storageList = dataCache.getStorageByMachineId(machineId);
for (Storage storage : storageList) {
totalCount = totalCount + storage.getTotalSlots();
emptyCount = emptyCount + storage.getEmptySlots();
usedCount = usedCount + (storage.getTotalSlots() - storage.getEmptySlots());
storageIdList.add(storage.getId());
}
int todayInCount = getTodayInOutCount(storageIdList, OP.PUT_IN);
int todayOutCount = getTodayInOutCount(storageIdList, OP.CHECKOUT);
MachineParameter machineParameter = new MachineParameter();
String dateStr = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
machineParameter.setOccurrenceTime(dateStr);
machineParameter.setMachineID(machineId);
machineParameter.setContentType("F");
machineParameter.setMachineType("智能仓储位");
machineParameter.setSupplierID("NEOTEL");
machineParameter.setProgramName("");
machineParameter.setProgramVersion("");
machineParameter.setSerialNumber("");
machineParameter.setResult("");
machineParameter.setEmpNo("");
machineParameter.setClientIP("");
List<MachineParameterData> dataList = new ArrayList<>();
dataList.add(new MachineParameterData("totalCount", totalCount + ""));
dataList.add(new MachineParameterData("emptyCount", emptyCount + ""));
dataList.add(new MachineParameterData("usedCount", usedCount + ""));
dataList.add(new MachineParameterData("todayInCount", todayInCount + ""));
dataList.add(new MachineParameterData("todayOutCount", todayOutCount + ""));
machineParameter.setData(dataList);
String machineParameterStr = JSON.toJSONString(machineParameter);
//log.info("MachineParameter主题为:" + KafkaConfig.MACHINEPARAMETER_TOPIC + "内容为:" + machineParameterStr);
ListenableFuture future = kafkaTemplate.send(KafkaConfig.MACHINEPARAMETER_TOPIC, machineParameterStr);
//log.info("MachineParameter返回结果为:" + JSON.toJSONString(future));
}
log.info("MachineParameter结束发送");
}
//发送出料口信息
/**
* 发送出料口心跳
*/
@Scheduled(fixedRate = 1000 * 60 * 5)
public void setStorageHeartbeat() {
log.info("发送出料口心跳开始");
EquipStatusBean statusBean = EquipStatusUtil.getStatusBean(KafkaConfig.LINE_CID);
List<EquipStatus> statusList = statusBean.getStatusList();
if (statusList != null && !statusList.isEmpty()) {
for (EquipStatus equipStatus : statusList) {
int status = equipStatus.getStatus(); //状态
String module = equipStatus.getModule(); //出口
String currentStatus = "1"; //正常
if (2 == status || 3 == status) {
currentStatus = "3"; //故障
}
if (0 == status) {
currentStatus = "5"; //离线
}
if ("1".equals(currentStatus)) {
Heartbeat heartbeat = new Heartbeat();
String dateStr = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
heartbeat.setOccurrenceTime(dateStr);
heartbeat.setMachineID(module);
heartbeat.setTopicType(KafkaConfig.HEARTBEAT_TOPIC);
String statusStr = JSON.toJSONString(heartbeat);
log.info("出料口主题为:" + KafkaConfig.HEARTBEAT_TOPIC + "内容为:" + statusStr);
ListenableFuture future = kafkaTemplate.send(KafkaConfig.HEARTBEAT_TOPIC, statusStr);
log.info("出料口返回结果为:" + JSON.toJSONString(future));
}
}
}
log.info("发送出料口心跳结束");
}
/**
* 设备状态发送
*/
@Scheduled(fixedRate = 1000 * 60 * 1)
@Scheduled(fixedRate = 1000 * 60 * 5)
public void setStorageExportStatus() {
log.info("发送出料口信息开始");
......@@ -244,24 +338,24 @@ public class KafkaService {
machineStatus.setErrorMsg(equipMsg.getMsg());
machineStatus.setClientIP("");
String statusStr = JSON.toJSONString(machineStatus);
//log.info("出料口主题为:" + KafkaConfig.MACHINESTATUS_TOPIC + "内容为:" + statusStr);
log.info("出料口主题为:" + KafkaConfig.MACHINESTATUS_TOPIC + "内容为:" + statusStr);
ListenableFuture future = kafkaTemplate.send(KafkaConfig.MACHINESTATUS_TOPIC, statusStr);
//log.info("出料口返回结果为:" + JSON.toJSONString(future));
log.info("出料口返回结果为:" + JSON.toJSONString(future));
}
} else {
MachineStatus machineStatus = new MachineStatus();
String dateStr = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
machineStatus.setOccurrenceTime(dateStr);
machineStatus.setMachineID(StorageExportConfig.getMachineId(module));
machineStatus.setMachineID(module);
machineStatus.setTopicType(KafkaConfig.MACHINESTATUS_TOPIC);
machineStatus.setCurrentStatus(currentStatus);
machineStatus.setErrorCode("");
machineStatus.setErrorMsg("");
machineStatus.setClientIP("");
String statusStr = JSON.toJSONString(machineStatus);
//log.info("出料口主题为:" + KafkaConfig.MACHINESTATUS_TOPIC + "内容为:" + statusStr);
log.info("出料口主题为:" + KafkaConfig.MACHINESTATUS_TOPIC + "内容为:" + statusStr);
ListenableFuture future = kafkaTemplate.send(KafkaConfig.MACHINESTATUS_TOPIC, statusStr);
//log.info("出料口返回结果为:" + JSON.toJSONString(future));
log.info("出料口返回结果为:" + JSON.toJSONString(future));
}
}
}
......@@ -269,94 +363,10 @@ public class KafkaService {
}
/**
* 发送出料口心跳
*/
@Scheduled(fixedRate = 1000 * 60 * 5)
public void setStorageHeartbeat() {
log.info("发送出料口心跳开始");
EquipStatusBean statusBean = EquipStatusUtil.getStatusBean(KafkaConfig.LINE_CID);
List<EquipStatus> statusList = statusBean.getStatusList();
if (statusList != null && !statusList.isEmpty()) {
for (EquipStatus equipStatus : statusList) {
int status = equipStatus.getStatus(); //状态
String module = equipStatus.getModule(); //出口
String currentStatus = "1"; //正常
if (2 == status || 3 == status) {
currentStatus = "3"; //故障
}
if (0 == status) {
currentStatus = "5"; //离线
}
if ("1".equals(currentStatus)) {
Heartbeat heartbeat = new Heartbeat();
String dateStr = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
heartbeat.setOccurrenceTime(dateStr);
heartbeat.setMachineID(StorageExportConfig.getMachineId(module));
heartbeat.setTopicType(KafkaConfig.HEARTBEAT_TOPIC);
String statusStr = JSON.toJSONString(heartbeat);
//log.info("出料口主题为:" + KafkaConfig.HEARTBEAT_TOPIC + "内容为:" + statusStr);
ListenableFuture future = kafkaTemplate.send(KafkaConfig.HEARTBEAT_TOPIC, statusStr);
//log.info("出料口返回结果为:" + JSON.toJSONString(future));
}
}
}
log.info("发送出料口心跳结束");
}
/**
* MachineParameter发送
*/
@Scheduled(fixedRate = 1000 * 60 * 5)
public void setMachineParameter() {
log.info("MachineParameter开始发送");
List<String> machineIdList = getMachineIdList();
for (String machineId : machineIdList) {
List<String> storageIdList = new ArrayList<>();
int totalCount = 0;
int usedCount = 0;
int emptyCount = 0;
List<Storage> storageList = dataCache.getStorageByMachineId(machineId);
for (Storage storage : storageList) {
totalCount = totalCount + storage.getTotalSlots();
emptyCount = emptyCount + storage.getEmptySlots();
usedCount = usedCount + (storage.getTotalSlots() - storage.getEmptySlots());
storageIdList.add(storage.getId());
}
int todayInCount = getTodayInOutCount(storageIdList, OP.PUT_IN);
int todayOutCount = getTodayInOutCount(storageIdList, OP.CHECKOUT);
MachineParameter machineParameter = new MachineParameter();
String dateStr = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
machineParameter.setOccurrenceTime(dateStr);
machineParameter.setMachineID(machineId);
machineParameter.setContentType("F");
machineParameter.setMachineType("智能仓储位");
machineParameter.setSupplierID("NEOTEL");
machineParameter.setProgramName("");
machineParameter.setProgramVersion("");
machineParameter.setSerialNumber("");
machineParameter.setResult("");
machineParameter.setEmpNo("");
machineParameter.setClientIP("");
List<MachineParameterData> dataList = new ArrayList<>();
dataList.add(new MachineParameterData("totalCount", totalCount + ""));
dataList.add(new MachineParameterData("emptyCount", emptyCount + ""));
dataList.add(new MachineParameterData("usedCount", usedCount + ""));
dataList.add(new MachineParameterData("todayInCount", todayInCount + ""));
dataList.add(new MachineParameterData("todayOutCount", todayOutCount + ""));
machineParameter.setData(dataList);
String machineParameterStr = JSON.toJSONString(machineParameter);
//log.info("MachineParameter主题为:" + KafkaConfig.MACHINEPARAMETER_TOPIC + "内容为:" + machineParameterStr);
ListenableFuture future = kafkaTemplate.send(KafkaConfig.MACHINEPARAMETER_TOPIC, machineParameterStr);
//log.info("MachineParameter返回结果为:" + JSON.toJSONString(future));
}
log.info("MachineParameter结束发送");
}
public int getTodayInOutCount(List<String> storageIdList, int type) {
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!