|
|
@@ -1,25 +1,32 @@
|
|
|
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"
|
|
|
"git.sxidc.com/service-supports/fserr"
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- ColumnFather = "father"
|
|
|
- ColumnMother = "mother"
|
|
|
+ FieldFather = "Father"
|
|
|
+ FieldMother = "Mother"
|
|
|
)
|
|
|
|
|
|
-const (
|
|
|
- fieldFatherMaxLen = 128
|
|
|
- fieldMotherMaxLen = 128
|
|
|
+var (
|
|
|
+ ColumnFather = domain.ColumnName(FieldFather)
|
|
|
+ ColumnMother = domain.ColumnName(FieldMother)
|
|
|
)
|
|
|
|
|
|
+var fieldMap = map[string]string{
|
|
|
+ FieldFather: "父亲姓名",
|
|
|
+ FieldMother: "母亲姓名",
|
|
|
+}
|
|
|
+
|
|
|
type Entity struct {
|
|
|
entity.Base
|
|
|
- Father string `sqlmapping:"column:father" sqlresult:"column:father"`
|
|
|
- Mother string `sqlmapping:"column:mother" sqlresult:"column:mother"`
|
|
|
+ Father string `sqlmapping:"column:father" sqlresult:"column:father" check:"required,lte=128"`
|
|
|
+ Mother string `sqlmapping:"column:mother" sqlresult:"column:mother" check:"required,lte=128"`
|
|
|
StudentID string `sqlmapping:"column:student_id" sqlresult:"column:student_id"`
|
|
|
entity.TimeFields
|
|
|
}
|
|
|
@@ -32,35 +39,20 @@ func (e *Entity) DomainCamelName() string {
|
|
|
return "Family"
|
|
|
}
|
|
|
|
|
|
-func (e *Entity) CheckFieldID() error {
|
|
|
- return e.Base.CheckFieldID(e.DomainCNName())
|
|
|
-}
|
|
|
-
|
|
|
func (e *Entity) ForCreate() error {
|
|
|
- err := e.CheckFieldID()
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
+ checkResult := check.Struct(e, fieldMap)
|
|
|
|
|
|
- err = e.checkFieldFather()
|
|
|
+ err := entity.CheckFieldIDResult(checkResult)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- return nil
|
|
|
-}
|
|
|
-
|
|
|
-func (e *Entity) ForDelete() error {
|
|
|
- return e.CheckFieldID()
|
|
|
-}
|
|
|
-
|
|
|
-func (e *Entity) ForUpdate() error {
|
|
|
- err := e.CheckFieldID()
|
|
|
+ err = domain.CheckField(checkResult, e.DomainCNName(), FieldFather)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- err = e.checkUpdateFields()
|
|
|
+ err = domain.CheckField(checkResult, e.DomainCNName(), FieldMother)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
@@ -68,41 +60,50 @@ func (e *Entity) ForUpdate() error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (e *Entity) checkFieldFather() error {
|
|
|
- if strutils.IsStringEmpty(e.Father) {
|
|
|
- return fserr.New(e.DomainCNName() + "父亲姓名为空")
|
|
|
- }
|
|
|
+func (e *Entity) ForDelete() error {
|
|
|
+ checkResult := check.Struct(e, fieldMap)
|
|
|
|
|
|
- if len(e.Father) > fieldFatherMaxLen {
|
|
|
- return fserr.New(e.DomainCNName() + "父亲姓名超出限定长度")
|
|
|
+ err := entity.CheckFieldIDResult(checkResult)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
}
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (e *Entity) checkFieldMother() error {
|
|
|
- if strutils.IsStringEmpty(e.Mother) {
|
|
|
- return fserr.New(e.DomainCNName() + "母亲姓名为空")
|
|
|
+func (e *Entity) ForUpdate() error {
|
|
|
+ checkResult := check.Struct(e, fieldMap)
|
|
|
+
|
|
|
+ err := entity.CheckFieldIDResult(checkResult)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
}
|
|
|
|
|
|
- if len(e.Mother) > fieldMotherMaxLen {
|
|
|
- return fserr.New(e.DomainCNName() + "母亲姓名超出限定长度")
|
|
|
+ err = e.checkUpdateFields(checkResult)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
}
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (e *Entity) checkUpdateFields() error {
|
|
|
+func (e *Entity) checkUpdateFields(checkResult check.Result) error {
|
|
|
if strutils.AllBlank(e.Father, e.Mother) {
|
|
|
return fserr.New(e.DomainCNName() + "没有传递需要更新的字段")
|
|
|
}
|
|
|
|
|
|
- if strutils.IsStringNotEmpty(e.Father) && len(e.Father) > fieldFatherMaxLen {
|
|
|
- return fserr.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) && len(e.Mother) > fieldMotherMaxLen {
|
|
|
- return fserr.New(e.DomainCNName() + "母亲姓名超出限定长度")
|
|
|
+ if strutils.IsStringNotEmpty(e.Mother) {
|
|
|
+ err := domain.CheckField(checkResult, e.DomainCNName(), FieldMother)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return nil
|