作者 yangfu

feat: sort zh

... ... @@ -266,6 +266,24 @@ func pin(name string) string {
return newPinyin.String()
}
func pinFull(name string) string {
prefixBuf := bytes.NewBuffer(nil)
runes := []rune(name)
for _, r := range runes {
if r > 0xFF {
if prefixBuf.Len() > 0 {
prefixBuf.WriteString("_")
}
prefixBuf.WriteString(pin(string(r)))
continue
}
//if isDigital(byte(r)) || isLetters(byte(r)){
prefixBuf.WriteRune(r)
//}
}
return prefixBuf.String()
}
func isDigital(b byte) bool {
return b >= byte('0') && b <= byte('9')
}
... ...
package domainService
import (
"github.com/stretchr/testify/assert"
"testing"
)
func Test_PinName(t *testing.T) {
inputs := []struct {
s string
want string
}{
{"a我们", "a_wo_men"},
{"a2我们", "a2_wo_men"},
{"1我们", "1_wo_men"},
{"10.我们", "10._wo_men"},
{"我们", "wo_men"},
{"z.我们", "z._wo_men"},
{"123", "123"},
{"年度", "nian_du"},
{"333", "333"},
{"yyy", "yyy"},
{"1.2.3", "1.2.3"},
}
for _, input := range inputs {
got := pinFull(input.s)
assert.Equal(t, input.want, got)
}
}
... ...
... ... @@ -41,7 +41,7 @@ func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) (*d
Flag: qs.Flag,
Name: qs.Name,
ParentId: qs.ParentId,
PinName: pin(qs.Name),
PinName: pinFull(qs.Name),
Status: domain.StatusOn,
QuerySetInfo: &domain.QuerySetInfo{},
QueryComponents: make([]*domain.QueryComponent, 0),
... ... @@ -1032,7 +1032,7 @@ func copyQuerySet(qs *domain.QuerySet, t string, groupId int, name string) *doma
Type: t,
Flag: qs.Flag,
Name: name,
PinName: pin(name),
PinName: pinFull(name),
ParentId: groupId,
Status: qs.Status,
QuerySetInfo: qs.QuerySetInfo,
... ...
package domainService
import (
"fmt"
pG "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
)
func Script() {
ScriptRenameQuerySetPinName()
}
func ScriptRenameQuerySetPinName() {
defer func() {
if p := recover(); p != nil {
log.Logger.Error(fmt.Sprintf("%v", p))
}
}()
var err error
transactionContext := pG.NewPGTransactionContext(pg.DB)
if err != nil {
return
}
if err := transactionContext.StartTransaction(); err != nil {
return
}
defer func() {
transactionContext.RollbackTransaction()
}()
querySetRepository, _ := repository.NewQuerySetRepository(transactionContext)
_, querySets, _ := querySetRepository.Find(map[string]interface{}{})
for i := range querySets {
pinName := pinFull(querySets[i].Name)
log.Logger.Info(fmt.Sprintf("%v %v -> %v", querySets[i].QuerySetId, querySets[i].Name, querySets[i]))
querySets[i].PinName = pinName
_, err := querySetRepository.Save(querySets[i])
if err != nil {
log.Logger.Error(err.Error(), map[string]interface{}{"qs": querySets[i]})
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return
}
}
... ...
... ... @@ -171,7 +171,7 @@ func (repository *QuerySetRepository) Find(queryOptions map[string]interface{})
query.Where("query_set_info->'BindTableId' in (?)", pg.In(utils.ToArrayString(v.([]int))))
}
if v, ok := queryOptions["sortByName"]; ok && len(v.(string)) > 0 {
query.SetOrderDirect("name", v.(string))//pin_name
query.SetOrderDirect("pin_name", v.(string)) //pin_name
} else if v, ok := queryOptions["sortByTime"]; ok && len(v.(string)) > 0 {
query.SetOrderDirect("created_at", v.(string))
} else {
... ...
... ... @@ -6,6 +6,8 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/query"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/service"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService"
"strings"
filecommand "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/command"
fileservice "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/service"
... ... @@ -284,3 +286,12 @@ func (controller *TableController) DependencyGraph() {
data, err := tableService.DependencyGraph(ParseContext(controller.BaseController), updateTableCommand)
controller.Response(data, err)
}
func (controller *TableController) ExecScript() {
name := controller.GetString(":name")
switch strings.ToLower(name) {
case "qsrename":
domainService.ScriptRenameQuerySetPinName()
}
controller.Response(nil, nil)
}
... ...
... ... @@ -41,4 +41,5 @@ func init() {
web.Router("/business/db-table-preview", tableController, "Post:DBTablePreview")
web.Router("/data/table-preview", tableController, "Post:Preview")
web.Router("/data/tables/exec/:name", tableController, "Get:ExecScript")
}
... ...