正在显示
4 个修改的文件
包含
33 行增加
和
3 行删除
@@ -15,7 +15,7 @@ type CreateQuerySetCommand struct { | @@ -15,7 +15,7 @@ type CreateQuerySetCommand struct { | ||
15 | // 标识 | 15 | // 标识 |
16 | Flag string `cname:"标识" json:"flag" valid:"Required"` | 16 | Flag string `cname:"标识" json:"flag" valid:"Required"` |
17 | // 名称 | 17 | // 名称 |
18 | - Name string `cname:"名称" json:"name" valid:"Required"` | 18 | + Name string `cname:"名称" json:"name"` |
19 | // 父级ID | 19 | // 父级ID |
20 | ParentId int `cname:"父级ID" json:"parentId,omitempty"` | 20 | ParentId int `cname:"父级ID" json:"parentId,omitempty"` |
21 | } | 21 | } |
@@ -98,8 +98,10 @@ func (querySetService *QuerySetService) CreateQuerySet(ctx *domain.Context, crea | @@ -98,8 +98,10 @@ func (querySetService *QuerySetService) CreateQuerySet(ctx *domain.Context, crea | ||
98 | Name: createQuerySetCommand.Name, | 98 | Name: createQuerySetCommand.Name, |
99 | ParentId: createQuerySetCommand.ParentId, | 99 | ParentId: createQuerySetCommand.ParentId, |
100 | } | 100 | } |
101 | - | ||
102 | svr, _ := factory.FastQuerySetServices(transactionContext) | 101 | svr, _ := factory.FastQuerySetServices(transactionContext) |
102 | + if len(createQuerySetCommand.Name) == 0 { | ||
103 | + createQuerySetCommand.Name = fmt.Sprintf("%s%s", domain.EnumsDescription(domain.ObjectTypeMap, createQuerySetCommand.Type), utils.Krand(5, utils.KC_RAND_KIND_NUM)) | ||
104 | + } | ||
103 | var querySet *domain.QuerySet | 105 | var querySet *domain.QuerySet |
104 | if querySet, err = svr.Create(ctx, newQuerySet); err != nil { | 106 | if querySet, err = svr.Create(ctx, newQuerySet); err != nil { |
105 | return nil, factory.FastError(err) | 107 | return nil, factory.FastError(err) |
@@ -43,7 +43,7 @@ func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) (*d | @@ -43,7 +43,7 @@ func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) (*d | ||
43 | Name: qs.Name, | 43 | Name: qs.Name, |
44 | ParentId: qs.ParentId, | 44 | ParentId: qs.ParentId, |
45 | PinName: pinFull(qs.Name), | 45 | PinName: pinFull(qs.Name), |
46 | - Status: domain.StatusOn, | 46 | + Status: domain.StatusOff, |
47 | QuerySetInfo: &domain.QuerySetInfo{}, | 47 | QuerySetInfo: &domain.QuerySetInfo{}, |
48 | QueryComponents: make([]*domain.QueryComponent, 0), | 48 | QueryComponents: make([]*domain.QueryComponent, 0), |
49 | CreatedAt: time.Now(), | 49 | CreatedAt: time.Now(), |
pkg/infrastructure/utils/krand.go
0 → 100644
1 | +package utils | ||
2 | + | ||
3 | +import ( | ||
4 | + "math/rand" | ||
5 | + "time" | ||
6 | +) | ||
7 | + | ||
8 | +const ( | ||
9 | + KC_RAND_KIND_NUM = 0 // 纯数字 | ||
10 | + KC_RAND_KIND_LOWER = 1 // 小写字母 | ||
11 | + KC_RAND_KIND_UPPER = 2 // 大写字母 | ||
12 | + KC_RAND_KIND_ALL = 3 // 数字、大小写字母 | ||
13 | +) | ||
14 | + | ||
15 | +// 随机字符串 | ||
16 | +func Krand(size int, kind int) string { | ||
17 | + ikind, kinds, result := kind, [][]int{[]int{10, 48}, []int{26, 97}, []int{26, 65}}, make([]byte, size) | ||
18 | + is_all := kind > 2 || kind < 0 | ||
19 | + rand.Seed(time.Now().UnixNano()) | ||
20 | + for i := 0; i < size; i++ { | ||
21 | + if is_all { // random ikind | ||
22 | + ikind = rand.Intn(3) | ||
23 | + } | ||
24 | + scope, base := kinds[ikind][0], kinds[ikind][1] | ||
25 | + result[i] = uint8(base + rand.Intn(scope)) | ||
26 | + } | ||
27 | + return string(result) | ||
28 | +} |
-
请 注册 或 登录 后发表评论