正在显示
13 个修改的文件
包含
360 行增加
和
148 行删除
| @@ -91,10 +91,10 @@ public class CascadeController { | @@ -91,10 +91,10 @@ public class CascadeController { | ||
| 91 | */ | 91 | */ | 
| 92 | @GetMapping("/queue") | 92 | @GetMapping("/queue") | 
| 93 | public ResultJson getQueueList(@RequestParam(value = "virtualHostId", required = false) String virtualHostId, | 93 | public ResultJson getQueueList(@RequestParam(value = "virtualHostId", required = false) String virtualHostId, | 
| 94 | - @RequestParam(value = "userId", required = false) String userId) | 94 | + @RequestParam(value = "username", required = false) String username) | 
| 95 | { | 95 | { | 
| 96 | // 获取查询参数 | 96 | // 获取查询参数 | 
| 97 | - BusQueue busQueue = BusQueue.builder().virtualHostId(virtualHostId).userId(userId).build(); | 97 | + BusQueue busQueue = BusQueue.builder().virtualHostId(virtualHostId).username(username).build(); | 
| 98 | List<BusQueue> busQueues = busQueueService.getQueueList(busQueue); | 98 | List<BusQueue> busQueues = busQueueService.getQueueList(busQueue); | 
| 99 | return busQueues.size() > 0 | 99 | return busQueues.size() > 0 | 
| 100 | ? new ResultJson<>("200", "查询队列列表,成功", busQueues) | 100 | ? new ResultJson<>("200", "查询队列列表,成功", busQueues) | 
| @@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.*; | @@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.*; | ||
| 7 | 7 | ||
| 8 | import javax.annotation.Resource; | 8 | import javax.annotation.Resource; | 
| 9 | import java.io.IOException; | 9 | import java.io.IOException; | 
| 10 | -import java.net.MalformedURLException; | ||
| 11 | import java.net.URISyntaxException; | 10 | import java.net.URISyntaxException; | 
| 12 | import java.util.List; | 11 | import java.util.List; | 
| 13 | import java.util.concurrent.TimeoutException; | 12 | import java.util.concurrent.TimeoutException; | 
| @@ -25,6 +24,20 @@ public class UserInfoController { | @@ -25,6 +24,20 @@ public class UserInfoController { | ||
| 25 | @Resource | 24 | @Resource | 
| 26 | private UserInfoService userInfoService; | 25 | private UserInfoService userInfoService; | 
| 27 | 26 | ||
| 27 | + @GetMapping("/list") | ||
| 28 | + public ResultJson selectUserInfoList( | ||
| 29 | + @RequestParam(value = "username", required = false) String username, | ||
| 30 | + @RequestParam(value = "serverName", required = false) String serverName, | ||
| 31 | + @RequestParam(value = "virtualHostName", required = false) String virtualHostName, | ||
| 32 | + @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, | ||
| 33 | + @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize | ||
| 34 | + ) | ||
| 35 | + { | ||
| 36 | + UserInfo userInfo = UserInfo.builder().username(username).serverName(serverName).virtualHostName(virtualHostName).build(); | ||
| 37 | + return userInfoService.selectUserInfoList(userInfo, pageNum, pageSize); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + | ||
| 28 | /** | 41 | /** | 
| 29 | * 仅,查询用户列表 | 42 | * 仅,查询用户列表 | 
| 30 | */ | 43 | */ | 
| @@ -44,9 +57,14 @@ public class UserInfoController { | @@ -44,9 +57,14 @@ public class UserInfoController { | ||
| 44 | * @return {@link ResultJson} | 57 | * @return {@link ResultJson} | 
| 45 | */ | 58 | */ | 
| 46 | @PostMapping("/insert") | 59 | @PostMapping("/insert") | 
| 47 | - public ResultJson insertUserByEntity(@RequestBody UserInfo userInfo) throws IOException, URISyntaxException, TimeoutException | 60 | + public ResultJson insertUserInfo(@RequestBody UserInfo userInfo) | 
| 48 | { | 61 | { | 
| 49 | - return userInfoService.insertSelective(userInfo); | 62 | + try { | 
| 63 | + return userInfoService.insertSelective(userInfo); | ||
| 64 | + } catch (IOException | URISyntaxException | TimeoutException e) { | ||
| 65 | + e.printStackTrace(); | ||
| 66 | + return new ResultJson<>("500", "服务器异常,添加用户信息失败"); | ||
| 67 | + } | ||
| 50 | } | 68 | } | 
| 51 | 69 | ||
| 52 | /** | 70 | /** | 
| @@ -68,9 +86,34 @@ public class UserInfoController { | @@ -68,9 +86,34 @@ public class UserInfoController { | ||
| 68 | * @return | 86 | * @return | 
| 69 | */ | 87 | */ | 
| 70 | @PutMapping("/updatePassword") | 88 | @PutMapping("/updatePassword") | 
| 71 | - public ResultJson updatePassword(@RequestBody UserInfo userInfo) throws MalformedURLException, URISyntaxException | 89 | + public ResultJson updatePassword(@RequestBody UserInfo userInfo) throws IOException, URISyntaxException | 
| 72 | { | 90 | { | 
| 73 | return userInfoService.updatePassword(userInfo); | 91 | return userInfoService.updatePassword(userInfo); | 
| 74 | } | 92 | } | 
| 75 | 93 | ||
| 94 | + /** | ||
| 95 | + * 删除用户(MQ服务器 and 数据库) | ||
| 96 | + */ | ||
| 97 | + @DeleteMapping("/delete") | ||
| 98 | + public ResultJson deleteUser(@RequestBody UserInfo userInfo) | ||
| 99 | + { | ||
| 100 | + try { | ||
| 101 | + return userInfoService.deleteUserInfo(userInfo); | ||
| 102 | + } catch (IOException | URISyntaxException e) { | ||
| 103 | + return new ResultJson<>("500", "服务器异常,删除用户失败"); | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * 删除数据关系(MQ服务器 and 数据库) | ||
| 109 | + */ | ||
| 110 | + @DeleteMapping("/deleteRelation") | ||
| 111 | + public ResultJson deleteUserRelation(@RequestBody UserInfo userInfo) | ||
| 112 | + { | ||
| 113 | + try { | ||
| 114 | + return userInfoService.deleteUserRelation(userInfo); | ||
| 115 | + } catch (IOException | URISyntaxException e) { | ||
| 116 | + return new ResultJson<>("500", "服务器异常,删除用户关系失败"); | ||
| 117 | + } | ||
| 118 | + } | ||
| 76 | } | 119 | } | 
| 1 | package com.sunyo.wlpt.message.bus.service.mapper; | 1 | package com.sunyo.wlpt.message.bus.service.mapper; | 
| 2 | 2 | ||
| 3 | import com.sunyo.wlpt.message.bus.service.domain.BusQueue; | 3 | import com.sunyo.wlpt.message.bus.service.domain.BusQueue; | 
| 4 | -import org.apache.ibatis.annotations.Mapper;import java.util.List; | 4 | +import org.apache.ibatis.annotations.Mapper; | 
| 5 | + | ||
| 6 | +import java.util.List; | ||
| 5 | 7 | ||
| 6 | /** | 8 | /** | 
| 7 | * @author 子诚 | 9 | * @author 子诚 | 
| @@ -97,4 +99,12 @@ public interface BusQueueMapper { | @@ -97,4 +99,12 @@ public interface BusQueueMapper { | ||
| 97 | * @return | 99 | * @return | 
| 98 | */ | 100 | */ | 
| 99 | List<BusQueue> getQueueList(BusQueue busQueue); | 101 | List<BusQueue> getQueueList(BusQueue busQueue); | 
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * 根据用户名称查询队列信息 | ||
| 105 | + * | ||
| 106 | + * @param username 用户名称 | ||
| 107 | + * @return | ||
| 108 | + */ | ||
| 109 | + List<BusQueue> selectByUsername(String username); | ||
| 100 | } | 110 | } | 
| @@ -69,7 +69,7 @@ public interface UserInfoMapper { | @@ -69,7 +69,7 @@ public interface UserInfoMapper { | ||
| 69 | * @param username 用户登录名称 | 69 | * @param username 用户登录名称 | 
| 70 | * @return {@link UserInfo} | 70 | * @return {@link UserInfo} | 
| 71 | */ | 71 | */ | 
| 72 | - UserInfo selectByUsername(String username); | 72 | + List<UserInfo> selectByUsername(String username); | 
| 73 | 73 | ||
| 74 | /** | 74 | /** | 
| 75 | * 仅,查询用户列表 | 75 | * 仅,查询用户列表 | 
| @@ -109,4 +109,12 @@ public interface UserInfoMapper { | @@ -109,4 +109,12 @@ public interface UserInfoMapper { | ||
| 109 | * @return | 109 | * @return | 
| 110 | */ | 110 | */ | 
| 111 | List<UserInfo> selectByBusQueue(BusQueue busQueue); | 111 | List<UserInfo> selectByBusQueue(BusQueue busQueue); | 
| 112 | + | ||
| 113 | + /** | ||
| 114 | + * 根据用户名称删除用户信息 | ||
| 115 | + * | ||
| 116 | + * @param username | ||
| 117 | + * @return | ||
| 118 | + */ | ||
| 119 | + int deleteByUsername(String username); | ||
| 112 | } | 120 | } | 
| 1 | package com.sunyo.wlpt.message.bus.service.rabbit.utils; | 1 | package com.sunyo.wlpt.message.bus.service.rabbit.utils; | 
| 2 | 2 | ||
| 3 | import com.rabbitmq.http.client.Client; | 3 | import com.rabbitmq.http.client.Client; | 
| 4 | -import com.rabbitmq.http.client.domain.TopicPermissions; | ||
| 5 | import com.rabbitmq.http.client.domain.UserPermissions; | 4 | import com.rabbitmq.http.client.domain.UserPermissions; | 
| 6 | import com.sunyo.wlpt.message.bus.service.domain.BusServer; | 5 | import com.sunyo.wlpt.message.bus.service.domain.BusServer; | 
| 7 | import com.sunyo.wlpt.message.bus.service.domain.UserInfo; | 6 | import com.sunyo.wlpt.message.bus.service.domain.UserInfo; | 
| @@ -49,28 +48,40 @@ public class ClientUtils { | @@ -49,28 +48,40 @@ public class ClientUtils { | ||
| 49 | { | 48 | { | 
| 50 | // 新增用户的用户名称 | 49 | // 新增用户的用户名称 | 
| 51 | String username = userInfo.getUsername(); | 50 | String username = userInfo.getUsername(); | 
| 52 | - // 虚拟主机名称 | ||
| 53 | - String virtualHostName = userInfo.getVirtualHostName(); | ||
| 54 | 51 | ||
| 55 | // 与客户端建立连接 | 52 | // 与客户端建立连接 | 
| 56 | Client client = connectClient(busServer); | 53 | Client client = connectClient(busServer); | 
| 57 | ArrayList<String> list = new ArrayList<>(); | 54 | ArrayList<String> list = new ArrayList<>(); | 
| 58 | // 创建用户,权限为none | 55 | // 创建用户,权限为none | 
| 59 | client.createUser(username, password.toCharArray(), list); | 56 | client.createUser(username, password.toCharArray(), list); | 
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * 用户与虚拟主机建立联系 | ||
| 61 | + * | ||
| 62 | + * @param userInfo 用户信息 | ||
| 63 | + * @param busServer 服务器信息 | ||
| 64 | + * @throws IOException | ||
| 65 | + * @throws URISyntaxException | ||
| 66 | + */ | ||
| 67 | + public static void userRelation(UserInfo userInfo, BusServer busServer) throws IOException, URISyntaxException | ||
| 68 | + { | ||
| 69 | + String username = userInfo.getUsername(); | ||
| 70 | + String virtualHostName = userInfo.getVirtualHostName(); | ||
| 71 | + Client client = connectClient(busServer); | ||
| 60 | 72 | ||
| 61 | - // 用户与虚拟主机建立联系 | ||
| 62 | UserPermissions p = new UserPermissions(); | 73 | UserPermissions p = new UserPermissions(); | 
| 63 | p.setConfigure(username + ".*"); | 74 | p.setConfigure(username + ".*"); | 
| 64 | p.setRead(username + ".*"); | 75 | p.setRead(username + ".*"); | 
| 65 | p.setWrite(username + ".*"); | 76 | p.setWrite(username + ".*"); | 
| 66 | client.updatePermissions(virtualHostName, username, p); | 77 | client.updatePermissions(virtualHostName, username, p); | 
| 67 | 78 | ||
| 68 | - TopicPermissions topicPermissions = new TopicPermissions(); | ||
| 69 | - topicPermissions.setVhost(virtualHostName); | ||
| 70 | - topicPermissions.setExchange(""); | ||
| 71 | - topicPermissions.setRead(".*"); | ||
| 72 | - topicPermissions.setWrite(".*"); | ||
| 73 | - client.updateTopicPermissions(virtualHostName, username, topicPermissions); | 79 | +// TopicPermissions topicPermissions = new TopicPermissions(); | 
| 80 | +// topicPermissions.setVhost(virtualHostName); | ||
| 81 | +// topicPermissions.setExchange(""); | ||
| 82 | +// topicPermissions.setRead(".*"); | ||
| 83 | +// topicPermissions.setWrite(".*"); | ||
| 84 | +// client.updateTopicPermissions(virtualHostName, username, topicPermissions); | ||
| 74 | } | 85 | } | 
| 75 | 86 | ||
| 76 | /** | 87 | /** | 
| @@ -84,6 +95,15 @@ public class ClientUtils { | @@ -84,6 +95,15 @@ public class ClientUtils { | ||
| 84 | } | 95 | } | 
| 85 | 96 | ||
| 86 | /** | 97 | /** | 
| 98 | + * 删除用户 | ||
| 99 | + */ | ||
| 100 | + public static void deleteMQUser(String username, BusServer busServer) throws IOException, URISyntaxException | ||
| 101 | + { | ||
| 102 | + Client client = connectClient(busServer); | ||
| 103 | + client.deleteUser(username); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + /** | ||
| 87 | * 修改MQ的用户密码 | 107 | * 修改MQ的用户密码 | 
| 88 | */ | 108 | */ | 
| 89 | public static void updatePassword(BusServer busServer, String username, String password) throws IOException, URISyntaxException | 109 | public static void updatePassword(BusServer busServer, String username, String password) throws IOException, URISyntaxException | 
| @@ -102,13 +122,14 @@ public class ClientUtils { | @@ -102,13 +122,14 @@ public class ClientUtils { | ||
| 102 | Client client = connectClient(busServer); | 122 | Client client = connectClient(busServer); | 
| 103 | client.createVhost(vHost); | 123 | client.createVhost(vHost); | 
| 104 | } | 124 | } | 
| 125 | + | ||
| 105 | /** | 126 | /** | 
| 106 | * 创建虚拟主机 | 127 | * 创建虚拟主机 | 
| 107 | */ | 128 | */ | 
| 108 | public static void createVirtualHost(BusServer busServer, VirtualHost vHost) throws IOException, URISyntaxException | 129 | public static void createVirtualHost(BusServer busServer, VirtualHost vHost) throws IOException, URISyntaxException | 
| 109 | { | 130 | { | 
| 110 | Client client = connectClient(busServer); | 131 | Client client = connectClient(busServer); | 
| 111 | - client.createVhost(vHost.getVirtualHostName(),vHost.getDescription()); | 132 | + client.createVhost(vHost.getVirtualHostName(), vHost.getDescription()); | 
| 112 | } | 133 | } | 
| 113 | 134 | ||
| 114 | /** | 135 | /** | 
| @@ -104,5 +104,13 @@ public interface BusQueueService { | @@ -104,5 +104,13 @@ public interface BusQueueService { | ||
| 104 | * @return | 104 | * @return | 
| 105 | */ | 105 | */ | 
| 106 | List<BusQueue> selectByVirtualHostId(String virtualHostId); | 106 | List<BusQueue> selectByVirtualHostId(String virtualHostId); | 
| 107 | + | ||
| 108 | + /** | ||
| 109 | + * 根据用户名查询队列信息 | ||
| 110 | + * | ||
| 111 | + * @param username 用户名称 | ||
| 112 | + * @return | ||
| 113 | + */ | ||
| 114 | + List<BusQueue> selectByUsername(String username); | ||
| 107 | } | 115 | } | 
| 108 | 116 | 
| @@ -4,7 +4,6 @@ import com.sunyo.wlpt.message.bus.service.domain.UserInfo; | @@ -4,7 +4,6 @@ import com.sunyo.wlpt.message.bus.service.domain.UserInfo; | ||
| 4 | import com.sunyo.wlpt.message.bus.service.response.ResultJson; | 4 | import com.sunyo.wlpt.message.bus.service.response.ResultJson; | 
| 5 | 5 | ||
| 6 | import java.io.IOException; | 6 | import java.io.IOException; | 
| 7 | -import java.net.MalformedURLException; | ||
| 8 | import java.net.URISyntaxException; | 7 | import java.net.URISyntaxException; | 
| 9 | import java.util.List; | 8 | import java.util.List; | 
| 10 | import java.util.concurrent.TimeoutException; | 9 | import java.util.concurrent.TimeoutException; | 
| @@ -49,14 +48,6 @@ public interface UserInfoService { | @@ -49,14 +48,6 @@ public interface UserInfoService { | ||
| 49 | UserInfo selectByPrimaryKey(String id); | 48 | UserInfo selectByPrimaryKey(String id); | 
| 50 | 49 | ||
| 51 | /** | 50 | /** | 
| 52 | - * 查询,根据用户名称 | ||
| 53 | - * | ||
| 54 | - * @param username 用户登录名称 | ||
| 55 | - * @return {@link UserInfo} | ||
| 56 | - */ | ||
| 57 | - UserInfo selectByUsername(String username); | ||
| 58 | - | ||
| 59 | - /** | ||
| 60 | * 更新,选择性,根据主键 | 51 | * 更新,选择性,根据主键 | 
| 61 | * | 52 | * | 
| 62 | * @param record the updated record | 53 | * @param record the updated record | 
| @@ -93,7 +84,33 @@ public interface UserInfoService { | @@ -93,7 +84,33 @@ public interface UserInfoService { | ||
| 93 | * @param userInfo {@link UserInfo} | 84 | * @param userInfo {@link UserInfo} | 
| 94 | * @return | 85 | * @return | 
| 95 | */ | 86 | */ | 
| 96 | - ResultJson updatePassword(UserInfo userInfo) throws MalformedURLException, URISyntaxException; | 87 | + ResultJson updatePassword(UserInfo userInfo) throws IOException, URISyntaxException; | 
| 88 | + | ||
| 89 | + /** | ||
| 90 | + * 分页查询,用户信息,用户关系 | ||
| 91 | + * | ||
| 92 | + * @param userInfo 用户信息 | ||
| 93 | + * @param pageNum 当前页数 | ||
| 94 | + * @param pageSize 每页大小 | ||
| 95 | + * @return | ||
| 96 | + */ | ||
| 97 | + ResultJson selectUserInfoList(UserInfo userInfo, Integer pageNum, Integer pageSize); | ||
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * 删除MQ用户 | ||
| 101 | + * | ||
| 102 | + * @param userInfo {@link UserInfo} | ||
| 103 | + * @return 返回结果 | ||
| 104 | + */ | ||
| 105 | + ResultJson deleteUserInfo(UserInfo userInfo) throws IOException, URISyntaxException; | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * 删除用户关系 | ||
| 109 | + * | ||
| 110 | + * @param userInfo {@link UserInfo} | ||
| 111 | + * @return 返回结果 | ||
| 112 | + */ | ||
| 113 | + ResultJson deleteUserRelation(UserInfo userInfo) throws IOException, URISyntaxException; | ||
| 97 | } | 114 | } | 
| 98 | 115 | ||
| 99 | 116 | 
| @@ -162,13 +162,13 @@ public class BusQueueServiceImpl implements BusQueueService { | @@ -162,13 +162,13 @@ public class BusQueueServiceImpl implements BusQueueService { | ||
| 162 | public List<BusQueue> getQueueList(BusQueue busQueue) | 162 | public List<BusQueue> getQueueList(BusQueue busQueue) | 
| 163 | { | 163 | { | 
| 164 | List<BusQueue> list = new ArrayList<>(); | 164 | List<BusQueue> list = new ArrayList<>(); | 
| 165 | - String userIds = busQueue.getUserId(); | 165 | + String usernames = busQueue.getUsername(); | 
| 166 | String splitItem = ","; | 166 | String splitItem = ","; | 
| 167 | - if (!StringUtil.isNullOrEmpty(userIds)) { | ||
| 168 | - if (userIds.contains(splitItem)) { | ||
| 169 | - String[] split = userIds.split(splitItem); | ||
| 170 | - for (String userId : split) { | ||
| 171 | - busQueue.setUserId(userId); | 167 | + if (!StringUtil.isNullOrEmpty(usernames)) { | 
| 168 | + if (usernames.contains(splitItem)) { | ||
| 169 | + String[] split = usernames.split(splitItem); | ||
| 170 | + for (String username : split) { | ||
| 171 | + busQueue.setUsername(username); | ||
| 172 | List<BusQueue> queueList = busQueueMapper.getQueueList(busQueue); | 172 | List<BusQueue> queueList = busQueueMapper.getQueueList(busQueue); | 
| 173 | if (queueList.size() > 0) { | 173 | if (queueList.size() > 0) { | 
| 174 | list.addAll(queueList); | 174 | list.addAll(queueList); | 
| @@ -185,5 +185,11 @@ public class BusQueueServiceImpl implements BusQueueService { | @@ -185,5 +185,11 @@ public class BusQueueServiceImpl implements BusQueueService { | ||
| 185 | { | 185 | { | 
| 186 | return busQueueMapper.selectByVirtualHostId(virtualHostId); | 186 | return busQueueMapper.selectByVirtualHostId(virtualHostId); | 
| 187 | } | 187 | } | 
| 188 | + | ||
| 189 | + @Override | ||
| 190 | + public List<BusQueue> selectByUsername(String username) | ||
| 191 | + { | ||
| 192 | + return busQueueMapper.selectByUsername(username); | ||
| 193 | + } | ||
| 188 | } | 194 | } | 
| 189 | 195 | 
| @@ -175,9 +175,6 @@ public class MessageNoteServiceImpl implements MessageNoteService { | @@ -175,9 +175,6 @@ public class MessageNoteServiceImpl implements MessageNoteService { | ||
| 175 | */ | 175 | */ | 
| 176 | public MessageNote note_fillId(MessageNote messageNote) | 176 | public MessageNote note_fillId(MessageNote messageNote) | 
| 177 | { | 177 | { | 
| 178 | - UserInfo userInfo = userInfoService.selectByUsername(messageNote.getUsername()); | ||
| 179 | - messageNote.setUserId(userInfo.getId()); | ||
| 180 | - | ||
| 181 | BusServer busServer = busServerService.selectByServerName(messageNote.getServerName()); | 178 | BusServer busServer = busServerService.selectByServerName(messageNote.getServerName()); | 
| 182 | messageNote.setServerId(busServer.getId()); | 179 | messageNote.setServerId(busServer.getId()); | 
| 183 | 180 | 
| 1 | package com.sunyo.wlpt.message.bus.service.service.impl; | 1 | package com.sunyo.wlpt.message.bus.service.service.impl; | 
| 2 | 2 | ||
| 3 | -import com.rabbitmq.http.client.Client; | ||
| 4 | -import com.rabbitmq.http.client.domain.TopicPermissions; | ||
| 5 | -import com.rabbitmq.http.client.domain.UserPermissions; | 3 | +import com.github.pagehelper.PageHelper; | 
| 4 | +import com.github.pagehelper.PageInfo; | ||
| 6 | import com.sunyo.wlpt.message.bus.service.domain.BusQueue; | 5 | import com.sunyo.wlpt.message.bus.service.domain.BusQueue; | 
| 7 | import com.sunyo.wlpt.message.bus.service.domain.BusServer; | 6 | import com.sunyo.wlpt.message.bus.service.domain.BusServer; | 
| 8 | import com.sunyo.wlpt.message.bus.service.domain.UserInfo; | 7 | import com.sunyo.wlpt.message.bus.service.domain.UserInfo; | 
| 9 | import com.sunyo.wlpt.message.bus.service.domain.VirtualHost; | 8 | import com.sunyo.wlpt.message.bus.service.domain.VirtualHost; | 
| 10 | import com.sunyo.wlpt.message.bus.service.mapper.UserInfoMapper; | 9 | import com.sunyo.wlpt.message.bus.service.mapper.UserInfoMapper; | 
| 10 | +import com.sunyo.wlpt.message.bus.service.rabbit.utils.ClientUtils; | ||
| 11 | import com.sunyo.wlpt.message.bus.service.rabbit.utils.RabbitUtils; | 11 | import com.sunyo.wlpt.message.bus.service.rabbit.utils.RabbitUtils; | 
| 12 | import com.sunyo.wlpt.message.bus.service.response.ResultJson; | 12 | import com.sunyo.wlpt.message.bus.service.response.ResultJson; | 
| 13 | import com.sunyo.wlpt.message.bus.service.service.BusQueueService; | 13 | import com.sunyo.wlpt.message.bus.service.service.BusQueueService; | 
| @@ -16,16 +16,16 @@ import com.sunyo.wlpt.message.bus.service.service.UserInfoService; | @@ -16,16 +16,16 @@ import com.sunyo.wlpt.message.bus.service.service.UserInfoService; | ||
| 16 | import com.sunyo.wlpt.message.bus.service.service.VirtualHostService; | 16 | import com.sunyo.wlpt.message.bus.service.service.VirtualHostService; | 
| 17 | import com.sunyo.wlpt.message.bus.service.utils.IdUtils; | 17 | import com.sunyo.wlpt.message.bus.service.utils.IdUtils; | 
| 18 | import io.netty.util.internal.StringUtil; | 18 | import io.netty.util.internal.StringUtil; | 
| 19 | +import lombok.extern.slf4j.Slf4j; | ||
| 19 | import org.springframework.beans.factory.annotation.Value; | 20 | import org.springframework.beans.factory.annotation.Value; | 
| 20 | import org.springframework.boot.autoconfigure.amqp.RabbitProperties; | 21 | import org.springframework.boot.autoconfigure.amqp.RabbitProperties; | 
| 21 | import org.springframework.stereotype.Service; | 22 | import org.springframework.stereotype.Service; | 
| 22 | -import org.springframework.util.DigestUtils; | 23 | +import org.springframework.transaction.annotation.Propagation; | 
| 24 | +import org.springframework.transaction.annotation.Transactional; | ||
| 23 | 25 | ||
| 24 | import javax.annotation.Resource; | 26 | import javax.annotation.Resource; | 
| 25 | import java.io.IOException; | 27 | import java.io.IOException; | 
| 26 | -import java.net.MalformedURLException; | ||
| 27 | import java.net.URISyntaxException; | 28 | import java.net.URISyntaxException; | 
| 28 | -import java.util.ArrayList; | ||
| 29 | import java.util.List; | 29 | import java.util.List; | 
| 30 | import java.util.concurrent.TimeoutException; | 30 | import java.util.concurrent.TimeoutException; | 
| 31 | 31 | ||
| @@ -34,6 +34,7 @@ import java.util.concurrent.TimeoutException; | @@ -34,6 +34,7 @@ import java.util.concurrent.TimeoutException; | ||
| 34 | * Description: | 34 | * Description: | 
| 35 | * 时间:2020/6/29 17:15 | 35 | * 时间:2020/6/29 17:15 | 
| 36 | */ | 36 | */ | 
| 37 | +@Slf4j | ||
| 37 | @Service | 38 | @Service | 
| 38 | public class UserInfoServiceImpl implements UserInfoService { | 39 | public class UserInfoServiceImpl implements UserInfoService { | 
| 39 | 40 | ||
| @@ -82,32 +83,81 @@ public class UserInfoServiceImpl implements UserInfoService { | @@ -82,32 +83,81 @@ public class UserInfoServiceImpl implements UserInfoService { | ||
| 82 | return userInfoMapper.insert(record); | 83 | return userInfoMapper.insert(record); | 
| 83 | } | 84 | } | 
| 84 | 85 | ||
| 86 | + /** | ||
| 87 | + * 在MQ服务器上,添加用户信息,并根据一个or多个虚拟主机id(由于其中包含着服务器id,故不做个数判断),设置用户与虚拟主机关系 | ||
| 88 | + * <p> | ||
| 89 | + * 并创建用户对应的队列 | ||
| 90 | + * <p> | ||
| 91 | + * 并存储于数据库 | ||
| 92 | + * | ||
| 93 | + * @param userInfo {@link UserInfo} | ||
| 94 | + * @return {@link ResultJson} | ||
| 95 | + * @throws IOException | ||
| 96 | + * @throws URISyntaxException | ||
| 97 | + * @throws TimeoutException | ||
| 98 | + */ | ||
| 85 | @Override | 99 | @Override | 
| 100 | + @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) | ||
| 86 | public ResultJson insertSelective(UserInfo userInfo) throws IOException, URISyntaxException, TimeoutException | 101 | public ResultJson insertSelective(UserInfo userInfo) throws IOException, URISyntaxException, TimeoutException | 
| 87 | { | 102 | { | 
| 88 | String password = userInfo.getPassword(); | 103 | String password = userInfo.getPassword(); | 
| 89 | - | ||
| 90 | - VirtualHost virtualHost = virtualHostService.selectByPrimaryKey(userInfo.getVirtualHostId()); | ||
| 91 | - userInfo.setVirtualHostName(virtualHost.getVirtualHostName()); | ||
| 92 | - BusServer busServer = busServerService.selectByPrimaryKey(userInfo.getServerId()); | ||
| 93 | - userInfo.setServerName(busServer.getServerName()); | ||
| 94 | - | ||
| 95 | - ResultJson validateResult = validateUser(userInfo); | ||
| 96 | - if (!"200".equals(validateUser(userInfo).getCode())) { | ||
| 97 | - return validateResult; | 104 | + String virtualHostId = userInfo.getVirtualHostId(); | 
| 105 | + String splitItem = ","; | ||
| 106 | + if (virtualHostId.contains(splitItem)) { | ||
| 107 | + int index = 0; | ||
| 108 | + String[] split_hostId = virtualHostId.split(splitItem); | ||
| 109 | + for (int i = 0; i < split_hostId.length; i++) { | ||
| 110 | + VirtualHost virtualHost = virtualHostService.selectByPrimaryKey(split_hostId[i]); | ||
| 111 | + if (virtualHost != null) { | ||
| 112 | + userInfo.setVirtualHostId(virtualHost.getId()); | ||
| 113 | + userInfo.setVirtualHostName(virtualHost.getVirtualHostName()); | ||
| 114 | + | ||
| 115 | + userInfo.setVirtualHostName(virtualHost.getVirtualHostName()); | ||
| 116 | + BusServer busServer = busServerService.selectByPrimaryKey(virtualHost.getServerId()); | ||
| 117 | + | ||
| 118 | + userInfo.setServerId(busServer.getId()); | ||
| 119 | + userInfo.setServerName(busServer.getServerName()); | ||
| 120 | + | ||
| 121 | + userInfo.setId(IdUtils.generateId()); | ||
| 122 | + | ||
| 123 | + int num = userInfoMapper.insertSelective(userInfo); | ||
| 124 | + ClientUtils.addRabbitUser(userInfo, busServer, password); | ||
| 125 | + ClientUtils.userRelation(userInfo, busServer); | ||
| 126 | + createQueue(userInfo); | ||
| 127 | + index = index + num; | ||
| 128 | + } else { | ||
| 129 | + log.warn(split_hostId[i] + "->是服务器id"); | ||
| 130 | + } | ||
| 131 | + } | ||
| 132 | + return index > 0 | ||
| 133 | + ? new ResultJson<>("200", "添加用户信息,成功") | ||
| 134 | + : new ResultJson<>("500", "添加用户信息,失败"); | ||
| 135 | + } else { | ||
| 136 | + VirtualHost virtualHost = virtualHostService.selectByPrimaryKey(userInfo.getVirtualHostId()); | ||
| 137 | + int num = 0; | ||
| 138 | + if (virtualHost != null) { | ||
| 139 | + userInfo.setVirtualHostId(virtualHost.getId()); | ||
| 140 | + userInfo.setVirtualHostName(virtualHost.getVirtualHostName()); | ||
| 141 | + | ||
| 142 | + userInfo.setVirtualHostName(virtualHost.getVirtualHostName()); | ||
| 143 | + BusServer busServer = busServerService.selectByPrimaryKey(virtualHost.getServerId()); | ||
| 144 | + | ||
| 145 | + userInfo.setServerId(busServer.getId()); | ||
| 146 | + userInfo.setServerName(busServer.getServerName()); | ||
| 147 | + | ||
| 148 | + userInfo.setId(IdUtils.generateId()); | ||
| 149 | + | ||
| 150 | + num = userInfoMapper.insertSelective(userInfo); | ||
| 151 | + ClientUtils.addRabbitUser(userInfo, busServer, password); | ||
| 152 | + ClientUtils.userRelation(userInfo, busServer); | ||
| 153 | + createQueue(userInfo); | ||
| 154 | + } else { | ||
| 155 | + log.error(userInfo.getVirtualHostId() + "->并不是虚拟主机id;故添加失败"); | ||
| 156 | + } | ||
| 157 | + return num > 0 | ||
| 158 | + ? new ResultJson<>("200", "添加用户信息,成功") | ||
| 159 | + : new ResultJson<>("500", "添加用户信息,失败"); | ||
| 98 | } | 160 | } | 
| 99 | - userInfo.setId(IdUtils.generateId()); | ||
| 100 | - userInfo.setPassword(DigestUtils.md5DigestAsHex(userInfo.getPassword().getBytes())); | ||
| 101 | - | ||
| 102 | - int num = userInfoMapper.insertSelective(userInfo); | ||
| 103 | - // 1.根据用户信息,在MQ创建用户 | ||
| 104 | - addMQUser(userInfo, password); | ||
| 105 | - // 3.在对应虚拟机下创建队列 | ||
| 106 | - createQueue(userInfo); | ||
| 107 | - | ||
| 108 | - return num > 0 | ||
| 109 | - ? new ResultJson<>("200", "添加用户信息,成功") | ||
| 110 | - : new ResultJson<>("500", "添加用户信息,失败"); | ||
| 111 | } | 161 | } | 
| 112 | 162 | ||
| 113 | /** | 163 | /** | 
| @@ -121,9 +171,8 @@ public class UserInfoServiceImpl implements UserInfoService { | @@ -121,9 +171,8 @@ public class UserInfoServiceImpl implements UserInfoService { | ||
| 121 | { | 171 | { | 
| 122 | BusQueue busQueue = BusQueue.builder() | 172 | BusQueue busQueue = BusQueue.builder() | 
| 123 | .id(IdUtils.generateId()) | 173 | .id(IdUtils.generateId()) | 
| 124 | - .userId(userInfo.getId()) | ||
| 125 | .username(userInfo.getUsername()) | 174 | .username(userInfo.getUsername()) | 
| 126 | - .queueName(userInfo.getUsername() + "_R") | 175 | + .queueName(userInfo.getVirtualHostName() + "_" + userInfo.getUsername() + "_R") | 
| 127 | .virtualHostId(userInfo.getVirtualHostId()) | 176 | .virtualHostId(userInfo.getVirtualHostId()) | 
| 128 | .durability(true) | 177 | .durability(true) | 
| 129 | .autoDelete(false) | 178 | .autoDelete(false) | 
| @@ -132,36 +181,6 @@ public class UserInfoServiceImpl implements UserInfoService { | @@ -132,36 +181,6 @@ public class UserInfoServiceImpl implements UserInfoService { | ||
| 132 | busQueueService.insertSelective(busQueue); | 181 | busQueueService.insertSelective(busQueue); | 
| 133 | } | 182 | } | 
| 134 | 183 | ||
| 135 | - | ||
| 136 | - /** | ||
| 137 | - * 添加MQ用户信息,并配置MQ用户与虚拟主机的关系 | ||
| 138 | - * | ||
| 139 | - * @param userInfo {@link UserInfo} | ||
| 140 | - */ | ||
| 141 | - public void addMQUser(UserInfo userInfo, String password) throws MalformedURLException, URISyntaxException | ||
| 142 | - { | ||
| 143 | - String username = userInfo.getUsername(); | ||
| 144 | - String virtualHostName = userInfo.getVirtualHostName(); | ||
| 145 | - | ||
| 146 | - String url = "http://" + host + ":15672/api"; | ||
| 147 | - Client client = new Client(url, rabbitUsername, rabbitPassword); | ||
| 148 | - ArrayList<String> list = new ArrayList<>(); | ||
| 149 | - client.createUser(username, password.toCharArray(), list); | ||
| 150 | - | ||
| 151 | - UserPermissions p = new UserPermissions(); | ||
| 152 | - p.setConfigure(username + ".*"); | ||
| 153 | - p.setRead(username + ".*"); | ||
| 154 | - p.setWrite(username + ".*"); | ||
| 155 | - client.updatePermissions(virtualHostName, username, p); | ||
| 156 | - | ||
| 157 | - TopicPermissions topicPermissions = new TopicPermissions(); | ||
| 158 | - topicPermissions.setVhost(virtualHostName); | ||
| 159 | - topicPermissions.setExchange(""); | ||
| 160 | - topicPermissions.setRead(".*"); | ||
| 161 | - topicPermissions.setWrite(".*"); | ||
| 162 | - client.updateTopicPermissions(virtualHostName, username, topicPermissions); | ||
| 163 | - } | ||
| 164 | - | ||
| 165 | @Override | 184 | @Override | 
| 166 | public UserInfo selectByPrimaryKey(String id) | 185 | public UserInfo selectByPrimaryKey(String id) | 
| 167 | { | 186 | { | 
| @@ -169,12 +188,6 @@ public class UserInfoServiceImpl implements UserInfoService { | @@ -169,12 +188,6 @@ public class UserInfoServiceImpl implements UserInfoService { | ||
| 169 | } | 188 | } | 
| 170 | 189 | ||
| 171 | @Override | 190 | @Override | 
| 172 | - public UserInfo selectByUsername(String username) | ||
| 173 | - { | ||
| 174 | - return userInfoMapper.selectByUsername(username); | ||
| 175 | - } | ||
| 176 | - | ||
| 177 | - @Override | ||
| 178 | public ResultJson updateByPrimaryKeySelective(UserInfo userInfo) | 191 | public ResultJson updateByPrimaryKeySelective(UserInfo userInfo) | 
| 179 | { | 192 | { | 
| 180 | if (StringUtil.isNullOrEmpty(userInfo.getId())) { | 193 | if (StringUtil.isNullOrEmpty(userInfo.getId())) { | 
| @@ -189,7 +202,7 @@ public class UserInfoServiceImpl implements UserInfoService { | @@ -189,7 +202,7 @@ public class UserInfoServiceImpl implements UserInfoService { | ||
| 189 | } | 202 | } | 
| 190 | 203 | ||
| 191 | /** | 204 | /** | 
| 192 | - * 校验用户名称是否已经存在 | 205 | + * 校验用户信息 | 
| 193 | */ | 206 | */ | 
| 194 | public ResultJson validateUser(UserInfo userInfo) | 207 | public ResultJson validateUser(UserInfo userInfo) | 
| 195 | { | 208 | { | 
| @@ -199,6 +212,7 @@ public class UserInfoServiceImpl implements UserInfoService { | @@ -199,6 +212,7 @@ public class UserInfoServiceImpl implements UserInfoService { | ||
| 199 | if (StringUtil.isNullOrEmpty(userInfo.getServerName()) || StringUtil.isNullOrEmpty(userInfo.getVirtualHostName())) { | 212 | if (StringUtil.isNullOrEmpty(userInfo.getServerName()) || StringUtil.isNullOrEmpty(userInfo.getVirtualHostName())) { | 
| 200 | return new ResultJson<>("400", "服务器和虚拟主机,不能为空"); | 213 | return new ResultJson<>("400", "服务器和虚拟主机,不能为空"); | 
| 201 | } | 214 | } | 
| 215 | + | ||
| 202 | String userId = userInfo.getId(); | 216 | String userId = userInfo.getId(); | 
| 203 | if (!StringUtil.isNullOrEmpty(userId)) { | 217 | if (!StringUtil.isNullOrEmpty(userId)) { | 
| 204 | UserInfo oldUserInfo = userInfoMapper.selectByPrimaryKey(userId); | 218 | UserInfo oldUserInfo = userInfoMapper.selectByPrimaryKey(userId); | 
| @@ -207,9 +221,9 @@ public class UserInfoServiceImpl implements UserInfoService { | @@ -207,9 +221,9 @@ public class UserInfoServiceImpl implements UserInfoService { | ||
| 207 | } | 221 | } | 
| 208 | return ResultJson.success("通过校验"); | 222 | return ResultJson.success("通过校验"); | 
| 209 | } else { | 223 | } else { | 
| 210 | - List<UserInfo> userInfos = userInfoMapper.selectUserExist(userInfo.getUsername()); | 224 | + List<UserInfo> userInfos = userInfoMapper.validateUserInfo(userInfo); | 
| 211 | return userInfos.size() > 0 | 225 | return userInfos.size() > 0 | 
| 212 | - ? new ResultJson<>("400", "该用户,已存在") | 226 | + ? new ResultJson<>("400", "该用户信息,已存在") | 
| 213 | : ResultJson.success("通过校验"); | 227 | : ResultJson.success("通过校验"); | 
| 214 | } | 228 | } | 
| 215 | } | 229 | } | 
| @@ -233,7 +247,7 @@ public class UserInfoServiceImpl implements UserInfoService { | @@ -233,7 +247,7 @@ public class UserInfoServiceImpl implements UserInfoService { | ||
| 233 | } | 247 | } | 
| 234 | 248 | ||
| 235 | @Override | 249 | @Override | 
| 236 | - public ResultJson updatePassword(UserInfo userInfo) throws MalformedURLException, URISyntaxException | 250 | + public ResultJson updatePassword(UserInfo userInfo) throws IOException, URISyntaxException | 
| 237 | { | 251 | { | 
| 238 | if (StringUtil.isNullOrEmpty(userInfo.getUsername()) || StringUtil.isNullOrEmpty(userInfo.getPassword())) { | 252 | if (StringUtil.isNullOrEmpty(userInfo.getUsername()) || StringUtil.isNullOrEmpty(userInfo.getPassword())) { | 
| 239 | return new ResultJson<>("400", "用户名和密码,不能为空"); | 253 | return new ResultJson<>("400", "用户名和密码,不能为空"); | 
| @@ -241,25 +255,70 @@ public class UserInfoServiceImpl implements UserInfoService { | @@ -241,25 +255,70 @@ public class UserInfoServiceImpl implements UserInfoService { | ||
| 241 | if (userInfoMapper.selectUserExist(userInfo.getUsername()).size() == 0) { | 255 | if (userInfoMapper.selectUserExist(userInfo.getUsername()).size() == 0) { | 
| 242 | return new ResultJson<>("400", "该用户不存在"); | 256 | return new ResultJson<>("400", "该用户不存在"); | 
| 243 | } | 257 | } | 
| 244 | - UserInfo oldUserInfo = userInfoMapper.selectByUsername(userInfo.getUsername()); | ||
| 245 | - oldUserInfo.setPassword(DigestUtils.md5DigestAsHex(userInfo.getPassword().getBytes())); | ||
| 246 | - int num = userInfoMapper.updateByPrimaryKeySelective(oldUserInfo); | ||
| 247 | - // 在这里修改MQ用户密码 | ||
| 248 | - Client client = connectClient(); | ||
| 249 | - ArrayList<String> tags = new ArrayList<>(); | ||
| 250 | - client.updateUser(userInfo.getUsername(), userInfo.getPassword().toCharArray(), tags); | ||
| 251 | - return num > 0 | ||
| 252 | - ? new ResultJson<>("200", userInfo.getUsername() + "用户:修改密码成功!") | ||
| 253 | - : new ResultJson<>("500", userInfo.getUsername() + "用户:修改密码失败!"); | 258 | + BusServer busServer = busServerService.selectByPrimaryKey(userInfo.getServerId()); | 
| 259 | + String newPassword = userInfo.getPassword(); | ||
| 260 | + ClientUtils.updatePassword(busServer, userInfo.getUsername(), newPassword); | ||
| 261 | + return new ResultJson<>("200", "修改密码成功"); | ||
| 254 | } | 262 | } | 
| 255 | 263 | ||
| 256 | - public Client connectClient() throws MalformedURLException, URISyntaxException | 264 | + @Override | 
| 265 | + public ResultJson selectUserInfoList(UserInfo userInfo, Integer pageNum, Integer pageSize) | ||
| 257 | { | 266 | { | 
| 258 | - String url = "http://" + host + ":15672/api"; | ||
| 259 | - Client client = new Client(url, rabbitUsername, rabbitPassword); | ||
| 260 | - return client; | 267 | + PageHelper.startPage(pageNum, pageSize); | 
| 268 | + List<UserInfo> userInfoList = userInfoMapper.selectUserInfoList(userInfo); | ||
| 269 | + PageInfo<UserInfo> pageInfo = new PageInfo<>(userInfoList); | ||
| 270 | + return pageInfo.getTotal() > 0 | ||
| 271 | + ? new ResultJson<>("200", "查询用户信息列表,成功!", pageInfo) | ||
| 272 | + : new ResultJson<>("500", "查询用户信息列表,失败!"); | ||
| 261 | } | 273 | } | 
| 262 | 274 | ||
| 275 | + /** | ||
| 276 | + * 删除根据用户名删除该用户的所有关系 | ||
| 277 | + * <p> | ||
| 278 | + * QM服务器上删除该用户(会自动删除该用户关系) | ||
| 279 | + * <p> | ||
| 280 | + * MQ服务器(以及数据库)删除该用户对应队列(日后需要时,打开注释,即可) | ||
| 281 | + */ | ||
| 282 | + @Override | ||
| 283 | + public ResultJson deleteUserInfo(UserInfo userInfo) throws IOException, URISyntaxException | ||
| 284 | + { | ||
| 285 | + String username = userInfo.getUsername(); | ||
| 286 | + List<UserInfo> userInfoList = userInfoMapper.selectByUsername(userInfo.getUsername()); | ||
| 287 | + int num = userInfoMapper.deleteByUsername(username); | ||
| 288 | + for (UserInfo item : userInfoList) { | ||
| 289 | + BusServer busServer = busServerService.selectByPrimaryKey(item.getServerId()); | ||
| 290 | + ClientUtils.deleteMQUser(username, busServer); | ||
| 291 | + } | ||
| 292 | + | ||
| 293 | + | ||
| 294 | +// List<BusQueue> queueList = busQueueService.selectByUsername(username); | ||
| 295 | +// for (BusQueue queue : queueList) { | ||
| 296 | +// busQueueService.deleteByPrimaryKey(queue.getId()); | ||
| 297 | +// } | ||
| 298 | + | ||
| 299 | + return num > 0 | ||
| 300 | + ? new ResultJson<>("200", "删除用户信息,成功!") | ||
| 301 | + : new ResultJson<>("500", "删除用户信息,失败!"); | ||
| 302 | + } | ||
| 303 | + | ||
| 304 | + /** | ||
| 305 | + * 删除用户关系(数据库 and MQ服务器) | ||
| 306 | + * | ||
| 307 | + * @param userInfo {@link UserInfo} | ||
| 308 | + * @return 返回结果 | ||
| 309 | + * @throws IOException 输入输出异常 | ||
| 310 | + * @throws URISyntaxException URI语法异常 | ||
| 311 | + */ | ||
| 312 | + @Override | ||
| 313 | + public ResultJson deleteUserRelation(UserInfo userInfo) throws IOException, URISyntaxException | ||
| 314 | + { | ||
| 315 | + int num = userInfoMapper.deleteByPrimaryKey(userInfo.getId()); | ||
| 316 | + BusServer busServer = busServerService.selectByPrimaryKey(userInfo.getServerId()); | ||
| 317 | + ClientUtils.clearPermissions(busServer, userInfo.getVirtualHostName(), userInfo.getUsername()); | ||
| 318 | + return num > 0 | ||
| 319 | + ? new ResultJson<>("200", "删除用户关系,成功!") | ||
| 320 | + : new ResultJson<>("500", "删除用户关系,失败!"); | ||
| 321 | + } | ||
| 263 | } | 322 | } | 
| 264 | 323 | ||
| 265 | 324 | 
| @@ -110,13 +110,13 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | @@ -110,13 +110,13 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | ||
| 110 | String queueId = userMessageBinding.getQueueId(); | 110 | String queueId = userMessageBinding.getQueueId(); | 
| 111 | String exchangeId = userMessageBinding.getExchangeId(); | 111 | String exchangeId = userMessageBinding.getExchangeId(); | 
| 112 | String routingKeyId = userMessageBinding.getRoutingKeyId(); | 112 | String routingKeyId = userMessageBinding.getRoutingKeyId(); | 
| 113 | - String userId = userMessageBinding.getUserId(); | 113 | + String username = userMessageBinding.getUsername(); | 
| 114 | String splitItem = ","; | 114 | String splitItem = ","; | 
| 115 | 115 | ||
| 116 | - // 循环最外层,userId | ||
| 117 | - if (userId.contains(splitItem)) { | ||
| 118 | - String[] split_userId = userId.split(splitItem); | ||
| 119 | - for (int i = 0; i < split_userId.length; i++) { | 116 | + // 循环最外层,username | 
| 117 | + if (username.contains(splitItem)) { | ||
| 118 | + String[] split_username = username.split(splitItem); | ||
| 119 | + for (int i = 0; i < split_username.length; i++) { | ||
| 120 | // 循环第二层,exchangeId | 120 | // 循环第二层,exchangeId | 
| 121 | if (exchangeId.contains(splitItem)) { | 121 | if (exchangeId.contains(splitItem)) { | 
| 122 | String[] split_exchangeId = exchangeId.split(splitItem); | 122 | String[] split_exchangeId = exchangeId.split(splitItem); | 
| @@ -129,7 +129,7 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | @@ -129,7 +129,7 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | ||
| 129 | if (queueId.contains(splitItem)) { | 129 | if (queueId.contains(splitItem)) { | 
| 130 | String[] split_queueId = queueId.split(splitItem); | 130 | String[] split_queueId = queueId.split(splitItem); | 
| 131 | for (int l = 0; l < split_queueId.length; l++) { | 131 | for (int l = 0; l < split_queueId.length; l++) { | 
| 132 | - userMessageBinding.setUserId(split_userId[i]); | 132 | + userMessageBinding.setUsername(split_username[i]); | 
| 133 | userMessageBinding.setExchangeId(split_exchangeId[j]); | 133 | userMessageBinding.setExchangeId(split_exchangeId[j]); | 
| 134 | userMessageBinding.setRoutingKeyId(split_routingKeyId[k]); | 134 | userMessageBinding.setRoutingKeyId(split_routingKeyId[k]); | 
| 135 | userMessageBinding.setQueueId(split_queueId[l]); | 135 | userMessageBinding.setQueueId(split_queueId[l]); | 
| @@ -139,7 +139,7 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | @@ -139,7 +139,7 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | ||
| 139 | } | 139 | } | 
| 140 | } | 140 | } | 
| 141 | } else { | 141 | } else { | 
| 142 | - userMessageBinding.setUserId(split_userId[i]); | 142 | + userMessageBinding.setUsername(split_username[i]); | 
| 143 | userMessageBinding.setExchangeId(split_exchangeId[j]); | 143 | userMessageBinding.setExchangeId(split_exchangeId[j]); | 
| 144 | userMessageBinding.setRoutingKeyId(split_routingKeyId[k]); | 144 | userMessageBinding.setRoutingKeyId(split_routingKeyId[k]); | 
| 145 | int num = nextValidateAndFill(userMessageBinding); | 145 | int num = nextValidateAndFill(userMessageBinding); | 
| @@ -153,7 +153,7 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | @@ -153,7 +153,7 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | ||
| 153 | if (queueId.contains(splitItem)) { | 153 | if (queueId.contains(splitItem)) { | 
| 154 | String[] split_queueId = queueId.split(splitItem); | 154 | String[] split_queueId = queueId.split(splitItem); | 
| 155 | for (int l = 0; l < split_queueId.length; l++) { | 155 | for (int l = 0; l < split_queueId.length; l++) { | 
| 156 | - userMessageBinding.setUserId(split_userId[i]); | 156 | + userMessageBinding.setUsername(split_username[i]); | 
| 157 | userMessageBinding.setExchangeId(split_exchangeId[j]); | 157 | userMessageBinding.setExchangeId(split_exchangeId[j]); | 
| 158 | userMessageBinding.setQueueId(split_queueId[l]); | 158 | userMessageBinding.setQueueId(split_queueId[l]); | 
| 159 | int num = nextValidateAndFill(userMessageBinding); | 159 | int num = nextValidateAndFill(userMessageBinding); | 
| @@ -162,7 +162,7 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | @@ -162,7 +162,7 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | ||
| 162 | } | 162 | } | 
| 163 | } | 163 | } | 
| 164 | } else { | 164 | } else { | 
| 165 | - userMessageBinding.setUserId(split_userId[i]); | 165 | + userMessageBinding.setUsername(split_username[i]); | 
| 166 | userMessageBinding.setExchangeId(split_exchangeId[j]); | 166 | userMessageBinding.setExchangeId(split_exchangeId[j]); | 
| 167 | int num = nextValidateAndFill(userMessageBinding); | 167 | int num = nextValidateAndFill(userMessageBinding); | 
| 168 | if (num > 0) { | 168 | if (num > 0) { | 
| @@ -181,7 +181,7 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | @@ -181,7 +181,7 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | ||
| 181 | if (queueId.contains(splitItem)) { | 181 | if (queueId.contains(splitItem)) { | 
| 182 | String[] split_queueId = queueId.split(splitItem); | 182 | String[] split_queueId = queueId.split(splitItem); | 
| 183 | for (int l = 0; l < split_queueId.length; l++) { | 183 | for (int l = 0; l < split_queueId.length; l++) { | 
| 184 | - userMessageBinding.setUserId(split_userId[i]); | 184 | + userMessageBinding.setUsername(split_username[i]); | 
| 185 | userMessageBinding.setRoutingKeyId(split_routingKeyId[k]); | 185 | userMessageBinding.setRoutingKeyId(split_routingKeyId[k]); | 
| 186 | userMessageBinding.setQueueId(split_queueId[l]); | 186 | userMessageBinding.setQueueId(split_queueId[l]); | 
| 187 | int num = nextValidateAndFill(userMessageBinding); | 187 | int num = nextValidateAndFill(userMessageBinding); | 
| @@ -190,7 +190,7 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | @@ -190,7 +190,7 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | ||
| 190 | } | 190 | } | 
| 191 | } | 191 | } | 
| 192 | } else { | 192 | } else { | 
| 193 | - userMessageBinding.setUserId(split_userId[i]); | 193 | + userMessageBinding.setUsername(split_username[i]); | 
| 194 | userMessageBinding.setRoutingKeyId(split_routingKeyId[k]); | 194 | userMessageBinding.setRoutingKeyId(split_routingKeyId[k]); | 
| 195 | int num = nextValidateAndFill(userMessageBinding); | 195 | int num = nextValidateAndFill(userMessageBinding); | 
| 196 | if (num > 0) { | 196 | if (num > 0) { | 
| @@ -203,7 +203,7 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | @@ -203,7 +203,7 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | ||
| 203 | if (queueId.contains(splitItem)) { | 203 | if (queueId.contains(splitItem)) { | 
| 204 | String[] split_queueId = queueId.split(splitItem); | 204 | String[] split_queueId = queueId.split(splitItem); | 
| 205 | for (int l = 0; l < split_queueId.length; l++) { | 205 | for (int l = 0; l < split_queueId.length; l++) { | 
| 206 | - userMessageBinding.setUserId(split_userId[i]); | 206 | + userMessageBinding.setUsername(split_username[i]); | 
| 207 | userMessageBinding.setQueueId(split_queueId[l]); | 207 | userMessageBinding.setQueueId(split_queueId[l]); | 
| 208 | int num = nextValidateAndFill(userMessageBinding); | 208 | int num = nextValidateAndFill(userMessageBinding); | 
| 209 | if (num > 0) { | 209 | if (num > 0) { | 
| @@ -211,7 +211,7 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | @@ -211,7 +211,7 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | ||
| 211 | } | 211 | } | 
| 212 | } | 212 | } | 
| 213 | } else { | 213 | } else { | 
| 214 | - userMessageBinding.setUserId(split_userId[i]); | 214 | + userMessageBinding.setUsername(split_username[i]); | 
| 215 | int num = nextValidateAndFill(userMessageBinding); | 215 | int num = nextValidateAndFill(userMessageBinding); | 
| 216 | if (num > 0) { | 216 | if (num > 0) { | 
| 217 | index = index + num; | 217 | index = index + num; | 
| @@ -352,30 +352,20 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | @@ -352,30 +352,20 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | ||
| 352 | */ | 352 | */ | 
| 353 | public UserMessageBinding umb_fillName(UserMessageBinding userMessageBinding) | 353 | public UserMessageBinding umb_fillName(UserMessageBinding userMessageBinding) | 
| 354 | { | 354 | { | 
| 355 | - // 增加之设置id | ||
| 356 | userMessageBinding.setId(IdUtils.generateId()); | 355 | userMessageBinding.setId(IdUtils.generateId()); | 
| 357 | 356 | ||
| 358 | - // 填充,用户名称 | ||
| 359 | - UserInfo userInfo = userInfoService.selectByPrimaryKey(userMessageBinding.getUserId()); | ||
| 360 | - userMessageBinding.setUsername(userInfo.getUsername()); | ||
| 361 | - | ||
| 362 | - // 填充,服务器名称 | ||
| 363 | BusServer busServer = busServerService.selectByPrimaryKey(userMessageBinding.getServerId()); | 357 | BusServer busServer = busServerService.selectByPrimaryKey(userMessageBinding.getServerId()); | 
| 364 | userMessageBinding.setServerName(busServer.getServerName()); | 358 | userMessageBinding.setServerName(busServer.getServerName()); | 
| 365 | 359 | ||
| 366 | - // 填充,虚拟主机名称 | ||
| 367 | VirtualHost virtualHost = virtualHostService.selectByPrimaryKey(userMessageBinding.getVirtualHostId()); | 360 | VirtualHost virtualHost = virtualHostService.selectByPrimaryKey(userMessageBinding.getVirtualHostId()); | 
| 368 | userMessageBinding.setVirtualHostName(virtualHost.getVirtualHostName()); | 361 | userMessageBinding.setVirtualHostName(virtualHost.getVirtualHostName()); | 
| 369 | 362 | ||
| 370 | - // 填充,交换机名称 | ||
| 371 | BusExchange busExchange = busExchangeService.selectByPrimaryKey(userMessageBinding.getExchangeId()); | 363 | BusExchange busExchange = busExchangeService.selectByPrimaryKey(userMessageBinding.getExchangeId()); | 
| 372 | userMessageBinding.setExchangeName(busExchange.getExchangeName()); | 364 | userMessageBinding.setExchangeName(busExchange.getExchangeName()); | 
| 373 | 365 | ||
| 374 | - // 填充,队列名称 | ||
| 375 | BusQueue busQueue = busQueueService.selectByPrimaryKey(userMessageBinding.getQueueId()); | 366 | BusQueue busQueue = busQueueService.selectByPrimaryKey(userMessageBinding.getQueueId()); | 
| 376 | userMessageBinding.setQueueName(busQueue.getQueueName()); | 367 | userMessageBinding.setQueueName(busQueue.getQueueName()); | 
| 377 | 368 | ||
| 378 | - // 填充,路由键名称 | ||
| 379 | RoutingKey routingKey = routingKeyService.selectByPrimaryKey(userMessageBinding.getRoutingKeyId()); | 369 | RoutingKey routingKey = routingKeyService.selectByPrimaryKey(userMessageBinding.getRoutingKeyId()); | 
| 380 | userMessageBinding.setRoutingKeyName(routingKey.getRoutingKeyName()); | 370 | userMessageBinding.setRoutingKeyName(routingKey.getRoutingKeyName()); | 
| 381 | 371 | ||
| @@ -408,8 +398,8 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | @@ -408,8 +398,8 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | ||
| 408 | log.error(userMessageBinding + "--> 该绑定关系已存在"); | 398 | log.error(userMessageBinding + "--> 该绑定关系已存在"); | 
| 409 | return 0; | 399 | return 0; | 
| 410 | } else if (validate == null) { | 400 | } else if (validate == null) { | 
| 411 | - // 此处添加MQ服务器上的绑定关系 | ||
| 412 | UserMessageBinding completeBinding = umb_fillName(userMessageBinding); | 401 | UserMessageBinding completeBinding = umb_fillName(userMessageBinding); | 
| 402 | + // MQ服务器上进行绑定关系 | ||
| 413 | rabbitUtils.toCreateBinding(completeBinding); | 403 | rabbitUtils.toCreateBinding(completeBinding); | 
| 414 | return userMessageBindingMapper.insertSelective(completeBinding); | 404 | return userMessageBindingMapper.insertSelective(completeBinding); | 
| 415 | } else { | 405 | } else { | 
| @@ -254,9 +254,16 @@ | @@ -254,9 +254,16 @@ | ||
| 254 | <if test="virtualHostId != null and virtualHostId != ''"> | 254 | <if test="virtualHostId != null and virtualHostId != ''"> | 
| 255 | virtual_host_id = #{virtualHostId,jdbcType=VARCHAR} | 255 | virtual_host_id = #{virtualHostId,jdbcType=VARCHAR} | 
| 256 | </if> | 256 | </if> | 
| 257 | - <if test="userId != null and userId != ''"> | ||
| 258 | - and user_id = #{userId,jdbcType=VARCHAR} | 257 | + <if test="username != null and username != ''"> | 
| 258 | + and username = #{username,jdbcType=VARCHAR} | ||
| 259 | </if> | 259 | </if> | 
| 260 | </where> | 260 | </where> | 
| 261 | </select> | 261 | </select> | 
| 262 | + | ||
| 263 | + <select id="selectByUsername" parameterType="java.lang.String" resultMap="BaseResultMap"> | ||
| 264 | + select | ||
| 265 | + <include refid="Base_Column_List"/> | ||
| 266 | + from bus_queue | ||
| 267 | + where username = #{username,jdbcType=VARCHAR} | ||
| 268 | + </select> | ||
| 262 | </mapper> | 269 | </mapper> | 
| 1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> | 
| 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | 
| 3 | <mapper namespace="com.sunyo.wlpt.message.bus.service.mapper.UserInfoMapper"> | 3 | <mapper namespace="com.sunyo.wlpt.message.bus.service.mapper.UserInfoMapper"> | 
| 4 | - <cache type="com.sunyo.wlpt.message.bus.service.cache.RedisCache"/> | 4 | + <cache-ref namespace="com.sunyo.wlpt.message.bus.service.mapper.VirtualHostMapper"/> | 
| 5 | <resultMap id="BaseResultMap" type="com.sunyo.wlpt.message.bus.service.domain.UserInfo"> | 5 | <resultMap id="BaseResultMap" type="com.sunyo.wlpt.message.bus.service.domain.UserInfo"> | 
| 6 | <!--@mbg.generated--> | 6 | <!--@mbg.generated--> | 
| 7 | <!--@Table user_info--> | 7 | <!--@Table user_info--> | 
| @@ -35,6 +35,11 @@ | @@ -35,6 +35,11 @@ | ||
| 35 | from user_info | 35 | from user_info | 
| 36 | where id = #{id,jdbcType=VARCHAR} | 36 | where id = #{id,jdbcType=VARCHAR} | 
| 37 | </delete> | 37 | </delete> | 
| 38 | + <delete id="deleteByUsername" parameterType="java.lang.String"> | ||
| 39 | + delete | ||
| 40 | + from user_info | ||
| 41 | + where username = #{username,jdbcType=VARCHAR} | ||
| 42 | + </delete> | ||
| 38 | <insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.UserInfo"> | 43 | <insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.UserInfo"> | 
| 39 | <!--@mbg.generated--> | 44 | <!--@mbg.generated--> | 
| 40 | insert into user_info (id, username, `password`, | 45 | insert into user_info (id, username, `password`, | 
| @@ -204,4 +209,45 @@ | @@ -204,4 +209,45 @@ | ||
| 204 | from user_info | 209 | from user_info | 
| 205 | where username = #{username,jdbcType=VARCHAR} | 210 | where username = #{username,jdbcType=VARCHAR} | 
| 206 | </select> | 211 | </select> | 
| 212 | + | ||
| 213 | + <select id="selectUserInfoList" resultMap="BaseResultMap"> | ||
| 214 | + select | ||
| 215 | + <include refid="Base_Column_List"/> | ||
| 216 | + from user_info | ||
| 217 | + <where> | ||
| 218 | + <if test="username != null and username != ''"> | ||
| 219 | + username = #{username,jdbcType=VARCHAR} | ||
| 220 | + </if> | ||
| 221 | + <if test="serverName != null and serverName != ''"> | ||
| 222 | + and server_name = #{serverName,jdbcType=VARCHAR} | ||
| 223 | + </if> | ||
| 224 | + <if test="virtualHostName != null and virtualHostName != ''"> | ||
| 225 | + and virtual_host_name = #{virtualHostName,jdbcType=VARCHAR} | ||
| 226 | + </if> | ||
| 227 | + </where> | ||
| 228 | + </select> | ||
| 229 | + <select id="validateUserInfo" resultType="com.sunyo.wlpt.message.bus.service.domain.UserInfo"> | ||
| 230 | + select | ||
| 231 | + <include refid="Base_Column_List"/> | ||
| 232 | + from user_info | ||
| 233 | + <where> | ||
| 234 | + username = #{username,jdbcType=VARCHAR} | ||
| 235 | + and server_name = #{serverName,jdbcType=VARCHAR} | ||
| 236 | + and virtual_host_name = #{virtualHostName,jdbcType=VARCHAR} | ||
| 237 | + </where> | ||
| 238 | + </select> | ||
| 239 | + | ||
| 240 | + <select id="selectByBusQueue" parameterType="com.sunyo.wlpt.message.bus.service.domain.BusQueue" | ||
| 241 | + resultMap="BaseResultMap"> | ||
| 242 | + select | ||
| 243 | + <include refid="Base_Column_List"/> | ||
| 244 | + from user_info | ||
| 245 | + <where> | ||
| 246 | + <!-- username必须得存在 --> | ||
| 247 | + username = #{username,jdbcType=VARCHAR} | ||
| 248 | + <if test="virtualHostId != null and virtualHostId != ''"> | ||
| 249 | + and virtual_host_id = #{virtualHostId,jdbcType=VARCHAR} | ||
| 250 | + </if> | ||
| 251 | + </where> | ||
| 252 | + </select> | ||
| 207 | </mapper> | 253 | </mapper> | 
- 
请 注册 或 登录 后发表评论
