package com.fs.crm.service.impl;

import com.fs.common.utils.DateUtils;
import com.fs.crm.domain.CrmMsg;
import com.fs.crm.mapper.CrmMsgMapper;
import com.fs.crm.param.CrmMsgListQueryParam;
import com.fs.crm.service.ICrmMsgService;
import com.fs.crm.vo.CrmMsgListQueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *  消息Service业务层处理
 *
 * @author fs
 * @date 2022-12-21
 */
@Service
public class CrmMsgServiceImpl implements ICrmMsgService
{
    @Autowired
    private CrmMsgMapper crmMsgMapper;

    /**
     * 查询 消息
     *
     * @param msgId  消息ID
     * @return  消息
     */
    @Override
    public CrmMsg selectCrmMsgById(Long msgId)
    {
        return crmMsgMapper.selectCrmMsgById(msgId);
    }

    /**
     * 查询 消息列表
     *
     * @param crmMsg  消息
     * @return  消息
     */
    @Override
    public List<CrmMsg> selectCrmMsgList(CrmMsg crmMsg)
    {
        return crmMsgMapper.selectCrmMsgList(crmMsg);
    }

    /**
     * 新增 消息
     *
     * @param crmMsg  消息
     * @return 结果
     */
    @Override
    public int insertCrmMsg(CrmMsg crmMsg)
    {
        crmMsg.setCreateTime(DateUtils.getNowDate());
        return crmMsgMapper.insertCrmMsg(crmMsg);
    }

    /**
     * 修改 消息
     *
     * @param crmMsg  消息
     * @return 结果
     */
    @Override
    public int updateCrmMsg(CrmMsg crmMsg)
    {
        return crmMsgMapper.updateCrmMsg(crmMsg);
    }

    /**
     * 批量删除 消息
     *
     * @param msgIds 需要删除的 消息ID
     * @return 结果
     */
    @Override
    public int deleteCrmMsgByIds(Long[] msgIds)
    {
        return crmMsgMapper.deleteCrmMsgByIds(msgIds);
    }

    /**
     * 删除 消息信息
     *
     * @param msgId  消息ID
     * @return 结果
     */
    @Override
    public int deleteCrmMsgById(Long msgId)
    {
        return crmMsgMapper.deleteCrmMsgById(msgId);
    }

    @Override
    public List<CrmMsgListQueryVO> selectCrmMsgListQuery(CrmMsgListQueryParam param) {
        return crmMsgMapper.selectCrmMsgListQuery(param);
    }

    @Override
    public Long selectCrmMsgCountByUserId(Long userId) {
        return crmMsgMapper.selectCrmMsgCountByUserId(userId);
    }

    @Override
    public Long selectCrmMsgCountByUserId(Long userId, int type) {
        return crmMsgMapper.selectCrmMsgCountByUserIdAndType(userId,type);
    }

    @Override
    public int setAllRead(Long userId) {
        return crmMsgMapper.setAllRead(userId);
    }

    @Override
    public String selectCrmNewMsgByUserId(long userId, int type) {
        return crmMsgMapper.selectCrmNewMsgByUserId(userId,type);
    }

    @Override
    public int setReadByType(Long userId,Integer msgType) {
        return crmMsgMapper.setReadByType(userId,msgType);
    }
}
