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.MemberPoint;
import com.izouma.awesomeadmin.service.MemberPointService;
import com.izouma.awesomeadmin.dao.MemberPointMapper;

/**
*  service接口实现类
*/
@Service
public class MemberPointServiceImpl implements MemberPointService{

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

    @Autowired
    private MemberPointMapper memberPointMapper;

    @Override
    public List<MemberPoint> getMemberPointList(MemberPoint record) {

        logger.info("getMemberPointList");
        try {

        return memberPointMapper.queryAllMemberPoint(record);
        } catch (Exception e) {
        logger.error("getMemberPointList", e);
        }

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

        logger.info("getMemberPointByPage");
        try {

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

        return memberPointMapper.queryMemberPointByPage(parameter);
        } catch (Exception e) {
        logger.error("getMemberPointByPage", e);
        }

        return null;
    }

    @Override
    public MemberPoint getMemberPointById(String id) {

        logger.info("getMemberPointyId");
        try {

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

        return null;
    }

    @Override
    public MemberPoint getMemberPoint(MemberPoint record) {

        logger.info("getMemberPoint");
        try {

            return memberPointMapper.queryMemberPoint(record);
        } catch (Exception e) {
        logger.error("getMemberPoint", e);
        }

        return null;
    }

    @Override
    public boolean createMemberPoint(MemberPoint record) {

        logger.info("createMemberPoint");
        try {

            int updates = memberPointMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteMemberPoint(String id) {

        logger.info("deleteMemberPoint");
        try {

             int updates = memberPointMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateMemberPoint(MemberPoint record) {

        logger.info("updateMemberPoint");
        try {

            int updates = memberPointMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

