取消限制
This commit is contained in:
parent
ee338d2a09
commit
49aee3a2ed
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
9
.idea/angle_dtu.iml
generated
Normal file
9
.idea/angle_dtu.iml
generated
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/angle_dtu.iml" filepath="$PROJECT_DIR$/.idea/angle_dtu.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
141
http_server.go
141
http_server.go
@ -4,12 +4,12 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"time"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 启动HTTP服务器
|
// 启动HTTP服务器
|
||||||
@ -55,76 +55,87 @@ func handleIndex(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// 处理获取传感器数据的API
|
// 处理获取传感器数据的API
|
||||||
func handleGetData(w http.ResponseWriter, r *http.Request) {
|
func handleGetData(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Printf("接收到获取数据请求: %s", r.URL.String())
|
log.Printf("接收到获取数据请求: %s", r.URL.String())
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
sensorIDStr := r.URL.Query().Get("sensor_id")
|
sensorIDStr := r.URL.Query().Get("sensor_id")
|
||||||
limitStr := r.URL.Query().Get("limit")
|
limitStr := r.URL.Query().Get("limit")
|
||||||
startDateStr := r.URL.Query().Get("start_date")
|
startDateStr := r.URL.Query().Get("start_date")
|
||||||
endDateStr := r.URL.Query().Get("end_date")
|
endDateStr := r.URL.Query().Get("end_date")
|
||||||
|
|
||||||
limit := 500
|
limit := 500 // 默认限制为500条数据
|
||||||
|
noLimit := false // 是否不限制数据条数
|
||||||
|
|
||||||
var sensorID int
|
var sensorID int
|
||||||
var err error
|
var err error
|
||||||
if sensorIDStr != "" && sensorIDStr != "all" {
|
if sensorIDStr != "" && sensorIDStr != "all" {
|
||||||
sensorID, err = strconv.Atoi(sensorIDStr)
|
sensorID, err = strconv.Atoi(sensorIDStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("错误: 无效的传感器ID: %s", sensorIDStr)
|
log.Printf("错误: 无效的传感器ID: %s", sensorIDStr)
|
||||||
http.Error(w, "无效的传感器ID", http.StatusBadRequest)
|
http.Error(w, "无效的传感器ID", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if limitStr != "" {
|
if limitStr != "" {
|
||||||
limit, err = strconv.Atoi(limitStr)
|
if limitStr == "all" {
|
||||||
if err != nil || limit <= 0 {
|
noLimit = true
|
||||||
log.Printf("错误: 无效的记录数限制: %s", limitStr)
|
limit = 1000000 // 使用一个非常大的数值作为实际上的"无限制"
|
||||||
http.Error(w, "无效的记录数限制", http.StatusBadRequest)
|
} else {
|
||||||
return
|
limit, err = strconv.Atoi(limitStr)
|
||||||
}
|
if err != nil || limit <= 0 {
|
||||||
}
|
log.Printf("错误: 无效的记录数限制: %s", limitStr)
|
||||||
|
http.Error(w, "无效的记录数限制", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var startDate, endDate time.Time
|
var startDate, endDate time.Time
|
||||||
if startDateStr != "" {
|
if startDateStr != "" {
|
||||||
startDate, err = time.Parse("2006-01-02T15:04", startDateStr)
|
startDate, err = time.Parse("2006-01-02T15:04", startDateStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("错误: 无效的开始日期: %s, %v", startDateStr, err)
|
log.Printf("错误: 无效的开始日期: %s, %v", startDateStr, err)
|
||||||
http.Error(w, "无效的开始日期", http.StatusBadRequest)
|
http.Error(w, "无效的开始日期", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if endDateStr != "" {
|
if endDateStr != "" {
|
||||||
endDate, err = time.Parse("2006-01-02T15:04", endDateStr)
|
endDate, err = time.Parse("2006-01-02T15:04", endDateStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("错误: 无效的结束日期: %s, %v", endDateStr, err)
|
log.Printf("错误: 无效的结束日期: %s, %v", endDateStr, err)
|
||||||
http.Error(w, "无效的结束日期", http.StatusBadRequest)
|
http.Error(w, "无效的结束日期", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var data []SensorData
|
var data []SensorData
|
||||||
if sensorIDStr == "all" || sensorIDStr == "" {
|
if sensorIDStr == "all" || sensorIDStr == "" {
|
||||||
data, err = GetAllSensorData(limit, startDate, endDate)
|
data, err = GetAllSensorData(limit, startDate, endDate)
|
||||||
} else {
|
} else {
|
||||||
data, err = GetSensorData(sensorID, limit, startDate, endDate)
|
data, err = GetSensorData(sensorID, limit, startDate, endDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("错误: 获取数据失败: %v", err)
|
log.Printf("错误: 获取数据失败: %v", err)
|
||||||
http.Error(w, "获取数据失败:"+err.Error(), http.StatusInternalServerError)
|
http.Error(w, "获取数据失败:"+err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("成功获取到 %d 条数据记录", len(data))
|
if noLimit {
|
||||||
|
log.Printf("成功获取到所有数据记录(%d条)", len(data))
|
||||||
|
} else {
|
||||||
|
log.Printf("成功获取到 %d 条数据记录(限制:%d条)", len(data), limit)
|
||||||
|
}
|
||||||
|
|
||||||
if err := json.NewEncoder(w).Encode(data); err != nil {
|
if err := json.NewEncoder(w).Encode(data); err != nil {
|
||||||
log.Printf("错误: 编码JSON失败: %v", err)
|
log.Printf("错误: 编码JSON失败: %v", err)
|
||||||
http.Error(w, "编码JSON失败:"+err.Error(), http.StatusInternalServerError)
|
http.Error(w, "编码JSON失败:"+err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理获取所有传感器ID的API
|
// 处理获取所有传感器ID的API
|
||||||
func handleGetSensors(w http.ResponseWriter, r *http.Request) {
|
func handleGetSensors(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Printf("接收到获取传感器列表请求")
|
log.Printf("接收到获取传感器列表请求")
|
||||||
@ -146,12 +157,12 @@ func handleGetSensors(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
func handleGetClients(w http.ResponseWriter, r *http.Request) {
|
func handleGetClients(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
clients := getAllClients()
|
clients := getAllClients()
|
||||||
|
|
||||||
if err := json.NewEncoder(w).Encode(clients); err != nil {
|
if err := json.NewEncoder(w).Encode(clients); err != nil {
|
||||||
log.Printf("错误: 编码客户端信息JSON失败: %v", err)
|
log.Printf("错误: 编码客户端信息JSON失败: %v", err)
|
||||||
http.Error(w, "编码JSON失败:"+err.Error(), http.StatusInternalServerError)
|
http.Error(w, "编码JSON失败:"+err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -159,6 +159,7 @@
|
|||||||
<option value="1000">1000</option>
|
<option value="1000">1000</option>
|
||||||
<option value="2000">2000</option>
|
<option value="2000">2000</option>
|
||||||
<option value="5000">5000</option>
|
<option value="5000">5000</option>
|
||||||
|
<option value="all">全部</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -328,7 +329,7 @@
|
|||||||
function resetFilters() {
|
function resetFilters() {
|
||||||
initializeDatePickers();
|
initializeDatePickers();
|
||||||
document.getElementById('sensorSelect').value = 'all';
|
document.getElementById('sensorSelect').value = 'all';
|
||||||
document.getElementById('limitSelect').value = '100';
|
document.getElementById('limitSelect').value = '500';
|
||||||
loadData();
|
loadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,7 +395,7 @@
|
|||||||
params.push(`sensor_id=${sensorID}`);
|
params.push(`sensor_id=${sensorID}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (limit) {
|
if (limit && limit !== 'all') {
|
||||||
params.push(`limit=${limit}`);
|
params.push(`limit=${limit}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user