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

import java.util.Date;
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.back.model.AdvAgent;
import com.cloudcross.ssp.back.service.IAdvAgentService;
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;
import com.cloudcross.ssp.web.widget.SelectorController.ISelector;
import com.cloudcross.ssp.web.widget.SelectorController.ISelectorProvider;

@Service
public class AdvAgentService implements IAdvAgentService,ISelectorProvider{

	@Autowired
	protected GenericIBatisDao myBatisDao;
	@Override
	public AdvAgent findById(Long id) {
		// TODO Auto-generated method stub
		return myBatisDao.get("back.advAgentSqlMapper.findById",id);
	}

	@Override
	public int countByParams(Map<String, Object> paramMap) {
		// TODO Auto-generated method stub
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		paramMap.put("value", searchValue);
		return myBatisDao.get("back.advAgentSqlMapper.countByParams",paramMap);
	}

	@Override
	public List<AdvAgent> findByParams(Map<String, Object> paramMap, Pager pager) {
		// TODO Auto-generated method stub
		paramMap.put("pager", pager);
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		paramMap.put("value", searchValue);
		return myBatisDao.get("back.advAgentSqlMapper.findByParams",paramMap);
	}

	@Override
	public boolean add(AdvAgent t) {
		// TODO Auto-generated method stub
		
		 myBatisDao.save("back.advAgentSqlMapper.addAdvAgent", t);
		 return true;
	}

	@Override
	public boolean edit(AdvAgent t) {
		// TODO Auto-generated method stub
		 myBatisDao.save("back.advAgentSqlMapper.editAdvAgent", t);
		 return true;
	}

	@Override
	public boolean updateStatus(List<Long> idList, int status) {
		// TODO Auto-generated method stub
		myBatisDao.save("back.advertiserSqlMapper.updateAdvAgentStatus",
				MapBuilder.create(HashMap.class)
					.add("advAgentIdList", idList)
					.add("modifyDate", new Date())
					.add("status", status).map());
		return true;
	}

	@Override
	public AdvAgent getNew(AdvAgent t) {
		// TODO Auto-generated method stub
		return myBatisDao.get("back.advAgentSqlMapper.getNew", t);
	}
	
	public List<AdvAgent> findAll(){
		return myBatisDao.getList("back.advAgentSqlMapper.findAll");
	}
	@Override
	public Map<String, List<? extends ISelector>> provideData(String[] parentId) {
		// TODO Auto-generated method stub
		List<AdvAgent> advAgentsList = findAll();
		return MapBuilder.create(HashMap.class).add("advAgentsList", advAgentsList)
				.map();
	}
}
