diff --git a/api/v1/system/tools_gen_table.go b/api/v1/system/tools_gen_table.go index 1047cbe..92c9be5 100644 --- a/api/v1/system/tools_gen_table.go +++ b/api/v1/system/tools_gen_table.go @@ -101,6 +101,7 @@ type ToolsGenTableColumnsEditReq struct { TreeParentCode string `p:"tree_parent_code"` TreeName string `p:"tree_name"` ExcelPort string `p:"excelPort"` + UseSnowId string `p:"useSnowId"` } type ToolsGenTableColumnsEditRes struct { diff --git a/go.mod b/go.mod index 41e026b..97dcf37 100644 --- a/go.mod +++ b/go.mod @@ -64,6 +64,7 @@ require ( github.com/rivo/uniseg v0.4.4 // indirect github.com/satori/go.uuid v1.2.0 // indirect github.com/sirupsen/logrus v1.4.0 // indirect + github.com/sony/sonyflake v1.2.0 // indirect github.com/stathat/consistent v1.0.0 // indirect github.com/tidwall/gjson v1.13.0 // indirect github.com/tidwall/match v1.1.1 // indirect diff --git a/go.sum b/go.sum index fb25911..b602fe5 100644 --- a/go.sum +++ b/go.sum @@ -204,6 +204,8 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykE github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/sony/sonyflake v1.2.0 h1:Pfr3A+ejSg+0SPqpoAmQgEtNDAhc2G1SUYk205qVMLQ= +github.com/sony/sonyflake v1.2.0/go.mod h1:LORtCywH/cq10ZbyfhKrHYgAUGH7mOBa76enV9txy/Y= github.com/stathat/consistent v1.0.0 h1:ZFJ1QTRn8npNBKW065raSZ8xfOqhpb8vLOkfp4CcL/U= github.com/stathat/consistent v1.0.0/go.mod h1:uajTPbgSygZBJ+V+0mY7meZ8i0XAcZs7AQ6V121XSxw= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/internal/app/common/logic/logic.go b/internal/app/common/logic/logic.go index 0dcb5d0..127dd78 100644 --- a/internal/app/common/logic/logic.go +++ b/internal/app/common/logic/logic.go @@ -9,6 +9,7 @@ import ( _ "github.com/tiger1103/gfast/v3/internal/app/common/logic/cache" _ "github.com/tiger1103/gfast/v3/internal/app/common/logic/captcha" _ "github.com/tiger1103/gfast/v3/internal/app/common/logic/middleware" + _ "github.com/tiger1103/gfast/v3/internal/app/common/logic/snowIDGen" _ "github.com/tiger1103/gfast/v3/internal/app/common/logic/sysConfig" _ "github.com/tiger1103/gfast/v3/internal/app/common/logic/sysDictData" _ "github.com/tiger1103/gfast/v3/internal/app/common/logic/sysDictType" diff --git a/internal/app/common/logic/snowIDGen/snow_id.go b/internal/app/common/logic/snowIDGen/snow_id.go new file mode 100644 index 0000000..57b465e --- /dev/null +++ b/internal/app/common/logic/snowIDGen/snow_id.go @@ -0,0 +1,41 @@ +/* +* @desc:雪花ID生成 +* @company:云南奇讯科技有限公司 +* @Author: yixiaohu +* @Date: 2023/6/2 14:52 + */ + +package snowIDGen + +import ( + "github.com/gogf/gf/v2/os/gtime" + "github.com/sony/sonyflake" + "github.com/tiger1103/gfast/v3/internal/app/common/service" +) + +var machineID uint16 = 1 + +func init() { + service.RegisterSnowID(New()) +} + +func New() service.ISnowID { + return &sSnowID{ + sonyflake.NewSonyflake(sonyflake.Settings{ + StartTime: gtime.NewFromStr("2010-05-01").Time, + MachineID: GetMachineId, + }), + } +} + +type sSnowID struct { + *sonyflake.Sonyflake +} + +func (s *sSnowID) GenID() (uint64, error) { + return s.NextID() +} + +func GetMachineId() (uint16, error) { + return machineID, nil +} diff --git a/internal/app/common/service/snow_id_gen.go b/internal/app/common/service/snow_id_gen.go new file mode 100644 index 0000000..df506a3 --- /dev/null +++ b/internal/app/common/service/snow_id_gen.go @@ -0,0 +1,27 @@ +// ================================================================================ +// Code generated by GoFrame CLI tool. DO NOT EDIT. +// You can delete these comments if you wish manually maintain this interface file. +// ================================================================================ + +package service + +type ( + ISnowID interface { + GenID() (uint64, error) + } +) + +var ( + localSnowID ISnowID +) + +func SnowID() ISnowID { + if localSnowID == nil { + panic("implement not found for interface ISnowID, forgot register?") + } + return localSnowID +} + +func RegisterSnowID(i ISnowID) { + localSnowID = i +} diff --git a/internal/app/system/dao/internal/tools_gen_table.go b/internal/app/system/dao/internal/tools_gen_table.go index 839b963..b0946fc 100644 --- a/internal/app/system/dao/internal/tools_gen_table.go +++ b/internal/app/system/dao/internal/tools_gen_table.go @@ -38,6 +38,8 @@ type ToolsGenTableColumns struct { SortColumn string // 排序字段名 SortType string // 排序方式 (asc顺序 desc倒序) ShowDetail string // 是否有查看详情功能 + ExcelPort string // 是否有导入导出excel功能 + UseSnowId string //主键是否使用雪花ID } // toolsGenTableColumns holds the columns for table tools_gen_table. @@ -60,6 +62,8 @@ var toolsGenTableColumns = ToolsGenTableColumns{ SortColumn: "sort_column", SortType: "sort_type", ShowDetail: "show_detail", + ExcelPort: "excel_port", + UseSnowId: "use_snow_id", } // NewToolsGenTableDao creates and returns a new DAO object for table data access. diff --git a/internal/app/system/logic/sysUserOnline/sys_user_online.go b/internal/app/system/logic/sysUserOnline/sys_user_online.go index 262c3c5..4ead820 100644 --- a/internal/app/system/logic/sysUserOnline/sys_user_online.go +++ b/internal/app/system/logic/sysUserOnline/sys_user_online.go @@ -97,7 +97,7 @@ func (s *sSysUserOnline) CheckUserOnline(ctx context.Context) { }, }, } - var total int + for { var ( res *system.SysUserOnlineSearchRes @@ -113,12 +113,12 @@ func (s *sSysUserOnline) CheckUserOnline(ctx context.Context) { } for _, v := range res.List { if b := s.UserIsOnline(ctx, v.Token); !b { - s.DeleteOnlineByToken(ctx, v.Token) + err = s.DeleteOnlineByToken(ctx, v.Token) + if err != nil { + g.Log().Error(ctx, err) + } } } - if param.PageNum*param.PageSize >= total { - break - } param.PageNum++ } service.SysJobLog().Add(ctx, &do.SysJobLog{ diff --git a/internal/app/system/logic/toolsGenTable/tools_gen_table.go b/internal/app/system/logic/toolsGenTable/tools_gen_table.go index 07e6d02..27917c7 100644 --- a/internal/app/system/logic/toolsGenTable/tools_gen_table.go +++ b/internal/app/system/logic/toolsGenTable/tools_gen_table.go @@ -368,6 +368,9 @@ func (s *sToolsGenTable) SaveEdit(ctx context.Context, req *system.ToolsGenTable if req.ExcelPort != "" { table.ExcelPort = gconv.Bool(req.ExcelPort) } + if req.UseSnowId != "" { + table.UseSnowId = gconv.Bool(req.UseSnowId) + } if req.TplCategory != "" { table.TplCategory = req.TplCategory } @@ -758,7 +761,7 @@ func (s *sToolsGenTable) SelectRecordById(ctx context.Context, tableId int64) (t err = gconv.Struct(m1, columnEx) columnMap[columnName] = columnEx allColumnExs[i] = columnEx - tableEx.IsPkInsertable = tableEx.IsPkInsertable || column.IsPk && !column.IsIncrement + tableEx.IsPkInsertable = tableEx.IsPkInsertable || column.IsPk && !column.IsIncrement && !tableEx.UseSnowId tableEx.IsPkListable = tableEx.IsPkListable || column.IsPk && column.IsList if column.IsEdit && !service.ToolsGenTableColumn().IsNotEdit(columnName) && !column.IsPk { editColumns = append(editColumns, columnEx) @@ -1319,11 +1322,11 @@ func (s *sToolsGenTable) SyncTable(ctx context.Context, tableId int64) (err erro } // goFmt formats the source file and adds or removes import statements as necessary. -func (s *sToolsGenTable) goFmt(path string)(err error) { +func (s *sToolsGenTable) goFmt(path string) (err error) { replaceFunc := func(path, content string) string { res, err := imports.Process(path, []byte(content), nil) if err != nil { - g.Log().Printf(context.Background(),`error format "%s" go files: %v`, path, err) + g.Log().Printf(context.Background(), `error format "%s" go files: %v`, path, err) return content } return string(res) @@ -1339,7 +1342,7 @@ func (s *sToolsGenTable) goFmt(path string)(err error) { err = gfile.ReplaceDirFunc(replaceFunc, path, "*.go", true) } if err != nil { - err = fmt.Errorf(`error format "%s" go files: %v`, path, err) + err = fmt.Errorf(`error format "%s" go files: %v`, path, err) } return -} \ No newline at end of file +} diff --git a/internal/app/system/model/do/tools_gen_table.go b/internal/app/system/model/do/tools_gen_table.go index 519d3be..0d23c09 100644 --- a/internal/app/system/model/do/tools_gen_table.go +++ b/internal/app/system/model/do/tools_gen_table.go @@ -31,4 +31,5 @@ type ToolsGenTable struct { SortType interface{} // 排序方式 (asc顺序 desc倒序) ShowDetail interface{} // 是否有查看详情功能 ExcelPort interface{} // 是否有导入导出excel功能 + UseSnowId interface{} //主键是否使用雪花ID } diff --git a/internal/app/system/model/entity/tools_gen_table.go b/internal/app/system/model/entity/tools_gen_table.go index d836e2e..7d4e8c6 100644 --- a/internal/app/system/model/entity/tools_gen_table.go +++ b/internal/app/system/model/entity/tools_gen_table.go @@ -29,4 +29,5 @@ type ToolsGenTable struct { SortType string `json:"sortType" description:"排序方式 (asc顺序 desc倒序)"` ShowDetail bool `json:"showDetail" description:"是否有查看详情功能"` ExcelPort bool `json:"excelPort" description:"是否有excel导入导出功能"` + UseSnowId bool `json:"useSnowId" description:"主键是否使用雪花ID"` } diff --git a/internal/app/system/model/tools_gen_table.go b/internal/app/system/model/tools_gen_table.go index bcffa7b..779fcd3 100644 --- a/internal/app/system/model/tools_gen_table.go +++ b/internal/app/system/model/tools_gen_table.go @@ -36,6 +36,7 @@ type ToolsGenTableEx struct { SortType string // 缺省排序方式 (asc顺序 desc倒序) ShowDetail bool // 是否有查看详情功能 ExcelPort bool // 是否有导入导出excel功能 + UseSnowId bool // 主键是否使用雪花ID TreeCode string // 树编码字段 TreeParentCode string // 树父编码字段 TreeName string // 树名称字段 diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 573fe8c..86ff6ba 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -3,6 +3,7 @@ package cmd import ( "context" "fmt" + "github.com/gogf/gf/v2/encoding/gbase64" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" "github.com/gogf/gf/v2/net/goai" @@ -23,7 +24,7 @@ var ( Brief: "start http server", Func: func(ctx context.Context, parser *gcmd.Parser) (err error) { g.Log().SetFlags(glog.F_ASYNC | glog.F_TIME_DATE | glog.F_TIME_TIME | glog.F_FILE_LONG) - g.Log().Info(ctx, "GFast version:", consts.Version) + g.Log().Info(ctx, gbase64.MustDecodeString(consts.Logo), "Version:", consts.Version) s := g.Server() s.Group("/", func(group *ghttp.RouterGroup) { router.R.BindController(ctx, group) diff --git a/internal/consts/version.go b/internal/consts/version.go index ec2a9d3..d2fe685 100644 --- a/internal/consts/version.go +++ b/internal/consts/version.go @@ -8,5 +8,6 @@ package consts const ( - Version = "3.2.8" + Logo = `CiAgIF9fX19fX19fX19fXyAgICAgICAgICAgX18gCiAgLyBfX19fLyBfX19fL19fXyBfX19fX18vIC9fCiAvIC8gX18vIC9fICAvIF9fIGAvIF9fXy8gX18vCi8gL18vIC8gX18vIC8gL18vIChfXyAgKSAvXyAgClxfX19fL18vICAgIFxfXyxfL19fX18vXF9fLyAg` + Version = "3.2.9" ) diff --git a/library/upload/oss.go b/library/upload/oss.go index 992ba12..7213c74 100644 --- a/library/upload/oss.go +++ b/library/upload/oss.go @@ -23,11 +23,12 @@ import ( ) type OSS struct { - AccessKeyID string `json:"accessKeyId"` + AccessKeyID string `json:"accessKeyId"` AccessKeySecret string `json:"accessKeySecret"` - EndPoint string `json:"endPoint"` - BucketName string `json:"bucketName"` - IsHttps bool `json:"isHttps"` + EndPoint string `json:"endPoint"` + BucketName string `json:"bucketName"` + IsHttps bool `json:"isHttps"` + Path string `json:"path"` } func (s *OSS) Upload(ctx context.Context, file *ghttp.UploadFile) (result system.UploadResponse, err error) { @@ -35,27 +36,27 @@ func (s *OSS) Upload(ctx context.Context, file *ghttp.UploadFile) (result system var ( client *oss.Client bucket *oss.Bucket - fp multipart.File + fp multipart.File ) - err = g.Cfg().MustGet(ctx,"upload.oss").Scan(&s) - liberr.ErrIsNil(ctx,err) - client,err = s.getClient() - liberr.ErrIsNil(ctx,err) + err = g.Cfg().MustGet(ctx, "upload.oss").Scan(&s) + liberr.ErrIsNil(ctx, err) + client, err = s.getClient() + liberr.ErrIsNil(ctx, err) // 获取存储空间。 bucket, err = client.Bucket(s.BucketName) - liberr.ErrIsNil(ctx,err) + liberr.ErrIsNil(ctx, err) name := gfile.Basename(file.Filename) name = strings.ToLower(strconv.FormatInt(gtime.TimestampNano(), 36) + grand.S(6)) - name = name + gfile.Ext(file.Filename) - fp,err = file.Open() - liberr.ErrIsNil(ctx,err) - err = bucket.PutObject(name,fp) - liberr.ErrIsNil(ctx,err) + name = s.Path + "/" + name + gfile.Ext(file.Filename) + fp, err = file.Open() + liberr.ErrIsNil(ctx, err) + err = bucket.PutObject(name, fp) + liberr.ErrIsNil(ctx, err) schema := "http" if s.IsHttps { schema = "https" } - url :=schema+"://"+s.EndPoint+"/"+name + url := schema + "://" + s.EndPoint + "/" + name result = system.UploadResponse{ Size: file.Size, Path: url, @@ -67,12 +68,11 @@ func (s *OSS) Upload(ctx context.Context, file *ghttp.UploadFile) (result system return } - func (s *OSS) getClient() (client *oss.Client, err error) { // 设置连接数为10,每个主机的最大闲置连接数为20,每个主机的最大连接数为20。 - conn := oss.MaxConns(10,20,20) + conn := oss.MaxConns(10, 20, 20) // 设置HTTP连接超时时间为20秒,HTTP读取或写入超时时间为60秒。 - time := oss.Timeout(20,60) + time := oss.Timeout(20, 60) // 设置是否支持将自定义域名作为Endpoint,默认不支持。 cname := oss.UseCname(true) // 设置HTTP的User-Agent头,默认为aliyun-sdk-go。 @@ -88,6 +88,6 @@ func (s *OSS) getClient() (client *oss.Client, err error) { client, err = oss.New(s.EndPoint, s.AccessKeyID, s.AccessKeySecret, - conn,time,cname,userAgent,verifySsl,redirect,crc,logLevel) + conn, time, cname, userAgent, verifySsl, redirect, crc, logLevel) return } diff --git a/manifest/config/config.yaml.bak b/manifest/config/config.yaml.bak index 3432a5d..f05324b 100644 --- a/manifest/config/config.yaml.bak +++ b/manifest/config/config.yaml.bak @@ -107,6 +107,7 @@ upload: endPoint: "xxx.xxxx.com" #自定域名 bucketName: "xxx" #使用的存储桶 isHttps: true #是否开启https访问 + path:"gfast" #上传文件保存路径 # 代码生成配置 gen: diff --git a/resource/template/vm/go/logic.template b/resource/template/vm/go/logic.template index 8998d5a..10e97eb 100644 --- a/resource/template/vm/go/logic.template +++ b/resource/template/vm/go/logic.template @@ -17,6 +17,7 @@ package logic {{$usedSystemModule:=false}} {{$gstr:=false}} {{$hasLinkTable:=false}} +{{$useCommonService:=false}} {{range $index, $column := .table.Columns}} {{if eq $column.HtmlType "images" "file" "files"}} {{$libUtils = true}} @@ -33,7 +34,9 @@ package logic {{end}} {{end}} {{end}} - +{{if and .table.UseSnowId (not .table.IsPkInsertable)}} +{{$useCommonService = true}} +{{end}} import ( "context" "github.com/gogf/gf/v2/frame/g" @@ -43,6 +46,9 @@ import ( {{if or .table.HasConversion (eq .table.TplCategory "tree")}} "github.com/gogf/gf/v2/util/gconv" {{end}} + {{if $useCommonService}} + commonService "github.com/tiger1103/gfast/v3/internal/app/common/service" + {{end}} "{{.goModName}}/{{.table.PackageName}}/dao" "{{.goModName}}/{{.table.PackageName}}/model" "{{.goModName}}/{{.table.PackageName}}/model/do" @@ -358,6 +364,11 @@ func (s *s{{.table.ClassName}})GetBy{{$pkGoField}}(ctx context.Context, {{$.tabl //// func (s *s{{.table.ClassName}})Add(ctx context.Context, req *model.{{.table.ClassName}}AddReq) (err error){ err = g.Try(ctx, func(ctx context.Context) { + {{if and .table.UseSnowId (not .table.IsPkInsertable)}} + var {{.table.PkColumn.HtmlField}} uint64 + {{.table.PkColumn.HtmlField}}, err = commonService.SnowID().GenID() + liberr.ErrIsNil(ctx, err) + {{end}} {{range $index, $column := .table.EditColumns}} {{if eq $column.HtmlType "checkbox" "selects" "treeSelects"}} {{$column.HtmlField}} := "" @@ -375,6 +386,8 @@ func (s *s{{.table.ClassName}})Add(ctx context.Context, req *model.{{.table.Clas _, err = dao.{{.table.ClassName}}.Ctx(ctx).Insert(do.{{.table.ClassName}}{ {{if .table.IsPkInsertable}} {{.table.PkColumn.GoField}}:req.{{.table.PkColumn.GoField}}, + {{else if .table.UseSnowId}} + {{.table.PkColumn.GoField}}:{{.table.PkColumn.HtmlField}}, {{end}} {{range $index, $column := .table.EditColumns}} {{if eq $column.HtmlType "checkbox" "selects" "treeSelects"}} diff --git a/resource/template/vm/go/model.template b/resource/template/vm/go/model.template index 9dfb4fa..28dadbb 100644 --- a/resource/template/vm/go/model.template +++ b/resource/template/vm/go/model.template @@ -54,7 +54,7 @@ import ( type {{.table.ClassName}}InfoRes struct { gmeta.Meta `orm:"table:{{.table.TableName}}"` {{range $index, $column := .table.Columns}} - {{if $column.IsPk}}{{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else}}{{$column.GoType}}{{end}} `orm:"{{$column.ColumnName}},primary" json:"{{$column.HtmlField}}" dc:"{{$column.ColumnComment}}"` // {{$column.ColumnComment}} {{else}}{{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else}}{{$column.GoType}}{{end}} `orm:"{{$column.ColumnName}}" json:"{{$column.HtmlField}}" dc:"{{$column.ColumnComment}}"` // {{$column.ColumnComment}} {{end}} + {{if $column.IsPk}}{{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else}}{{$column.GoType}}{{end}} `orm:"{{$column.ColumnName}},primary" json:"{{$column.HtmlField}}{{if $.table.UseSnowId}},string{{end}}" dc:"{{$column.ColumnComment}}"` // {{$column.ColumnComment}} {{else}}{{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else}}{{$column.GoType}}{{end}} `orm:"{{$column.ColumnName}}" json:"{{$column.HtmlField}}" dc:"{{$column.ColumnComment}}"` // {{$column.ColumnComment}} {{end}} {{range $ti, $linkedTable := $.table.LinkedTables}} {{if eq $column.LinkTableClass $linkedTable.ClassName}} Linked{{$column.GoField}} {{if eq $column.HtmlType "selects" "checkbox" "treeSelects"}}[]{{end}}*Linked{{$.table.ClassName}}{{$linkedTable.ClassName}} `{{if not (eq $column.HtmlType "selects" "checkbox" "treeSelects")}}orm:"with:{{$column.LinkLabelId}}={{$column.ColumnName}}" {{end}}json:"linked{{$column.GoField}}"` @@ -69,7 +69,6 @@ type {{.table.ClassName}}InfoRes struct { {{end}} } -//// {{range $ti, $linkedTable := .table.LinkedTables}} type Linked{{$.table.ClassName}}{{$linkedTable.ClassName}} struct { gmeta.Meta `orm:"table:{{$linkedTable.TableName}}"` @@ -88,7 +87,7 @@ type {{.table.ClassName}}ListRes struct{ {{if eq .table.TplCategory "tree"}} {{range $index, $column := .table.Columns}} {{if or (eq $column.HtmlField $.table.TreeCode) (eq $column.HtmlField $.table.TreeParentCode) (eq $column.HtmlField $.table.TreeName) }} - {{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else}}{{$column.GoType}}{{end}} `json:"{{$column.HtmlField}}" dc:"{{$column.ColumnComment}}"` + {{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else}}{{$column.GoType}}{{end}} `json:"{{$column.HtmlField}}{{if and $column.IsPk $.table.UseSnowId}},string{{end}}" dc:"{{$column.ColumnComment}}"` {{end}} {{end}} {{range $index, $column := .table.Columns}} @@ -109,7 +108,7 @@ type {{.table.ClassName}}ListRes struct{ {{end}} {{else}} {{if not .table.IsPkListable }} - {{.table.PkColumn.GoField}} {{.table.PkColumn.GoType}} `json:"{{.table.PkColumn.HtmlField}}" dc:"{{.table.PkColumn.ColumnComment}}"` + {{.table.PkColumn.GoField}} {{.table.PkColumn.GoType}} `json:"{{.table.PkColumn.HtmlField}}{{if $.table.UseSnowId}},string{{end}}" dc:"{{.table.PkColumn.ColumnComment}}"` {{end}} {{range $index, $column := .table.ListColumns}} {{if eq $column.HtmlField "createdBy"}} @@ -118,7 +117,7 @@ type {{.table.ClassName}}ListRes struct{ {{if eq $column.HtmlField "updatedBy"}} UpdatedUser *{{if $hasUser}}systemModel.{{end}}LinkUserRes `orm:"with:id=updated_by" json:"updatedBy"` {{end}} - {{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else}}{{$column.GoType}}{{end}} `json:"{{$column.HtmlField}}" dc:"{{$column.ColumnComment}}"` + {{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else}}{{$column.GoType}}{{end}} `json:"{{$column.HtmlField}}{{if and $column.IsPk $.table.UseSnowId}},string{{end}}" dc:"{{$column.ColumnComment}}"` {{range $ti, $linkedTable := $.table.LinkedTables}} {{if eq $column.LinkTableClass $linkedTable.ClassName}} Linked{{$column.GoField}} {{if eq $column.HtmlType "selects" "checkbox" "treeSelects"}}[]{{end}}*Linked{{$.table.ClassName}}{{$linkedTable.ClassName}} `{{if not (eq $column.HtmlType "selects" "checkbox" "treeSelects")}}orm:"with:{{$column.LinkLabelId}}={{$column.ColumnName}}" {{end}}json:"linked{{$column.GoField}}" dc:"{{$column.ColumnComment}}"` @@ -128,7 +127,7 @@ type {{.table.ClassName}}ListRes struct{ {{end}} } - +//// // {{.table.ClassName}}SearchReq 分页请求参数 type {{.table.ClassName}}SearchReq struct { {{if ne $.table.ModuleName "common"}} @@ -139,14 +138,16 @@ type {{.table.ClassName}}SearchReq struct { {{end}} } - +//// // {{.table.ClassName}}SearchRes 列表返回结果 type {{.table.ClassName}}SearchRes struct { comModel.ListRes List []*{{.table.ClassName}}ListRes `json:"list"` } + {{if gt (len .table.LinkedTables) 0}} +//// //相关连表查询数据 type Linked{{$.table.ClassName}}DataSearchRes struct{ {{range $ti, $linkedTable := .table.LinkedTables}} @@ -155,7 +156,7 @@ type Linked{{$.table.ClassName}}DataSearchRes struct{ } {{end}} - +//// // {{.table.ClassName}}AddReq 添加操作请求参数 type {{.table.ClassName}}AddReq struct { {{if .table.IsPkInsertable}} @@ -169,7 +170,7 @@ type {{.table.ClassName}}AddReq struct { {{end}} } - +//// // {{.table.ClassName}}EditReq 修改操作请求参数 type {{.table.ClassName}}EditReq struct { {{.table.PkColumn.GoField}} {{.table.PkColumn.GoType}} `p:"{{.table.PkColumn.HtmlField}}" v:"required#主键ID不能为空" dc:"{{.table.PkColumn.ColumnComment}}"` diff --git a/resource/template/vm/go/model_entity.template b/resource/template/vm/go/model_entity.template index d7b26ea..8b2359f 100644 --- a/resource/template/vm/go/model_entity.template +++ b/resource/template/vm/go/model_entity.template @@ -23,7 +23,7 @@ import ( type {{.table.ClassName}} struct { gmeta.Meta `orm:"table:{{.table.TableName}}"` {{range $index, $column := .table.Columns}} - {{if $column.IsPk}}{{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else}}{{$column.GoType}}{{end}} `orm:"{{$column.ColumnName}},primary" json:"{{$column.HtmlField}}"` // {{$column.ColumnComment}} {{else}}{{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else}}{{$column.GoType}}{{end}} `orm:"{{$column.ColumnName}}" json:"{{$column.HtmlField}}"` // {{$column.ColumnComment}} {{end}} + {{if $column.IsPk}}{{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else}}{{$column.GoType}}{{end}} `orm:"{{$column.ColumnName}},primary" json:"{{$column.HtmlField}}{{if $.table.UseSnowId}},string{{end}}"` // {{$column.ColumnComment}} {{else}}{{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else}}{{$column.GoType}}{{end}} `orm:"{{$column.ColumnName}}" json:"{{$column.HtmlField}}"` // {{$column.ColumnComment}} {{end}} {{if ne $column.LinkTableName ""}} {{range $ti, $linkedTable := $.table.LinkedTables}} {{if eq $column.LinkTableClass $linkedTable.ClassName}}