create_attendance.go
2.5 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
package command
import (
"fmt"
"reflect"
"strings"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
)
type CreateAttendanceCommand struct {
// 考勤记录ID
//ProductAttendanceId int `cname:"考勤记录ID" json:"productAttendanceId" valid:"Required"`
// 考勤类型 1.正常 2.支援
AttendanceType int `cname:"考勤类型" json:"attendanceType,omitempty"`
// 生产班组Id
// ProductGroupId int `cname:"生产班组Id" json:"productGroupId,omitempty" valid:"Required"`
// 生产工人
ProductWorkerId int `cname:"生产工人" 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"`
// 生产日期
ProductDate string `cname:"生产日期" json:"productDate,omitempty" valid:"Required"`
// 签到
SignIn string `cname:"上岗时间" json:"signIn,omitempty" valid:"Required"`
// 签退
SignOut string `cname:"下岗时间" json:"signOut,omitempty" valid:"Required"`
// 考勤状态 1.未审核 2:审核
AttendanceStatus int `cname:"考勤状态" json:"attendanceStatus,omitempty"`
// 休息时长
BreakTime float64 `cname:"休息时长" json:"breakTime"`
// 工时
WorkTime float64 `cname:"工时" json:"workTime"`
// 准备(true:准备完毕 false:进行预查)
Prepared bool `json:"prepared"`
}
func (createAttendanceCommand *CreateAttendanceCommand) Valid(validation *validation.Validation) {
if err := utils.ValidWorkTime(createAttendanceCommand.SignIn); err != nil {
validation.Error(err.Error())
return
}
if err := utils.ValidWorkTime(createAttendanceCommand.SignOut); err != nil {
validation.Error(err.Error())
return
}
validation.Range(createAttendanceCommand.AttendanceStatus, 1, 2, "attendanceStatus")
}
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
}