feat:update api model router tpl

This commit is contained in:
zhangwenjian committed 2020-09-10 14:14:08 +08:00
1 parent fa07a57d22
commit 8a7a9db7fd
12 files changed
+148 -38

No files matched your search

+84
View File
@@ -0,0 +1,84 @@
package student
import (
"github.com/gin-gonic/gin"
"go-admin/app/admin/models"
"go-admin/app/admin/service/dto"
"go-admin/tools"
"go-admin/tools/app"
"go-admin/tools/app/msg"
)
func GetStudentList(c *gin.Context) {
var data models.Student
var err error
var pageSize = 10
var pageIndex = 1
if size := c.Request.FormValue("pageSize"); size != "" {
pageSize, err = tools.StringToInt(size)
}
if index := c.Request.FormValue("pageIndex"); index != "" {
pageIndex, err = tools.StringToInt(index)
}
var v dto.StudentSearch
err = c.Bind(&v)
tools.HasError(err, "数据解析失败", 422)
data.DataScope = tools.GetUserIdStr(c)
result, count, err := data.GetPage(pageSize, pageIndex, v)
tools.HasError(err, "", -1)
app.PageOK(c, result, count, pageIndex, pageSize, "")
}
func GetStudent(c *gin.Context) {
var data models.Student
data.Id, _ = tools.StringToInt(c.Param("id"))
result, err := data.Get()
tools.HasError(err, "抱歉未找到相关信息", -1)
app.OK(c, result, "")
}
// @Summary 添加Student
// @Description 获取JSON
// @Tags Student
// @Accept application/json
// @Product application/json
// @Param data body models.Student true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/student [post]
func InsertStudent(c *gin.Context) {
var data models.Student
err := c.ShouldBindJSON(&data)
data.CreateBy = tools.GetUserIdStr(c)
tools.HasError(err, "", 500)
result, err := data.Create()
tools.HasError(err, "", -1)
app.OK(c, result, "")
}
func UpdateStudent(c *gin.Context) {
var data models.Student
err := c.ShouldBindJSON(&data)
tools.HasError(err, "数据解析失败", -1)
data.UpdateBy = tools.GetUserIdStr(c)
result, err := data.Update(data.Id)
tools.HasError(err, "", -1)
app.OK(c, result, "")
}
func DeleteStudent(c *gin.Context) {
var data models.Student
data.UpdateBy = tools.GetUserIdStr(c)
IDS := tools.IdsStrToIdsIntGroup("id", c)
_, err := data.BatchDelete(IDS)
tools.HasError(err, msg.DeletedFail, 500)
app.OK(c, nil, msg.DeletedSuccess)
}
+6 -6
View File
@@ -71,7 +71,7 @@ func GenCode(c *gin.Context) {
oldTest := "// {{认证路由自动补充在此处请勿删除}}"
newText := "// {{认证路由自动补充在此处请勿删除}} \r\n register" + tab.ClassName + "Router(v1,authMiddleware)"
if !tab.IsAuth {
if tab.IsAuth == 2 {
oldTest = "// {{无需认证路由自动补充在此处请勿删除}}"
newText = "// {{无需认证路由自动补充在此处请勿删除}} \r\n register" + tab.ClassName + "Router(v1)"
routerfile = "template/routernocheckrole.go.template"
@@ -142,7 +142,7 @@ func GenCodeV2(c *gin.Context) {
table.TableId = id
tab, _ := table.Get()
if tab.IsActions {
if tab.IsActions == 1 {
ActionsGen(tab)
} else {
NOActionsGen(tab)
@@ -154,7 +154,7 @@ func GenCodeV2(c *gin.Context) {
func NOActionsGen(tab tools.SysTables) {
routerfile := "template/routercheckrole.go.template"
if !tab.IsAuth {
if tab.IsAuth == 2 {
routerfile = "template/routernocheckrole.go.template"
}
@@ -171,7 +171,7 @@ func NOActionsGen(tab tools.SysTables) {
t6, err := template.ParseFiles("template/v2/dto.go.template")
tools2.HasError(err, "", -1)
_ = tools2.PathCreate("./app/" + tab.PackageName + "/apis/" + tab.ModuleName + "/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/apis/" + tab.ModuleName)
_ = tools2.PathCreate("./app/" + tab.PackageName + "/models/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/router/")
_ = tools2.PathCreate("./app/" + tab.PackageName + "/service/dto/")
@@ -202,7 +202,7 @@ func NOActionsGen(tab tools.SysTables) {
func ActionsGen(tab tools.SysTables) {
routerfile := "template/v2/routercheckrole.go.template"
if !tab.IsAuth {
if tab.IsAuth == 2 {
routerfile = "template/v2/routernocheckrole.go.template"
}
@@ -464,7 +464,7 @@ func GenMenuAndApi(c *gin.Context) {
ADelete.MenuName = ""
ADelete.Title = "删除" + tab.TableComment
ADelete.Icon = "bug"
ADelete.Path = "/api/v1/" + tab.ModuleName + "/:id"
ADelete.Path = "/api/v1/" + tab.ModuleName
ADelete.MenuType = "A"
ADelete.Action = "DELETE"
ADelete.ParentId = Amenu.MenuId
+7 -7
View File
@@ -28,9 +28,9 @@ type SysTables struct {
Tree bool `gorm:"size:1;" json:"tree"`
Crud bool `gorm:"size:1;" json:"crud"`
Remark string `gorm:"size:255;" json:"remark"`
IsDataScope bool `gorm:"size:1;" json:"isDataScope"`
IsActions bool `gorm:"size:1;" json:"isActions"`
IsAuth bool `gorm:"size:1;" json:"isAuth"`
IsDataScope int `gorm:"size:1;" json:"isDataScope"`
IsActions int `gorm:"size:1;" json:"isActions"`
IsAuth int `gorm:"size:1;" json:"isAuth"`
IsLogicalDelete string `gorm:"size:1;" json:"isLogicalDelete"`
LogicalDelete bool `gorm:"size:1;" json:"logicalDelete"`
LogicalDeleteColumn string `gorm:"size:128;" json:"logicalDeleteColumn"`
@@ -150,13 +150,13 @@ func (e *SysTables) Create() (SysTables, error) {
}
func (e *SysTables) Update() (update SysTables, err error) {
if err = orm.Eloquent.Table("sys_tables").First(&update, e.TableId).Error; err != nil {
return
}
//if err = orm.Eloquent.Table("sys_tables").First(&update, e.TableId).Error; err != nil {
// return
//}
//参数1:是要修改的数据
//参数2:是修改的数据
if err = orm.Eloquent.Table("sys_tables").Model(&update).Updates(&e).Error; err != nil {
if err = orm.Eloquent.Table("sys_tables").Where("table_id = ?", e.TableId).Updates(&e).Error; err != nil {
return
}