package com.sckw.slope.detection.service;

import com.alibaba.fastjson2.JSONObject;
import com.sckw.slope.detection.dao.tdengine.DevicesMapper;
import com.sckw.slope.detection.dao.tdengine.InsTablesMapper;
import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
import com.sckw.slope.detection.model.dos.tdengine.Devices;
import com.sckw.slope.detection.model.dos.tdengine.InsTables;
import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
import com.sckw.slope.detection.model.vo.SlopeDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author lfdc
 * @description
 * @date 2023-10-25 09:10:15
 */
@Service
public class TdengineService {
    @Autowired
    SlopeDataMapper slopeDataMapper;

    @Autowired
    InsTablesMapper insTablesMapper;

    @Autowired
     DevicesMapper devicesMapper;

    public void tdengineDemo() {
        List<SlopeDataVo> list = slopeDataMapper.selectAll("6", "7");
        System.out.println(JSONObject.toJSONString(list));
        List<SlopeDataVo> list1 = slopeDataMapper.selectList();
        System.out.println(JSONObject.toJSONString(list1));
        SlopeData data = new SlopeData();
        Date now = new Date();
        data.setTs(now);
        data.setRawId(now);
        data.setTslverId(1);
        data.setGuid("1");
        data.setLine("2");
        data.setVal("3");
        data.setMsgId("4");
        data.setVin("6");
        data.setSerialNumber("7");
        data.setTagsTitle("name");
        data.setTags("sss");
        data.setCreateTime(new Date());
        int insert = slopeDataMapper.insertData(data);
    }

    public Devices selectLastData(String deviceCode) {
//        SlopeData slopeData = slopeDataMapper.selectLastData(deviceCode);
        Devices devices = devicesMapper.selectLastData(deviceCode);
        return devices;
    }

    public void getTable() {
        String tableName = "devicesv26_7";
        InsTables insTables = insTablesMapper.selectTableIsExit(tableName);
        if (insTables != null) {
        }
    }

    public void createTable() {
        String tableName = "devicesv220231108";
        insTablesMapper.createTable(tableName);
    }
}
