正在显示
21 个修改的文件
包含
447 行增加
和
28 行删除
| @@ -8,7 +8,9 @@ import com.sunyo.wlpt.message.bus.service.utils.IdUtils; | @@ -8,7 +8,9 @@ import com.sunyo.wlpt.message.bus.service.utils.IdUtils; | ||
| 8 | import org.springframework.web.bind.annotation.*; | 8 | import org.springframework.web.bind.annotation.*; |
| 9 | 9 | ||
| 10 | import javax.annotation.Resource; | 10 | import javax.annotation.Resource; |
| 11 | +import java.io.IOException; | ||
| 11 | import java.util.List; | 12 | import java.util.List; |
| 13 | +import java.util.concurrent.TimeoutException; | ||
| 12 | 14 | ||
| 13 | import static com.sunyo.wlpt.message.bus.service.common.Constant.EXIST_SERVERNAME; | 15 | import static com.sunyo.wlpt.message.bus.service.common.Constant.EXIST_SERVERNAME; |
| 14 | import static com.sunyo.wlpt.message.bus.service.common.Constant.EXIST_SERVER_INFO; | 16 | import static com.sunyo.wlpt.message.bus.service.common.Constant.EXIST_SERVER_INFO; |
| @@ -56,7 +58,7 @@ public class BusServerController { | @@ -56,7 +58,7 @@ public class BusServerController { | ||
| 56 | * @return {@link ResultJson} | 58 | * @return {@link ResultJson} |
| 57 | */ | 59 | */ |
| 58 | @DeleteMapping("/delete") | 60 | @DeleteMapping("/delete") |
| 59 | - public ResultJson deleteBusServer(@RequestBody BusServer busServer) | 61 | + public ResultJson deleteBusServer(@RequestBody BusServer busServer) throws IOException, TimeoutException |
| 60 | { | 62 | { |
| 61 | return busServerService.deleteByPrimaryKey(busServer.getId()) > 0 | 63 | return busServerService.deleteByPrimaryKey(busServer.getId()) > 0 |
| 62 | ? new ResultJson<>("200", "删除MQ服务器,成功") | 64 | ? new ResultJson<>("200", "删除MQ服务器,成功") |
| @@ -70,7 +72,7 @@ public class BusServerController { | @@ -70,7 +72,7 @@ public class BusServerController { | ||
| 70 | * @return {@link ResultJson} | 72 | * @return {@link ResultJson} |
| 71 | */ | 73 | */ |
| 72 | @GetMapping("/batchRemove") | 74 | @GetMapping("/batchRemove") |
| 73 | - public ResultJson batchRemoveBusServer(String ids) | 75 | + public ResultJson batchRemoveBusServer(String ids) throws IOException, TimeoutException |
| 74 | { | 76 | { |
| 75 | return busServerService.deleteByPrimaryKey(ids) > 0 | 77 | return busServerService.deleteByPrimaryKey(ids) > 0 |
| 76 | ? new ResultJson<>("200", "批量删除服务器,成功") | 78 | ? new ResultJson<>("200", "批量删除服务器,成功") |
| @@ -8,7 +8,9 @@ import com.sunyo.wlpt.message.bus.service.utils.IdUtils; | @@ -8,7 +8,9 @@ import com.sunyo.wlpt.message.bus.service.utils.IdUtils; | ||
| 8 | import org.springframework.web.bind.annotation.*; | 8 | import org.springframework.web.bind.annotation.*; |
| 9 | 9 | ||
| 10 | import javax.annotation.Resource; | 10 | import javax.annotation.Resource; |
| 11 | +import java.io.IOException; | ||
| 11 | import java.util.List; | 12 | import java.util.List; |
| 13 | +import java.util.concurrent.TimeoutException; | ||
| 12 | 14 | ||
| 13 | import static com.sunyo.wlpt.message.bus.service.common.Constant.EXIST_HOST_INFO; | 15 | import static com.sunyo.wlpt.message.bus.service.common.Constant.EXIST_HOST_INFO; |
| 14 | 16 | ||
| @@ -56,7 +58,8 @@ public class VirtualHostController { | @@ -56,7 +58,8 @@ public class VirtualHostController { | ||
| 56 | * @return {@link ResultJson} | 58 | * @return {@link ResultJson} |
| 57 | */ | 59 | */ |
| 58 | @DeleteMapping("/delete") | 60 | @DeleteMapping("/delete") |
| 59 | - public ResultJson deleteVirtualHost(@RequestBody VirtualHost virtualHost) { | 61 | + public ResultJson deleteVirtualHost(@RequestBody VirtualHost virtualHost) throws IOException, TimeoutException |
| 62 | + { | ||
| 60 | return virtualHostService.deleteByPrimaryKey(virtualHost.getId()) > 0 | 63 | return virtualHostService.deleteByPrimaryKey(virtualHost.getId()) > 0 |
| 61 | ? new ResultJson<>("200", "删除虚拟主机信息,成功") | 64 | ? new ResultJson<>("200", "删除虚拟主机信息,成功") |
| 62 | : new ResultJson<>("500", "删除虚拟主机信息,失败"); | 65 | : new ResultJson<>("500", "删除虚拟主机信息,失败"); |
| @@ -69,7 +72,8 @@ public class VirtualHostController { | @@ -69,7 +72,8 @@ public class VirtualHostController { | ||
| 69 | * @return {@link ResultJson} | 72 | * @return {@link ResultJson} |
| 70 | */ | 73 | */ |
| 71 | @GetMapping("/batchRemove") | 74 | @GetMapping("/batchRemove") |
| 72 | - public ResultJson batchRemoveVirtualHost(String ids) { | 75 | + public ResultJson batchRemoveVirtualHost(String ids) throws IOException, TimeoutException |
| 76 | + { | ||
| 73 | return virtualHostService.deleteByPrimaryKey(ids) > 0 | 77 | return virtualHostService.deleteByPrimaryKey(ids) > 0 |
| 74 | ? new ResultJson<>("200", "批量删除虚拟主机,成功") | 78 | ? new ResultJson<>("200", "批量删除虚拟主机,成功") |
| 75 | : new ResultJson<>("500", "批量删除虚拟主机,失败"); | 79 | : new ResultJson<>("500", "批量删除虚拟主机,失败"); |
| @@ -22,6 +22,13 @@ public interface BusExchangeMapper { | @@ -22,6 +22,13 @@ public interface BusExchangeMapper { | ||
| 22 | int deleteByPrimaryKey(String id); | 22 | int deleteByPrimaryKey(String id); |
| 23 | 23 | ||
| 24 | /** | 24 | /** |
| 25 | + * 根据虚拟主机删除交换机 | ||
| 26 | + * | ||
| 27 | + * @param virtualHostId 虚拟主机id | ||
| 28 | + * @return | ||
| 29 | + */ | ||
| 30 | + int deleteByVirtualHostId(String virtualHostId); | ||
| 31 | + /** | ||
| 25 | * 新增 | 32 | * 新增 |
| 26 | * | 33 | * |
| 27 | * @param record the record | 34 | * @param record the record |
| @@ -92,4 +99,13 @@ public interface BusExchangeMapper { | @@ -92,4 +99,13 @@ public interface BusExchangeMapper { | ||
| 92 | * @return List<BusExchange> | 99 | * @return List<BusExchange> |
| 93 | */ | 100 | */ |
| 94 | List<BusExchange> selectExchangeExist(BusExchange exchange); | 101 | List<BusExchange> selectExchangeExist(BusExchange exchange); |
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * 查询交换机列表,根据虚拟主机id | ||
| 105 | + * | ||
| 106 | + * @param virtualHostId 虚拟主机 | ||
| 107 | + * @return | ||
| 108 | + */ | ||
| 109 | + List<BusExchange> selectByVirtualHostId(String virtualHostId); | ||
| 110 | + | ||
| 95 | } | 111 | } |
| @@ -19,6 +19,14 @@ public interface BusQueueMapper { | @@ -19,6 +19,14 @@ public interface BusQueueMapper { | ||
| 19 | int deleteByPrimaryKey(String id); | 19 | int deleteByPrimaryKey(String id); |
| 20 | 20 | ||
| 21 | /** | 21 | /** |
| 22 | + * 删除队列,根据虚拟主机id | ||
| 23 | + * | ||
| 24 | + * @param virtualHostId 虚拟主机id | ||
| 25 | + * @return | ||
| 26 | + */ | ||
| 27 | + int deleteByVirtualHostId(String virtualHostId); | ||
| 28 | + | ||
| 29 | + /** | ||
| 22 | * insert record to table | 30 | * insert record to table |
| 23 | * | 31 | * |
| 24 | * @param record the record | 32 | * @param record the record |
| @@ -43,6 +51,14 @@ public interface BusQueueMapper { | @@ -43,6 +51,14 @@ public interface BusQueueMapper { | ||
| 43 | BusQueue selectByPrimaryKey(String id); | 51 | BusQueue selectByPrimaryKey(String id); |
| 44 | 52 | ||
| 45 | /** | 53 | /** |
| 54 | + * 根据虚拟主机id,查询队列列表 | ||
| 55 | + * | ||
| 56 | + * @param virtualHostId 虚拟主机id | ||
| 57 | + * @return | ||
| 58 | + */ | ||
| 59 | + List<BusQueue> selectByVirtualHostId(String virtualHostId); | ||
| 60 | + | ||
| 61 | + /** | ||
| 46 | * update record selective | 62 | * update record selective |
| 47 | * | 63 | * |
| 48 | * @param record the updated record | 64 | * @param record the updated record |
| @@ -47,6 +47,22 @@ public interface UserMessageBindingMapper { | @@ -47,6 +47,22 @@ public interface UserMessageBindingMapper { | ||
| 47 | int deleteByRoutingKeyId(String routingKeyId); | 47 | int deleteByRoutingKeyId(String routingKeyId); |
| 48 | 48 | ||
| 49 | /** | 49 | /** |
| 50 | + * 删除配置关系 | ||
| 51 | + * | ||
| 52 | + * @param virtualHostId 虚拟主机id | ||
| 53 | + * @return | ||
| 54 | + */ | ||
| 55 | + int deleteByVirtualHostId(String virtualHostId); | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * 根据服务器id,删除绑定关系 | ||
| 59 | + * | ||
| 60 | + * @param serverId 服务器id | ||
| 61 | + * @return | ||
| 62 | + */ | ||
| 63 | + int deleteByServerId(String serverId); | ||
| 64 | + | ||
| 65 | + /** | ||
| 50 | * insert record to table | 66 | * insert record to table |
| 51 | * | 67 | * |
| 52 | * @param record the record | 68 | * @param record the record |
| @@ -79,6 +95,22 @@ public interface UserMessageBindingMapper { | @@ -79,6 +95,22 @@ public interface UserMessageBindingMapper { | ||
| 79 | List<UserMessageBinding> selectByRoutingKeyId(String routingKeyId); | 95 | List<UserMessageBinding> selectByRoutingKeyId(String routingKeyId); |
| 80 | 96 | ||
| 81 | /** | 97 | /** |
| 98 | + * 根据虚拟主机id,查询配置关系列表 | ||
| 99 | + * | ||
| 100 | + * @param virtualHostId 虚拟主机id | ||
| 101 | + * @return List<UserMessageBinding> | ||
| 102 | + */ | ||
| 103 | + List<UserMessageBinding> selectByVirtualHostId(String virtualHostId); | ||
| 104 | + | ||
| 105 | + /** | ||
| 106 | + * 根据服务器id,查询配置关系列表 | ||
| 107 | + * | ||
| 108 | + * @param serverId 服务器id | ||
| 109 | + * @return List<UserMessageBinding> | ||
| 110 | + */ | ||
| 111 | + List<UserMessageBinding> selectByServerId(String serverId); | ||
| 112 | + | ||
| 113 | + /** | ||
| 82 | * update record selective | 114 | * update record selective |
| 83 | * | 115 | * |
| 84 | * @param record the updated record | 116 | * @param record the updated record |
| @@ -22,6 +22,14 @@ public interface VirtualHostMapper { | @@ -22,6 +22,14 @@ public interface VirtualHostMapper { | ||
| 22 | int deleteByPrimaryKey(String id); | 22 | int deleteByPrimaryKey(String id); |
| 23 | 23 | ||
| 24 | /** | 24 | /** |
| 25 | + * 根据服务器id,删除虚拟主机 | ||
| 26 | + * | ||
| 27 | + * @param serverId 服务器id | ||
| 28 | + * @return | ||
| 29 | + */ | ||
| 30 | + int deleteByServerId(String serverId); | ||
| 31 | + | ||
| 32 | + /** | ||
| 25 | * 新增 | 33 | * 新增 |
| 26 | * | 34 | * |
| 27 | * @param record the record | 35 | * @param record the record |
| @@ -46,6 +54,14 @@ public interface VirtualHostMapper { | @@ -46,6 +54,14 @@ public interface VirtualHostMapper { | ||
| 46 | VirtualHost selectByPrimaryKey(String id); | 54 | VirtualHost selectByPrimaryKey(String id); |
| 47 | 55 | ||
| 48 | /** | 56 | /** |
| 57 | + * 根据服务器id,查询虚拟主机列表 | ||
| 58 | + * | ||
| 59 | + * @param serverId 服务器id | ||
| 60 | + * @return | ||
| 61 | + */ | ||
| 62 | + List<VirtualHost> selectByServerId(String serverId); | ||
| 63 | + | ||
| 64 | + /** | ||
| 49 | * 更新,选择性,根据主键 | 65 | * 更新,选择性,根据主键 |
| 50 | * | 66 | * |
| 51 | * @param record the updated record | 67 | * @param record the updated record |
| @@ -96,4 +96,20 @@ public interface BusExchangeService { | @@ -96,4 +96,20 @@ public interface BusExchangeService { | ||
| 96 | * @return List<BusExchange> | 96 | * @return List<BusExchange> |
| 97 | */ | 97 | */ |
| 98 | List<BusExchange> selectExchangeExist(BusExchange exchange); | 98 | List<BusExchange> selectExchangeExist(BusExchange exchange); |
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * 根据虚拟主机删除交换机 | ||
| 102 | + * | ||
| 103 | + * @param virtualHostId 虚拟主机id | ||
| 104 | + * @return | ||
| 105 | + */ | ||
| 106 | + int deleteByVirtualHostId(String virtualHostId); | ||
| 107 | + | ||
| 108 | + /** | ||
| 109 | + * 查询交换机列表,根据虚拟主机id | ||
| 110 | + * | ||
| 111 | + * @param virtualHostId 虚拟主机 | ||
| 112 | + * @return | ||
| 113 | + */ | ||
| 114 | + List<BusExchange> selectByVirtualHostId(String virtualHostId); | ||
| 99 | } | 115 | } |
| @@ -23,6 +23,14 @@ public interface BusQueueService { | @@ -23,6 +23,14 @@ public interface BusQueueService { | ||
| 23 | int deleteByPrimaryKey(String id) throws IOException, TimeoutException; | 23 | int deleteByPrimaryKey(String id) throws IOException, TimeoutException; |
| 24 | 24 | ||
| 25 | /** | 25 | /** |
| 26 | + * 删除队列,根据虚拟主机id | ||
| 27 | + * | ||
| 28 | + * @param virtualHostId 虚拟主机id | ||
| 29 | + * @return | ||
| 30 | + */ | ||
| 31 | + int deleteByVirtualHostId(String virtualHostId); | ||
| 32 | + | ||
| 33 | + /** | ||
| 26 | * 新增 | 34 | * 新增 |
| 27 | * | 35 | * |
| 28 | * @param record the record | 36 | * @param record the record |
| @@ -87,5 +95,13 @@ public interface BusQueueService { | @@ -87,5 +95,13 @@ public interface BusQueueService { | ||
| 87 | * @return | 95 | * @return |
| 88 | */ | 96 | */ |
| 89 | List<BusQueue> getQueueList(BusQueue busQueue); | 97 | List<BusQueue> getQueueList(BusQueue busQueue); |
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * 根据虚拟主机id,查询队列列表 | ||
| 101 | + * | ||
| 102 | + * @param virtualHostId 虚拟主机id | ||
| 103 | + * @return | ||
| 104 | + */ | ||
| 105 | + List<BusQueue> selectByVirtualHostId(String virtualHostId); | ||
| 90 | } | 106 | } |
| 91 | 107 |
| @@ -3,7 +3,9 @@ package com.sunyo.wlpt.message.bus.service.service; | @@ -3,7 +3,9 @@ package com.sunyo.wlpt.message.bus.service.service; | ||
| 3 | import com.github.pagehelper.PageInfo; | 3 | import com.github.pagehelper.PageInfo; |
| 4 | import com.sunyo.wlpt.message.bus.service.domain.BusServer; | 4 | import com.sunyo.wlpt.message.bus.service.domain.BusServer; |
| 5 | 5 | ||
| 6 | +import java.io.IOException; | ||
| 6 | import java.util.List; | 7 | import java.util.List; |
| 8 | +import java.util.concurrent.TimeoutException; | ||
| 7 | 9 | ||
| 8 | /** | 10 | /** |
| 9 | * @author 子诚 | 11 | * @author 子诚 |
| @@ -18,7 +20,7 @@ public interface BusServerService { | @@ -18,7 +20,7 @@ public interface BusServerService { | ||
| 18 | * @param id primaryKey | 20 | * @param id primaryKey |
| 19 | * @return deleteCount | 21 | * @return deleteCount |
| 20 | */ | 22 | */ |
| 21 | - int deleteByPrimaryKey(String id); | 23 | + int deleteByPrimaryKey(String id) throws IOException, TimeoutException; |
| 22 | 24 | ||
| 23 | /** | 25 | /** |
| 24 | * 新增 | 26 | * 新增 |
| @@ -111,6 +111,38 @@ public interface UserMessageBindingService { | @@ -111,6 +111,38 @@ public interface UserMessageBindingService { | ||
| 111 | * @return | 111 | * @return |
| 112 | */ | 112 | */ |
| 113 | List<UserMessageBinding> selectByRoutingKeyId(String routingKeyId); | 113 | List<UserMessageBinding> selectByRoutingKeyId(String routingKeyId); |
| 114 | + | ||
| 115 | + /** | ||
| 116 | + * 根据虚拟主机id,查询配置关系列表 | ||
| 117 | + * | ||
| 118 | + * @param virtualHostId 虚拟主机id | ||
| 119 | + * @return List<UserMessageBinding> | ||
| 120 | + */ | ||
| 121 | + List<UserMessageBinding> selectByVirtualHostId(String virtualHostId); | ||
| 122 | + | ||
| 123 | + /** | ||
| 124 | + * 删除配置关系 | ||
| 125 | + * | ||
| 126 | + * @param virtualHostId 虚拟主机id | ||
| 127 | + * @return | ||
| 128 | + */ | ||
| 129 | + int deleteByVirtualHostId(String virtualHostId); | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * 根据服务器id,查询配置关系列表 | ||
| 133 | + * | ||
| 134 | + * @param serverId 服务器id | ||
| 135 | + * @return List<UserMessageBinding> | ||
| 136 | + */ | ||
| 137 | + List<UserMessageBinding> selectByServerId(String serverId); | ||
| 138 | + | ||
| 139 | + /** | ||
| 140 | + * 根据服务器id,删除绑定关系 | ||
| 141 | + * | ||
| 142 | + * @param serverId 服务器id | ||
| 143 | + * @return | ||
| 144 | + */ | ||
| 145 | + int deleteByServerId(String serverId); | ||
| 114 | } | 146 | } |
| 115 | 147 | ||
| 116 | 148 |
| @@ -3,7 +3,9 @@ package com.sunyo.wlpt.message.bus.service.service; | @@ -3,7 +3,9 @@ package com.sunyo.wlpt.message.bus.service.service; | ||
| 3 | import com.github.pagehelper.PageInfo; | 3 | import com.github.pagehelper.PageInfo; |
| 4 | import com.sunyo.wlpt.message.bus.service.domain.VirtualHost; | 4 | import com.sunyo.wlpt.message.bus.service.domain.VirtualHost; |
| 5 | 5 | ||
| 6 | +import java.io.IOException; | ||
| 6 | import java.util.List; | 7 | import java.util.List; |
| 8 | +import java.util.concurrent.TimeoutException; | ||
| 7 | 9 | ||
| 8 | /** | 10 | /** |
| 9 | * @author 子诚 | 11 | * @author 子诚 |
| @@ -18,7 +20,7 @@ public interface VirtualHostService { | @@ -18,7 +20,7 @@ public interface VirtualHostService { | ||
| 18 | * @param id primaryKey | 20 | * @param id primaryKey |
| 19 | * @return deleteCount | 21 | * @return deleteCount |
| 20 | */ | 22 | */ |
| 21 | - int deleteByPrimaryKey(String id); | 23 | + int deleteByPrimaryKey(String id) throws IOException, TimeoutException; |
| 22 | 24 | ||
| 23 | /** | 25 | /** |
| 24 | * 新增 | 26 | * 新增 |
| @@ -88,8 +90,25 @@ public interface VirtualHostService { | @@ -88,8 +90,25 @@ public interface VirtualHostService { | ||
| 88 | 90 | ||
| 89 | /** | 91 | /** |
| 90 | * 检验是否存在 | 92 | * 检验是否存在 |
| 91 | - * @param virtualHost {@link VirtualHost} | 93 | + * |
| 94 | + * @param virtualHost {@link VirtualHost} | ||
| 92 | * @return List<VirtualHost> | 95 | * @return List<VirtualHost> |
| 93 | */ | 96 | */ |
| 94 | List<VirtualHost> selectVirtualHostExist(VirtualHost virtualHost); | 97 | List<VirtualHost> selectVirtualHostExist(VirtualHost virtualHost); |
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * 根据服务器id,查询虚拟主机列表 | ||
| 101 | + * | ||
| 102 | + * @param serverId 服务器id | ||
| 103 | + * @return | ||
| 104 | + */ | ||
| 105 | + List<VirtualHost> selectByServerId(String serverId); | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * 根据服务器id,删除虚拟主机 | ||
| 109 | + * | ||
| 110 | + * @param serverId 服务器id | ||
| 111 | + * @return | ||
| 112 | + */ | ||
| 113 | + int deleteByServerId(String serverId); | ||
| 95 | } | 114 | } |
| @@ -2,9 +2,8 @@ package com.sunyo.wlpt.message.bus.service.service.impl; | @@ -2,9 +2,8 @@ package com.sunyo.wlpt.message.bus.service.service.impl; | ||
| 2 | 2 | ||
| 3 | import com.sunyo.wlpt.message.bus.service.domain.*; | 3 | import com.sunyo.wlpt.message.bus.service.domain.*; |
| 4 | import com.sunyo.wlpt.message.bus.service.rabbit.utils.RabbitUtils; | 4 | import com.sunyo.wlpt.message.bus.service.rabbit.utils.RabbitUtils; |
| 5 | -import com.sunyo.wlpt.message.bus.service.service.MessageNoteService; | ||
| 6 | -import com.sunyo.wlpt.message.bus.service.service.RoutingKeyService; | ||
| 7 | -import com.sunyo.wlpt.message.bus.service.service.UserMessageBindingService; | 5 | +import com.sunyo.wlpt.message.bus.service.service.*; |
| 6 | +import org.springframework.context.annotation.Lazy; | ||
| 8 | import org.springframework.scheduling.annotation.Async; | 7 | import org.springframework.scheduling.annotation.Async; |
| 9 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
| 10 | import org.springframework.transaction.annotation.Propagation; | 9 | import org.springframework.transaction.annotation.Propagation; |
| @@ -30,12 +29,25 @@ public class AsyncTaskService { | @@ -30,12 +29,25 @@ public class AsyncTaskService { | ||
| 30 | @Resource | 29 | @Resource |
| 31 | private MessageNoteService messageNoteService; | 30 | private MessageNoteService messageNoteService; |
| 32 | 31 | ||
| 32 | + @Lazy | ||
| 33 | @Resource | 33 | @Resource |
| 34 | private RoutingKeyService routingKeyService; | 34 | private RoutingKeyService routingKeyService; |
| 35 | 35 | ||
| 36 | @Resource | 36 | @Resource |
| 37 | private UserMessageBindingService userMessageBindingService; | 37 | private UserMessageBindingService userMessageBindingService; |
| 38 | 38 | ||
| 39 | + @Lazy | ||
| 40 | + @Resource | ||
| 41 | + private BusQueueService busQueueService; | ||
| 42 | + | ||
| 43 | + @Lazy | ||
| 44 | + @Resource | ||
| 45 | + private BusExchangeService busExchangeService; | ||
| 46 | + | ||
| 47 | + @Lazy | ||
| 48 | + @Resource | ||
| 49 | + private VirtualHostService virtualHostService; | ||
| 50 | + | ||
| 39 | /** | 51 | /** |
| 40 | * 异步,无论消息是否发送成功,将消息存储于数据库 | 52 | * 异步,无论消息是否发送成功,将消息存储于数据库 |
| 41 | * | 53 | * |
| @@ -49,14 +61,80 @@ public class AsyncTaskService { | @@ -49,14 +61,80 @@ public class AsyncTaskService { | ||
| 49 | } | 61 | } |
| 50 | 62 | ||
| 51 | /** | 63 | /** |
| 52 | - * 当删除服务器的时候 | 64 | + * 当删除服务器的时候,级联删除与服务器有关的 |
| 65 | + * 虚拟主机,交换机,路由键,队列,绑定关系 | ||
| 53 | */ | 66 | */ |
| 54 | - | 67 | + @Async |
| 68 | + @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) | ||
| 69 | + public void serverCascadeDelete(BusServer busServer) throws IOException, TimeoutException | ||
| 70 | + { | ||
| 71 | + String serverId = busServer.getId(); | ||
| 72 | + List<UserMessageBinding> bindings = userMessageBindingService.selectByServerId(serverId); | ||
| 73 | + // 1.1 删除数据库中的绑定关系 | ||
| 74 | + userMessageBindingService.deleteByServerId(serverId); | ||
| 75 | + for (UserMessageBinding userMessageBinding : bindings) { | ||
| 76 | + // 1.2、解除MQ服务器上的绑定关系 | ||
| 77 | + rabbitUtils.toRemoveBinding(userMessageBinding); | ||
| 78 | + } | ||
| 79 | + List<VirtualHost> virtualHostList = virtualHostService.selectByServerId(serverId); | ||
| 80 | + // 2.1、删除数据库中的虚拟主机列表 | ||
| 81 | + virtualHostService.deleteByServerId(serverId); | ||
| 82 | + for (VirtualHost virtualHost : virtualHostList) { | ||
| 83 | + String virtualHostId = virtualHost.getId(); | ||
| 84 | + List<BusQueue> queues = busQueueService.selectByVirtualHostId(virtualHostId); | ||
| 85 | + // 3.1、删除数据库中对应的队列 | ||
| 86 | + busQueueService.deleteByVirtualHostId(virtualHostId); | ||
| 87 | + for (BusQueue queue : queues) { | ||
| 88 | + // 3.2、删除MQ服务器上的队列 | ||
| 89 | + rabbitUtils.toRemoveQueue(queue); | ||
| 90 | + } | ||
| 91 | + List<BusExchange> exchanges = busExchangeService.selectByVirtualHostId(virtualHostId); | ||
| 92 | + // 4.1 根据虚拟主机id,删除交换机 | ||
| 93 | + busExchangeService.deleteByVirtualHostId(virtualHostId); | ||
| 94 | + for (BusExchange busExchange : exchanges) { | ||
| 95 | + String exchangeId = busExchange.getId(); | ||
| 96 | + // 5.1、删除数据库中对应的路由键 | ||
| 97 | + routingKeyService.deleteByExchangeId(exchangeId); | ||
| 98 | + // 4.2 在MQ服务器上删除该交换机 | ||
| 99 | + rabbitUtils.toRemoveExchange(busExchange); | ||
| 100 | + } | ||
| 101 | + } | ||
| 102 | + } | ||
| 55 | 103 | ||
| 56 | /** | 104 | /** |
| 57 | - * 当删除虚拟主机的时候 | 105 | + * 当删除虚拟主机的时候,级联删除与虚拟主机有关的 |
| 106 | + * 交换机,路由键,队列,绑定关系 | ||
| 58 | */ | 107 | */ |
| 59 | - | 108 | + @Async |
| 109 | + @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) | ||
| 110 | + public void virtualHostCascadeDelete(VirtualHost virtualHost) throws IOException, TimeoutException | ||
| 111 | + { | ||
| 112 | + String virtualHostId = virtualHost.getId(); | ||
| 113 | + List<UserMessageBinding> bindings = userMessageBindingService.selectByVirtualHostId(virtualHostId); | ||
| 114 | + // 1.1、删除数据库中的绑定关系 | ||
| 115 | + userMessageBindingService.deleteByVirtualHostId(virtualHostId); | ||
| 116 | + for (UserMessageBinding userMessageBinding : bindings) { | ||
| 117 | + // 1.2、解除MQ服务器上的绑定关系 | ||
| 118 | + rabbitUtils.toRemoveBinding(userMessageBinding); | ||
| 119 | + } | ||
| 120 | + List<BusQueue> queues = busQueueService.selectByVirtualHostId(virtualHostId); | ||
| 121 | + // 2.1、删除数据库中对应的队列 | ||
| 122 | + busQueueService.deleteByVirtualHostId(virtualHostId); | ||
| 123 | + for (BusQueue queue : queues) { | ||
| 124 | + // 2.2、删除MQ服务器上的队列 | ||
| 125 | + rabbitUtils.toRemoveQueue(queue); | ||
| 126 | + } | ||
| 127 | + List<BusExchange> exchanges = busExchangeService.selectByVirtualHostId(virtualHostId); | ||
| 128 | + // 3.1 根据虚拟主机id,删除交换机 | ||
| 129 | + busExchangeService.deleteByVirtualHostId(virtualHostId); | ||
| 130 | + for (BusExchange busExchange : exchanges) { | ||
| 131 | + String exchangeId = busExchange.getId(); | ||
| 132 | + // 4.1、删除数据库中对应的路由键 | ||
| 133 | + routingKeyService.deleteByExchangeId(exchangeId); | ||
| 134 | + // 3.2 在MQ服务器上删除该交换机 | ||
| 135 | + rabbitUtils.toRemoveExchange(busExchange); | ||
| 136 | + } | ||
| 137 | + } | ||
| 60 | 138 | ||
| 61 | /** | 139 | /** |
| 62 | * 当删除交换机的时候, | 140 | * 当删除交换机的时候, |
| @@ -67,34 +145,34 @@ public class AsyncTaskService { | @@ -67,34 +145,34 @@ public class AsyncTaskService { | ||
| 67 | */ | 145 | */ |
| 68 | @Async | 146 | @Async |
| 69 | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) | 147 | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) |
| 70 | - void exchangeCascadeDelete(BusExchange busExchange) | 148 | + public void exchangeCascadeDelete(BusExchange busExchange) |
| 71 | { | 149 | { |
| 72 | String exchangeId = busExchange.getId(); | 150 | String exchangeId = busExchange.getId(); |
| 73 | List<RoutingKey> routingKeyList = routingKeyService.selectByExchangeId(exchangeId); | 151 | List<RoutingKey> routingKeyList = routingKeyService.selectByExchangeId(exchangeId); |
| 74 | // 删除相关路由键 | 152 | // 删除相关路由键 |
| 75 | routingKeyService.deleteByExchangeId(exchangeId); | 153 | routingKeyService.deleteByExchangeId(exchangeId); |
| 76 | - // 删除交换机相关配置关系 | 154 | + // 删除交换机相关绑定关系 |
| 77 | userMessageBindingService.deleteByExchangeId(exchangeId); | 155 | userMessageBindingService.deleteByExchangeId(exchangeId); |
| 78 | - // 删除路由键相关配置关系 | 156 | + // 删除路由键相关绑定关系 |
| 79 | for (int i = 0; i < routingKeyList.size(); i++) { | 157 | for (int i = 0; i < routingKeyList.size(); i++) { |
| 80 | userMessageBindingService.deleteByRoutingKeyId(routingKeyList.get(0).getId()); | 158 | userMessageBindingService.deleteByRoutingKeyId(routingKeyList.get(0).getId()); |
| 81 | } | 159 | } |
| 82 | } | 160 | } |
| 83 | 161 | ||
| 84 | /** | 162 | /** |
| 85 | - * 当删除路由键的时候,删除包含该路由键的配置关系 | 163 | + * 当删除路由键的时候,删除包含该路由键的绑定关系 |
| 86 | */ | 164 | */ |
| 87 | @Async | 165 | @Async |
| 88 | - void routingKeyCascadeDelete(RoutingKey routingKey) throws IOException, TimeoutException | 166 | + public void routingKeyCascadeDelete(RoutingKey routingKey) throws IOException, TimeoutException |
| 89 | { | 167 | { |
| 90 | String routingKeyId = routingKey.getId(); | 168 | String routingKeyId = routingKey.getId(); |
| 91 | - // 根据路由键id查询出所有的包含该路由键的配置关系 | 169 | + // 根据路由键id查询出所有的包含该路由键的绑定关系 |
| 92 | List<UserMessageBinding> bindings = userMessageBindingService.selectByRoutingKeyId(routingKeyId); | 170 | List<UserMessageBinding> bindings = userMessageBindingService.selectByRoutingKeyId(routingKeyId); |
| 93 | for (UserMessageBinding userMessageBinding : bindings) { | 171 | for (UserMessageBinding userMessageBinding : bindings) { |
| 94 | - // 解除MQ服务器上的配置关系 | 172 | + // 解除MQ服务器上的绑定关系 |
| 95 | rabbitUtils.toRemoveBinding(userMessageBinding); | 173 | rabbitUtils.toRemoveBinding(userMessageBinding); |
| 96 | } | 174 | } |
| 97 | - // 删除数据库中的包含该路由键相关配置关系 | 175 | + // 删除数据库中的包含该路由键相关绑定关系 |
| 98 | userMessageBindingService.deleteByRoutingKeyId(routingKey.getId()); | 176 | userMessageBindingService.deleteByRoutingKeyId(routingKey.getId()); |
| 99 | } | 177 | } |
| 100 | 178 | ||
| @@ -102,9 +180,9 @@ public class AsyncTaskService { | @@ -102,9 +180,9 @@ public class AsyncTaskService { | ||
| 102 | * 当删除队列的时候,删除包含队列的绑定关系 | 180 | * 当删除队列的时候,删除包含队列的绑定关系 |
| 103 | */ | 181 | */ |
| 104 | @Async | 182 | @Async |
| 105 | - void queueCascadeDelete(BusQueue busQueue) | 183 | + public void queueCascadeDelete(BusQueue busQueue) |
| 106 | { | 184 | { |
| 107 | - // 删除相关配置关系 | 185 | + // 删除相关绑定关系 |
| 108 | userMessageBindingService.deleteByQueueId(busQueue.getId()); | 186 | userMessageBindingService.deleteByQueueId(busQueue.getId()); |
| 109 | } | 187 | } |
| 110 | 188 |
| @@ -6,6 +6,7 @@ import com.sunyo.wlpt.message.bus.service.domain.BusExchange; | @@ -6,6 +6,7 @@ import com.sunyo.wlpt.message.bus.service.domain.BusExchange; | ||
| 6 | import com.sunyo.wlpt.message.bus.service.mapper.BusExchangeMapper; | 6 | import com.sunyo.wlpt.message.bus.service.mapper.BusExchangeMapper; |
| 7 | import com.sunyo.wlpt.message.bus.service.rabbit.utils.RabbitUtils; | 7 | import com.sunyo.wlpt.message.bus.service.rabbit.utils.RabbitUtils; |
| 8 | import com.sunyo.wlpt.message.bus.service.service.BusExchangeService; | 8 | import com.sunyo.wlpt.message.bus.service.service.BusExchangeService; |
| 9 | +import org.springframework.context.annotation.Lazy; | ||
| 9 | import org.springframework.stereotype.Service; | 10 | import org.springframework.stereotype.Service; |
| 10 | import org.springframework.transaction.annotation.Propagation; | 11 | import org.springframework.transaction.annotation.Propagation; |
| 11 | import org.springframework.transaction.annotation.Transactional; | 12 | import org.springframework.transaction.annotation.Transactional; |
| @@ -26,6 +27,7 @@ public class BusExchangeServiceImpl implements BusExchangeService { | @@ -26,6 +27,7 @@ public class BusExchangeServiceImpl implements BusExchangeService { | ||
| 26 | @Resource | 27 | @Resource |
| 27 | private BusExchangeMapper busExchangeMapper; | 28 | private BusExchangeMapper busExchangeMapper; |
| 28 | 29 | ||
| 30 | + @Lazy | ||
| 29 | @Resource | 31 | @Resource |
| 30 | private AsyncTaskService asyncTaskService; | 32 | private AsyncTaskService asyncTaskService; |
| 31 | 33 | ||
| @@ -137,4 +139,15 @@ public class BusExchangeServiceImpl implements BusExchangeService { | @@ -137,4 +139,15 @@ public class BusExchangeServiceImpl implements BusExchangeService { | ||
| 137 | return busExchangeMapper.selectExchangeExist(exchange); | 139 | return busExchangeMapper.selectExchangeExist(exchange); |
| 138 | } | 140 | } |
| 139 | 141 | ||
| 142 | + @Override | ||
| 143 | + public int deleteByVirtualHostId(String virtualHostId) | ||
| 144 | + { | ||
| 145 | + return busExchangeMapper.deleteByVirtualHostId(virtualHostId); | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + @Override | ||
| 149 | + public List<BusExchange> selectByVirtualHostId(String virtualHostId) | ||
| 150 | + { | ||
| 151 | + return busExchangeMapper.selectByVirtualHostId(virtualHostId); | ||
| 152 | + } | ||
| 140 | } | 153 | } |
| @@ -84,6 +84,12 @@ public class BusQueueServiceImpl implements BusQueueService { | @@ -84,6 +84,12 @@ public class BusQueueServiceImpl implements BusQueueService { | ||
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | @Override | 86 | @Override |
| 87 | + public int deleteByVirtualHostId(String virtualHostId) | ||
| 88 | + { | ||
| 89 | + return busQueueMapper.deleteByVirtualHostId(virtualHostId); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + @Override | ||
| 87 | public int insert(BusQueue record) | 93 | public int insert(BusQueue record) |
| 88 | { | 94 | { |
| 89 | return busQueueMapper.insert(record); | 95 | return busQueueMapper.insert(record); |
| @@ -150,5 +156,11 @@ public class BusQueueServiceImpl implements BusQueueService { | @@ -150,5 +156,11 @@ public class BusQueueServiceImpl implements BusQueueService { | ||
| 150 | } | 156 | } |
| 151 | return busQueueMapper.getQueueList(busQueue); | 157 | return busQueueMapper.getQueueList(busQueue); |
| 152 | } | 158 | } |
| 159 | + | ||
| 160 | + @Override | ||
| 161 | + public List<BusQueue> selectByVirtualHostId(String virtualHostId) | ||
| 162 | + { | ||
| 163 | + return busQueueMapper.selectByVirtualHostId(virtualHostId); | ||
| 164 | + } | ||
| 153 | } | 165 | } |
| 154 | 166 |
| @@ -5,12 +5,15 @@ import com.github.pagehelper.PageInfo; | @@ -5,12 +5,15 @@ import com.github.pagehelper.PageInfo; | ||
| 5 | import com.sunyo.wlpt.message.bus.service.domain.BusServer; | 5 | import com.sunyo.wlpt.message.bus.service.domain.BusServer; |
| 6 | import com.sunyo.wlpt.message.bus.service.mapper.BusServerMapper; | 6 | import com.sunyo.wlpt.message.bus.service.mapper.BusServerMapper; |
| 7 | import com.sunyo.wlpt.message.bus.service.service.BusServerService; | 7 | import com.sunyo.wlpt.message.bus.service.service.BusServerService; |
| 8 | +import org.springframework.context.annotation.Lazy; | ||
| 8 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
| 9 | import org.springframework.transaction.annotation.Propagation; | 10 | import org.springframework.transaction.annotation.Propagation; |
| 10 | import org.springframework.transaction.annotation.Transactional; | 11 | import org.springframework.transaction.annotation.Transactional; |
| 11 | 12 | ||
| 12 | import javax.annotation.Resource; | 13 | import javax.annotation.Resource; |
| 14 | +import java.io.IOException; | ||
| 13 | import java.util.List; | 15 | import java.util.List; |
| 16 | +import java.util.concurrent.TimeoutException; | ||
| 14 | 17 | ||
| 15 | /** | 18 | /** |
| 16 | * @author 子诚 | 19 | * @author 子诚 |
| @@ -23,6 +26,10 @@ public class BusServerServiceImpl implements BusServerService { | @@ -23,6 +26,10 @@ public class BusServerServiceImpl implements BusServerService { | ||
| 23 | @Resource | 26 | @Resource |
| 24 | private BusServerMapper busServerMapper; | 27 | private BusServerMapper busServerMapper; |
| 25 | 28 | ||
| 29 | + @Lazy | ||
| 30 | + @Resource | ||
| 31 | + private AsyncTaskService asyncTaskService; | ||
| 32 | + | ||
| 26 | @Override | 33 | @Override |
| 27 | public PageInfo selectBusServerList(BusServer busServer, Integer pageNum, Integer pageSize) | 34 | public PageInfo selectBusServerList(BusServer busServer, Integer pageNum, Integer pageSize) |
| 28 | { | 35 | { |
| @@ -41,7 +48,7 @@ public class BusServerServiceImpl implements BusServerService { | @@ -41,7 +48,7 @@ public class BusServerServiceImpl implements BusServerService { | ||
| 41 | 48 | ||
| 42 | @Override | 49 | @Override |
| 43 | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) | 50 | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) |
| 44 | - public int deleteByPrimaryKey(String id) | 51 | + public int deleteByPrimaryKey(String id) throws IOException, TimeoutException |
| 45 | { | 52 | { |
| 46 | // 判断删除的个数,需被删除的个数是否一致 | 53 | // 判断删除的个数,需被删除的个数是否一致 |
| 47 | int index = 0; | 54 | int index = 0; |
| @@ -50,7 +57,10 @@ public class BusServerServiceImpl implements BusServerService { | @@ -50,7 +57,10 @@ public class BusServerServiceImpl implements BusServerService { | ||
| 50 | if (id.contains(splitItem)) { | 57 | if (id.contains(splitItem)) { |
| 51 | String[] split = id.split(splitItem); | 58 | String[] split = id.split(splitItem); |
| 52 | for (int i = 0; i < split.length; i++) { | 59 | for (int i = 0; i < split.length; i++) { |
| 60 | + BusServer busServer = busServerMapper.selectByPrimaryKey(split[i]); | ||
| 53 | int num = busServerMapper.deleteByPrimaryKey(split[i]); | 61 | int num = busServerMapper.deleteByPrimaryKey(split[i]); |
| 62 | + // 异步删除与该服务器相关的:虚拟主机,配置关系,队列,交换机,路由键 | ||
| 63 | + asyncTaskService.serverCascadeDelete(busServer); | ||
| 54 | if (num > 0) { | 64 | if (num > 0) { |
| 55 | index = index + num; | 65 | index = index + num; |
| 56 | } | 66 | } |
| @@ -61,7 +71,11 @@ public class BusServerServiceImpl implements BusServerService { | @@ -61,7 +71,11 @@ public class BusServerServiceImpl implements BusServerService { | ||
| 61 | return 0; | 71 | return 0; |
| 62 | } | 72 | } |
| 63 | } else { | 73 | } else { |
| 64 | - return busServerMapper.deleteByPrimaryKey(id); | 74 | + BusServer busServer = busServerMapper.selectByPrimaryKey(id); |
| 75 | + int num = busServerMapper.deleteByPrimaryKey(id); | ||
| 76 | + // 异步删除与该服务器相关的:虚拟主机,配置关系,队列,交换机,路由键 | ||
| 77 | + asyncTaskService.serverCascadeDelete(busServer); | ||
| 78 | + return num; | ||
| 65 | } | 79 | } |
| 66 | } | 80 | } |
| 67 | 81 |
| @@ -447,6 +447,30 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | @@ -447,6 +447,30 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | ||
| 447 | { | 447 | { |
| 448 | return userMessageBindingMapper.selectByRoutingKeyId(routingKeyId); | 448 | return userMessageBindingMapper.selectByRoutingKeyId(routingKeyId); |
| 449 | } | 449 | } |
| 450 | + | ||
| 451 | + @Override | ||
| 452 | + public List<UserMessageBinding> selectByVirtualHostId(String virtualHostId) | ||
| 453 | + { | ||
| 454 | + return userMessageBindingMapper.selectByVirtualHostId(virtualHostId); | ||
| 455 | + } | ||
| 456 | + | ||
| 457 | + @Override | ||
| 458 | + public int deleteByVirtualHostId(String virtualHostId) | ||
| 459 | + { | ||
| 460 | + return userMessageBindingMapper.deleteByVirtualHostId(virtualHostId); | ||
| 461 | + } | ||
| 462 | + | ||
| 463 | + @Override | ||
| 464 | + public List<UserMessageBinding> selectByServerId(String serverId) | ||
| 465 | + { | ||
| 466 | + return userMessageBindingMapper.selectByServerId(serverId); | ||
| 467 | + } | ||
| 468 | + | ||
| 469 | + @Override | ||
| 470 | + public int deleteByServerId(String serverId) | ||
| 471 | + { | ||
| 472 | + return userMessageBindingMapper.deleteByServerId(serverId); | ||
| 473 | + } | ||
| 450 | } | 474 | } |
| 451 | 475 | ||
| 452 | 476 |
| @@ -5,12 +5,15 @@ import com.github.pagehelper.PageInfo; | @@ -5,12 +5,15 @@ import com.github.pagehelper.PageInfo; | ||
| 5 | import com.sunyo.wlpt.message.bus.service.domain.VirtualHost; | 5 | import com.sunyo.wlpt.message.bus.service.domain.VirtualHost; |
| 6 | import com.sunyo.wlpt.message.bus.service.mapper.VirtualHostMapper; | 6 | import com.sunyo.wlpt.message.bus.service.mapper.VirtualHostMapper; |
| 7 | import com.sunyo.wlpt.message.bus.service.service.VirtualHostService; | 7 | import com.sunyo.wlpt.message.bus.service.service.VirtualHostService; |
| 8 | +import org.springframework.context.annotation.Lazy; | ||
| 8 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
| 9 | import org.springframework.transaction.annotation.Propagation; | 10 | import org.springframework.transaction.annotation.Propagation; |
| 10 | import org.springframework.transaction.annotation.Transactional; | 11 | import org.springframework.transaction.annotation.Transactional; |
| 11 | 12 | ||
| 12 | import javax.annotation.Resource; | 13 | import javax.annotation.Resource; |
| 14 | +import java.io.IOException; | ||
| 13 | import java.util.List; | 15 | import java.util.List; |
| 16 | +import java.util.concurrent.TimeoutException; | ||
| 14 | 17 | ||
| 15 | /** | 18 | /** |
| 16 | * @author 子诚 | 19 | * @author 子诚 |
| @@ -23,9 +26,13 @@ public class VirtualHostServiceImpl implements VirtualHostService { | @@ -23,9 +26,13 @@ public class VirtualHostServiceImpl implements VirtualHostService { | ||
| 23 | @Resource | 26 | @Resource |
| 24 | private VirtualHostMapper virtualHostMapper; | 27 | private VirtualHostMapper virtualHostMapper; |
| 25 | 28 | ||
| 29 | + @Lazy | ||
| 30 | + @Resource | ||
| 31 | + private AsyncTaskService asyncTaskService; | ||
| 32 | + | ||
| 26 | @Override | 33 | @Override |
| 27 | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) | 34 | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) |
| 28 | - public int deleteByPrimaryKey(String id) | 35 | + public int deleteByPrimaryKey(String id) throws IOException, TimeoutException |
| 29 | { | 36 | { |
| 30 | // 判断删除的个数,需被删除的个数是否一致 | 37 | // 判断删除的个数,需被删除的个数是否一致 |
| 31 | int index = 0; | 38 | int index = 0; |
| @@ -34,7 +41,10 @@ public class VirtualHostServiceImpl implements VirtualHostService { | @@ -34,7 +41,10 @@ public class VirtualHostServiceImpl implements VirtualHostService { | ||
| 34 | if (id.contains(splitItem)) { | 41 | if (id.contains(splitItem)) { |
| 35 | String[] split = id.split(splitItem); | 42 | String[] split = id.split(splitItem); |
| 36 | for (int i = 0; i < split.length; i++) { | 43 | for (int i = 0; i < split.length; i++) { |
| 44 | + VirtualHost virtualHost = virtualHostMapper.selectByPrimaryKey(split[i]); | ||
| 37 | int num = virtualHostMapper.deleteByPrimaryKey(split[i]); | 45 | int num = virtualHostMapper.deleteByPrimaryKey(split[i]); |
| 46 | + // 异步删除与该虚拟主机相关的队列,交换机,路由键,配置关系 | ||
| 47 | + asyncTaskService.virtualHostCascadeDelete(virtualHost); | ||
| 38 | if (num > 0) { | 48 | if (num > 0) { |
| 39 | index = index + num; | 49 | index = index + num; |
| 40 | } | 50 | } |
| @@ -46,7 +56,11 @@ public class VirtualHostServiceImpl implements VirtualHostService { | @@ -46,7 +56,11 @@ public class VirtualHostServiceImpl implements VirtualHostService { | ||
| 46 | } | 56 | } |
| 47 | 57 | ||
| 48 | } else { | 58 | } else { |
| 49 | - return virtualHostMapper.deleteByPrimaryKey(id); | 59 | + VirtualHost virtualHost = virtualHostMapper.selectByPrimaryKey(id); |
| 60 | + int num = virtualHostMapper.deleteByPrimaryKey(id); | ||
| 61 | + // 异步删除与该虚拟主机相关的队列,交换机,路由键,配置关系 | ||
| 62 | + asyncTaskService.virtualHostCascadeDelete(virtualHost); | ||
| 63 | + return num; | ||
| 50 | } | 64 | } |
| 51 | 65 | ||
| 52 | } | 66 | } |
| @@ -108,4 +122,15 @@ public class VirtualHostServiceImpl implements VirtualHostService { | @@ -108,4 +122,15 @@ public class VirtualHostServiceImpl implements VirtualHostService { | ||
| 108 | return virtualHostMapper.selectVirtualHostExist(virtualHost); | 122 | return virtualHostMapper.selectVirtualHostExist(virtualHost); |
| 109 | } | 123 | } |
| 110 | 124 | ||
| 125 | + @Override | ||
| 126 | + public List<VirtualHost> selectByServerId(String serverId) | ||
| 127 | + { | ||
| 128 | + return virtualHostMapper.selectByServerId(serverId); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + @Override | ||
| 132 | + public int deleteByServerId(String serverId) | ||
| 133 | + { | ||
| 134 | + return virtualHostMapper.deleteByServerId(serverId); | ||
| 135 | + } | ||
| 111 | } | 136 | } |
| @@ -40,6 +40,16 @@ | @@ -40,6 +40,16 @@ | ||
| 40 | from bus_exchange | 40 | from bus_exchange |
| 41 | where id = #{id,jdbcType=VARCHAR} | 41 | where id = #{id,jdbcType=VARCHAR} |
| 42 | </select> | 42 | </select> |
| 43 | + | ||
| 44 | + <!-- 获取交换机列表,根据虚拟主机id --> | ||
| 45 | + <select id="selectByVirtualHostId" parameterType="java.lang.String" resultMap="BaseResultMap"> | ||
| 46 | + <!--@mbg.generated--> | ||
| 47 | + select | ||
| 48 | + <include refid="Base_Column_List"/> | ||
| 49 | + from bus_exchange | ||
| 50 | + where virtual_host_id = #{virtualHostId,jdbcType=VARCHAR} | ||
| 51 | + </select> | ||
| 52 | + | ||
| 43 | <!-- 获取交换机列表 --> | 53 | <!-- 获取交换机列表 --> |
| 44 | <select id="selectBusExchangeList" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusExchange" | 54 | <select id="selectBusExchangeList" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusExchange" |
| 45 | resultMap="ExchangeAndHostMap"> | 55 | resultMap="ExchangeAndHostMap"> |
| @@ -101,6 +111,14 @@ | @@ -101,6 +111,14 @@ | ||
| 101 | from bus_exchange | 111 | from bus_exchange |
| 102 | where id = #{id,jdbcType=VARCHAR} | 112 | where id = #{id,jdbcType=VARCHAR} |
| 103 | </delete> | 113 | </delete> |
| 114 | + | ||
| 115 | + <delete id="deleteByVirtualHostId" parameterType="java.lang.String"> | ||
| 116 | + <!--@mbg.generated--> | ||
| 117 | + delete | ||
| 118 | + from bus_exchange | ||
| 119 | + where virtual_host_id = #{virtualHostId,jdbcType=VARCHAR} | ||
| 120 | + </delete> | ||
| 121 | + | ||
| 104 | <insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusExchange"> | 122 | <insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusExchange"> |
| 105 | <!--@mbg.generated--> | 123 | <!--@mbg.generated--> |
| 106 | insert into bus_exchange (id, exchange_name, virtual_host_id, | 124 | insert into bus_exchange (id, exchange_name, virtual_host_id, |
| @@ -28,12 +28,28 @@ | @@ -28,12 +28,28 @@ | ||
| 28 | from bus_queue | 28 | from bus_queue |
| 29 | where id = #{id,jdbcType=VARCHAR} | 29 | where id = #{id,jdbcType=VARCHAR} |
| 30 | </select> | 30 | </select> |
| 31 | + | ||
| 32 | + <select id="selectByVirtualHostId" parameterType="java.lang.String" resultMap="BaseResultMap"> | ||
| 33 | + select | ||
| 34 | + <include refid="Base_Column_List"/> | ||
| 35 | + from bus_queue | ||
| 36 | + where virtual_host_id = #{virtualHostId,jdbcType=VARCHAR} | ||
| 37 | + </select> | ||
| 38 | + | ||
| 31 | <delete id="deleteByPrimaryKey" parameterType="java.lang.String"> | 39 | <delete id="deleteByPrimaryKey" parameterType="java.lang.String"> |
| 32 | <!--@mbg.generated--> | 40 | <!--@mbg.generated--> |
| 33 | delete | 41 | delete |
| 34 | from bus_queue | 42 | from bus_queue |
| 35 | where id = #{id,jdbcType=VARCHAR} | 43 | where id = #{id,jdbcType=VARCHAR} |
| 36 | </delete> | 44 | </delete> |
| 45 | + | ||
| 46 | + <delete id="deleteByVirtualHostId" parameterType="java.lang.String"> | ||
| 47 | + <!--@mbg.generated--> | ||
| 48 | + delete | ||
| 49 | + from bus_queue | ||
| 50 | + where virtual_host_id = #{virtualHostId,jdbcType=VARCHAR} | ||
| 51 | + </delete> | ||
| 52 | + | ||
| 37 | <insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusQueue"> | 53 | <insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusQueue"> |
| 38 | <!--@mbg.generated--> | 54 | <!--@mbg.generated--> |
| 39 | insert into bus_queue (id, queue_name, user_id, | 55 | insert into bus_queue (id, queue_name, user_id, |
| @@ -42,6 +42,22 @@ | @@ -42,6 +42,22 @@ | ||
| 42 | where routing_key_id = #{routingKeyId,jdbcType=VARCHAR} | 42 | where routing_key_id = #{routingKeyId,jdbcType=VARCHAR} |
| 43 | </select> | 43 | </select> |
| 44 | 44 | ||
| 45 | + <select id="selectByServerId" parameterType="java.lang.String" resultMap="BaseResultMap"> | ||
| 46 | + <!--@mbg.generated--> | ||
| 47 | + select | ||
| 48 | + <include refid="Base_Column_List"/> | ||
| 49 | + from user_message_binding | ||
| 50 | + where server_id = #{serverId,jdbcType=VARCHAR} | ||
| 51 | + </select> | ||
| 52 | + | ||
| 53 | + <select id="selectByVirtualHostId" parameterType="java.lang.String" resultMap="BaseResultMap"> | ||
| 54 | + <!--@mbg.generated--> | ||
| 55 | + select | ||
| 56 | + <include refid="Base_Column_List"/> | ||
| 57 | + from user_message_binding | ||
| 58 | + where virtual_host_id = #{virtualHostId,jdbcType=VARCHAR} | ||
| 59 | + </select> | ||
| 60 | + | ||
| 45 | <delete id="deleteByPrimaryKey" parameterType="java.lang.String"> | 61 | <delete id="deleteByPrimaryKey" parameterType="java.lang.String"> |
| 46 | <!--@mbg.generated--> | 62 | <!--@mbg.generated--> |
| 47 | delete | 63 | delete |
| @@ -49,6 +65,20 @@ | @@ -49,6 +65,20 @@ | ||
| 49 | where id = #{id,jdbcType=VARCHAR} | 65 | where id = #{id,jdbcType=VARCHAR} |
| 50 | </delete> | 66 | </delete> |
| 51 | 67 | ||
| 68 | +<!-- 根据服务器id,删除配置关系--> | ||
| 69 | + <delete id="deleteByServerId" parameterType="java.lang.String"> | ||
| 70 | + <!--@mbg.generated--> | ||
| 71 | + delete | ||
| 72 | + from user_message_binding | ||
| 73 | + where server_id = #{serverId,jdbcType=VARCHAR} | ||
| 74 | + </delete> | ||
| 75 | + <!-- 根据虚拟主机id,删除配置关系--> | ||
| 76 | + <delete id="deleteByVirtualHostId" parameterType="java.lang.String"> | ||
| 77 | + <!--@mbg.generated--> | ||
| 78 | + delete | ||
| 79 | + from user_message_binding | ||
| 80 | + where virtual_host_id = #{virtualHostId,jdbcType=VARCHAR} | ||
| 81 | + </delete> | ||
| 52 | <!-- 根据交换机id,删除配置关系--> | 82 | <!-- 根据交换机id,删除配置关系--> |
| 53 | <delete id="deleteByExchangeId" parameterType="java.lang.String"> | 83 | <delete id="deleteByExchangeId" parameterType="java.lang.String"> |
| 54 | <!--@mbg.generated--> | 84 | <!--@mbg.generated--> |
| @@ -32,6 +32,16 @@ | @@ -32,6 +32,16 @@ | ||
| 32 | from virtual_host | 32 | from virtual_host |
| 33 | where id = #{id,jdbcType=VARCHAR} | 33 | where id = #{id,jdbcType=VARCHAR} |
| 34 | </select> | 34 | </select> |
| 35 | + | ||
| 36 | + <!-- 根据服务器id,查询虚拟主机列表 --> | ||
| 37 | + <select id="selectByServerId" parameterType="java.lang.String" resultMap="BaseResultMap"> | ||
| 38 | + <!--@mbg.generated--> | ||
| 39 | + select | ||
| 40 | + <include refid="Base_Column_List"/> | ||
| 41 | + from virtual_host | ||
| 42 | + where server_id = #{serverId,jdbcType=VARCHAR} | ||
| 43 | + </select> | ||
| 44 | + | ||
| 35 | <!-- 查询虚拟主机列表,选择性 --> | 45 | <!-- 查询虚拟主机列表,选择性 --> |
| 36 | <select id="selectVirtualHostList" parameterType="com.sunyo.wlpt.message.bus.service.domain.VirtualHost" | 46 | <select id="selectVirtualHostList" parameterType="com.sunyo.wlpt.message.bus.service.domain.VirtualHost" |
| 37 | resultMap="HostAndServerMap"> | 47 | resultMap="HostAndServerMap"> |
| @@ -108,6 +118,14 @@ | @@ -108,6 +118,14 @@ | ||
| 108 | from virtual_host | 118 | from virtual_host |
| 109 | where id = #{id,jdbcType=VARCHAR} | 119 | where id = #{id,jdbcType=VARCHAR} |
| 110 | </delete> | 120 | </delete> |
| 121 | + | ||
| 122 | + <delete id="deleteByServerId" parameterType="java.lang.String"> | ||
| 123 | + <!--@mbg.generated--> | ||
| 124 | + delete | ||
| 125 | + from virtual_host | ||
| 126 | + where server_id = #{serverId,jdbcType=VARCHAR} | ||
| 127 | + </delete> | ||
| 128 | + | ||
| 111 | <insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.VirtualHost"> | 129 | <insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.VirtualHost"> |
| 112 | <!--@mbg.generated--> | 130 | <!--@mbg.generated--> |
| 113 | insert into virtual_host (id, virtual_host_name, server_id, | 131 | insert into virtual_host (id, virtual_host_name, server_id, |
-
请 注册 或 登录 后发表评论