change
This commit is contained in:
parent
0b5729fbf7
commit
ba22bff210
|
@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RequestMapping("/weather")
|
||||
@RestController
|
||||
|
@ -58,4 +59,9 @@ public class WeatherController {
|
|||
return weatherService.getSubTables();
|
||||
}
|
||||
|
||||
@GetMapping("/avg")
|
||||
public Map avg() {
|
||||
return weatherService.avg();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,9 +4,12 @@ import com.taosdata.example.springbootdemo.domain.Weather;
|
|||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface WeatherMapper {
|
||||
|
||||
void dropDB();
|
||||
|
||||
void createDB();
|
||||
|
||||
void createSuperTable();
|
||||
|
@ -20,4 +23,7 @@ public interface WeatherMapper {
|
|||
int count();
|
||||
|
||||
List<String> getSubTables();
|
||||
|
||||
Map avg();
|
||||
|
||||
}
|
||||
|
|
|
@ -9,16 +9,20 @@
|
|||
<result column="humidity" jdbcType="FLOAT" property="humidity"/>
|
||||
</resultMap>
|
||||
|
||||
<update id="dropDB">
|
||||
drop database if exists test
|
||||
</update>
|
||||
|
||||
<update id="createDB">
|
||||
create database if not exists test
|
||||
</update>
|
||||
|
||||
<update id="createSuperTable">
|
||||
create table if not exists test.weather(ts timestamp, temporary float, humidity int) tags(location nchar(64), groupId int)
|
||||
create table if not exists test.weather(ts timestamp, temperature float, humidity int) tags(location nchar(64), groupId int)
|
||||
</update>
|
||||
|
||||
<update id="createTable" parameterType="com.taosdata.example.springbootdemo.domain.Weather">
|
||||
create table test.t#{groupId} using test.weather tags(#{location}, #{groupId})
|
||||
create table if not exists test.t#{groupId} using test.weather tags(#{location}, #{groupId})
|
||||
</update>
|
||||
|
||||
<select id="select" resultMap="BaseResultMap">
|
||||
|
@ -32,7 +36,7 @@
|
|||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.taosdata.example.springbootdemo.domain.Weather">
|
||||
insert into test.t#{groupId} (ts, temperature, humidity) values (#{ts}, #{temperature}, #{humidity})
|
||||
insert into test.t#{groupId} (ts, temperature, humidity) values (#{ts}, ${temperature}, ${humidity})
|
||||
</insert>
|
||||
|
||||
<select id="getSubTables">
|
||||
|
@ -43,4 +47,8 @@
|
|||
select count(*) from test.weather
|
||||
</select>
|
||||
|
||||
<select id="avg" resultType="map">
|
||||
select avg(temperature), avg(humidity)from test.weather interval(1m)
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
@Service
|
||||
|
@ -18,12 +19,14 @@ public class WeatherService {
|
|||
private String[] locations = {"北京", "上海", "广州", "深圳", "天津"};
|
||||
|
||||
public int init() {
|
||||
weatherMapper.dropDB();
|
||||
weatherMapper.createDB();
|
||||
weatherMapper.createSuperTable();
|
||||
long ts = System.currentTimeMillis();
|
||||
long thirtySec = 1000 * 30;
|
||||
int count = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Weather weather = new Weather(new Timestamp(ts + (1000 * i)), 30 * random.nextFloat(), random.nextInt(100));
|
||||
for (int i = 0; i < 20; i++) {
|
||||
Weather weather = new Weather(new Timestamp(ts + (thirtySec * i)), 30 * random.nextFloat(), random.nextInt(100));
|
||||
weather.setLocation(locations[random.nextInt(locations.length)]);
|
||||
weather.setGroupId(i % locations.length);
|
||||
weatherMapper.createTable(weather);
|
||||
|
@ -52,4 +55,7 @@ public class WeatherService {
|
|||
return weatherMapper.getSubTables();
|
||||
}
|
||||
|
||||
public Map avg() {
|
||||
return weatherMapper.avg();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
# datasource config - JDBC-JNI
|
||||
#spring.datasource.driver-class-name=com.taosdata.jdbc.TSDBDriver
|
||||
#spring.datasource.url=jdbc:TAOS://127.0.0.1:6030/test?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
|
||||
#spring.datasource.username=root
|
||||
#spring.datasource.password=taosdata
|
||||
|
||||
# datasource config - JDBC-RESTful
|
||||
spring.datasource.driver-class-name=com.taosdata.jdbc.rs.RestfulDriver
|
||||
spring.datasource.url=jdbc:TAOS-RS://master:6041/test?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
|
||||
spring.datasource.driver-class-name=com.taosdata.jdbc.TSDBDriver
|
||||
spring.datasource.url=jdbc:TAOS://127.0.0.1:6030/test?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=taosdata
|
||||
|
||||
# datasource config - JDBC-RESTful
|
||||
#spring.datasource.driver-class-name=com.taosdata.jdbc.rs.RestfulDriver
|
||||
#spring.datasource.url=jdbc:TAOS-RS://master:6041/test?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
|
||||
#spring.datasource.username=root
|
||||
#spring.datasource.password=taosdata
|
||||
|
||||
spring.datasource.druid.initial-size=5
|
||||
spring.datasource.druid.min-idle=5
|
||||
spring.datasource.druid.max-active=5
|
||||
|
|
Loading…
Reference in New Issue