作者 yangfu

计算集默认值

... ... @@ -15,7 +15,7 @@ type CreateQuerySetCommand struct {
// 标识
Flag string `cname:"标识" json:"flag" valid:"Required"`
// 名称
Name string `cname:"名称" json:"name" valid:"Required"`
Name string `cname:"名称" json:"name"`
// 父级ID
ParentId int `cname:"父级ID" json:"parentId,omitempty"`
}
... ...
... ... @@ -98,8 +98,10 @@ func (querySetService *QuerySetService) CreateQuerySet(ctx *domain.Context, crea
Name: createQuerySetCommand.Name,
ParentId: createQuerySetCommand.ParentId,
}
svr, _ := factory.FastQuerySetServices(transactionContext)
if len(createQuerySetCommand.Name) == 0 {
createQuerySetCommand.Name = fmt.Sprintf("%s%s", domain.EnumsDescription(domain.ObjectTypeMap, createQuerySetCommand.Type), utils.Krand(5, utils.KC_RAND_KIND_NUM))
}
var querySet *domain.QuerySet
if querySet, err = svr.Create(ctx, newQuerySet); err != nil {
return nil, factory.FastError(err)
... ...
... ... @@ -43,7 +43,7 @@ func (ptr *QuerySetService) Create(ctx *domain.Context, qs *domain.QuerySet) (*d
Name: qs.Name,
ParentId: qs.ParentId,
PinName: pinFull(qs.Name),
Status: domain.StatusOn,
Status: domain.StatusOff,
QuerySetInfo: &domain.QuerySetInfo{},
QueryComponents: make([]*domain.QueryComponent, 0),
CreatedAt: time.Now(),
... ...
package utils
import (
"math/rand"
"time"
)
const (
KC_RAND_KIND_NUM = 0 // 纯数字
KC_RAND_KIND_LOWER = 1 // 小写字母
KC_RAND_KIND_UPPER = 2 // 大写字母
KC_RAND_KIND_ALL = 3 // 数字、大小写字母
)
// 随机字符串
func Krand(size int, kind int) string {
ikind, kinds, result := kind, [][]int{[]int{10, 48}, []int{26, 97}, []int{26, 65}}, make([]byte, size)
is_all := kind > 2 || kind < 0
rand.Seed(time.Now().UnixNano())
for i := 0; i < size; i++ {
if is_all { // random ikind
ikind = rand.Intn(3)
}
scope, base := kinds[ikind][0], kinds[ikind][1]
result[i] = uint8(base + rand.Intn(scope))
}
return string(result)
}
... ...