commit
e840dc2d87
4 changed files with 29 additions and 2 deletions
3
studio/studio.go
Normal file
3
studio/studio.go
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
package studio
|
||||||
|
|
||||||
|
// Yao Studio
|
||||||
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/yaoapp/gou"
|
"github.com/yaoapp/gou"
|
||||||
"github.com/yaoapp/kun/any"
|
"github.com/yaoapp/kun/any"
|
||||||
"github.com/yaoapp/kun/log"
|
"github.com/yaoapp/kun/log"
|
||||||
|
|
@ -344,6 +345,7 @@ func ProcessSelect(process *gou.Process) interface{} {
|
||||||
// Export query result to Excel
|
// Export query result to Excel
|
||||||
func ProcessExport(process *gou.Process) interface{} {
|
func ProcessExport(process *gou.Process) interface{} {
|
||||||
|
|
||||||
|
debug := os.Getenv("YAO_EXPORT_DEBUG") != ""
|
||||||
process.ValidateArgNums(1)
|
process.ValidateArgNums(1)
|
||||||
name := process.ArgsString(0)
|
name := process.ArgsString(0)
|
||||||
table := Select(name)
|
table := Select(name)
|
||||||
|
|
@ -372,6 +374,11 @@ func ProcessExport(process *gou.Process) interface{} {
|
||||||
pagesize = process.ArgsInt(3, api.DefaultInt(1))
|
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).
|
response := gou.NewProcess(api.Process, param, page, pagesize).
|
||||||
WithGlobal(process.Global).
|
WithGlobal(process.Global).
|
||||||
|
|
@ -381,6 +388,11 @@ func ProcessExport(process *gou.Process) interface{} {
|
||||||
// After Hook
|
// After Hook
|
||||||
response = table.After(table.Hooks.AfterSearch, response, []interface{}{param, page, pagesize}, process.Sid)
|
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{})
|
res, ok := response.(map[string]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
res, ok = response.(maps.MapStrAny)
|
res, ok = response.(maps.MapStrAny)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/yaoapp/gou"
|
"github.com/yaoapp/gou"
|
||||||
"github.com/yaoapp/kun/any"
|
"github.com/yaoapp/kun/any"
|
||||||
"github.com/yaoapp/kun/maps"
|
"github.com/yaoapp/kun/maps"
|
||||||
"github.com/yaoapp/kun/utils"
|
|
||||||
"github.com/yaoapp/xun/capsule"
|
"github.com/yaoapp/xun/capsule"
|
||||||
"github.com/yaoapp/yao/config"
|
"github.com/yaoapp/yao/config"
|
||||||
"github.com/yaoapp/yao/flow"
|
"github.com/yaoapp/yao/flow"
|
||||||
|
|
@ -58,7 +57,7 @@ func TestTableProcessSearchWithHook(t *testing.T) {
|
||||||
|
|
||||||
args := []interface{}{"hooks.search"}
|
args := []interface{}{"hooks.search"}
|
||||||
response := gou.NewProcess("xiang.table.Search", args...).Run()
|
response := gou.NewProcess("xiang.table.Search", args...).Run()
|
||||||
utils.Dump(response)
|
// utils.Dump(response)
|
||||||
|
|
||||||
assert.NotNil(t, response)
|
assert.NotNil(t, response)
|
||||||
res := any.Of(response).Map()
|
res := any.Of(response).Map()
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/xuri/excelize/v2"
|
"github.com/xuri/excelize/v2"
|
||||||
"github.com/yaoapp/gou"
|
"github.com/yaoapp/gou"
|
||||||
"github.com/yaoapp/gou/helper"
|
"github.com/yaoapp/gou/helper"
|
||||||
|
|
@ -350,6 +351,13 @@ func (table *Table) loadColumns() {
|
||||||
// Export Export query result to Excel
|
// Export Export query result to Excel
|
||||||
func (table *Table) Export(filename string, data interface{}, page int, chunkSize int) error {
|
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{}
|
rows := []maps.MapStr{}
|
||||||
if values, ok := data.([]maps.MapStrAny); ok {
|
if values, ok := data.([]maps.MapStrAny); ok {
|
||||||
for _, row := range values {
|
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()
|
columns, err := table.exportSetting()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue