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.MarketCodeLog;
import com.izouma.awesomeadmin.service.MarketCodeLogService;
import com.izouma.awesomeadmin.dao.MarketCodeLogMapper;

/**
*  service接口实现类
*/
@Service
public class MarketCodeLogServiceImpl implements MarketCodeLogService{

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

    @Autowired
    private MarketCodeLogMapper marketCodeLogMapper;

    @Override
    public List<MarketCodeLog> getMarketCodeLogList(MarketCodeLog record) {

        logger.info("getMarketCodeLogList");
        try {

        return marketCodeLogMapper.queryAllMarketCodeLog(record);
        } catch (Exception e) {
        logger.error("getMarketCodeLogList", e);
        }

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

        logger.info("getMarketCodeLogByPage");
        try {

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

        return marketCodeLogMapper.queryMarketCodeLogByPage(parameter);
        } catch (Exception e) {
        logger.error("getMarketCodeLogByPage", e);
        }

        return null;
    }

    @Override
    public MarketCodeLog getMarketCodeLogById(String id) {

        logger.info("getMarketCodeLogyId");
        try {

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

        return null;
    }

    @Override
    public MarketCodeLog getMarketCodeLog(MarketCodeLog record) {

        logger.info("getMarketCodeLog");
        try {

            return marketCodeLogMapper.queryMarketCodeLog(record);
        } catch (Exception e) {
        logger.error("getMarketCodeLog", e);
        }

        return null;
    }

    @Override
    public boolean createMarketCodeLog(MarketCodeLog record) {

        logger.info("createMarketCodeLog");
        try {

            int updates = marketCodeLogMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteMarketCodeLog(MarketCodeLog record) {

        logger.info("deleteMarketCodeLog");
        try {

             int updates = marketCodeLogMapper.delete(record);

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

        return false;
    }

    @Override
    public boolean updateMarketCodeLog(MarketCodeLog record) {

        logger.info("updateMarketCodeLog");
        try {

            int updates = marketCodeLogMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

