update_dictionary.go
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type UpdateDictionaryCommand struct {
// 字典编号 主键
DictionaryId int64 `json:"dictionaryId" valid:"Required"`
// 字典编码
DictCode string `json:"dictCode" valid:"Required;MaxSize(30)"`
// 字典名称
DictName string `json:"dictName" valid:"Required;MaxSize(30)"`
// 备注信息
Describe string `json:"describe" valid:"Required;MaxSize(100)"`
// 字典值列表
DictItems []DictionaryItem `json:"dictItems"`
}
func (updateDictionaryCommand *UpdateDictionaryCommand) Valid(v *validation.Validation) {
//检查items
sortmap := make(map[int]struct{})
for _, item := range updateDictionaryCommand.DictItems {
if _, ok := sortmap[item.Sort]; ok {
v.SetError("sort", "明细项顺序值重复")
}
sortmap[item.Sort] = struct{}{}
}
}
func (updateDictionaryCommand *UpdateDictionaryCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateDictionaryCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}