提交 b980ed1d 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

close task#8435

上级 986da6a0
......@@ -145,16 +145,11 @@ func (*ZdRangesItem) TableName() string {
}
type ZdInstances struct {
Model
Title string `gorm:"column:title" json:"title"`
Name string `gorm:"column:name" json:"name"`
Desc string `gorm:"column:desc" json:"desc"`
Field string `gorm:"column:field" json:"field"`
Note string `gorm:"column:note" json:"note"`
Prefix string `gorm:"column:prefix" json:"prefix"`
Postfix string `gorm:"column:postfix" json:"postfix"`
Format string `gorm:"column:format" json:"format"`
Instances []ZdInstancesItem `gorm:"ForeignKey:instancesID" json:"instances"`
Model `yaml:"-"`
Title string `gorm:"column:title" json:"title" yaml:"title,omitempty"`
Name string `gorm:"column:name" json:"name" yaml:"-"`
Desc string `gorm:"column:desc" json:"desc" yaml:"desc,omitempty"`
Instances []ZdInstancesItem `gorm:"ForeignKey:instancesID" json:"instances" yaml:"instances"`
Yaml string `gorm:"yaml" json:"yaml" yaml:"-"`
Path string `gorm:"column:path" json:"path" yaml:"-"`
......@@ -165,46 +160,46 @@ func (*ZdInstances) TableName() string {
}
type ZdInstancesItem struct {
Model
InstancesID uint `gorm:"column:instancesID" json:"instancesID"`
ParentID uint `gorm:"column:parentID" json:"parentID"`
Field string `gorm:"column:field" json:"field"`
Note string `gorm:"column:note" json:"note"`
Instance string `gorm:"column:instance" json:"instance"`
Range string `gorm:"column:range" json:"range"`
Exp string `gorm:"column:exp" json:"exp"`
Prefix string `gorm:"column:prefix" json:"prefix"`
Postfix string `gorm:"column:postfix" json:"postfix"`
Loop string `gorm:"column:loop" json:"loop"`
Loopfix string `gorm:"column:loopfix" json:"loopfix"`
Format string `gorm:"column:format" json:"format"`
Type string `gorm:"column:type" json:"type"`
Mode string `gorm:"column:mode" json:"mode"`
Length int `gorm:"column:length" json:"length"`
LeftPad string `gorm:"column:leftPad" json:"leftPad"`
RightPad string `gorm:"column:rightPad" json:"rightPad"`
Rand bool `gorm:"column:rand" json:"rand"`
ConfigID uint `gorm:"column:configID" json:"configID"`
Config string `gorm:"column:config" json:"config"`
Use string `gorm:"column:use" json:"use"`
UseID uint `gorm:"column:useID" json:"useID"`
From string `gorm:"column:fromCol" json:"fromCol"`
Select string `gorm:"column:selectCol" json:"selectCol"`
Where string `gorm:"column:whereCol" json:"whereCol"`
Limit int `gorm:"column:limitCol" json:"limitCol"`
Ord int `gorm:"column:ord;default:1" json:"ord"`
Fields []*ZdInstancesItem `gorm:"-" json:"fields"`
Froms []*ZdInstancesItem `gorm:"-" json:"froms"`
Model `yaml:"-"`
InstancesID uint `gorm:"column:instancesID" json:"instancesID" yaml:"-"`
ParentID uint `gorm:"column:parentID" json:"parentID" yaml:"-"`
Field string `gorm:"column:field" json:"field" yaml:"field,omitempty"`
Note string `gorm:"column:note" json:"note" yaml:"note,omitempty"`
Instance string `gorm:"column:instance" json:"instance" yaml:"instance,omitempty"`
Range string `gorm:"column:range" json:"range" yaml:"range,omitempty"`
Exp string `gorm:"column:exp" json:"exp" yaml:"exp,omitempty"`
Prefix string `gorm:"column:prefix" json:"prefix" yaml:"prefix,omitempty"`
Postfix string `gorm:"column:postfix" json:"postfix" yaml:"postfix,omitempty"`
Loop string `gorm:"column:loop" json:"loop" yaml:"loop,omitempty"`
Loopfix string `gorm:"column:loopfix" json:"loopfix" yaml:"loopfix,omitempty"`
Format string `gorm:"column:format" json:"format" yaml:"format,omitempty"`
Type string `gorm:"column:type" json:"type" yaml:"type,omitempty"`
Mode string `gorm:"column:mode" json:"mode" yaml:"mode,omitempty"`
Length int `gorm:"column:length" json:"length" yaml:"length,omitempty"`
LeftPad string `gorm:"column:leftPad" json:"leftPad" yaml:"leftPad,omitempty"`
RightPad string `gorm:"column:rightPad" json:"rightPad" yaml:"rightPad,omitempty"`
Rand bool `gorm:"column:rand" json:"rand" yaml:"rand,omitempty"`
ConfigID uint `gorm:"column:configID" json:"configID" yaml:"-"`
Config string `gorm:"column:config" json:"config" yaml:"config,omitempty"`
Use string `gorm:"column:use" json:"use" yaml:"use,omitempty"`
UseID uint `gorm:"column:useID" json:"useID" yaml:"-"`
From string `gorm:"column:fromCol" json:"fromCol" yaml:"from,omitempty"`
Select string `gorm:"column:selectCol" json:"selectCol" yaml:"select,omitempty"`
Where string `gorm:"column:whereCol" json:"whereCol" yaml:"where,omitempty"`
Limit int `gorm:"column:limitCol" json:"limitCol" yaml:"limit,omitempty"`
Ord int `gorm:"column:ord;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:"column:isRange;default:true" json:"isRange"`
Sections []ZdSection `gorm:"ForeignKey:fieldID" json:"sections"`
IsRange bool `gorm:"column:isRange;default:true" json:"isRange" yaml:"-"`
Sections []ZdSection `gorm:"ForeignKey:fieldID" json:"sections" yaml:"-"`
// for refer edit
Refer ZdRefer `gorm:"ForeignKey:fieldID" json:"refer"`
Refer ZdRefer `gorm:"ForeignKey:fieldID" json:"refer" yaml:"-"`
}
func (*ZdInstancesItem) TableName() string {
return constant.TablePrefix + "instances_item"
......
......@@ -130,7 +130,6 @@ func (r *InstancesRepo) haveChild(Data []*model.ZdInstancesItem,
func (r *InstancesRepo) GenInst(po model.ZdInstances, res *model.ResInsts) {
res.Title = po.Title
res.Desc = po.Desc
res.Field = po.Field
}
func NewInstancesRepo(db *gorm.DB) *InstancesRepo {
......
......@@ -2,48 +2,6 @@ package serverService
import "github.com/easysoft/zendata/src/model"
func instancesItemToResInstForExport(item model.ZdInstancesItem) (inst model.ResInst) {
inst.Note = item.Note
for _, child := range item.Fields {
childField := model.DefField{}
instancesItemToResFieldForExport(*child, &childField)
inst.Fields = append(inst.Fields, childField)
}
if len(inst.Fields) == 0 {
inst.Fields = nil
}
if len(inst.Froms) == 0 {
inst.Froms = nil
}
return
}
func instancesItemToResFieldForExport(item model.ZdInstancesItem, field *model.DefField) {
for _, item := range item.Fields {
childField := model.DefField{}
instancesItemToResFieldForExport(*item, &childField)
field.Fields = append(field.Fields, childField)
}
for _, from := range item.Froms { // only one level
childField := model.DefField{}
genFieldFromZdInstancesItem(*from, &childField)
field.Froms = append(field.Froms, childField)
}
if len(field.Fields) == 0 {
field.Fields = nil
}
if len(field.Froms) == 0 {
field.Froms = nil
}
}
func zdFieldToFieldForExport(treeNode model.ZdField, field *model.DefField) {
genFieldFromZdField(treeNode, field)
......@@ -97,28 +55,70 @@ func genFieldFromZdField(treeNode model.ZdField, field *model.DefField) () {
field.Limit = treeNode.Limit
}
func genFieldFromZdInstancesItem(item model.ZdInstancesItem, field *model.DefField) () {
field.Field = item.Field
field.Note = item.Note
field.Range = item.Range
field.Value = item.Exp
field.Prefix = item.Prefix
field.Postfix = item.Postfix
field.Loop = item.Loop
field.Loopfix = item.Loopfix
field.Format = item.Format
field.Type = item.Type
field.Mode = item.Mode
field.Length = item.Length
field.LeftPad = item.LeftPad
field.RightPad = item.RightPad
field.Rand = item.Rand
field.Config = item.Config
field.Use = item.Use
field.From = item.From
field.Select = item.Select
field.Where = item.Where
field.Limit = item.Limit
}
//func instancesItemToResInstForExport(item model.ZdInstancesItem) (inst model.ResInst) {
// inst.Note = item.Note
//
// for _, child := range item.Fields {
// childField := model.DefField{}
// instancesItemToResFieldForExport(*child, &childField)
//
// inst.Fields = append(inst.Fields, childField)
// }
//
// if len(inst.Fields) == 0 {
// inst.Fields = nil
// }
// if len(inst.Froms) == 0 {
// inst.Froms = nil
// }
//
// return
//}
//func instancesItemToResFieldForExport(item model.ZdInstancesItem, field *model.DefField) {
// for _, item := range item.Fields {
// childField := model.DefField{}
// instancesItemToResFieldForExport(*item, &childField)
//
// field.Fields = append(field.Fields, childField)
// }
//
// for _, from := range item.Froms { // only one level
// childField := model.DefField{}
// genFieldFromZdInstancesItem(*from, &childField)
//
// field.Froms = append(field.Froms, childField)
// }
//
// if len(field.Fields) == 0 {
// field.Fields = nil
// }
// if len(field.Froms) == 0 {
// field.Froms = nil
// }
//}
//}
//func genFieldFromZdInstancesItem(item model.ZdInstancesItem, field *model.DefField) () {
// field.Field = item.Field
// field.Note = item.Note
//
// field.Range = item.Range
// field.Value = item.Exp
// field.Prefix = item.Prefix
// field.Postfix = item.Postfix
// field.Loop = item.Loop
// field.Loopfix = item.Loopfix
// field.Format = item.Format
// field.Type = item.Type
// field.Mode = item.Mode
// field.Length = item.Length
// field.LeftPad = item.LeftPad
// field.RightPad = item.RightPad
// field.Rand = item.Rand
//
// field.Config = item.Config
// field.Use = item.Use
// field.From = item.From
// field.Select = item.Select
// field.Where = item.Where
// field.Limit = item.Limit
//}
......@@ -90,21 +90,25 @@ func (s *InstancesService) updateYaml(id uint) (err error) {
return
}
func (s *InstancesService) genYaml(instances *model.ZdInstances) (str string) {
items, err := s.instancesRepo.GetItems(instances.ID)
if err != nil {
return
}
yamlObj := model.ResInsts{}
s.instancesRepo.GenInst(*instances, &yamlObj)
for _, item := range items {
inst := instancesItemToResInstForExport(*item)
yamlObj.Instances = append(yamlObj.Instances, inst)
//items, err := s.instancesRepo.GetItems(instances.ID)
//if err != nil {
// return
//}
//
//yamlObj := model.ResInsts{}
//s.instancesRepo.GenInst(*instances, &yamlObj)
//
//for _, item := range items {
// inst := instancesItemToResInstForExport(*item)
//
// yamlObj.Instances = append(yamlObj.Instances, inst)
//}
root := s.GetItemTree(instances.ID)
for _, item := range root.Fields {
instances.Instances = append(instances.Instances, *item)
}
bytes, err := yaml.Marshal(yamlObj)
bytes, _ := yaml.Marshal(instances)
instances.Yaml = stringUtils.ConvertYamlStringToMapFormat(bytes)
return
......
......@@ -5,7 +5,7 @@ import (
constant "github.com/easysoft/zendata/src/utils/const"
)
func (s *InstancesService) GetItemTree(instancesId int) (root model.ZdInstancesItem) {
func (s *InstancesService) GetItemTree(instancesId uint) (root model.ZdInstancesItem) {
root = s.instancesRepo.GetItemTree(uint(instancesId))
return
}
......
......@@ -475,7 +475,7 @@ func (s *Server) admin(writer http.ResponseWriter, req *http.Request) {
case "removeInstances":
err = s.instancesService.Remove(reqData.Id)
case "getResInstancesItemTree":
ret.Data = s.instancesService.GetItemTree(reqData.Id)
ret.Data = s.instancesService.GetItemTree(uint(reqData.Id))
case "getResInstancesItem":
ret.Data = s.instancesService.GetItem(reqData.Id)
case "createResInstancesItem":
......@@ -483,14 +483,14 @@ func (s *Server) admin(writer http.ResponseWriter, req *http.Request) {
ownerId := reqData.DomainId
item, err = s.instancesService.CreateItem(ownerId, reqData.Id, reqData.Mode)
ret.Data = s.instancesService.GetItemTree(ownerId)
ret.Data = s.instancesService.GetItemTree(uint(ownerId))
ret.Model = item
case "saveInstancesItem":
rangesItem := serverUtils.ConvertInstancesItem(reqData.Data)
ret.Data = s.instancesService.SaveItem(&rangesItem)
case "removeResInstancesItem":
err = s.instancesService.RemoveItem(reqData.Id)
ret.Data = s.instancesService.GetItemTree(reqData.DomainId)
ret.Data = s.instancesService.GetItemTree(uint(reqData.DomainId))
case "listExcel":
ret.Data, ret.Total = s.excelService.List(reqData.Keywords, reqData.Page)
......
title: _test-instacnes
desc: 实例测试
field: country
instances:
- field: ""
- field: instant1
note: 测试
range: ""
instance: ""
fields: []
froms: []
- field: ""
note: 测试
range: ""
instance: ""
fields: []
froms: []
- field: ""
range: ""
instance: ""
fields: []
froms: []
- field: ""
range: ""
instance: ""
fields: []
froms: []
- field: ""
range: ""
instance: ""
fields: []
froms: []
instance: instant1
fields:
- field: field1
note: 测试
fields:
- field: field1-1
range: 0-9
postfix: ','
- field: field1-2
range: a-z
- field: field2
range: A-Z
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册