|
@@ -47,6 +47,8 @@ public class ItemGroupServiceImpl implements ItemGroupService {
|
|
|
public synchronized Result addItemGroup(ItemGroup itemGroup) {
|
|
|
String userId = userUtil.getCurrentUserId();
|
|
|
itemGroup.setUserId(userId);
|
|
|
+ DataSource dataSource = dataSourceDao.getDataSourceById(itemGroup.getDataSourceId());
|
|
|
+ DataSourceType dataSourceType = dataSourceDao.getDataSourceTypeById(dataSource.getTypeId());
|
|
|
if (Blank.isEmpty(itemGroup.getId())) {
|
|
|
ItemGroup isExistItemGroup = itemGroupDao.getItemGroupByName(userId, itemGroup.getGroupName());
|
|
|
if (Blank.isNotEmpty(isExistItemGroup)) {
|
|
@@ -54,6 +56,29 @@ public class ItemGroupServiceImpl implements ItemGroupService {
|
|
|
}
|
|
|
itemGroupDao.addItemGroup(itemGroup);
|
|
|
if (Blank.isNotEmpty(itemGroup.getItemList())) {
|
|
|
+ if (dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_DA_REAL.getValue())) {
|
|
|
+ List<Item> itemList = itemGroup.getItemList();
|
|
|
+ if (dataSource.getClsId().equals(OpcDaDriverEnum.KEPSERVER.getValue())) {
|
|
|
+ for (int i = 0; i < itemList.size(); i++) {
|
|
|
+ itemList.get(i).setItemReadName(itemList.get(i).getItemName());
|
|
|
+ }
|
|
|
+ } else if (dataSource.getClsId().equals(OpcDaDriverEnum.OPCIFIX.getValue())) {
|
|
|
+ for (int i = 0; i < itemList.size(); i++) {
|
|
|
+ String itemName = itemList.get(i).getItemName();
|
|
|
+ int j = itemName.indexOf(".");
|
|
|
+ String s = itemName.substring(j + 1);
|
|
|
+ itemList.get(i).setItemReadName(itemName.substring(0, j) + s.substring(s.indexOf(".")));
|
|
|
+ }
|
|
|
+ } else if (dataSource.getClsId().equals(OpcDaDriverEnum.WINCC.getValue())) {
|
|
|
+ for (int i = 0; i < itemList.size(); i++) {
|
|
|
+ String itemName = itemList.get(i).getItemName();
|
|
|
+ itemList.get(i).setItemReadName(itemName.substring(itemName.lastIndexOf(".") + 1));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前未适配此种驱动类型");
|
|
|
+ }
|
|
|
+ itemGroup.setItemList(itemList);
|
|
|
+ }
|
|
|
itemGroupDao.addItem(itemGroup.getId(), itemGroup.getItemList());
|
|
|
}
|
|
|
return Result.ok("添加item组成功");
|
|
@@ -70,6 +95,29 @@ public class ItemGroupServiceImpl implements ItemGroupService {
|
|
|
if (itemGroupDao.updateItemGroup(itemGroup) <= 0) {
|
|
|
return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "修改item组失败");
|
|
|
}
|
|
|
+ if (dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_DA_REAL.getValue())) {
|
|
|
+ List<Item> itemList = itemGroup.getItemList();
|
|
|
+ if (dataSource.getClsId().equals(OpcDaDriverEnum.KEPSERVER.getValue())) {
|
|
|
+ for (int i = 0; i < itemList.size(); i++) {
|
|
|
+ itemList.get(i).setItemReadName(itemList.get(i).getItemName());
|
|
|
+ }
|
|
|
+ } else if (dataSource.getClsId().equals(OpcDaDriverEnum.OPCIFIX.getValue())) {
|
|
|
+ for (int i = 0; i < itemList.size(); i++) {
|
|
|
+ String itemName = itemList.get(i).getItemName();
|
|
|
+ int j = itemName.indexOf(".");
|
|
|
+ String s = itemName.substring(j + 1);
|
|
|
+ itemList.get(i).setItemReadName(itemName.substring(0, j) + s.substring(s.indexOf(".")));
|
|
|
+ }
|
|
|
+ } else if (dataSource.getClsId().equals(OpcDaDriverEnum.WINCC.getValue())) {
|
|
|
+ for (int i = 0; i < itemList.size(); i++) {
|
|
|
+ String itemName = itemList.get(i).getItemName();
|
|
|
+ itemList.get(i).setItemReadName(itemName.substring(itemName.lastIndexOf(".") + 1));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前未适配此种驱动类型");
|
|
|
+ }
|
|
|
+ itemGroup.setItemList(itemList);
|
|
|
+ }
|
|
|
if (Blank.isNotEmpty(itemGroup.getDataSourceId()) && Blank.isNotEmpty(itemGroup1.getDataSourceId())) {
|
|
|
if (itemGroup.getDataSourceId() == itemGroup1.getDataSourceId()) {
|
|
|
List<Item> itemList = itemGroup.getItemList();
|
|
@@ -154,6 +202,7 @@ public class ItemGroupServiceImpl implements ItemGroupService {
|
|
|
DataSourceType dataSourceType = dataSourceDao.getDataSourceTypeById(dataSource.getTypeId());
|
|
|
Boolean flage = false;
|
|
|
List<Item> allItemList = itemGroupDao.getItemListByGroupId(id);
|
|
|
+ itemGroup.setItemList(allItemList);
|
|
|
if (Blank.isNotEmpty(allItemList)) {
|
|
|
for (Item item : allItemList) {
|
|
|
if (Blank.isNotEmpty(item.getDataModelId())) {
|
|
@@ -193,15 +242,13 @@ public class ItemGroupServiceImpl implements ItemGroupService {
|
|
|
}
|
|
|
//异步读取opcUA数据并保存
|
|
|
opcAsyncTask.runOpcUa(itemGroup, dataSource, map);
|
|
|
- } else if (dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_DA_REAL.getValue()) ||
|
|
|
- dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_HDA_HISTORY.getValue()) ||
|
|
|
- dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_AE_ALARMS.getValue())
|
|
|
- ) {
|
|
|
+ } else if (dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_DA_REAL.getValue())) {
|
|
|
if (Blank.isEmpty(dataSource.getIpAddress(), dataSource.getIpUserName(), dataSource.getIpPassword())) {
|
|
|
throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "数据源ip,用户名,密码都不能为空");
|
|
|
}
|
|
|
//读取数据并保存
|
|
|
Timer timer = new Timer();
|
|
|
+ //获取读取使用的itemName
|
|
|
List<String> itemList = itemGroupDao.getItemByIdChange(id);
|
|
|
//如果驱动是kepserver,则不进行变化
|
|
|
if (dataSource.getClsId().equals(OpcDaDriverEnum.OPCIFIX.getValue())) {
|
|
@@ -213,14 +260,17 @@ public class ItemGroupServiceImpl implements ItemGroupService {
|
|
|
itemList.set(i, itemName.substring(0, j) + s.substring(s.indexOf(".")));
|
|
|
}
|
|
|
}
|
|
|
+ String[] items = itemList.toArray(new String[]{});
|
|
|
+ timer.schedule(new OpcTimerTask(redisUtil, opcAsyncTask, itemGroupDao, timer, itemGroup, dataSource, map, items),
|
|
|
+ DateUtil.strChangeDate(DateUtil.getCurrentYmd() + " " + itemGroup.getStartReadTime()), ConstantStr.PERIOD_DAY);
|
|
|
} else if (dataSource.getClsId().equals(OpcDaDriverEnum.WINCC.getValue())) {
|
|
|
|
|
|
} else {
|
|
|
throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前未适配此种驱动类型");
|
|
|
}
|
|
|
- String[] items = itemList.toArray(new String[]{});
|
|
|
- timer.schedule(new OpcTimerTask(redisUtil, opcAsyncTask, itemGroupDao, timer, itemGroup, dataSource, map, items),
|
|
|
- DateUtil.strChangeDate(DateUtil.getCurrentYmd() + " " + itemGroup.getStartReadTime()), ConstantStr.PERIOD_DAY);
|
|
|
+ } else if (dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_HDA_HISTORY.getValue()) ||
|
|
|
+ dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_AE_ALARMS.getValue())) {
|
|
|
+
|
|
|
} else if (dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.KEP_SERVER_REAL.getValue())) {
|
|
|
if (Blank.isEmpty(dataSource.getIpAddress(), dataSource.getIpUserName(), dataSource.getIpPassword())) {
|
|
|
throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "数据源ip,用户名,密码都不能为空");
|
|
@@ -281,10 +331,16 @@ public class ItemGroupServiceImpl implements ItemGroupService {
|
|
|
}
|
|
|
}
|
|
|
//读取数据并返回
|
|
|
- List<Item> itemList = itemGroupDao.getItemListByGroupId(itemGroup.getId());
|
|
|
- return Result.ok(OpcUaUtil.opcUaReadNodeIdList(dataSource, itemList, map));
|
|
|
- } else if (dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_DA_REAL.getValue()) ||
|
|
|
- dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_HDA_HISTORY.getValue()) ||
|
|
|
+ return Result.ok(OpcUaUtil.opcUaReadNodeIdList(dataSource, allItemList, map));
|
|
|
+ } else if (dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_DA_REAL.getValue())) {
|
|
|
+ if (Blank.isEmpty(dataSource.getIpAddress(), dataSource.getIpUserName(), dataSource.getIpPassword())) {
|
|
|
+ throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "数据源ip,用户名,密码都不能为空");
|
|
|
+ }
|
|
|
+ //读取数据并返回
|
|
|
+ List<String> itemStrList = itemGroupDao.getItemByIdChange(itemGroup.getId());
|
|
|
+ String[] items = itemStrList.toArray(new String[]{});
|
|
|
+ return Result.ok(OpcDaUtil.opcReadItemListValue(dataSource, items, allItemList, map));
|
|
|
+ } else if (dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_HDA_HISTORY.getValue()) ||
|
|
|
dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_AE_ALARMS.getValue())
|
|
|
) {
|
|
|
if (Blank.isEmpty(dataSource.getIpAddress(), dataSource.getIpUserName(), dataSource.getIpPassword())) {
|
|
@@ -297,10 +353,9 @@ public class ItemGroupServiceImpl implements ItemGroupService {
|
|
|
throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "数据源ip,用户名,密码都不能为空");
|
|
|
}
|
|
|
//读取数据并返回
|
|
|
- List<String> itemList = itemGroupDao.getItemByIdChange(itemGroup.getId());
|
|
|
- String[] items = itemList.toArray(new String[]{});
|
|
|
- List<Item> itemList1 = itemGroupDao.getItemListByGroupId(itemGroup.getId());
|
|
|
- return Result.ok(KepOpcServerUtil.opcReadItemListValue(dataSource, items, itemList1, map));
|
|
|
+ List<String> itemStrList = itemGroupDao.getItemByIdChange(itemGroup.getId());
|
|
|
+ String[] items = itemStrList.toArray(new String[]{});
|
|
|
+ return Result.ok(KepOpcServerUtil.opcReadItemListValue(dataSource, items, allItemList, map));
|
|
|
} else {
|
|
|
return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "目前还没有此种类型的连接方式");
|
|
|
}
|