add_notice_setting.go 1.2 KB
package command

import (
	"fmt"

	"github.com/beego/beego/v2/core/validation"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
)

type AddNoticeSettingCommand struct {
	// 公司id
	CompanyId int64 `json:"companyId"`
	// 内容模板
	Content string `json:"content"`
	// 是否推送 【是:1】【否:2】
	IsPush int `json:"isPush"`
	// 消息对应的业务模块
	Module string `json:"module"`
	// 业务环节
	ModuleAction string `json:"moduleAction"`
	// 组织id
	OrgId int64 `json:"orgId"`
}

func (addNoticeSettingCommand *AddNoticeSettingCommand) Valid(v *validation.Validation) {
	ok := domain.ValidNoticeModule(addNoticeSettingCommand.Module)
	if !ok {
		v.SetError("Module", "不是规定的值")
	}
	//检查消息编码
	ok = domain.ValidNoticeModuleAction(addNoticeSettingCommand.Module, addNoticeSettingCommand.ModuleAction)
	if !ok {
		v.SetError("ModuleAction", "不是规定的值")
	}
}

func (addNoticeSettingCommand *AddNoticeSettingCommand) ValidateCommand() error {
	valid := validation.Validation{}
	b, err := valid.Valid(addNoticeSettingCommand)
	if err != nil {
		return err
	}
	if !b {
		for _, validErr := range valid.Errors {
			return fmt.Errorf("%s  %s", validErr.Key, validErr.Message)
		}
	}
	return nil
}