package com.cloudcross.ssp.service.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloudcross.ssp.base.dao.GenericIBatisDao;
import com.cloudcross.ssp.common.utils.Pager;
import com.cloudcross.ssp.model.Correlation;
import com.cloudcross.ssp.service.ICorrelationService;

@Service
public class CorrelationService implements ICorrelationService{

	@Autowired
	private GenericIBatisDao myBatisDao;
	
	@Override
	public List<Correlation> findAllCorrelation(Pager p) {
		// TODO Auto-generated method stub
		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("pager", p);
		return myBatisDao.getList("correlationSqlMapper.findAllCorrelation",paramMap);
	}

	@Override
	public List<Correlation> findCorrelationByOperatorId(Long operatorId) {
		// TODO 通过operatorId查询是否关联代理商
		return myBatisDao.getList("correlationSqlMapper.findCorrelationByOperatorId",operatorId);
	}


	public boolean addCorrelation1(Correlation c) {
		// TODO 添加所有的账号，代理商，广告主，订单，活动，投放的关联
		myBatisDao.save("correlationSqlMapper.addCorrelation11", c);
		myBatisDao.save("correlationSqlMapper.addCorrelation12", c);
		myBatisDao.save("correlationSqlMapper.addCorrelation13", c);
		myBatisDao.save("correlationSqlMapper.addCorrelation14", c);
		myBatisDao.save("correlationSqlMapper.addCorrelation15", c);
		myBatisDao.save("correlationSqlMapper.addCorrelation16", c);
		return true;
	}


	public boolean deleteCorrelation1(Correlation c) {
		// TODO 添加所有的账号，代理商，广告主，订单，活动，投放的关联
		myBatisDao.save("correlationSqlMapper.deleteCorrelation11", c);
		myBatisDao.save("correlationSqlMapper.deleteCorrelation12", c);
		myBatisDao.save("correlationSqlMapper.deleteCorrelation13", c);
		myBatisDao.save("correlationSqlMapper.deleteCorrelation14", c);
		myBatisDao.save("correlationSqlMapper.deleteCorrelation15", c);
		myBatisDao.save("correlationSqlMapper.deleteCorrelation16", c);
		return true;
	}


	public boolean addCorrelation2(Correlation c) {
		// TODO 添加所有的报表的operator关联
		myBatisDao.save("correlationSqlMapper.addCorrelation21", c);
		myBatisDao.save("correlationSqlMapper.addCorrelation22", c);
		myBatisDao.save("correlationSqlMapper.addCorrelation23", c);
		myBatisDao.save("correlationSqlMapper.addCorrelation24", c);
		myBatisDao.save("correlationSqlMapper.addCorrelation25", c);
		myBatisDao.save("correlationSqlMapper.addCorrelation26", c);
		return true;
	}


	public boolean deleteCorrelation2(Correlation c) {
		// TODO Auto-generated method stub
		myBatisDao.save("correlationSqlMapper.deleteCorrelation21", c);
		myBatisDao.save("correlationSqlMapper.deleteCorrelation22", c);
		myBatisDao.save("correlationSqlMapper.deleteCorrelation23", c);
		myBatisDao.save("correlationSqlMapper.deleteCorrelation24", c);
		myBatisDao.save("correlationSqlMapper.deleteCorrelation25", c);
		myBatisDao.save("correlationSqlMapper.deleteCorrelation26", c);
		return true;
	}

	@Override
	public boolean addCorrelation(Correlation c) {
		// TODO Auto-generated method stub
		addCorrelation1(c);
		addCorrelation2(c);
		return true;
	}

	@Override
	public boolean deleteCorrelation(Correlation c) {
		// TODO Auto-generated method stub
		deleteCorrelation1(c);
		deleteCorrelation2(c);
		return true;
	}

	@Override
	public int countAllCorrelation() {
		// TODO Auto-generated method stub
		return myBatisDao.get("correlationSqlMapper.countAllCorrelation",null);
	}
}
