Skip to content

Commit e0c15cc

Browse files
author
piexlmax
committed
自动化代码结构体无需手动添加time包
1 parent 68317c1 commit e0c15cc

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

server/model/system/sys_auto_code.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type AutoCodeStruct struct {
1717
AutoCreateApiToSql bool `json:"autoCreateApiToSql"` // 是否自动创建api
1818
AutoMoveFile bool `json:"autoMoveFile"` // 是否自动移动文件
1919
Fields []*Field `json:"fields,omitempty"`
20+
HasTimer bool
2021
DictTypes []string `json:"-"`
2122
Package string `json:"package"`
2223
PackageT string `json:"-"`

server/resource/autocode_template/server/model.go.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package {{.Package}}
33

44
import (
55
"github.com/flipped-aurora/gin-vue-admin/server/global"
6+
{{ if .HasTimer }}"time"{{ end }}
67
)
78

89
// {{.StructName}} 结构体
9-
// 如果含有time.Time 请自行import time包
1010
type {{.StructName}} struct {
1111
global.GVA_MODEL {{- range .Fields}}
1212
{{- if eq .FieldType "enum" }}

server/service/system/sys_auto_code.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ var AutoCodeServiceApp = new(AutoCodeService)
149149

150150
func (autoCodeService *AutoCodeService) PreviewTemp(autoCode system.AutoCodeStruct) (map[string]string, error) {
151151
makeDictTypes(&autoCode)
152+
for i := range autoCode.Fields {
153+
if autoCode.Fields[i].FieldType == "time.Time" {
154+
autoCode.HasTimer = true
155+
break
156+
}
157+
}
152158
dataList, _, needMkdir, err := autoCodeService.getNeedList(&autoCode)
153159
if err != nil {
154160
return nil, err
@@ -228,6 +234,12 @@ func makeDictTypes(autoCode *system.AutoCodeStruct) {
228234

229235
func (autoCodeService *AutoCodeService) CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) {
230236
makeDictTypes(&autoCode)
237+
for i := range autoCode.Fields {
238+
if autoCode.Fields[i].FieldType == "time.Time" {
239+
autoCode.HasTimer = true
240+
break
241+
}
242+
}
231243
// 增加判断: 重复创建struct
232244
if autoCode.AutoMoveFile && AutoCodeHistoryServiceApp.Repeat(autoCode.StructName, autoCode.Package) {
233245
return RepeatErr

0 commit comments

Comments
 (0)