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

import com.ssj.bean.sys.schoolmatecircle.domain.SchoolmateMessage;
import com.ssj.dao.sys.schoolmatecircle.dao.SchoolmateCircleQueryDao;
import com.ssj.dao.sys.schoolmatecircle.dao.SchoolmateMessageDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.service.sys.schoolmatecircle.service.SchoolmateMessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author Mount Liu
 * @date 2018/8/15
 */
@Service
@Transactional
public class SchoolmateMessageServiceImpl extends BaseServiceImpl<SchoolmateMessage, String> implements SchoolmateMessageService {

    private   Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private SchoolmateMessageDao dao;

    @Autowired
    private SchoolmateCircleQueryDao schoolmateCircleQueryDao;

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

    @Override
    public long countByUserId(String userId) {
        return dao.countByUserId(userId);
    }

    @Override
    public List<Map<String, Object>> findByUserId(String userId) {
        return schoolmateCircleQueryDao.findByUserId(userId);
    }

    @Override
    public void removeAfterQueryUnReadMessage(String userId, Date now) {
        dao.removeByUserIdAndCreateTimeBefore(userId, now);
    }
}
