202209061653

This commit is contained in:
GS-HQY 2022-09-06 16:53:14 +08:00
parent 1dae83ea2e
commit fd65318629
16 changed files with 121948 additions and 21 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -45,7 +45,7 @@ public class ConnectDTO {
public int status; public int status;
public Boolean isUpload; public int isUpload;
List<String> items; List<String> items;
@ -71,7 +71,7 @@ public class ConnectDTO {
this.device = connectionEntity.getDeviceId(); this.device = connectionEntity.getDeviceId();
this.mode = connectionEntity.getConnectionProtocol(); this.mode = connectionEntity.getConnectionProtocol();
this.updateTimestamp = connectionEntity.getUpdatedTime().toEpochSecond(ZoneOffset.of("+8")) * 1000; this.updateTimestamp = connectionEntity.getUpdatedTime().toEpochSecond(ZoneOffset.of("+8")) * 1000;
this.isUpload = connectionEntity.getIsUploaded() == 1 ? true : false; this.isUpload = connectionEntity.getIsUploaded();
this.status = connectionEntity.getConnectionStatus(); this.status = connectionEntity.getConnectionStatus();
this.clientId = connectionEntity.getClientId(); this.clientId = connectionEntity.getClientId();
this.storeStrategy = connectionEntity.getStoreStrategy(); this.storeStrategy = connectionEntity.getStoreStrategy();

View File

@ -66,7 +66,7 @@ public class AuthServiceImpl implements MqttAuth {
connectionEntity.setIsUploaded(UploadStatus.UPLOADING); connectionEntity.setIsUploaded(UploadStatus.UPLOADING);
connectionEntity.setConnectionStatus(ConfigConstant.CONNECTION_STATUS_ON); connectionEntity.setConnectionStatus(ConfigConstant.CONNECTION_STATUS_ON);
connectionMapper.updateById(connectionEntity); connectionMapper.updateById(connectionEntity);
connectionService.updateSchedule(connectionEntity); connectionService.updateSchedule(connectionEntity,false);
} }
connectionMapper.updateById(connectionEntity); connectionMapper.updateById(connectionEntity);
ConfigContext.connections.put(connectionEntity.getDeviceId(), connectionEntity); ConfigContext.connections.put(connectionEntity.getDeviceId(), connectionEntity);

View File

@ -207,7 +207,7 @@ public class ProtocolProcess implements InternalRecvice {
public void processDisConnect(Channel channel, MqttMessage msg) { public void processDisConnect(Channel channel, MqttMessage msg) {
String clientId = NettyUtil.getClientId(channel); String clientId = NettyUtil.getClientId(channel);
if (clientId.startsWith(ConfigConstant.CLIENT_PREFIX)) { if (clientId.startsWith(ConfigConstant.CLIENT_PREFIX)) {
clientService.clientDisconnect(clientId.replace(ConfigConstant.CLIENT_PREFIX, "")); clientService.clientDisconnect(clientId);
} else if (clientId.startsWith(ConfigConstant.MQTT_CONNECTION_PREFIX)) { } else if (clientId.startsWith(ConfigConstant.MQTT_CONNECTION_PREFIX)) {
clientService.clientDisconnect(clientId); clientService.clientDisconnect(clientId);
} }

View File

@ -65,7 +65,9 @@ public interface ConnectionService extends IService<ConnectionEntity> {
//更新上传任务 //更新上传任务
Boolean updateSchedule(String connectionSign, int uploadType, int uploadcycle, Integer storeStrategy, Integer status, boolean throwEx) throws SchedulerException; Boolean updateSchedule(String connectionSign, int uploadType, int uploadcycle, Integer storeStrategy, Integer status, boolean throwEx) throws SchedulerException;
Boolean updateSchedule(ConnectionEntity connectionEntity) throws SchedulerException; Boolean updateSchedule(Long deviceId, int uploadType, int uploadcycle, Integer storeStrategy, Integer status, boolean throwEx) throws SchedulerException;
Boolean updateSchedule(ConnectionEntity connectionEntity, boolean throwEx) throws SchedulerException;
//暂停上传任务 //暂停上传任务
Boolean stopSchedule(Long deviceId); Boolean stopSchedule(Long deviceId);

View File

@ -78,6 +78,7 @@ public class ClientServiceImpl implements ClientService {
public void clientDisconnect(String clientId) { public void clientDisconnect(String clientId) {
//级联客户端断连 //级联客户端断连
if (clientId.startsWith(ConfigConstant.CLIENT_PREFIX)) { if (clientId.startsWith(ConfigConstant.CLIENT_PREFIX)) {
clientId = clientId.replace(ConfigConstant.CLIENT_PREFIX,"");
ClientEntity clientEntity = ConfigContext.clients.get(clientId); ClientEntity clientEntity = ConfigContext.clients.get(clientId);
clientEntity.setClientStatus(ConfigConstant.CLIENT_STATUS_OFF); clientEntity.setClientStatus(ConfigConstant.CLIENT_STATUS_OFF);
clientMapper.updateById(clientEntity); clientMapper.updateById(clientEntity);

View File

@ -531,14 +531,42 @@ public class ConnectionServiceImpl extends ServiceImpl<ConnectionMapper, Connect
connectionEntity.setUploadCycle(uploadcycle); connectionEntity.setUploadCycle(uploadcycle);
connectionEntity.setIsUploaded(status); connectionEntity.setIsUploaded(status);
connectionEntity.setStoreStrategy(storeStrategy); connectionEntity.setStoreStrategy(storeStrategy);
//内部configJosn更新
if (connectionEntity.getConnectionProtocol() == ProtocolConstant.OPCDA) {
OPCDaConfig opcDaConfig = JSON.parseObject(connectionEntity.getConnectionJson(), OPCDaConfig.class);
opcDaConfig.setUploadType(uploadType);
opcDaConfig.setCycle(uploadcycle);
connectionEntity.setConnectionJson(JSON.toJSONString(opcDaConfig));
} else if (connectionEntity.getConnectionProtocol() == ProtocolConstant.IEC104) {
IEC104Config iec104Config = JSON.parseObject(connectionEntity.getConnectionJson(), IEC104Config.class);
iec104Config.setUploadType(uploadType);
iec104Config.setCycle(uploadcycle);
connectionEntity.setConnectionJson(JSON.toJSONString(iec104Config));
} else if (connectionEntity.getConnectionProtocol() == ProtocolConstant.MQTT) {
MqttConnectionConfig mqttConnectionConfig = JSON.parseObject(connectionEntity.getConnectionJson(), MqttConnectionConfig.class);
mqttConnectionConfig.setUploadType(uploadType);
mqttConnectionConfig.setCycle(uploadcycle);
connectionEntity.setConnectionJson(JSON.toJSONString(mqttConnectionConfig));
}
this.updateById(connectionEntity); this.updateById(connectionEntity);
ConfigContext.connections.put(connectionEntity.getDeviceId(), connectionEntity); ConfigContext.connections.put(connectionEntity.getDeviceId(), connectionEntity);
centerService.remoteSyn();
return true; return true;
} }
@Override @Override
public Boolean updateSchedule(ConnectionEntity connectionEntity) throws SchedulerException { public Boolean updateSchedule(Long deviceId, int uploadType, int uploadcycle, Integer storeStrategy, Integer status, boolean throwEx) throws SchedulerException {
return updateSchedule(connectionEntity.getConnectionSign(), connectionEntity.getUploadType(), connectionEntity.getUploadCycle(), connectionEntity.getStoreStrategy(), connectionEntity.getIsUploaded(), false); ConnectionEntity connectionEntity = this.getOne(new QueryWrapper<ConnectionEntity>().eq("device_id", deviceId));
connectionEntity.setUploadType(uploadType);
connectionEntity.setUploadCycle(uploadcycle);
connectionEntity.setIsUploaded(status);
return updateSchedule(connectionEntity, throwEx);
}
@Override
public Boolean updateSchedule(ConnectionEntity connectionEntity, boolean throwEx) throws SchedulerException {
return updateSchedule(connectionEntity.getConnectionSign(), connectionEntity.getUploadType(), connectionEntity.getUploadCycle(), connectionEntity.getStoreStrategy(), connectionEntity.getIsUploaded(), throwEx);
} }
@Override @Override
@ -625,23 +653,20 @@ public class ConnectionServiceImpl extends ServiceImpl<ConnectionMapper, Connect
isSuccess = this.delBrokerConnection(connectDTO.getConnectSign()); isSuccess = this.delBrokerConnection(connectDTO.getConnectSign());
break; break;
} }
mqttClientService.deviceResponse(request.getMethod(), request.getRequestId(), isSuccess, "", "{}"); mqttClientService.deviceResponse(request.getMethod(), request.getRequestId(), isSuccess, "", connectDTO);
this.syncDeviceChannelConfig(); this.syncDeviceChannelConfig();
} }
@Override @Override
public void updateConectionConfig(DeviceBaseRequest request) { public void updateConectionConfig(DeviceBaseRequest request) {
List<ConnectDTO> list = JSON.parseObject(request.getPayload().toString(), List.class); ConnectDTO connectDTO = JSON.parseObject(request.getPayload().toString(), ConnectDTO.class);
list.forEach(
i -> {
try { try {
updateSchedule(i.getConnectSign(), i.getUploadType(), i.getCycle(), i.getStoreStrategy(), i.getStatus(), false); updateSchedule(connectDTO.getDevice(), connectDTO.getUploadType(), connectDTO.getCycle(), connectDTO.getStoreStrategy(), connectDTO.getStatus(), true);
} catch (SchedulerException e) { } catch (Exception e) {
e.printStackTrace(); mqttClientService.deviceResponse(request.getMethod(), request.getRequestId(), false, e.getMessage(), connectDTO);
return;
} }
} mqttClientService.deviceResponse(request.getMethod(), request.getRequestId(), true, null, connectDTO);
);
mqttClientService.deviceResponse(request.getMethod(), request.getRequestId(), true, null, null);
} }
@Override @Override

View File

@ -153,7 +153,7 @@ public class MqttClientServiceImpl implements MqttClientService {
DeviceBaseResponse response = new DeviceBaseResponse(); DeviceBaseResponse response = new DeviceBaseResponse();
response.requestId = requestId; response.requestId = requestId;
response.method = method; response.method = method;
response.payload = o == null ? "{}" : o; response.payload = o == null ? (new Object()) : o;
response.success = isSuccess; response.success = isSuccess;
response.error = err; response.error = err;
MqttMessage mqttMessage = new MqttMessage(); MqttMessage mqttMessage = new MqttMessage();