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.NavigationPackage;
import com.izouma.awesomeadmin.service.NavigationPackageService;
import com.izouma.awesomeadmin.dao.NavigationPackageMapper;

/**
*  service接口实现类
*/
@Service
public class NavigationPackageServiceImpl implements NavigationPackageService{

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

    @Autowired
    private NavigationPackageMapper navigationPackageMapper;

    @Override
    public List<NavigationPackage> getNavigationPackageList(NavigationPackage record) {

        logger.info("getNavigationPackageList");
        try {

        return navigationPackageMapper.queryAllNavigationPackage(record);
        } catch (Exception e) {
        logger.error("getNavigationPackageList", e);
        }

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

        logger.info("getNavigationPackageByPage");
        try {

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

        return navigationPackageMapper.queryNavigationPackageByPage(parameter);
        } catch (Exception e) {
        logger.error("getNavigationPackageByPage", e);
        }

        return null;
    }

    @Override
    public NavigationPackage getNavigationPackageById(String id) {

        logger.info("getNavigationPackageyId");
        try {

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

        return null;
    }

    @Override
    public NavigationPackage getNavigationPackage(NavigationPackage record) {

        logger.info("getNavigationPackage");
        try {

            return navigationPackageMapper.queryNavigationPackage(record);
        } catch (Exception e) {
        logger.error("getNavigationPackage", e);
        }

        return null;
    }

    @Override
    public NavigationPackage getBoughtNavigationPackage(NavigationPackage record) {

        logger.info("getNavigationPackage");
        try {

            return navigationPackageMapper.queryBoughtNavigationPackage(record);
        } catch (Exception e) {
        logger.error("getNavigationPackage", e);
        }

        return null;
    }

    @Override
    public boolean createNavigationPackage(NavigationPackage record) {

        logger.info("createNavigationPackage");
        try {

            int updates = navigationPackageMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteNavigationPackage(NavigationPackage record) {

        logger.info("deleteNavigationPackage");
        try {

             int updates = navigationPackageMapper.delete(record);

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

        return false;
    }

    @Override
    public boolean updateNavigationPackage(NavigationPackage record) {

        logger.info("updateNavigationPackage");
        try {

            int updates = navigationPackageMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

