package com.yuchen.saas.park.service.pull.property.device;

import com.yuchen.saas.device.api.dto.irrigate.SaasHandleAutoIrrigationDTO;
import com.yuchen.saas.device.api.feign.IrrigateFeign;
import com.yuchen.saas.park.api.entity.device.PmgBatSmartEquipment;
import com.yuchen.saas.park.api.vo.fault.DeviceProperty;
import com.yuchen.saas.park.api.vo.park.devicepro.SoilHumidityDevicePro;
import com.yuchen.saas.park.service.pull.property.template.DeviceHandleBasePropertyValue;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.tool.utils.SpringUtil;

/**
 * @Author: 肖润飞
 * @CreateTime: 2022/10/01 10:25
 * @Description:  土壤温湿度传感器 ,基于设备的属性值进行处理
 * @Version: 1.0
 */
@Slf4j
public class SoilHumidityHandleImpl implements DeviceHandleBasePropertyValue {

    /**
     * 注入灌溉相关操作
     */
    private static IrrigateFeign irrigateFeign;

    static {
        //从 spring容器中获得指定的bean数据
        irrigateFeign = SpringUtil.getBean(IrrigateFeign.class);
    }

    @Override
    public boolean doHandle(DeviceProperty deviceProperty, PmgBatSmartEquipment deviceInfo) {
        if (SoilHumidityDevicePro.CHECK_ATTRIBUTE_HUMIDITY.equals(deviceProperty.getIdentify())){
            SaasHandleAutoIrrigationDTO handleAutoIrrigationDTO = new SaasHandleAutoIrrigationDTO();
            handleAutoIrrigationDTO.setProductKey(deviceProperty.getProductKey());
            handleAutoIrrigationDTO.setDeviceName(deviceProperty.getDeviceName());
            handleAutoIrrigationDTO.setHumidity( Float.valueOf(deviceProperty.getValue().toString()));
            Boolean handleAutoIrrigationRet = irrigateFeign.handleAutoIrrigation(handleAutoIrrigationDTO).getData();
            log.info("handleAutoIrrigationRet: {}", handleAutoIrrigationRet);
           return handleAutoIrrigationRet;
        }
        return true;
    }


}