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.CompanyType;
import com.izouma.awesomeadmin.service.CompanyTypeService;
import com.izouma.awesomeadmin.dao.CompanyTypeMapper;

/**
*  service接口实现类
*/
@Service
public class CompanyTypeServiceImpl implements CompanyTypeService{

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

    @Autowired
    private CompanyTypeMapper companyTypeMapper;

    @Override
    public List<CompanyType> getCompanyTypeList(CompanyType record) {

        logger.info("getCompanyTypeList");
        try {

        return companyTypeMapper.queryAllCompanyType(record);
        } catch (Exception e) {
        logger.error("getCompanyTypeList", e);
        }

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

        logger.info("getCompanyTypeByPage");
        try {

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

        return companyTypeMapper.queryCompanyTypeByPage(parameter);
        } catch (Exception e) {
        logger.error("getCompanyTypeByPage", e);
        }

        return null;
    }

    @Override
    public CompanyType getCompanyTypeById(String id) {

        logger.info("getCompanyTypeyId");
        try {

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

        return null;
    }

    @Override
    public CompanyType getCompanyType(CompanyType record) {

        logger.info("getCompanyType");
        try {

            return companyTypeMapper.queryCompanyType(record);
        } catch (Exception e) {
        logger.error("getCompanyType", e);
        }

        return null;
    }

    @Override
    public boolean createCompanyType(CompanyType record) {

        logger.info("createCompanyType");
        try {

            int updates = companyTypeMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteCompanyType(String id) {

        logger.info("deleteCompanyType");
        try {

             int updates = companyTypeMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateCompanyType(CompanyType record) {

        logger.info("updateCompanyType");
        try {

            int updates = companyTypeMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

