package com.ssj.service.sys.schoolmatecircle.service.impl;

import com.ssj.bean.sys.schoolmatecircle.domain.SSJUserMessage;
import com.ssj.dao.sys.schoolmatecircle.dao.SSJUserMessageDao;
import com.ssj.dao.sys.schoolmatecircle.dao.SSJUserMessageQueryDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.service.sys.schoolmatecircle.service.SSJUserMessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
@Service
@Transactional
public class SSJUserMessageServiceImpl extends BaseServiceImpl<SSJUserMessage, String> implements SSJUserMessageService {
    protected static final Logger logger = LoggerFactory.getLogger(SSJUserMessageServiceImpl.class);

    @Autowired
    private SSJUserMessageDao dao;
    
    @Autowired
    private SSJUserMessageQueryDao queryDao;

	@Override
	public PagingAndSortingRepository<SSJUserMessage, String> getDao() {
		return dao;
	}

	@Override
	public int countByReceiveUserId(String userId) {
		return dao.countByReceiveUserId(userId);
	}

	@Override
	public Page<Map<String, Object>> findOnlineMessages(Map<String, Object> searchParams, Pageable pageable) {
		return queryDao.findOnlineMessages(searchParams, pageable);
	}

	@Override
	public void updateMessageHaveRead(String sendUserId, String receiveUserId) {
		dao.updateMessageHaveRead(sendUserId, receiveUserId);
	}

	@Override
	public SSJUserMessage findLastOnlineMessage(String sendUserId, String receiveUserId) {
		return dao.findLastOnlineMessage(sendUserId,receiveUserId,receiveUserId,sendUserId);
	}

	@Override
	public void deleteUserMessage(String sendUserId, String receiveUserId) {
		dao.deleteUserMessage(sendUserId, receiveUserId);
	}


	@Override
	public List<SSJUserMessage> findBySendUserIdAndRecieveUserId(String sendUserId, String receiveUserId) {
	return 	dao.findBySendUserIdAndRecieveUserId(sendUserId, receiveUserId);
	}

}