Browse Source

Merge branch 'master' of http://116.63.33.55/git/read_opc

FinalYu 2 years ago
parent
commit
3af48404c2
25 changed files with 519 additions and 78 deletions
  1. 7 1
      chuanyi-admin/src/components/SelectTree/index.vue
  2. 3 0
      chuanyi-admin/src/views/system/dept/index.vue
  3. 3 1
      chuanyi_server/src/main/java/com/judong/chuanyiserver/ChuanyiServerApplication.java
  4. 17 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/config/AsyncTask.java
  5. 63 8
      chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/ChannelSettingController.java
  6. 17 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/DataSourceController.java
  7. 15 2
      chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/DictController.java
  8. 25 4
      chuanyi_server/src/main/java/com/judong/chuanyiserver/dao/ChannelSettingDao.java
  9. 7 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/dao/DataSourceDao.java
  10. 9 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/dao/DictDao.java
  11. 16 6
      chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/ChannelSetting.java
  12. 33 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/Config.java
  13. 4 2
      chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/Dict.java
  14. 11 3
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/ChannelSettingService.java
  15. 4 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/DataSourceService.java
  16. 4 1
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/DictService.java
  17. 87 14
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ChannelSettingServiceImpl.java
  18. 4 1
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ConnectServiceImpl.java
  19. 16 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/DataSourceServiceImpl.java
  20. 26 6
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/DictServiceImpl.java
  21. 4 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/util/ConstantStr.java
  22. 32 3
      chuanyi_server/src/main/java/com/judong/chuanyiserver/util/KepOpcServerUtil.java
  23. 91 26
      chuanyi_server/src/main/resources/mapper/ChannelSettingDao.xml
  24. 6 0
      chuanyi_server/src/main/resources/mapper/DataSourceDao.xml
  25. 15 0
      chuanyi_server/src/main/resources/mapper/DictDao.xml

+ 7 - 1
chuanyi-admin/src/components/SelectTree/index.vue

@@ -18,6 +18,10 @@ export default {
     // 占位符
     placeholder: {
       type: String
+    },
+    // 自定义键名
+    name: {
+      type: String
     }
   },
   data() {
@@ -26,12 +30,14 @@ export default {
     }
   },
   methods: {
+    // 选择节点
     handelInput(val) {
       this.$emit('handelGetValue', val)
     },
+    // 自定义键名
     normalizer(node) {
       return {
-        label: node.departmentName
+        label: node[this.name]
       }
     }
   }

+ 3 - 0
chuanyi-admin/src/views/system/dept/index.vue

@@ -63,6 +63,7 @@
                 v-if="options.length"
                 :options="options"
                 placeholder="请选择上级部门"
+                :name="name"
                 @handelGetValue="handelGetValue"
               />
             </el-form-item>
@@ -147,6 +148,7 @@ export default {
       multiple: true,
       // 删除部门id集合
       ids: [],
+      // 自定义treeselect键名
       name: null
     }
   },
@@ -171,6 +173,7 @@ export default {
         this.$nextTick(() => {
           this.$delTreeChildrenNode(data)
           this.options = data
+          this.name = 'departmentName'
         })
       })
     },

+ 3 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/ChuanyiServerApplication.java

@@ -3,13 +3,15 @@ package com.judong.chuanyiserver;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 import org.springframework.web.bind.annotation.CrossOrigin;
 
 @CrossOrigin
 @SpringBootApplication
