|
@@ -0,0 +1,75 @@
|
|
|
+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.ChannelSetting;
|
|
|
+import com.judong.chuanyiserver.entity.ServerInformation;
|
|
|
+import com.judong.chuanyiserver.enums.ConnectModeEnum;
|
|
|
+import com.judong.chuanyiserver.enums.ResultEnum;
|
|
|
+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 org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Transactional
|
|
|
+public class ChannelSettingServiceImpl implements ChannelSettingService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ConnectDao connectDao;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ChannelSettingDao channelSettingDao;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public synchronized Result channelSetting(ChannelSetting channelSetting) {
|
|
|
+ if (Blank.isEmpty(channelSetting.getId())) {
|
|
|
+ ChannelSetting isExistChannelSetting = channelSettingDao.getChannelBySeChName(channelSetting.getServerId(), channelSetting.getChannelName());
|
|
|
+ if (Blank.isNotEmpty(isExistChannelSetting)) {
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已经存在此标签配置,请更换标签名称");
|
|
|
+ }
|
|
|
+ if (channelSettingDao.addChannelSetting(isExistChannelSetting) <= 0) {
|
|
|
+ return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "保存标签配置失败");
|
|
|
+ }
|
|
|
+ return Result.ok("保存标签配置成功");
|
|
|
+ } else {
|
|
|
+ ChannelSetting isExistChannelSetting = channelSettingDao.getLabelByIdSeChName(channelSetting.getId(), channelSetting.getServerId(), channelSetting.getChannelName());
|
|
|
+ if (Blank.isNotEmpty(isExistChannelSetting)) {
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已经存在此标签配置,请更换标签名称");
|
|
|
+ }
|
|
|
+ if (channelSettingDao.updateChannelSetting(channelSetting) <= 0) {
|
|
|
+ return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "保存标签配置失败");
|
|
|
+ }
|
|
|
+ return Result.ok("保存标签配置成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result getChannelSetting(Integer serverId, String channelName) {
|
|
|
+ return Result.ok(channelSettingDao.getChannelBySeChName(serverId, channelName));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result getConnectTree(Integer serverId) {
|
|
|
+ ServerInformation serverInformation = connectDao.getServerInformationById(serverId);
|
|
|
+ if (Blank.isEmpty(serverInformation)) {
|
|
|
+ return Result.no(ResultEnum.NOT_FOUND.getRespCode(), ResultEnum.NOT_FOUND.getRespMsg());
|
|
|
+ }
|
|
|
+ if (serverInformation.getConnectMode() == ConnectModeEnum.KingOPCServer.getValue()) {
|
|
|
+ if (KepOpcServerUtil.validationServerInformation(serverInformation)) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ List<JSONObject> jsonObjectList = KepOpcServerUtil.opcReadItemTree(serverInformation);
|
|
|
+ jsonObject.put("tree", jsonObjectList);
|
|
|
+ return Result.ok(jsonObject);
|
|
|
+ }
|
|
|
+ return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|