package com.fuyuanshen.global.mqtt.rule.bjq;

import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
import com.fuyuanshen.global.mqtt.config.MqttGateway;
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.time.Duration;

import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;

/**
 * 定位数据命令处理
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class BjqPersonnelInfoDataRule implements MqttMessageRule {
    
    private final MqttGateway mqttGateway;


    @Override
    public String getCommandType() {
        return LightingCommandTypeConstants.PERSONNEL_INFO;
    }

    @Override
    public void execute(MqttRuleContext context) {
        String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();
        try {
//            Object[] convertArr = context.getConvertArr();
//            RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(30));
        } catch (Exception e) {
            log.error("处理定位数据命令时出错", e);
            RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(30));
        }
    }

}
