作者 王勇

init commit

... ... @@ -27,20 +27,25 @@ public class BusExchangeController {
/**
* 分页查询,交换机列表
*
* @param exchangeName 交换机名称
* @param pageNum 当前页数
* @param pageSize 每页数量
* @param virtualHostId 所属虚拟主机ID
* @param exchangeName 交换机名称
* @param pageNum 当前页数
* @param pageSize 每页数量
* @return 成功返回交换机列表
*/
@GetMapping("/list")
public ResultJson<PageInfo> selectBusExchangeList(
@RequestParam(value = "virtualHostId", required = false) String virtualHostId,
@RequestParam(value = "exchangeName", required = false) String exchangeName,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
ResultJson<PageInfo> result = new ResultJson<>();
BusExchange busExchange = new BusExchange();
// 获取参数,所属虚拟主机ID
busExchange.setVirtualHostId(virtualHostId);
// 获取参数,交换机名称
busExchange.setExchangeName(exchangeName);
// 分页查询
PageInfo pageInfo = busExchangeService.selectBusExchangeList(busExchange, pageNum, pageSize);
if (pageInfo.getTotal() > 0) {
... ...
package com.sunyo.wlpt.message.bus.service.controller;
import com.github.pagehelper.PageInfo;
import com.sunyo.wlpt.message.bus.service.domain.BusServer;
import com.sunyo.wlpt.message.bus.service.domain.VirtualHost;
import com.sunyo.wlpt.message.bus.service.response.ResultJson;
import com.sunyo.wlpt.message.bus.service.service.BusServerService;
import com.sunyo.wlpt.message.bus.service.service.VirtualHostService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
... ... @@ -11,7 +13,7 @@ import java.util.List;
/**
* @author 子诚
* Description:
* Description:主要是 服务器、虚拟主机、交换机的联查
* 时间:2020/7/6 14:28
*/
@CrossOrigin
... ... @@ -21,11 +23,16 @@ public class CascadeController {
@Resource
private BusServerService busServerService;
@Resource
private VirtualHostService virtualHostService;
/**
* @return 查询服务器列表
* 仅,查询服务器列表
*
* @return {@link ResultJson}
*/
@GetMapping("/server")
public ResultJson selectList() {
public ResultJson selectServerList() {
ResultJson result = new ResultJson();
List<BusServer> busServers = busServerService.selectAll();
... ... @@ -40,4 +47,43 @@ public class CascadeController {
}
return result;
}
/**
* 仅,查询虚拟主机列表
*
* @return {@link ResultJson}
*/
@GetMapping("/host")
public ResultJson selectVirtualHostList() {
ResultJson result = new ResultJson();
List<VirtualHost> virtualHosts = virtualHostService.selectAll();
int num = virtualHosts.size();
if (num > 0) {
result.setCode("200");
result.setData(virtualHosts);
result.setMsg("查询虚拟主机,成功");
} else {
result.setCode("500");
result.setMsg("查询虚拟主机,失败");
}
return result;
}
/**
* 服务器与虚拟主机是1:n的关系
* 查询,服务器列表(包含虚拟机)
*
* @return {@link ResultJson}
*/
@GetMapping("/server_host")
public ResultJson selectServerAndHostList(){
ResultJson result = new ResultJson();
List<BusServer> servers = busServerService.selectServerAndHostList();
int num = servers.size();
if (num > 0) {
return new ResultJson("200","查询服务器列表,成功",servers);
} else {
return new ResultJson("500","查询服务器列表,失败");
}
}
}
... ...
... ... @@ -78,4 +78,5 @@ public class BusExchange implements Serializable {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date gmtModified;
private VirtualHost virtualHost;
}
... ...
... ... @@ -2,6 +2,7 @@ package com.sunyo.wlpt.message.bus.service.domain;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
... ... @@ -57,4 +58,13 @@ public class BusServer implements Serializable {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date gmtModified;
/**
* 一个服务器对应多个虚拟主机
*/
private List<VirtualHost> virtualHosts;
/**
* 服务器名称的别名
*/
private String aliasName;
}
... ...
... ... @@ -52,5 +52,13 @@ public class VirtualHost implements Serializable {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date gmtModified;
/**
* 一个虚拟主机对应一个服务器
*/
private BusServer busServer;
/**
* 虚拟主机名称的别名
*/
private String aliasName;
}
... ...
... ... @@ -83,4 +83,11 @@ public interface BusServerMapper {
* @return 服务器列表
*/
List<BusServer> selectAll();
/**
* 查询,服务器(1:n虚拟主机)的基本信息
*
* @return List<BusServer>
*/
List<BusServer> selectServerAndHostList();
}
... ...
... ... @@ -76,4 +76,11 @@ public interface VirtualHostMapper {
* @return List<VirtualHost>
*/
List<VirtualHost> validateVirtualHost(VirtualHost virtualHost);
/**
* 查询虚拟主机列表
*
* @return 虚拟主机列表
*/
List<VirtualHost> selectAll();
}
... ...
... ... @@ -84,4 +84,11 @@ public interface BusServerService {
* @return 服务器列表
*/
List<BusServer> selectAll();
/**
* 查询,服务器(1:n虚拟主机)的基本信息
*
* @return List<BusServer>
*/
List<BusServer> selectServerAndHostList();
}
... ...
... ... @@ -78,4 +78,11 @@ public interface VirtualHostService {
* @return List<VirtualHost>
*/
List<VirtualHost> validateVirtualHost(VirtualHost virtualHost);
/**
* 查询虚拟主机列表
*
* @return 虚拟主机列表
*/
List<VirtualHost> selectAll();
}
... ...
... ... @@ -98,4 +98,9 @@ public class BusServerServiceImpl implements BusServerService {
public List<BusServer> selectAll() {
return busServerMapper.selectAll();
}
@Override
public List<BusServer> selectServerAndHostList() {
return busServerMapper.selectServerAndHostList();
}
}
... ...
... ... @@ -95,4 +95,9 @@ public class VirtualHostServiceImpl implements VirtualHostService {
return virtualHostMapper.validateVirtualHost(virtualHost);
}
@Override
public List<VirtualHost> selectAll() {
return virtualHostMapper.selectAll();
}
}
... ...
... ... @@ -16,11 +16,22 @@
<result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate"/>
<result column="gmt_modified" jdbcType="TIMESTAMP" property="gmtModified"/>
</resultMap>
<!-- 该Mapper映射关系的作用,是交换机与虚拟主机的1:1的关系映射 -->
<resultMap id="ExchangeAndHostMap" extends="BaseResultMap"
type="com.sunyo.wlpt.message.bus.service.domain.BusExchange">
<association property="virtualHost" javaType="com.sunyo.wlpt.message.bus.service.domain.VirtualHost">
<id column="id" property="id"></id>
<result column="virtual_host_name" property="virtualHostName"/>
</association>
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, exchange_name, virtual_host_id, exchange_type, durability, auto_delete, internal,
arguments, description, gmt_create, gmt_modified
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
<!--@mbg.generated-->
select
... ... @@ -30,15 +41,21 @@
</select>
<!-- 获取交换机列表 -->
<select id="selectBusExchangeList" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusExchange"
resultMap="BaseResultMap">
resultMap="ExchangeAndHostMap">
select
<include refid="Base_Column_List"/>
from bus_exchange
e.id, e.exchange_name, e.virtual_host_id, e.exchange_type, e.durability, e.auto_delete, e.internal,
e.arguments, e.description, e.gmt_create, e.gmt_modified,v.virtual_host_name
from bus_exchange as e,virtual_host as v
<where>
<!-- 所属虚拟主机ID -->
<if test="virtualHostId != null and virtualHostId !=''">
e.virtual_host_id = #{virtualHostId,jdbcType=VARCHAR}
</if>
<!-- 交换机名称 -->
<if test="exchangeName != null and exchangeName !=''">
exchange_name = #{exchangeName,jdbcType=VARCHAR}
and e.exchange_name = #{exchangeName,jdbcType=VARCHAR}
</if>
and e.virtual_host_id = v.id
</where>
</select>
<!-- 校验交换机是否已存在 -->
... ...
... ... @@ -6,12 +6,25 @@
<!--@Table bus_server-->
<id column="id" jdbcType="VARCHAR" property="id"/>
<result column="server_name" jdbcType="VARCHAR" property="serverName"/>
<result column="server_name" jdbcType="VARCHAR" property="aliasName"/>
<result column="server_ip" jdbcType="VARCHAR" property="serverIp"/>
<result column="server_port" jdbcType="VARCHAR" property="serverPort"/>
<result column="description" jdbcType="VARCHAR" property="description"/>
<result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate"/>
<result column="gmt_modified" jdbcType="TIMESTAMP" property="gmtModified"/>
</resultMap>
<!-- 该Mapper映射关系的作用,是服务器与虚拟主机的1:n的关系映射 -->
<resultMap id="ServerAndVirtualHostMap" type="com.sunyo.wlpt.message.bus.service.domain.BusServer"
extends="BaseResultMap">
<collection property="virtualHosts" ofType="com.sunyo.wlpt.message.bus.service.domain.VirtualHost">
<id column="vid" jdbcType="VARCHAR" property="id"/>
<result column="virtual_host_name" jdbcType="VARCHAR" property="virtualHostName"/>
<result column="virtual_host_name" jdbcType="VARCHAR" property="aliasName"/>
</collection>
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, `server_name`, server_ip, server_port, description, gmt_create, gmt_modified
... ... @@ -26,14 +39,19 @@
</select>
<!-- 获取服务器列表,可能要级联或者懒加载 -->
<select id="selectAll" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer"
resultMap="BaseResultMap">
<select id="selectAll" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from bus_server
</select>
<!-- 查询服务器和虚拟主机基本信息(id,名称) -->
<select id="selectServerAndHostList" resultMap="ServerAndVirtualHostMap">
select
s.id,s.server_name,v.id as vid,v.virtual_host_name
from bus_server as s, virtual_host as v
where s.id = v.server_id
</select>
<!-- 获取服务器列表,分页 -->
<select id="selectBusServerList" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer"
resultMap="BaseResultMap">
... ...
... ... @@ -11,8 +11,8 @@
<result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate"/>
<result column="gmt_modified" jdbcType="TIMESTAMP" property="gmtModified"/>
</resultMap>
<!-- 该Mapper映射关系的作用,是虚拟主机与 -->
<resultMap id="ServerAndHostMap" extends="BaseResultMap"
<!-- 该Mapper映射关系的作用,是虚拟主机与服务器的1:1的关系映射 -->
<resultMap id="HostAndServerMap" extends="BaseResultMap"
type="com.sunyo.wlpt.message.bus.service.domain.VirtualHost">
<association property="busServer" javaType="com.sunyo.wlpt.message.bus.service.domain.BusServer">
<id column="id" property="id"></id>
... ... @@ -32,9 +32,9 @@
from virtual_host
where id = #{id,jdbcType=VARCHAR}
</select>
<!-- 查询虚拟主机列表,选择性 -->
<select id="selectVirtualHostList" parameterType="com.sunyo.wlpt.message.bus.service.domain.VirtualHost"
resultMap="ServerAndHostMap">
resultMap="HostAndServerMap">
select
v.id, v.virtual_host_name, v.server_id, v.description, v.gmt_create, v.gmt_modified, s.server_name
from virtual_host as v,bus_server as s
... ... @@ -83,6 +83,12 @@
</if>
</where>
</select>
<!-- 查询全部虚拟主机列表 -->
<select id="selectAll" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from virtual_host
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
<!--@mbg.generated-->
... ...