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.ServiceType;
import com.izouma.awesomeadmin.service.ServiceTypeService;
import com.izouma.awesomeadmin.dao.ServiceTypeMapper;

/**
 * service接口实现类
 */
@Service
public class ServiceTypeServiceImpl implements ServiceTypeService {

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

    @Autowired
    private ServiceTypeMapper serviceTypeMapper;

    @Override
    public List<ServiceType> getServiceTypeList(ServiceType record) {

        logger.info("getServiceTypeList");
        try {

            return serviceTypeMapper.queryAllServiceType(record);
        } catch (Exception e) {
            logger.error("getServiceTypeList", e);
        }

        return null;
    }

    @Override
    public List<ServiceType> getServiceTypeListForHome(ServiceType record) {

        logger.info("getServiceTypeListForHome");
        try {

            return serviceTypeMapper.queryAllServiceTypeForHome(record);
        } catch (Exception e) {
            logger.error("getServiceTypeListForHome", e);
        }

        return null;
    }

    @Override
    public List<ServiceType> getServiceTypeByPage(Page page, ServiceType record) {

        logger.info("getServiceTypeByPage");
        try {

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

            return serviceTypeMapper.queryServiceTypeByPage(parameter);
        } catch (Exception e) {
            logger.error("getServiceTypeByPage", e);
        }

        return null;
    }

    @Override
    public ServiceType getServiceTypeById(String id) {

        logger.info("getServiceTypeyId");
        try {

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

        return null;
    }

    @Override
    public ServiceType getServiceType(ServiceType record) {

        logger.info("getServiceType");
        try {

            return serviceTypeMapper.queryServiceType(record);
        } catch (Exception e) {
            logger.error("getServiceType", e);
        }

        return null;
    }

    @Override
    public boolean createServiceType(ServiceType record) {

        logger.info("createServiceType");
        try {

            int updates = serviceTypeMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteServiceType(String id) {

        logger.info("deleteServiceType");
        try {

            int updates = serviceTypeMapper.delete(id);

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

        return false;
    }

    @Override
    public boolean updateServiceType(ServiceType record) {

        logger.info("updateServiceType");
        try {

            int updates = serviceTypeMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

