api.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. package system
  2. import (
  3. "context"
  4. "github.com/pkg/errors"
  5. "gorm.io/gorm"
  6. sysModel "server/model/system"
  7. "server/service/system"
  8. )
  9. type initApi struct{}
  10. const initOrderApi = system.InitOrderSystem + 1
  11. // auto run
  12. func init() {
  13. system.RegisterInit(initOrderApi, &initApi{})
  14. }
  15. func (i initApi) InitializerName() string {
  16. return sysModel.SysApi{}.TableName()
  17. }
  18. func (i *initApi) MigrateTable(ctx context.Context) (context.Context, error) {
  19. db, ok := ctx.Value("db").(*gorm.DB)
  20. if !ok {
  21. return ctx, system.ErrMissingDBContext
  22. }
  23. return ctx, db.AutoMigrate(&sysModel.SysApi{})
  24. }
  25. func (i *initApi) TableCreated(ctx context.Context) bool {
  26. db, ok := ctx.Value("db").(*gorm.DB)
  27. if !ok {
  28. return false
  29. }
  30. return db.Migrator().HasTable(&sysModel.SysApi{})
  31. }
  32. func (i *initApi) InitializeData(ctx context.Context) (context.Context, error) {
  33. db, ok := ctx.Value("db").(*gorm.DB)
  34. if !ok {
  35. return ctx, system.ErrMissingDBContext
  36. }
  37. entities := []sysModel.SysApi{
  38. {ApiGroup: "jwt", Method: "POST", Path: "/jwt/jsonInBlacklist", Description: "jwt加入黑名单(退出,必选)"},
  39. {ApiGroup: "系统用户", Method: "DELETE", Path: "/user/deleteUser", Description: "删除用户"},
  40. {ApiGroup: "系统用户", Method: "POST", Path: "/user/admin_register", Description: "用户注册"},
  41. {ApiGroup: "系统用户", Method: "POST", Path: "/user/getUserList", Description: "获取用户列表"},
  42. {ApiGroup: "系统用户", Method: "PUT", Path: "/user/setUserInfo", Description: "设置用户信息"},
  43. {ApiGroup: "系统用户", Method: "PUT", Path: "/user/setSelfInfo", Description: "设置自身信息(必选)"},
  44. {ApiGroup: "系统用户", Method: "GET", Path: "/user/getUserInfo", Description: "获取自身信息(必选)"},
  45. {ApiGroup: "系统用户", Method: "POST", Path: "/user/setUserAuthorities", Description: "设置权限组"},
  46. {ApiGroup: "系统用户", Method: "POST", Path: "/user/changePassword", Description: "修改密码(建议选择)"},
  47. {ApiGroup: "系统用户", Method: "POST", Path: "/user/setUserAuthority", Description: "修改用户角色(必选)"},
  48. {ApiGroup: "系统用户", Method: "POST", Path: "/user/resetPassword", Description: "重置用户密码"},
  49. {ApiGroup: "api", Method: "POST", Path: "/api/createApi", Description: "创建api"},
  50. {ApiGroup: "api", Method: "POST", Path: "/api/deleteApi", Description: "删除Api"},
  51. {ApiGroup: "api", Method: "POST", Path: "/api/updateApi", Description: "更新Api"},
  52. {ApiGroup: "api", Method: "POST", Path: "/api/getApiList", Description: "获取api列表"},
  53. {ApiGroup: "api", Method: "POST", Path: "/api/getAllApis", Description: "获取所有api"},
  54. {ApiGroup: "api", Method: "POST", Path: "/api/getApiById", Description: "获取api详细信息"},
  55. {ApiGroup: "api", Method: "DELETE", Path: "/api/deleteApisByIds", Description: "批量删除api"},
  56. {ApiGroup: "角色", Method: "POST", Path: "/authority/copyAuthority", Description: "拷贝角色"},
  57. {ApiGroup: "角色", Method: "POST", Path: "/authority/createAuthority", Description: "创建角色"},
  58. {ApiGroup: "角色", Method: "POST", Path: "/authority/deleteAuthority", Description: "删除角色"},
  59. {ApiGroup: "角色", Method: "PUT", Path: "/authority/updateAuthority", Description: "更新角色信息"},
  60. {ApiGroup: "角色", Method: "POST", Path: "/authority/getAuthorityList", Description: "获取角色列表"},
  61. {ApiGroup: "角色", Method: "POST", Path: "/authority/setDataAuthority", Description: "设置角色资源权限"},
  62. {ApiGroup: "casbin", Method: "POST", Path: "/casbin/updateCasbin", Description: "更改角色api权限"},
  63. {ApiGroup: "casbin", Method: "POST", Path: "/casbin/getPolicyPathByAuthorityId", Description: "获取权限列表"},
  64. {ApiGroup: "菜单", Method: "POST", Path: "/menu/addBaseMenu", Description: "新增菜单"},
  65. {ApiGroup: "菜单", Method: "POST", Path: "/menu/getMenu", Description: "获取菜单树(必选)"},
  66. {ApiGroup: "菜单", Method: "POST", Path: "/menu/deleteBaseMenu", Description: "删除菜单"},
  67. {ApiGroup: "菜单", Method: "POST", Path: "/menu/updateBaseMenu", Description: "更新菜单"},
  68. {ApiGroup: "菜单", Method: "POST", Path: "/menu/getBaseMenuById", Description: "根据id获取菜单"},
  69. {ApiGroup: "菜单", Method: "POST", Path: "/menu/getMenuList", Description: "分页获取基础menu列表"},
  70. {ApiGroup: "菜单", Method: "POST", Path: "/menu/getBaseMenuTree", Description: "获取用户动态路由"},
  71. {ApiGroup: "菜单", Method: "POST", Path: "/menu/getMenuAuthority", Description: "获取指定角色menu"},
  72. {ApiGroup: "菜单", Method: "POST", Path: "/menu/addMenuAuthority", Description: "增加menu和角色关联关系"},
  73. {ApiGroup: "分片上传", Method: "GET", Path: "/deptUploadAndDownload/findFile", Description: "寻找目标文件(秒传)"},
  74. {ApiGroup: "分片上传", Method: "POST", Path: "/deptUploadAndDownload/breakpointContinue", Description: "断点续传"},
  75. {ApiGroup: "分片上传", Method: "POST", Path: "/deptUploadAndDownload/breakpointContinueFinish", Description: "断点续传完成"},
  76. {ApiGroup: "分片上传", Method: "POST", Path: "/deptUploadAndDownload/removeChunk", Description: "上传完成移除文件"},
  77. {ApiGroup: "文件上传与下载", Method: "POST", Path: "/deptUploadAndDownload/upload", Description: "文件上传示例"},
  78. {ApiGroup: "文件上传与下载", Method: "POST", Path: "/deptUploadAndDownload/deleteFile", Description: "删除文件"},
  79. {ApiGroup: "文件上传与下载", Method: "POST", Path: "/deptUploadAndDownload/editFileName", Description: "文件名或者备注编辑"},
  80. {ApiGroup: "文件上传与下载", Method: "POST", Path: "/deptUploadAndDownload/getFileList", Description: "获取上传文件列表"},
  81. {ApiGroup: "系统服务", Method: "POST", Path: "/system/getServerInfo", Description: "获取服务器信息"},
  82. {ApiGroup: "系统服务", Method: "POST", Path: "/system/getSystemConfig", Description: "获取配置文件内容"},
  83. {ApiGroup: "系统服务", Method: "POST", Path: "/system/setSystemConfig", Description: "设置配置文件内容"},
  84. {ApiGroup: "客户", Method: "PUT", Path: "/customer/customer", Description: "更新客户"},
  85. {ApiGroup: "客户", Method: "POST", Path: "/customer/customer", Description: "创建客户"},
  86. {ApiGroup: "客户", Method: "DELETE", Path: "/customer/customer", Description: "删除客户"},
  87. {ApiGroup: "客户", Method: "GET", Path: "/customer/customer", Description: "获取单一客户"},
  88. {ApiGroup: "客户", Method: "GET", Path: "/customer/customerList", Description: "获取客户列表"},
  89. {ApiGroup: "代码生成器", Method: "GET", Path: "/autoCode/getDB", Description: "获取所有数据库"},
  90. {ApiGroup: "代码生成器", Method: "GET", Path: "/autoCode/getTables", Description: "获取数据库表"},
  91. {ApiGroup: "代码生成器", Method: "POST", Path: "/autoCode/createTemp", Description: "自动化代码"},
  92. {ApiGroup: "代码生成器", Method: "POST", Path: "/autoCode/preview", Description: "预览自动化代码"},
  93. {ApiGroup: "代码生成器", Method: "GET", Path: "/autoCode/getColumn", Description: "获取所选table的所有字段"},
  94. {ApiGroup: "代码生成器", Method: "POST", Path: "/autoCode/createPlug", Description: "自动创建插件包"},
  95. {ApiGroup: "代码生成器", Method: "POST", Path: "/autoCode/installPlugin", Description: "安装插件"},
  96. {ApiGroup: "代码生成器", Method: "POST", Path: "/autoCode/pubPlug", Description: "打包插件"},
  97. {ApiGroup: "包(pkg)生成器", Method: "POST", Path: "/autoCode/createPackage", Description: "生成包(package)"},
  98. {ApiGroup: "包(pkg)生成器", Method: "POST", Path: "/autoCode/getPackage", Description: "获取所有包(package)"},
  99. {ApiGroup: "包(pkg)生成器", Method: "POST", Path: "/autoCode/delPackage", Description: "删除包(package)"},
  100. {ApiGroup: "代码生成器历史", Method: "POST", Path: "/autoCode/getMeta", Description: "获取meta信息"},
  101. {ApiGroup: "代码生成器历史", Method: "POST", Path: "/autoCode/rollback", Description: "回滚自动生成代码"},
  102. {ApiGroup: "代码生成器历史", Method: "POST", Path: "/autoCode/getSysHistory", Description: "查询回滚记录"},
  103. {ApiGroup: "代码生成器历史", Method: "POST", Path: "/autoCode/delSysHistory", Description: "删除回滚记录"},
  104. {ApiGroup: "系统字典详情", Method: "PUT", Path: "/sysDictionaryDetail/updateSysDictionaryDetail", Description: "更新字典内容"},
  105. {ApiGroup: "系统字典详情", Method: "POST", Path: "/sysDictionaryDetail/createSysDictionaryDetail", Description: "新增字典内容"},
  106. {ApiGroup: "系统字典详情", Method: "DELETE", Path: "/sysDictionaryDetail/deleteSysDictionaryDetail", Description: "删除字典内容"},
  107. {ApiGroup: "系统字典详情", Method: "GET", Path: "/sysDictionaryDetail/findSysDictionaryDetail", Description: "根据ID获取字典内容"},
  108. {ApiGroup: "系统字典详情", Method: "GET", Path: "/sysDictionaryDetail/getSysDictionaryDetailList", Description: "获取字典内容列表"},
  109. {ApiGroup: "系统字典", Method: "POST", Path: "/sysDictionary/createSysDictionary", Description: "新增字典"},
  110. {ApiGroup: "系统字典", Method: "DELETE", Path: "/sysDictionary/deleteSysDictionary", Description: "删除字典"},
  111. {ApiGroup: "系统字典", Method: "PUT", Path: "/sysDictionary/updateSysDictionary", Description: "更新字典"},
  112. {ApiGroup: "系统字典", Method: "GET", Path: "/sysDictionary/findSysDictionary", Description: "根据ID获取字典"},
  113. {ApiGroup: "系统字典", Method: "GET", Path: "/sysDictionary/getSysDictionaryList", Description: "获取字典列表"},
  114. {ApiGroup: "操作记录", Method: "POST", Path: "/sysOperationRecord/createSysOperationRecord", Description: "新增操作记录"},
  115. {ApiGroup: "操作记录", Method: "GET", Path: "/sysOperationRecord/findSysOperationRecord", Description: "根据ID获取操作记录"},
  116. {ApiGroup: "操作记录", Method: "GET", Path: "/sysOperationRecord/getSysOperationRecordList", Description: "获取操作记录列表"},
  117. {ApiGroup: "操作记录", Method: "DELETE", Path: "/sysOperationRecord/deleteSysOperationRecord", Description: "删除操作记录"},
  118. {ApiGroup: "操作记录", Method: "DELETE", Path: "/sysOperationRecord/deleteSysOperationRecordByIds", Description: "批量删除操作历史"},
  119. {ApiGroup: "断点续传(插件版)", Method: "POST", Path: "/simpleUploader/upload", Description: "插件版分片上传"},
  120. {ApiGroup: "断点续传(插件版)", Method: "GET", Path: "/simpleUploader/checkFileMd5", Description: "文件完整度验证"},
  121. {ApiGroup: "断点续传(插件版)", Method: "GET", Path: "/simpleUploader/mergeFileMd5", Description: "上传完成合并文件"},
  122. {ApiGroup: "email", Method: "POST", Path: "/email/emailTest", Description: "发送测试邮件"},
  123. {ApiGroup: "email", Method: "POST", Path: "/email/emailSend", Description: "发送邮件示例"},
  124. {ApiGroup: "按钮权限", Method: "POST", Path: "/authorityBtn/setAuthorityBtn", Description: "设置按钮权限"},
  125. {ApiGroup: "按钮权限", Method: "POST", Path: "/authorityBtn/getAuthorityBtn", Description: "获取已有按钮权限"},
  126. {ApiGroup: "按钮权限", Method: "POST", Path: "/authorityBtn/canRemoveAuthorityBtn", Description: "删除按钮"},
  127. {ApiGroup: "表格模板", Method: "POST", Path: "/sysExportTemplate/createSysExportTemplate", Description: "新增导出模板"},
  128. {ApiGroup: "表格模板", Method: "DELETE", Path: "/sysExportTemplate/deleteSysExportTemplate", Description: "删除导出模板"},
  129. {ApiGroup: "表格模板", Method: "DELETE", Path: "/sysExportTemplate/deleteSysExportTemplateByIds", Description: "批量删除导出模板"},
  130. {ApiGroup: "表格模板", Method: "PUT", Path: "/sysExportTemplate/updateSysExportTemplate", Description: "更新导出模板"},
  131. {ApiGroup: "表格模板", Method: "GET", Path: "/sysExportTemplate/findSysExportTemplate", Description: "根据ID获取导出模板"},
  132. {ApiGroup: "表格模板", Method: "GET", Path: "/sysExportTemplate/getSysExportTemplateList", Description: "获取导出模板列表"},
  133. {ApiGroup: "表格模板", Method: "GET", Path: "/sysExportTemplate/exportExcel", Description: "导出Excel"},
  134. {ApiGroup: "表格模板", Method: "GET", Path: "/sysExportTemplate/exportTemplate", Description: "下载模板"},
  135. {ApiGroup: "表格模板", Method: "POST", Path: "/sysExportTemplate/importExcel", Description: "导入Excel"},
  136. }
  137. if err := db.Create(&entities).Error; err != nil {
  138. return ctx, errors.Wrap(err, sysModel.SysApi{}.TableName()+"表数据初始化失败!")
  139. }
  140. next := context.WithValue(ctx, i.InitializerName(), entities)
  141. return next, nil
  142. }
  143. func (i *initApi) DataInserted(ctx context.Context) bool {
  144. db, ok := ctx.Value("db").(*gorm.DB)
  145. if !ok {
  146. return false
  147. }
  148. if errors.Is(db.Where("path = ? AND method = ?", "/authorityBtn/canRemoveAuthorityBtn", "POST").
  149. First(&sysModel.SysApi{}).Error, gorm.ErrRecordNotFound) {
  150. return false
  151. }
  152. return true
  153. }