|
|
|
@ -2,16 +2,34 @@ package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.mqtt;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.mqtt.MqttService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.apiservice.mqtt.PcnMqttClient;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesEquipmentLog;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesEquipmentVariable;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesEquipmentLogRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesEquipmentVariableRepository;
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
import org.eclipse.paho.client.mqttv3.MqttException;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class MqttServiceImpl implements MqttService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private PcnMqttClient myMqttClient;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesEquipmentVariableRepository mesEquipmentVariableRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesEquipmentLogRepository mesEquipmentLogRepository;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void addTopic(String topic) {
|
|
|
|
|
myMqttClient.subscribe(topic);
|
|
|
|
@ -57,4 +75,93 @@ public class MqttServiceImpl implements MqttService {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void testSend() {
|
|
|
|
|
/* MesEquipmentVariable equipmentVariable = mesEquipmentVariableRepository.getById(1813525136173084672l);
|
|
|
|
|
List<MesEquipmentVariable> array = new ArrayList<>();
|
|
|
|
|
for (int i = 0; i< 10000; i++) {
|
|
|
|
|
MesEquipmentVariable equipmentVariableNew = new MesEquipmentVariable();
|
|
|
|
|
BeanUtils.copyProperties(equipmentVariable, equipmentVariableNew);
|
|
|
|
|
//equipmentVariableNew.setId(equipmentVariable.getId()+1);
|
|
|
|
|
equipmentVariableNew.setId(null);
|
|
|
|
|
equipmentVariableNew.setTagAddress(equipmentVariableNew.getTagAddress() +i);
|
|
|
|
|
equipmentVariableNew.setTagName(equipmentVariableNew.getTagName() +i);
|
|
|
|
|
ConvertBean.serviceModelInitialize(equipmentVariableNew,"test");
|
|
|
|
|
array.add(equipmentVariableNew);
|
|
|
|
|
}
|
|
|
|
|
List<List<MesEquipmentVariable>> lists = Lists.partition(array, 100);
|
|
|
|
|
for (List<MesEquipmentVariable> list : lists) {
|
|
|
|
|
mesEquipmentVariableRepository.saveAll(list);
|
|
|
|
|
}*/
|
|
|
|
|
DdlPackBean packBean = new DdlPackBean();
|
|
|
|
|
DdlPreparedPack.getNumEqualPack(300, "equipId", packBean);
|
|
|
|
|
|
|
|
|
|
List<MesEquipmentLog> arrayEquip = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
List<MesEquipmentVariable> equipmentVariables = mesEquipmentVariableRepository.findByHqlWhere(packBean);
|
|
|
|
|
for (MesEquipmentVariable variable : equipmentVariables) {
|
|
|
|
|
MesEquipmentLog mesEquipmentLogNew = new MesEquipmentLog();
|
|
|
|
|
|
|
|
|
|
mesEquipmentLogNew.setEquipVariableName(variable.getTagAddress());
|
|
|
|
|
mesEquipmentLogNew.setEquipVariableId(variable.getId());
|
|
|
|
|
mesEquipmentLogNew.setEquipId(variable.getEquipId());
|
|
|
|
|
mesEquipmentLogNew.setEquipmentCode(variable.getEquipmentCode());
|
|
|
|
|
mesEquipmentLogNew.setEquipVariableStatus(0);
|
|
|
|
|
mesEquipmentLogNew.setEquipVariableValue("1");
|
|
|
|
|
arrayEquip.add(mesEquipmentLogNew);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
List<List<MesEquipmentLog>> lists1 = Lists.partition(arrayEquip, 100);
|
|
|
|
|
for (List<MesEquipmentLog> list : lists1) {
|
|
|
|
|
mesEquipmentLogRepository.saveAll(list);
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
DdlPackBean packBean = new DdlPackBean();
|
|
|
|
|
DdlPreparedPack.getNumEqualPack(1813525136173084672l, "id", packBean);
|
|
|
|
|
DdlPreparedPack.getNumEqualPack(300, "equipId", packBean);
|
|
|
|
|
|
|
|
|
|
MesEquipmentLog mesEquipmentLog = mesEquipmentLogRepository.getByProperty(packBean);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<MesEquipmentLog> arrayEquip = new ArrayList<>();
|
|
|
|
|
for (int i = 0; i< 10000; i++) {
|
|
|
|
|
Long id = 1813525136173084672l;
|
|
|
|
|
MesEquipmentLog mesEquipmentLogNew = new MesEquipmentLog();
|
|
|
|
|
BeanUtils.copyProperties(mesEquipmentLog, mesEquipmentLogNew);
|
|
|
|
|
mesEquipmentLogNew.setId(mesEquipmentLog.getId()+1);
|
|
|
|
|
mesEquipmentLogNew.setEquipVariableId(id +i);
|
|
|
|
|
mesEquipmentLogNew.setEquipVariableDesc(mesEquipmentLog.getEquipVariableValue() +i);
|
|
|
|
|
mesEquipmentLogNew.setEquipVariableDesc(mesEquipmentLog.getEquipVariableValue() +i);
|
|
|
|
|
|
|
|
|
|
arrayEquip.add(mesEquipmentLogNew);
|
|
|
|
|
}
|
|
|
|
|
List<List<MesEquipmentLog>> lists1 = Lists.partition(arrayEquip, 100);
|
|
|
|
|
for (List<MesEquipmentLog> list : lists1) {
|
|
|
|
|
mesEquipmentLogRepository.saveAll(list);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
String aa = "[{\"PTCode\":\"156\",\"key\":\"DB1000,X344.0\",\"tagAddress\":\"DB1000.344.0\",\"value\":false,\"time\":\"2024-07-17 16:18:13\"}]"
|
|
|
|
|
|
|
|
|
|
myMqttClient.publish(msgJson, topic);*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void testSendList() {
|
|
|
|
|
String start ="[";
|
|
|
|
|
for (int i=0; i<100 ; i++) {
|
|
|
|
|
String aa = "{\"PTCode\":\"156\",\"key\":\"aa " + i +
|
|
|
|
|
"\",\"value\":2,\"time\":\"2024-07-17 16:18:13\"}";
|
|
|
|
|
|
|
|
|
|
start += aa;
|
|
|
|
|
}
|
|
|
|
|
String end ="]";
|
|
|
|
|
start += end;
|
|
|
|
|
|
|
|
|
|
myMqttClient.publish(start, "ABC");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|