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.MarketType;
import com.izouma.awesomeadmin.service.MarketTypeService;
import com.izouma.awesomeadmin.dao.MarketTypeMapper;

/**
*  service接口实现类
*/
@Service
public class MarketTypeServiceImpl implements MarketTypeService{

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

    @Autowired
    private MarketTypeMapper marketTypeMapper;

    @Override
    public List<MarketType> getMarketTypeList(MarketType record) {

        logger.info("getMarketTypeList");
        try {

        return marketTypeMapper.queryAllMarketType(record);
        } catch (Exception e) {
        logger.error("getMarketTypeList", e);
        }

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

        logger.info("getMarketTypeByPage");
        try {

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

        return marketTypeMapper.queryMarketTypeByPage(parameter);
        } catch (Exception e) {
        logger.error("getMarketTypeByPage", e);
        }

        return null;
    }

    @Override
    public MarketType getMarketTypeById(String id) {

        logger.info("getMarketTypeyId");
        try {

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

        return null;
    }

    @Override
    public MarketType getMarketType(MarketType record) {

        logger.info("getMarketType");
        try {

            return marketTypeMapper.queryMarketType(record);
        } catch (Exception e) {
        logger.error("getMarketType", e);
        }

        return null;
    }

    @Override
    public boolean createMarketType(MarketType record) {

        logger.info("createMarketType");
        try {

            int updates = marketTypeMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteMarketType(MarketType record) {

        logger.info("deleteMarketType");
        try {

             int updates = marketTypeMapper.delete(record);

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

        return false;
    }

    @Override
    public boolean updateMarketType(MarketType record) {

        logger.info("updateMarketType");
        try {

            int updates = marketTypeMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

