create_attendance.go
1.7 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
package command
import (
"fmt"
"reflect"
"strings"
"time"
"github.com/beego/beego/v2/core/validation"
)
type CreateAttendanceCommand struct {
// 考勤记录ID
//ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
// 考勤类型 1.正常 2.支援
AttendanceType int `json:"attendanceType,omitempty"`
// 生产班组Id
ProductGroupId int `json:"productGroupId,omitempty" valid:"Required"`
// 生产工人
ProductWorkerId int `json:"productWorkerId,omitempty" valid:"Required"`
// 车间ID
WorkshopId int `cname:"车间ID" json:"workshopId" valid:"Required"`
// 生产线ID
LineId int `cname:"生产线ID" json:"lineId" valid:"Required"`
// 工段ID
SectionId int `cname:"工段ID" json:"sectionId" valid:"Required"`
// 签到
SignIn time.Time `json:"signIn,omitempty"`
// 签退
SignOut time.Time `json:"signOut,omitempty"`
// 考勤状态 1.未审核 2:已审核 3.自动审核
//AttendanceStatus int `json:"attendanceStatus,omitempty"`
}
func (createAttendanceCommand *CreateAttendanceCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createAttendanceCommand *CreateAttendanceCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createAttendanceCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(createAttendanceCommand).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
}