Merge branch 'master' of http://42.192.7.176:3000/suojin/lab-ops-svr
commit
8e3cf3eb32
12 changed files with 371 additions and 6 deletions
@ -0,0 +1,90 @@ |
|||||||
|
package org.springblade.modules.business.contraller; |
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Operation; |
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springblade.core.boot.ctrl.BladeController; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.modules.business.pojo.dto.MessageUpdateDTO; |
||||||
|
import org.springblade.modules.business.pojo.entity.Message; |
||||||
|
import org.springblade.modules.business.pojo.vo.MessageVO; |
||||||
|
import org.springblade.modules.business.service.IMessageService; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import java.time.LocalDate; |
||||||
|
import java.time.LocalDateTime; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
@RestController |
||||||
|
@AllArgsConstructor |
||||||
|
@RequestMapping("/messeage") |
||||||
|
@Tag(name = "消息处理", description = "消息处理") |
||||||
|
public class MessageController extends BladeController { |
||||||
|
|
||||||
|
private final IMessageService messageService; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 获取消息列表接口 |
||||||
|
* |
||||||
|
* @param current |
||||||
|
* @param size |
||||||
|
* @param startTime |
||||||
|
* @param endTime |
||||||
|
* @param status |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@GetMapping("/list") |
||||||
|
@Operation(summary = "消息列表获取", description = "消息列表获取") |
||||||
|
public R getMessageList(Integer current, Integer size, LocalDate startTime, LocalDate endTime, Integer status) { |
||||||
|
return R.data(messageService.getMessageList(current, size, startTime, endTime, status)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取消息总数接口 |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@GetMapping("/total") |
||||||
|
@Operation(summary = "获取消息总数", description = "获取消息总数") |
||||||
|
public R getMessageTotal() { |
||||||
|
Long messageTotal = messageService.getMessageTotal(); |
||||||
|
return R.data(messageTotal); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 更新已读接口 |
||||||
|
* |
||||||
|
* @param messageUpdateDTO |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@PostMapping("/updateStatus") |
||||||
|
@Operation(summary = "更新已读", description = "更新已读") |
||||||
|
public R updateMessageStatus(@RequestBody MessageUpdateDTO messageUpdateDTO) { |
||||||
|
Integer status = messageUpdateDTO.getStatus(); |
||||||
|
Long id = messageUpdateDTO.getId(); |
||||||
|
messageService.updateMessageStatus(id, status); |
||||||
|
return R.success(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 一键已读全部接口 |
||||||
|
*/ |
||||||
|
@PostMapping("/updateStatusAll") |
||||||
|
@Operation(summary = "一键全部已读", description = "一键全部已读") |
||||||
|
public R updateMessageStatusAll() { |
||||||
|
messageService.updateMessageStatusAll(); |
||||||
|
return R.success(); |
||||||
|
} |
||||||
|
|
||||||
|
@PostMapping("/saveMessage") |
||||||
|
public void saveMessage(@RequestBody Message message) { |
||||||
|
String content = message.getContent(); |
||||||
|
String title = message.getTitle(); |
||||||
|
String systemType = message.getSystemType(); |
||||||
|
Long messageUser = message.getMessageUser(); |
||||||
|
Integer messageType = message.getMessageType(); |
||||||
|
messageService.saveMessage(systemType, title, content, messageUser, messageType); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,9 @@ |
|||||||
|
package org.springblade.modules.business.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import org.springblade.modules.business.pojo.entity.Message; |
||||||
|
|
||||||
|
public interface MessageMapper extends BaseMapper<Message> { |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
package org.springblade.modules.business.pojo.dto; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
@Data |
||||||
|
public class MessageUpdateDTO { |
||||||
|
|
||||||
|
private Long id; |
||||||
|
|
||||||
|
private Integer status; |
||||||
|
} |
||||||
@ -0,0 +1,40 @@ |
|||||||
|
package org.springblade.modules.business.pojo.entity; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import org.springblade.core.mp.base.BaseEntity; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
@Data |
||||||
|
@TableName("blade_message") |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class Message extends BaseEntity { |
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Long id; |
||||||
|
|
||||||
|
private String systemType; |
||||||
|
|
||||||
|
private String tenantId; |
||||||
|
|
||||||
|
private Long createUser; |
||||||
|
|
||||||
|
private String title; |
||||||
|
|
||||||
|
private String content; |
||||||
|
|
||||||
|
private Integer level; |
||||||
|
|
||||||
|
private Integer method; |
||||||
|
|
||||||
|
private Integer isRead; |
||||||
|
|
||||||
|
private Integer messageType; |
||||||
|
|
||||||
|
private Long messageUser; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
package org.springblade.modules.business.pojo.vo; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.time.LocalDateTime; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
@Data |
||||||
|
public class MessageVO { |
||||||
|
|
||||||
|
private Long id; |
||||||
|
|
||||||
|
private String content; |
||||||
|
|
||||||
|
private Date createTime; |
||||||
|
|
||||||
|
private Integer status; |
||||||
|
|
||||||
|
private Integer messageType; |
||||||
|
} |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
package org.springblade.modules.business.pojo.vo; |
||||||
|
|
||||||
|
import io.lettuce.core.protocol.CommandHandler; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
|
||||||
|
@Data |
||||||
|
public class PageVO { |
||||||
|
|
||||||
|
private List<MessageVO> list; |
||||||
|
|
||||||
|
private Long total; |
||||||
|
} |
||||||
@ -0,0 +1,24 @@ |
|||||||
|
package org.springblade.modules.business.service; |
||||||
|
|
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
import org.springblade.modules.business.pojo.entity.Message; |
||||||
|
import org.springblade.modules.business.pojo.vo.MessageVO; |
||||||
|
import org.springblade.modules.business.pojo.vo.PageVO; |
||||||
|
|
||||||
|
import java.time.LocalDate; |
||||||
|
import java.time.LocalDateTime; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
public interface IMessageService extends BaseService<Message> { |
||||||
|
|
||||||
|
void saveMessage(String systemType, String title, String content, Long messageUser, Integer messageType); |
||||||
|
|
||||||
|
|
||||||
|
PageVO getMessageList(Integer current, Integer size, LocalDate start, LocalDate end, Integer status); |
||||||
|
|
||||||
|
Long getMessageTotal(); |
||||||
|
|
||||||
|
void updateMessageStatus(Long id, Integer status); |
||||||
|
|
||||||
|
void updateMessageStatusAll(); |
||||||
|
} |
||||||
@ -0,0 +1,131 @@ |
|||||||
|
package org.springblade.modules.business.service.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springblade.core.secure.utils.AuthUtil; |
||||||
|
import org.springblade.modules.business.mapper.MessageMapper; |
||||||
|
import org.springblade.modules.business.pojo.entity.Message; |
||||||
|
import org.springblade.modules.business.pojo.vo.MessageVO; |
||||||
|
import org.springblade.modules.business.pojo.vo.PageVO; |
||||||
|
import org.springblade.modules.business.service.IMessageService; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.time.LocalDate; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
@Service |
||||||
|
public class MessageServiceImpl extends BaseServiceImpl<MessageMapper, Message> implements IMessageService { |
||||||
|
|
||||||
|
/** |
||||||
|
* 保存消息 |
||||||
|
* |
||||||
|
* @param systemType |
||||||
|
* @param title |
||||||
|
* @param content |
||||||
|
* @param messageUser |
||||||
|
* @param messageType |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void saveMessage(String systemType, String title, String content, Long messageUser, Integer messageType) { |
||||||
|
Message saveInformation = new Message(); |
||||||
|
saveInformation.setSystemType(systemType); |
||||||
|
saveInformation.setTitle(title); |
||||||
|
saveInformation.setContent(content); |
||||||
|
saveInformation.setMessageUser(messageUser); |
||||||
|
saveInformation.setTenantId(AuthUtil.getTenantId()); |
||||||
|
saveInformation.setCreateUser(AuthUtil.getUserId()); |
||||||
|
saveInformation.setLevel(1); |
||||||
|
saveInformation.setMethod(2); |
||||||
|
saveInformation.setIsRead(0); |
||||||
|
saveInformation.setMessageType(messageType); |
||||||
|
this.save(saveInformation); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 消息列表获取 |
||||||
|
* |
||||||
|
* @param current |
||||||
|
* @param size |
||||||
|
* @param startTime |
||||||
|
* @param endTime |
||||||
|
* @param status |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public PageVO getMessageList(Integer current, Integer size, LocalDate startTime, LocalDate endTime, Integer status) { |
||||||
|
QueryWrapper<Message> queryWrapper = new QueryWrapper<>(); |
||||||
|
if (startTime != null && endTime != null) { |
||||||
|
queryWrapper.between("create_time", startTime, endTime); |
||||||
|
} |
||||||
|
if (status != null) { |
||||||
|
queryWrapper.eq("is_read", status); |
||||||
|
} |
||||||
|
//筛选专属该用户的信息
|
||||||
|
queryWrapper.eq("message_user", AuthUtil.getUserId()); |
||||||
|
//使未读在已读之上
|
||||||
|
queryWrapper.orderByAsc("is_read"); |
||||||
|
//在未读在已读之上的基础上 再按时间进行排序
|
||||||
|
queryWrapper.orderByDesc("create_time"); |
||||||
|
Page<Message> page = new Page<>(current, size); |
||||||
|
Page<Message> messagePage = baseMapper.selectPage(page, queryWrapper); |
||||||
|
List<Message> records = messagePage.getRecords(); |
||||||
|
Long total = messagePage.getTotal(); |
||||||
|
List<MessageVO> messageVOList = new ArrayList<>(); |
||||||
|
for (Message record : records) { |
||||||
|
MessageVO messageVO = new MessageVO(); |
||||||
|
messageVO.setId(record.getId()); |
||||||
|
messageVO.setContent(record.getContent()); |
||||||
|
messageVO.setMessageType(record.getMessageType()); |
||||||
|
messageVO.setStatus(record.getIsRead()); |
||||||
|
messageVO.setCreateTime(record.getCreateTime()); |
||||||
|
messageVOList.add(messageVO); |
||||||
|
} |
||||||
|
PageVO pageVO = new PageVO(); |
||||||
|
pageVO.setList(messageVOList); |
||||||
|
pageVO.setTotal(total); |
||||||
|
return pageVO; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取消息总数 |
||||||
|
* |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public Long getMessageTotal() { |
||||||
|
QueryWrapper<Message> queryWrapper = new QueryWrapper<>(); |
||||||
|
//筛选该用户的专属消息
|
||||||
|
queryWrapper.eq("message_user", AuthUtil.getUserId()); |
||||||
|
//只查询未读的消息
|
||||||
|
queryWrapper.eq("is_read", 0); |
||||||
|
return baseMapper.selectCount(queryWrapper); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 更新消息为已读状态 |
||||||
|
* |
||||||
|
* @param id |
||||||
|
* @param status |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void updateMessageStatus(Long id, Integer status) { |
||||||
|
UpdateWrapper<Message> updateWrapper = new UpdateWrapper<>(); |
||||||
|
updateWrapper.eq("id", id).set("is_read", status); |
||||||
|
baseMapper.update(updateWrapper); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 一键已读全部 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void updateMessageStatusAll() { |
||||||
|
UpdateWrapper<Message> updateWrapper = new UpdateWrapper<>(); |
||||||
|
//筛选该用户的专属消息
|
||||||
|
updateWrapper.eq("message_user", AuthUtil.getUserId()); |
||||||
|
updateWrapper.eq("is_read", 0).set("is_read", 1); |
||||||
|
baseMapper.update(updateWrapper); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue