search_log.go
2.3 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package command
import (
"fmt"
"reflect"
"strings"
"time"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
"github.com/beego/beego/v2/core/validation"
)
type SearchLogCommand struct {
// 日志类型 VerifiedStepLog:校验步骤 CommonLog:常规日志
LogType string `json:"logType"`
// 日志内容
MatchContent string `cname:"匹配日志内容" json:"matchContent,omitempty"`
// 源数据ID
SourceId int `cname:"源数据ID" json:"sourceId"`
// 多个源数据ID
InSourceId []int `cname:"多个源数据ID" json:"inSourceId"`
// 页码
PageNumber int `cname:"页码" json:"pageNumber,omitempty"`
// 页数
PageSize int `cname:"页数" json:"pageSize,omitempty"`
// 对象名称
ObjectName string `cname:"页数" json:"objectName,omitempty"`
Year int `cname:"年" json:"year,omitempty"`
Month int `cname:"月" json:"month,omitempty"`
Day int `cname:"日" json:"day,omitempty"`
// 开始时间
BeginTime time.Time `cname:"开始时间" json:"beginTime"`
// 结束时间
EndTime time.Time `cname:"结束时间" json:"endTime"`
// 按log_id 排序
SortByLogId string `json:"sortByLogId"`
Context *domain.Context
}
func (cmd *SearchLogCommand) Valid(validation *validation.Validation) {
if cmd.Year > 0 && cmd.Month == 0 && cmd.Day == 0 {
cmd.BeginTime = time.Date(cmd.Year, 1, 1, 0, 0, 0, 0, time.Local)
cmd.EndTime = cmd.BeginTime.AddDate(1, 0, 0)
}
if cmd.Year > 0 && cmd.Month > 0 && cmd.Day == 0 {
cmd.BeginTime = time.Date(cmd.Year, time.Month(cmd.Month), 1, 0, 0, 0, 0, time.Local)
cmd.EndTime = cmd.BeginTime.AddDate(0, 1, 0)
}
if cmd.Year > 0 && cmd.Month > 0 && cmd.Day > 0 {
cmd.BeginTime = time.Date(cmd.Year, time.Month(cmd.Month), cmd.Day, 0, 0, 0, 0, time.Local)
cmd.EndTime = cmd.BeginTime.AddDate(0, 0, 1)
}
if cmd.PageNumber == 0 {
cmd.PageNumber = 1
}
}
func (cmd *SearchLogCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(cmd)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(cmd).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}