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

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.StoryAddress;
import com.ssj.dao.weixin.story.dao.StoryAddressDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.service.weixin.story.service.StoryAddressService;

import java.util.Date;


/** 
 * @author  ZhangCaibao 
 * @version 2018年3月21日 上午11:15:01 
 * 类说明 
 */
@Service(version="1.0")
@Transactional
public class StoryAddressServiceImpl extends BaseServiceImpl<StoryAddress, String> implements StoryAddressService{
	@Autowired
	private  StoryAddressDao  storyAddressDao;
	@Override
	public PagingAndSortingRepository<StoryAddress, String> getDao() {
		return storyAddressDao;
	}
	@Override
	public int integralcount(String userId) {
		return storyAddressDao.integralcount(userId);
	}

	@Override
	public  void  saveStoryAddress(StoryAddress  storyAddress) {
	           String openId =storyAddress.getAddress();
		int count=storyAddressDao.integralAddresscount(openId,storyAddress.getType());
		if(count==0){
			storyAddress.setCreateTime(new Date());
			this.save(storyAddress);
		}

	}

	@Override
	public void deleteByAddress(String address) {
		storyAddressDao.deleteByAddress(address);
	}

	@Override
	public StoryAddress findStoryByUserIdAndType(String userId, int type) {
		return storyAddressDao.findStoryByUserIdAndType(userId,type);
	}

}
