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.CompanyInfo;
import com.izouma.awesomeadmin.service.CompanyInfoService;
import com.izouma.awesomeadmin.dao.CompanyInfoMapper;

/**
*  service接口实现类
*/
@Service
public class CompanyInfoServiceImpl implements CompanyInfoService{

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

    @Autowired
    private CompanyInfoMapper companyInfoMapper;

    @Override
    public List<CompanyInfo> getCompanyInfoList(CompanyInfo record) {

        logger.info("getCompanyInfoList");
        try {

        return companyInfoMapper.queryAllCompanyInfo(record);
        } catch (Exception e) {
        logger.error("getCompanyInfoList", e);
        }

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

        logger.info("getCompanyInfoByPage");
        try {

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

        return companyInfoMapper.queryCompanyInfoByPage(parameter);
        } catch (Exception e) {
        logger.error("getCompanyInfoByPage", e);
        }

        return null;
    }

    @Override
    public CompanyInfo getCompanyInfoById(String id) {

        logger.info("getCompanyInfoyId");
        try {

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

        return null;
    }

    @Override
    public CompanyInfo getCompanyInfo(CompanyInfo record) {

        logger.info("getCompanyInfo");
        try {

            return companyInfoMapper.queryCompanyInfo(record);
        } catch (Exception e) {
        logger.error("getCompanyInfo", e);
        }

        return null;
    }

    @Override
    public boolean createCompanyInfo(CompanyInfo record) {

        logger.info("createCompanyInfo");
        try {

            int updates = companyInfoMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteCompanyInfo(String id) {

        logger.info("deleteCompanyInfo");
        try {

             int updates = companyInfoMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateCompanyInfo(CompanyInfo record) {

        logger.info("updateCompanyInfo");
        try {

            int updates = companyInfoMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

