gt 2 years ago
parent
commit
1bfcd38dd4

+ 26 - 5
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ChannelSettingServiceImpl.java

@@ -1,8 +1,10 @@
 package com.judong.chuanyiserver.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
-import com.judong.chuanyiserver.dao.ConnectDao;
+import com.judong.chuanyiserver.config.KepOpcServerTimerTask;
+import com.judong.chuanyiserver.config.OpcAsyncTask;
 import com.judong.chuanyiserver.dao.ChannelSettingDao;
+import com.judong.chuanyiserver.dao.ConnectDao;
 import com.judong.chuanyiserver.entity.ChannelSetting;
 import com.judong.chuanyiserver.entity.Config;
 import com.judong.chuanyiserver.entity.ServerInformation;
@@ -17,7 +19,7 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
+import java.util.Timer;
 
 @Service
 @Transactional
@@ -29,6 +31,9 @@ public class ChannelSettingServiceImpl implements ChannelSettingService {
     @Resource
     private ChannelSettingDao channelSettingDao;
 
+    @Resource
+    private OpcAsyncTask opcAsyncTask;
+
     @Override
     public synchronized Result channelSetting(ChannelSetting channelSetting) {
         if (Blank.isEmpty(channelSetting.getId())) {
@@ -142,7 +147,7 @@ public class ChannelSettingServiceImpl implements ChannelSettingService {
 
     @Override
     public Result selectConfig(Integer configId) {
-        return Result.ok(channelSettingDao.getChannelByConfigId(configId));
+        return Result.ok(channelSettingDao.getConfigList(configId));
     }
 
     @Override
@@ -171,12 +176,28 @@ public class ChannelSettingServiceImpl implements ChannelSettingService {
         serverInformation.setIpPassword(RSAUtil.decrypt(serverInformation.getIpPassword(), "utf-8"));
         if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
             if (KepOpcServerUtil.validationServerInformation(serverInformation)) {
-                return KepOpcServerUtil.opcReadItemListValue(serverInformation, channelSettingList);
+                if (runState==ConstantStr.START_UP){
+                    //将配置的状态更换为运行
+                    Timer timer = new Timer(true);
+                    timer.scheduleAtFixedRate(new KepOpcServerTimerTask(serverInformation,channelSettingList),0,1*1000);
+
+//                    opcAsyncTask.KepServerReadItemList(serverInformation, channelSettingList);
+                }else{
+                    //将配置的状态更换为停止
+
+                    opcAsyncTask.KepServerCloseReadItemList(serverInformation, channelSettingList);
+                }
+                return Result.ok("操作成功");
             }
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         } else if (serverInformation.getConnectMode() == ConnectModeEnum.KingOPCServer.getValue()) {
             if (OpcServerUaUtil.validationServerInformation(serverInformation)) {
-                return OpcServerUaUtil.opcReadItemValue(serverInformation, "");
+                if (runState==ConstantStr.START_UP){
+                    opcAsyncTask.OpcServerUaReadItemList(serverInformation, channelSettingList);
+                }else{
+                    opcAsyncTask.OpcServerUaCloseReadItemList(serverInformation, channelSettingList);
+                }
+                return Result.ok("操作成功");
             }
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         } else {