作者 yangfu

feat: sort zh

@@ -266,6 +266,24 @@ func pin(name string) string { @@ -266,6 +266,24 @@ func pin(name string) string {
266 return newPinyin.String() 266 return newPinyin.String()
267 } 267 }
268 268
  269 +func pinFull(name string) string {
  270 + prefixBuf := bytes.NewBuffer(nil)
  271 + runes := []rune(name)
  272 + for _, r := range runes {
  273 + if r > 0xFF {
  274 + if prefixBuf.Len() > 0 {
  275 + prefixBuf.WriteString("_")
  276 + }
  277 + prefixBuf.WriteString(pin(string(r)))
  278 + continue
  279 + }
  280 + //if isDigital(byte(r)) || isLetters(byte(r)){
  281 + prefixBuf.WriteRune(r)
  282 + //}
  283 + }
  284 + return prefixBuf.String()
  285 +}
  286 +
269 func isDigital(b byte) bool { 287 func isDigital(b byte) bool {
270 return b >= byte('0') && b <= byte('9') 288 return b >= byte('0') && b <= byte('9')
271 } 289 }
  1 +package domainService
  2 +
  3 +import (
  4 + "github.com/stretchr/testify/assert"
  5 + "testing"
  6 +)
  7 +
  8 +func Test_PinName(t *testing.T) {
  9 + inputs := []struct {
  10 + s string
  11 + want string
  12 + }{
  13 + {"a我们", "a_wo_men"},
  14 + {"a2我们", "a2_wo_men"},
  15 + {"1我们", "1_wo_men"},
  16 + {"10.我们", "10._wo_men"},
  17 + {"我们", "wo_men"},
  18 + {"z.我们", "z._wo_men"},
  19 + {"123", "123"},
  20 + {"年度", "nian_du"},
  21 + {"333", "333"},
  22 + {"yyy", "yyy"},
  23 + {"1.2.3", "1.2.3"},
  24 + }
  25 + for _, input := range inputs {
  26 + got := pinFull(input.s)
  27 + assert.Equal(t, input.want, got)
  28 + }
  29 +}
