package com.yuchen.saas.park.service.iot.input;

import com.alibaba.fastjson.JSONObject;
import com.yuchen.saas.park.api.vo.fault.DeviceProperty;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.redis.cache.NestRedis;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Slf4j
@Service
public class ParkDevicePropertyInput {

    @Resource
    private NestRedis nestRedis;

    /**
     * 处理 IOT平台推送的属性数据
     *
     * @param deviceProperty 入参
     */
    @Async
    public void inputData(DeviceProperty deviceProperty) {
        // 获取设备的 productKey 和 deviceName
        String productKey = deviceProperty.getProductKey();
        String deviceName = deviceProperty.getDeviceName();
        log.info("productKey：{}", productKey);
        log.info("deviceName：{}", deviceName);
        // 缓存设备最新属性信息
        nestRedis.set("deviceName:identify:" + deviceProperty.getDeviceName() + ":" + deviceProperty.getIdentify(), JSONObject.toJSONString(deviceProperty));
        log.info("deviceName:identify:" + deviceProperty.getDeviceName() + ":" + deviceProperty.getIdentify() + ":{}", (Object) nestRedis.get("deviceName:identify:" + deviceProperty.getDeviceName() + ":" + deviceProperty.getIdentify()));
        // 可以存库，需要更换其他sql存储
    }
}