正在显示
3 个修改的文件
包含
29 行增加
和
15 行删除
| @@ -2,12 +2,10 @@ package com.sunyo.wlpt.message.bus.service.controller; | @@ -2,12 +2,10 @@ package com.sunyo.wlpt.message.bus.service.controller; | ||
| 2 | 2 | ||
| 3 | import com.github.pagehelper.PageInfo; | 3 | import com.github.pagehelper.PageInfo; |
| 4 | import com.sunyo.wlpt.message.bus.service.domain.BusQueue; | 4 | import com.sunyo.wlpt.message.bus.service.domain.BusQueue; |
| 5 | -import com.sunyo.wlpt.message.bus.service.domain.UserInfo; | ||
| 6 | import com.sunyo.wlpt.message.bus.service.response.ResultJson; | 5 | import com.sunyo.wlpt.message.bus.service.response.ResultJson; |
| 7 | import com.sunyo.wlpt.message.bus.service.service.BusQueueService; | 6 | import com.sunyo.wlpt.message.bus.service.service.BusQueueService; |
| 8 | import com.sunyo.wlpt.message.bus.service.service.UserInfoService; | 7 | import com.sunyo.wlpt.message.bus.service.service.UserInfoService; |
| 9 | import com.sunyo.wlpt.message.bus.service.utils.IdUtils; | 8 | import com.sunyo.wlpt.message.bus.service.utils.IdUtils; |
| 10 | -import io.netty.util.internal.StringUtil; | ||
| 11 | import org.springframework.web.bind.annotation.*; | 9 | import org.springframework.web.bind.annotation.*; |
| 12 | 10 | ||
| 13 | import javax.annotation.Resource; | 11 | import javax.annotation.Resource; |
| @@ -29,6 +27,7 @@ public class BusQueueController { | @@ -29,6 +27,7 @@ public class BusQueueController { | ||
| 29 | 27 | ||
| 30 | @Resource | 28 | @Resource |
| 31 | private UserInfoService userInfoService; | 29 | private UserInfoService userInfoService; |
| 30 | + | ||
| 32 | @Resource | 31 | @Resource |
| 33 | private BusQueueService busQueueService; | 32 | private BusQueueService busQueueService; |
| 34 | 33 | ||
| @@ -117,31 +116,28 @@ public class BusQueueController { | @@ -117,31 +116,28 @@ public class BusQueueController { | ||
| 117 | @PostMapping("/insert") | 116 | @PostMapping("/insert") |
| 118 | public ResultJson insertBusQueue(@RequestBody BusQueue busQueue) throws IOException, TimeoutException | 117 | public ResultJson insertBusQueue(@RequestBody BusQueue busQueue) throws IOException, TimeoutException |
| 119 | { | 118 | { |
| 120 | - //先验证,增加的虚拟主机的核心信息(交换机名称)是否已存在 | ||
| 121 | String message = validateBusQueue(busQueue); | 119 | String message = validateBusQueue(busQueue); |
| 122 | // 设置id | 120 | // 设置id |
| 123 | busQueue.setId(IdUtils.generateId()); | 121 | busQueue.setId(IdUtils.generateId()); |
| 124 | //验证通过 | 122 | //验证通过 |
| 125 | return message == null | 123 | return message == null |
| 126 | - ? busQueueService.insertSelective(busQueue) > 0 | ||
| 127 | - ? new ResultJson<>("200", "添加消息队列,成功") | ||
| 128 | - : new ResultJson<>("500", "添加消息队列,失败") | 124 | + ? busQueueService.insertSelective(busQueue) |
| 129 | : new ResultJson<>("400", message); | 125 | : new ResultJson<>("400", message); |
| 130 | } | 126 | } |
| 131 | 127 | ||
| 132 | /** | 128 | /** |
| 133 | - * 校验-消息队列,添加和修改之前,是否已存在 | 129 | + * 校验-消息队列的队列名称的唯一性 |
| 134 | * | 130 | * |
| 135 | * @param busQueue {@link BusQueue} | 131 | * @param busQueue {@link BusQueue} |
| 136 | * @return 通过校验,无返回消息 | 132 | * @return 通过校验,无返回消息 |
| 137 | */ | 133 | */ |
| 138 | private String validateBusQueue(BusQueue busQueue) | 134 | private String validateBusQueue(BusQueue busQueue) |
| 139 | { | 135 | { |
| 140 | - if (!StringUtil.isNullOrEmpty(busQueue.getUserId())) { | ||
| 141 | - // 根据用户id,填充用户名称;违背了单一职责原则,有时间再改 | ||
| 142 | - UserInfo userInfo = userInfoService.selectByPrimaryKey(busQueue.getUserId()); | ||
| 143 | - busQueue.setUsername(userInfo.getUsername()); | ||
| 144 | - } | 136 | +// if (!StringUtil.isNullOrEmpty(busQueue.getUserId())) { |
| 137 | +// // 根据用户id,填充用户名称;违背了单一职责原则,有时间再改 | ||
| 138 | +// UserInfo userInfo = userInfoService.selectByPrimaryKey(busQueue.getUserId()); | ||
| 139 | +// busQueue.setUsername(userInfo.getUsername()); | ||
| 140 | +// } | ||
| 145 | 141 | ||
| 146 | // 判断队列名称,是否为空 | 142 | // 判断队列名称,是否为空 |
| 147 | if ("".equals(busQueue.getQueueName()) || busQueue.getQueueName() == null) { | 143 | if ("".equals(busQueue.getQueueName()) || busQueue.getQueueName() == null) { |
| @@ -2,6 +2,7 @@ package com.sunyo.wlpt.message.bus.service.service; | @@ -2,6 +2,7 @@ package com.sunyo.wlpt.message.bus.service.service; | ||
| 2 | 2 | ||
| 3 | import com.github.pagehelper.PageInfo; | 3 | import com.github.pagehelper.PageInfo; |
| 4 | import com.sunyo.wlpt.message.bus.service.domain.BusQueue; | 4 | import com.sunyo.wlpt.message.bus.service.domain.BusQueue; |
| 5 | +import com.sunyo.wlpt.message.bus.service.response.ResultJson; | ||
| 5 | 6 | ||
| 6 | import java.io.IOException; | 7 | import java.io.IOException; |
| 7 | import java.util.List; | 8 | import java.util.List; |
| @@ -44,7 +45,7 @@ public interface BusQueueService { | @@ -44,7 +45,7 @@ public interface BusQueueService { | ||
| 44 | * @param record the record | 45 | * @param record the record |
| 45 | * @return insert count | 46 | * @return insert count |
| 46 | */ | 47 | */ |
| 47 | - int insertSelective(BusQueue record) throws IOException, TimeoutException; | 48 | + ResultJson insertSelective(BusQueue record) throws IOException, TimeoutException; |
| 48 | 49 | ||
| 49 | /** | 50 | /** |
| 50 | * 查询,根据主键 | 51 | * 查询,根据主键 |
| @@ -4,7 +4,9 @@ import com.github.pagehelper.PageHelper; | @@ -4,7 +4,9 @@ import com.github.pagehelper.PageHelper; | ||
| 4 | import com.github.pagehelper.PageInfo; | 4 | import com.github.pagehelper.PageInfo; |
| 5 | import com.sunyo.wlpt.message.bus.service.domain.BusQueue; | 5 | import com.sunyo.wlpt.message.bus.service.domain.BusQueue; |
| 6 | import com.sunyo.wlpt.message.bus.service.mapper.BusQueueMapper; | 6 | import com.sunyo.wlpt.message.bus.service.mapper.BusQueueMapper; |
| 7 | +import com.sunyo.wlpt.message.bus.service.mapper.UserInfoMapper; | ||
| 7 | import com.sunyo.wlpt.message.bus.service.rabbit.utils.RabbitUtils; | 8 | import com.sunyo.wlpt.message.bus.service.rabbit.utils.RabbitUtils; |
| 9 | +import com.sunyo.wlpt.message.bus.service.response.ResultJson; | ||
| 8 | import com.sunyo.wlpt.message.bus.service.service.BusQueueService; | 10 | import com.sunyo.wlpt.message.bus.service.service.BusQueueService; |
| 9 | import io.netty.util.internal.StringUtil; | 11 | import io.netty.util.internal.StringUtil; |
| 10 | import org.springframework.context.annotation.Lazy; | 12 | import org.springframework.context.annotation.Lazy; |
| @@ -32,6 +34,9 @@ public class BusQueueServiceImpl implements BusQueueService { | @@ -32,6 +34,9 @@ public class BusQueueServiceImpl implements BusQueueService { | ||
| 32 | @Resource | 34 | @Resource |
| 33 | private RabbitUtils rabbitUtils; | 35 | private RabbitUtils rabbitUtils; |
| 34 | 36 | ||
| 37 | + @Resource | ||
| 38 | + private UserInfoMapper userInfoMapper; | ||
| 39 | + | ||
| 35 | @Lazy | 40 | @Lazy |
| 36 | @Resource | 41 | @Resource |
| 37 | private AsyncTaskService asyncTaskService; | 42 | private AsyncTaskService asyncTaskService; |
| @@ -95,11 +100,23 @@ public class BusQueueServiceImpl implements BusQueueService { | @@ -95,11 +100,23 @@ public class BusQueueServiceImpl implements BusQueueService { | ||
| 95 | return busQueueMapper.insert(record); | 100 | return busQueueMapper.insert(record); |
| 96 | } | 101 | } |
| 97 | 102 | ||
| 103 | + /** | ||
| 104 | + * 校验用户名称是否存在 | ||
| 105 | + * <p> | ||
| 106 | + * 创建队列于MQ服务器 | ||
| 107 | + * <p> | ||
| 108 | + * 存储创建的队列信息于数据库 | ||
| 109 | + */ | ||
| 98 | @Override | 110 | @Override |
| 99 | - public int insertSelective(BusQueue record) throws IOException, TimeoutException | 111 | + public ResultJson insertSelective(BusQueue record) throws IOException, TimeoutException |
| 100 | { | 112 | { |
| 113 | + if (userInfoMapper.selectUserExist(record.getUsername()).size() == 0) { | ||
| 114 | + return new ResultJson<>("400", "该用户信息,不存在"); | ||
| 115 | + } | ||
| 101 | rabbitUtils.toCreateQueue(record); | 116 | rabbitUtils.toCreateQueue(record); |
| 102 | - return busQueueMapper.insertSelective(record); | 117 | + return busQueueMapper.insertSelective(record) > 0 |
| 118 | + ? new ResultJson<>("200", "添加消息队列,成功") | ||
| 119 | + : new ResultJson<>("500", "添加消息队列,失败"); | ||
| 103 | } | 120 | } |
| 104 | 121 | ||
| 105 | @Override | 122 | @Override |
-
请 注册 或 登录 后发表评论