作者 xudada

路由管理

1 package com.sunyo.wlpt.message.bus.service.controller; 1 package com.sunyo.wlpt.message.bus.service.controller;
2 2
3 3
  4 +import com.github.pagehelper.PageInfo;
4 import com.sunyo.wlpt.message.bus.service.model.MessageRouter; 5 import com.sunyo.wlpt.message.bus.service.model.MessageRouter;
  6 +import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciver;
  7 +import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter;
5 import com.sunyo.wlpt.message.bus.service.response.ResultJson; 8 import com.sunyo.wlpt.message.bus.service.response.ResultJson;
  9 +import com.sunyo.wlpt.message.bus.service.service.MessageRouterReciverFilterService;
  10 +import com.sunyo.wlpt.message.bus.service.service.MessageRouterReciverService;
  11 +import com.sunyo.wlpt.message.bus.service.service.MessageRouterService;
6 import com.sunyo.wlpt.message.bus.service.service.RouterService; 12 import com.sunyo.wlpt.message.bus.service.service.RouterService;
7 import io.swagger.annotations.ApiOperation; 13 import io.swagger.annotations.ApiOperation;
8 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.web.bind.annotation.*; 15 import org.springframework.web.bind.annotation.*;
  16 +import org.springframework.transaction.annotation.Transactional;
  17 +import org.springframework.web.bind.annotation.*;
10 18
11 import java.util.List; 19 import java.util.List;
  20 +import java.util.UUID;
12 21
13 @RequestMapping("/bus/router") 22 @RequestMapping("/bus/router")
14 @RestController 23 @RestController
@@ -17,6 +26,12 @@ public class RouterController { @@ -17,6 +26,12 @@ public class RouterController {
17 @Autowired 26 @Autowired
18 RouterService routerService; 27 RouterService routerService;
19 28
  29 + @Autowired
  30 + MessageRouterService messageRouterService;
  31 + @Autowired
  32 + MessageRouterReciverService messageRouterReciverService;
  33 + @Autowired
  34 + MessageRouterReciverFilterService messageRouterReciverFilterService;
20 35
21 @ApiOperation(value = "批量添加消息路由", notes = "超级管理修改其他用户密码") 36 @ApiOperation(value = "批量添加消息路由", notes = "超级管理修改其他用户密码")
22 @PostMapping("batchAdd") 37 @PostMapping("batchAdd")
@@ -31,4 +46,51 @@ public class RouterController { @@ -31,4 +46,51 @@ public class RouterController {
31 return new ResultJson<>("200","success",all); 46 return new ResultJson<>("200","success",all);
32 } 47 }
33 48
  49 +
  50 + @PostMapping("/addRouter")
  51 + @Transactional
  52 + public ResultJson addRouter(@RequestBody MessageRouter messageRouter) throws Exception {
  53 + String routerid=UUID.randomUUID().toString();
  54 + String reciverid=UUID.randomUUID().toString();
  55 + messageRouter.setId(routerid);
  56 + int result=messageRouterService.addRouter(messageRouter);
  57 + if(messageRouter.getReciver()!=null){
  58 + MessageRouterReciver routerReciver=new MessageRouterReciver();
  59 + routerReciver.setId(reciverid);
  60 + routerReciver.setMessageRouterId(routerid);
  61 + routerReciver.setRcvrTopic(messageRouter.getReciver().getRcvrTopic());
  62 + messageRouterReciverService.addMessageRouterReciver(routerReciver);
  63 + if(messageRouter.getReciver().getReciverFilter()!=null){
  64 + MessageRouterReciverFilter routerReciverFilter=new MessageRouterReciverFilter();
  65 + routerReciverFilter.setId(UUID.randomUUID().toString());
  66 + routerReciverFilter.setMessageRouterReciverId(reciverid);
  67 + routerReciverFilter.setFilter(messageRouter.getReciver().getReciverFilter().getFilter());
  68 + messageRouterReciverFilterService.addMessageRouterReciverFilter(routerReciverFilter);
  69 + }
  70 + }
  71 + return result>0?new ResultJson("200","路由消息新增成功"):new ResultJson("500","路由消息新增失败");
  72 + }
  73 + @RequestMapping("/delRouter")
  74 + public ResultJson delRouter(@RequestParam(value = "id", required = false) String id)throws Exception{
  75 + int result=messageRouterService.delRouter(id);
  76 + return result>0?new ResultJson("200","路由消息删除成功"):new ResultJson("500","路由消息删除失败");
  77 + }
  78 + @PutMapping("/ediRouter")
  79 + public ResultJson edi(@RequestBody MessageRouter messageRouter)throws Exception {
  80 + int result=messageRouterService.ediRouter(messageRouter);
  81 + return result>0?new ResultJson("200","路由消息修改成功"):new ResultJson("500","路由消息修改失败");
  82 + }
  83 + @RequestMapping("/queRouter")
  84 + public ResultJson<PageInfo> queRouter(@RequestParam(value = "sndr", required = false) String sndr,
  85 + @RequestParam(value = "btype", required = false) String btype,
  86 + @RequestParam(value = "stype", required = false) String stype,
  87 + @RequestParam(value = "currentPage",required = false,defaultValue = "1") int currentPage,
  88 + @RequestParam(value = "pageSize",required = false,defaultValue = "10") int pageSize)throws Exception{
  89 + MessageRouter messageRouter=new MessageRouter();
  90 + messageRouter.setSndr(sndr);
  91 + messageRouter.setBtype(btype);
  92 + messageRouter.setStype(stype);
  93 + PageInfo<MessageRouter> pageInfo=messageRouterService.queRouterList(messageRouter,currentPage,pageSize);
  94 + return new ResultJson<>("200","success",pageInfo);
  95 + }
34 } 96 }
1 package com.sunyo.wlpt.message.bus.service.mapper; 1 package com.sunyo.wlpt.message.bus.service.mapper;
2 2
  3 +import com.github.pagehelper.PageInfo;
