Browse Source

修改opcda数据源获取数据是不需要通过枚举进行判断

zhoupeng 1 year ago
parent
commit
88accaccd2

+ 0 - 34
chaunyi_opc/opc_common/src/main/java/com/example/opc_common/enums/OpcDaDriverEnum.java

@@ -1,34 +0,0 @@
-package com.example.opc_common.enums;
-
-public enum OpcDaDriverEnum {
-    KEPSERVER("KEPSERVER", "7BC0CC8E-482C-47CA-ABDC-0FE7F9C6E729"),
-    OPCIFIX("OPCIFIX", "3C5702A2-EB8E-11D4-83A4-00105A984CBD"),
-    WINCC("WINCC", "75D00BBB-DDA5-11D1-B944-9E614D000000"),
-    SCADA("SCADA", "04524449-C6B2-4D62-8471-C64FA1DDF64F"),
-    YOKOGAWA("YOKOGAWA", "E6C32641-F1CF-11D0-B0E4-080009CCD384"),
-    PAS300("PAS300", "4EA2713D-CA07-11D4-BEF5-00002120DB5E");
-
-    private String name;
-    private String value;
-
-    OpcDaDriverEnum(String name, String value) {
-        this.name = name;
-        this.value = value;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public String getValue() {
-        return value;
-    }
-
-    public void setValue(String value) {
-        this.value = value;
-    }
-}

+ 1 - 1
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/controller/DataSourceController.java

@@ -136,7 +136,7 @@ public class DataSourceController {
     }
 
     /**
-     * 获取opcda枚举中所有的clsId值
+     * 获取数据库中已经配置的数据源的所有opcda的clsId值
      *
      * @return
      */

+ 2 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/DataSourceDao.java

@@ -54,4 +54,6 @@ public interface DataSourceDao {
     DataSourceDriver getDataSourceDriverByclsId(String clsId);
 
     List<DataSource> getDataSourceByclsId(String clsId);
+
+    List<DataSource> getDataSourceClsId();
 }

+ 37 - 43
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dynamicSchedule/DynamicScheduleConfig.java

@@ -80,56 +80,50 @@ public class DynamicScheduleConfig implements SchedulingConfigurer {
                             itemGroupDao.stopItemGroupById(id, ConstantStr.STOP_IT);
                             redisUtil.del(ConstantStr.ITEM_GROUP + id);
                         }
-                        if (OpcDaUtil.isAdapterClsId(clsId)) {
-                            //如果opc服务未启动,数据组连接不上,直接将这个数据组设为停止状态
-                            //如果opc服务启动好了,数据组连接不上,直接将数据组设置为停止状态
-                            //如果opc服务启动好了,我们能连接上,将数据组设置为启动状态,并重新运行
-                            Server server = null;
-                            try {
-                                server = OpcDaUtil.createServer(dataSource);
-                                if (Blank.isEmpty(server)) {
-                                    itemGroupDao.stopItemGroupById(id, ConstantStr.STOP_IT);
-                                    redisUtil.del(ConstantStr.ITEM_GROUP + id);
-                                    continue;
-                                }
-                                server.connect();
-                            } catch (Exception e) {
+                        //如果opc服务未启动,数据组连接不上,直接将这个数据组设为停止状态
+                        //如果opc服务启动好了,数据组连接不上,直接将数据组设置为停止状态
+                        //如果opc服务启动好了,我们能连接上,将数据组设置为启动状态,并重新运行
+                        Server server = null;
+                        try {
+                            server = OpcDaUtil.createServer(dataSource);
+                            if (Blank.isEmpty(server)) {
                                 itemGroupDao.stopItemGroupById(id, ConstantStr.STOP_IT);
                                 redisUtil.del(ConstantStr.ITEM_GROUP + id);
                                 continue;
-                            } finally {
-                                if (Blank.isNotEmpty(server)) {
-                                    server.dispose();
-                                }
                             }
-                            //新增定时器任务
-                            String cronId = Blank.isEmpty(itemGroup.getCronId()) ?
-                                    UUID.randomUUID().toString().replace("-", "") :
-                                    itemGroup.getCronId();
-                            String cron = "0 0 0 ? * ";
-                            if (Blank.isEmpty(readWeek)) {
-                                cron = cron + "MON,TUE,WED,THU,FRI,SAT,SUN";
-                                //立即执行一次Timer
-                                opcDaTask.opcDaTask(itemGroup, dataSource, cronId);
-                            } else {
-                                cron = cron + readWeek;
-                                for (String str : readWeek.split(",")) {
-                                    if (str.equals(DateUtil.getCurrentWeekEn())) {
-                                        //立即执行一次Timer
-                                        opcDaTask.opcDaTask(itemGroup, dataSource, cronId);
-                                        break;
-                                    }
-                                }
-                            }
-                            SchedulingRunnable task = new SchedulingRunnable(OpcDaTask.class, "opcDaTask", new Object[]{itemGroup, dataSource, cronId});
-                            cronTaskRegister.addCronTask(task, cronId, cron);
-                            itemGroupDao.runItemGroupById(id, ConstantStr.START_UP, cronId);
-                            redisUtil.set(ConstantStr.ITEM_GROUP + id, true);
-                        } else {
-                            //如果目前未适配此种驱动类型,直接关停数据组
+                            server.connect();
+                        } catch (Exception e) {
                             itemGroupDao.stopItemGroupById(id, ConstantStr.STOP_IT);
                             redisUtil.del(ConstantStr.ITEM_GROUP + id);
+                            continue;
+                        } finally {
+                            if (Blank.isNotEmpty(server)) {
+                                server.dispose();
+                            }
+                        }
+                        //新增定时器任务
+                        String cronId = Blank.isEmpty(itemGroup.getCronId()) ?
+                                UUID.randomUUID().toString().replace("-", "") :
+                                itemGroup.getCronId();
+                        String cron = "0 0 0 ? * ";
+                        if (Blank.isEmpty(readWeek)) {
+                            cron = cron + "MON,TUE,WED,THU,FRI,SAT,SUN";
+                            //立即执行一次Timer
+                            opcDaTask.opcDaTask(itemGroup, dataSource, cronId);
+                        } else {
+                            cron = cron + readWeek;
+                            for (String str : readWeek.split(",")) {
+                                if (str.equals(DateUtil.getCurrentWeekEn())) {
+                                    //立即执行一次Timer
+                                    opcDaTask.opcDaTask(itemGroup, dataSource, cronId);
+                                    break;
+                                }
+                            }
                         }
+                        SchedulingRunnable task = new SchedulingRunnable(OpcDaTask.class, "opcDaTask", new Object[]{itemGroup, dataSource, cronId});
+                        cronTaskRegister.addCronTask(task, cronId, cron);
+                        itemGroupDao.runItemGroupById(id, ConstantStr.START_UP, cronId);
+                        redisUtil.set(ConstantStr.ITEM_GROUP + id, true);
                     }
                 }
             }

