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

load instances yaml to db

上级 3ae2d730
......@@ -81,7 +81,7 @@ fields:
- field: field_loop # 自循环的字段。
range: a-z # a|b|c ...
loop: 3 # 循环三次
loopfix: _ # 每次循环的连接符。
loopfix: "|" # 每次循环的连接符。
postfix: "\t"
- field: field_repeat # 通过{}定义重复的元素。
......@@ -89,12 +89,12 @@ fields:
postfix: "\t"
- field: field_format # 通过格式化字符串输出。
range: 1-10 # passwd 1,passwd 2,passwd 3 ... passwd10。
range: 1-10 # passwd01,passwd02,passwd03 ... passwd10。
format: "passwd%02d" # 用%02d补零,使密码整体保持8位。
postfix: "\t"
- field: field_length # 指定宽度。
range: 1-99 # 01\t,02\t,03\t..., 99\t
range: 1-99 # 001\t;002\t;003\t...;099\t
length: 3 # 包含前后缀的宽度。
leftpad: 0 # 宽度不够时,补充的字符。
postfix: "\t"
......@@ -147,4 +147,4 @@ fields:
- field: field_grandson
prefix: int_
range: 10-20
postfix:
\ No newline at end of file
postfix:
......@@ -197,9 +197,9 @@ type ZdInstancesItem struct {
Where string `gorm:"column:whereCol" json:"whereCol"`
Limit int `gorm:"column:limitCol" json:"limitCol"`
Ord int `gorm:"column:ord;default:1" json:"ord"`
Children []*ZdInstancesItem `gorm:"-" json:"children"`
Froms []*ZdInstancesItem `gorm:"-" json:"froms"`
Ord int `gorm:"column:ord;default:1" json:"ord"`
Fields []*ZdInstancesItem `gorm:"-" json:"fields"`
Froms []*ZdInstancesItem `gorm:"-" json:"froms"`
// for range edit
IsRange bool `gorm:"column:isRange;default:true" json:"isRange"`
......
......@@ -6,6 +6,8 @@ import (
constant "github.com/easysoft/zendata/src/utils/const"
logUtils "github.com/easysoft/zendata/src/utils/log"
stringUtils "github.com/easysoft/zendata/src/utils/string"
"gopkg.in/yaml.v3"
"io/ioutil"
)
type InstancesService struct {
......@@ -56,7 +58,7 @@ func (s *InstancesService) GetItemTree(rangesId int) (root model.ZdInstancesItem
root.Field = "实例"
for _, item := range items {
item.ParentID = root.ID
root.Children = append(root.Children, item)
root.Fields = append(root.Fields, item)
}
return
......@@ -91,15 +93,38 @@ func (s *InstancesService) saveResToDB(instances []model.ResFile, list []*model.
names = append(names, item.Path)
}
for _, item := range instances {
if !stringUtils.FindInArrBool(item.Path, names) {
instances := model.ZdInstances{Title: item.Title, Name: item.Name, Desc: item.Desc, Path: item.Path}
s.instancesRepo.Save(&instances)
for _, inst := range instances {
if !stringUtils.FindInArrBool(inst.Path, names) {
//if strings.Contains(inst.Path, "aaa") {
content, _ := ioutil.ReadFile(inst.Path)
yamlContent := stringUtils.ReplaceSpecialChars(content)
instPo := model.ZdInstances{}
err = yaml.Unmarshal(yamlContent, &instPo)
instPo.Title = inst.Title
instPo.Name = inst.Name
instPo.Desc = inst.Desc
instPo.Path = inst.Path
s.instancesRepo.Save(&instPo)
for _, item := range instPo.Instances {
s.saveItemToDB(&item, 0, instPo.ID)
}
//}
}
}
return
}
func (s *InstancesService) saveItemToDB(item *model.ZdInstancesItem, parentID, instancesID uint) {
item.InstancesID = instancesID
item.ParentID = parentID
s.instancesRepo.SaveItem(item)
for _, child := range item.Fields {
s.saveItemToDB(child, item.ID, instancesID)
}
}
func NewInstancesService(instancesRepo *serverRepo.InstancesRepo, referRepo *serverRepo.ReferRepo) *InstancesService {
return &InstancesService{instancesRepo: instancesRepo, referRepo: referRepo}
......
无法预览此类型文件
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册