package com.muyu.data.processing.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.rabbit.config.RabbitmqConfig;
import com.muyu.data.processing.service.DataProcessingService;

import javax.annotation.Resource;

import lombok.NonNull;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;

/**
 * 数据处理控制层
 *
 * @Author: 胡杨
 * @Name: DataProcessing
 * @Description: 数据处理控制层
 * @CreatedDate: 2024/9/28 下午3:53
 * @FilePath: com.muyu.data.processing.controller
 */

@Slf4j
@RestController
@RequestMapping("/DataProcessing")
public class DataProcessingController {
    @Resource
    private DataProcessingService service;
    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 车辆上线测试
     * @param vin 车辆VIN码
     */
    @GetMapping("/goOnline")
    public void goOnline(@RequestParam("vin") String vin) {
        rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS_INFORM, "inform.email", vin);
        log.info("车辆 {} 上线测试消息发送成功...",vin);
    }

    /**
     * 车辆下线测试
     * @param vin 车辆VIN码
     */
    @GetMapping("/downline")
    public void downline(@RequestParam("vin") String vin) {
        rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS_INFORM, "inform.send", vin);
        log.info("车辆 {} 下线测试消息发送成功...",vin);
    }

    /**
     * 车辆实时数据订阅开关
     * @param vin 车辆vin码
     * @param status 开关状态
     * @return 返回结果
     */
    @GetMapping("/carRealTimeStatus")
    public Result<String> carRealTimeStatus(@RequestParam("vin") @NonNull String vin, @RequestParam("status") @NonNull Boolean status) {
        return Result.success(service.carRealTimeStatus(vin, status));
    }
}