@@ -41,7 +41,7 @@ func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) (*d @@ -41,7 +41,7 @@ func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) (*d
41 Flag: qs.Flag, 41 Flag: qs.Flag,
42 Name: qs.Name, 42 Name: qs.Name,
43 ParentId: qs.ParentId, 43 ParentId: qs.ParentId,
44 - PinName: pin(qs.Name), 44 + PinName: pinFull(qs.Name),
45 Status: domain.StatusOn, 45 Status: domain.StatusOn,
46 QuerySetInfo: &domain.QuerySetInfo{}, 46 QuerySetInfo: &domain.QuerySetInfo{},
47 QueryComponents: make([]*domain.QueryComponent, 0), 47 QueryComponents: make([]*domain.QueryComponent, 0),
@@ -1032,7 +1032,7 @@ func copyQuerySet(qs *domain.QuerySet, t string, groupId int, name string) *doma @@ -1032,7 +1032,7 @@ func copyQuerySet(qs *domain.QuerySet, t string, groupId int, name string) *doma
1032 Type: t, 1032 Type: t,
1033 Flag: qs.Flag, 1033 Flag: qs.Flag,
1034 Name: name, 1034 Name: name,
1035 - PinName: pin(name), 1035 + PinName: pinFull(name),
1036 ParentId: groupId, 1036 ParentId: groupId,
1037 Status: qs.Status, 1037 Status: qs.Status,
1038 QuerySetInfo: qs.QuerySetInfo, 1038 QuerySetInfo: qs.QuerySetInfo,
  1 +package domainService
  2 +
  3 +import (
  4 + "fmt"
  5 + pG "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/pg"
  7 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository"
  8 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
  9 +)
  10 +
  11 +func Script() {
  12 + ScriptRenameQuerySetPinName()
  13 +}
  14 +
  15 +func ScriptRenameQuerySetPinName() {
  16 + defer func() {
  17 + if p := recover(); p != nil {
  18 + log.Logger.Error(fmt.Sprintf("%v", p))
  19 + }
  20 + }()
  21 + var err error
  22 + transactionContext := pG.NewPGTransactionContext(pg.DB)
  23 + if err != nil {
  24 + return
  25 + }
  26 + if err := transactionContext.StartTransaction(); err != nil {
  27 + return
  28 + }
  29 + defer func() {
  30 + transactionContext.RollbackTransaction()
  31 + }()
  32 + querySetRepository, _ := repository.NewQuerySetRepository(transactionContext)
  33 + _, querySets, _ := querySetRepository.Find(map[string]interface{}{})
  34 + for i := range querySets {
  35 + pinName := pinFull(querySets[i].Name)
  36 + log.Logger.Info(fmt.Sprintf("%v %v -> %v", querySets[i].QuerySetId, querySets[i].Name, querySets[i]))
  37 + querySets[i].PinName = pinName
  38 + _, err := querySetRepository.Save(querySets[i])
  39 + if err != nil {
  40 + log.Logger.Error(err.Error(), map[string]interface{}{"qs": querySets[i]})
  41 + }
  42 + }
  43 + if err := transactionContext.CommitTransaction(); err != nil {
  44 + return
  45 + }
  46 +}
@@ -171,7 +171,7 @@ func (repository *QuerySetRepository) Find(queryOptions map[string]interface{}) @@ -171,7 +171,7 @@ func (repository *QuerySetRepository) Find(queryOptions map[string]interface{})
171 query.Where("query_set_info->'BindTableId' in (?)", pg.In(utils.ToArrayString(v.([]int)))) 171 query.Where("query_set_info->'BindTableId' in (?)", pg.In(utils.ToArrayString(v.([]int))))
172 } 172 }
173 if v, ok := queryOptions["sortByName"]; ok && len(v.(string)) > 0 { 173 if v, ok := queryOptions["sortByName"]; ok && len(v.(string)) > 0 {
174 - query.SetOrderDirect("name", v.(string))//pin_name 174 + query.SetOrderDirect("pin_name", v.(string)) //pin_name
175 } else if v, ok := queryOptions["sortByTime"]; ok && len(v.(string)) > 0 { 175 } else if v, ok := queryOptions["sortByTime"]; ok && len(v.(string)) > 0 {
176 query.SetOrderDirect("created_at", v.(string)) 176 query.SetOrderDirect("created_at", v.(string))
177 } else { 177 } else {
@@ -6,6 +6,8 @@ import ( @@ -6,6 +6,8 @@ import (
6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/query" 6 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/query"
7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/service" 7 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/table/service"
8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain" 8 "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/domainService"
  10 + "strings"
9 11
10 filecommand "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/command" 12 filecommand "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/command"
11 fileservice "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/service" 13 fileservice "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/file/service"
@@ -284,3 +286,12 @@ func (controller *TableController) DependencyGraph() { @@ -284,3 +286,12 @@ func (controller *TableController) DependencyGraph() {
284 data, err := tableService.DependencyGraph(ParseContext(controller.BaseController), updateTableCommand) 286 data, err := tableService.DependencyGraph(ParseContext(controller.BaseController), updateTableCommand)
285 controller.Response(data, err) 287 controller.Response(data, err)
286 } 288 }
  289 +
  290 +func (controller *TableController) ExecScript() {
  291 + name := controller.GetString(":name")
  292 + switch strings.ToLower(name) {
  293 + case "qsrename":
  294 + domainService.ScriptRenameQuerySetPinName()
  295 + }
  296 + controller.Response(nil, nil)
  297 +}
@@ -41,4 +41,5 @@ func init() { @@ -41,4 +41,5 @@ func init() {
41 web.Router("/business/db-table-preview", tableController, "Post:DBTablePreview") 41 web.Router("/business/db-table-preview", tableController, "Post:DBTablePreview")
42 web.Router("/data/table-preview", tableController, "Post:Preview") 42 web.Router("/data/table-preview", tableController, "Post:Preview")
43 43
  44 + web.Router("/data/tables/exec/:name", tableController, "Get:ExecScript")
44 } 45 }