|
@@ -19,6 +19,7 @@ import com.example.opc_ua.task.OpcAsyncTask;
|
|
|
import com.example.opc_ua.task.OpcUaTask;
|
|
|
import com.example.opc_ua.util.OpcUaUtil;
|
|
|
import com.example.opc_ua.util.RedisUtil;
|
|
|
+import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -121,6 +122,20 @@ public class ItemGroupServiceImpl implements ItemGroupService {
|
|
|
throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "选择不匿名方式,需要填写帐户和密码");
|
|
|
}
|
|
|
}
|
|
|
+ OpcUaClient opcUaClient = null;
|
|
|
+ try {
|
|
|
+ opcUaClient = OpcUaUtil.createClient(dataSource);
|
|
|
+ if (Blank.isEmpty(opcUaClient)) {
|
|
|
+ return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "客户端创建失败");
|
|
|
+ }
|
|
|
+ opcUaClient.connect().get();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), OpcUaUtil.genException(e.getMessage()));
|
|
|
+ } finally {
|
|
|
+ if (Blank.isNotEmpty(opcUaClient)) {
|
|
|
+ opcUaClient.disconnect();
|
|
|
+ }
|
|
|
+ }
|
|
|
redisUtil.set(ConstantStr.ITEM_GROUP + id, true);
|
|
|
//新增定时器任务
|
|
|
String cronId = "";
|