作者 xudada

添加路由验证,存在提示

@@ -41,6 +41,10 @@ public class MessageTypesController { @@ -41,6 +41,10 @@ public class MessageTypesController {
41 @ApiOperation(value = "添加一个消息类", notes = "类名与消息类型必填") 41 @ApiOperation(value = "添加一个消息类", notes = "类名与消息类型必填")
42 @PostMapping("add") 42 @PostMapping("add")
43 public ResultJson add(@RequestBody MessageType messageType){ 43 public ResultJson add(@RequestBody MessageType messageType){
  44 + int count=messageTypeService.selectCountMessageType(messageType);
  45 + if(count>0){
  46 + return new ResultJson("400","消息类型已存在");
  47 + }
44 boolean result = messageTypeService.add(messageType); 48 boolean result = messageTypeService.add(messageType);
45 return result ? new ResultJson("200","success") : new ResultJson("400","error"); 49 return result ? new ResultJson("200","success") : new ResultJson("400","error");
46 } 50 }
@@ -36,6 +36,19 @@ public class RouterController { @@ -36,6 +36,19 @@ public class RouterController {
36 @ApiOperation(value = "批量添加消息路由", notes = "超级管理修改其他用户密码") 36 @ApiOperation(value = "批量添加消息路由", notes = "超级管理修改其他用户密码")
37 @PostMapping("batchAdd") 37 @PostMapping("batchAdd")
38 public ResultJson batchAddRouter(@RequestBody MessageRouter messageRouter){ 38 public ResultJson batchAddRouter(@RequestBody MessageRouter messageRouter){
  39 + if (messageRouter.getSndrs()!=null && messageRouter.getTypes()!=null && messageRouter.getRcvrs()!=null){
  40 + List<String> senders = messageRouter.getSndrs();
  41 + if (senders!=null && !senders.isEmpty()){
  42 + for (String sndr: senders) {
  43 + MessageRouter record=new MessageRouter();
  44 + record.setSndr(sndr);
  45 + int count=messageRouterService.selectCountRouter(record);
  46 + if(count>0){
  47 + return new ResultJson("400","消息路由已存在!");
  48 + }
  49 + }
  50 + }
  51 + }
39 boolean result = routerService.batchAddRouter(messageRouter); 52 boolean result = routerService.batchAddRouter(messageRouter);
40 return result ? new ResultJson("200","success") :new ResultJson("400","error"); 53 return result ? new ResultJson("200","success") :new ResultJson("400","error");
41 } 54 }
@@ -50,17 +63,21 @@ public class RouterController { @@ -50,17 +63,21 @@ public class RouterController {
50 @PostMapping("/addRouter") 63 @PostMapping("/addRouter")
51 @Transactional 64 @Transactional
52 public ResultJson addRouter(@RequestBody MessageRouter messageRouter) throws Exception { 65 public ResultJson addRouter(@RequestBody MessageRouter messageRouter) throws Exception {
  66 + int count=messageRouterService.selectCountRouter(messageRouter);
  67 + if(count>0){
  68 + return new ResultJson("200","路由消息已存在!");
  69 + }
53 String routerid=UUID.randomUUID().toString(); 70 String routerid=UUID.randomUUID().toString();
54 String reciverid=UUID.randomUUID().toString(); 71 String reciverid=UUID.randomUUID().toString();
55 messageRouter.setId(routerid); 72 messageRouter.setId(routerid);
56 int result=messageRouterService.addRouter(messageRouter); 73 int result=messageRouterService.addRouter(messageRouter);
57 - if(messageRouter.getReciver()!=null){ 74 + if(messageRouter.getReciver().getRcvrTopic()!=null &&messageRouter.getReciver().getRcvrTopic()!=""){
58 MessageRouterReciver routerReciver=new MessageRouterReciver(); 75 MessageRouterReciver routerReciver=new MessageRouterReciver();
59 routerReciver.setId(reciverid); 76 routerReciver.setId(reciverid);
60 routerReciver.setMessageRouterId(routerid); 77 routerReciver.setMessageRouterId(routerid);
61 routerReciver.setRcvrTopic(messageRouter.getReciver().getRcvrTopic()); 78 routerReciver.setRcvrTopic(messageRouter.getReciver().getRcvrTopic());
62 messageRouterReciverService.addMessageRouterReciver(routerReciver); 79 messageRouterReciverService.addMessageRouterReciver(routerReciver);
63 - if(messageRouter.getReciver().getReciverFilter()!=null){ 80 + if(messageRouter.getReciver().getReciverFilter().getFilter()!=null&& messageRouter.getReciver().getReciverFilter().getFilter()!=""){
64 MessageRouterReciverFilter routerReciverFilter=new MessageRouterReciverFilter(); 81 MessageRouterReciverFilter routerReciverFilter=new MessageRouterReciverFilter();
65 routerReciverFilter.setId(UUID.randomUUID().toString()); 82 routerReciverFilter.setId(UUID.randomUUID().toString());
66 routerReciverFilter.setMessageRouterReciverId(reciverid); 83 routerReciverFilter.setMessageRouterReciverId(reciverid);
@@ -2,6 +2,7 @@ package com.sunyo.wlpt.message.bus.service.mapper; @@ -2,6 +2,7 @@ package com.sunyo.wlpt.message.bus.service.mapper;
2 2
3 import com.github.pagehelper.PageInfo; 3 import com.github.pagehelper.PageInfo;
4 import com.sunyo.wlpt.message.bus.service.model.MessageRouter; 4 import com.sunyo.wlpt.message.bus.service.model.MessageRouter;
  5 +import org.apache.ibatis.annotations.Param;
5 6
6 import java.util.List; 7 import java.util.List;
7 8
@@ -20,5 +21,7 @@ public interface MessageRouterMapper { @@ -20,5 +21,7 @@ public interface MessageRouterMapper {
20 21
21 int updateByPrimaryKey(MessageRouter record); 22 int updateByPrimaryKey(MessageRouter record);
22 23
  24 + int selectCountRouter(MessageRouter messageRouter);
  25 +
23 List<MessageRouter> queRouterList(MessageRouter messageRouter); 26 List<MessageRouter> queRouterList(MessageRouter messageRouter);
24 } 27 }
@@ -24,4 +24,6 @@ public interface MessageTypeMapper { @@ -24,4 +24,6 @@ public interface MessageTypeMapper {
24 int updateByPrimaryKeySelective(MessageType record); 24 int updateByPrimaryKeySelective(MessageType record);
25 25
26 int updateByPrimaryKey(MessageType record); 26 int updateByPrimaryKey(MessageType record);
  27 +
  28 + int selectCountMessageType(MessageType record);
27 } 29 }
@@ -7,5 +7,6 @@ public interface MessageRouterService { @@ -7,5 +7,6 @@ public interface MessageRouterService {
7 int addRouter(MessageRouter messageRouter)throws Exception; 7 int addRouter(MessageRouter messageRouter)throws Exception;
8 int delRouter(String id)throws Exception; 8 int delRouter(String id)throws Exception;
9 int ediRouter(MessageRouter messageRouter)throws Exception; 9 int ediRouter(MessageRouter messageRouter)throws Exception;
  10 + int selectCountRouter(MessageRouter messageRouter);
10 PageInfo<MessageRouter> queRouterList(MessageRouter messageRouter,int pageNum,int pageSize)throws Exception; 11 PageInfo<MessageRouter> queRouterList(MessageRouter messageRouter,int pageNum,int pageSize)throws Exception;
11 } 12 }
@@ -20,4 +20,6 @@ public interface MessageTypeService { @@ -20,4 +20,6 @@ public interface MessageTypeService {
20 20
21 boolean batchDel(String[] ids); 21 boolean batchDel(String[] ids);
22 22
  23 + int selectCountMessageType(MessageType messageType);
  24 +
23 } 25 }
@@ -31,6 +31,11 @@ public class MessageRouterImpl implements MessageRouterService { @@ -31,6 +31,11 @@ public class MessageRouterImpl implements MessageRouterService {
31 } 31 }
32 32
33 @Override 33 @Override
  34 + public int selectCountRouter(MessageRouter messageRouter) {
  35 + return messageRouterMapper.selectCountRouter(messageRouter);
  36 + }
  37 +
  38 + @Override
34 public PageInfo<MessageRouter> queRouterList(MessageRouter messageRouter,int pageNum,int pageSize) throws Exception { 39 public PageInfo<MessageRouter> queRouterList(MessageRouter messageRouter,int pageNum,int pageSize) throws Exception {
35 PageHelper.startPage(pageNum,pageSize); 40 PageHelper.startPage(pageNum,pageSize);
36 List<MessageRouter> list=messageRouterMapper.queRouterList(messageRouter); 41 List<MessageRouter> list=messageRouterMapper.queRouterList(messageRouter);
@@ -58,4 +58,9 @@ public class MessageTypeServiceImp implements MessageTypeService { @@ -58,4 +58,9 @@ public class MessageTypeServiceImp implements MessageTypeService {
58 return i > 0; 58 return i > 0;
59 } 59 }
60 60
  61 + @Override
  62 + public int selectCountMessageType(MessageType messageType) {
  63 + return messageTypeMapper.selectCountMessageType(messageType);
  64 + }
  65 +
61 } 66 }
@@ -24,6 +24,19 @@ @@ -24,6 +24,19 @@
24 id, sndr, btype, stype, optype, msg_limit, `character`, status, `usage`, des, ver, creat_time, 24 id, sndr, btype, stype, optype, msg_limit, `character`, status, `usage`, des, ver, creat_time,
25 update_time 25 update_time
26 </sql> 26 </sql>
  27 + <select id="selectCountRouter" resultType="java.lang.Integer">
  28 + select count(*) from message_router
  29 + where 1=1
  30 + <if test="sndr != null" >
  31 + and sndr = #{sndr,jdbcType=VARCHAR}
  32 + </if>
  33 + <if test="btype != null" >
  34 + and btype = #{btype,jdbcType=VARCHAR}
  35 + </if>
  36 + <if test="stype != null" >
  37 + and stype = #{stype,jdbcType=VARCHAR}
  38 + </if>
  39 + </select>
27 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" > 40 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
28 select 41 select
29 <include refid="Base_Column_List" /> 42 <include refid="Base_Column_List" />
@@ -18,6 +18,12 @@ @@ -18,6 +18,12 @@
18 from message_type 18 from message_type
19 where ID = #{id,jdbcType=VARCHAR} 19 where ID = #{id,jdbcType=VARCHAR}
20 </select> 20 </select>
  21 + <select id="selectCountMessageType" resultType="java.lang.Integer">
  22 + select count(*) from message_type where 1=1
  23 + <if test="name != null and name != ''">
  24 + and name = #{name,jdbcType=VARCHAR}
  25 + </if>
  26 + </select>
21 <select id="selectByParentId" resultMap="BaseResultMap" parameterType="java.lang.String" > 27 <select id="selectByParentId" resultMap="BaseResultMap" parameterType="java.lang.String" >
22 select 28 select
23 <include refid="Base_Column_List" /> 29 <include refid="Base_Column_List" />