-@EnableScheduling
+@EnableAsync//开启异步
+@EnableScheduling//开启定时器
 @MapperScan("com.judong.chuanyiserver.dao")
 public class ChuanyiServerApplication {
 

+ 17 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/config/AsyncTask.java

@@ -0,0 +1,17 @@
+package com.judong.chuanyiserver.config;
+
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Component;
+
+@Component
+@Async
+public class AsyncTask {
+
+    public void testA() {
+        System.out.println("异步任务A在执行");
+    }
+
+    public void testB() {
+        System.out.println("异步任务B在执行");
+    }
+}

+ 63 - 8
chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/ChannelSettingController.java

@@ -9,7 +9,6 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
-import java.util.List;
 
 @RestController
 @RequestMapping("channelSetting")
@@ -55,7 +54,7 @@ public class ChannelSettingController {
      * @return
      */
     @GetMapping("/getConnectTree")
-    public Result getConnectTree(Integer serverId) {
+    public Result getConnectTree(Integer serverId) throws Exception {
         if (Blank.isEmpty(serverId)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
@@ -65,16 +64,72 @@ public class ChannelSettingController {
     /**
      * 保存配置里面的通道配置
      *
-     * @param serverId
-     * @param channelNameList
-     * @param configName
+     * @param channelSetting
      * @return
      */
     @PostMapping("/assignChannelSettingList")
-    public Result assignChannelSettingList(Integer serverId, List<String> channelNameList, String configName) {
-        if (Blank.isEmpty(serverId, channelNameList, configName)) {
+    public Result assignChannelSettingList(@RequestBody ChannelSetting channelSetting) {
+        if (Blank.isEmpty(channelSetting, channelSetting.getServerId(), channelSetting.getChannelNameList(), channelSetting.getConfigName())) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        }
+        return channelSettingService.assignChannelSettingList(channelSetting.getConfigId(), channelSetting.getServerId(), channelSetting.getChannelNameList(), channelSetting.getConfigName());
+    }
+
+    /**
+     * 重命名配置
+     *
+     * @param configId
+     * @param configName
+     * @return
+     */
+    @PostMapping("/renameConfig")
+    public Result renameConfig(Integer configId, String configName) {
+        if (Blank.isEmpty(configId, configName)) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        }
+        return channelSettingService.renameConfig(configId, configName);
+    }
+
+    /**
+     * 通过配置id查询有哪些通道配置
+     *
+     * @param configId
+     * @return
+     */
+    @GetMapping("/selectConfig/{configId}")
+    public Result selectConfig(@PathVariable Integer configId) {
+        if (Blank.isEmpty(configId)) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        }
+        return channelSettingService.selectConfig(configId);
+    }
+
+    /**
+     * 通过配置id删除相应的配置信息和通道信息
+     *
+     * @param configId
+     * @return
+     */
+    @PostMapping("/deleteConfig/{configId}")
+    public Result deleteConfig(@PathVariable Integer configId) {
+        if (Blank.isEmpty(configId)) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        }
+        return channelSettingService.deleteConfig(configId);
+    }
+
+    /**
+     * 通过配置id和状态,控制配置的启用和停用
+     *
+     * @param configId
+     * @param runState
+     * @return
+     */
+    @PostMapping("/runConfigById")
+    public Result runConfigById(Integer configId, Integer runState) throws Exception {
+        if (Blank.isEmpty(configId, runState)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
-        return channelSettingService.assignChannelSettingList(serverId, channelNameList, configName);
+        return channelSettingService.runConfigById(configId, runState);
     }
 }

+ 17 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/DataSourceController.java

@@ -0,0 +1,17 @@
+package com.judong.chuanyiserver.controller;
+
+import com.judong.chuanyiserver.service.DataSourceService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+@RestController
+@RequestMapping("dataSource")
+@Slf4j
+public class DataSourceController {
+
+    @Resource
+    private DataSourceService dataSourceService;
+}

+ 15 - 2
chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/DictController.java

@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.util.List;
+import java.util.Map;
 
 @RestController
 @RequestMapping("dict")
@@ -64,8 +65,8 @@ public class DictController {
         if (Blank.isEmpty(parentId)){
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "父id不能为空");
         }
-        List<Dict> dicts = dictService.queryByParentId(parentId);
-        return Result.ok(dicts);
+        Map<String, Dict> stringDictMap = dictService.queryByParentId(parentId);
+        return Result.ok(stringDictMap);
     }
 
     /**
@@ -92,6 +93,18 @@ public class DictController {
         return dictService.deleteByid(ids);
     }
 
+    /**
+     * 根据key批量查询
+     */
+    @GetMapping("queryByDictKey")
+    public Result queryByDictKey(@RequestParam("dictKeys") List<String> dictKeys){
+        if (dictKeys.size()<=0){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "参数错误");
+        }
+        Map<String, Object> map = dictService.queryByDictKey(dictKeys);
+        return Result.ok(map);
+    }
+
 
 
 }

+ 25 - 4
chuanyi_server/src/main/java/com/judong/chuanyiserver/dao/ChannelSettingDao.java

@@ -1,9 +1,12 @@
 package com.judong.chuanyiserver.dao;
 
 import com.judong.chuanyiserver.entity.ChannelSetting;
+import com.judong.chuanyiserver.entity.Config;
+import com.judong.chuanyiserver.util.Result;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
+import java.util.Map;
 
 @Repository
 public interface ChannelSettingDao {
@@ -16,11 +19,29 @@ public interface ChannelSettingDao {
 
     Integer updateChannelSetting(ChannelSetting channelSetting);
 
-    List<String> getConfigList(int serverId);
+    List<Config> getConfigList(int serverId);
 
-    List<ChannelSetting> getChannelListNoConfig(Integer serverId);
+    Integer addConfigByName(Integer serverId, String configName,Integer runState);
 
-    Integer clearConfigByName(Integer serverId, String configName);
+    Config getConfigByName(Integer serverId, String configName);
 
-    Integer addConfigByName(Integer serverId, List<String> channelNameList, String configName);
+    Integer getConfigId(Integer serverId, String configName);
+
+    Integer clearChannelConfig(Integer configId);
+
+    Integer renameConfig(Integer configId, String configName);
+
+    Config getConfigNoIdName(Integer configId, String configName);
+
+    List<ChannelSetting> getChHaConfByServerId(Integer serverId);
+
+    Integer addChannelConfigList(Integer serverId, List<String> channelNameList, Integer configId);
+
+    ChannelSetting getChannelByConfigId(Integer configId);
+
+    Integer deleteConfig(Integer configId);
+
+    Config getConfigById(Integer configId);
+
+    List<ChannelSetting> getChannelListBySeCoId(Integer serverId, Integer configId);
 }

+ 7 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/dao/DataSourceDao.java

@@ -0,0 +1,7 @@
+package com.judong.chuanyiserver.dao;
+
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface DataSourceDao {
+}

+ 9 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/dao/DictDao.java

@@ -60,6 +60,15 @@ public interface DictDao {
 
     Dict queryById(Integer id);
 
+    /**
+     * 判断key是否重复
+     */
+    Dict queryByDictKeyIsExist(String dictKey);
+
+    /**
+     * 根据key批量查询
+     */
+    List<Dict> queryByDictKey(@Param("dictKeys") List<String> dictKeys);
 
 
 }

+ 16 - 6
chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/ChannelSetting.java

@@ -3,6 +3,7 @@ package com.judong.chuanyiserver.entity;
 import lombok.Data;
 
 import java.io.Serializable;
+import java.util.List;
 
 @Data
 public class ChannelSetting implements Serializable {
@@ -26,10 +27,6 @@ public class ChannelSetting implements Serializable {
      */
     private String channelMapName;
     /**
-     * 数据类型
-     */
-    private Integer dataType;
-    /**
      * 读取机制
      */
     private Integer readMechanism;
@@ -42,7 +39,20 @@ public class ChannelSetting implements Serializable {
      */
     private String policyValue;
     /**
-     * 配置名称
+     * 配置id
+     */
+    private Integer configId;
+    /**
+     * 创建时间
+     */
+    private String createTime;
+
+    /**
+     * 虚拟的configName用来接收数据
+     */
+    private String configName;
+    /**
+     * 通道配置名称集合,虚拟的,用来接收数据
      */
-    private String configurationName;
+    List<String> channelNameList;
 }

+ 33 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/Config.java

@@ -0,0 +1,33 @@
+package com.judong.chuanyiserver.entity;
+
+import com.judong.chuanyiserver.util.ConstantStr;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class Config implements Serializable {
+
+    private static final long serialVersionUID = -96536212774977561L;
+
+    /**
+     * 主键id
+     */
+    private Integer id;
+    /**
+     * 服务器id
+     */
+    private Integer serverId;
+    /**
+     * 配置名称
+     */
+    private String configurationName;
+    /**
+     * 启用状态
+     */
+    private Integer runState;
+    /**
+     * 创建时间
+     */
+    private String createTime;
+}

+ 4 - 2
chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/Dict.java

@@ -3,7 +3,9 @@ package com.judong.chuanyiserver.entity;
 import lombok.Data;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @Data
 public class Dict {
@@ -39,8 +41,8 @@ public class Dict {
     private String createTime;
 
     /**
-     * 子节点
+     * 子节点    private List<Dict> children=new ArrayList<>();
      */
-    private List<Dict> children=new ArrayList<>();
+    private Map<String, Dict> children=new HashMap<>();
 
 }

+ 11 - 3
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/ChannelSettingService.java

@@ -9,9 +9,17 @@ public interface ChannelSettingService {
 
     Result channelSetting(ChannelSetting channelSetting);
 
-    Result getChannelSetting(Integer serverId,String ChannelName);
+    Result getChannelSetting(Integer serverId, String ChannelName);
 
-    Result getConnectTree(Integer serverId);
+    Result getConnectTree(Integer serverId) throws Exception;
 
-    Result assignChannelSettingList(Integer serverId, List<String> channelNameList, String configName);
+    Result assignChannelSettingList(Integer configId, Integer serverId, List<String> channelNameList, String configName);
+
+    Result renameConfig(Integer configId, String configName);
+
+    Result selectConfig(Integer configId);
+
+    Result deleteConfig(Integer configId);
+
+    Result runConfigById(Integer configId, Integer runState) throws Exception;
 }

+ 4 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/DataSourceService.java

@@ -0,0 +1,4 @@
+package com.judong.chuanyiserver.service;
+
+public interface DataSourceService {
+}

+ 4 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/DictService.java

@@ -4,6 +4,7 @@ import com.judong.chuanyiserver.entity.Dict;
 import com.judong.chuanyiserver.util.Result;
 
 import java.util.List;
+import java.util.Map;
 
 public interface DictService {
     /**
@@ -30,7 +31,7 @@ public interface DictService {
      * 根据父id查子节点信息 树结构
      * param parentId
      */
-    List<Dict> queryByParentId(Integer parentId);
+    Map<String, Dict> queryByParentId(Integer parentId);
 
     /**
      * 新增
@@ -46,4 +47,6 @@ public interface DictService {
      * 根据id删除(批量)
      */
     Result deleteByid( List<Integer> ids);
+
+    Map<String, Object> queryByDictKey(List<String> dictKeys);
 }

+ 87 - 14
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ChannelSettingServiceImpl.java

@@ -4,18 +4,19 @@ import com.alibaba.fastjson.JSONObject;
 import com.judong.chuanyiserver.dao.ConnectDao;
 import com.judong.chuanyiserver.dao.ChannelSettingDao;
 import com.judong.chuanyiserver.entity.ChannelSetting;
+import com.judong.chuanyiserver.entity.Config;
 import com.judong.chuanyiserver.entity.ServerInformation;
 import com.judong.chuanyiserver.enums.ConnectModeEnum;
 import com.judong.chuanyiserver.enums.ResultEnum;
+import com.judong.chuanyiserver.exception.CustomException;
 import com.judong.chuanyiserver.service.ChannelSettingService;
-import com.judong.chuanyiserver.util.Blank;
-import com.judong.chuanyiserver.util.KepOpcServerUtil;
-import com.judong.chuanyiserver.util.Result;
+import com.judong.chuanyiserver.util.*;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.util.List;
+import java.util.Map;
 
 @Service
 @Transactional
@@ -35,7 +36,7 @@ public class ChannelSettingServiceImpl implements ChannelSettingService {
                 return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已经存在此标签配置,请更换标签名称");
             }
             if (channelSettingDao.addChannelSetting(channelSetting) <= 0) {
-                return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "保存标签配置失败");
+                throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "保存标签配置失败");
             }
             return Result.ok("保存标签配置成功");
         } else {
@@ -44,7 +45,7 @@ public class ChannelSettingServiceImpl implements ChannelSettingService {
                 return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已经存在此标签配置,请更换标签名称");
             }
             if (channelSettingDao.updateChannelSetting(channelSetting) <= 0) {
-                return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "保存标签配置失败");
+                throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "保存标签配置失败");
             }
             return Result.ok("保存标签配置成功");
         }
