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.ThingInfo;
import com.izouma.awesomeadmin.service.ThingInfoService;
import com.izouma.awesomeadmin.dao.ThingInfoMapper;

/**
*  service接口实现类
*/
@Service
public class ThingInfoServiceImpl implements ThingInfoService{

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

    @Autowired
    private ThingInfoMapper thingInfoMapper;

    @Override
    public List<ThingInfo> getThingInfoList(ThingInfo record) {

        logger.info("getThingInfoList");
        try {

        return thingInfoMapper.queryAllThingInfo(record);
        } catch (Exception e) {
        logger.error("getThingInfoList", e);
        }

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

        logger.info("getThingInfoByPage");
        try {

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

        return thingInfoMapper.queryThingInfoByPage(parameter);
        } catch (Exception e) {
        logger.error("getThingInfoByPage", e);
        }

        return null;
    }

    @Override
    public ThingInfo getThingInfoById(String id) {

        logger.info("getThingInfoyId");
        try {

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

        return null;
    }

    @Override
    public ThingInfo getThingInfo(ThingInfo record) {

        logger.info("getThingInfo");
        try {

            return thingInfoMapper.queryThingInfo(record);
        } catch (Exception e) {
        logger.error("getThingInfo", e);
        }

        return null;
    }

    @Override
    public boolean createThingInfo(ThingInfo record) {

        logger.info("createThingInfo");
        try {

            int updates = thingInfoMapper.insertSelective(record);

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

        return false;
    }

    @Override
    public boolean deleteThingInfo(ThingInfo record) {

        logger.info("deleteThingInfo");
        try {

             int updates = thingInfoMapper.delete(record);

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

        return false;
    }

    @Override
    public boolean updateThingInfo(ThingInfo record) {

        logger.info("updateThingInfo");
        try {

            int updates = thingInfoMapper.updateByPrimaryKeySelective(record);

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

        return false;
    }
}

