package com.casic.missiles.modular.system.rs;

import com.casic.missiles.modular.system.dto.CommConfigDTO;
import com.casic.missiles.core.util.SpringContextHolder;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by lenovo on 2018/1/9.
 */
public class LiquidRequest extends AbstractRequest {

    private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());

    @Override
    public void send(String devCode, String content, String attemptsMax) {

        RedisCommon  redisCommon =SpringContextHolder.getBean("redisCommon");
        CommConfigDTO commConfigDTO = new CommConfigDTO();
        commConfigDTO.setThresh(StringUtils.isNotBlank(content.split(",")[0])?
                Float.valueOf(content.split(",")[0]):null);
        commConfigDTO.setHeight(Float.valueOf(content.split(",")[1]));
        commConfigDTO.setRepeat(Long.valueOf(content.split(",")[2]));
        if(StringUtils.isNotBlank(content.split(",", 6)[4]))
        commConfigDTO.setIp(content.split(",", 6)[4]);
        if(StringUtils.isNotBlank(content.split(",",6)[5]))
        commConfigDTO.setPort(Long.valueOf(content.split(",", 6)[5]));
        redisCommon.setRedisConfig(devCode, commConfigDTO);
        if (/*"1".equals(this.getNetType()) &&*/ StringUtils.isNotBlank(getConcentratorCode()))
            redisCommon.setRedisConcentrator(getConcentratorCode(), devCode, attemptsMax);
    }

}