@@ -56,15 +57,16 @@ public class ChannelSettingServiceImpl implements ChannelSettingService {
     }
 
     @Override
-    public Result getConnectTree(Integer serverId) {
+    public Result getConnectTree(Integer serverId) throws Exception {
         ServerInformation serverInformation = connectDao.getServerInformationById(serverId);
         if (Blank.isEmpty(serverInformation)) {
             return Result.no(ResultEnum.NOT_FOUND.getRespCode(), ResultEnum.NOT_FOUND.getRespMsg());
         }
+        serverInformation.setIpPassword(RSAUtil.decrypt(serverInformation.getIpPassword(), "utf-8"));
         if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
             if (KepOpcServerUtil.validationServerInformation(serverInformation)) {
                 JSONObject jsonObject = new JSONObject();
-                List<ChannelSetting> channelSettings = channelSettingDao.getChannelListNoConfig(serverId);
+                List<ChannelSetting> channelSettings = channelSettingDao.getChHaConfByServerId(serverId);
                 if (Blank.isNotEmpty(channelSettings)) {
                     jsonObject.put("tree", KepOpcServerUtil.opcNoConfigTree(serverInformation, channelSettings));
                 } else {
@@ -78,13 +80,84 @@ public class ChannelSettingServiceImpl implements ChannelSettingService {
     }
 
     @Override
-    public synchronized Result assignChannelSettingList(Integer serverId, List<String> channelNameList, String configName) {
-        //清空配置名称为configName的通道配置
-        channelSettingDao.clearConfigByName(serverId, configName);
-        //给传入的List都添加configName
-        if (channelSettingDao.addConfigByName(serverId, channelNameList, configName) <= 0) {
-            return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "保存配置失败");
+    public synchronized Result assignChannelSettingList(Integer configId, Integer serverId, List<String> channelNameList, String configName) {
+        if (Blank.isEmpty(configId)) {
+            Config config = channelSettingDao.getConfigByName(serverId, configName);
+            if (Blank.isEmpty(config)) {
+                if (channelSettingDao.addConfigByName(serverId, configName, ConstantStr.STOP_IT) <= 0) {
+                    throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "保存配置失败");
+                }
+                configId = channelSettingDao.getConfigId(serverId, configName);
+                if (channelSettingDao.addChannelConfigList(serverId, channelNameList, configId) <= 0) {
+                    throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "保存配置失败,可能是选择的配置中,没有一个进行标签映射");
+                }
+                return Result.ok("保存配置成功");
+            } else {
+                return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已存在同名的配置,请更换配置名称");
+            }
+        } else {
+            channelSettingDao.clearChannelConfig(configId);
+            if (channelSettingDao.addChannelConfigList(serverId, channelNameList, configId) <= 0) {
+                throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "保存配置失败,可能是选择的配置中,没有一个进行标签映射");
+            }
+            return Result.ok("保存配置成功");
+        }
+    }
+
+    @Override
+    public synchronized Result renameConfig(Integer configId, String configName) {
+        Config config = channelSettingDao.getConfigNoIdName(configId, configName);
+        if (Blank.isNotEmpty(config)) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已存在同名的配置,请更换配置名称");
+        }
+        if (channelSettingDao.renameConfig(configId, configName) <= 0) {
+            throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "重命名配置失败");
+        }
+        return Result.ok("重命名配置成功");
+    }
+
+    @Override
+    public Result selectConfig(Integer configId) {
+        return Result.ok(channelSettingDao.getChannelByConfigId(configId));
+    }
+
+    @Override
+    public synchronized Result deleteConfig(Integer configId) {
+        Config config = channelSettingDao.getConfigById(configId);
+        if (Blank.isNotEmpty(config)) {
+            if (config.getRunState() == ConstantStr.START_UP) {
+                return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此配置现在处于启动中,无法删除");
+            }
+            if (channelSettingDao.deleteConfig(configId) <= 0) {
+                throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "删除配置失败");
+            }
+        }
+        channelSettingDao.clearChannelConfig(configId);
+        return Result.ok("删除配置成功");
+    }
+
+    @Override
+    public Result runConfigById(Integer configId, Integer runState) throws Exception {
+        if (runState != ConstantStr.STOP_IT && runState != ConstantStr.START_UP) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "状态只能为启用或者停用");
+        }
+        Config config = channelSettingDao.getConfigById(configId);
+        ServerInformation serverInformation = connectDao.getServerInformationById(config.getServerId());
+        List<ChannelSetting> channelSettingList=channelSettingDao.getChannelListBySeCoId(config.getServerId(),configId);
+        serverInformation.setIpPassword(RSAUtil.decrypt(serverInformation.getIpPassword(), "utf-8"));
+        if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
+            if (KepOpcServerUtil.validationServerInformation(serverInformation)) {
+                return KepOpcServerUtil.opcReadItemListValue(serverInformation, channelSettingList);
+            }
+            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, "");
+            }
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        } else {
+            throw new CustomException(ResultEnum.NOT_FOUND.getRespCode(), "没有此连接方式");
         }
