create_attendance.go 1.7 KB
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
}