15 files changed
+36
-49
No files matched your search
@@ -145,3 +145,5 @@ func DeleteConfig(c *gin.Context) {
|
||||
tools.HasError(err, "修改失败", 500)
|
||||
app.OK(c, result, msg.DeletedSuccess)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
@@ -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
@@ -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,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
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,4 +113,3 @@ func (e *SysConfig) BatchDelete(id []int) (Result bool, err error) {
|
||||
Result = true
|
||||
return
|
||||
}
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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 != "" {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -36,7 +36,6 @@ return doc, nil
|
||||
// 获取{{.ClassName}}
|
||||
func (e *{{.ClassName}}) Get() ({{.ClassName}}, error) {
|
||||
var doc {{.ClassName}}
|
||||
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
{{ range .Columns -}}
|
||||
{{$z := .IsQuery}}
|
||||
|
||||
Reference in new issue
Block a user