-        return Result.ok("保存配置成功");
     }
+
 }

+ 4 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ConnectServiceImpl.java

@@ -3,6 +3,7 @@ package com.judong.chuanyiserver.service.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.judong.chuanyiserver.dao.ConnectDao;
 import com.judong.chuanyiserver.dao.ChannelSettingDao;
+import com.judong.chuanyiserver.entity.Config;
 import com.judong.chuanyiserver.entity.ServerInformation;
 import com.judong.chuanyiserver.enums.ConnectModeEnum;
 import com.judong.chuanyiserver.enums.ResultEnum;
@@ -15,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.util.List;
+import java.util.Map;
 
 @Service
 @Transactional
@@ -162,8 +164,9 @@ public class ConnectServiceImpl implements ConnectService {
         serverInformation.setIpPassword(RSAUtil.decrypt(serverInformation.getIpPassword(), "utf-8"));
         //如果连接方式为kepserver
         JSONObject jsonObject = new JSONObject();
-        List<String> configList = channelSettingDao.getConfigList(id);
+        List<Config> configList = channelSettingDao.getConfigList(id);
         jsonObject.put("config", configList);
+        jsonObject.put("run", configList);
         if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
             if (KepOpcServerUtil.validationServerInformation(serverInformation)) {
                 jsonObject.put("tree", KepOpcServerUtil.opcReadItemTree(serverInformation));

+ 16 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/DataSourceServiceImpl.java

@@ -0,0 +1,16 @@
+package com.judong.chuanyiserver.service.impl;
+
+import com.judong.chuanyiserver.dao.DataSourceDao;
+import com.judong.chuanyiserver.service.DataSourceService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+
+@Service
+@Transactional
+public class DataSourceServiceImpl implements DataSourceService {
+
+    @Resource
+    private DataSourceDao dataSourceDao;
+}

+ 26 - 6
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/DictServiceImpl.java

@@ -11,8 +11,9 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 
 @Service
@@ -60,17 +61,17 @@ public class DictServiceImpl implements DictService {
     }
 
     @Override
-    public List<Dict> queryByParentId(Integer parentId) {
+    public Map<String, Dict> queryByParentId(Integer parentId) {
         //存放节点数据
-        List<Dict> dictAll = new ArrayList<>();
+        Map<String, Dict> map = new HashMap<>();
         //根据父节点获取子节点对象
         List<Dict> dictSon = dictDao.queryByParentId(parentId);
         //判断子节点是否为其他节点的父节点
-        for (Dict d : dictSon){
+        for (Dict d:dictSon){
             d.setChildren(queryByParentId(d.getId()));
-            dictAll.add(d);
+            map.put(d.getDictKey(),d);
         }
-        return dictAll;
+        return map;
     }
 
     @Override
@@ -78,6 +79,9 @@ public class DictServiceImpl implements DictService {
         if (Blank.isEmpty(dict.getParentId(),dict.getDictKey(),dict.getDictValue(),dict.getSortNum())){
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "父id,字典key,字典值以及序号不能为空");
         }
+        if (Blank.isNotEmpty(dictDao.queryByDictKeyIsExist(dict.getDictKey()))){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "字典key已存在");
+        }
         dictDao.addDict(dict);
         return Result.ok("新增成功");
     }
@@ -92,6 +96,10 @@ public class DictServiceImpl implements DictService {
         if (dictShow==null){
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "修改失败");
         }
+        //判断key是否重复
+        if (Blank.isNotEmpty(dictDao.queryByDictKeyIsExist(dict.getDictKey()))){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "key已存在,修改失败");
+        }
         if (dictDao.updataById(dict)<=0){
             throw new ClassCastException("修改失败");
         }
@@ -106,4 +114,16 @@ public class DictServiceImpl implements DictService {
         Integer integer = dictDao.deleteByid(ids);
         return Result.ok(integer);
     }
+
+    @Override
+    public Map<String, Object> queryByDictKey(List<String> dictKeys) {
+        //存储数据
+        Map<String, Object> map = new HashMap<>();
+        List<Dict> dicts = dictDao.queryByDictKey(dictKeys);
+        for (Dict d:dicts){
+            d.setChildren(queryByParentId(d.getId()));
+            map.put(d.getDictKey(),d);
+        }
+        return map;
+    }
 }

