|  | @@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.*; |  | @@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.*; | 
| 10 | import javax.annotation.Resource; | 10 | import javax.annotation.Resource; | 
| 11 | import java.util.List; | 11 | import java.util.List; | 
| 12 |  | 12 |  | 
|  |  | 13 | +import static com.sunyo.wlpt.message.bus.service.common.Constant.EXIST_ROUTINGKEY_INFO; | 
|  |  | 14 | + | 
| 13 | /** | 15 | /** | 
| 14 | * @author 子诚 | 16 | * @author 子诚 | 
| 15 | * Description:关于路由键的控制器 | 17 | * Description:关于路由键的控制器 | 
|  | @@ -34,28 +36,16 @@ public class RoutingKeyController { |  | @@ -34,28 +36,16 @@ public class RoutingKeyController { | 
| 34 | */ | 36 | */ | 
| 35 | @GetMapping("/list") | 37 | @GetMapping("/list") | 
| 36 | public ResultJson<PageInfo> selectRoutingKeyList( | 38 | public ResultJson<PageInfo> selectRoutingKeyList( | 
| 37 | -            @RequestParam(value = "exchangeId", required = false) String exchangeId, |  |  | 
| 38 | @RequestParam(value = "routingKeyName", required = false) String routingKeyName, | 39 | @RequestParam(value = "routingKeyName", required = false) String routingKeyName, | 
|  |  | 40 | +            @RequestParam(value = "exchangeId", required = false) String exchangeId, | 
| 39 | @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, | 41 | @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, | 
| 40 | @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { | 42 | @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { | 
| 41 | -        ResultJson<PageInfo> result = new ResultJson<>(); |  |  | 
| 42 |  | 43 |  | 
| 43 | -        RoutingKey routingKey = new RoutingKey(); |  |  | 
| 44 | -        // 获取参数,虚拟机id |  |  | 
| 45 | -        routingKey.setExchangeId(exchangeId); |  |  | 
| 46 | -        // 获取参数,路由键名称 |  |  | 
| 47 | -        routingKey.setRoutingKeyName(routingKeyName); |  |  | 
| 48 | // 分页查询 | 44 | // 分页查询 | 
| 49 | -        PageInfo pageInfo = routingKeyService.selectRoutingKeyList(routingKey, pageNum, pageSize); |  |  | 
| 50 | -        if (pageInfo.getTotal() > 0) { |  |  | 
| 51 | -            result.setCode("200"); |  |  | 
| 52 | -            result.setData(pageInfo); |  |  | 
| 53 | -            result.setMsg("查询路由键列表,成功!"); |  |  | 
| 54 | -        } else { |  |  | 
| 55 | -            result.setCode("500"); |  |  | 
| 56 | -            result.setMsg("查询路由键列表,失败!"); |  |  | 
| 57 | -        } |  |  | 
| 58 | -        return result; | 45 | +        PageInfo pageInfo = routingKeyService.selectRoutingKeyList(new RoutingKey(routingKeyName, exchangeId), pageNum, pageSize); | 
|  |  | 46 | +        return pageInfo.getTotal() > 0 | 
|  |  | 47 | +                ? new ResultJson<>("200", "查询路由键列表,成功!", pageInfo) | 
|  |  | 48 | +                : new ResultJson<>("500", "查询路由键列表,失败!"); | 
| 59 | } | 49 | } | 
| 60 |  | 50 |  | 
| 61 | /** | 51 | /** | 
|  | @@ -66,16 +56,10 @@ public class RoutingKeyController { |  | @@ -66,16 +56,10 @@ public class RoutingKeyController { | 
| 66 | */ | 56 | */ | 
| 67 | @DeleteMapping("/delete") | 57 | @DeleteMapping("/delete") | 
| 68 | public ResultJson deleteRoutingKey(@RequestBody RoutingKey routingKey) { | 58 | public ResultJson deleteRoutingKey(@RequestBody RoutingKey routingKey) { | 
| 69 | -        ResultJson result = new ResultJson<>(); |  |  | 
| 70 | -        int num = routingKeyService.deleteByPrimaryKey(routingKey.getId()); |  |  | 
| 71 | -        if (num > 0) { |  |  | 
| 72 | -            result.setCode("200"); |  |  | 
| 73 | -            result.setMsg("删除路由键,成功"); |  |  | 
| 74 | -        } else { |  |  | 
| 75 | -            result.setCode("500"); |  |  | 
| 76 | -            result.setMsg("删除路由键,失败"); |  |  | 
| 77 | -        } |  |  | 
| 78 | -        return result; | 59 | + | 
|  |  | 60 | +        return routingKeyService.deleteByPrimaryKey(routingKey.getId()) > 0 | 
|  |  | 61 | +                ? new ResultJson<>("200", "删除路由键,成功") | 
|  |  | 62 | +                : new ResultJson<>("500", "删除路由键,失败"); | 
| 79 | } | 63 | } | 
| 80 |  | 64 |  | 
| 81 | /** | 65 | /** | 
|  | @@ -86,70 +70,49 @@ public class RoutingKeyController { |  | @@ -86,70 +70,49 @@ public class RoutingKeyController { | 
| 86 | */ | 70 | */ | 
| 87 | @GetMapping("/batchRemove") | 71 | @GetMapping("/batchRemove") | 
| 88 | public ResultJson batchRemoveRoutingKey(String ids) { | 72 | public ResultJson batchRemoveRoutingKey(String ids) { | 
| 89 | -        ResultJson result = new ResultJson<>(); |  |  | 
| 90 | -        int num = routingKeyService.deleteByPrimaryKey(ids); |  |  | 
| 91 | -        if (num > 0) { |  |  | 
| 92 | -            result.setCode("200"); |  |  | 
| 93 | -            result.setMsg("批量删除路由键,成功!"); |  |  | 
| 94 | -        } else { |  |  | 
| 95 | -            result.setCode("500"); |  |  | 
| 96 | -            result.setMsg("批量删除路由键,失败!"); |  |  | 
| 97 | -        } |  |  | 
| 98 | -        return result; | 73 | + | 
|  |  | 74 | +        return routingKeyService.deleteByPrimaryKey(ids) > 0 | 
|  |  | 75 | +                ? new ResultJson<>("200", "删除路由键,成功") | 
|  |  | 76 | +                : new ResultJson<>("500", "删除路由键,失败"); | 
| 99 | } | 77 | } | 
| 100 |  | 78 |  | 
| 101 | /** | 79 | /** | 
| 102 | -     * 修改路由键信息 | 80 | +     * 编辑路由键信息 | 
| 103 | * | 81 | * | 
| 104 | * @param routingKey {@link RoutingKey} | 82 | * @param routingKey {@link RoutingKey} | 
| 105 | * @return {@link ResultJson} | 83 | * @return {@link ResultJson} | 
| 106 | */ | 84 | */ | 
| 107 | @PutMapping("/update") | 85 | @PutMapping("/update") | 
| 108 | public ResultJson updateRoutingKey(@RequestBody RoutingKey routingKey) { | 86 | public ResultJson updateRoutingKey(@RequestBody RoutingKey routingKey) { | 
|  |  | 87 | + | 
| 109 | //先验证,修改好的核心信息(路由键名称)是否已存在 | 88 | //先验证,修改好的核心信息(路由键名称)是否已存在 | 
| 110 | String message = validateRoutingKey(routingKey); | 89 | String message = validateRoutingKey(routingKey); | 
| 111 | -        //验证通过 |  |  | 
| 112 | -        if (message == null) { |  |  | 
| 113 | -            ResultJson result = new ResultJson<>(); |  |  | 
| 114 | -            int num = routingKeyService.updateByPrimaryKeySelective(routingKey); |  |  | 
| 115 | -            if (num > 0) { |  |  | 
| 116 | -                result.setCode("200"); |  |  | 
| 117 | -                result.setMsg("修改路由键信息,成功"); |  |  | 
| 118 | -            } else { |  |  | 
| 119 | -                result.setCode("500"); |  |  | 
| 120 | -                result.setMsg("修改路由键信息,失败"); |  |  | 
| 121 | -            } |  |  | 
| 122 | -            return result; |  |  | 
| 123 | -        } |  |  | 
| 124 | -        return new ResultJson("400", message != null ? message : "修改路由键信息,失败!"); | 90 | +        return message == null | 
|  |  | 91 | +                ? routingKeyService.updateByPrimaryKeySelective(routingKey) > 0 | 
|  |  | 92 | +                    ? new ResultJson<>("200", "编辑路由键信息,成功") | 
|  |  | 93 | +                    : new ResultJson<>("500", "编辑路由键信息,失败") | 
|  |  | 94 | +                : new ResultJson<>("400", message); | 
| 125 | } | 95 | } | 
| 126 |  | 96 |  | 
| 127 | /** | 97 | /** | 
| 128 | -     * 新增路由键 | 98 | +     * 增加路由键信息 | 
| 129 | * | 99 | * | 
| 130 | * @param routingKey {@link RoutingKey} | 100 | * @param routingKey {@link RoutingKey} | 
| 131 | * @return {@link ResultJson} | 101 | * @return {@link ResultJson} | 
| 132 | */ | 102 | */ | 
| 133 | @PostMapping("/insert") | 103 | @PostMapping("/insert") | 
| 134 | public ResultJson insertRoutingKey(@RequestBody RoutingKey routingKey) { | 104 | public ResultJson insertRoutingKey(@RequestBody RoutingKey routingKey) { | 
|  |  | 105 | + | 
| 135 | //先验证,增加的服务器的核心信息(ip和port,同时存在)是否已存在 | 106 | //先验证,增加的服务器的核心信息(ip和port,同时存在)是否已存在 | 
| 136 | String message = validateRoutingKey(routingKey); | 107 | String message = validateRoutingKey(routingKey); | 
| 137 | -        //验证通过 |  |  | 
| 138 | -        if (message == null) { |  |  | 
| 139 | -            ResultJson result = new ResultJson<>(); |  |  | 
| 140 | -            // 设置id |  |  | 
| 141 | -            routingKey.setId(IdUtils.generateId()); |  |  | 
| 142 | -            int num = routingKeyService.insertSelective(routingKey); |  |  | 
| 143 | -            if (num > 0) { |  |  | 
| 144 | -                result.setCode("200"); |  |  | 
| 145 | -                result.setMsg("添加路由键信息,成功!"); |  |  | 
| 146 | -            } else { |  |  | 
| 147 | -                result.setCode("500"); |  |  | 
| 148 | -                result.setMsg("添加路由键信息,失败!"); |  |  | 
| 149 | -            } |  |  | 
| 150 | -            return result; |  |  | 
| 151 | -        } |  |  | 
| 152 | -        return new ResultJson("400", message != null ? message : "添加路由键信息,失败!"); | 108 | +        // 设置id | 
|  |  | 109 | +        routingKey.setId(IdUtils.generateId()); | 
|  |  | 110 | + | 
|  |  | 111 | +        return message == null | 
|  |  | 112 | +                ? routingKeyService.insertSelective(routingKey) > 0 | 
|  |  | 113 | +                    ? new ResultJson<>("200", "增加路由键信息,成功") | 
|  |  | 114 | +                    : new ResultJson<>("500", "增加路由键信息,失败") | 
|  |  | 115 | +                : new ResultJson<>("400", message); | 
| 153 | } | 116 | } | 
| 154 |  | 117 |  | 
| 155 | /** | 118 | /** | 
|  | @@ -174,7 +137,7 @@ public class RoutingKeyController { |  | @@ -174,7 +137,7 @@ public class RoutingKeyController { | 
| 174 | List<RoutingKey> info = routingKeyService.validateRoutingKey(routingKey); | 137 | List<RoutingKey> info = routingKeyService.validateRoutingKey(routingKey); | 
| 175 | // 多于0个,则代表已存在;否则则是,校验通过 | 138 | // 多于0个,则代表已存在;否则则是,校验通过 | 
| 176 | if (info.size() > 0) { | 139 | if (info.size() > 0) { | 
| 177 | -                    return "该-路由键(路由键名称)-信息已存在,请谨慎输入"; | 140 | +                    return EXIST_ROUTINGKEY_INFO; | 
| 178 | } | 141 | } | 
| 179 | return null; | 142 | return null; | 
| 180 | } | 143 | } | 
|  | @@ -187,7 +150,7 @@ public class RoutingKeyController { |  | @@ -187,7 +150,7 @@ public class RoutingKeyController { | 
| 187 | List<RoutingKey> info = routingKeyService.validateRoutingKey(routingKey); | 150 | List<RoutingKey> info = routingKeyService.validateRoutingKey(routingKey); | 
| 188 | // 多于0个,则代表已存在;否则则是,校验通过 | 151 | // 多于0个,则代表已存在;否则则是,校验通过 | 
| 189 | if (info.size() > 0) { | 152 | if (info.size() > 0) { | 
| 190 | -                return "该-路由键(路由键名称)-信息已存在,请谨慎输入"; | 153 | +                return EXIST_ROUTINGKEY_INFO; | 
| 191 | } | 154 | } | 
| 192 | return null; | 155 | return null; | 
| 193 | } | 156 | } |