diff --git a/internal/server/model/base.go b/internal/server/model/base.go new file mode 100644 index 0000000000000000000000000000000000000000..cd2660a5e8ba084a4c1b7142c8aad297264f76c8 --- /dev/null +++ b/internal/server/model/base.go @@ -0,0 +1,16 @@ +package model + +import ( + "time" +) + +type BaseModel struct { + //gorm.Model + + ID uint `gorm:"primary_key" sql:"type:INT(10) UNSIGNED NOT NULL" json:"id"` + CreatedAt *time.Time `json:"createdAt,omitempty"` + UpdatedAt *time.Time `json:"updatedAt,omitempty"` + + Deleted bool `json:"-" gorm:"default:false"` + Disabled bool `json:"disabled,omitempty" gorm:"default:false"` +} diff --git a/internal/server/model/models.go b/internal/server/model/models.go new file mode 100644 index 0000000000000000000000000000000000000000..8fd052eb27026a811ef29dd224adb0f24393c4a4 --- /dev/null +++ b/internal/server/model/models.go @@ -0,0 +1,18 @@ +package model + +var ( + CommonPrefix = "zd_" + Models = []interface{}{ + &ZdDef{}, + &ZdField{}, + &ZdSection{}, + &ZdRefer{}, + &ZdConfig{}, + &ZdRanges{}, + &ZdRangesItem{}, + &ZdInstances{}, + &ZdInstancesItem{}, + &ZdText{}, + &ZdExcel{}, + } +) diff --git a/internal/server/model/zd-config.go b/internal/server/model/zd-config.go new file mode 100644 index 0000000000000000000000000000000000000000..52b035e02308c2465c62363ad85615e76d7b676b --- /dev/null +++ b/internal/server/model/zd-config.go @@ -0,0 +1,33 @@ +package model + +import ( + consts "github.com/easysoft/zendata/internal/pkg/const" +) + +type ZdConfig struct { + BaseModel + + Title string `json:"title"` + Desc string `json:"desc"` + + Range string `json:"range"` + Prefix string `json:"prefix"` + Postfix string `json:"postfix"` + Loop string `json:"loop"` + Loopfix string `json:"loopfix"` + Format string `json:"format"` + + Yaml string `json:"yaml"` + Path string `json:"path" yaml:"-"` + Folder string `json:"folder" yaml:"-"` + FileName string `json:"fileName" yaml:"-"` + ReferName string `json:"referName" yaml:"-"` + + // for range edit + IsRange bool `gorm:"default:true" json:"isRange" yaml:"-"` + Sections []ZdSection `gorm:"ForeignKey:ownerID" json:"sections" yaml:"-"` +} + +func (*ZdConfig) TableName() string { + return consts.TablePrefix + "config" +} diff --git a/internal/server/model/zd-def.go b/internal/server/model/zd-def.go new file mode 100644 index 0000000000000000000000000000000000000000..a025b8ebc369fd73c939ff80770c0ab6bc2660a7 --- /dev/null +++ b/internal/server/model/zd-def.go @@ -0,0 +1,27 @@ +package model + +import ( + consts "github.com/easysoft/zendata/internal/pkg/const" +) + +type ZdDef struct { + BaseModel + + Title string `json:"title"` + Type string `json:"type"` + Desc string `json:"desc"` + + Yaml string `json:"yaml"` + Path string `json:"path" yaml:"-"` + Folder string `json:"folder" yaml:"-"` + FileName string `json:"fileName" yaml:"-"` + IsMock bool `json:"isMock"` + + ReferName string `json:"referName" yaml:"-"` + From string `json:"from"` + Fields []ZdField `json:"fields"` +} + +func (ZdDef) TableName() string { + return consts.TablePrefix + "def" +} diff --git a/internal/server/model/zd-excel.go b/internal/server/model/zd-excel.go new file mode 100644 index 0000000000000000000000000000000000000000..0132e769e1e771941e53818ac8dd1a9790ce9951 --- /dev/null +++ b/internal/server/model/zd-excel.go @@ -0,0 +1,23 @@ +package model + +import ( + consts "github.com/easysoft/zendata/internal/pkg/const" +) + +type ZdExcel struct { + BaseModel + + Title string `json:"title"` + Sheet string `json:"sheet"` + + ChangeTime string `json:"changeTime"` + Yaml string `json:"yaml"` + Path string `json:"path" yaml:"-"` + Folder string `json:"folder" yaml:"-"` + FileName string `json:"fileName" yaml:"-"` + ReferName string `json:"referName" yaml:"-"` +} + +func (*ZdExcel) TableName() string { + return consts.TablePrefix + "excel" +} diff --git a/internal/server/model/zd-field.go b/internal/server/model/zd-field.go new file mode 100644 index 0000000000000000000000000000000000000000..b8fd1d9f8ce1faf0609ab9b593ed674024bcd237 --- /dev/null +++ b/internal/server/model/zd-field.go @@ -0,0 +1,63 @@ +package model + +import ( + consts "github.com/easysoft/zendata/internal/pkg/const" +) + +type ZdField struct { + BaseModel + + Field string `json:"field"` + Note string `json:"note"` + + Range string `json:"range"` + Prefix string `json:"prefix"` + Postfix string `json:"postfix"` + Divider string `json:"divider"` + Loop string `json:"loop"` + Loopfix string `json:"loopfix"` + Format string `json:"format"` + Type string `json:"type"` + Mode string `json:"mode"` + Items int `json:"records"` + Length int `json:"length"` + LeftPad string `json:"leftPad"` + RightPad string `json:"rightPad"` + Rand bool `json:"rand"` + Config string `json:"config"` + Use string `json:"use"` + From string `json:"fromCol"` + Select string `json:"selectCol"` + Where string `json:"whereCol"` + Limit int `json:"limitCol"` + + // refer to yaml or text by using range prop + Step string `json:"step"` + Repeat string `json:"repeat"` + + Exp string `json:"exp"` + DefID uint `json:"defID"` + ParentID uint `json:"parentID"` + UseID uint `json:"useID"` + ConfigID uint `json:"configID"` + + Ord int `gorm:"default:1" json:"ord"` + Join bool `json:"join"` + + Fields []*ZdField `gorm:"-" json:"fields"` + Froms []*ZdField `gorm:"-" json:"froms"` + + // for range edit + IsRange bool `gorm:"default:true" json:"isRange"` + Sections []ZdSection `gorm:"ForeignKey:ownerID" json:"sections"` + + // for refer edit + Refer ZdRefer `gorm:"ForeignKey:ownerID" json:"refer"` + + // generated by range or refer + GeneratedBy consts.GeneratedBy `gorm:"default:range" json:"generatedBy"` +} + +func (*ZdField) TableName() string { + return consts.TablePrefix + "field" +} diff --git a/internal/server/model/zd-instances-item.go b/internal/server/model/zd-instances-item.go new file mode 100644 index 0000000000000000000000000000000000000000..5f1c3a9207d27e72ab6ea8b05e3b09721bcdf36d --- /dev/null +++ b/internal/server/model/zd-instances-item.go @@ -0,0 +1,55 @@ +package model + +import ( + consts "github.com/easysoft/zendata/internal/pkg/const" +) + +type ZdInstancesItem struct { + BaseModel + + Instance string `json:"instance" yaml:"instance,omitempty"` + Note string `json:"note" yaml:"note,omitempty"` + + Field string `json:"field" yaml:"field,omitempty"` + Range string `json:"range" yaml:"range,omitempty"` + Prefix string `json:"prefix" yaml:"prefix,omitempty"` + Postfix string `json:"postfix" yaml:"postfix,omitempty"` + Loop string `json:"loop" yaml:"loop,omitempty"` + Loopfix string `json:"loopfix" yaml:"loopfix,omitempty"` + Format string `json:"format" yaml:"format,omitempty"` + Type string `json:"type" yaml:"type,omitempty"` + Mode string `json:"mode" yaml:"mode,omitempty"` + Items int `json:"records,omitempty" yaml:"records,omitempty"` + Length int `json:"length" yaml:"length,omitempty"` + LeftPad string `json:"leftPad" yaml:"leftPad,omitempty"` + RightPad string `json:"rightPad" yaml:"rightPad,omitempty"` + Rand bool `json:"rand" yaml:"rand,omitempty"` + + Config string `json:"config" yaml:"config,omitempty"` + Use string `json:"use" yaml:"use,omitempty"` + From string `json:"fromCol" yaml:"from,omitempty"` + Select string `json:"selectCol" yaml:"select,omitempty"` + Where string `json:"whereCol" yaml:"where,omitempty"` + Limit int `json:"limitCol" yaml:"limit,omitempty"` + + Exp string `json:"exp" yaml:"exp,omitempty"` + InstancesID uint `json:"instancesID" yaml:"-"` + ParentID uint `json:"parentID" yaml:"-"` + ConfigID uint `json:"configID" yaml:"-"` + UseID uint `json:"useID" yaml:"-"` + + Ord int `gorm:"default:1" json:"ord" yaml:"-"` + Fields []*ZdInstancesItem `gorm:"-" json:"fields" yaml:"fields,omitempty"` + Froms []*ZdInstancesItem `gorm:"-" json:"froms" yaml:"froms,omitempty"` + + // for range edit + IsRange bool `gorm:"default:true" json:"isRange" yaml:"-"` + Sections []ZdSection `gorm:"ForeignKey:ownerID" json:"sections" yaml:"-"` + + // for refer edit + Refer ZdRefer `gorm:"ForeignKey:ownerID" json:"refer" yaml:"-"` +} + +func (*ZdInstancesItem) TableName() string { + return consts.TablePrefix + "instances_item" +} diff --git a/internal/server/model/zd-instances.go b/internal/server/model/zd-instances.go new file mode 100644 index 0000000000000000000000000000000000000000..e7d998659cbce1d47bc8612323c533c840686677 --- /dev/null +++ b/internal/server/model/zd-instances.go @@ -0,0 +1,26 @@ +package model + +import ( + consts "github.com/easysoft/zendata/internal/pkg/const" +) + +type ZdInstances struct { + BaseModel + + Title string `json:"title" yaml:"title,omitempty"` + Desc string `json:"desc" yaml:"desc,omitempty"` + + Yaml string `json:"yaml" yaml:"-"` + Path string `json:"path" yaml:"-"` + Folder string `json:"folder" yaml:"-"` + + FileName string `json:"fileName" yaml:"-"` + ReferName string `json:"referName" yaml:"-"` + + From string `gorm:"-" json:"from"` + Instances []ZdInstancesItem `gorm:"ForeignKey:instancesID" json:"instances" yaml:"instances"` +} + +func (*ZdInstances) TableName() string { + return consts.TablePrefix + "instances" +} diff --git a/internal/server/model/zd-ranges-item.go b/internal/server/model/zd-ranges-item.go new file mode 100644 index 0000000000000000000000000000000000000000..9e573fa8cd63cd3062d8d8deafba963174edba88 --- /dev/null +++ b/internal/server/model/zd-ranges-item.go @@ -0,0 +1,24 @@ +package model + +import ( + consts "github.com/easysoft/zendata/internal/pkg/const" +) + +type ZdRangesItem struct { + BaseModel + + RangesID uint `json:"rangesID"` + Field string `json:"field"` + Ord int `json:"ord"` + + Value string `json:"value"` + Sections []ZdSection `gorm:"ForeignKey:ownerID" json:"sections"` + + // for tree node + ParentID uint `gorm:"-" json:"parentID"` + Fields []*ZdRangesItem `gorm:"-" json:"fields"` +} + +func (*ZdRangesItem) TableName() string { + return consts.TablePrefix + "ranges_item" +} diff --git a/internal/server/model/zd-ranges.go b/internal/server/model/zd-ranges.go new file mode 100644 index 0000000000000000000000000000000000000000..e6c57b4ea98a0c6749951b0563b23aada782ad29 --- /dev/null +++ b/internal/server/model/zd-ranges.go @@ -0,0 +1,28 @@ +package model + +import ( + consts "github.com/easysoft/zendata/internal/pkg/const" +) + +type ZdRanges struct { + BaseModel + + Title string `json:"title"` + Desc string `json:"desc"` + Prefix string `json:"prefix"` + Postfix string `json:"postfix"` + Format string `json:"format"` + + Yaml string `json:"yaml"` + Path string `json:"path" yaml:"-"` + Folder string `json:"folder" yaml:"-"` + FileName string `json:"fileName" yaml:"-"` + ReferName string `json:"referName" yaml:"-"` + + Ranges []ZdRangesItem `gorm:"ForeignKey:rangesID" json:"ranges" yaml:"-"` + RangeMap map[string]string `gorm:"-" yaml:"ranges"` +} + +func (*ZdRanges) TableName() string { + return consts.TablePrefix + "ranges" +} diff --git a/internal/server/model/zd-refer.go b/internal/server/model/zd-refer.go new file mode 100644 index 0000000000000000000000000000000000000000..39447ddb2be352f3962209ff3788cbb3a50e6e4e --- /dev/null +++ b/internal/server/model/zd-refer.go @@ -0,0 +1,30 @@ +package model + +import ( + consts "github.com/easysoft/zendata/internal/pkg/const" +) + +type ZdRefer struct { + BaseModel + + OwnerType string `json:"ownerType"` // field or instances + OwnerID uint `json:"ownerID"` + Type string `json:"type"` + + Value string `json:"value"` + File string `json:"file"` + Sheet string `json:"sheet"` + + ColName string `json:"colName"` + ColIndex int `json:"colIndex"` + Condition string `json:"condition"` + Count int `json:"count"` + CountTag string `json:"countTag"` + Step int `json:"step"` + Rand bool `json:"rand"` + HasTitle bool `json:"hasTitle"` +} + +func (*ZdRefer) TableName() string { + return consts.TablePrefix + "refer" +} diff --git a/internal/server/model/zd-section.go b/internal/server/model/zd-section.go new file mode 100644 index 0000000000000000000000000000000000000000..0aecfb752378fa2d13427fd5f1694ddb5ba1b2e4 --- /dev/null +++ b/internal/server/model/zd-section.go @@ -0,0 +1,30 @@ +package model + +import ( + consts "github.com/easysoft/zendata/internal/pkg/const" +) + +type ZdSection struct { + BaseModel + + OwnerType string `json:"ownerType"` // field or instances + OwnerID uint `json:"ownerID"` + Type string `gorm:"default:interval" json:"type"` + Value string `json:"value"` + Ord int `gorm:"default:1" json:"ord"` + + // for range + Start string `json:"start"` + End string `json:"end"` + Step int `gorm:"default:1" json:"step"` + Repeat string `gorm:"default:1" json:"repeat"` + RepeatTag string `json:"repeatTag"` + Rand bool `gorm:"default:false" json:"rand"` + + // for arr and const + Text string `gorm:"-" json:"-"` +} + +func (*ZdSection) TableName() string { + return consts.TablePrefix + "field" +} diff --git a/internal/server/model/zd-text.go b/internal/server/model/zd-text.go new file mode 100644 index 0000000000000000000000000000000000000000..f16120ab714d2e64277aee75d6cc230eac2d4304 --- /dev/null +++ b/internal/server/model/zd-text.go @@ -0,0 +1,21 @@ +package model + +import ( + consts "github.com/easysoft/zendata/internal/pkg/const" +) + +type ZdText struct { + BaseModel + + Title string `json:"title"` + + Content string `json:"content"` + Path string `json:"path" yaml:"-"` + Folder string `json:"folder" yaml:"-"` + FileName string `json:"fileName" yaml:"-"` + ReferName string `json:"referName" yaml:"-"` +} + +func (*ZdText) TableName() string { + return consts.TablePrefix + "text" +} diff --git a/t.json b/t.json new file mode 100755 index 0000000000000000000000000000000000000000..33e1974f5749934faf14c598fdebfae611998c37 --- /dev/null +++ b/t.json @@ -0,0 +1,42 @@ +[ + { + "f1": "1, ", + "f2": "101 - 10101" + }, + { + "f1": "2, ", + "f2": "102 - 10102" + }, + { + "f1": "3, ", + "f2": "103 - 10103" + }, + { + "f1": "1, ", + "f2": "101 - 10101" + }, + { + "f1": "2, ", + "f2": "102 - 10102" + }, + { + "f1": "3, ", + "f2": "103 - 10103" + }, + { + "f1": "1, ", + "f2": "101 - 10101" + }, + { + "f1": "2, ", + "f2": "102 - 10102" + }, + { + "f1": "3, ", + "f2": "103 - 10103" + }, + { + "f1": "1, ", + "f2": "101 - 10101" + } +]