iot-server/bnhz-admin/src/test/java/com/bnhz/TDengineTest.java

122 lines
5.9 KiB
Java

package com.bnhz;
import com.alibaba.fastjson.JSONObject;
import com.bnhz.adapter.model.blackcar.Point;
import com.bnhz.adapter.model.fumes.FumesAlarmMsg;
import com.bnhz.adapter.util.ThingsModelUtils;
import com.bnhz.common.core.thingsModel.ThingsModelSimpleItem;
import com.bnhz.common.core.thingsModel.ThingsModelValuesInput;
import com.bnhz.common.utils.reflect.ReflectUtils;
import com.bnhz.iot.domain.ThingsModel;
import com.bnhz.iot.model.ThingsModels.ThingsModelQuery;
import com.bnhz.iot.model.dto.ColumnDto;
import com.bnhz.iot.tdengine.dao.TDDynamicDAO;
import com.bnhz.iot.tdengine.service.IColumnModeOperationsService;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author Leo
* @date 2024/6/27 11:24
*/
@ActiveProfiles("test")
@SpringBootTest
@Disabled
public class TDengineTest {
@Autowired
private IColumnModeOperationsService columnModeOperationsService;
@Autowired
private TDDynamicDAO tdDynamicDAO;
@Test
public void ddlTest() {
String json = "{\"templateId\":null,\"templateName\":\"测试DDL\",\"userId\":null,\"userName\":null,\"tenantId\":null,\"tenantName\":null,\"identifier\":\"abc\",\"modelOrder\":0,\"type\":\"3\",\"datatype\":\"object\",\"isSys\":null,\"isChart\":0,\"isHistory\":1,\"isMonitor\":0,\"isReadonly\":1,\"isSharePerm\":0,\"delFlag\":null,\"createBy\":\"admin\",\"createTime\":null,\"updateBy\":null,\"updateTime\":null,\"remark\":null,\"owner\":null,\"specs\":\"{\\\"type\\\":\\\"object\\\",\\\"params\\\":[{\\\"name\\\":\\\"二硫化碳天累计值\\\",\\\"id\\\":\\\"abc_a99051-Cou-D\\\",\\\"order\\\":1,\\\"datatype\\\":{\\\"type\\\":\\\"decimal\\\",\\\"min\\\":0,\\\"max\\\":1000,\\\"unit\\\":\\\"毫克/立方米\\\",\\\"step\\\":1},\\\"isChart\\\":0,\\\"isHistory\\\":1,\\\"isSharePerm\\\":0,\\\"isMonitor\\\":1,\\\"isReadonly\\\":1},{\\\"name\\\":\\\"二硫化碳时累计值\\\",\\\"id\\\":\\\"abc_a99051-Cou-H\\\",\\\"order\\\":1,\\\"datatype\\\":{\\\"type\\\":\\\"decimal\\\",\\\"min\\\":0,\\\"max\\\":1000,\\\"unit\\\":\\\"毫克/立方米\\\",\\\"step\\\":1},\\\"isChart\\\":0,\\\"isHistory\\\":1,\\\"isSharePerm\\\":0,\\\"isMonitor\\\":1,\\\"isReadonly\\\":1},{\\\"name\\\":\\\"丙烯腈时累计值\\\",\\\"id\\\":\\\"abc_a99010-Cou-H\\\",\\\"order\\\":1,\\\"datatype\\\":{\\\"type\\\":\\\"decimal\\\",\\\"min\\\":0,\\\"max\\\":1000,\\\"unit\\\":\\\"毫克/立方米\\\",\\\"step\\\":1},\\\"isChart\\\":0,\\\"isHistory\\\":1,\\\"isSharePerm\\\":0,\\\"isMonitor\\\":1,\\\"isReadonly\\\":1}]}\"}";
ThingsModel thingsModel = JSONObject.parseObject(json, ThingsModel.class);
thingsModel.setProductId(1L);
thingsModel.setModelId(1000L);
columnModeOperationsService.ddl(thingsModel.getProductId(), Arrays.asList(thingsModel));
columnModeOperationsService.save(mockThingsModelValuesInput());
}
@Test
public void ddlEntityTest() throws IllegalAccessException {
Map<String, ReflectUtils.FieldInfo> allFields = ReflectUtils.getAllFields(new Point());
Long productId = 1L;
List<ThingsModel> propertyThingsModel = ThingsModelUtils.toPropertyThingsModel(allFields, productId, "测试产品2");
columnModeOperationsService.ddl(productId, propertyThingsModel);
}
@Test
public void queryTest() {
//columnModeOperationsService.save(mockThingsModelValuesInput());
ThingsModelQuery thingsModelQuery = new ThingsModelQuery();
thingsModelQuery.setType(3);
thingsModelQuery.setProductId(164L);
thingsModelQuery.setDeviceId(1L);
thingsModelQuery.setModelId(1514L);
thingsModelQuery.setStartDateTime(LocalDateTime.now().minusDays(2));
thingsModelQuery.setEndDateTime(LocalDateTime.now());
thingsModelQuery.setOrderField("create_time");
List<Map<String, Object>> query = columnModeOperationsService.query(thingsModelQuery);
System.out.println(query.size());
}
@Test
public void columnNameTest() {
Set<String> columnNames = tdDynamicDAO.queryColumnName("daqi_log", "abc");
System.out.println(columnNames);
}
@Test
public void tableNameTest() {
Set<String> tableList = tdDynamicDAO.queryTableList("daqi_log");
System.out.println(tableList);
}
@Test
public void addColumnTest() {
ColumnDto columnDto = new ColumnDto();
columnDto.setColumnName("a_b_c");
columnDto.setType("string");
tdDynamicDAO.addColumn("daqi_log", "event_999_1473", columnDto);
}
private ThingsModelValuesInput mockThingsModelValuesInput() {
ThingsModelValuesInput thingsModelValuesInput = new ThingsModelValuesInput();
thingsModelValuesInput.setDataTime(LocalDateTime.now().minusDays(1));
thingsModelValuesInput.setType(3);
thingsModelValuesInput.setProductId(1L);
thingsModelValuesInput.setDeviceId(1L);
thingsModelValuesInput.setModelId(1000L);
thingsModelValuesInput.setDeviceNumber("S001");
ThingsModelSimpleItem thingsModelSimpleItem1 = new ThingsModelSimpleItem();
thingsModelSimpleItem1.setId("a99010_cou_h");
thingsModelSimpleItem1.setValue("10.2");
ThingsModelSimpleItem thingsModelSimpleItem2 = new ThingsModelSimpleItem();
thingsModelSimpleItem2.setId("a99051_cou_d");
thingsModelSimpleItem2.setValue("10.3");
ThingsModelSimpleItem thingsModelSimpleItem3 = new ThingsModelSimpleItem();
thingsModelSimpleItem3.setId("a99051_cou_h");
thingsModelSimpleItem3.setValue("10.4");
thingsModelValuesInput.setThingsModelValueRemarkItem(Arrays.asList(thingsModelSimpleItem1, thingsModelSimpleItem2, thingsModelSimpleItem3));
return thingsModelValuesInput;
}
}