|
@@ -1,9 +1,12 @@
|
|
|
package com.jiayue.biz.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.jiayue.biz.conf.Channel;
|
|
|
import com.jiayue.biz.domain.TunnelInfo;
|
|
|
import com.jiayue.biz.mapper.TunnelInfoMapper;
|
|
|
import com.jiayue.biz.service.TunnelInfoService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
@@ -16,21 +19,69 @@ import java.util.Map;
|
|
|
*/
|
|
|
@Service
|
|
|
public class TunnelInfoServiceImpl extends ServiceImpl<TunnelInfoMapper, TunnelInfo> implements TunnelInfoService {
|
|
|
+
|
|
|
+ @Lazy
|
|
|
+ @Autowired
|
|
|
+ Channel channel;
|
|
|
+
|
|
|
/*首页通道信息*/
|
|
|
- public List<Map<String,Object>> homepageTunnelInfo(){
|
|
|
- List<Map<String,Object>> list = new ArrayList<>();
|
|
|
+ public List<Map<String, Object>> homepageTunnelInfo() {
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
try {
|
|
|
List<TunnelInfo> tunnelInfoList = this.list();
|
|
|
- for(TunnelInfo tunnelInfo : tunnelInfoList){
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
- map.put("tunnelName",tunnelInfo.getTunnelName());
|
|
|
- map.put("address",tunnelInfo.getIp()+":"+tunnelInfo.getPort());
|
|
|
- map.put("status",tunnelInfo.getStatus());
|
|
|
+ for (TunnelInfo tunnelInfo : tunnelInfoList) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("tunnelName", tunnelInfo.getTunnelName());
|
|
|
+ map.put("address", tunnelInfo.getIp() + ":" + tunnelInfo.getPort());
|
|
|
+ map.put("status", tunnelInfo.getStatus());
|
|
|
list.add(map);
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ *
|
|
|
+ * @param tunnelInfo 通道信息
|
|
|
+ * @return true/false
|
|
|
+ */
|
|
|
+ public boolean addTunnelForMasterMap(TunnelInfo tunnelInfo) {
|
|
|
+ channel.addMasterMap(tunnelInfo);
|
|
|
+ return this.save(tunnelInfo);
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 修改
|
|
|
+ *
|
|
|
+ * @param tunnelInfo 通道信息
|
|
|
+ * @return true/false
|
|
|
+ */
|
|
|
+ public boolean updateTunnelForMasterMap(TunnelInfo tunnelInfo) {
|
|
|
+ List<TunnelInfo> tunnelInfoList = this.lambdaQuery().eq(TunnelInfo::getId, tunnelInfo.getId()).list();
|
|
|
+ if (!tunnelInfoList.get(0).getIp().equals(tunnelInfo.getIp()) || tunnelInfoList.get(0).getPort() != tunnelInfo.getPort()) {
|
|
|
+ channel.stop(tunnelInfo.getId());
|
|
|
+ channel.addMasterMap(tunnelInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.updateById(tunnelInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ *
|
|
|
+ * @param id id
|
|
|
+ * @return true/false
|
|
|
+ */
|
|
|
+ public boolean deleteTunnelForMasterMap(String id) {
|
|
|
+
|
|
|
+ channel.stop(id);
|
|
|
+
|
|
|
+ return this.removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|