You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

497 lines
34 KiB

  1. package init_data
  2. import (
  3. "gin-vue-admin/global"
  4. "gin-vue-admin/model"
  5. gormadapter "github.com/casbin/gorm-adapter/v3"
  6. "github.com/satori/go.uuid"
  7. "go.uber.org/zap"
  8. "gorm.io/gorm"
  9. "time"
  10. )
  11. type SysAuthorityMenus struct {
  12. SysAuthorityAuthorityId string
  13. SysBaseMenuId uint
  14. }
  15. type SysDataAuthorityId struct {
  16. SysAuthorityAuthorityId string
  17. DataAuthorityIdAuthorityId string
  18. }
  19. func InitSysApi() (err error) {
  20. tx := global.GVA_DB.Begin() // 开始事务
  21. insert := []model.SysApi{
  22. {gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/base/login", "用户登录", "base", "POST"},
  23. {gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/base/register", "用户注册", "base", "POST"},
  24. {gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/createApi", "创建api", "api", "POST"},
  25. {gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getApiList", "获取api列表", "api", "POST"},
  26. {gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getApiById", "获取api详细信息", "api", "POST"},
  27. {gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/deleteApi", "删除Api", "api", "POST"},
  28. {gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/updateApi", "更新Api", "api", "POST"},
  29. {gorm.Model{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getAllApis", "获取所有api", "api", "POST"},
  30. {gorm.Model{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/createAuthority", "创建角色", "authority", "POST"},
  31. {gorm.Model{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/deleteAuthority", "删除角色", "authority", "POST"},
  32. {gorm.Model{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/getAuthorityList", "获取角色列表", "authority", "POST"},
  33. {gorm.Model{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenu", "获取菜单树", "menu", "POST"},
  34. {gorm.Model{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenuList", "分页获取基础menu列表", "menu", "POST"},
  35. {gorm.Model{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/addBaseMenu", "新增菜单", "menu", "POST"},
  36. {gorm.Model{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getBaseMenuTree", "获取用户动态路由", "menu", "POST"},
  37. {gorm.Model{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/addMenuAuthority", "增加menu和角色关联关系", "menu", "POST"},
  38. {gorm.Model{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenuAuthority", "获取指定角色menu", "menu", "POST"},
  39. {gorm.Model{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/deleteBaseMenu", "删除菜单", "menu", "POST"},
  40. {gorm.Model{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/updateBaseMenu", "更新菜单", "menu", "POST"},
  41. {gorm.Model{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getBaseMenuById", "根据id获取菜单", "menu", "POST"},
  42. {gorm.Model{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/changePassword", "修改密码", "user", "POST"},
  43. {gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/getUserList", "获取用户列表", "user", "POST"},
  44. {gorm.Model{ID: 24, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserAuthority", "修改用户角色", "user", "POST"},
  45. {gorm.Model{ID: 25, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/upload", "文件上传示例", "fileUploadAndDownload", "POST"},
  46. {gorm.Model{ID: 26, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/getFileList", "获取上传文件列表", "fileUploadAndDownload", "POST"},
  47. {gorm.Model{ID: 27, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/updateCasbin", "更改角色api权限", "casbin", "POST"},
  48. {gorm.Model{ID: 28, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/getPolicyPathByAuthorityId", "获取权限列表", "casbin", "POST"},
  49. {gorm.Model{ID: 29, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/deleteFile", "删除文件", "fileUploadAndDownload", "POST"},
  50. {gorm.Model{ID: 30, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/jwt/jsonInBlacklist", "jwt加入黑名单", "jwt", "POST"},
  51. {gorm.Model{ID: 31, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/setDataAuthority", "设置角色资源权限", "authority", "POST"},
  52. {gorm.Model{ID: 32, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/getSystemConfig", "获取配置文件内容", "system", "POST"},
  53. {gorm.Model{ID: 33, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/setSystemConfig", "设置配置文件内容", "system", "POST"},
  54. {gorm.Model{ID: 34, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "创建客户", "customer", "POST"},
  55. {gorm.Model{ID: 35, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "更新客户", "customer", "PUT"},
  56. {gorm.Model{ID: 36, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "删除客户", "customer", "DELETE"},
  57. {gorm.Model{ID: 37, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "获取单一客户", "customer", "GET"},
  58. {gorm.Model{ID: 38, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customerList", "获取客户列表", "customer", "GET"},
  59. {gorm.Model{ID: 39, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/casbinTest/:pathParam", "RESTFUL模式测试", "casbin", "GET"},
  60. {gorm.Model{ID: 40, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/createTemp", "自动化代码", "autoCode", "POST"},
  61. {gorm.Model{ID: 41, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/updateAuthority", "更新角色信息", "authority", "PUT"},
  62. {gorm.Model{ID: 42, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/copyAuthority", "拷贝角色", "authority", "POST"},
  63. {gorm.Model{ID: 43, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/deleteUser", "删除用户", "user", "DELETE"},
  64. {gorm.Model{ID: 44, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/createSysDictionaryDetail", "新增字典内容", "sysDictionaryDetail", "POST"},
  65. {gorm.Model{ID: 45, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/deleteSysDictionaryDetail", "删除字典内容", "sysDictionaryDetail", "DELETE"},
  66. {gorm.Model{ID: 46, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/updateSysDictionaryDetail", "更新字典内容", "sysDictionaryDetail", "PUT"},
  67. {gorm.Model{ID: 47, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/findSysDictionaryDetail", "根据ID获取字典内容", "sysDictionaryDetail", "GET"},
  68. {gorm.Model{ID: 48, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/getSysDictionaryDetailList", "获取字典内容列表", "sysDictionaryDetail", "GET"},
  69. {gorm.Model{ID: 49, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/createSysDictionary", "新增字典", "sysDictionary", "POST"},
  70. {gorm.Model{ID: 50, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/deleteSysDictionary", "删除字典", "sysDictionary", "DELETE"},
  71. {gorm.Model{ID: 51, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/updateSysDictionary", "更新字典", "sysDictionary", "PUT"},
  72. {gorm.Model{ID: 52, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/findSysDictionary", "根据ID获取字典", "sysDictionary", "GET"},
  73. {gorm.Model{ID: 53, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/getSysDictionaryList", "获取字典列表", "sysDictionary", "GET"},
  74. {gorm.Model{ID: 54, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/createSysOperationRecord", "新增操作记录", "sysOperationRecord", "POST"},
  75. {gorm.Model{ID: 55, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/deleteSysOperationRecord", "删除操作记录", "sysOperationRecord", "DELETE"},
  76. {gorm.Model{ID: 56, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/findSysOperationRecord", "根据ID获取操作记录", "sysOperationRecord", "GET"},
  77. {gorm.Model{ID: 57, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/getSysOperationRecordList", "获取操作记录列表", "sysOperationRecord", "GET"},
  78. {gorm.Model{ID: 58, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getTables", "获取数据库表", "autoCode", "GET"},
  79. {gorm.Model{ID: 59, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getDB", "获取所有数据库", "autoCode", "GET"},
  80. {gorm.Model{ID: 60, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getColume", "获取所选table的所有字段", "autoCode", "GET"},
  81. {gorm.Model{ID: 61, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/deleteSysOperationRecordByIds", "批量删除操作历史", "sysOperationRecord", "DELETE"},
  82. {gorm.Model{ID: 62, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/upload", "插件版分片上传", "simpleUploader", "POST"},
  83. {gorm.Model{ID: 63, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/checkFileMd5", "文件完整度验证", "simpleUploader", "GET"},
  84. {gorm.Model{ID: 64, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/mergeFileMd5", "上传完成合并文件", "simpleUploader", "GET"},
  85. {gorm.Model{ID: 65, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserInfo", "设置用户信息", "user", "PUT"},
  86. {gorm.Model{ID: 66, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/getServerInfo", "获取服务器信息", "system", "POST"},
  87. {gorm.Model{ID: 67, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/email/emailTest", "发送测试邮件", "email", "POST"},
  88. }
  89. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  90. tx.Rollback()
  91. }
  92. return tx.Commit().Error
  93. }
  94. func InitSysUser() (err error) {
  95. tx := global.GVA_DB.Begin() // 开始事务
  96. insert := []model.SysUser{
  97. {Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, UUID: uuid.NewV4(), Username: "admin", Password: "e10adc3949ba59abbe56e057f20f883e", NickName: "超级管理员", HeaderImg: "http://qmplusimg.henrongyi.top/1571627762timg.jpg", AuthorityId: "888"},
  98. {Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, UUID: uuid.NewV4(), Username: "a303176530", Password: "3ec063004a6f31642261936a379fde3d", NickName: "QMPlusUser", HeaderImg: "http://qmplusimg.henrongyi.top/1572075907logo.png", AuthorityId: "9528"},
  99. }
  100. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  101. tx.Rollback()
  102. }
  103. return tx.Commit().Error
  104. }
  105. func InitExaCustomer() (err error) {
  106. tx := global.GVA_DB.Begin() // 开始事务
  107. insert := []model.ExaCustomer{
  108. {Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, CustomerName: "测试客户", CustomerPhoneData: "1761111111", SysUserID: 1, SysUserAuthorityID: "888"},
  109. }
  110. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  111. tx.Rollback()
  112. }
  113. return tx.Commit().Error
  114. }
  115. func InitCasbinModel() (err error) {
  116. if !global.GVA_DB.Migrator().HasTable("casbin_rule") {
  117. if err := global.GVA_DB.Migrator().CreateTable(&gormadapter.CasbinRule{}); err != nil {
  118. return err
  119. }
  120. }
  121. tx := global.GVA_DB.Begin() // 开始事务
  122. insert := []model.CasbinModel{
  123. {"p", "888", "/base/login", "POST"},
  124. {"p", "888", "/base/register", "POST"},
  125. {"p", "888", "/api/createApi", "POST"},
  126. {"p", "888", "/api/getApiList", "POST"},
  127. {"p", "888", "/api/getApiById", "POST"},
  128. {"p", "888", "/api/deleteApi", "POST"},
  129. {"p", "888", "/api/updateApi", "POST"},
  130. {"p", "888", "/api/getAllApis", "POST"},
  131. {"p", "888", "/authority/createAuthority", "POST"},
  132. {"p", "888", "/authority/deleteAuthority", "POST"},
  133. {"p", "888", "/authority/getAuthorityList", "POST"},
  134. {"p", "888", "/authority/setDataAuthority", "POST"},
  135. {"p", "888", "/authority/updateAuthority", "PUT"},
  136. {"p", "888", "/authority/copyAuthority", "POST"},
  137. {"p", "888", "/menu/getMenu", "POST"},
  138. {"p", "888", "/menu/getMenuList", "POST"},
  139. {"p", "888", "/menu/addBaseMenu", "POST"},
  140. {"p", "888", "/menu/getBaseMenuTree", "POST"},
  141. {"p", "888", "/menu/addMenuAuthority", "POST"},
  142. {"p", "888", "/menu/getMenuAuthority", "POST"},
  143. {"p", "888", "/menu/deleteBaseMenu", "POST"},
  144. {"p", "888", "/menu/updateBaseMenu", "POST"},
  145. {"p", "888", "/menu/getBaseMenuById", "POST"},
  146. {"p", "888", "/user/changePassword", "POST"},
  147. {"p", "888", "/user/getUserList", "POST"},
  148. {"p", "888", "/user/setUserAuthority", "POST"},
  149. {"p", "888", "/user/deleteUser", "DELETE"},
  150. {"p", "888", "/fileUploadAndDownload/upload", "POST"},
  151. {"p", "888", "/fileUploadAndDownload/getFileList", "POST"},
  152. {"p", "888", "/fileUploadAndDownload/deleteFile", "POST"},
  153. {"p", "888", "/casbin/updateCasbin", "POST"},
  154. {"p", "888", "/casbin/getPolicyPathByAuthorityId", "POST"},
  155. {"p", "888", "/casbin/casbinTest/:pathParam", "GET"},
  156. {"p", "888", "/jwt/jsonInBlacklist", "POST"},
  157. {"p", "888", "/system/getSystemConfig", "POST"},
  158. {"p", "888", "/system/setSystemConfig", "POST"},
  159. {"p", "888", "/system/getServerInfo", "POST"},
  160. {"p", "888", "/customer/customer", "POST"},
  161. {"p", "888", "/customer/customer", "PUT"},
  162. {"p", "888", "/customer/customer", "DELETE"},
  163. {"p", "888", "/customer/customer", "GET"},
  164. {"p", "888", "/customer/customerList", "GET"},
  165. {"p", "888", "/autoCode/createTemp", "POST"},
  166. {"p", "888", "/autoCode/getTables", "GET"},
  167. {"p", "888", "/autoCode/getDB", "GET"},
  168. {"p", "888", "/autoCode/getColume", "GET"},
  169. {"p", "888", "/sysDictionaryDetail/createSysDictionaryDetail", "POST"},
  170. {"p", "888", "/sysDictionaryDetail/deleteSysDictionaryDetail", "DELETE"},
  171. {"p", "888", "/sysDictionaryDetail/updateSysDictionaryDetail", "PUT"},
  172. {"p", "888", "/sysDictionaryDetail/findSysDictionaryDetail", "GET"},
  173. {"p", "888", "/sysDictionaryDetail/getSysDictionaryDetailList", "GET"},
  174. {"p", "888", "/sysDictionary/createSysDictionary", "POST"},
  175. {"p", "888", "/sysDictionary/deleteSysDictionary", "DELETE"},
  176. {"p", "888", "/sysDictionary/updateSysDictionary", "PUT"},
  177. {"p", "888", "/sysDictionary/findSysDictionary", "GET"},
  178. {"p", "888", "/sysDictionary/getSysDictionaryList", "GET"},
  179. {"p", "888", "/sysOperationRecord/createSysOperationRecord", "POST"},
  180. {"p", "888", "/sysOperationRecord/deleteSysOperationRecord", "DELETE"},
  181. {"p", "888", "/sysOperationRecord/updateSysOperationRecord", "PUT"},
  182. {"p", "888", "/sysOperationRecord/findSysOperationRecord", "GET"},
  183. {"p", "888", "/sysOperationRecord/getSysOperationRecordList", "GET"},
  184. {"p", "888", "/sysOperationRecord/deleteSysOperationRecordByIds", "DELETE"},
  185. {"p", "888", "/user/setUserInfo", "PUT"},
  186. {"p", "888", "/email/emailTest", "POST"},
  187. {"p", "8881", "/base/login", "POST"},
  188. {"p", "8881", "/base/register", "POST"},
  189. {"p", "8881", "/api/createApi", "POST"},
  190. {"p", "8881", "/api/getApiList", "POST"},
  191. {"p", "8881", "/api/getApiById", "POST"},
  192. {"p", "8881", "/api/deleteApi", "POST"},
  193. {"p", "8881", "/api/updateApi", "POST"},
  194. {"p", "8881", "/api/getAllApis", "POST"},
  195. {"p", "8881", "/authority/createAuthority", "POST"},
  196. {"p", "8881", "/authority/deleteAuthority", "POST"},
  197. {"p", "8881", "/authority/getAuthorityList", "POST"},
  198. {"p", "8881", "/authority/setDataAuthority", "POST"},
  199. {"p", "8881", "/menu/getMenu", "POST"},
  200. {"p", "8881", "/menu/getMenuList", "POST"},
  201. {"p", "8881", "/menu/addBaseMenu", "POST"},
  202. {"p", "8881", "/menu/getBaseMenuTree", "POST"},
  203. {"p", "8881", "/menu/addMenuAuthority", "POST"},
  204. {"p", "8881", "/menu/getMenuAuthority", "POST"},
  205. {"p", "8881", "/menu/deleteBaseMenu", "POST"},
  206. {"p", "8881", "/menu/updateBaseMenu", "POST"},
  207. {"p", "8881", "/menu/getBaseMenuById", "POST"},
  208. {"p", "8881", "/user/changePassword", "POST"},
  209. {"p", "8881", "/user/getUserList", "POST"},
  210. {"p", "8881", "/user/setUserAuthority", "POST"},
  211. {"p", "8881", "/fileUploadAndDownload/upload", "POST"},
  212. {"p", "8881", "/fileUploadAndDownload/getFileList", "POST"},
  213. {"p", "8881", "/fileUploadAndDownload/deleteFile", "POST"},
  214. {"p", "8881", "/casbin/updateCasbin", "POST"},
  215. {"p", "8881", "/casbin/getPolicyPathByAuthorityId", "POST"},
  216. {"p", "8881", "/jwt/jsonInBlacklist", "POST"},
  217. {"p", "8881", "/system/getSystemConfig", "POST"},
  218. {"p", "8881", "/system/setSystemConfig", "POST"},
  219. {"p", "8881", "/customer/customer", "POST"},
  220. {"p", "8881", "/customer/customer", "PUT"},
  221. {"p", "8881", "/customer/customer", "DELETE"},
  222. {"p", "8881", "/customer/customer", "GET"},
  223. {"p", "8881", "/customer/customerList", "GET"},
  224. {"p", "9528", "/base/login", "POST"},
  225. {"p", "9528", "/base/register", "POST"},
  226. {"p", "9528", "/api/createApi", "POST"},
  227. {"p", "9528", "/api/getApiList", "POST"},
  228. {"p", "9528", "/api/getApiById", "POST"},
  229. {"p", "9528", "/api/deleteApi", "POST"},
  230. {"p", "9528", "/api/updateApi", "POST"},
  231. {"p", "9528", "/api/getAllApis", "POST"},
  232. {"p", "9528", "/authority/createAuthority", "POST"},
  233. {"p", "9528", "/authority/deleteAuthority", "POST"},
  234. {"p", "9528", "/authority/getAuthorityList", "POST"},
  235. {"p", "9528", "/authority/setDataAuthority", "POST"},
  236. {"p", "9528", "/menu/getMenu", "POST"},
  237. {"p", "9528", "/menu/getMenuList", "POST"},
  238. {"p", "9528", "/menu/addBaseMenu", "POST"},
  239. {"p", "9528", "/menu/getBaseMenuTree", "POST"},
  240. {"p", "9528", "/menu/addMenuAuthority", "POST"},
  241. {"p", "9528", "/menu/getMenuAuthority", "POST"},
  242. {"p", "9528", "/menu/deleteBaseMenu", "POST"},
  243. {"p", "9528", "/menu/updateBaseMenu", "POST"},
  244. {"p", "9528", "/menu/getBaseMenuById", "POST"},
  245. {"p", "9528", "/user/changePassword", "POST"},
  246. {"p", "9528", "/user/getUserList", "POST"},
  247. {"p", "9528", "/user/setUserAuthority", "POST"},
  248. {"p", "9528", "/fileUploadAndDownload/upload", "POST"},
  249. {"p", "9528", "/fileUploadAndDownload/getFileList", "POST"},
  250. {"p", "9528", "/fileUploadAndDownload/deleteFile", "POST"},
  251. {"p", "9528", "/casbin/updateCasbin", "POST"},
  252. {"p", "9528", "/casbin/getPolicyPathByAuthorityId", "POST"},
  253. {"p", "9528", "/jwt/jsonInBlacklist", "POST"},
  254. {"p", "9528", "/system/getSystemConfig", "POST"},
  255. {"p", "9528", "/system/setSystemConfig", "POST"},
  256. {"p", "9528", "/customer/customer", "POST"},
  257. {"p", "9528", "/customer/customer", "PUT"},
  258. {"p", "9528", "/customer/customer", "DELETE"},
  259. {"p", "9528", "/customer/customer", "GET"},
  260. {"p", "9528", "/customer/customerList", "GET"},
  261. {"p", "9528", "/autoCode/createTemp", "POST"},
  262. }
  263. if tx.Table("casbin_rule").Create(&insert).Error != nil { // 遇到错误时回滚事务
  264. tx.Rollback()
  265. }
  266. return tx.Commit().Error
  267. }
  268. func InitSysAuthority() (err error) {
  269. tx := global.GVA_DB.Begin() // 开始事务
  270. insert := []model.SysAuthority{
  271. {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "888", AuthorityName: "普通用户", ParentId: "0"},
  272. {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "8881", AuthorityName: "普通用户子角色", ParentId: "888"},
  273. {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "9528", AuthorityName: "测试角色", ParentId: "0"},
  274. }
  275. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  276. tx.Rollback()
  277. }
  278. return tx.Commit().Error
  279. }
  280. func InitSysBaseMenus() (err error) {
  281. tx := global.GVA_DB.Begin() // 开始事务
  282. insert := []model.SysBaseMenu{
  283. {Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "dashboard", Name: "dashboard", Hidden: false, Component: "view/dashboard/index.vue", Sort: 1, Meta: model.Meta{Title: "仪表盘", Icon: "setting"}},
  284. {Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "about", Name: "about", Component: "view/about/index.vue", Sort: 7, Meta: model.Meta{Title: "关于我们", Icon: "info"}},
  285. {Model: gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "admin", Name: "superAdmin", Component: "view/superAdmin/index.vue", Sort: 3, Meta: model.Meta{Title: "超级管理员", Icon: "user-solid"}},
  286. {Model: gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "authority", Name: "authority", Component: "view/superAdmin/authority/authority.vue", Sort: 1, Meta: model.Meta{Title: "角色管理", Icon: "s-custom"}},
  287. {Model: gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "menu", Name: "menu", Component: "view/superAdmin/menu/menu.vue", Sort: 2, Meta: model.Meta{Title: "菜单管理", Icon: "s-order", KeepAlive: true}},
  288. {Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "api", Name: "api", Component: "view/superAdmin/api/api.vue", Sort: 3, Meta: model.Meta{Title: "api管理", Icon: "s-platform", KeepAlive: true}},
  289. {Model: gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "user", Name: "user", Component: "view/superAdmin/user/user.vue", Sort: 4, Meta: model.Meta{Title: "用户管理", Icon: "coordinate"}},
  290. {Model: gorm.Model{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: true, ParentId: "0", Path: "person", Name: "person", Component: "view/person/person.vue", Sort: 4, Meta: model.Meta{Title: "个人信息", Icon: "message-solid"}},
  291. {Model: gorm.Model{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "example", Name: "example", Component: "view/example/index.vue", Sort: 6, Meta: model.Meta{Title: "示例文件", Icon: "s-management"}},
  292. {Model: gorm.Model{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "table", Name: "table", Component: "view/example/table/table.vue", Sort: 1, Meta: model.Meta{Title: "表格示例", Icon: "s-order"}},
  293. {Model: gorm.Model{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "form", Name: "form", Component: "view/example/form/form.vue", Sort: 2, Meta: model.Meta{Title: "表单示例", Icon: "document"}},
  294. {Model: gorm.Model{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "rte", Name: "rte", Component: "view/example/rte/rte.vue", Sort: 3, Meta: model.Meta{Title: "富文本编辑器", Icon: "reading"}},
  295. {Model: gorm.Model{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "excel", Name: "excel", Component: "view/example/excel/excel.vue", Sort: 4, Meta: model.Meta{Title: "excel导入导出", Icon: "s-marketing"}},
  296. {Model: gorm.Model{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "upload", Name: "upload", Component: "view/example/upload/upload.vue", Sort: 5, Meta: model.Meta{Title: "上传下载", Icon: "upload"}},
  297. {Model: gorm.Model{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "breakpoint", Name: "breakpoint", Component: "view/example/breakpoint/breakpoint.vue", Sort: 6, Meta: model.Meta{Title: "断点续传", Icon: "upload"}},
  298. {Model: gorm.Model{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "customer", Name: "customer", Component: "view/example/customer/customer.vue", Sort: 7, Meta: model.Meta{Title: "客户列表(资源示例)", Icon: "s-custom"}},
  299. {Model: gorm.Model{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "systemTools", Name: "systemTools", Component: "view/systemTools/index.vue", Sort: 5, Meta: model.Meta{Title: "系统工具", Icon: "s-cooperation"}},
  300. {Model: gorm.Model{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "17", Path: "autoCode", Name: "autoCode", Component: "view/systemTools/autoCode/index.vue", Sort: 1, Meta: model.Meta{Title: "代码生成器", Icon: "cpu", KeepAlive: true}},
  301. {Model: gorm.Model{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "17", Path: "formCreate", Name: "formCreate", Component: "view/systemTools/formCreate/index.vue", Sort: 2, Meta: model.Meta{Title: "表单生成器", Icon: "magic-stick", KeepAlive: true}},
  302. {Model: gorm.Model{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "17", Path: "system", Name: "system", Component: "view/systemTools/system/system.vue", Sort: 3, Meta: model.Meta{Title: "系统配置", Icon: "s-operation"}},
  303. {Model: gorm.Model{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "iconList", Name: "iconList", Component: "view/iconList/index.vue", Sort: 2, Meta: model.Meta{Title: "图标集合", Icon: "star-on"}},
  304. {Model: gorm.Model{ID: 22, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "dictionary", Name: "dictionary", Component: "view/superAdmin/dictionary/sysDictionary.vue", Sort: 5, Meta: model.Meta{Title: "字典管理", Icon: "notebook-2"}},
  305. {Model: gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: true, ParentId: "3", Path: "dictionaryDetail/:id", Name: "dictionaryDetail", Component: "view/superAdmin/dictionary/sysDictionaryDetail.vue", Sort: 1, Meta: model.Meta{Title: "字典详情", Icon: "s-order"}},
  306. {Model: gorm.Model{ID: 24, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "operation", Name: "operation", Component: "view/superAdmin/operation/sysOperationRecord.vue", Sort: 6, Meta: model.Meta{Title: "操作历史", Icon: "time"}},
  307. {Model: gorm.Model{ID: 25, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "simpleUploader", Name: "simpleUploader", Component: "view/example/simpleUploader/simpleUploader", Sort: 6, Meta: model.Meta{Title: "断点续传(插件版)", Icon: "upload"}},
  308. {Model: gorm.Model{ID: 26, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "https://www.gin-vue-admin.com", Name: "https://www.gin-vue-admin.com", Hidden: false, Component: "/", Sort: 0, Meta: model.Meta{Title: "官方网站", Icon: "s-home"}},
  309. {Model: gorm.Model{ID: 27, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "state", Name: "state", Hidden: false, Component: "view/system/state.vue", Sort: 6, Meta: model.Meta{Title: "服务器状态", Icon: "cloudy"}},
  310. }
  311. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  312. tx.Rollback()
  313. }
  314. return tx.Commit().Error
  315. }
  316. func InitAuthorityMenu() (err error) {
  317. return global.GVA_DB.Exec("CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `authority_menu` AS select `sys_base_menus`.`id` AS `id`,`sys_base_menus`.`created_at` AS `created_at`, `sys_base_menus`.`updated_at` AS `updated_at`, `sys_base_menus`.`deleted_at` AS `deleted_at`, `sys_base_menus`.`menu_level` AS `menu_level`,`sys_base_menus`.`parent_id` AS `parent_id`,`sys_base_menus`.`path` AS `path`,`sys_base_menus`.`name` AS `name`,`sys_base_menus`.`hidden` AS `hidden`,`sys_base_menus`.`component` AS `component`, `sys_base_menus`.`title` AS `title`,`sys_base_menus`.`icon` AS `icon`,`sys_base_menus`.`sort` AS `sort`,`sys_authority_menus`.`sys_authority_authority_id` AS `authority_id`,`sys_authority_menus`.`sys_base_menu_id` AS `menu_id`,`sys_base_menus`.`keep_alive` AS `keep_alive`,`sys_base_menus`.`default_menu` AS `default_menu` from (`sys_authority_menus` join `sys_base_menus` on ((`sys_authority_menus`.`sys_base_menu_id` = `sys_base_menus`.`id`)))").Error
  318. }
  319. func InitSysDictionary() (err error) {
  320. status := new(bool)
  321. *status = true
  322. tx := global.GVA_DB.Begin() // 开始事务
  323. insert := []model.SysDictionary{
  324. {Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "性别", Type: "sex", Status: status, Desc: "性别字典"},
  325. {Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库int类型", Type: "int", Status: status, Desc: "int类型对应的数据库类型"},
  326. {Model: gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库时间日期类型", Type: "time.Time", Status: status, Desc: "数据库时间日期类型"},
  327. {Model: gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库浮点型", Type: "float64", Status: status, Desc: "数据库浮点型"},
  328. {Model: gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库字符串", Type: "string", Status: status, Desc: "数据库字符串"},
  329. {Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Desc: "数据库bool类型"},
  330. }
  331. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  332. tx.Rollback()
  333. }
  334. return tx.Commit().Error
  335. }
  336. func InitSysAuthorityMenus() (err error) {
  337. tx := global.GVA_DB.Begin() // 开始事务
  338. insert := []SysAuthorityMenus{
  339. {"888", 1},
  340. {"888", 2},
  341. {"888", 3},
  342. {"888", 4},
  343. {"888", 5},
  344. {"888", 6},
  345. {"888", 7},
  346. {"888", 8},
  347. {"888", 9},
  348. {"888", 10},
  349. {"888", 11},
  350. {"888", 12},
  351. {"888", 13},
  352. {"888", 14},
  353. {"888", 15},
  354. {"888", 16},
  355. {"888", 17},
  356. {"888", 18},
  357. {"888", 19},
  358. {"888", 20},
  359. {"888", 21},
  360. {"888", 22},
  361. {"888", 23},
  362. {"888", 24},
  363. {"888", 25},
  364. {"888", 26},
  365. {"888", 27},
  366. {"8881", 1},
  367. {"8881", 2},
  368. {"8881", 8},
  369. {"8881", 17},
  370. {"8881", 18},
  371. {"8881", 19},
  372. {"8881", 20},
  373. {"9528", 1},
  374. {"9528", 2},
  375. {"9528", 3},
  376. {"9528", 4},
  377. {"9528", 5},
  378. {"9528", 6},
  379. {"9528", 7},
  380. {"9528", 8},
  381. {"9528", 9},
  382. {"9528", 10},
  383. {"9528", 11},
  384. {"9528", 12},
  385. {"9528", 13},
  386. {"9528", 14},
  387. {"9528", 15},
  388. {"9528", 17},
  389. {"9528", 18},
  390. {"9528", 19},
  391. {"9528", 20},
  392. }
  393. if tx.Table("sys_authority_menus").Create(&insert).Error != nil { // 遇到错误时回滚事务
  394. tx.Rollback()
  395. }
  396. return tx.Commit().Error
  397. }
  398. func InitSysDataAuthorityId() (err error) {
  399. tx := global.GVA_DB.Begin() // 开始事务
  400. insert := []SysDataAuthorityId{
  401. {"888", "888"},
  402. {"888", "8881"},
  403. {"888", "9528"},
  404. {"9528", "8881"},
  405. {"9528", "9528"},
  406. }
  407. if global.GVA_DB.Migrator().HasTable("sys_data_authority_ids") {
  408. if tx.Table("sys_data_authority_ids").Create(&insert).Error != nil { // 遇到错误时回滚事务
  409. tx.Rollback()
  410. }
  411. return tx.Commit().Error
  412. }
  413. if tx.Table("sys_data_authority_id").Create(&insert).Error != nil { // 遇到错误时回滚事务
  414. tx.Rollback()
  415. }
  416. return tx.Commit().Error
  417. }
  418. func InitSysDictionaryDetail() (err error) {
  419. status := new(bool)
  420. *status = true
  421. tx := global.GVA_DB.Begin() // 开始事务
  422. insert := []model.SysDictionaryDetail{
  423. {gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "smallint", 1, status, 1, 2},
  424. {gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumint", 2, status, 2, 2},
  425. {gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "int", 3, status, 3, 2},
  426. {gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "bigint", 4, status, 4, 2},
  427. {gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "data", 0, status, 0, 3},
  428. {gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "time", 1, status, 1, 3},
  429. {gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "year", 2, status, 2, 3},
  430. {gorm.Model{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "datetime", 3, status, 3, 3},
  431. {gorm.Model{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "timestamp", 5, status, 5, 3},
  432. {gorm.Model{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "float", 0, status, 0, 4},
  433. {gorm.Model{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "double", 1, status, 1, 4},
  434. {gorm.Model{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "decimal", 2, status, 2, 4},
  435. {gorm.Model{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "char", 0, status, 0, 5},
  436. {gorm.Model{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "varchar", 1, status, 1, 5},
  437. {gorm.Model{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyblob", 2, status, 2, 5},
  438. {gorm.Model{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinytext", 3, status, 3, 5},
  439. {gorm.Model{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "text", 4, status, 4, 5},
  440. {gorm.Model{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "blob", 5, status, 5, 5},
  441. {gorm.Model{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumblob", 6, status, 6, 5},
  442. {gorm.Model{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumtext", 7, status, 7, 5},
  443. {gorm.Model{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "longblob", 8, status, 8, 5},
  444. {gorm.Model{ID: 22, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "longtext", 9, status, 9, 5},
  445. {gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyint", 0, status, 0, 6},
  446. }
  447. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  448. tx.Rollback()
  449. }
  450. return tx.Commit().Error
  451. }
  452. func InitExaFileUploadAndDownload() (err error) {
  453. tx := global.GVA_DB.Begin() // 开始事务
  454. insert := []model.ExaFileUploadAndDownload{
  455. {gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "10.png", "http://qmplusimg.henrongyi.top/gvalogo.png", "png", "158787308910.png"},
  456. {gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "logo.png", "http://qmplusimg.henrongyi.top/1576554439myAvatar.png", "png", "1587973709logo.png"},
  457. }
  458. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  459. tx.Rollback()
  460. }
  461. return tx.Commit().Error
  462. }
  463. func InitData() {
  464. var err error
  465. err = InitSysApi()
  466. err = InitSysUser()
  467. err = InitExaCustomer()
  468. err = InitCasbinModel()
  469. err = InitSysAuthority()
  470. err = InitSysBaseMenus()
  471. err = InitAuthorityMenu()
  472. err = InitSysDictionary()
  473. err = InitSysAuthorityMenus()
  474. err = InitSysDataAuthorityId()
  475. err = InitSysDictionaryDetail()
  476. err = InitExaFileUploadAndDownload()
  477. if err != nil {
  478. global.GVA_LOG.Error("initialize data failed", zap.Any("err", err))
  479. }
  480. global.GVA_LOG.Info("initialize data success")
  481. }