change
This commit is contained in:
parent
04f06f9d4d
commit
2a683c5b9c
|
@ -20,7 +20,7 @@ public class WeatherController {
|
|||
* @return
|
||||
*/
|
||||
@GetMapping("/init")
|
||||
public boolean init() {
|
||||
public int init() {
|
||||
return weatherService.init();
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class WeatherController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("/{temperature}/{humidity}")
|
||||
public int saveWeather(@PathVariable int temperature, @PathVariable float humidity) {
|
||||
public int saveWeather(@PathVariable float temperature, @PathVariable int humidity) {
|
||||
return weatherService.save(temperature, humidity);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,15 +7,17 @@ import java.util.List;
|
|||
|
||||
public interface WeatherMapper {
|
||||
|
||||
int insert(Weather weather);
|
||||
void createDB();
|
||||
|
||||
int batchInsert(List<Weather> weatherList);
|
||||
void createSuperTable();
|
||||
|
||||
void createTable();
|
||||
|
||||
List<Weather> select(@Param("limit") Long limit, @Param("offset") Long offset);
|
||||
|
||||
void createDB();
|
||||
int insert(Weather weather);
|
||||
|
||||
void createTable();
|
||||
int batchInsert(List<Weather> weatherList);
|
||||
|
||||
int count();
|
||||
|
||||
|
|
|
@ -13,19 +13,16 @@
|
|||
create database if not exists test;
|
||||
</update>
|
||||
|
||||
<update id="createTable">
|
||||
create table if not exists test.weather(ts timestamp, temperature int, humidity float);
|
||||
<update id="createSuperTable">
|
||||
create table if not exists test.weather(ts timestamp, temporary float, humidity int) tags(location nchar(64), groupId int)
|
||||
</update>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
ts, temperature, humidity
|
||||
</sql>
|
||||
<update id="createTable" parameterType="com.taosdata.example.springbootdemo.domain.Weather">
|
||||
create table test.t#{groupId} using test.weather tags(#{location}, #{groupId})
|
||||
</update>
|
||||
|
||||
<select id="select" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from test.weather
|
||||
order by ts desc
|
||||
select * from test.weather order by ts desc
|
||||
<if test="limit != null">
|
||||
limit #{limit,jdbcType=BIGINT}
|
||||
</if>
|
||||
|
@ -50,7 +47,7 @@
|
|||
</select>
|
||||
|
||||
<select id="count">
|
||||
select count(*) from test.weather;
|
||||
select count(*) from test.weather
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -8,10 +8,19 @@ public class Weather {
|
|||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
|
||||
private Timestamp ts;
|
||||
private float temperature;
|
||||
private int humidity;
|
||||
private String location;
|
||||
private int groupId;
|
||||
|
||||
private int temperature;
|
||||
public Weather() {
|
||||
}
|
||||
|
||||
private float humidity;
|
||||
public Weather(Timestamp ts, float temperature, int humidity) {
|
||||
this.ts = ts;
|
||||
this.temperature = temperature;
|
||||
this.humidity = humidity;
|
||||
}
|
||||
|
||||
public Timestamp getTs() {
|
||||
return ts;
|
||||
|
@ -21,19 +30,35 @@ public class Weather {
|
|||
this.ts = ts;
|
||||
}
|
||||
|
||||
public int getTemperature() {
|
||||
public float getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
public void setTemperature(int temperature) {
|
||||
public void setTemperature(float temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
public float getHumidity() {
|
||||
public int getHumidity() {
|
||||
return humidity;
|
||||
}
|
||||
|
||||
public void setHumidity(float humidity) {
|
||||
public void setHumidity(int humidity) {
|
||||
this.humidity = humidity;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public int getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(int groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,25 +5,34 @@ import com.taosdata.example.springbootdemo.domain.Weather;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@Service
|
||||
public class WeatherService {
|
||||
|
||||
@Autowired
|
||||
private WeatherMapper weatherMapper;
|
||||
private Random random = new Random(System.currentTimeMillis());
|
||||
|
||||
public boolean init() {
|
||||
public int init() {
|
||||
weatherMapper.createDB();
|
||||
weatherMapper.createSuperTable();
|
||||
weatherMapper.createTable();
|
||||
return true;
|
||||
long ts = System.currentTimeMillis();
|
||||
int count = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
count += weatherMapper.insert(new Weather(new Timestamp(ts + (1000 * i)), 30 * random.nextFloat(), random.nextInt(100)));
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public List<Weather> query(Long limit, Long offset) {
|
||||
return weatherMapper.select(limit, offset);
|
||||
}
|
||||
|
||||
public int save(int temperature, float humidity) {
|
||||
public int save(float temperature, int humidity) {
|
||||
Weather weather = new Weather();
|
||||
weather.setTemperature(temperature);
|
||||
weather.setHumidity(humidity);
|
||||
|
|
Loading…
Reference in New Issue