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

import com.ssj.bean.weixin.sales.domain.LibVipService;
import com.ssj.bean.weixin.user.domain.UserCount;
import com.ssj.dao.weixin.user.dao.UserCountDao;
import com.ssj.dao.weixin.user.dao.UserQueryDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.service.weixin.sales.service.LibVipServiceService;
import com.ssj.service.weixin.user.service.UserCountService;
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.Date;
import java.util.Map;


/** 
 * @author  ZhangCaibao 
 * @version 2018年2月2日 下午4:11:26 
 * 类说明 
 */
@Service
@Transactional
public class UserCountServiceImpl extends BaseServiceImpl<UserCount, String> implements UserCountService {
	
	
	@Autowired
	private UserCountDao userCountDao;

	@Autowired
	private LibVipServiceService libVipServiceService;

	@Autowired
	private UserQueryDao userQueryDao;
	
	@Override
	public PagingAndSortingRepository<UserCount, String> getDao() {
		return userCountDao;
	}


	@Override
	public void saveUserCount(String userId, String vipId, int type) {
		LibVipService libVipServices= libVipServiceService.findLastZybService(vipId);
		UserCount userCount  =new UserCount();
		userCount.setCreateTime(new Date());userCount.setNum(1);userCount.setType(type);
		userCount.setUserId(userId);userCount.setVipId(vipId);if(libVipServices!=null){userCount.setLibId(libVipServices.getLibId());}
		this.save(userCount);

	}

	@Override
	public void saveUserCount(String userId, String vipId, int type, String libId) {
		UserCount userCount  =new UserCount();
		userCount.setCreateTime(new Date());userCount.setNum(1);userCount.setType(type);
		userCount.setUserId(userId);userCount.setVipId(vipId);userCount.setLibId(libId);
		this.save(userCount);
	}

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