package com.ruoyi.mall.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mall.mapper.MemberMessageMapper;
import com.ruoyi.mall.domain.MemberMessage;
import com.ruoyi.mall.service.IMemberMessageService;

import javax.annotation.Resource;

/**
 * 用户消息Service业务层处理
 * （论坛帖子消息）
 * @author ruoyi
 * @date 2023-10-18
 */
@Service
public class MemberMessageServiceImpl implements IMemberMessageService 
{
    @Resource
    private MemberMessageMapper memberMessageMapper;

    /**消息已读
     */
    @Override
    public int readMessage(Long messageId) {
        MemberMessage bm=new MemberMessage();
        bm.setMessageId(messageId);
        bm.setReadStatus("1");
        bm.setUpdateTime(DateUtils.getNowDate());
        int affectRows=memberMessageMapper.updateMemberMessage(bm);
        return affectRows;
    }

    /**
     * 点赞/评论 未读数量
     */
    @Override
    public Long noReadCount(Long userId) {
        MemberMessage bo = new MemberMessage();
        bo.setUserId(userId);
        bo.setReadStatus("0");
        return memberMessageMapper.countUnRead(bo);
    }

    /**
     * 查询用户消息
     * 
     * @param messageId 用户消息主键
     * @return 用户消息
     */
    @Override
    public MemberMessage selectMemberMessageByMessageId(Long messageId)
    {
        return memberMessageMapper.selectMemberMessageByMessageId(messageId);
    }

    /**
     * 查询用户消息列表
     * 
     * @param memberMessage 用户消息
     * @return 用户消息
     */
    @Override
    public List<MemberMessage> selectMemberMessageList(MemberMessage memberMessage)
    {
        return memberMessageMapper.selectMemberMessageList(memberMessage);
    }

    /**
     * 新增用户消息
     * 
     * @param memberMessage 用户消息
     * @return 结果
     */
    @Override
    public int insertMemberMessage(MemberMessage memberMessage)
    {
        memberMessage.setCreateTime(DateUtils.getNowDate());
        return memberMessageMapper.insertMemberMessage(memberMessage);
    }

    /**
     * 修改用户消息
     * 
     * @param memberMessage 用户消息
     * @return 结果
     */
    @Override
    public int updateMemberMessage(MemberMessage memberMessage)
    {
        memberMessage.setUpdateTime(DateUtils.getNowDate());
        return memberMessageMapper.updateMemberMessage(memberMessage);
    }

    /**
     * 批量删除用户消息
     * 
     * @param messageIds 需要删除的用户消息主键
     * @return 结果
     */
    @Override
    public int deleteMemberMessageByMessageIds(Long[] messageIds)
    {
        return memberMessageMapper.deleteMemberMessageByMessageIds(messageIds);
    }

    /**
     * 删除用户消息信息
     * 
     * @param messageId 用户消息主键
     * @return 结果
     */
    @Override
    public int deleteMemberMessageByMessageId(Long messageId)
    {
        return memberMessageMapper.deleteMemberMessageByMessageId(messageId);
    }
}
