作者 xudada

添加路由验证,存在提示

... ... @@ -41,6 +41,10 @@ public class MessageTypesController {
@ApiOperation(value = "添加一个消息类", notes = "类名与消息类型必填")
@PostMapping("add")
public ResultJson add(@RequestBody MessageType messageType){
int count=messageTypeService.selectCountMessageType(messageType);
if(count>0){
return new ResultJson("400","消息类型已存在");
}
boolean result = messageTypeService.add(messageType);
return result ? new ResultJson("200","success") : new ResultJson("400","error");
}
... ...
... ... @@ -36,8 +36,21 @@ public class RouterController {
@ApiOperation(value = "批量添加消息路由", notes = "超级管理修改其他用户密码")
@PostMapping("batchAdd")
public ResultJson batchAddRouter(@RequestBody MessageRouter messageRouter){
boolean result = routerService.batchAddRouter(messageRouter);
return result ? new ResultJson("200","success") :new ResultJson("400","error");
if (messageRouter.getSndrs()!=null && messageRouter.getTypes()!=null && messageRouter.getRcvrs()!=null){
List<String> senders = messageRouter.getSndrs();
if (senders!=null && !senders.isEmpty()){
for (String sndr: senders) {
MessageRouter record=new MessageRouter();
record.setSndr(sndr);
int count=messageRouterService.selectCountRouter(record);
if(count>0){
return new ResultJson("400","消息路由已存在!");
}
}
}
}
boolean result = routerService.batchAddRouter(messageRouter);
return result ? new ResultJson("200","success") :new ResultJson("400","error");
}
@GetMapping("searchBysndr")
... ... @@ -50,17 +63,21 @@ public class RouterController {
@PostMapping("/addRouter")
@Transactional
public ResultJson addRouter(@RequestBody MessageRouter messageRouter) throws Exception {
int count=messageRouterService.selectCountRouter(messageRouter);
if(count>0){
return new ResultJson("200","路由消息已存在!");
}
String routerid=UUID.randomUUID().toString();
String reciverid=UUID.randomUUID().toString();
messageRouter.setId(routerid);
int result=messageRouterService.addRouter(messageRouter);
if(messageRouter.getReciver()!=null){
if(messageRouter.getReciver().getRcvrTopic()!=null &&messageRouter.getReciver().getRcvrTopic()!=""){
MessageRouterReciver routerReciver=new MessageRouterReciver();
routerReciver.setId(reciverid);
routerReciver.setMessageRouterId(routerid);
routerReciver.setRcvrTopic(messageRouter.getReciver().getRcvrTopic());
messageRouterReciverService.addMessageRouterReciver(routerReciver);
if(messageRouter.getReciver().getReciverFilter()!=null){
if(messageRouter.getReciver().getReciverFilter().getFilter()!=null&& messageRouter.getReciver().getReciverFilter().getFilter()!=""){
MessageRouterReciverFilter routerReciverFilter=new MessageRouterReciverFilter();
routerReciverFilter.setId(UUID.randomUUID().toString());
routerReciverFilter.setMessageRouterReciverId(reciverid);
... ...
... ... @@ -2,6 +2,7 @@ package com.sunyo.wlpt.message.bus.service.mapper;
import com.github.pagehelper.PageInfo;
import com.sunyo.wlpt.message.bus.service.model.MessageRouter;
import org.apache.ibatis.annotations.Param;
import java.util.List;
... ... @@ -20,5 +21,7 @@ public interface MessageRouterMapper {
int updateByPrimaryKey(MessageRouter record);
int selectCountRouter(MessageRouter messageRouter);
List<MessageRouter> queRouterList(MessageRouter messageRouter);
}
... ...
... ... @@ -24,4 +24,6 @@ public interface MessageTypeMapper {
int updateByPrimaryKeySelective(MessageType record);
int updateByPrimaryKey(MessageType record);
}
\ No newline at end of file
int selectCountMessageType(MessageType record);
}
... ...
... ... @@ -7,5 +7,6 @@ public interface MessageRouterService {
int addRouter(MessageRouter messageRouter)throws Exception;
int delRouter(String id)throws Exception;
int ediRouter(MessageRouter messageRouter)throws Exception;
int selectCountRouter(MessageRouter messageRouter);
PageInfo<MessageRouter> queRouterList(MessageRouter messageRouter,int pageNum,int pageSize)throws Exception;
}
... ...
... ... @@ -20,4 +20,6 @@ public interface MessageTypeService {
boolean batchDel(String[] ids);
int selectCountMessageType(MessageType messageType);
}
... ...
... ... @@ -31,6 +31,11 @@ public class MessageRouterImpl implements MessageRouterService {
}
@Override
public int selectCountRouter(MessageRouter messageRouter) {
return messageRouterMapper.selectCountRouter(messageRouter);
}
@Override
public PageInfo<MessageRouter> queRouterList(MessageRouter messageRouter,int pageNum,int pageSize) throws Exception {
PageHelper.startPage(pageNum,pageSize);
List<MessageRouter> list=messageRouterMapper.queRouterList(messageRouter);
... ...
... ... @@ -58,4 +58,9 @@ public class MessageTypeServiceImp implements MessageTypeService {
return i > 0;
}
@Override
public int selectCountMessageType(MessageType messageType) {
return messageTypeMapper.selectCountMessageType(messageType);
}
}
... ...
... ... @@ -24,6 +24,19 @@
id, sndr, btype, stype, optype, msg_limit, `character`, status, `usage`, des, ver, creat_time,
update_time
</sql>
<select id="selectCountRouter" resultType="java.lang.Integer">
select count(*) 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="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
... ...
... ... @@ -13,11 +13,17 @@
ID, name, parent_id, des, type
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
select
<include refid="Base_Column_List" />
from message_type
where ID = #{id,jdbcType=VARCHAR}
</select>
<select id="selectCountMessageType" resultType="java.lang.Integer">
select count(*) from message_type where 1=1
<if test="name != null and name != ''">
and name = #{name,jdbcType=VARCHAR}
</if>
</select>
<select id="selectByParentId" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
... ... @@ -64,9 +70,9 @@
</delete>
<insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageType" >
insert into message_type (ID, name, parent_id,
insert into message_type (ID, name, parent_id,
des, type)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{parentId,jdbcType=VARCHAR},
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{parentId,jdbcType=VARCHAR},
#{des,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageType" >
... ... @@ -132,4 +138,4 @@
type = #{type,jdbcType=INTEGER}
where ID = #{id,jdbcType=VARCHAR}
</update>
</mapper>
\ No newline at end of file
</mapper>
... ...