69 lines
2.6 KiB
Java
69 lines
2.6 KiB
Java
package com.peanut.modules.master.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.peanut.common.utils.R;
|
|
import com.peanut.modules.common.entity.Message;
|
|
import com.peanut.modules.master.service.MessageService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 公共消息
|
|
*/
|
|
@Slf4j
|
|
@RestController("masterMessage")
|
|
@RequestMapping("master/message")
|
|
public class MessageController {
|
|
|
|
@Autowired
|
|
private MessageService messageService;
|
|
|
|
@RequestMapping("/listByPage")
|
|
public R listByPage(@RequestBody Map<String, Object> params) {
|
|
LambdaQueryWrapper<Message> wrapper = new LambdaQueryWrapper();
|
|
if (StringUtils.isNotEmpty(params.get("title").toString())) {
|
|
wrapper.like(Message::getTitle,params.get("title"));
|
|
}
|
|
if (StringUtils.isNotEmpty(params.get("type").toString())) {
|
|
wrapper.eq(Message::getType,params.get("type"));
|
|
}
|
|
if (StringUtils.isNotEmpty(params.get("isBook").toString())||
|
|
StringUtils.isNotEmpty(params.get("isMedical").toString())||
|
|
StringUtils.isNotEmpty(params.get("isSociology").toString())) {
|
|
wrapper.and(t->t.eq("1".equals(params.get("isBook").toString()),Message::getIsBook,params.get("isBook"))
|
|
.or().eq("1".equals(params.get("isMedical").toString()),Message::getIsMedical,params.get("isMedical"))
|
|
.or().eq("1".equals(params.get("isSociology").toString()),Message::getIsSociology,params.get("isSociology")));
|
|
}
|
|
wrapper.orderByDesc(Message::getCreateTime);
|
|
Page<Message> page = messageService.page(new Page<>(
|
|
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())), wrapper);
|
|
return R.ok().put("result", page);
|
|
}
|
|
|
|
@RequestMapping("/getMessageById")
|
|
public R getMessageById(String id) {
|
|
return R.ok().put("result", messageService.getById(id));
|
|
}
|
|
|
|
@RequestMapping("/saveOrUpdateMessage")
|
|
public R saveOrUpdateMessage(@RequestBody Message message) {
|
|
messageService.saveOrUpdate(message);
|
|
return R.ok();
|
|
}
|
|
|
|
@RequestMapping("/delMessage")
|
|
public R delMessage(String id) {
|
|
messageService.removeById(id);
|
|
return R.ok();
|
|
}
|
|
|
|
|
|
|
|
}
|