Skip to content

Commit

Permalink
[add] table export debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Oct 13, 2022
1 parent 9c4b51d commit 3f0869c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions studio/studio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package studio

// Yao Studio
12 changes: 12 additions & 0 deletions table/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"time"

jsoniter "github.com/json-iterator/go"
"github.com/yaoapp/gou"
"github.com/yaoapp/kun/any"
"github.com/yaoapp/kun/log"
Expand Down Expand Up @@ -344,6 +345,7 @@ func ProcessSelect(process *gou.Process) interface{} {
// Export query result to Excel
func ProcessExport(process *gou.Process) interface{} {

debug := os.Getenv("YAO_EXPORT_DEBUG") != ""
process.ValidateArgNums(1)
name := process.ArgsString(0)
table := Select(name)
Expand Down Expand Up @@ -372,6 +374,11 @@ func ProcessExport(process *gou.Process) interface{} {
pagesize = process.ArgsInt(3, api.DefaultInt(1))
}

if debug {
bytes, _ := jsoniter.Marshal(param)
log.Info("[Export] %s %s %d %d Params: %s", api.Process, filename, page, pagesize, string(bytes))
}

// 查询数据
response := gou.NewProcess(api.Process, param, page, pagesize).
WithGlobal(process.Global).
Expand All @@ -381,6 +388,11 @@ func ProcessExport(process *gou.Process) interface{} {
// After Hook
response = table.After(table.Hooks.AfterSearch, response, []interface{}{param, page, pagesize}, process.Sid)

if debug {
bytes, _ := jsoniter.Marshal(response)
log.Info("[Export] %s %d %d Prepare: %s", filename, page, pagesize, string(bytes))
}

res, ok := response.(map[string]interface{})
if !ok {
res, ok = response.(maps.MapStrAny)
Expand Down
3 changes: 1 addition & 2 deletions table/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/yaoapp/gou"
"github.com/yaoapp/kun/any"
"github.com/yaoapp/kun/maps"
"github.com/yaoapp/kun/utils"
"github.com/yaoapp/xun/capsule"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/flow"
Expand Down Expand Up @@ -58,7 +57,7 @@ func TestTableProcessSearchWithHook(t *testing.T) {

args := []interface{}{"hooks.search"}
response := gou.NewProcess("xiang.table.Search", args...).Run()
utils.Dump(response)
// utils.Dump(response)

assert.NotNil(t, response)
res := any.Of(response).Map()
Expand Down
13 changes: 13 additions & 0 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/gin-gonic/gin"
jsoniter "github.com/json-iterator/go"
"github.com/xuri/excelize/v2"
"github.com/yaoapp/gou"
"github.com/yaoapp/gou/helper"
Expand Down Expand Up @@ -350,6 +351,13 @@ func (table *Table) loadColumns() {
// Export Export query result to Excel
func (table *Table) Export(filename string, data interface{}, page int, chunkSize int) error {

debug := os.Getenv("YAO_EXPORT_DEBUG") != ""

if debug {
bytes, _ := jsoniter.Marshal(data)
log.Info("[Export] %s %d %d Before: %s", filename, page, chunkSize, string(bytes))
}

rows := []maps.MapStr{}
if values, ok := data.([]maps.MapStrAny); ok {
for _, row := range values {
Expand All @@ -365,6 +373,11 @@ func (table *Table) Export(filename string, data interface{}, page int, chunkSiz
}
}

if debug {
bytes, _ := jsoniter.Marshal(rows)
log.Info("[Export] %s %d %d After: %s", filename, page, chunkSize, string(bytes))
}

columns, err := table.exportSetting()
if err != nil {
return err
Expand Down

0 comments on commit 3f0869c

Please sign in to comment.