Commit 583ff673 authored by brent's avatar brent

add time filter

parent 395b64a3
......@@ -122,10 +122,23 @@ func (server *ClientController) TasksPerDay() {
countQB.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))
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("SELECT count(*) FROM (%s);", sql)
......@@ -194,6 +207,15 @@ func (server *ClientController) Tasks() {
queryQB.Select("id", "fee", "type", "time", "exec_duration", "workload", "profit_acc", "worker_acc", "result").
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()
total, err := postgres.QueryTotal(sql)
if err != nil {
......
......@@ -96,68 +96,76 @@ func QueryTset(sql string, args ...interface{}) ([]models.Bills, error) {
func QueryBills(sql string) ([]models.Bills, error) {
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
logs.Debug("QueryBills = ", string(arr))
err = json.Unmarshal(arr, &containers)
if err != nil {
return nil, err
}
return containers, nil
_, err := ormpost.Raw(sql).QueryRows(&containers)
return containers, err
//_ = ormpost.Raw(sql).QueryRow(&count)
//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
//}
//
//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) {
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
logs.Debug("QueryFunds = ", string(arr))
err = json.Unmarshal(arr, &containers)
if err != nil {
return nil, err
}
return containers, nil
_, err := ormpost.Raw(sql).QueryRows(&containers)
return containers, err
//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
//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) {
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
logs.Debug("CountFunds = ", string(arr))
err = json.Unmarshal(arr, &containers)
if err != nil {
return nil, err
}
return containers, nil
_, err := ormpost.Raw(sql).QueryRows(&containers)
return containers, err
//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
//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) {
......@@ -207,21 +215,24 @@ func InsertWithSql(sql string) (int64, error) {
func CountTasks(sql string) ([]models.TaskCount, error) {
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
err = json.Unmarshal(arr, &containers)
if err != nil {
return nil, err
}
return containers, nil
_, err := ormpost.Raw(sql).QueryRows(&containers)
return containers, err
//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
//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