fix: parameter of exportTable to CSV file
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"be.ems/lib/core/datasource"
|
||||
"be.ems/lib/log"
|
||||
"be.ems/src/framework/cron"
|
||||
)
|
||||
|
||||
@@ -26,13 +27,13 @@ type BarProcessor struct {
|
||||
}
|
||||
|
||||
type BarParams struct {
|
||||
Duration int `json:"duration"`
|
||||
TableName string `json:"tableName"`
|
||||
TimeCol string `json:"timeCol"` // time stamp of column name
|
||||
TimeUnit string `json:"timeUnit"` // timestamp unit: second/micro/milli
|
||||
ExportCols string `json:"exportCols"` // exported column name of time string
|
||||
Extras string `json:"extras"` // extras condition for where
|
||||
FilePath string `json:"filePath"` // file path
|
||||
Duration int `json:"duration"`
|
||||
TableName string `json:"tableName"`
|
||||
Columns string `json:"columns"` // exported column name of time string
|
||||
TimeCol string `json:"timeCol"` // time stamp of column name
|
||||
TimeUnit string `json:"timeUnit"` // timestamp unit: second/micro/milli
|
||||
Extras string `json:"extras"` // extras condition for where
|
||||
FilePath string `json:"filePath"` // file path
|
||||
}
|
||||
|
||||
func (s *BarProcessor) Execute(data any) (any, error) {
|
||||
@@ -64,12 +65,13 @@ func (s *BarProcessor) Execute(data any) (any, error) {
|
||||
var query string
|
||||
if params.Extras != "" {
|
||||
query = fmt.Sprintf("SELECT %s FROM `%s` WHERE `%s` >= UNIX_TIMESTAMP(NOW() - INTERVAL 2*%d HOUR) * %d AND `%s` < UNIX_TIMESTAMP(NOW() - INTERVAL %d HOUR) * %d AND %s",
|
||||
params.ExportCols, params.TableName, params.TimeCol, params.Duration, unitNum, params.TimeCol, params.Duration, unitNum, params.Extras)
|
||||
params.Columns, params.TableName, params.TimeCol, params.Duration, unitNum, params.TimeCol, params.Duration, unitNum, params.Extras)
|
||||
} else {
|
||||
query = fmt.Sprintf("SELECT %s FROM `%s` WHERE `%s` >= UNIX_TIMESTAMP(NOW() - INTERVAL 2*%d HOUR) * %d AND `%s` < UNIX_TIMESTAMP(NOW() - INTERVAL %d HOUR) * %d",
|
||||
params.ExportCols, params.TableName, params.TimeCol, params.Duration, unitNum, params.TimeCol, params.Duration, unitNum)
|
||||
params.Columns, params.TableName, params.TimeCol, params.Duration, unitNum, params.TimeCol, params.Duration, unitNum)
|
||||
}
|
||||
|
||||
log.Trace("query:", query)
|
||||
//filePath := fmt.Sprintf("%s/%s_export_%s.csv", params.FilePath, params.TableName, time.Now().Format("20060102150405"))
|
||||
filePath := fmt.Sprintf("%s/%s_export_%s.csv", params.FilePath, params.TableName, time.Now().Format("20060102150405"))
|
||||
affected, err := s.exportData(query, filePath)
|
||||
|
||||
Reference in New Issue
Block a user