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