package com.cloudcross.ssp.back.service.impl;

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

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloudcross.ssp.back.model.AdvBalance;
import com.cloudcross.ssp.back.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 {
	private static final Logger LOG = Logger.getLogger(AdvBalanceService.class);
	@Autowired
	private GenericIBatisDao myBatisDao;
	
	@Override
	public AdvBalance findById(Long id) {
		return myBatisDao.get("back.advBalanceSqlMapper.findById", id);
	}

	@Override
	public int countByParams(Map<String, Object> paramMap) {
		//这里的搜索只是对日期进行搜索
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		
		System.out.println("chenyou:searchValue" + searchValue);
		paramMap.put("actTime", searchValue);
		return myBatisDao.get("back.advBalanceSqlMapper.countByParams", paramMap);
	}

	@Override
	public List<AdvBalance> findByParams(Map<String, Object> paramMap,
			Pager pager) {
		//这里的搜索只是对日期进行搜索
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		paramMap.put("actTime", searchValue);
		paramMap.put("pager", pager);
		return myBatisDao.getList("back.advBalanceSqlMapper.findByParams", paramMap);
	}

	@Override
	public boolean add(AdvBalance t) {
		myBatisDao.save("back.advBalanceSqlMapper.add", t);
		return true;
	}

	@Override
	public boolean edit(AdvBalance t) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateStatus(List<Long> idList, int status) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Float findBalanceByAgentId(Long agentId) {
		return myBatisDao.get("back.advBalanceSqlMapper.findBalanceByAgentId", agentId);
	}

	@Override
	public List<AdvBalance> findByParams(Map<String, Object> paramMap) {
		//这里的搜索只是对日期进行搜索
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		paramMap.put("actTime", searchValue);
		return myBatisDao.getList("back.advBalanceSqlMapper.findByParams1", paramMap);
	}

	@Override
	public boolean updateBalanceByAgentId(Long agentId, Float balance) {
		myBatisDao.save("back.advBalanceSqlMapper.updateBalanceByAgentId", MapBuilder.create(HashMap.class)
																	.add("agentId", agentId)
																	.add("balance", balance)
																	.map());
		return true;
	}

	@Override
	public boolean deleteAdvBalanceById(Long id) {
		myBatisDao.save("back.advBalanceSqlMapper.deleteAdvBalanceById", id);
		return true;
	}

}