3 import com.sunyo.wlpt.message.bus.service.model.MessageRouter; 4 import com.sunyo.wlpt.message.bus.service.model.MessageRouter;
4 5
5 import java.util.List; 6 import java.util.List;
@@ -18,4 +19,6 @@ public interface MessageRouterMapper { @@ -18,4 +19,6 @@ public interface MessageRouterMapper {
18 int updateByPrimaryKeySelective(MessageRouter record); 19 int updateByPrimaryKeySelective(MessageRouter record);
19 20
20 int updateByPrimaryKey(MessageRouter record); 21 int updateByPrimaryKey(MessageRouter record);
  22 +
  23 + List<MessageRouter> queRouterList(MessageRouter messageRouter);
21 } 24 }
@@ -2,6 +2,8 @@ package com.sunyo.wlpt.message.bus.service.mapper; @@ -2,6 +2,8 @@ package com.sunyo.wlpt.message.bus.service.mapper;
2 2
3 import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter; 3 import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter;
4 4
  5 +import java.util.List;
  6 +
5 public interface MessageRouterReciverFilterMapper { 7 public interface MessageRouterReciverFilterMapper {
6 int deleteByPrimaryKey(String id); 8 int deleteByPrimaryKey(String id);
7 9
@@ -11,6 +13,8 @@ public interface MessageRouterReciverFilterMapper { @@ -11,6 +13,8 @@ public interface MessageRouterReciverFilterMapper {
11 13
12 MessageRouterReciverFilter selectByPrimaryKey(String id); 14 MessageRouterReciverFilter selectByPrimaryKey(String id);
13 15
  16 + List<MessageRouterReciverFilter> selectByFilterKey(String id);
  17 +
14 int updateByPrimaryKeySelective(MessageRouterReciverFilter record); 18 int updateByPrimaryKeySelective(MessageRouterReciverFilter record);
15 19
16 int updateByPrimaryKey(MessageRouterReciverFilter record); 20 int updateByPrimaryKey(MessageRouterReciverFilter record);
1 package com.sunyo.wlpt.message.bus.service.model; 1 package com.sunyo.wlpt.message.bus.service.model;
2 2
  3 +import lombok.Data;
  4 +
3 import java.util.Date; 5 import java.util.Date;
4 import java.util.List; 6 import java.util.List;
5 - 7 +@Data
6 public class MessageRouter { 8 public class MessageRouter {
7 private String id; 9 private String id;
8 10
@@ -32,6 +34,8 @@ public class MessageRouter { @@ -32,6 +34,8 @@ public class MessageRouter {
32 34
33 private List<MessageRouterReciver> rcvrList; 35 private List<MessageRouterReciver> rcvrList;
34 36
  37 + private MessageRouterReciver reciver;
  38 +
35 private List<String> sndrs; 39 private List<String> sndrs;
36 40
37 private List<MessageType> types; 41 private List<MessageType> types;
1 package com.sunyo.wlpt.message.bus.service.model; 1 package com.sunyo.wlpt.message.bus.service.model;
2 2
  3 +import lombok.Data;
  4 +
3 import java.util.Date; 5 import java.util.Date;
  6 +import java.util.List;
4 7
  8 +@Data
5 public class MessageRouterReciver { 9 public class MessageRouterReciver {
6 private String id; 10 private String id;
7 11
@@ -12,6 +16,8 @@ public class MessageRouterReciver { @@ -12,6 +16,8 @@ public class MessageRouterReciver {
12 private Date creatTime; 16 private Date creatTime;
13 17
14 private Date updateTime; 18 private Date updateTime;
  19 + private MessageRouterReciverFilter reciverFilter;
  20 + private List<MessageRouterReciverFilter> filterList;
15 21
16 public String getId() { 22 public String getId() {
17 return id; 23 return id;
1 package com.sunyo.wlpt.message.bus.service.model; 1 package com.sunyo.wlpt.message.bus.service.model;
2 2
3 -import java.util.Date; 3 +import lombok.Data;
4 4
  5 +import java.util.Date;
  6 +@Data
5 public class MessageRouterReciverFilter { 7 public class MessageRouterReciverFilter {
6 private String id; 8 private String id;
7 9
  1 +package com.sunyo.wlpt.message.bus.service.service;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter;
  4 +
  5 +public interface MessageRouterReciverFilterService {
  6 + int addMessageRouterReciverFilter(MessageRouterReciverFilter messageRouterReciverFilter);
  7 +}
  1 +package com.sunyo.wlpt.message.bus.service.service;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciver;
  4 +
  5 +public interface MessageRouterReciverService {
  6 + int addMessageRouterReciver(MessageRouterReciver messageRouterReciver)throws Exception;
  7 +}
  1 +package com.sunyo.wlpt.message.bus.service.service;
  2 +
  3 +import com.github.pagehelper.PageInfo;
  4 +import com.sunyo.wlpt.message.bus.service.model.MessageRouter;
  5 +
  6 +public interface MessageRouterService {
  7 + int addRouter(MessageRouter messageRouter)throws Exception;
  8 + int delRouter(String id)throws Exception;
  9 + int ediRouter(MessageRouter messageRouter)throws Exception;
  10 + PageInfo<MessageRouter> queRouterList(MessageRouter messageRouter,int pageNum,int pageSize)throws Exception;
  11 +}
  1 +package com.sunyo.wlpt.message.bus.service.service.impl;
  2 +
  3 +import com.github.pagehelper.PageHelper;
  4 +import com.github.pagehelper.PageInfo;
  5 +import com.sunyo.wlpt.message.bus.service.mapper.MessageRouterMapper;
  6 +import com.sunyo.wlpt.message.bus.service.model.MessageRouter;
  7 +import com.sunyo.wlpt.message.bus.service.service.MessageRouterService;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +import java.util.List;
  12 +import java.util.UUID;
  13 +
  14 +@Service
  15 +public class MessageRouterImpl implements MessageRouterService {
  16 + @Autowired
  17 + MessageRouterMapper messageRouterMapper;
  18 + @Override
  19 + public int addRouter(MessageRouter messageRouter) throws Exception {
  20 + return messageRouterMapper.insertSelective(messageRouter);
  21 + }
  22 +
  23 + @Override
  24 + public int delRouter(String id) throws Exception {
  25 + return messageRouterMapper.deleteByPrimaryKey(id);
  26 + }
  27 +
  28 + @Override
  29 + public int ediRouter(MessageRouter messageRouter) throws Exception {
  30 + return messageRouterMapper.updateByPrimaryKeySelective(messageRouter);
  31 + }
  32 +
  33 + @Override
  34 + public PageInfo<MessageRouter> queRouterList(MessageRouter messageRouter,int pageNum,int pageSize) throws Exception {
  35 + PageHelper.startPage(pageNum,pageSize);
  36 + List<MessageRouter> list=messageRouterMapper.queRouterList(messageRouter);
  37 + PageInfo<MessageRouter> result=new PageInfo<>(list);
  38 + return result;
  39 + }
  40 +}
  1 +package com.sunyo.wlpt.message.bus.service.service.impl;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.mapper.MessageRouterReciverFilterMapper;
  4 +import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter;
  5 +import com.sunyo.wlpt.message.bus.service.service.MessageRouterReciverFilterService;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +@Service
  10 +public class MessageRouterReciverFilterImpl implements MessageRouterReciverFilterService {
  11 + @Autowired
  12 + MessageRouterReciverFilterMapper messageRouterReciverFilterMapper;
  13 +
  14 + @Override
  15 + public int addMessageRouterReciverFilter(MessageRouterReciverFilter messageRouterReciverFilter) {
  16 + return messageRouterReciverFilterMapper.insertSelective(messageRouterReciverFilter);
  17 + }
  18 +}
  1 +package com.sunyo.wlpt.message.bus.service.service.impl;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.mapper.MessageRouterReciverMapper;
  4 +import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciver;
  5 +import com.sunyo.wlpt.message.bus.service.service.MessageRouterReciverService;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +@Service
  10 +public class MessageRouterReciverImpl implements MessageRouterReciverService {
  11 + @Autowired
  12 + MessageRouterReciverMapper messageRouterReciverMapper;
  13 + @Override
  14 + public int addMessageRouterReciver(MessageRouterReciver messageRouterReciver) throws Exception {
  15 + return messageRouterReciverMapper.insertSelective(messageRouterReciver);
  16 + }
  17 +}
@@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
15 <result column="ver" property="ver" jdbcType="VARCHAR" /> 15 <result column="ver" property="ver" jdbcType="VARCHAR" />
16 <result column="creat_time" property="creatTime" jdbcType="TIMESTAMP" /> 16 <result column="creat_time" property="creatTime" jdbcType="TIMESTAMP" />
17 <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" /> 17 <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  18 + <collection column="id" javaType="java.util.ArrayList" ofType="com.sunyo.wlpt.message.bus.service.model.MessageRouterReciver" property="rcvrList" select="com.sunyo.wlpt.message.bus.service.mapper.MessageRouterReciverMapper.selectByRouterKey" />
18 </resultMap> 19 </resultMap>
19 <sql id="Base_Column_List" > 20 <sql id="Base_Column_List" >
20 id, sndr, btype, stype, optype, msg_limit, `character`, status, `usage`, des, ver, creat_time, 21 id, sndr, btype, stype, optype, msg_limit, `character`, status, `usage`, des, ver, creat_time,
@@ -26,6 +27,20 @@ @@ -26,6 +27,20 @@
26 from message_router 27 from message_router
27 where id = #{id,jdbcType=VARCHAR} 28 where id = #{id,jdbcType=VARCHAR}
28 </select> 29 </select>
  30 + <select id="queRouterList" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageRouter" resultMap="BaseResultMap">
  31 + select
  32 + <include refid="Base_Column_List" />
  33 + from message_router where 1=1
  34 + <if test="sndr != null" >
  35 + and sndr = #{sndr,jdbcType=VARCHAR}
  36 + </if>
  37 + <if test="btype != null" >
  38 + and btype = #{btype,jdbcType=VARCHAR}
  39 + </if>
  40 + <if test="stype != null" >
  41 + and stype = #{stype,jdbcType=VARCHAR}
  42 + </if>
  43 + </select>
29 44
30 <select id="selectBySndr" resultMap="BaseResultMap" parameterType="java.lang.String" > 45 <select id="selectBySndr" resultMap="BaseResultMap" parameterType="java.lang.String" >
31 select 46 select
@@ -36,7 +51,7 @@ @@ -36,7 +51,7 @@
36 51
37 <delete id="deleteByPrimaryKey" parameterType="java.lang.String" > 52 <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
38 delete from message_router 53 delete from message_router
39 - where id = #{sndr,jdbcType=VARCHAR} 54 + where id = #{id,jdbcType=VARCHAR}
40 </delete> 55 </delete>
41 <insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageRouter" > 56 <insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageRouter" >
42 insert into message_router (id, sndr, btype, 57 insert into message_router (id, sndr, btype,
@@ -20,6 +20,12 @@ @@ -20,6 +20,12 @@
20 from message_router_reciver_filter 20 from message_router_reciver_filter
21 where id = #{id,jdbcType=VARCHAR} 21 where id = #{id,jdbcType=VARCHAR}
22 </select> 22 </select>
  23 + <select id="selectByFilterKey" parameterType="java.lang.String" resultMap="BaseResultMap">
  24 + select
  25 + <include refid="Base_Column_List" />
  26 + from message_router_reciver_filter
  27 + where message_router_reciver_id = #{messageRouterReciverId,jdbcType=VARCHAR}
  28 + </select>
23 <delete id="deleteByPrimaryKey" parameterType="java.lang.String"> 29 <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
24 delete from message_router_reciver_filter 30 delete from message_router_reciver_filter
25 where id = #{id,jdbcType=VARCHAR} 31 where id = #{id,jdbcType=VARCHAR}
@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 <result column="message_router_id" property="messageRouterId" jdbcType="VARCHAR" /> 7 <result column="message_router_id" property="messageRouterId" jdbcType="VARCHAR" />
8 <result column="creat_time" property="creatTime" jdbcType="TIMESTAMP" /> 8 <result column="creat_time" property="creatTime" jdbcType="TIMESTAMP" />
9 <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" /> 9 <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  10 + <collection column="id" javaType="java.util.ArrayList" ofType="com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter" property="filterList" select="com.sunyo.wlpt.message.bus.service.mapper.MessageRouterReciverFilterMapper.selectByFilterKey" />
10 </resultMap> 11 </resultMap>
11 <sql id="Base_Column_List" > 12 <sql id="Base_Column_List" >
12 id, rcvr_topic, message_router_id, creat_time, update_time 13 id, rcvr_topic, message_router_id, creat_time, update_time
@@ -23,6 +24,12 @@ @@ -23,6 +24,12 @@
23 from message_router_reciver 24 from message_router_reciver
24 where message_router_id = #{messageRouterId,jdbcType=VARCHAR} 25 where message_router_id = #{messageRouterId,jdbcType=VARCHAR}
25 </select> 26 </select>
  27 + <select id="queReciverList" resultMap="BaseResultMap" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageRouterReciver" >
  28 + select
  29 + <include refid="Base_Column_List" />
  30 + from message_router_reciver
  31 + where id = #{id,jdbcType=VARCHAR}
  32 + </select>
26 <delete id="deleteByPrimaryKey" parameterType="java.lang.String" > 33 <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
27 delete from message_router_reciver 34 delete from message_router_reciver
28 where id = #{id,jdbcType=VARCHAR} 35 where id = #{id,jdbcType=VARCHAR}