auto_code_plugin.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package system
  2. import (
  3. "fmt"
  4. "github.com/flipped-aurora/gin-vue-admin/server/global"
  5. "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
  6. "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
  7. "github.com/gin-gonic/gin"
  8. "go.uber.org/zap"
  9. )
  10. type AutoCodePluginApi struct{}
  11. // Install
  12. // @Tags AutoCodePlugin
  13. // @Summary 安装插件
  14. // @Security ApiKeyAuth
  15. // @accept multipart/form-data
  16. // @Produce application/json
  17. // @Param plug formData file true "this is a test file"
  18. // @Success 200 {object} response.Response{data=[]interface{},msg=string} "安装插件成功"
  19. // @Router /autoCode/installPlugin [post]
  20. func (a *AutoCodePluginApi) Install(c *gin.Context) {
  21. header, err := c.FormFile("plug")
  22. if err != nil {
  23. response.FailWithMessage(err.Error(), c)
  24. return
  25. }
  26. web, server, err := autoCodePluginService.Install(header)
  27. webStr := "web插件安装成功"
  28. serverStr := "server插件安装成功"
  29. if web == -1 {
  30. webStr = "web端插件未成功安装,请按照文档自行解压安装,如果为纯后端插件请忽略此条提示"
  31. }
  32. if server == -1 {
  33. serverStr = "server端插件未成功安装,请按照文档自行解压安装,如果为纯前端插件请忽略此条提示"
  34. }
  35. if err != nil {
  36. response.FailWithMessage(err.Error(), c)
  37. return
  38. }
  39. response.OkWithData([]interface{}{
  40. gin.H{
  41. "code": web,
  42. "msg": webStr,
  43. },
  44. gin.H{
  45. "code": server,
  46. "msg": serverStr,
  47. }}, c)
  48. }
  49. // Packaged
  50. // @Tags AutoCodePlugin
  51. // @Summary 打包插件
  52. // @Security ApiKeyAuth
  53. // @accept application/json
  54. // @Produce application/json
  55. // @Param plugName query string true "插件名称"
  56. // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "打包插件成功"
  57. // @Router /autoCode/pubPlug [post]
  58. func (a *AutoCodePluginApi) Packaged(c *gin.Context) {
  59. plugName := c.Query("plugName")
  60. zipPath, err := autoCodePluginService.PubPlug(plugName)
  61. if err != nil {
  62. global.GVA_LOG.Error("打包失败!", zap.Error(err))
  63. response.FailWithMessage("打包失败"+err.Error(), c)
  64. return
  65. }
  66. response.OkWithMessage(fmt.Sprintf("打包成功,文件路径为:%s", zipPath), c)
  67. }
  68. // InitMenu
  69. // @Tags AutoCodePlugin
  70. // @Summary 打包插件
  71. // @Security ApiKeyAuth
  72. // @accept application/json
  73. // @Produce application/json
  74. // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "打包插件成功"
  75. // @Router /autoCode/initMenu [post]
  76. func (a *AutoCodePluginApi) InitMenu(c *gin.Context) {
  77. var menuInfo request.InitMenu
  78. err := c.ShouldBindJSON(&menuInfo)
  79. if err != nil {
  80. response.FailWithMessage(err.Error(), c)
  81. return
  82. }
  83. err = autoCodePluginService.InitMenu(menuInfo)
  84. if err != nil {
  85. global.GVA_LOG.Error("创建初始化Menu失败!", zap.Error(err))
  86. response.FailWithMessage("创建初始化Menu失败"+err.Error(), c)
  87. return
  88. }
  89. response.OkWithMessage("文件变更成功", c)
  90. }
  91. // InitAPI
  92. // @Tags AutoCodePlugin
  93. // @Summary 打包插件
  94. // @Security ApiKeyAuth
  95. // @accept application/json
  96. // @Produce application/json
  97. // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "打包插件成功"
  98. // @Router /autoCode/initAPI [post]
  99. func (a *AutoCodePluginApi) InitAPI(c *gin.Context) {
  100. var apiInfo request.InitApi
  101. err := c.ShouldBindJSON(&apiInfo)
  102. if err != nil {
  103. response.FailWithMessage(err.Error(), c)
  104. return
  105. }
  106. err = autoCodePluginService.InitAPI(apiInfo)
  107. if err != nil {
  108. global.GVA_LOG.Error("创建初始化API失败!", zap.Error(err))
  109. response.FailWithMessage("创建初始化API失败"+err.Error(), c)
  110. return
  111. }
  112. response.OkWithMessage("文件变更成功", c)
  113. }