|
|
@@ -3,9 +3,6 @@ package family
|
|
|
import (
|
|
|
"git.sxidc.com/go-framework/baize/framework/core/domain"
|
|
|
"git.sxidc.com/go-framework/baize/framework/core/domain/entity"
|
|
|
- "git.sxidc.com/go-framework/baize/framework/core/tag/check"
|
|
|
- "git.sxidc.com/go-tools/utils/strutils"
|
|
|
- "github.com/pkg/errors"
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
@@ -25,8 +22,8 @@ var fieldMap = map[string]string{
|
|
|
|
|
|
type Entity struct {
|
|
|
entity.Base
|
|
|
- Father string `sqlmapping:"column:father" sqlresult:"column:father" check:"required,lte=128"`
|
|
|
- Mother string `sqlmapping:"column:mother" sqlresult:"column:mother" check:"required,lte=128"`
|
|
|
+ Father string `sqlmapping:"column:father" sqlresult:"column:father" check:"required,lte=128,when=create/update"`
|
|
|
+ Mother string `sqlmapping:"column:mother" sqlresult:"column:mother" check:"required,lte=128,when=create/update"`
|
|
|
StudentID string `sqlmapping:"column:student_id" sqlresult:"column:student_id" check:"required,eq=32"`
|
|
|
entity.TimeFields
|
|
|
}
|
|
|
@@ -39,72 +36,6 @@ func (e *Entity) DomainCamelName() string {
|
|
|
return "Family"
|
|
|
}
|
|
|
|
|
|
-func (e *Entity) ForCreate() error {
|
|
|
- checkResult := check.Struct(e, fieldMap)
|
|
|
-
|
|
|
- err := entity.CheckFieldIDResult(checkResult)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- err = domain.CheckField(checkResult, e.DomainCNName(), FieldFather)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- err = domain.CheckField(checkResult, e.DomainCNName(), FieldMother)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
-func (e *Entity) ForDelete() error {
|
|
|
- checkResult := check.Struct(e, fieldMap)
|
|
|
-
|
|
|
- err := entity.CheckFieldIDResult(checkResult)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
-func (e *Entity) ForUpdate() error {
|
|
|
- checkResult := check.Struct(e, fieldMap)
|
|
|
-
|
|
|
- err := entity.CheckFieldIDResult(checkResult)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- err = e.checkUpdateFields(checkResult)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
-func (e *Entity) checkUpdateFields(checkResult check.Result) error {
|
|
|
- if strutils.AllBlank(e.Father, e.Mother) {
|
|
|
- return errors.New(e.DomainCNName() + "没有传递需要更新的字段")
|
|
|
- }
|
|
|
-
|
|
|
- if strutils.IsStringNotEmpty(e.Father) {
|
|
|
- err := domain.CheckField(checkResult, e.DomainCNName(), FieldFather)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if strutils.IsStringNotEmpty(e.Mother) {
|
|
|
- err := domain.CheckField(checkResult, e.DomainCNName(), FieldMother)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return nil
|
|
|
+func (e *Entity) GetFieldMap() map[string]string {
|
|
|
+ return fieldMap
|
|
|
}
|