package com.izouma.awesomeadmin.service.impl;

import java.util.*;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.izouma.awesomeadmin.constant.AppConstant;
import com.izouma.awesomeadmin.dto.Page;
import com.izouma.awesomeadmin.model.MarketMap;
import com.izouma.awesomeadmin.service.MarketMapService;
import com.izouma.awesomeadmin.dao.MarketMapMapper;

/**
*  service接口实现类
*/
@Service
public class MarketMapServiceImpl implements MarketMapService{

    private static Logger logger = Logger.getLogger(MarketMapServiceImpl.class);

    @Autowired
    private MarketMapMapper marketMapMapper;

    @Override
    public List<MarketMap> getMarketMapList(MarketMap record) {

        logger.info("getMarketMapList");
        try {

        return marketMapMapper.queryAllMarketMap(record);
        } catch (Exception e) {
        logger.error("getMarketMapList", e);
        }

        return null;
    }
    @Override
    public List<MarketMap> getMarketMapByPage(Page page, MarketMap record) {

        logger.info("getMarketMapByPage");
        try {

        Map<String, Object> parameter = new HashMap<String, Object>();
        parameter.put("record", record);
        parameter.put(AppConstant.PAGE, page);

        return marketMapMapper.queryMarketMapByPage(parameter);
        } catch (Exception e) {
        logger.error("getMarketMapByPage", e);
        }

        return null;
    }

    @Override
    public MarketMap getMarketMapById(String id) {

        logger.info("getMarketMapyId");
        try {

            return marketMapMapper.selectByPrimaryKey(Integer.valueOf(id));
        } catch (Exception e) {
        logger.error("getMarketMapById", e);
        }

        return null;
    }

    @Override
    public MarketMap getMarketMap(MarketMap record) {

        logger.info("getMarketMap");
        try {

            return marketMapMapper.queryMarketMap(record);
        } catch (Exception e) {
        logger.error("getMarketMap", e);
        }

        return null;
    }

    @Override
    public boolean createMarketMap(MarketMap record) {

        logger.info("createMarketMap");
        try {

            int updates = marketMapMapper.insertSelective(record);

            if (updates > 0) {
                 return true;
            }
        } catch (Exception e) {
            logger.error("createMarketMap", e);
        }

        return false;
    }

    @Override
    public boolean deleteMarketMap(MarketMap record) {

        logger.info("deleteMarketMap");
        try {

             int updates = marketMapMapper.delete(record);

            if (updates > 0) {
                 return true;
            }
        } catch (Exception e) {
             logger.error("deleteMarketMap", e);
        }

        return false;
    }

    @Override
    public boolean updateMarketMap(MarketMap record) {

        logger.info("updateMarketMap");
        try {

            int updates = marketMapMapper.updateByPrimaryKeySelective(record);

            if (updates > 0) {
                 return true;
            }
        } catch (Exception e) {
             logger.error("updateMarketMap", e);
        }

        return false;
    }
}

