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.AimTemplate;
import com.izouma.awesomeadmin.service.AimTemplateService;
import com.izouma.awesomeadmin.dao.AimTemplateMapper;

/**
 * service接口实现类
 */
@Service
public class AimTemplateServiceImpl implements AimTemplateService {

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

    @Autowired
    private AimTemplateMapper aimTemplateMapper;

    @Override
    public List<AimTemplate> getAimTemplateList(AimTemplate record) {

        logger.info("getAimTemplateList");
        try {

            return aimTemplateMapper.queryAllAimTemplate(record);
        } catch (Exception e) {
            logger.error("getAimTemplateList", e);
        }

        return null;
    }

    @Override
    public List<AimTemplate> getAimTemplateByPage(Page page, AimTemplate record) {

        logger.info("getAimTemplateByPage");
        try {

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

            return aimTemplateMapper.queryAimTemplateByPage(parameter);
        } catch (Exception e) {
            logger.error("getAimTemplateByPage", e);
        }

        return null;
    }

    @Override
    public AimTemplate getAimTemplateById(String id) {

        logger.info("getAimTemplateyId");
        try {

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

        return null;
    }

    @Override
    public AimTemplate getAimTemplate(AimTemplate record) {

        logger.info("getAimTemplate");
        try {

            return aimTemplateMapper.queryAimTemplate(record);
        } catch (Exception e) {
            logger.error("getAimTemplate", e);
        }

        return null;
    }

    @Override
    public AimTemplate getAimTemplateAllInfo(AimTemplate record) {

        logger.info("getAimTemplateAllInfo");
        try {

            return aimTemplateMapper.queryAimTemplateAllInfo(record);
        } catch (Exception e) {
            logger.error("getAimTemplateAllInfo", e);
        }

        return null;
    }

    @Override
    public boolean createAimTemplate(AimTemplate record) {

        logger.info("createAimTemplate");
        try {

            int updates = aimTemplateMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteAimTemplate(AimTemplate record) {

        logger.info("deleteAimTemplate");
        try {

            int updates = aimTemplateMapper.delete(record);

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

        return false;
    }

    @Override
    public boolean updateAimTemplate(AimTemplate record) {

        logger.info("updateAimTemplate");
        try {

            int updates = aimTemplateMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

