
* beta:2.7.8-a 增加自动化创建树形结构 (#1941) * feat: 支持创建树形结构 --------- Co-authored-by: piexlMax(奇淼 <qimiaojiangjizhao@gmail.com> * 优化user store部分写法 * Update user.js * feat: 升级版本号 * Dev 278 beta2 (#1954) * 在关闭详情弹窗后 detailFrom为空对象,arr为undefined 使用slice控制台会报错 * 查询不重置pageSize * 优化主题模式相关内容 * 优化弹窗手机端显示 * bugfix:PostgreSQL initdb (#1953) * bugfix:postgresql增加显示指定template --------- Co-authored-by: PiexlMax(奇淼 <165128580+pixelmaxQm@users.noreply.github.com> --------- Co-authored-by: zayn <972858472@qq.com> Co-authored-by: Azir <2075125282@qq.com> Co-authored-by: Qing Liang <106448173+xue-ding-e@users.noreply.github.com> * docs:调整部分代码注释以及代码格式 * feat: 自动化代码字典支持多选 * fix:调整值接收器和指针接收器 * feat: 支持导出表格复制,优化增加方法页面。 * chore:初始化代码规范化。 --------- Co-authored-by: piexlMax(奇淼 <qimiaojiangjizhao@gmail.com> Co-authored-by: Azir <2075125282@qq.com> Co-authored-by: zayn <972858472@qq.com> Co-authored-by: Qing Liang <106448173+xue-ding-e@users.noreply.github.com> Co-authored-by: cjb <75364055@qq.com>
122 lines
3.6 KiB
Go
122 lines
3.6 KiB
Go
package system
|
|
|
|
import (
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/utils"
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type AutoCodeTemplateApi struct{}
|
|
|
|
// Preview
|
|
// @Tags AutoCodeTemplate
|
|
// @Summary 预览创建后的代码
|
|
// @Security ApiKeyAuth
|
|
// @accept application/json
|
|
// @Produce application/json
|
|
// @Param data body request.AutoCode true "预览创建代码"
|
|
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "预览创建后的代码"
|
|
// @Router /autoCode/preview [post]
|
|
func (a *AutoCodeTemplateApi) Preview(c *gin.Context) {
|
|
var info request.AutoCode
|
|
err := c.ShouldBindJSON(&info)
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
err = utils.Verify(info, utils.AutoCodeVerify)
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
err = info.Pretreatment()
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
info.PackageT = utils.FirstUpper(info.Package)
|
|
autoCode, err := autoCodeTemplateService.Preview(c.Request.Context(), info)
|
|
if err != nil {
|
|
global.GVA_LOG.Error(err.Error(), zap.Error(err))
|
|
response.FailWithMessage("预览失败:"+err.Error(), c)
|
|
} else {
|
|
response.OkWithDetailed(gin.H{"autoCode": autoCode}, "预览成功", c)
|
|
}
|
|
}
|
|
|
|
// Create
|
|
// @Tags AutoCodeTemplate
|
|
// @Summary 自动代码模板
|
|
// @Security ApiKeyAuth
|
|
// @accept application/json
|
|
// @Produce application/json
|
|
// @Param data body request.AutoCode true "创建自动代码"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
|
|
// @Router /autoCode/createTemp [post]
|
|
func (a *AutoCodeTemplateApi) Create(c *gin.Context) {
|
|
var info request.AutoCode
|
|
err := c.ShouldBindJSON(&info)
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
err = utils.Verify(info, utils.AutoCodeVerify)
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
err = info.Pretreatment()
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
err = autoCodeTemplateService.Create(c.Request.Context(), info)
|
|
if err != nil {
|
|
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
|
response.FailWithMessage(err.Error(), c)
|
|
} else {
|
|
response.OkWithMessage("创建成功", c)
|
|
}
|
|
}
|
|
|
|
// AddFunc
|
|
// @Tags AddFunc
|
|
// @Summary 增加方法
|
|
// @Security ApiKeyAuth
|
|
// @accept application/json
|
|
// @Produce application/json
|
|
// @Param data body request.AutoCode true "增加方法"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
|
|
// @Router /autoCode/addFunc [post]
|
|
func (a *AutoCodeTemplateApi) AddFunc(c *gin.Context) {
|
|
var info request.AutoFunc
|
|
err := c.ShouldBindJSON(&info)
|
|
if err != nil {
|
|
response.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
var tempMap map[string]string
|
|
if info.IsPreview {
|
|
info.Router = "填充router"
|
|
info.FuncName = "填充funcName"
|
|
info.Method = "填充method"
|
|
info.Description = "填充description"
|
|
tempMap, err = autoCodeTemplateService.GetApiAndServer(info)
|
|
} else {
|
|
err = autoCodeTemplateService.AddFunc(info)
|
|
}
|
|
if err != nil {
|
|
global.GVA_LOG.Error("注入失败!", zap.Error(err))
|
|
response.FailWithMessage("注入失败", c)
|
|
} else {
|
|
if info.IsPreview {
|
|
response.OkWithDetailed(tempMap, "注入成功", c)
|
|
return
|
|
}
|
|
response.OkWithMessage("注入成功", c)
|
|
}
|
|
}
|