+ 75 - 95
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/DataSourceServiceImpl.java

@@ -2,7 +2,6 @@ package com.example.opc_da.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
 import com.example.opc_common.entity.*;
-import com.example.opc_common.enums.OpcDaDriverEnum;
 import com.example.opc_common.enums.ResultEnum;
 import com.example.opc_common.exception.CustomException;
 import com.example.opc_common.util.Blank;
@@ -24,8 +23,6 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.client.RestTemplate;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.util.*;
 
 @Service
@@ -189,23 +186,15 @@ public class DataSourceServiceImpl implements DataSourceService {
 
     @Override
     public Result getOpcDaDriverEnum() {
-        Class<OpcDaDriverEnum> clazz = OpcDaDriverEnum.class;
-        Object[] objects = clazz.getEnumConstants();
-        try {
-            Method getName = clazz.getMethod("getName");
-            Method getValue = clazz.getMethod("getValue");
+        List<DataSource> dataSourceList = dataSourceDao.getDataSourceClsId();
+        if (Blank.isNotEmpty(dataSourceList)) {
             Map<String, String> map = new HashMap<>();
-            for (Object o : objects) {
-                map.put(getName.invoke(o).toString(), getValue.invoke(o).toString().toLowerCase());
+            for (DataSource dataSource : dataSourceList) {
+                map.put(dataSource.getDataSourceDescribe(), dataSource.getClsId());
             }
             return Result.ok(map);
-        } catch (NoSuchMethodException e) {
-            throw new RuntimeException(e);
-        } catch (InvocationTargetException e) {
-            throw new RuntimeException(e);
-        } catch (IllegalAccessException e) {
-            throw new RuntimeException(e);
         }
+        return Result.ok(null);
     }
 
     @Override
@@ -218,102 +207,93 @@ public class DataSourceServiceImpl implements DataSourceService {
 
     @Override
     public synchronized Result addDataSourceDriver(DataSourceDriver dataSourceDriver) {
-        String clsId = dataSourceDriver.getClsId();
-        if (OpcDaUtil.isAdapterClsId(clsId)) {
-            DataSourceDriver dataSourceDriver1 = dataSourceDao.getDataSourceDriver(dataSourceDriver);
-            if (Blank.isNotEmpty(dataSourceDriver1)) {
-                return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已经存在此种驱动的配置了");
-            }
-            if (dataSourceDao.addDataSourceDriver(dataSourceDriver) <= 0) {
-                return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "新增驱动配置失败");
-            }
-            List<DriverBasicItem> driverBasicItemList = dataSourceDriver.getDriverBasicItemList();
-            if (Blank.isNotEmpty(driverBasicItemList)) {
-                Integer id = dataSourceDriver.getId();
-                dataSourceDao.addDriverBasicItemList(id, driverBasicItemList);
-            }
-            List<DataSource> dataSourceList = dataSourceDao.getDataSourceByclsId(dataSourceDriver.getClsId());
-            if (Blank.isNotEmpty(dataSourceList)) {
-                List<ItemGroup> itemGroupList = itemGroupDao.getIgListByDsId(dataSourceList);
-                if (Blank.isNotEmpty(itemGroupList)) {
-                    for (ItemGroup itemGroup : itemGroupList) {
-                        Integer runState = itemGroup.getRunState();
-                        if (runState.equals(ConstantStr.START_UP)) {
-                            throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此数据源配置的数据组,存在处于运行中,不能修改");
-                        }
+        DataSourceDriver dataSourceDriver1 = dataSourceDao.getDataSourceDriver(dataSourceDriver);
+        if (Blank.isNotEmpty(dataSourceDriver1)) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已经存在此种驱动的配置了");
+        }
+        if (dataSourceDao.addDataSourceDriver(dataSourceDriver) <= 0) {
+            return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "新增驱动配置失败");
+        }
+        List<DriverBasicItem> driverBasicItemList = dataSourceDriver.getDriverBasicItemList();
+        if (Blank.isNotEmpty(driverBasicItemList)) {
+            Integer id = dataSourceDriver.getId();
+            dataSourceDao.addDriverBasicItemList(id, driverBasicItemList);
+        }
+        List<DataSource> dataSourceList = dataSourceDao.getDataSourceByclsId(dataSourceDriver.getClsId());
+        if (Blank.isNotEmpty(dataSourceList)) {
+            List<ItemGroup> itemGroupList = itemGroupDao.getIgListByDsId(dataSourceList);
+            if (Blank.isNotEmpty(itemGroupList)) {
+                for (ItemGroup itemGroup : itemGroupList) {
+                    Integer runState = itemGroup.getRunState();
+                    if (runState.equals(ConstantStr.START_UP)) {
+                        throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此数据源配置的数据组,存在处于运行中,不能修改");
                     }
-                    List<Item> itemList = itemGroupDao.getItemListByGidList(itemGroupList);
-                    itemList = OpcDaUtil.genBasicDa(itemList,
-                            Blank.isEmpty(dataSourceDriver) ? null : dataSourceDriver);
-                    if (Blank.isNotEmpty(itemList)) {
-                        String strArr = "";
-                        int size = itemList.size();
-                        for (int i = 0; i < size; i++) {
-                            Item item = itemList.get(i);
-                            strArr += item.getId() + "," + item.getItemType();
-                            if (i != size - 1) {
-                                strArr += "-";
-                            }
+                }
+                List<Item> itemList = itemGroupDao.getItemListByGidList(itemGroupList);
+                itemList = OpcDaUtil.genBasicDa(itemList,
+                        Blank.isEmpty(dataSourceDriver) ? null : dataSourceDriver);
+                if (Blank.isNotEmpty(itemList)) {
+                    String strArr = "";
+                    int size = itemList.size();
+                    for (int i = 0; i < size; i++) {
+                        Item item = itemList.get(i);
+                        strArr += item.getId() + "," + item.getItemType();
+                        if (i != size - 1) {
+                            strArr += "-";
                         }
-                        itemGroupDao.updateItemTypeList(strArr, "-");
                     }
+                    itemGroupDao.updateItemTypeList(strArr, "-");
                 }
             }
-            return Result.ok("新增驱动配置成功");
-        } else {
-            throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前未适配此种类型的驱动");
         }
+        return Result.ok("新增驱动配置成功");
     }
 
     @Override
     public synchronized Result updateDataSourceDriver(DataSourceDriver dataSourceDriver) {
         String clsId = dataSourceDriver.getClsId();
-        if (OpcDaUtil.isAdapterClsId(clsId)) {
-            //查询数据库中原有的数据驱动
-            DataSourceDriver dataSouceDriver1 = dataSourceDao.getDataSourceDriverNoId(dataSourceDriver);
-            if (Blank.isNotEmpty(dataSouceDriver1)) {
-                return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已经存在此种驱动的配置了");
-            }
-            //修改数据驱动
-            if (dataSourceDao.updateDataSourceDriver(dataSourceDriver) <= 0) {
-                return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "修改驱动配置失败");
-            }
-            Integer id = dataSourceDriver.getId();
-            List<DriverBasicItem> driverBasicItemList = dataSourceDriver.getDriverBasicItemList();
-            dataSourceDao.delDriverBasicItem(id);
-            if (Blank.isNotEmpty(driverBasicItemList)) {
-                dataSourceDao.addDriverBasicItemList(id, driverBasicItemList);
-            }
-            List<DataSource> dataSourceList = dataSourceDao.getDataSourceByclsId(clsId);
-            if (Blank.isNotEmpty(dataSourceList)) {
-                List<ItemGroup> itemGroupList = itemGroupDao.getIgListByDsId(dataSourceList);
-                if (Blank.isNotEmpty(itemGroupList)) {
-                    for (ItemGroup itemGroup : itemGroupList) {
-                        Integer runState = itemGroup.getRunState();
-                        if (runState.equals(ConstantStr.START_UP)) {
-                            throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此数据源配置的数据组,存在处于运行中,不能修改");
-                        }
+        //查询数据库中原有的数据驱动
+        DataSourceDriver dataSouceDriver1 = dataSourceDao.getDataSourceDriverNoId(dataSourceDriver);
+        if (Blank.isNotEmpty(dataSouceDriver1)) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已经存在此种驱动的配置了");
+        }
+        //修改数据驱动
+        if (dataSourceDao.updateDataSourceDriver(dataSourceDriver) <= 0) {
+            return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "修改驱动配置失败");
+        }
+        Integer id = dataSourceDriver.getId();
+        List<DriverBasicItem> driverBasicItemList = dataSourceDriver.getDriverBasicItemList();
+        dataSourceDao.delDriverBasicItem(id);
+        if (Blank.isNotEmpty(driverBasicItemList)) {
+            dataSourceDao.addDriverBasicItemList(id, driverBasicItemList);
+        }
+        List<DataSource> dataSourceList = dataSourceDao.getDataSourceByclsId(clsId);
+        if (Blank.isNotEmpty(dataSourceList)) {
+            List<ItemGroup> itemGroupList = itemGroupDao.getIgListByDsId(dataSourceList);
+            if (Blank.isNotEmpty(itemGroupList)) {
+                for (ItemGroup itemGroup : itemGroupList) {
+                    Integer runState = itemGroup.getRunState();
+                    if (runState.equals(ConstantStr.START_UP)) {
+                        throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此数据源配置的数据组,存在处于运行中,不能修改");
                     }
-                    List<Item> itemList = itemGroupDao.getItemListByGidList(itemGroupList);
-                    itemList = OpcDaUtil.genBasicDa(itemList, dataSourceDriver);
-                    if (Blank.isNotEmpty(itemList)) {
-                        String strArr = "";
-                        int size = itemList.size();
-                        for (int i = 0; i < size; i++) {
-                            Item item = itemList.get(i);
-                            strArr += item.getId() + "," + item.getItemType();
-                            if (i != size - 1) {
-                                strArr += "-";
-                            }
+                }
+                List<Item> itemList = itemGroupDao.getItemListByGidList(itemGroupList);
+                itemList = OpcDaUtil.genBasicDa(itemList, dataSourceDriver);
+                if (Blank.isNotEmpty(itemList)) {
+                    String strArr = "";
+                    int size = itemList.size();
+                    for (int i = 0; i < size; i++) {
+                        Item item = itemList.get(i);
+                        strArr += item.getId() + "," + item.getItemType();
+                        if (i != size - 1) {
+                            strArr += "-";
                         }
-                        itemGroupDao.updateItemTypeList(strArr, "-");
                     }
+                    itemGroupDao.updateItemTypeList(strArr, "-");
                 }
             }
-            return Result.ok("修改驱动配置成功");
-        } else {
-            throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前未适配此种类型的驱动");
         }
+        return Result.ok("修改驱动配置成功");
     }
 
     @Override

+ 36 - 41
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/ItemGroupServiceImpl.java

@@ -145,7 +145,7 @@ public class ItemGroupServiceImpl implements ItemGroupService {
                 if (tttiCount > 0) {
                     return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "数据组在报表中配置了相应的数据项无法修改");
                 }
-                Long ttciCount =reportTableDao.getTtciCountByItemId(itemList1);
+                Long ttciCount = reportTableDao.getTtciCountByItemId(itemList1);
                 if (ttciCount > 0) {
                     return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "数据组在报表中配置了相应的数据项无法修改");
                 }
@@ -267,7 +267,7 @@ public class ItemGroupServiceImpl implements ItemGroupService {
             if (tttiCount > 0) {
                 return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "数据组在报表中配置了相应的数据项无法删除");
             }
-            Long ttciCount =reportTableDao.getTtciCountByItemId(itemList);
+            Long ttciCount = reportTableDao.getTtciCountByItemId(itemList);
             if (ttciCount > 0) {
                 return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "数据组在报表中配置了相应的数据项无法删除");
             }
@@ -284,7 +284,6 @@ public class ItemGroupServiceImpl implements ItemGroupService {
         DataSource dataSource = DataSource.convertPassword(dataSourceDao.getDataSourceById(itemGroup.getDataSourceId()));
         DataSourceType dataSourceType = dataSourceDao.getDataSourceTypeById(dataSource.getTypeId());
         String dataSourceTypeKey = dataSourceType.getDataSourceTypeKey();
-        String clsId = dataSource.getClsId().toUpperCase();
         if (OpcUtil.isOpcUa(dataSourceTypeKey)) {
             return restTemplate.postForObject(opcUaUrl + "/itemGroup/runItemGroupById?id=" + id + "&runState=" + runState,
                     new HttpEntity<>(null, new HttpHeaders()), Result.class);
@@ -296,48 +295,44 @@ public class ItemGroupServiceImpl implements ItemGroupService {
                 if (Blank.isEmpty(dataSource.getIpAddress(), dataSource.getIpUserName(), dataSource.getIpPassword())) {
                     throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "数据组配置的数据源的ip地址,帐户,密码都不能为空");
                 }
-                if (OpcDaUtil.isAdapterClsId(clsId)) {
-                    Server server = null;
-                    try {
-                        server = OpcDaUtil.createServer(dataSource);
-                        if (Blank.isEmpty(server)) {
-                            return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "创建服务失败");
-                        }
-                        server.connect();
-                    } catch (Exception e) {
-                        throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), OpcDaUtil.genException(e.getMessage()));
-                    } finally {
-                        if (Blank.isNotEmpty(server)) {
-                            server.dispose();
-                        }
+                Server server = null;
+                try {
+                    server = OpcDaUtil.createServer(dataSource);
+                    if (Blank.isEmpty(server)) {
+                        return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "创建服务失败");
                     }
-                    redisUtil.set(ConstantStr.ITEM_GROUP + id, true);
-                    //新增定时器任务
-                    String cronId = Blank.isEmpty(itemGroup.getCronId()) ?
-                            UUID.randomUUID().toString().replace("-", "") :
-                            itemGroup.getCronId();
-                    String cron = "0 0 0 ? * ";
-                    if (Blank.isEmpty(readWeek)) {
-                        cron = cron + "MON,TUE,WED,THU,FRI,SAT,SUN";
-                        //立即执行一次Timer
-                        opcDaTask.opcDaTask(itemGroup, dataSource, cronId);
-                    } else {
-                        cron = cron + readWeek;
-                        for (String str : readWeek.split(",")) {
-                            if (str.equals(DateUtil.getCurrentWeekEn())) {
-                                //立即执行一次Timer
-                                opcDaTask.opcDaTask(itemGroup, dataSource, cronId);
-                                break;
-                            }
-                        }
+                    server.connect();
+                } catch (Exception e) {
+                    throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), OpcDaUtil.genException(e.getMessage()));
+                } finally {
+                    if (Blank.isNotEmpty(server)) {
+                        server.dispose();
                     }
-                    SchedulingRunnable task = new SchedulingRunnable(OpcDaTask.class, "opcDaTask", new Object[]{itemGroup, dataSource, cronId});
-                    cronTaskRegister.addCronTask(task, cronId, cron);
-                    itemGroupDao.runItemGroupById(id, runState, cronId);
-                    return Result.ok("启动成功");
+                }
+                redisUtil.set(ConstantStr.ITEM_GROUP + id, true);
+                //新增定时器任务
+                String cronId = Blank.isEmpty(itemGroup.getCronId()) ?
+                        UUID.randomUUID().toString().replace("-", "") :
+                        itemGroup.getCronId();
+                String cron = "0 0 0 ? * ";
+                if (Blank.isEmpty(readWeek)) {
+                    cron = cron + "MON,TUE,WED,THU,FRI,SAT,SUN";
+                    //立即执行一次Timer
+                    opcDaTask.opcDaTask(itemGroup, dataSource, cronId);
                 } else {
-                    throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前未适配此种驱动类型");
+                    cron = cron + readWeek;
+                    for (String str : readWeek.split(",")) {
+                        if (str.equals(DateUtil.getCurrentWeekEn())) {
+                            //立即执行一次Timer
+                            opcDaTask.opcDaTask(itemGroup, dataSource, cronId);
+                            break;
+                        }
+                    }
                 }
+                SchedulingRunnable task = new SchedulingRunnable(OpcDaTask.class, "opcDaTask", new Object[]{itemGroup, dataSource, cronId});
+                cronTaskRegister.addCronTask(task, cronId, cron);
+                itemGroupDao.runItemGroupById(id, runState, cronId);
+                return Result.ok("启动成功");
             } else if (runState.equals(ConstantStr.STOP_IT)) {
                 redisUtil.set(ConstantStr.ITEM_GROUP + id, false);
                 itemGroupDao.stopItemGroupById(id, runState);

+ 3 - 37
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/util/OpcDaUtil.java

@@ -3,7 +3,6 @@ package com.example.opc_da.util;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.example.opc_common.entity.*;
-import com.example.opc_common.enums.OpcDaDriverEnum;
 import com.example.opc_common.enums.ResultEnum;
 import com.example.opc_common.exception.CustomException;
 import com.example.opc_common.util.Blank;
@@ -28,8 +27,6 @@ import org.openscada.opc.lib.list.Categories;
 import org.openscada.opc.lib.list.Category;
 import org.openscada.opc.lib.list.ServerList;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.Executors;
@@ -371,33 +368,6 @@ public class OpcDaUtil {
         return "通信异常(" + message + ")";
     }
 
-    /**
-     * 查看传入的这个clsId,是否在适配的驱动中
-     *
-     * @param clsId
-     * @return
-     */
-    public static Boolean isAdapterClsId(String clsId) {
-        Class<OpcDaDriverEnum> daDriverClass = OpcDaDriverEnum.class;
-        OpcDaDriverEnum[] enumConstants = daDriverClass.getEnumConstants();
-        try {
-            Method getValue = daDriverClass.getMethod("getValue");
-            for (OpcDaDriverEnum opcDaDriverEnum : enumConstants) {
-                String s = getValue.invoke(opcDaDriverEnum).toString();
-                if (clsId.toUpperCase().equals(s)) {
-                    return true;
-                }
-            }
-            return false;
-        } catch (NoSuchMethodException e) {
-            throw new RuntimeException(e);
-        } catch (InvocationTargetException e) {
-            throw new RuntimeException(e);
-        } catch (IllegalAccessException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
     public static Result getNextAllItem(DataSource dataSource, String itemStr) {
         try {
             Server server = getServer(dataSource);
@@ -405,13 +375,9 @@ public class OpcDaUtil {
                 throw new CustomException(ResultEnum.NOT_FOUND.getRespCode(), "连接失败");
             }
             if (OPCSERVERSTATE.OPC_STATUS_RUNNING == server.getServerState().getServerState()) {
-                if (isAdapterClsId(dataSource.getClsId())) {
-                    TreeBrowser treeBrowser = server.getTreeBrowser();
-                    returnServer(dataSource, server);
-                    return Result.ok(getNextItem(treeBrowser, itemStr));
-                } else {
-                    throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前未适配此种驱动类型");
-                }
+                TreeBrowser treeBrowser = server.getTreeBrowser();
+                returnServer(dataSource, server);
+                return Result.ok(getNextItem(treeBrowser, itemStr));
             }
             returnServer(dataSource, server);
         } catch (Exception e) {

+ 11 - 0
chaunyi_opc/opc_da/src/main/resources/mapper/DataSourceDao.xml

@@ -226,4 +226,15 @@
         from t_data_source
         where cls_id = #{clsId}
     </select>
+
+    <select id="getDataSourceClsId" resultType="com.example.opc_common.entity.DataSource">
+        SELECT DISTINCT
+            cls_id,
+            driver_describe
+        FROM
+            t_data_source
+        WHERE
+            cls_id IS NOT NULL
+          AND cls_id != ''
+    </select>
 </mapper>