Merge pull request #77 from wenjianzhang/v1.0.0

V1.0.0
This commit is contained in:
wenjianzhang authored and GitHub committed 2020-05-12 23:59:25 +08:00
commit cebca5862e
16 files changed
+98 -111

No files matched your search

+2
View File
@@ -145,3 +145,5 @@ func DeleteConfig(c *gin.Context) {
tools.HasError(err, "修改失败", 500)
app.OK(c, result, msg.DeletedSuccess)
}
-1
View File
@@ -71,7 +71,6 @@ func GetDictType(c *gin.Context) {
c.JSON(http.StatusOK, res.ReturnOK())
}
func GetDictTypeOptionSelect(c *gin.Context) {
var DictType models.DictType
DictType.DictName = c.Request.FormValue("dictName")
+3 -3
View File
@@ -106,9 +106,9 @@ func UpdatePost(c *gin.Context) {
// @Router /api/v1/post/{postId} [delete]
func DeletePost(c *gin.Context) {
var data models.Post
id, err := tools.StringToInt(c.Param("postId"))
data.UpdateBy = tools.GetUserIdStr(c)
_, err = data.Delete(id)
IDS := tools.IdsStrToIdsIntGroup("postId", c)
result, err := data.BatchDelete(IDS)
tools.HasError(err, "删除失败", 500)
app.OK(c,"","删除成功")
app.OK(c,result,"删除成功")
}
+18 -10
View File
@@ -81,10 +81,26 @@ func GetSysTables(c *gin.Context) {
// @Router /api/v1/sys/tables/info [post]
// @Security Bearer
func InsertSysTable(c *gin.Context) {
tablesList := strings.Split(c.Request.FormValue("tables"), ",")
for i := 0; i < len(tablesList); i++ {
data, err := genTableInit(tablesList, i, c)
_, err = data.Create()
tools2.HasError(err, "", -1)
}
var res app.Response
res.Msg = "添加成功!"
c.JSON(http.StatusOK, res.ReturnOK())
}
func genTableInit(tablesList []string, i int, c *gin.Context) (tools.SysTables, error) {
var data tools.SysTables
var dbTable tools.DBTables
var dbColumn tools.DBColumns
data.TBName = c.Request.FormValue("tables")
data.TBName = tablesList[i]
data.CreateBy = tools2.GetUserIdStr(c)
dbTable.TableName = data.TBName
@@ -161,15 +177,7 @@ func InsertSysTable(c *gin.Context) {
data.Columns = append(data.Columns, column)
}
result, err := data.Create()
tools2.HasError(err, "", -1)
var res app.Response
res.Data = result
res.Msg = "添加成功!"
c.JSON(http.StatusOK, res.ReturnOK())
return data, err
}
// @Summary 修改表结构
-1
View File
@@ -1,7 +1,6 @@
settings:
application:
mode: dev # dev开发环境 test测试环境 prod线上环境
demomsg: "谢谢您的参与,但为了大家更好的体验,所以本次提交就算了吧!\U0001F600\U0001F600\U0001F600"
host: 0.0.0.0
name: testApp
port: 8000
+1 -2
View File
@@ -10,10 +10,9 @@ import (
func AuthInit() (*jwt.GinJWTMiddleware, error) {
return jwt.New(&jwt.GinJWTMiddleware{
Realm: "test zone",
Key: []byte("secret key"),
Key: []byte(config.ApplicationConfig.JwtSecret),
Timeout: time.Hour,
MaxRefresh: time.Hour,
IdentityKey: config.ApplicationConfig.JwtSecret,
PayloadFunc: handler.PayloadFunc,
IdentityHandler: handler.IdentityHandler,
Authenticator: handler.Authenticator,
-27
View File
@@ -1,27 +0,0 @@
package middleware
import (
"github.com/gin-gonic/gin"
config2 "go-admin/tools/config"
"net/http"
)
func DemoEvn() gin.HandlerFunc {
return func(c *gin.Context) {
if config2.ApplicationConfig.Mode == "demo" {
method := c.Request.Method
if method == "GET" || method == "OPTIONS" || c.Request.RequestURI == "/login" || c.Request.RequestURI == "/api/v1/logout" {
c.Next()
} else {
c.JSON(http.StatusOK, gin.H{
"code": 500,
"msg": config2.ApplicationConfig.DemoMsg,
})
c.Abort()
return
}
} else {
c.Next()
}
}
}
-1
View File
@@ -113,4 +113,3 @@ func (e *SysConfig) BatchDelete(id []int) (Result bool, err error) {
Result = true
return
}
+1 -1
View File
@@ -126,4 +126,4 @@ func (e *DictType) BatchDelete(id []int) (Result bool, err error) {
}
Result = true
return
}
}
+1 -1
View File
@@ -20,7 +20,7 @@ func InitDb() error {
return err
}
sqlList := strings.Split(sql, ";")
for i := 0; i < len(sqlList); i++ {
for i := 0; i < len(sqlList) - 1; i++ {
if strings.Contains(sqlList[i], "--") {
fmt.Println(sqlList[i])
continue
+8
View File
@@ -129,3 +129,11 @@ func (e *Post) Delete(id int) (success bool, err error) {
success = true
return
}
func (e *Post) BatchDelete(id []int) (Result bool, err error) {
if err = orm.Eloquent.Table(e.TableName()).Where("post_id in (?)", id).Delete(&Post{}).Error; err != nil {
return
}
Result = true
return
}
+14 -13
View File
@@ -6,20 +6,20 @@ import (
)
type SysRole struct {
RoleId int `json:"roleId" gorm:"primary_key;AUTO_INCREMENT"` // 角色编码
RoleName string `json:"roleName" gorm:"type:varchar(128);"` // 角色名称
Status string `json:"status" gorm:"type:int(1);"` //
RoleKey string `json:"roleKey" gorm:"type:varchar(128);"` //角色代码
RoleSort int `json:"roleSort" gorm:"type:int(4);"` //角色排序
Flag string `json:"flag" gorm:"type:varchar(128);"` //
CreateBy string `json:"createBy" gorm:"type:varchar(128);"` //
UpdateBy string `json:"updateBy" gorm:"type:varchar(128);"` //
Remark string `json:"remark" gorm:"type:varchar(255);"` //备注
Admin bool `json:"admin" gorm:"type:char(1);"`
RoleId int `json:"roleId" gorm:"primary_key;AUTO_INCREMENT"` // 角色编码
RoleName string `json:"roleName" gorm:"type:varchar(128);"` // 角色名称
Status string `json:"status" gorm:"type:int(1);"` //
RoleKey string `json:"roleKey" gorm:"type:varchar(128);"` //角色代码
RoleSort int `json:"roleSort" gorm:"type:int(4);"` //角色排序
Flag string `json:"flag" gorm:"type:varchar(128);"` //
CreateBy string `json:"createBy" gorm:"type:varchar(128);"` //
UpdateBy string `json:"updateBy" gorm:"type:varchar(128);"` //
Remark string `json:"remark" gorm:"type:varchar(255);"` //备注
Admin bool `json:"admin" gorm:"type:char(1);"`
DataScope string `json:"dataScope" gorm:"type:varchar(128);"`
Params string `json:"params" gorm:"-"`
MenuIds []int `json:"menuIds" gorm:"-"`
DeptIds []int `json:"deptIds" gorm:"-"`
Params string `json:"params" gorm:"-"`
MenuIds []int `json:"menuIds" gorm:"-"`
DeptIds []int `json:"deptIds" gorm:"-"`
BaseModel
}
@@ -92,6 +92,7 @@ func (role *SysRole) GetList() (SysRole []SysRole, err error) {
return
}
// 获取角色对应的菜单ids
func (role *SysRole) GetRoleMeunId() ([]int, error) {
menuIds := make([]int, 0)
menuList := make([]MenuIdList, 0)
+1
View File
@@ -20,6 +20,7 @@ func (e *DBTables) GetPage(pageSize int, pageIndex int) ([]DBTables, int, error)
var doc []DBTables
table := orm.Eloquent.Select("*").Table("information_schema.tables")
table = table.Where("TABLE_NAME not in (select table_name from "+config2.DatabaseConfig.Name+".sys_tables) ")
table = table.Where("table_schema= ? ", config2.DatabaseConfig.Name)
if e.TableName != "" {
+1 -1
View File
@@ -144,7 +144,7 @@ func (e *SysTables) Delete() (success bool, err error) {
}
func (e *SysTables) BatchDelete(id []int) (Result bool, err error) {
if err = orm.Eloquent.Table(e.TableName()).Where(" table_id in (?)", id).Delete(&SysColumns{}).Error; err != nil {
if err = orm.Eloquent.Unscoped().Table(e.TableName()).Where(" table_id in (?)", id).Delete(&SysColumns{}).Error; err != nil {
return
}
Result = true
-1
View File
@@ -25,7 +25,6 @@ func InitRouter() *gin.Engine {
r.Use(middleware.Options)
r.Use(middleware.Secure)
r.Use(middleware.RequestId())
r.Use(middleware.DemoEvn())
r.GET("/", system.HelloWorld)
r.Static("/static", "./static")
+48 -49
View File
@@ -11,34 +11,33 @@ type {{.ClassName}} struct {
{{$x := .Pk}}
{{if ($x)}}{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key"`{{else}}{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};"`{{end}} // {{.ColumnComment}}
{{- end }}
DataScope string `json:"dataScope" gorm:"-"`
Params string `json:"params" gorm:"-"`
BaseModel
DataScope string `json:"dataScope" gorm:"-"`
Params string `json:"params" gorm:"-"`
BaseModel
}
func ({{.ClassName}}) TableName() string {
return "{{.TBName}}"
return "{{.TBName}}"
}
// 创建{{.ClassName}}
func (e *{{.ClassName}}) Create() ({{.ClassName}}, error) {
var doc {{.ClassName}}
result := orm.Eloquent.Table(e.TableName()).Create(&e)
if result.Error != nil {
err := result.Error
return doc, err
}
doc = *e
return doc, nil
var doc {{.ClassName}}
result := orm.Eloquent.Table(e.TableName()).Create(&e)
if result.Error != nil {
err := result.Error
return doc, err
}
doc = *e
return doc, nil
}
// 获取{{.ClassName}}
func (e *{{.ClassName}}) Get() ({{.ClassName}}, error) {
var doc {{.ClassName}}
table := orm.Eloquent.Table(e.TableName())
{{ range .Columns -}}
table := orm.Eloquent.Table(e.TableName())
{{ range .Columns -}}
{{$z := .IsQuery}}
{{- if ($z) -}}
if e.{{.GoField}} != "" {
@@ -55,61 +54,61 @@ return doc, nil
// 获取{{.ClassName}}带分页
func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int) ([]{{.ClassName}}, int, error) {
var doc []{{.ClassName}}
var doc []{{.ClassName}}
table := orm.Eloquent.Select("*").Table(e.TableName())
{{ range .Columns -}}
table := orm.Eloquent.Select("*").Table(e.TableName())
{{ range .Columns -}}
{{$z := .IsQuery}}
{{- if ($z) -}}
if e.{{.GoField}} != "" {
table = table.Where("{{.ColumnName}} = ?", e.{{.GoField}})
}
{{ end -}}
{{ end }}
{{ end }}
// 数据权限控制(如果不需要数据权限请将此处去掉)
dataPermission := new(DataPermission)
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
table = dataPermission.GetDataScope(e.TableName(), table)
// 数据权限控制(如果不需要数据权限请将此处去掉)
dataPermission := new(DataPermission)
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
table = dataPermission.GetDataScope(e.TableName(), table)
var count int
var count int
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
return nil, 0, err
}
table.Count(&count)
return doc, count, nil
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
return nil, 0, err
}
table.Count(&count)
return doc, count, nil
}
// 更新{{.ClassName}}
func (e *{{.ClassName}}) Update(id int) (update {{.ClassName}}, err error) {
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil {
return
}
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil {
return
}
//参数1:是要修改的数据
//参数2:是修改的数据
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
return
}
return
//参数1:是要修改的数据
//参数2:是修改的数据
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
return
}
return
}
// 删除{{.ClassName}}
func (e *{{.ClassName}}) Delete(id int) (success bool, err error) {
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil {
success = false
return
}
success = true
return
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil {
success = false
return
}
success = true
return
}
//批量删除
func (e *{{.ClassName}}) BatchDelete(id []int) (Result bool, err error) {
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} in (?)", id).Delete(&{{.ClassName}}{}).Error; err != nil {
return
}
Result = true
return
if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} in (?)", id).Delete(&{{.ClassName}}{}).Error; err != nil {
return
}
Result = true
return
}