+ 4 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/util/ConstantStr.java

@@ -47,4 +47,8 @@ public class ConstantStr {
     public static final Integer PUBLIC_NO_DELETE = 0;
     public static final Integer PUBLIC_IS_DELETE = 1;
 
+    //配置启用状态,0停用,1启用
+    public static final Integer STOP_IT=0;
+    public static final Integer START_UP=1;
+
 }

+ 32 - 3
chuanyi_server/src/main/java/com/judong/chuanyiserver/util/KepOpcServerUtil.java

@@ -13,9 +13,7 @@ import org.jinterop.dcom.common.JIException;
 import org.jinterop.dcom.core.JIVariant;
 import org.openscada.opc.dcom.da.OPCSERVERSTATE;
 import org.openscada.opc.lib.common.ConnectionInformation;
-import org.openscada.opc.lib.da.Group;
-import org.openscada.opc.lib.da.Item;
-import org.openscada.opc.lib.da.Server;
+import org.openscada.opc.lib.da.*;
 import org.openscada.opc.lib.da.browser.Branch;
 import org.openscada.opc.lib.da.browser.Leaf;
 import org.openscada.opc.lib.da.browser.TreeBrowser;
@@ -244,6 +242,37 @@ public class KepOpcServerUtil {
         return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
     }
 
