作者 xudada

路由管理

package com.sunyo.wlpt.message.bus.service.controller;
import com.github.pagehelper.PageInfo;
import com.sunyo.wlpt.message.bus.service.model.MessageRouter;
import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciver;
import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter;
import com.sunyo.wlpt.message.bus.service.response.ResultJson;
import com.sunyo.wlpt.message.bus.service.service.MessageRouterReciverFilterService;
import com.sunyo.wlpt.message.bus.service.service.MessageRouterReciverService;
import com.sunyo.wlpt.message.bus.service.service.MessageRouterService;
import com.sunyo.wlpt.message.bus.service.service.RouterService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.UUID;
@RequestMapping("/bus/router")
@RestController
... ... @@ -17,6 +26,12 @@ public class RouterController {
@Autowired
RouterService routerService;
@Autowired
MessageRouterService messageRouterService;
@Autowired
MessageRouterReciverService messageRouterReciverService;
@Autowired
MessageRouterReciverFilterService messageRouterReciverFilterService;
@ApiOperation(value = "批量添加消息路由", notes = "超级管理修改其他用户密码")
@PostMapping("batchAdd")
... ... @@ -31,4 +46,51 @@ public class RouterController {
return new ResultJson<>("200","success",all);
}
@PostMapping("/addRouter")
@Transactional
public ResultJson addRouter(@RequestBody MessageRouter messageRouter) throws Exception {
String routerid=UUID.randomUUID().toString();
String reciverid=UUID.randomUUID().toString();
messageRouter.setId(routerid);
int result=messageRouterService.addRouter(messageRouter);
if(messageRouter.getReciver()!=null){
MessageRouterReciver routerReciver=new MessageRouterReciver();
routerReciver.setId(reciverid);
routerReciver.setMessageRouterId(routerid);
routerReciver.setRcvrTopic(messageRouter.getReciver().getRcvrTopic());
messageRouterReciverService.addMessageRouterReciver(routerReciver);
if(messageRouter.getReciver().getReciverFilter()!=null){
MessageRouterReciverFilter routerReciverFilter=new MessageRouterReciverFilter();
routerReciverFilter.setId(UUID.randomUUID().toString());
routerReciverFilter.setMessageRouterReciverId(reciverid);
routerReciverFilter.setFilter(messageRouter.getReciver().getReciverFilter().getFilter());
messageRouterReciverFilterService.addMessageRouterReciverFilter(routerReciverFilter);
}
}
return result>0?new ResultJson("200","路由消息新增成功"):new ResultJson("500","路由消息新增失败");
}
@RequestMapping("/delRouter")
public ResultJson delRouter(@RequestParam(value = "id", required = false) String id)throws Exception{
int result=messageRouterService.delRouter(id);
return result>0?new ResultJson("200","路由消息删除成功"):new ResultJson("500","路由消息删除失败");
}
@PutMapping("/ediRouter")
public ResultJson edi(@RequestBody MessageRouter messageRouter)throws Exception {
int result=messageRouterService.ediRouter(messageRouter);
return result>0?new ResultJson("200","路由消息修改成功"):new ResultJson("500","路由消息修改失败");
}
@RequestMapping("/queRouter")
public ResultJson<PageInfo> queRouter(@RequestParam(value = "sndr", required = false) String sndr,
@RequestParam(value = "btype", required = false) String btype,
@RequestParam(value = "stype", required = false) String stype,
@RequestParam(value = "currentPage",required = false,defaultValue = "1") int currentPage,
@RequestParam(value = "pageSize",required = false,defaultValue = "10") int pageSize)throws Exception{
MessageRouter messageRouter=new MessageRouter();
messageRouter.setSndr(sndr);
messageRouter.setBtype(btype);
messageRouter.setStype(stype);
PageInfo<MessageRouter> pageInfo=messageRouterService.queRouterList(messageRouter,currentPage,pageSize);
return new ResultJson<>("200","success",pageInfo);
}
}
... ...
package com.sunyo.wlpt.message.bus.service.mapper;
import com.github.pagehelper.PageInfo;
import com.sunyo.wlpt.message.bus.service.model.MessageRouter;
import java.util.List;
... ... @@ -18,4 +19,6 @@ public interface MessageRouterMapper {
int updateByPrimaryKeySelective(MessageRouter record);
int updateByPrimaryKey(MessageRouter record);
List<MessageRouter> queRouterList(MessageRouter messageRouter);
}
... ...
... ... @@ -2,6 +2,8 @@ package com.sunyo.wlpt.message.bus.service.mapper;
import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter;
import java.util.List;
public interface MessageRouterReciverFilterMapper {
int deleteByPrimaryKey(String id);
... ... @@ -11,6 +13,8 @@ public interface MessageRouterReciverFilterMapper {
MessageRouterReciverFilter selectByPrimaryKey(String id);
List<MessageRouterReciverFilter> selectByFilterKey(String id);
int updateByPrimaryKeySelective(MessageRouterReciverFilter record);
int updateByPrimaryKey(MessageRouterReciverFilter record);
... ...
package com.sunyo.wlpt.message.bus.service.model;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
public class MessageRouter {
private String id;
... ... @@ -32,6 +34,8 @@ public class MessageRouter {
private List<MessageRouterReciver> rcvrList;
private MessageRouterReciver reciver;
private List<String> sndrs;
private List<MessageType> types;
... ...
package com.sunyo.wlpt.message.bus.service.model;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
public class MessageRouterReciver {
private String id;
... ... @@ -12,6 +16,8 @@ public class MessageRouterReciver {
private Date creatTime;
private Date updateTime;
private MessageRouterReciverFilter reciverFilter;
private List<MessageRouterReciverFilter> filterList;
public String getId() {
return id;
... ...
package com.sunyo.wlpt.message.bus.service.model;
import java.util.Date;
import lombok.Data;
import java.util.Date;
@Data
public class MessageRouterReciverFilter {
private String id;
... ...
package com.sunyo.wlpt.message.bus.service.service;
import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter;
public interface MessageRouterReciverFilterService {
int addMessageRouterReciverFilter(MessageRouterReciverFilter messageRouterReciverFilter);
}
... ...
package com.sunyo.wlpt.message.bus.service.service;
import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciver;
public interface MessageRouterReciverService {
int addMessageRouterReciver(MessageRouterReciver messageRouterReciver)throws Exception;
}
... ...
package com.sunyo.wlpt.message.bus.service.service;
import com.github.pagehelper.PageInfo;
import com.sunyo.wlpt.message.bus.service.model.MessageRouter;
public interface MessageRouterService {
int addRouter(MessageRouter messageRouter)throws Exception;
int delRouter(String id)throws Exception;
int ediRouter(MessageRouter messageRouter)throws Exception;
PageInfo<MessageRouter> queRouterList(MessageRouter messageRouter,int pageNum,int pageSize)throws Exception;
}
... ...
package com.sunyo.wlpt.message.bus.service.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sunyo.wlpt.message.bus.service.mapper.MessageRouterMapper;
import com.sunyo.wlpt.message.bus.service.model.MessageRouter;
import com.sunyo.wlpt.message.bus.service.service.MessageRouterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.UUID;
@Service
public class MessageRouterImpl implements MessageRouterService {
@Autowired
MessageRouterMapper messageRouterMapper;
@Override
public int addRouter(MessageRouter messageRouter) throws Exception {
return messageRouterMapper.insertSelective(messageRouter);
}
@Override
public int delRouter(String id) throws Exception {
return messageRouterMapper.deleteByPrimaryKey(id);
}
@Override
public int ediRouter(MessageRouter messageRouter) throws Exception {
return messageRouterMapper.updateByPrimaryKeySelective(messageRouter);
}
@Override
public PageInfo<MessageRouter> queRouterList(MessageRouter messageRouter,int pageNum,int pageSize) throws Exception {
PageHelper.startPage(pageNum,pageSize);
List<MessageRouter> list=messageRouterMapper.queRouterList(messageRouter);
PageInfo<MessageRouter> result=new PageInfo<>(list);
return result;
}
}
... ...
package com.sunyo.wlpt.message.bus.service.service.impl;
import com.sunyo.wlpt.message.bus.service.mapper.MessageRouterReciverFilterMapper;
import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter;
import com.sunyo.wlpt.message.bus.service.service.MessageRouterReciverFilterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class MessageRouterReciverFilterImpl implements MessageRouterReciverFilterService {
@Autowired
MessageRouterReciverFilterMapper messageRouterReciverFilterMapper;
@Override
public int addMessageRouterReciverFilter(MessageRouterReciverFilter messageRouterReciverFilter) {
return messageRouterReciverFilterMapper.insertSelective(messageRouterReciverFilter);
}
}
... ...
package com.sunyo.wlpt.message.bus.service.service.impl;
import com.sunyo.wlpt.message.bus.service.mapper.MessageRouterReciverMapper;
import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciver;
import com.sunyo.wlpt.message.bus.service.service.MessageRouterReciverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class MessageRouterReciverImpl implements MessageRouterReciverService {
@Autowired
MessageRouterReciverMapper messageRouterReciverMapper;
@Override
public int addMessageRouterReciver(MessageRouterReciver messageRouterReciver) throws Exception {
return messageRouterReciverMapper.insertSelective(messageRouterReciver);
}
}
... ...
... ... @@ -15,6 +15,7 @@
<result column="ver" property="ver" jdbcType="VARCHAR" />
<result column="creat_time" property="creatTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
<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" />
</resultMap>
<sql id="Base_Column_List" >
id, sndr, btype, stype, optype, msg_limit, `character`, status, `usage`, des, ver, creat_time,
... ... @@ -26,6 +27,20 @@
from message_router
where id = #{id,jdbcType=VARCHAR}
</select>
<select id="queRouterList" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageRouter" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from message_router where 1=1
<if test="sndr != null" >
and sndr = #{sndr,jdbcType=VARCHAR}
</if>
<if test="btype != null" >
and btype = #{btype,jdbcType=VARCHAR}
</if>
<if test="stype != null" >
and stype = #{stype,jdbcType=VARCHAR}
</if>
</select>
<select id="selectBySndr" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
... ... @@ -36,7 +51,7 @@
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
delete from message_router
where id = #{sndr,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageRouter" >
insert into message_router (id, sndr, btype,
... ...
... ... @@ -20,6 +20,12 @@
from message_router_reciver_filter
where id = #{id,jdbcType=VARCHAR}
</select>
<select id="selectByFilterKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from message_router_reciver_filter
where message_router_reciver_id = #{messageRouterReciverId,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from message_router_reciver_filter
where id = #{id,jdbcType=VARCHAR}
... ...
... ... @@ -7,6 +7,7 @@
<result column="message_router_id" property="messageRouterId" jdbcType="VARCHAR" />
<result column="creat_time" property="creatTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
<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" />
</resultMap>
<sql id="Base_Column_List" >
id, rcvr_topic, message_router_id, creat_time, update_time
... ... @@ -23,6 +24,12 @@
from message_router_reciver
where message_router_id = #{messageRouterId,jdbcType=VARCHAR}
</select>
<select id="queReciverList" resultMap="BaseResultMap" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageRouterReciver" >
select
<include refid="Base_Column_List" />
from message_router_reciver
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
delete from message_router_reciver
where id = #{id,jdbcType=VARCHAR}
... ...