package com.ylcm.sys.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylcm.sys.domain.AdSpecial;
import com.ylcm.sys.form.AdSpecialAnalysisBenchmarkingQueryForm;
import com.ylcm.sys.form.AdSpecialAnalysisQueryForm;
import com.ylcm.sys.mapper.AdSpecialMapper;
import com.ylcm.sys.service.AdPlatformService;
import com.ylcm.sys.service.AdProductService;
import com.ylcm.sys.service.SpecialAnalysisService;
import com.ylcm.sys.vo.AdSpecialAnalysisBenchmarkingVO;
import com.ylcm.sys.vo.AdSpecialAnalysisVO;
import com.ylcm.sys.vo.AdSpecialDistVO;
import com.ylcm.sys.vo.AdSpecialTopVO;

@Service
public class SpecialAnalysisServiceImpl implements SpecialAnalysisService {

	@Resource
	private AdSpecialMapper adSpecialMapper;
	
	@Resource 
	private AdProductService adProductService;
	
	@Resource 
	private AdPlatformService adPlatformService;
	
	@Override
	public IPage<AdSpecialAnalysisVO> page(AdSpecialAnalysisQueryForm queryForm) {
		
		if(StringUtils.isNotBlank(queryForm.getKeyword())) {
			queryForm.setKeyword(queryForm.getKeyword().trim());
		}
		if(queryForm.getType() == null) {
			return adSpecialMapper.getALLPage(new Page<AdSpecial>(queryForm.getPageNo(), queryForm.getPageSize()), queryForm);
		}
		return adSpecialMapper.getPage(new Page<AdSpecial>(queryForm.getPageNo(), queryForm.getPageSize()), queryForm);
	}

	@Cacheable(value = "SpecialAnalysis",keyGenerator = "cacheKeyGenerator")
	@Override
	public List<AdSpecialTopVO> specialTop(Integer type, String startDate, String endDate) {
		if(type == null) {
			return new ArrayList<AdSpecialTopVO>();
		}
		return adSpecialMapper.specialTop(type, startDate, endDate);
	}

	@Override
	public List<AdSpecialDistVO> mediaDist(Integer type, String productName, String startDate, String endDate) {
		return adSpecialMapper.mediaDist(type, productName, startDate, endDate);
	}
	
	
	@Override
	public List<AdSpecialDistVO> tvDist(Integer type, String productName, String startDate, String endDate) {
		return adSpecialMapper.tvDist(type, productName, startDate, endDate);
	}

	@Override
	public List<AdSpecialDistVO> secondIndDist(Integer type, Integer launch, String secondInd, String startDate, String endDate) {
		if(StringUtils.isBlank(secondInd)) {
			return new ArrayList<AdSpecialDistVO>();
		}
		return adSpecialMapper.secondIndDist(type, launch, secondInd, startDate, endDate);
	}

	@Override
	public IPage<AdSpecialAnalysisBenchmarkingVO> benchmarkingPage(AdSpecialAnalysisBenchmarkingQueryForm queryForm) {
		
		return adSpecialMapper.benchmarkingPage(new Page<AdSpecialAnalysisBenchmarkingQueryForm>(queryForm.getPageNo(), queryForm.getPageSize()), queryForm);
	}



}
