package com.cloudcross.ssp.service.impl;



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

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

import com.cloudcross.ssp.model.AdvBalance;
import com.cloudcross.ssp.service.IAdvBalanceService;
import com.cloudcross.ssp.base.dao.GenericIBatisDao;
import com.cloudcross.ssp.common.utils.MapBuilder;
import com.cloudcross.ssp.common.utils.Pager;
import com.cloudcross.ssp.common.utils.SqlHelper;

@Service
public class AdvBalanceService implements IAdvBalanceService{
	@Autowired
	private GenericIBatisDao myBatisDao;	
	@Override
	public int countByParams(Map<String, Object> paramMap) {
		return myBatisDao.get("advBalanceSqlMapper.countByParams", paramMap);
	}
	public boolean updateBalanceByAgentId(Long agentId, Float balance) {
		myBatisDao.save("advBalanceSqlMapper.updateBalanceByAgentId.back", MapBuilder.create(HashMap.class)
																	.add("agentId", agentId)
																	.add("balance", balance)
																	.map());
		return true;
	}
	public int countByParamsBack(Map<String, Object> paramMap) {
		//这里的搜索只是对日期进行搜索
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		paramMap.put("actTime", searchValue);
		return myBatisDao.get("advBalanceSqlMapper.countByParamsBack", paramMap);
	}
	@Override
	public int countByParams2(Map<String, Object> paramMap) {
		return myBatisDao.get("advBalanceSqlMapper.countByParams2", paramMap);
	}
	
	@Override
	public AdvBalance findById(Long id) {
		return myBatisDao.get("advBalanceSqlMapper.selectById", id);
	}
	
	@Override
	public List<AdvBalance> findByParams(Map<String, Object> paramMap, Pager pager) {
		paramMap.put("pager", pager);
		return myBatisDao.getList("advBalanceSqlMapper.selectByParams", paramMap);
		
	}
	/**
	 * back
	 * @param paramMap
	 * @param pager
	 * @return
	 */
	public List<AdvBalance> findByParamsBack(Map<String, Object> paramMap,
			Pager pager) {
		//这里的搜索只是对日期进行搜索
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		paramMap.put("actTime", searchValue);
		paramMap.put("pager", pager);
		return myBatisDao.getList("advBalanceSqlMapper.findByParamsBack", paramMap);
	}
	
	public List<AdvBalance> findByParams(Map<String, Object> paramMap) {
		//这里的搜索只是对日期进行搜索
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		paramMap.put("actTime", searchValue);
		return myBatisDao.getList("advBalanceSqlMapper.findByParams1Back", paramMap);
	}
	@Override
	public List<AdvBalance> findByParams2(Map<String, Object> paramMap) {
		return myBatisDao.getList("advBalanceSqlMapper.selectByParams3", paramMap);
	}
	
	
	@Override
	public boolean edit(AdvBalance t) {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public AdvBalance findAdvertiserName(String advertiserName) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public boolean add(AdvBalance t) {
		myBatisDao.save("advBalanceSqlMapper.addBack", t);
		return true;
	}
	@Override
	public boolean updateStatus(List<Long> idList, int status) {
		// TODO Auto-generated method stub
		return false;
	}
	
	@Override
	public Double findBalanceByAgentId(Long agentId) {
		return myBatisDao.get("advBalanceSqlMapper.findBalanceByAgentIdBack", agentId);
	}
	
	@Override
	public boolean deleteAdvBalanceById(Long id) {
		myBatisDao.save("advBalanceSqlMapper.deleteAdvBalanceByIdBack", id);
		return true;
	}

	@Override
	public boolean updateBalanceByAgentId(Long agentId, Double balance) {
		// TODO Auto-generated method stub
		return false;
	}
	
	
	@Override
	public List<AdvBalance> findByParamsAdvertiser(Map<String, Object> paramMap) {
		return myBatisDao.getList("advBalanceSqlMapper.selectByParams1", paramMap);
	}
	@Override
	public List<AdvBalance> findByParams2(Map<String, Object> paramMap,
			Pager pager) {
		paramMap.put("pager", pager);
		return myBatisDao.getList("advBalanceSqlMapper.selectByParams2", paramMap);
	}
	@Override
	public Double findBalanceByAdvertiserId(Long advertiserId) {
		return myBatisDao.get("advBalanceSqlMapper.findBalanceByAdvertiserId", advertiserId);
	}
	@Override
	public boolean backOut(Map<String, Object> paramMap) {
		myBatisDao.save("advBalanceSqlMapper.backOut", paramMap);
		return true;
	}

}
