save_reward_standard.go 1.6 KB
package command

import (
	"fmt"
	"reflect"
	"strings"

	"github.com/beego/beego/v2/core/validation"
)

type SaveRewardStandardCommand struct {
	Id         int    `json:"id"`                          //奖惩标准 id
	WorkshopId int    `json:"workshopId" valid:"Required"` //车间id
	LineId     int    `json:"lineId" valid:"Required"`     //生产线ID
	SectionId  int    `json:"sectionId" valid:"Required"`  //工段ID
	Remark     string `json:"remark"`                      //备注
	TargetType int    `json:"targetType" valid:"Required"` //指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数
	TargeVal1  string `json:"targeVal1"`                   //填写的指标值1
	TargeVal2  string `json:"targeVal2"`                   //填写的指标值2
	TargeVal3  string `json:"targeVal3"`                   //填写的指标值3
	TargeVal4  string `json:"targeVal4"`                   //填写的指标值4
}

func (removeProductCommand *SaveRewardStandardCommand) Valid(validation *validation.Validation) {

}

func (removeProductCommand *SaveRewardStandardCommand) ValidateCommand() error {
	valid := validation.Validation{}
	b, err := valid.Valid(removeProductCommand)
	if err != nil {
		return err
	}
	if !b {
		elem := reflect.TypeOf(removeProductCommand).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
}