MessageServiceImpl.java 1.76 KB
package com.zhongzhi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhongzhi.common.constant.Code;
import com.zhongzhi.common.exception.HttpException;
import com.zhongzhi.common.utils.Localstorage;
import com.zhongzhi.dto.message.MessagePageDTO;
import com.zhongzhi.model.AdministerDO;
import com.zhongzhi.model.MessageDO;
import com.zhongzhi.dao.MessageDAO;
import com.zhongzhi.service.AdministerService;
import com.zhongzhi.service.MessageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 通知消息表 服务实现类
 * </p>
 *
 * @author DengMin
 * @since 2021-05-17
 */
@Service
public class MessageServiceImpl extends ServiceImpl<MessageDAO, MessageDO> implements MessageService {

    @Override
    public void createMessage(MessageDO messageDO) {
        AdministerDO administerDO = (AdministerDO) Localstorage.getUser();
        if (administerDO == null) {
            throw new HttpException(Code.TOKEN_EXPIRED.getCode(), Code.TOKEN_EXPIRED.getMessage());
        }

        messageDO.setUsername(administerDO.getUsername());
        this.baseMapper.insert(messageDO);
    }

    @Override
    public IPage<MessageDO> getMessagePage(MessagePageDTO messagePageDTO) {
        IPage<MessageDO> iPage = this.baseMapper.selectPage(new Page(messagePageDTO.getPageNo(), messagePageDTO.getPageSize()),
                new QueryWrapper<MessageDO>()
                        .lambda()
                        .orderByDesc(MessageDO::getCreateTime));
        return iPage;
    }
}