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.CouponInfo;
import com.izouma.awesomeadmin.service.CouponInfoService;
import com.izouma.awesomeadmin.dao.CouponInfoMapper;

/**
*  service接口实现类
*/
@Service
public class CouponInfoServiceImpl implements CouponInfoService{

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

    @Autowired
    private CouponInfoMapper couponInfoMapper;

    @Override
    public List<CouponInfo> getCouponInfoList(CouponInfo record) {

        logger.info("getCouponInfoList");
        try {

        return couponInfoMapper.queryAllCouponInfo(record);
        } catch (Exception e) {
        logger.error("getCouponInfoList", e);
        }

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

        logger.info("getCouponInfoByPage");
        try {

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

        return couponInfoMapper.queryCouponInfoByPage(parameter);
        } catch (Exception e) {
        logger.error("getCouponInfoByPage", e);
        }

        return null;
    }

    @Override
    public CouponInfo getCouponInfoById(String id) {

        logger.info("getCouponInfoyId");
        try {

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

        return null;
    }

    @Override
    public CouponInfo getCouponInfo(CouponInfo record) {

        logger.info("getCouponInfo");
        try {

            return couponInfoMapper.queryCouponInfo(record);
        } catch (Exception e) {
        logger.error("getCouponInfo", e);
        }

        return null;
    }

    @Override
    public boolean createCouponInfo(CouponInfo record) {

        logger.info("createCouponInfo");
        try {

            int updates = couponInfoMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteCouponInfo(String id) {

        logger.info("deleteCouponInfo");
        try {

             int updates = couponInfoMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateCouponInfo(CouponInfo record) {

        logger.info("updateCouponInfo");
        try {

            int updates = couponInfoMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

