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.OperatorBalance;
import com.cloudcross.ssp.back.service.IOperatorBalanceService;
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 OperatorBalanceService implements IOperatorBalanceService {
	private static final Logger LOG = Logger.getLogger(OperatorBalanceService.class);
	@Autowired
	private GenericIBatisDao myBatisDao;
	
	@Override
	public OperatorBalance findById(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int countByParams(Map<String, Object> paramMap) {
		//这里的搜索只是对交易号进行搜索
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		paramMap.put("num", searchValue);
		return myBatisDao.get("back.operatorBalanceSqlMapper.countByParams", paramMap);
	}

	@Override
	public List<OperatorBalance> findByParams(Map<String, Object> paramMap,
			Pager pager) {
		//这里的搜索只是对交易号进行搜索
		String searchValue = SqlHelper.doLike(paramMap.get("searchValue"));
		paramMap.put("num", searchValue);
		paramMap.put("pager", pager);
		return myBatisDao.getList("back.operatorBalanceSqlMapper.findByParams", paramMap);
	}

	@Override
	public boolean add(OperatorBalance t) {
		myBatisDao.save("back.operatorBalanceSqlMapper.addOperatorBalance", t);
		return true;
	}

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

	@Override
	public boolean updateStatus(List<Long> idList, int status) {
		myBatisDao.save("back.operatorBalanceSqlMapper.updateOperatorBalanceStatus",MapBuilder.create(HashMap.class)
				.add("state", status)
				.add("idList", idList)
				.map());
		return true;
	}


	@Override
	public Float findAvailableMoney(Long operatorId) {
		return myBatisDao.get("back.operatorBalanceSqlMapper.findAvailableMoney", operatorId);
	}

	@Override
	public boolean updateStatus(List<Long> idList, String reason, int status) {
		myBatisDao.save("back.operatorBalanceSqlMapper.updateOperatorBalanceStatus",MapBuilder.create(HashMap.class)
				.add("state", status)
				.add("idList", idList)
				.add("reason", reason)
				.map());
		return true;
	}

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


}
