|
|
@@ -0,0 +1,101 @@
|
|
|
+package family
|
|
|
+
|
|
|
+import (
|
|
|
+ "git.sxidc.com/go-framework/baize/framwork/domain"
|
|
|
+ "git.sxidc.com/go-tools/utils/strutils"
|
|
|
+ "git.sxidc.com/service-supports/fserr"
|
|
|
+)
|
|
|
+
|
|
|
+const (
|
|
|
+ TableName = "test.families"
|
|
|
+)
|
|
|
+
|
|
|
+const (
|
|
|
+ ColumnFather = "father"
|
|
|
+ ColumnMother = "mother"
|
|
|
+)
|
|
|
+
|
|
|
+const (
|
|
|
+ fieldFatherMaxLen = 128
|
|
|
+ fieldMotherMaxLen = 128
|
|
|
+)
|
|
|
+
|
|
|
+type Entity struct {
|
|
|
+ domain.BaseEntity
|
|
|
+ Father string `sqlmapping:"column:father" sqlresult:"column:father"`
|
|
|
+ Mother string `sqlmapping:"column:mother" sqlresult:"column:mother"`
|
|
|
+ StudentID string `sqlmapping:"column:student_id" sqlresult:"column:student_id"`
|
|
|
+ domain.TimeFields
|
|
|
+}
|
|
|
+
|
|
|
+func (e *Entity) DomainCNName() string {
|
|
|
+ return "家庭"
|
|
|
+}
|
|
|
+
|
|
|
+func (e *Entity) ForCreate() error {
|
|
|
+ err := e.CheckFieldID(e.DomainCNName())
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ err = e.checkFieldFather()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (e *Entity) ForUpdate() error {
|
|
|
+ err := e.CheckFieldID(e.DomainCNName())
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ err = e.checkUpdateFields()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (e *Entity) checkFieldFather() error {
|
|
|
+ if strutils.IsStringEmpty(e.Father) {
|
|
|
+ return fserr.New(e.DomainCNName() + "父亲姓名为空")
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(e.Father) > fieldFatherMaxLen {
|
|
|
+ return fserr.New(e.DomainCNName() + "父亲姓名超出限定长度")
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (e *Entity) checkFieldMother() error {
|
|
|
+ if strutils.IsStringEmpty(e.Mother) {
|
|
|
+ return fserr.New(e.DomainCNName() + "母亲姓名为空")
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(e.Mother) > fieldMotherMaxLen {
|
|
|
+ return fserr.New(e.DomainCNName() + "母亲姓名超出限定长度")
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (e *Entity) checkUpdateFields() 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.Mother) && len(e.Mother) > fieldMotherMaxLen {
|
|
|
+ return fserr.New(e.DomainCNName() + "母亲姓名超出限定长度")
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|