123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- 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;
- import java.util.HashMap;
- import java.util.List;
- 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<>();
- 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());
- list.add(map);
- }
- } 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);
- }
- }
|