Commit 583ff673 authored by brent's avatar brent

add time filter

parent 395b64a3
...@@ -122,10 +122,23 @@ func (server *ClientController) TasksPerDay() { ...@@ -122,10 +122,23 @@ func (server *ClientController) TasksPerDay() {
countQB.Where(fmt.Sprintf("worker_acc = '%s'", appRequest.WorkerAcc)) countQB.Where(fmt.Sprintf("worker_acc = '%s'", appRequest.WorkerAcc))
queryQB.Where(fmt.Sprintf("worker_acc = '%s'", appRequest.WorkerAcc)) queryQB.Where(fmt.Sprintf("worker_acc = '%s'", appRequest.WorkerAcc))
} }
if appRequest.ProfitAcc != "" { if appRequest.ProfitAcc != "" && appRequest.WorkerAcc == "" {
countQB.Where(fmt.Sprintf("profit_acc = '%s'", appRequest.ProfitAcc)) countQB.Where(fmt.Sprintf("profit_acc = '%s'", appRequest.ProfitAcc))
queryQB.Where(fmt.Sprintf("profit_acc = '%s'", appRequest.ProfitAcc)) queryQB.Where(fmt.Sprintf("profit_acc = '%s'", appRequest.ProfitAcc))
} }
if appRequest.ProfitAcc != "" && appRequest.WorkerAcc != "" {
countQB.And(fmt.Sprintf("profit_acc = '%s'", appRequest.ProfitAcc))
queryQB.And(fmt.Sprintf("profit_acc = '%s'", appRequest.ProfitAcc))
}
if appRequest.StartTime != "" && appRequest.EndTime != "" {
temp, _ := time.Parse(layout, appRequest.StartTime)
startTime := fmt.Sprintf(temp.Format(format))
temp, _ = time.Parse(layout, appRequest.EndTime)
endTime := fmt.Sprintf(temp.Format(format))
countQB.And(fmt.Sprintf("time >= '%s'", startTime)).And(fmt.Sprintf("time <= '%s'", endTime))
queryQB.And(fmt.Sprintf("time >= '%s'", startTime)).And(fmt.Sprintf("time <= '%s'", endTime))
}
sql := fmt.Sprintf("%s SAMPLE BY 1M ALIGN TO CALENDAR", countQB.String()) sql := fmt.Sprintf("%s SAMPLE BY 1M ALIGN TO CALENDAR", countQB.String())
sql = fmt.Sprintf("SELECT count(*) FROM (%s);", sql) sql = fmt.Sprintf("SELECT count(*) FROM (%s);", sql)
...@@ -194,6 +207,15 @@ func (server *ClientController) Tasks() { ...@@ -194,6 +207,15 @@ func (server *ClientController) Tasks() {
queryQB.Select("id", "fee", "type", "time", "exec_duration", "workload", "profit_acc", "worker_acc", "result"). queryQB.Select("id", "fee", "type", "time", "exec_duration", "workload", "profit_acc", "worker_acc", "result").
From("bills").Where(fmt.Sprintf("worker_acc = '%s'", appRequest.WorkerAcc)) From("bills").Where(fmt.Sprintf("worker_acc = '%s'", appRequest.WorkerAcc))
if appRequest.StartTime != "" && appRequest.EndTime != "" {
temp, _ := time.Parse(layout, appRequest.StartTime)
startTime := fmt.Sprintf(temp.Format(format))
temp, _ = time.Parse(layout, appRequest.EndTime)
endTime := fmt.Sprintf(temp.Format(format))
countQB.And(fmt.Sprintf("time >= '%s'", startTime)).And(fmt.Sprintf("time <= '%s'", endTime))
queryQB.And(fmt.Sprintf("time >= '%s'", startTime)).And(fmt.Sprintf("time <= '%s'", endTime))
}
sql := countQB.String() sql := countQB.String()
total, err := postgres.QueryTotal(sql) total, err := postgres.QueryTotal(sql)
if err != nil { if err != nil {
......
...@@ -96,68 +96,76 @@ func QueryTset(sql string, args ...interface{}) ([]models.Bills, error) { ...@@ -96,68 +96,76 @@ func QueryTset(sql string, args ...interface{}) ([]models.Bills, error) {
func QueryBills(sql string) ([]models.Bills, error) { func QueryBills(sql string) ([]models.Bills, error) {
logs.Debug("QueryBills = ", sql) logs.Debug("QueryBills = ", sql)
qs := ormpost.Raw(sql)
var params []orm.Params
_, err := qs.Values(&params)
if err != nil {
return nil, err
}
arr, err := json.Marshal(params)
if err != nil {
return nil, err
}
var containers []models.Bills var containers []models.Bills
logs.Debug("QueryBills = ", string(arr)) _, err := ormpost.Raw(sql).QueryRows(&containers)
err = json.Unmarshal(arr, &containers) return containers, err
if err != nil { //_ = ormpost.Raw(sql).QueryRow(&count)
return nil, err //var params []orm.Params
} //_, err := qs.Values(&params)
//if err != nil {
return containers, nil // return nil, err
//}
//arr, err := json.Marshal(params)
//if err != nil {
// return nil, err
//}
//
//logs.Debug("QueryBills = ", string(arr))
//err = json.Unmarshal(arr, &containers)
//if err != nil {
// return nil, err
//}
//
//return containers, nil
} }
func QueryFunds(sql string) ([]models.Funds, error) { func QueryFunds(sql string) ([]models.Funds, error) {
logs.Debug("QueryFunds = ", sql) logs.Debug("QueryFunds = ", sql)
qs := ormpost.Raw(sql)
var params []orm.Params
_, err := qs.Values(&params)
if err != nil {
return nil, err
}
arr, err := json.Marshal(params)
if err != nil {
return nil, err
}
var containers []models.Funds var containers []models.Funds
logs.Debug("QueryFunds = ", string(arr)) _, err := ormpost.Raw(sql).QueryRows(&containers)
err = json.Unmarshal(arr, &containers) return containers, err
if err != nil { //var params []orm.Params
return nil, err //_, err := qs.Values(&params)
} //if err != nil {
// return nil, err
return containers, nil //}
//arr, err := json.Marshal(params)
//if err != nil {
// return nil, err
//}
//var containers []models.Funds
//logs.Debug("QueryFunds = ", string(arr))
//err = json.Unmarshal(arr, &containers)
//if err != nil {
// return nil, err
//}
//
//return containers, nil
} }
func CountFunds(sql string) ([]models.IncomeAndExpenseRsponse, error) { func CountFunds(sql string) ([]models.IncomeAndExpenseRsponse, error) {
logs.Debug("CountFunds = ", sql) logs.Debug("CountFunds = ", sql)
qs := ormpost.Raw(sql)
var params []orm.Params
_, err := qs.Values(&params)
if err != nil {
return nil, err
}
arr, err := json.Marshal(params)
if err != nil {
return nil, err
}
var containers []models.IncomeAndExpenseRsponse var containers []models.IncomeAndExpenseRsponse
logs.Debug("CountFunds = ", string(arr)) _, err := ormpost.Raw(sql).QueryRows(&containers)
err = json.Unmarshal(arr, &containers) return containers, err
if err != nil { //qs := ormpost.Raw(sql)
return nil, err //var params []orm.Params
} //_, err := qs.Values(&params)
//if err != nil {
return containers, nil // return nil, err
//}
//arr, err := json.Marshal(params)
//if err != nil {
// return nil, err
//}
//var containers []models.IncomeAndExpenseRsponse
//logs.Debug("CountFunds = ", string(arr))
//err = json.Unmarshal(arr, &containers)
//if err != nil {
// return nil, err
//}
//
//return containers, nil
} }
func QueryTotal(sql string) (int64, error) { func QueryTotal(sql string) (int64, error) {
...@@ -207,21 +215,24 @@ func InsertWithSql(sql string) (int64, error) { ...@@ -207,21 +215,24 @@ func InsertWithSql(sql string) (int64, error) {
func CountTasks(sql string) ([]models.TaskCount, error) { func CountTasks(sql string) ([]models.TaskCount, error) {
logs.Debug("CountTasks = ", sql) logs.Debug("CountTasks = ", sql)
qs := ormpost.Raw(sql)
var params []orm.Params
_, err := qs.Values(&params)
if err != nil {
return nil, err
}
arr, err := json.Marshal(params)
if err != nil {
return nil, err
}
var containers []models.TaskCount var containers []models.TaskCount
err = json.Unmarshal(arr, &containers) _, err := ormpost.Raw(sql).QueryRows(&containers)
if err != nil { return containers, err
return nil, err //qs := ormpost.Raw(sql)
} //var params []orm.Params
//_, err := qs.Values(&params)
return containers, nil //if err != nil {
// return nil, err
//}
//arr, err := json.Marshal(params)
//if err != nil {
// return nil, err
//}
//var containers []models.TaskCount
//err = json.Unmarshal(arr, &containers)
//if err != nil {
// return nil, err
//}
//
//return containers, nil
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment