|
@@ -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
|