diff --git a/LICENSE.md b/LICENSE.md index 2e5981c..36b35f4 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 wenjianzhang +Copyright (c) 2020 go-admin-team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.Zh-cn.md b/README.Zh-cn.md index 9447895..7d38d5e 100644 --- a/README.Zh-cn.md +++ b/README.Zh-cn.md @@ -74,9 +74,9 @@ ### 轻松实现go-admin写出第一个应用 - 文档教程 -[步骤一 - 基础内容介绍](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial01.html) +[步骤一 - 基础内容介绍](https://doc.zhangwj.com/guide/intro/tutorial01.html) -[步骤二 - 实际应用 - 编写增删改查](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial02.html) +[步骤二 - 实际应用 - 编写增删改查](https://doc.zhangwj.com/guide/intro/tutorial02.html) ### 手把手教你从入门到放弃 - 视频教程 diff --git a/README.md b/README.md index 4338902..427fa13 100644 --- a/README.md +++ b/README.md @@ -68,9 +68,9 @@ At the same time, a series of tutorials including videos and documents are provi ### Easily implement go-admin to write the first application-documentation tutorial -[Step 1 - basic content introduction](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial01.html) +[Step 1 - basic content introduction](https://doc.zhangwj.com/guide/intro/tutorial01.html) -[Step 2 - Practical application - writing database operations](http://doc.zhangwj.com/go-admin-site/guide/intro/tutorial02.html) +[Step 2 - Practical application - writing database operations](https://doc.zhangwj.com/guide/intro/tutorial02.html) ### Teach you from getting started to giving up-video tutorial diff --git a/app/admin/apis/sys_user.go b/app/admin/apis/sys_user.go index 16fcff1..5f669f7 100644 --- a/app/admin/apis/sys_user.go +++ b/app/admin/apis/sys_user.go @@ -2,6 +2,7 @@ package apis import ( "github.com/gin-gonic/gin/binding" + "github.com/go-admin-team/go-admin-core/sdk/config" "go-admin/app/admin/models" "net/http" @@ -30,7 +31,7 @@ type SysUser struct { // @Security Bearer func (e SysUser) GetPage(c *gin.Context) { s := service.SysUser{} - req :=dto.SysUserGetPageReq{} + req := dto.SysUserGetPageReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req). @@ -67,7 +68,7 @@ func (e SysUser) GetPage(c *gin.Context) { // @Security Bearer func (e SysUser) Get(c *gin.Context) { s := service.SysUser{} - req :=dto.SysUserById{} + req := dto.SysUserById{} err := e.MakeContext(c). MakeOrm(). Bind(&req, nil). @@ -101,7 +102,7 @@ func (e SysUser) Get(c *gin.Context) { // @Security Bearer func (e SysUser) Insert(c *gin.Context) { s := service.SysUser{} - req :=dto.SysUserInsertReq{} + req := dto.SysUserInsertReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req, binding.JSON). @@ -136,7 +137,7 @@ func (e SysUser) Insert(c *gin.Context) { // @Security Bearer func (e SysUser) Update(c *gin.Context) { s := service.SysUser{} - req :=dto.SysUserUpdateReq{} + req := dto.SysUserUpdateReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req). @@ -171,7 +172,7 @@ func (e SysUser) Update(c *gin.Context) { // @Security Bearer func (e SysUser) Delete(c *gin.Context) { s := service.SysUser{} - req :=dto.SysUserById{} + req := dto.SysUserById{} err := e.MakeContext(c). MakeOrm(). Bind(&req, binding.JSON). @@ -208,7 +209,7 @@ func (e SysUser) Delete(c *gin.Context) { // @Security Bearer func (e SysUser) InsetAvatar(c *gin.Context) { s := service.SysUser{} - req :=dto.UpdateSysUserAvatarReq{} + req := dto.UpdateSysUserAvatarReq{} err := e.MakeContext(c). MakeOrm(). MakeService(&s.Service). @@ -257,7 +258,7 @@ func (e SysUser) InsetAvatar(c *gin.Context) { // @Security Bearer func (e SysUser) UpdateStatus(c *gin.Context) { s := service.SysUser{} - req :=dto.UpdateSysUserStatusReq{} + req := dto.UpdateSysUserStatusReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req, binding.JSON, nil). @@ -294,7 +295,7 @@ func (e SysUser) UpdateStatus(c *gin.Context) { // @Security Bearer func (e SysUser) ResetPwd(c *gin.Context) { s := service.SysUser{} - req :=dto.ResetSysUserPwdReq{} + req := dto.ResetSysUserPwdReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req, binding.JSON). @@ -311,16 +312,23 @@ func (e SysUser) ResetPwd(c *gin.Context) { //数据权限检查 p := actions.GetPermissionFromContext(c) + if req.UserId == 1 && config.ApplicationConfig.Mode == "demo" { + req.Password = "123456" + } err = s.ResetPwd(&req, p) if err != nil { e.Logger.Error(err) return } - e.OK(req.GetId(), "更新成功") + if req.UserId == 1 && config.ApplicationConfig.Mode == "demo" { + e.OK(req.GetId(), "admin:现在使用的预览环境,休想改掉我!否则会影响其他朋友体验的哦!可以创建其他用户体验该功能!") + } else { + e.OK(req.GetId(), "更新成功") + } } // UpdatePwd -// @Summary 重置密码 +// @Summary 修改密码 // @Description 获取JSON // @Tags 用户 // @Accept application/json @@ -331,7 +339,7 @@ func (e SysUser) ResetPwd(c *gin.Context) { // @Security Bearer func (e SysUser) UpdatePwd(c *gin.Context) { s := service.SysUser{} - req :=dto.PassWord{} + req := dto.PassWord{} err := e.MakeContext(c). MakeOrm(). Bind(&req). @@ -345,14 +353,20 @@ func (e SysUser) UpdatePwd(c *gin.Context) { // 数据权限检查 p := actions.GetPermissionFromContext(c) - + if user.GetUserId(c) == 1 && config.ApplicationConfig.Mode == "demo" { + req.NewPassword = "123456" + } err = s.UpdatePwd(user.GetUserId(c), req.OldPassword, req.NewPassword, p) if err != nil { e.Logger.Error(err) e.Error(http.StatusForbidden, err, "密码修改失败") return } - e.OK(nil, "密码修改成功") + if user.GetUserId(c) == 1 && config.ApplicationConfig.Mode == "demo" { + e.OK(nil, "admin:现在使用的预览环境,休想改掉我!否则会影响其他朋友体验的哦!可以创建其他用户体验该功能!") + } else { + e.OK(nil, "密码修改成功") + } } // GetProfile @@ -364,7 +378,7 @@ func (e SysUser) UpdatePwd(c *gin.Context) { // @Security Bearer func (e SysUser) GetProfile(c *gin.Context) { s := service.SysUser{} - req :=dto.SysUserById{} + req := dto.SysUserById{} err := e.MakeContext(c). MakeOrm(). MakeService(&s.Service). @@ -401,7 +415,7 @@ func (e SysUser) GetProfile(c *gin.Context) { // @Router /api/v1/getinfo [get] // @Security Bearer func (e SysUser) GetInfo(c *gin.Context) { - req :=dto.SysUserById{} + req := dto.SysUserById{} s := service.SysUser{} r := service.SysRole{} err := e.MakeContext(c). @@ -450,4 +464,4 @@ func (e SysUser) GetInfo(c *gin.Context) { mp["name"] = sysUser.NickName mp["code"] = 200 e.OK(mp, "") -} \ No newline at end of file +} diff --git a/app/admin/service/sys_role.go b/app/admin/service/sys_role.go index d5879a3..c1f1853 100644 --- a/app/admin/service/sys_role.go +++ b/app/admin/service/sys_role.go @@ -227,7 +227,7 @@ func (e *SysRole) UpdateDataScope(c *dto.RoleDataScopeReq) *SysRole { var dlist = make([]models.SysDept, 0) var model = models.SysRole{} tx.Preload("SysDept").First(&model, c.RoleId) - tx.Where("id in ?", c.DeptIds).Find(&dlist) + tx.Where("dept_id in ?", c.DeptIds).Find(&dlist) err = tx.Model(&model).Association("SysDept").Delete(model.SysDept) if err != nil { e.Log.Errorf("delete SysDept error:%s", err) diff --git a/app/admin/service/sys_user.go b/app/admin/service/sys_user.go index 24a6e28..e09f9d1 100644 --- a/app/admin/service/sys_user.go +++ b/app/admin/service/sys_user.go @@ -127,8 +127,7 @@ func (e *SysUser) UpdateAvatar(c *dto.UpdateSysUserAvatarReq, p *actions.DataPer return errors.New("无权更新该数据") } - c.Generate(&model) - err = e.Orm.Save(&model).Error + err = e.Orm.Table(model.TableName()).Where("user_id =? ", c.UserId).Updates(c).Error if err != nil { e.Log.Errorf("Service UpdateSysUser error: %s", err) return err @@ -151,8 +150,7 @@ func (e *SysUser) UpdateStatus(c *dto.UpdateSysUserStatusReq, p *actions.DataPer return errors.New("无权更新该数据") } - c.Generate(&model) - err = e.Orm.Save(&model).Error + err = e.Orm.Table(model.TableName()).Where("user_id =? ", c.UserId).Updates(c).Error if err != nil { e.Log.Errorf("Service UpdateSysUser error: %s", err) return err @@ -174,8 +172,7 @@ func (e *SysUser) ResetPwd(c *dto.ResetSysUserPwdReq, p *actions.DataPermission) if db.RowsAffected == 0 { return errors.New("无权更新该数据") } - c.Generate(&model) - err = e.Orm.Save(&model).Error + err = e.Orm.Table(model.TableName()).Where("user_id =? ", c.UserId).Updates(c).Error if err != nil { e.Log.Errorf("At Service ResetSysUserPwd error: %s", err) return err diff --git a/common/file_store/initialize.go b/common/file_store/initialize.go index 2190b21..fabce9f 100644 --- a/common/file_store/initialize.go +++ b/common/file_store/initialize.go @@ -1,13 +1,45 @@ package file_store -type FileStore struct { +import "fmt" + +type OXS struct { + // Endpoint 访问域名 + Endpoint string + // AccessKeyID AK + AccessKeyID string + // AccessKeySecret AKS + AccessKeySecret string + // BucketName 桶名称 + BucketName string } -// Setup 配置数据库 -func (e *FileStore) Setup(driver string) { - //fileStoreType := driver - //if fileStoreType == "ALiYunOSS" { - // var store = new(ALiYunOSS) - // store.Setup() - //} +// Setup 配置文件存储driver +func (e *OXS) Setup(driver DriverType, options ...ClientOption) FileStoreType { + fileStoreType := driver + var fileStore FileStoreType + switch fileStoreType { + case AliYunOSS: + fileStore = new(ALiYunOSS) + err := fileStore.Setup(e.Endpoint, e.AccessKeyID, e.AccessKeySecret, e.BucketName) + if err != nil { + fmt.Println(err) + } + return fileStore + case HuaweiOBS: + fileStore = new(HuaWeiOBS) + err := fileStore.Setup(e.Endpoint, e.AccessKeyID, e.AccessKeySecret, e.BucketName) + if err != nil { + fmt.Println(err) + } + return fileStore + case QiNiuKodo: + fileStore = new(QiNiuKODO) + err := fileStore.Setup(e.Endpoint, e.AccessKeyID, e.AccessKeySecret, e.BucketName) + if err != nil { + fmt.Println(err) + } + return fileStore + } + + return nil } diff --git a/common/file_store/interface.go b/common/file_store/interface.go index 5ba5c42..acecbe9 100644 --- a/common/file_store/interface.go +++ b/common/file_store/interface.go @@ -1,6 +1,27 @@ package file_store +// DriverType 驱动类型 +type DriverType string + +const ( + // HuaweiOBS 华为云OBS + HuaweiOBS DriverType = "HuaweiOBS" + // AliYunOSS 阿里云OSS + AliYunOSS DriverType = "AliYunOSS" + // QiNiuKodo 七牛云kodo + QiNiuKodo DriverType = "QiNiuKodo" +) + +type ClientOption map[string]interface{} + +// TODO: FileStoreType名称待定 + +// FileStoreType OXS type FileStoreType interface { - Setup() error - UpLoad(yourObjectName string, localFile string) error + // Setup 装载 endpoint sss + Setup(endpoint, accessKeyID, accessKeySecret, BucketName string, options ...ClientOption) error + // UpLoad 上传 + UpLoad(yourObjectName string, localFile interface{}) error + // GetTempToken 获取临时Token + GetTempToken() (string, error) } diff --git a/common/file_store/kodo.go b/common/file_store/kodo.go new file mode 100644 index 0000000..db896e2 --- /dev/null +++ b/common/file_store/kodo.go @@ -0,0 +1,111 @@ +package file_store + +import ( + "context" + "fmt" + "github.com/qiniu/go-sdk/v7/auth/qbox" + "github.com/qiniu/go-sdk/v7/storage" +) + +type Zone string + +const ( + // HuaDong 华东 + HuaDong Zone = "HuaDong" + // HuaBei 华北 + HuaBei Zone = "HuaBei" + // HuaNan 华南 + HuaNan Zone = "HuaNan" + // BeiMei 北美 + BeiMei Zone = "BeiMei" + // XinJiaPo 新加坡 + XinJiaPo Zone = "XinJiaPo" +) + +type QiNiuKODO struct { + Client interface{} + BucketName string + cfg storage.Config + options []ClientOption +} + +func (e *QiNiuKODO) getToken() string { + putPolicy := storage.PutPolicy{ + Scope: e.BucketName, + } + if len(e.options) > 0 && e.options[0]["Expires"] != nil { + putPolicy.Expires = e.options[0]["Expires"].(uint64) + } + upToken := putPolicy.UploadToken(e.Client.(*qbox.Mac)) + return upToken +} + +//Setup 装载 +//endpoint sss +func (e *QiNiuKODO) Setup(endpoint, accessKeyID, accessKeySecret, BucketName string, options ...ClientOption) error { + + mac := qbox.NewMac(accessKeyID, accessKeySecret) + // 获取存储空间。 + cfg := storage.Config{} + // 空间对应的机房 + e.setZoneORDefault(cfg, options...) + // 是否使用https域名 + cfg.UseHTTPS = true + // 上传是否使用CDN上传加速 + cfg.UseCdnDomains = false + + e.Client = mac + e.BucketName = BucketName + e.cfg = cfg + e.options = options + return nil +} + +// setZoneORDefault 设置Zone或者默认华东 +func (e *QiNiuKODO) setZoneORDefault(cfg storage.Config, options ...ClientOption) { + if len(options) > 0 && options[0]["Zone"] != nil { + if _, ok := options[0]["Zone"].(Zone); !ok { + cfg.Zone = &storage.ZoneHuadong + } + switch options[0]["Zone"].(Zone) { + case HuaDong: + cfg.Zone = &storage.ZoneHuadong + case HuaBei: + cfg.Zone = &storage.ZoneHuabei + case HuaNan: + cfg.Zone = &storage.ZoneHuanan + case BeiMei: + cfg.Zone = &storage.ZoneBeimei + case XinJiaPo: + cfg.Zone = &storage.ZoneXinjiapo + default: + cfg.Zone = &storage.ZoneHuadong + } + } +} + +// UpLoad 文件上传 +func (e *QiNiuKODO) UpLoad(yourObjectName string, localFile interface{}) error { + + // 构建表单上传的对象 + formUploader := storage.NewFormUploader(&e.cfg) + ret := storage.PutRet{} + // 可选配置 + putExtra := storage.PutExtra{ + Params: map[string]string{ + "x:name": "github logo", + }, + } + err := formUploader.PutFile(context.Background(), &ret, e.getToken(), yourObjectName, localFile.(string), &putExtra) + if err != nil { + fmt.Println(err) + return err + } + fmt.Println(ret.Key, ret.Hash) + return nil +} + +func (e *QiNiuKODO) GetTempToken() (string, error) { + token := e.getToken() + return token, nil +} diff --git a/common/file_store/kodo_test.go b/common/file_store/kodo_test.go new file mode 100644 index 0000000..a8767ae --- /dev/null +++ b/common/file_store/kodo_test.go @@ -0,0 +1,23 @@ +package file_store + +import ( + "testing" +) + +func TestKODOUpload(t *testing.T) { + e := OXS{"", "", "", ""} + var oxs = e.Setup(QiNiuKodo, map[string]interface{}{"Zone": "华东"}) + err := oxs.UpLoad("test.png", "./test.png") + if err != nil { + t.Error(err) + } + t.Log("ok") +} + +func TestKODOGetTempToken(t *testing.T) { + e := OXS{"", "", "", ""} + var oxs = e.Setup(QiNiuKodo, map[string]interface{}{"Zone": "华东"}) + token, _ := oxs.GetTempToken() + t.Log(token) + t.Log("ok") +} diff --git a/common/file_store/obs.go b/common/file_store/obs.go new file mode 100644 index 0000000..e937729 --- /dev/null +++ b/common/file_store/obs.go @@ -0,0 +1,52 @@ +package file_store + +import ( + "fmt" + "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs" + "log" +) + +type HuaWeiOBS struct { + Client interface{} + BucketName string +} + +func (e *HuaWeiOBS) Setup(endpoint, accessKeyID, accessKeySecret, BucketName string, options ...ClientOption) error { + // 创建ObsClient结构体 + client, err := obs.New(accessKeyID, accessKeySecret, endpoint) + if err != nil { + log.Println("Error:", err) + return err + } + e.Client = client + e.BucketName = BucketName + return nil +} + +// UpLoad 文件上传 +// yourObjectName 文件路径名称,与objectKey是同一概念,表示断点续传上传文件到OSS时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg +func (e *HuaWeiOBS) UpLoad(yourObjectName string, localFile interface{}) error { + // 获取存储空间。 + input := &obs.PutFileInput{} + input.Bucket = e.BucketName + input.Key = yourObjectName + input.SourceFile = localFile.(string) + output, err := e.Client.(*obs.ObsClient).PutFile(input) + + if err == nil { + fmt.Printf("RequestId:%s\n", output.RequestId) + fmt.Printf("ETag:%s, StorageClass:%s\n", output.ETag, output.StorageClass) + } else { + if obsError, ok := err.(obs.ObsError); ok { + fmt.Println(obsError.Code) + fmt.Println(obsError.Message) + } else { + fmt.Println(err) + } + } + return nil +} + +func (e *HuaWeiOBS) GetTempToken() (string, error) { + return "", nil +} diff --git a/common/file_store/obs_test.go b/common/file_store/obs_test.go new file mode 100644 index 0000000..0960750 --- /dev/null +++ b/common/file_store/obs_test.go @@ -0,0 +1,15 @@ +package file_store + +import ( + "testing" +) + +func TestOBSUpload(t *testing.T) { + e := OXS{"", "", "", ""} + var oxs = e.Setup(HuaweiOBS) + err := oxs.UpLoad("test.png", "./test.png") + if err != nil { + t.Error(err) + } + t.Log("ok") +} diff --git a/common/file_store/oss.go b/common/file_store/oss.go index fb7a2a4..c35627b 100644 --- a/common/file_store/oss.go +++ b/common/file_store/oss.go @@ -6,50 +6,43 @@ import ( ) type ALiYunOSS struct { - Client interface{} - Endpoint string - AccessKeyId string - AccessKeySecret string - BucketName string + Client interface{} + BucketName string } -func (e *ALiYunOSS) Setup() error { - // TODO: 如果需要使用阿里云OSS请在此处填写对应信息 - e.AccessKeyId = "" - e.AccessKeySecret = "" - e.Endpoint = "" - e.BucketName = "" - - client, err := oss.New(e.Endpoint, e.AccessKeyId, e.AccessKeySecret) +//Setup 装载 +//endpoint sss +func (e *ALiYunOSS) Setup(endpoint, accessKeyID, accessKeySecret, BucketName string, options ...ClientOption) error { + client, err := oss.New(endpoint, accessKeyID, accessKeySecret) if err != nil { log.Println("Error:", err) return err } e.Client = client + e.BucketName = BucketName + return nil } // UpLoad 文件上传 -func (e *ALiYunOSS) UpLoad(yourObjectName string, localFile string) error { - err := e.Setup() - if err != nil { - log.Println("Error:", err) - return err - } +func (e *ALiYunOSS) UpLoad(yourObjectName string, localFile interface{}) error { // 获取存储空间。 bucket, err := e.Client.(*oss.Client).Bucket(e.BucketName) if err != nil { log.Println("Error:", err) return err } - // 设置分片大小为100 KB,指定分片上传并发数为3,并开启断点续传上传。 // 其中与objectKey是同一概念,表示断点续传上传文件到OSS时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。 // "LocalFile"为filePath,100*1024为partSize。 - err = bucket.UploadFile(yourObjectName, localFile, 100*1024, oss.Routines(3), oss.Checkpoint(true, "")) + err = bucket.UploadFile(yourObjectName, localFile.(string), 100*1024, oss.Routines(3), oss.Checkpoint(true, "")) if err != nil { log.Println("Error:", err) return err } return nil } + +func (e *ALiYunOSS) GetTempToken() (string, error) { + return "", nil +} diff --git a/common/file_store/oss_test.go b/common/file_store/oss_test.go new file mode 100644 index 0000000..f04dd22 --- /dev/null +++ b/common/file_store/oss_test.go @@ -0,0 +1,16 @@ +package file_store + +import ( + "testing" +) + +func TestOSSUpload(t *testing.T) { + // 打括号内填写自己的测试信息即可 + e := OXS{} + var oxs = e.Setup(AliYunOSS) + err := oxs.UpLoad("test.png", "./test.png") + if err != nil { + t.Error(err) + } + t.Log("ok") +} diff --git a/common/global/adm.go b/common/global/adm.go index 9755dc6..f593fa6 100644 --- a/common/global/adm.go +++ b/common/global/adm.go @@ -2,7 +2,7 @@ package global const ( // Version go-admin version info - Version = "2.0.9" + Version = "2.0.10" ) var ( diff --git a/go.mod b/go.mod index a8a33c6..28fc048 100644 --- a/go.mod +++ b/go.mod @@ -13,9 +13,11 @@ require ( github.com/go-admin-team/go-admin-core v1.3.8 github.com/go-admin-team/go-admin-core/sdk v1.3.9 github.com/google/uuid v1.2.0 + github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.12+incompatible github.com/mssola/user_agent v0.5.2 github.com/opentracing/opentracing-go v1.1.0 github.com/prometheus/client_golang v1.11.0 + github.com/qiniu/go-sdk/v7 v7.11.1 github.com/robfig/cron/v3 v3.0.1 github.com/shirou/gopsutil/v3 v3.22.1 github.com/spf13/cast v1.3.1 @@ -23,7 +25,7 @@ require ( github.com/swaggo/gin-swagger v1.2.0 github.com/swaggo/swag v1.6.7 github.com/unrolled/secure v1.0.8 - golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 + golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect gorm.io/driver/mysql v1.0.4-0.20201206014609-ae5fd10184f6 gorm.io/driver/postgres v1.0.6-0.20201208020313-1ed927cfab53 diff --git a/template/v4/dto.go.template b/template/v4/dto.go.template index 1aa5bfe..4f84c9f 100644 --- a/template/v4/dto.go.template +++ b/template/v4/dto.go.template @@ -1,9 +1,6 @@ package dto import ( - "go-admin/app/{{.PackageName}}/models" - "go-admin/common/dto" - common "go-admin/common/models" {{- $bb := false -}} {{- range .Columns -}} @@ -18,6 +15,10 @@ import ( {{- if eq $bb true -}} "time" {{- end }} + + "go-admin/app/{{.PackageName}}/models" + "go-admin/common/dto" + common "go-admin/common/models" ) type {{.ClassName}}GetPageReq struct { @@ -70,7 +71,8 @@ func (s *{{.ClassName}}InsertReq) Generate(model *models.{{.ClassName}}) { {{- else if eq .GoField "CreatedAt" -}} {{- else if eq .GoField "UpdatedAt" -}} {{- else if eq .GoField "DeletedAt" -}} - {{- else if eq .GoField "CreateBy" -}} + {{- else if eq .GoField "CreateBy"}} + model.{{.GoField}} = s.{{.GoField}} // 添加这而,需要记录是被谁创建的 {{- else if eq .GoField "UpdateBy" -}} {{- else }} model.{{.GoField}} = s.{{.GoField}} @@ -110,7 +112,8 @@ func (s *{{.ClassName}}UpdateReq) Generate(model *models.{{.ClassName}}) { {{- else if eq .GoField "UpdatedAt" -}} {{- else if eq .GoField "DeletedAt" -}} {{- else if eq .GoField "CreateBy" -}} - {{- else if eq .GoField "UpdateBy" -}} + {{- else if eq .GoField "UpdateBy"}} + model.{{.GoField}} = s.{{.GoField}} // 添加这而,需要记录是被谁更新的 {{- else }} model.{{.GoField}} = s.{{.GoField}} {{- end -}} diff --git a/template/v4/model.go.template b/template/v4/model.go.template index 1862b03..1e34cd9 100644 --- a/template/v4/model.go.template +++ b/template/v4/model.go.template @@ -1,9 +1,23 @@ package models import ( - // "gorm.io/gorm" + + {{- $bb := false -}} + {{- range .Columns -}} + {{$z := .IsQuery}} + {{- if ($z) }} + {{if eq .GoType "time.Time"}}{{- $bb = true -}}{{- end -}} + {{- end -}} + {{- end -}} + {{- range .Columns -}} + {{if eq .GoType "time.Time"}}{{- $bb = true -}}{{- end -}} + {{- end -}} + {{- if eq $bb true -}} + "time" + {{- end }} "go-admin/common/models" + ) type {{.ClassName}} struct { diff --git a/template/v4/no_actions/router_check_role.go.template b/template/v4/no_actions/router_check_role.go.template index 249c61c..f8a3c3a 100644 --- a/template/v4/no_actions/router_check_role.go.template +++ b/template/v4/no_actions/router_check_role.go.template @@ -6,6 +6,7 @@ import ( "go-admin/app/{{.PackageName}}/apis" "go-admin/common/middleware" + "go-admin/common/actions" ) func init() { @@ -17,10 +18,10 @@ func register{{.ClassName}}Router(v1 *gin.RouterGroup, authMiddleware *jwt.GinJW api := apis.{{.ClassName}}{} r := v1.Group("/{{.ModuleName}}").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole()) { - r.GET("", api.GetPage) - r.GET("/:id", api.Get) + r.GET("", actions.PermissionAction(), api.GetPage) + r.GET("/:id", actions.PermissionAction(), api.Get) r.POST("", api.Insert) - r.PUT("/:id", api.Update) + r.PUT("/:id", actions.PermissionAction(), api.Update) r.DELETE("", api.Delete) } } \ No newline at end of file