package com.chinaitop.depot.intelligent.ventilation.service.impl;

import com.chinaitop.depot.intelligent.ventilation.mapper.TCtldevinfoBypeMapper;
import com.chinaitop.depot.intelligent.ventilation.model.TCtldevinfoBype;
import com.chinaitop.depot.intelligent.ventilation.model.TCtldevinfoBypeExample;
import com.chinaitop.depot.intelligent.ventilation.service.AerationBypeService;
import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class AerationBypeServiceImpl implements AerationBypeService {

//    Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private TCtldevinfoBypeMapper bypeMapper;

    @Override
    public Map<Integer, String> getUpOrDownList(String type) {
        Map<Integer, String> returnMap = null;
        TCtldevinfoBypeExample bypeExample = new TCtldevinfoBypeExample();
        TCtldevinfoBypeExample.Criteria criteria = bypeExample.createCriteria();
        if (StringUtils.isNotEmpty(type)) {
            criteria.andUpOrDownEqualTo(Integer.valueOf(type));
        }
        List<TCtldevinfoBype> tCtldevinfoBypes = bypeMapper.selectByExample(bypeExample);
        if (tCtldevinfoBypes.size() > 0) {
            returnMap = Maps.newHashMap();
            for (TCtldevinfoBype bype : tCtldevinfoBypes) {
                returnMap.put(bype.getTcCode(), bype.getTcName());
            }
        }
        return returnMap;
    }

    @Override
    public TCtldevinfoBype getByte(Integer tcCode) {
        TCtldevinfoBype tCtldevinfoBype = null;
        TCtldevinfoBypeExample bypeExample = new TCtldevinfoBypeExample();
        TCtldevinfoBypeExample.Criteria criteria = bypeExample.createCriteria();
        if (tcCode != null) {
            criteria.andTcCodeEqualTo(tcCode);
            List<TCtldevinfoBype> tCtldevinfoBypes = bypeMapper.selectByExample(bypeExample);
            if (tCtldevinfoBypes.size() > 0) {
                tCtldevinfoBype = tCtldevinfoBypes.get(0);
            }
        }
        return tCtldevinfoBype;
    }
}
