Blame view

MessageServiceImpl.java 1.76 KB
涂亚平 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
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;
    }
}