package com.cloudcross.ssp.service.impl;



import java.util.Date;
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.model.AuditBanner;
import com.cloudcross.ssp.service.IAuditBannerService;
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 AuditBannerService implements IAuditBannerService {
	
	private static final Logger LOG = Logger.getLogger(AuditBannerService.class);
	
	@Autowired
	private GenericIBatisDao myBatisDao;

	@Override
	public AuditBanner findById(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int countByParams(Map<String, Object> paramMap) {
		// TODO Auto-generated method stub
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		String checked = SqlHelper.doLike(paramMap.get("checked"));
		paramMap.put("checked", checked);
	    paramMap.put("key", paramMap.get("searchKey"));
		paramMap.put("value", searchValue);
		LOG.info("paramMap的值为"+paramMap);
		
		return myBatisDao.get("auditBannerSqlMapper.countByParams", paramMap);
		
	}

	@Override
	public List<AuditBanner> findByParams(Map<String, Object> paramMap, Pager pager) {
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		paramMap.put("key", paramMap.get("searchKey"));
		paramMap.put("value", searchValue);
		paramMap.put("pager", pager);
		LOG.info("paramMap的值为"+paramMap);
		return myBatisDao.getList("auditBannerSqlMapper.findByParams", paramMap);
	}

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

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

	@Override
	public boolean updateStatus(List<Long> auditBannerIdList, int checked) {
		System.out.println("aaaaaaaaaaa==="+checked);
		// TODO Auto-generated method stub
		myBatisDao.save("auditBannerSqlMapper.updateBannerStatus",
				MapBuilder.create(HashMap.class)
					.add("auditBannerIdList", auditBannerIdList)
					.add("updated", new Date())
					.add("checked", checked).map());
		return true;
	}

	@Override
	public int countByOperatorIdandParams(Long operatorId,Map<String, Object> paramMap) {
		// TODO Auto-generated method stub
		LOG.info("传入的参数：" + operatorId);
		paramMap.put("operatorId", operatorId);
		paramMap.put("searchValue", "%" + paramMap.get("searchValue") + "%");
		int bannerNumber = myBatisDao.get("bannerSqlMapper.countByOperatorId", paramMap);
		LOG.info("计算素材的个数：" + bannerNumber);
		return bannerNumber;
	}

	@Override
	public List<AuditBanner> findByOperatorIdandParams(Long operatorId,Map<String, Object> paramMap, Pager pager) {
		// TODO Auto-generated method stub
		LOG.info("传入的参数：" + operatorId);
		paramMap.put("operatorId", operatorId);
		paramMap.put("pager", pager);
		paramMap.put("searchValue", "%" + paramMap.get("searchValue") + "%");
		List<AuditBanner> bannerList = myBatisDao.getList("bannerSqlMapper.findByOperatorId", paramMap);
		LOG.info("素材列表：" + bannerList);
		for(AuditBanner banner:bannerList){
			System.out.println("aaa:" + banner);
		}
		return bannerList;
	}

	@Override
	public boolean UpcheckStatus(List<Long> auditBannerIdList, int checked,
			String memo) {
		Date date = new Date();
		myBatisDao.save("auditBannerSqlMapper.updateBannerStatus",
				MapBuilder.create(HashMap.class)
					.add("auditBannerIdList", auditBannerIdList)
					.add("memo",memo)
					.add("updated", date)
					.add("checked", checked).map());
		myBatisDao.save("auditBannerSqlMapper.updateOperatorBannerTime",
				MapBuilder.create(HashMap.class)
					.add("auditBannerIdList", auditBannerIdList)
					.add("supdated", date)
					.map());			
		return true;
	}

	@Override
	public List<AuditBanner> findAudit(Map<String, Object> paramMap) {
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		String checked = SqlHelper.doLike(paramMap.get("checked"));
		paramMap.put("key", paramMap.get("searchKey"));
		paramMap.put("value", searchValue);
		paramMap.put("checked", checked);
		return myBatisDao.getList("auditBannerSqlMapper.findAudit", paramMap);

	}
}