+    public static Result opcReadItemListValue(ServerInformation serverInformation, List<ChannelSetting> channelSettingList) {
+        try {
+            String opcServerDaPoolKey = KepOpcServerUtil.generateOpcPoolKey(serverInformation);
+            if (KepOpcServerUtil.validationKey(opcServerDaPoolKey)) {
+                Server server = KepOpcServerUtil.getServer(opcServerDaPoolKey);
+                if (null == server.getServerState()) {
+                    return Result.no(ResultEnum.NOT_FOUND.getRespCode(), "连接失败");
+                }
+                if (OPCSERVERSTATE.OPC_STATUS_RUNNING == server.getServerState().getServerState()) {
+                    Group group = server.addGroup();
+                    //循环读值需要使用到的
+                    final AccessBase access=new SyncAccess(server,1000);
+                    //开始读值
+                    access.bind();
+                    //停止读值
+                    access.unbind();
+                    Iterator<ChannelSetting> iterator = channelSettingList.iterator();
+                    while (iterator.hasNext()){
+                        Item item = group.addItem(iterator.next().getChannelName());
+                        Map<String, Object> value = getVal(item.read(true).getValue());
+                    }
+                    KepOpcServerUtil.returnServer(opcServerDaPoolKey, server);
+                    return Result.ok("");
+                }
+            }
+        } catch (Exception e) {
+            return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), e.getMessage());
+        }
+        return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+    }
+
     /**
      * 获取OPCDA服务器的tree
      *

+ 91 - 26
chuanyi_server/src/main/resources/mapper/ChannelSettingDao.xml

@@ -3,52 +3,65 @@
 <mapper namespace="com.judong.chuanyiserver.dao.ChannelSettingDao">
 
     <insert id="addChannelSetting">
-        insert into t_channel_setting(server_id, channel_name, channel_map_name, data_type, read_mechanism, read_policy,
-                                      policy_value, configuration_name, create_time)
+        insert into t_channel_setting(server_id, channel_name, channel_map_name, read_mechanism, read_policy,
+                                      policy_value, create_time)
             value (#{serverId}, #{channelName},
-                   #{channelMapName}, #{dataType},
+                   #{channelMapName},
                    #{readMechanism}, #{readPolicy},
-                   #{policyValue}, #{configurationName}, now())
+                   #{policyValue}, now())
     </insert>
 
-    <update id="addConfigByName">
+    <insert id="addChannelConfigList">
         update t_channel_setting
-        set configuration_name=#{configName}
+        set config_id=#{configId}
         where server_id = #{serverId}
-        and channel_name in (
+        AND channel_name in (
         <foreach collection="channelNameList" item="channelName" index="index" separator=",">
             #{channelName}
         </foreach>
         )
+    </insert>
+
+    <update id="addConfigByName">
+        insert into t_config (server_id, configuration_name, run_state, create_time)
+            VALUE (#{serverId}, #{configName}, #{runState}, now())
     </update>
 
     <update id="updateChannelSetting">
         update t_channel_setting
         set channel_map_name=#{channelMapName},
-            data_type=#{dataType},
             read_mechanism=#{readMechanism},
             read_policy=#{readPolicy},
             policy_value=#{policyValue}
         where id = #{id}
     </update>
 
-    <update id="clearConfigByName">
-        update t_channel_setting
-        set configuration_name=null
-        where server_id = #{serverId}
-          and configuration_name = #{configName}
+    <update id="renameConfig">
+        update t_config
+        set configuration_name=#{configName}
+        where id = #{configId}
     </update>
 
+    <delete id="clearChannelConfig">
+        update t_channel_setting
+        set config_id=null
+        where config_id = #{configId}
+    </delete>
+
+    <delete id="deleteConfig">
+        delete
+        from t_config
+        where id = #{configId}
+    </delete>
+
     <select id="getChannelBySeChName" resultType="com.judong.chuanyiserver.entity.ChannelSetting">
         select id,
                server_id,
                channel_name,
                channel_map_name,
-               data_type,
                read_mechanism,
                read_policy,
                policy_value,
-               configuration_name,
                create_time
         from t_channel_setting
         where server_id = #{serverId}
@@ -60,11 +73,9 @@
                server_id,
                channel_name,
                channel_map_name,
-               data_type,
                read_mechanism,
                read_policy,
                policy_value,
-               configuration_name,
                create_time
         from t_channel_setting
         where server_id = #{serverId}
@@ -72,27 +83,81 @@
           and id != #{id}
     </select>
 
-    <select id="getConfigList" resultType="java.lang.String">
-        select distinct (tcs.configuration_name)
-        from (select configuration_name
-              from t_channel_setting
-              order by create_time) tcs
+    <select id="getConfigList" resultType="com.judong.chuanyiserver.entity.Config">
+        select id, server_id, configuration_name, run_state, create_time
+        from t_config
+        where server_id = #{serverId}
+        order by create_time
+    </select>
+
+    <select id="getConfigByName" resultType="com.judong.chuanyiserver.entity.Config">
+        select id, server_id, configuration_name, run_state, create_time
+        from t_config
+        where server_id = #{serverId}
+          and configuration_name = #{configName}
+    </select>
+
+    <select id="getConfigId" resultType="java.lang.Integer">
+        select id
+        from t_config
+        where server_id = #{serverId}
+          and configuration_name = #{configName}
     </select>
 
-    <select id="getChannelListNoConfig" resultType="com.judong.chuanyiserver.entity.ChannelSetting">
+    <select id="getConfigNoIdName" resultType="com.judong.chuanyiserver.entity.Config">
+        select id, server_id, configuration_name, run_state, create_time
+        from t_config
+        where id != #{configId}
+          AND configuration_name = #{configName}
+    </select>
+
+    <select id="getChHaConfByServerId" resultType="com.judong.chuanyiserver.entity.ChannelSetting">
+        select id,
+               server_id,
+               channel_name,
+               channel_map_name,
+               read_mechanism,
+               read_policy,
+               policy_value,
+               config_id,
+               create_time
+        from t_channel_setting
+        where server_id = #{serverId}
+          and config_id is not null
+    </select>
+
+    <select id="getChannelByConfigId" resultType="com.judong.chuanyiserver.entity.ChannelSetting">
+        select id,
+               server_id,
+               channel_name,
+               channel_map_name,
+               read_mechanism,
+               read_policy,
+               policy_value,
+               config_id,
+               create_time
+        from t_channel_setting
+        where config_id = #{configId}
+    </select>
+
+    <select id="getConfigById" resultType="com.judong.chuanyiserver.entity.Config">
+        select id, server_id, configuration_name, run_state, create_time
+        from t_config
+        where id = #{configId}
+    </select>
+    <select id="getChannelListBySeCoId" resultType="com.judong.chuanyiserver.entity.ChannelSetting">
         select id,
                server_id,
                channel_name,
                channel_map_name,
-               data_type,
                read_mechanism,
                read_policy,
                policy_value,
-               configuration_name,
+               config_id,
                create_time
         from t_channel_setting
         where server_id = #{serverId}
-          and configuration_name is null
+          and config_id = #{configId}
     </select>
 
 </mapper>

+ 6 - 0
chuanyi_server/src/main/resources/mapper/DataSourceDao.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.judong.chuanyiserver.dao.DataSourceDao">
+
+
+</mapper>

+ 15 - 0
chuanyi_server/src/main/resources/mapper/DictDao.xml

@@ -74,6 +74,12 @@
         INSERT INTO sys_dict VALUES (DEFAULT,#{dict.parentId},#{dict.dictKey},#{dict.dictValue},#{dict.sortNum},NOW())
     </insert>
 
+    <!--判断key是否重复-->
+    <select id="queryByDictKeyIsExist" resultType="com.judong.chuanyiserver.entity.Dict">
+        SELECT id,parent_id,dict_key,dict_value,sort_num,create_time FROM sys_dict
+        where dict_key=#{dictKey}
+    </select>
+
     <!--修改-->
     <update id="updataById">
         UPDATE sys_dict SET
@@ -98,4 +104,13 @@
         where id=#{id}
     </select>
 
+    <!--根据key批量查询-->
+    <select id="queryByDictKey" resultType="com.judong.chuanyiserver.entity.Dict">
+        SELECT id,parent_id,dict_key,dict_value,sort_num,create_time FROM sys_dict
+        where dict_key in
+        <foreach collection="dictKeys" item="dictKey" separator="," open="(" close=")">
+            #{dictKey}
+        </foreach>
+    </select>
+
 </mapper>