package com.ssj.service.weixin.story.service.impl;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.ssj.bean.weixin.story.bean.StoryPraise;
import com.ssj.dao.weixin.story.dao.StoryPraiseDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.service.weixin.story.service.StoryPraiseService;


/** 
 * @author  ZhangCaibao 
 * @version 2017年8月7日 下午5:27:11 
 * 类说明 
 */
@Service(version="1.0")
@Transactional
public class StoryPraiseServiceImpl extends BaseServiceImpl<StoryPraise, String> implements StoryPraiseService{

	@Autowired
	private StoryPraiseDao storyPraiseDao;
	@Override
	public PagingAndSortingRepository<StoryPraise, String> getDao() {
		return storyPraiseDao;
	}
	@Override
	public  StoryPraise  findByObjectIdAndStatAndUserId(String objectId,String stat,String userId){
		return storyPraiseDao.findByObjectIdAndStatAndUserId(objectId, stat,userId);
	}
	@Override
	public void insertPraise(String userId,String objectId,String stat) {
		Integer  count=this.getStatAndUserId(stat, userId);
		if(count==0){
			StoryPraise praise = new  StoryPraise();
			praise.setCreateTime(new Date());
			praise.setObjectId(objectId);
			praise.setStat(stat);
			praise.setUserId(userId);
			this.save(praise);
		}
		
	}
	@Override
	public List<StoryPraise> findByStat(String stat) {
		return storyPraiseDao.findByStat(stat);
	}
	@Override
	public Integer getStatAndUserId(String stat, String userId) {
		return storyPraiseDao.getStatAndUserId(stat, userId);
	}

}
