package com.lightinit.hsdataplatformresdir.impl;

import com.lightinit.hsdataplatformresdir.mapper.QueueserverMapper;
import com.lightinit.hsdataplatformresdir.entity.Queueserver;
import com.lightinit.hsdataplatformresdir.service.IActiveMQService;
import com.lightinit.hsdataplatformresdir.spring.DynamicDataContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * Created by Mr.Yao on 2017/12/6.
 */
@Service
public class ActiveMQServiceImpl implements IActiveMQService {
    @Autowired
    private QueueserverMapper mapper;
    @Override
    public List<Queueserver> queryServer(String keyword) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        String whereStr =null;
        if(StringUtils.isEmpty(keyword)==false) {
            whereStr = "(INSTR(servername,'"+keyword+"')>0 OR INSTR(servercode,'"+keyword+"')>0 OR INSTR(serverip,'"+keyword+"')>0)";
        }
        return mapper.selectServer(whereStr);
    }

    @Override
    public Queueserver queryServer(long id) {
        if(id<=0)
            return null;
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        return mapper.selectByPrimaryKey(id);
    }
}
