Merge pull request #195 from trheyi/main

[add] table export debug log
This commit is contained in:
Max 2022-10-13 10:15:50 +08:00 committed by GitHub
commit e840dc2d87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 2 deletions

3
studio/studio.go Normal file
View file

@ -0,0 +1,3 @@
package studio
// Yao Studio

View file

@ -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"
@ -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)
@ -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).
@ -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)

View file

@ -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"
@ -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()

View file

@ -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"
@ -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 {
@ -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