作者 王勇

简单优化Controller层代码

... ... @@ -59,7 +59,7 @@ public class MessageNoteController {
* @return 消息收发记录-列表
*/
@GetMapping("/list")
public ResultJson<PageInfo> selectMessageNoteList(
public ResultJson selectMessageNoteList(
@RequestParam(value = "username", required = false) String username,
@RequestParam(value = "serverName", required = false) String serverName,
@RequestParam(value = "virtualHostName", required = false) String virtualHostName,
... ... @@ -73,35 +73,13 @@ public class MessageNoteController {
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
ResultJson<PageInfo> result = new ResultJson<>();
MessageNote messageNote = new MessageNote();
// 获取参数,用户登陆名称
messageNote.setUsername(username);
// 获取参数,MQ服务器名称
messageNote.setServerName(serverName);
// 获取参数,虚拟主机名称
messageNote.setVirtualHostName(virtualHostName);
// 获取参数,交换机名称
messageNote.setExchangeName(exchangeName);
// 获取参数,队列名称
messageNote.setQueueName(queueName);
// 获取参数,路由键名称
messageNote.setRoutingKeyName(routingKeyName);
// 获取参数,发送消息时间
messageNote.setSendTime(sendTime);
// 获取参数,接收消息时间
messageNote.setReceiveTime(receiveTime);
// 获取参数
MessageNote messageNote = new MessageNote(username, serverName, virtualHostName, exchangeName, queueName, routingKeyName, sendTime, receiveTime);
// 分页查询
PageInfo pageInfo = messageNoteService.selectMessageNoteList(messageNote, pageNum, pageSize);
if (pageInfo.getTotal() > 0) {
result.setCode("200");
result.setData(pageInfo);
result.setMsg("查询MQ服务器列表,成功!");
} else {
result.setCode("500");
result.setMsg("查询MQ服务器列表,失败!");
}
return result;
return pageInfo.getTotal() > 0
? new ResultJson<>("200", "查询MQ服务器列表,成功!", pageInfo)
: new ResultJson<>("500", "查询MQ服务器列表,失败!");
}
/**
... ... @@ -112,16 +90,10 @@ public class MessageNoteController {
*/
@DeleteMapping("/delete")
public ResultJson deleteMessageNote(@RequestBody MessageNote messageNote) {
ResultJson result = new ResultJson<>();
int num = messageNoteService.deleteByPrimaryKey(messageNote.getId());
if (num > 0) {
result.setCode("200");
result.setMsg("删除-消息收发记录,成功");
} else {
result.setCode("500");
result.setMsg("删除-消息收发记录,失败");
}
return result;
return messageNoteService.deleteByPrimaryKey(messageNote.getId()) > 0
? new ResultJson<>("200", "删除-消息收发记录,成功")
: new ResultJson<>("500", "删除-消息收发记录,失败");
}
/**
... ... @@ -132,16 +104,10 @@ public class MessageNoteController {
*/
@GetMapping("/batchRemove")
public ResultJson batchRemoveMessageNote(String ids) {
ResultJson result = new ResultJson<>();
int num = messageNoteService.deleteByPrimaryKey(ids);
if (num > 0) {
result.setCode("200");
result.setMsg("批量删除-消息收发记录,成功!");
} else {
result.setCode("500");
result.setMsg("批量删除-消息收发记录,失败!");
}
return result;
return messageNoteService.deleteByPrimaryKey(ids) > 0
? new ResultJson<>("200", "删除-消息收发记录,成功")
: new ResultJson<>("500", "删除-消息收发记录,失败");
}
/**
... ... @@ -152,16 +118,10 @@ public class MessageNoteController {
*/
@PutMapping("/update")
public ResultJson updateMessageNote(@RequestBody MessageNote messageNote) {
ResultJson result = new ResultJson<>();
int num = messageNoteService.updateByPrimaryKeySelective(note_fillName(messageNote));
if (num > 0) {
result.setCode("200");
result.setMsg("编辑-消息收发记录,成功");
} else {
result.setCode("500");
result.setMsg("编辑-消息收发记录,失败");
}
return result;
return messageNoteService.updateByPrimaryKeySelective(note_fillName(messageNote)) > 0
? new ResultJson<>("200", "编辑-消息收发记录,成功")
: new ResultJson<>("500", "编辑-消息收发记录,失败");
}
/**
... ... @@ -172,21 +132,11 @@ public class MessageNoteController {
*/
@PostMapping("/insert")
public ResultJson insertMessageNote(@RequestBody MessageNote messageNote) {
ResultJson result = new ResultJson<>();
// 设置id
messageNote.setId(IdUtils.generateId());
if (!"".equals(messageNote.getAlias_sendContent()) && messageNote.getAlias_sendContent() != null) {
messageNote.setSendContent(messageNote.getAlias_sendContent().getBytes());
}
int num = messageNoteService.insertSelective(note_fillName(messageNote));
if (num > 0) {
result.setCode("200");
result.setMsg("添加-消息收发记录,成功");
} else {
result.setCode("500");
result.setMsg("添加-消息收发记录,失败");
}
return result;
return messageNoteService.insertSelective(note_fillName(messageNote)) > 0
? new ResultJson<>("200", "编辑-消息收发记录,成功")
: new ResultJson<>("500", "编辑-消息收发记录,失败");
}
/**
... ...
package com.sunyo.wlpt.message.bus.service.domain;
import java.io.Serializable;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
/**
* @author 子诚
* Description:消息收发记录表(默认存储七天)
... ... @@ -120,4 +120,26 @@ public class MessageNote implements Serializable {
*/
private Date gmtModified;
/**
* 自定义有参构造器,封装 MessageNoteController 的查询参数
*
* @param username 用户登陆名称
* @param serverName MQ服务器名称
* @param virtualHostName 虚拟主机名称
* @param exchangeName 交换机名称
* @param queueName 队列名称
* @param routingKeyName 路由键名称
* @param sendTime 发送消息时间
* @param receiveTime 接收消息时间
*/
public MessageNote(String username, String serverName, String virtualHostName, String exchangeName, String queueName, String routingKeyName, Date sendTime, Date receiveTime) {
this.username = username;
this.serverName = serverName;
this.virtualHostName = virtualHostName;
this.exchangeName = exchangeName;
this.queueName = queueName;
this.routingKeyName = routingKeyName;
this.sendTime = sendTime;
this.receiveTime = receiveTime;
}
}
\ No newline at end of file
... ...
... ... @@ -104,6 +104,17 @@ public class UserMessageBinding implements Serializable {
*/
private Date gmtModified;
/**
* 自定义有参构造器,封装 UserMessageBindingController 的查询参数
*
* @param username 用户名称
* @param serverName 服务器名称
* @param virtualHostName 虚拟主机名称
* @param exchangeName 交换机名称
* @param queueName 队列名称
* @param routingKeyName 路由键名称
* @param subscriber 订阅者
*/
public UserMessageBinding(String username, String serverName, String virtualHostName, String exchangeName, String queueName, String routingKeyName, String subscriber) {
this.username = username;
this.serverName = serverName;
... ...