作者 王勇

服务器与虚拟主机的相关修改

... ... @@ -105,6 +105,7 @@ public class BusServerController {
*
* @param busServer {@link BusServer}
* @return {@link ResultJson}
* @throws Exception
*/
@PostMapping("/insert")
public ResultJson insertBusServer(@RequestBody BusServer busServer)
... ...
... ... @@ -5,12 +5,13 @@ 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.VirtualHostService;
import com.sunyo.wlpt.message.bus.service.utils.IdUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
import java.util.concurrent.TimeoutException;
import static com.sunyo.wlpt.message.bus.service.common.Constant.EXIST_HOST_INFO;
... ... @@ -19,6 +20,7 @@ import static com.sunyo.wlpt.message.bus.service.common.Constant.EXIST_HOST_INFO
* Description:关于MQ虚拟主机信息的控制器
* 时间:2020/7/1 14:28
*/
@Slf4j
@CrossOrigin
@RequestMapping("bus/host")
@RestController
... ... @@ -41,7 +43,8 @@ public class VirtualHostController {
@RequestParam(value = "virtualHostName", required = false) String virtualHostName,
@RequestParam(value = "serverId", required = false) String serverId,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize)
{
// 获取查询参数
VirtualHost virtualHost = VirtualHost.builder().virtualHostName(virtualHostName).serverId(serverId).build();
// 分页查询
... ... @@ -58,11 +61,15 @@ public class VirtualHostController {
* @return {@link ResultJson}
*/
@DeleteMapping("/delete")
public ResultJson deleteVirtualHost(@RequestBody VirtualHost virtualHost) throws IOException, TimeoutException
public ResultJson deleteVirtualHost(@RequestBody VirtualHost virtualHost)
{
return virtualHostService.deleteByPrimaryKey(virtualHost.getId()) > 0
? new ResultJson<>("200", "删除虚拟主机信息,成功")
: new ResultJson<>("500", "删除虚拟主机信息,失败");
try {
return virtualHostService.deleteByPrimaryKey(virtualHost.getId()) > 0
? new ResultJson<>("200", "删除虚拟主机信息,成功")
: new ResultJson<>("500", "删除虚拟主机信息,失败");
} catch (IOException | URISyntaxException e) {
return new ResultJson<>("500", "服务器异常,删除虚拟主机信息,失败");
}
}
/**
... ... @@ -72,11 +79,15 @@ public class VirtualHostController {
* @return {@link ResultJson}
*/
@GetMapping("/batchRemove")
public ResultJson batchRemoveVirtualHost(String ids) throws IOException, TimeoutException
public ResultJson batchRemoveVirtualHost(String ids)
{
return virtualHostService.deleteByPrimaryKey(ids) > 0
? new ResultJson<>("200", "批量删除虚拟主机,成功")
: new ResultJson<>("500", "批量删除虚拟主机,失败");
try {
return virtualHostService.deleteByPrimaryKey(ids) > 0
? new ResultJson<>("200", "批量删除虚拟主机,成功")
: new ResultJson<>("500", "批量删除虚拟主机,失败");
} catch (IOException | URISyntaxException e) {
return new ResultJson<>("500", "服务器异常,批量删除虚拟主机信息,失败");
}
}
/**
... ... @@ -86,7 +97,8 @@ public class VirtualHostController {
* @return {@link ResultJson}
*/
@PutMapping("/update")
public ResultJson updateVirtualHost(@RequestBody VirtualHost virtualHost) {
public ResultJson updateVirtualHost(@RequestBody VirtualHost virtualHost)
{
//先验证,修改好的核心信息(虚拟主机名称)是否已存在
String message = validateVirtualHost(virtualHost);
return message == null
... ... @@ -103,16 +115,21 @@ public class VirtualHostController {
* @return {@link ResultJson}
*/
@PostMapping("/insert")
public ResultJson insertVirtualHost(@RequestBody VirtualHost virtualHost) {
//先验证,增加的虚拟主机的核心信息(虚拟主机名称)是否已存在
String message = validateVirtualHost(virtualHost);
// 设置id
virtualHost.setId(IdUtils.generateId());
return message == null
? virtualHostService.insertSelective(virtualHost) > 0
? new ResultJson<>("200", "新增虚拟主机信息,成功")
: new ResultJson<>("500", "新增虚拟主机信息,失败")
: new ResultJson<>("400", message);
public ResultJson insertVirtualHost(@RequestBody VirtualHost virtualHost)
{
try {
//先验证,增加的虚拟主机的核心信息(虚拟主机名称)是否已存在
String message = validateVirtualHost(virtualHost);
virtualHost.setId(IdUtils.generateId());
return message == null
? virtualHostService.insertSelective(virtualHost) > 0
? new ResultJson<>("200", "新增虚拟主机信息,成功")
: new ResultJson<>("500", "新增虚拟主机信息,失败")
: new ResultJson<>("400", message);
} catch (IOException | URISyntaxException e) {
return new ResultJson<>("500", "新增虚拟主机信息失败,请检查服务器配置是否正确!");
}
}
/**
... ... @@ -121,7 +138,8 @@ public class VirtualHostController {
* @param virtualHost {@link VirtualHost}
* @return 通过,无返回消息
*/
private String validateVirtualHost(VirtualHost virtualHost) {
private String validateVirtualHost(VirtualHost virtualHost)
{
if ("".equals(virtualHost.getVirtualHostName()) || virtualHost.getVirtualHostName() == null) {
return "该虚拟主机信息中,没有虚拟主机名称";
}
... ...
... ... @@ -13,7 +13,7 @@ import java.util.List;
/**
* @author 子诚
* Description:MQ服务器静态信息表
* 时间:2020/7/1 10:02
* 时间:2020/8/12 14:07
*/
@Data
@Builder
... ... @@ -21,7 +21,7 @@ import java.util.List;
@NoArgsConstructor
public class BusServer implements Serializable {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = -5662106932282473768L;
/**
* 服务器ID
... ... @@ -44,6 +44,21 @@ public class BusServer implements Serializable {
private Integer serverPort;
/**
* 客户端的端口号
*/
private Integer clientPort;
/**
* 备用字段,超级用户的用户名
*/
private String superUsername;
/**
* 备用字段,超级用户的密码
*/
private String superPassword;
/**
* 服务器相关描述
*/
private String description;
... ... @@ -75,13 +90,4 @@ public class BusServer implements Serializable {
*/
private String aliasName;
/**
* 定义有参构造器
* 封装 BusController 的查询参数
*
* @param serverName 服务器名称
*/
public BusServer(String serverName) {
this.serverName = serverName;
}
}
}
\ No newline at end of file
... ...
... ... @@ -108,4 +108,8 @@ public class XmlData implements Serializable {
private String serverIp;
private Integer serverPort;
private String superUsername;
private String superPassword;
}
... ...
package com.sunyo.wlpt.message.bus.service.mapper;
import com.sunyo.wlpt.message.bus.service.domain.BusServer;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;import org.apache.ibatis.annotations.Param;import java.util.List;
/**
* @author 子诚
* Description:
* 时间:2020/7/1 10:02
* 时间:2020/8/12 14:07
*/
@Mapper
public interface BusServerMapper {
/**
* 删除,根据主键
* delete by primary key
*
* @param id primaryKey
* @return deleteCount
... ... @@ -23,7 +19,7 @@ public interface BusServerMapper {
int deleteByPrimaryKey(String id);
/**
* 新增
* insert record to table
*
* @param record the record
* @return insert count
... ... @@ -31,7 +27,7 @@ public interface BusServerMapper {
int insert(BusServer record);
/**
* 新增,选择性
* insert record to table selective
*
* @param record the record
* @return insert count
... ... @@ -39,7 +35,7 @@ public interface BusServerMapper {
int insertSelective(BusServer record);
/**
* 查询,根据主键
* select by primary key
*
* @param id primary key
* @return object by primary key
... ... @@ -47,36 +43,36 @@ public interface BusServerMapper {
BusServer selectByPrimaryKey(String id);
/**
* 查询,根据服务器名称
* update record selective
*
* @param serverName 服务器名称
* @return
* @param record the updated record
* @return update count
*/
BusServer selectByServerName(String serverName);
int updateByPrimaryKeySelective(BusServer record);
/**
* 查询服务器列表,选择性
* update record
*
* @param busServer 服务器以及参数
* @return 服务器列表
* @param record the updated record
* @return update count
*/
List<BusServer> selectBusServerList(BusServer busServer);
int updateByPrimaryKey(BusServer record);
/**
* 更新,选择性,根据主键
* 查询,根据服务器名称
*
* @param record the updated record
* @return update count
* @param serverName 服务器名称
* @return
*/
int updateByPrimaryKeySelective(BusServer record);
BusServer selectByServerName(String serverName);
/**
* 更新,根据主键
* 查询服务器列表,选择性
*
* @param record the updated record
* @return update count
* @param busServer 服务器以及参数
* @return 服务器列表
*/
int updateByPrimaryKey(BusServer record);
List<BusServer> selectBusServerList(BusServer busServer);
/**
* 先校验该服务器名称是否存在
... ... @@ -124,4 +120,4 @@ public interface BusServerMapper {
* @return List<BusServer>
*/
List<BusServer> selectServerExist(@Param("serverName") String serverName);
}
}
\ No newline at end of file
... ...
... ... @@ -35,6 +35,7 @@ public interface BusServerService {
*
* @param record the record
* @return insert count
* @throws Exception
*/
int insertSelective(BusServer record);
... ... @@ -127,3 +128,4 @@ public interface BusServerService {
*/
List<BusServer> selectServerExist(String serverName);
}
... ...
... ... @@ -4,8 +4,8 @@ import com.github.pagehelper.PageInfo;
import com.sunyo.wlpt.message.bus.service.domain.VirtualHost;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
import java.util.concurrent.TimeoutException;
/**
* @author 子诚
... ... @@ -20,7 +20,7 @@ public interface VirtualHostService {
* @param id primaryKey
* @return deleteCount
*/
int deleteByPrimaryKey(String id) throws IOException, TimeoutException;
int deleteByPrimaryKey(String id) throws IOException, URISyntaxException;
/**
* 新增
... ... @@ -36,7 +36,7 @@ public interface VirtualHostService {
* @param record the record
* @return insert count
*/
int insertSelective(VirtualHost record);
int insertSelective(VirtualHost record) throws IOException, URISyntaxException;
/**
* 查询,根据主键
... ...
... ... @@ -6,6 +6,7 @@ import com.sunyo.wlpt.message.bus.service.domain.*;
import com.sunyo.wlpt.message.bus.service.mapper.BusServerMapper;
import com.sunyo.wlpt.message.bus.service.rabbit.utils.RabbitUtils;
import com.sunyo.wlpt.message.bus.service.service.*;
import com.sunyo.wlpt.message.bus.service.utils.EncryptionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
... ... @@ -100,9 +101,12 @@ public class BusServerServiceImpl implements BusServerService {
}
@Override
public int insertSelective(BusServer record)
public int insertSelective(BusServer server)
{
return busServerMapper.insertSelective(record);
// 超级用户的密码,设计规则(超级用户名+.+超级用户密码)
String key = server.getSuperUsername() + "." + server.getSuperPassword();
server.setSuperPassword(EncryptionUtils.encryptBase64(key));
return busServerMapper.insertSelective(server);
}
@Override
... ... @@ -194,3 +198,4 @@ public class BusServerServiceImpl implements BusServerService {
}
}
}
... ...
... ... @@ -4,9 +4,10 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sunyo.wlpt.message.bus.service.domain.BusExchange;
import com.sunyo.wlpt.message.bus.service.domain.BusQueue;
import com.sunyo.wlpt.message.bus.service.domain.UserMessageBinding;
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.mapper.VirtualHostMapper;
import com.sunyo.wlpt.message.bus.service.rabbit.utils.ClientUtils;
import com.sunyo.wlpt.message.bus.service.rabbit.utils.RabbitUtils;
import com.sunyo.wlpt.message.bus.service.service.*;
import org.springframework.stereotype.Service;
... ... @@ -15,8 +16,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
import java.util.concurrent.TimeoutException;
/**
* @author 子诚
... ... @@ -30,6 +31,9 @@ public class VirtualHostServiceImpl implements VirtualHostService {
private VirtualHostMapper virtualHostMapper;
@Resource
private BusServerService busServerService;
@Resource
private RabbitUtils rabbitUtils;
@Resource
... ... @@ -46,7 +50,7 @@ public class VirtualHostServiceImpl implements VirtualHostService {
@Override
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public int deleteByPrimaryKey(String id) throws IOException, TimeoutException
public int deleteByPrimaryKey(String id) throws IOException, URISyntaxException
{
// 判断删除的个数,需被删除的个数是否一致
int index = 0;
... ... @@ -83,10 +87,18 @@ public class VirtualHostServiceImpl implements VirtualHostService {
return virtualHostMapper.insert(record);
}
/**
* 创建虚拟主机于MQ服务器
* <p>
* 存储于数据库
*/
@Override
public int insertSelective(VirtualHost record)
public int insertSelective(VirtualHost vHost) throws IOException, URISyntaxException
{
return virtualHostMapper.insertSelective(record);
BusServer busServer = busServerService.selectByPrimaryKey(vHost.getServerId());
int num = virtualHostMapper.insertSelective(vHost);
ClientUtils.createVirtualHost(busServer, vHost);
return num;
}
@Override
... ... @@ -152,23 +164,20 @@ public class VirtualHostServiceImpl implements VirtualHostService {
return virtualHostMapper.deleteByServerId(serverId);
}
public void virtualHostCascadeDelete(VirtualHost virtualHost) throws IOException, TimeoutException
/**
* 先删除MQ服务器上的虚拟主机,再删除数据库表中的所有相关字段
*/
public void virtualHostCascadeDelete(VirtualHost virtualHost) throws IOException, URISyntaxException
{
BusServer busServer = busServerService.selectByPrimaryKey(virtualHost.getServerId());
ClientUtils.deleteVirtualHost(busServer, virtualHost.getVirtualHostName());
String virtualHostId = virtualHost.getId();
List<UserMessageBinding> bindings = userMessageBindingService.selectByVirtualHostId(virtualHostId);
// 1.1、删除数据库中的绑定关系
userMessageBindingService.deleteByVirtualHostId(virtualHostId);
for (UserMessageBinding userMessageBinding : bindings) {
// 1.2、解除MQ服务器上的绑定关系
rabbitUtils.toRemoveBinding(userMessageBinding);
}
List<BusQueue> queues = busQueueService.selectByVirtualHostId(virtualHostId);
// 2.1、删除数据库中对应的队列
busQueueService.deleteByVirtualHostId(virtualHostId);
for (BusQueue queue : queues) {
// 2.2、删除MQ服务器上的队列
rabbitUtils.toRemoveQueue(queue);
}
List<BusExchange> exchanges = busExchangeService.selectByVirtualHostId(virtualHostId);
// 3.1 根据虚拟主机id,删除交换机
busExchangeService.deleteByVirtualHostId(virtualHostId);
... ... @@ -176,8 +185,6 @@ public class VirtualHostServiceImpl implements VirtualHostService {
String exchangeId = busExchange.getId();
// 4.1、删除数据库中对应的路由键
routingKeyService.deleteByExchangeId(exchangeId);
// 3.2 在MQ服务器上删除该交换机
rabbitUtils.toRemoveExchange(busExchange);
}
}
}
... ...
package com.sunyo.wlpt.message.bus.service.utils;
import org.springframework.util.DigestUtils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import java.io.IOException;
/**
* @author 子诚
* Description:各种常用的加密与解密
* 时间:2020/8/12 15:22
*/
public class EncryptionUtils {
/**
* Base64加密,重载
*
* @param key 需要Base64加密的属性
* @return
*/
public static String encryptBase64(byte[] key)
{
return (new BASE64Encoder()).encodeBuffer(key);
}
/**
* Base64加密,重载
*
* @param key 需要Base64加密的属性
* @return
*/
public static String encryptBase64(String key)
{
byte[] newKey = key.getBytes();
return (new BASE64Encoder()).encodeBuffer(newKey);
}
/**
* Base64解密,重载
*
* @param key 需要Base64解密的属性
* @return
* @throws IOException
*/
public static byte[] decryptBase(String key) throws IOException
{
return (new BASE64Decoder()).decodeBuffer(key);
}
/**
* Base64解密,重载
*
* @param key 需要Base64解密的属性
* @return
* @throws Exception
*/
public static String decryptBase64(String key) throws IOException
{
byte[] bytes = (new BASE64Decoder()).decodeBuffer(key);
if (bytes == null) {
return null;
}
String str = new String(bytes);
return str;
}
/**
* MD5加密
*
* @param key 需要MD5加密的属性
* @return
*/
private static String encryptionKey(String key)
{
return DigestUtils.md5DigestAsHex(key.getBytes());
}
}
... ...
... ... @@ -147,6 +147,11 @@ public class XmlUtils {
xmlData.setServerPort(serverList.get(0).getServerPort());
// 获取服务器port
xmlData.setServerIp(serverList.get(0).getServerIp());
// 获取超级用户名称
xmlData.setSuperUsername(serverList.get(0).getSuperUsername());
// 获取超级用户密码
xmlData.setSuperPassword(serverList.get(0).getSuperPassword());
ResultJson<XmlData> result = new ResultJson<>("200", "通过格式与数据校验", xmlData);
return result;
... ...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sunyo.wlpt.message.bus.service.mapper.BusServerMapper">
<cache-ref namespace="com.sunyo.wlpt.message.bus.service.mapper.VirtualHostMapper"/>
<resultMap id="BaseResultMap" type="com.sunyo.wlpt.message.bus.service.domain.BusServer">
<!--@mbg.generated-->
<!--@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="INTEGER" 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"/>
<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="INTEGER" property="serverPort"/>
<result column="client_port" jdbcType="INTEGER" property="clientPort"/>
<result column="super_username" jdbcType="VARCHAR" property="superUsername"/>
<result column="super_password" jdbcType="VARCHAR" property="superPassword"/>
<result column="description" jdbcType="VARCHAR" property="description"/>
<result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate"/>
<result column="gmt_modified" jdbcType="TIMESTAMP" property="gmtModified"/>
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, `server_name`, server_ip, server_port, client_port, super_username, super_password,
description, gmt_create, gmt_modified
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
<!--@mbg.generated-->
select
<include refid="Base_Column_List"/>
from bus_server
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
<!--@mbg.generated-->
delete
from bus_server
where id = #{id,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer">
<!--@mbg.generated-->
insert into bus_server (id, `server_name`, server_ip,
server_port, client_port, super_username,
super_password, description, gmt_create,
gmt_modified)
values (#{id,jdbcType=VARCHAR}, #{serverName,jdbcType=VARCHAR}, #{serverIp,jdbcType=VARCHAR},
#{serverPort,jdbcType=INTEGER}, #{clientPort,jdbcType=INTEGER}, #{superUsername,jdbcType=VARCHAR},
#{superPassword,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{gmtCreate,jdbcType=TIMESTAMP},
#{gmtModified,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer">
<!--@mbg.generated-->
insert into bus_server
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="serverName != null">
`server_name`,
</if>
<if test="serverIp != null">
server_ip,
</if>
<if test="serverPort != null">
server_port,
</if>
<if test="clientPort != null">
client_port,
</if>
<if test="superUsername != null">
super_username,
</if>
<if test="superPassword != null">
super_password,
</if>
<if test="description != null">
description,
</if>
<if test="gmtCreate != null">
gmt_create,
</if>
<if test="gmtModified != null">
gmt_modified,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
</if>
<if test="serverName != null">
#{serverName,jdbcType=VARCHAR},
</if>
<if test="serverIp != null">
#{serverIp,jdbcType=VARCHAR},
</if>
<if test="serverPort != null">
#{serverPort,jdbcType=INTEGER},
</if>
<if test="clientPort != null">
#{clientPort,jdbcType=INTEGER},
</if>
<if test="superUsername != null">
#{superUsername,jdbcType=VARCHAR},
</if>
<if test="superPassword != null">
#{superPassword,jdbcType=VARCHAR},
</if>
<if test="description != null">
#{description,jdbcType=VARCHAR},
</if>
<if test="gmtCreate != null">
#{gmtCreate,jdbcType=TIMESTAMP},
</if>
<if test="gmtModified != null">
#{gmtModified,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer">
<!--@mbg.generated-->
update bus_server
<set>
<if test="serverName != null">
`server_name` = #{serverName,jdbcType=VARCHAR},
</if>
<if test="serverIp != null">
server_ip = #{serverIp,jdbcType=VARCHAR},
</if>
<if test="serverPort != null">
server_port = #{serverPort,jdbcType=INTEGER},
</if>
<if test="clientPort != null">
client_port = #{clientPort,jdbcType=INTEGER},
</if>
<if test="superUsername != null">
super_username = #{superUsername,jdbcType=VARCHAR},
</if>
<if test="superPassword != null">
super_password = #{superPassword,jdbcType=VARCHAR},
</if>
<if test="description != null">
description = #{description,jdbcType=VARCHAR},
</if>
<if test="gmtCreate != null">
gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
</if>
<if test="gmtModified != null">
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer">
<!--@mbg.generated-->
update bus_server
set `server_name` = #{serverName,jdbcType=VARCHAR},
server_ip = #{serverIp,jdbcType=VARCHAR},
server_port = #{serverPort,jdbcType=INTEGER},
client_port = #{clientPort,jdbcType=INTEGER},
super_username = #{superUsername,jdbcType=VARCHAR},
super_password = #{superPassword,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=VARCHAR}
</update>
<cache-ref namespace="com.sunyo.wlpt.message.bus.service.mapper.VirtualHostMapper"/>
<!-- 该Mapper映射关系的作用,是服务器与虚拟主机的1:n的关系映射 -->
<resultMap id="ServerAndVirtualHostMap" type="com.sunyo.wlpt.message.bus.service.domain.BusServer"
extends="BaseResultMap">
<collection property="aliasList" ofType="com.sunyo.wlpt.message.bus.service.domain.VirtualHost">
<resultMap extends="BaseResultMap" id="ServerAndVirtualHostMap"
type="com.sunyo.wlpt.message.bus.service.domain.BusServer">
<collection ofType="com.sunyo.wlpt.message.bus.service.domain.VirtualHost" property="aliasList">
<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"/>
<result column="server_id" jdbcType="VARCHAR" property="serverId"/>
</collection>
</resultMap>
<!-- 该Mapper映射关系的作用,服务器:虚拟主机—>1:n ; 虚拟主机:交换机—>1:n 的关系映射 -->
<resultMap id="ServerAndHostAndExchangeMap" type="com.sunyo.wlpt.message.bus.service.domain.BusServer"
extends="BaseResultMap">
<collection property="aliasList" ofType="com.sunyo.wlpt.message.bus.service.domain.VirtualHost">
<!-- 该Mapper映射关系的作用,服务器:虚拟主机—&gt;1:n ; 虚拟主机:交换机—&gt;1:n 的关系映射 -->
<resultMap extends="BaseResultMap" id="ServerAndHostAndExchangeMap"
type="com.sunyo.wlpt.message.bus.service.domain.BusServer">
<collection ofType="com.sunyo.wlpt.message.bus.service.domain.VirtualHost" property="aliasList">
<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 property="aliasList" ofType="com.sunyo.wlpt.message.bus.service.domain.BusExchange">
<collection ofType="com.sunyo.wlpt.message.bus.service.domain.BusExchange" property="aliasList">
<id column="eid" jdbcType="VARCHAR" property="id"/>
<result column="exchange_name" jdbcType="VARCHAR" property="exchangeName"/>
<result column="exchange_name" jdbcType="VARCHAR" property="aliasName"/>
... ... @@ -38,28 +187,6 @@
</collection>
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, `server_name`, server_ip, server_port, description, gmt_create, gmt_modified
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
<!--@mbg.generated-->
select
<include refid="Base_Column_List"/>
from bus_server
where id = #{id,jdbcType=VARCHAR}
</select>
<select id="selectByServerName" parameterType="java.lang.String" resultMap="BaseResultMap">
<!--@mbg.generated-->
select
<include refid="Base_Column_List"/>
from bus_server
where server_name = #{serverName,jdbcType=VARCHAR}
</select>
<!-- 获取服务器列表,可能要级联或者懒加载 -->
<select id="getServerList" resultMap="BaseResultMap">
select
... ... @@ -72,7 +199,8 @@
select s.id,
s.server_name,
v.id as vid,
v.virtual_host_name
v.virtual_host_name,
v.server_id
from bus_server as s,
virtual_host as v
where s.id = v.server_id
... ... @@ -92,11 +220,19 @@
where s.id = v.server_id
and v.id = e.virtual_host_id
</select>
<!-- 获取服务器列表,分页 -->
<select id="selectBusServerList" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer"
resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
select id,
`server_name`,
server_ip,
server_port,
client_port,
super_username,
description,
gmt_create,
gmt_modified
from bus_server
<where>
<!-- 服务器名称 -->
... ... @@ -119,6 +255,7 @@
</if>
</where>
</select>
<!-- 再校验服务器信息(服务器的ip,服务器的port)是否同时存在 -->
<select id="validateBusServer" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer"
resultMap="BaseResultMap">
... ... @@ -137,107 +274,13 @@
</where>
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
<select id="selectByServerName" parameterType="java.lang.String" resultMap="BaseResultMap">
<!--@mbg.generated-->
delete
select
<include refid="Base_Column_List"/>
from bus_server
where id = #{id,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer">
<!--@mbg.generated-->
insert into bus_server (id, `server_name`, server_ip,
server_port, description, gmt_create,
gmt_modified)
values (#{id,jdbcType=VARCHAR}, #{serverName,jdbcType=VARCHAR}, #{serverIp,jdbcType=VARCHAR},
#{serverPort,jdbcType=INTEGER}, #{description,jdbcType=VARCHAR}, #{gmtCreate,jdbcType=TIMESTAMP},
#{gmtModified,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer">
<!--@mbg.generated-->
insert into bus_server
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="serverName != null">
`server_name`,
</if>
<if test="serverIp != null">
server_ip,
</if>
<if test="serverPort != null">
server_port,
</if>
<if test="description != null">
description,
</if>
<if test="gmtCreate != null">
gmt_create,
</if>
<if test="gmtModified != null">
gmt_modified,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
</if>
<if test="serverName != null">
#{serverName,jdbcType=VARCHAR},
</if>
<if test="serverIp != null">
#{serverIp,jdbcType=VARCHAR},
</if>
<if test="serverPort != null">
#{serverPort,jdbcType=INTEGER},
</if>
<if test="description != null">
#{description,jdbcType=VARCHAR},
</if>
<if test="gmtCreate != null">
#{gmtCreate,jdbcType=TIMESTAMP},
</if>
<if test="gmtModified != null">
#{gmtModified,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer">
<!--@mbg.generated-->
update bus_server
<set>
<if test="serverName != null">
`server_name` = #{serverName,jdbcType=VARCHAR},
</if>
<if test="serverIp != null">
server_ip = #{serverIp,jdbcType=VARCHAR},
</if>
<if test="serverPort != null">
server_port = #{serverPort,jdbcType=INTEGER},
</if>
<if test="description != null">
description = #{description,jdbcType=VARCHAR},
</if>
<if test="gmtCreate != null">
gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
</if>
<if test="gmtModified != null">
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusServer">
<!--@mbg.generated-->
update bus_server
set `server_name` = #{serverName,jdbcType=VARCHAR},
server_ip = #{serverIp,jdbcType=VARCHAR},
server_port = #{serverPort,jdbcType=INTEGER},
description = #{description,jdbcType=VARCHAR},
gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=VARCHAR}
</update>
where server_name = #{serverName,jdbcType=VARCHAR}
</select>
<select id="selectServerExist" parameterType="java.lang.String" resultMap="BaseResultMap">
<!--@mbg.generated-->
... ... @@ -246,4 +289,4 @@
from bus_server
where server_name = #{serverName,jdbcType=VARCHAR}
</select>
</mapper>
</mapper>
\ No newline at end of file
... ...