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.MarketCode;
import com.izouma.awesomeadmin.service.MarketCodeService;
import com.izouma.awesomeadmin.dao.MarketCodeMapper;

/**
*  service接口实现类
*/
@Service
public class MarketCodeServiceImpl implements MarketCodeService{

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

    @Autowired
    private MarketCodeMapper marketCodeMapper;

    @Override
    public List<MarketCode> getMarketCodeList(MarketCode record) {

        logger.info("getMarketCodeList");
        try {

        return marketCodeMapper.queryAllMarketCode(record);
        } catch (Exception e) {
        logger.error("getMarketCodeList", e);
        }

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

        logger.info("getMarketCodeByPage");
        try {

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

        return marketCodeMapper.queryMarketCodeByPage(parameter);
        } catch (Exception e) {
        logger.error("getMarketCodeByPage", e);
        }

        return null;
    }

    @Override
    public MarketCode getMarketCodeById(String id) {

        logger.info("getMarketCodeyId");
        try {

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

        return null;
    }

    @Override
    public MarketCode getMarketCode(MarketCode record) {

        logger.info("getMarketCode");
        try {

            return marketCodeMapper.queryMarketCode(record);
        } catch (Exception e) {
        logger.error("getMarketCode", e);
        }

        return null;
    }

    @Override
    public boolean createMarketCode(MarketCode record) {

        logger.info("createMarketCode");
        try {

            int updates = marketCodeMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteMarketCode(MarketCode record) {

        logger.info("deleteMarketCode");
        try {

             int updates = marketCodeMapper.delete(record);

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

        return false;
    }

    @Override
    public boolean updateMarketCode(MarketCode record) {

        logger.info("updateMarketCode");
        try {

            int updates = marketCodeMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

