package com.cloudcross.ssp.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.model.Audit;
import com.cloudcross.ssp.service.IAuditService;
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 AuditService implements IAuditService{

	@Autowired
	private GenericIBatisDao myBatisDao;

	@Override
	public Audit findById(Long id) {
		return myBatisDao.get("auditSqlMapper.selectByIdBack", id);
	}

	@Override
	public int countByParams(Map<String, Object> paramMap) {
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		paramMap.put("key", paramMap.get("searchKey"));
		paramMap.put("value", searchValue);
		return myBatisDao.get("auditSqlMapper.countByParamsBack", paramMap);
	}

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

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

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

	@Override
	public boolean updateStatus(List<Long> auditIdList, int checkStatus) {
		myBatisDao.save("auditSqlMapper.updateAuditStatus",
				MapBuilder.create(HashMap.class)
					.add("auditIdList", auditIdList)
					.add("modifyDate", new Date())
					.add("checkStatus", checkStatus).map());
		return true;
	}

	@Override
	public int countByStatus(Map<String, Object> paramMap) {
		// TODO Auto-generated method stub
		return myBatisDao.get("auditSqlMapper.countByStatus", paramMap);
	
	}

	@Override
	public List<Audit> findByStatus(Map<String, Object> paramMap) {
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		paramMap.put("key", paramMap.get("searchKey"));
		paramMap.put("value", searchValue);
		return myBatisDao.getList("auditSqlMapper.selectByStatus", paramMap);
	}

	@Override
	public long findByName(String name) {
		return myBatisDao.get("auditSqlMapper.selectByName", name);
	}

	@Override
	public boolean updateCheckStatus(Map<String, Object> paramMap) {
		 myBatisDao.save("auditSqlMapper.updateCheckStatus", paramMap);
		return true;
	}
	@Override
	public List<Audit> findDeliverEffectAnalysis(Map<String, Object> paramMap) {
		return myBatisDao.getList("auditSqlMapper.findDeliverEffectAnalysis", paramMap);
	}



}
