package com.muyu.processing.controller;

import com.muyu.processing.config.IotDBConfig;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * iotdb测试
 * @Author：杨鹏
 * @Package：com.muyu.processing.controller
 * @Project：car-cloud-server
 * @name：IotdbController
 * @Date：2024/10/2 9:39
 */
@RestController
@RequestMapping("iotdb")
public class IotDbController {

    @Resource
    private IotDBConfig iotDBConfig;

    private String json = "{\n" + " \"carVin\": \"VIN123456\",\n" +
                            " \"carName\": \"宝马\",\n" + "}";

    /**
     * 添加数据
     */
    @GetMapping("add")
    public void add(){
//        Map map = JSON.parseObject(json, Map.class);
//        Set set = map.keySet();
        ArrayList<String> key = new ArrayList<>();
        ArrayList<String> value = new ArrayList<>();
        key.add("car_vin");
        key.add("car_name");
        value.add("VIN123456");
        value.add("宝马");
        System.out.println(key);
        System.out.println(value);
        long l = System.currentTimeMillis();
        iotDBConfig.execute("root.vehicle", l, key, value);
    }

    /**
     * 查询列表
     */
    @GetMapping("findList")
    public void findList(){
        String sql = "select * from root.vehicle";
        List<HashMap<String, Object>> list = iotDBConfig.executeQuery(sql);
        System.out.println(list);
    }
}
