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.

183 lines
5.0 KiB

  1. package service
  2. import (
  3. "gin-vue-admin/global"
  4. "gin-vue-admin/model"
  5. gormadapter "github.com/casbin/gorm-adapter/v3"
  6. )
  7. type SysAuthorityMenus struct {
  8. SysAuthorityAuthorityId string
  9. SysBaseMenuId uint
  10. }
  11. type SysDataAuthorityId struct {
  12. SysAuthorityAuthorityId string
  13. DataAuthorityIdAuthorityId string
  14. }
  15. func InitSysApi() (err error) {
  16. tx := global.GVA_DB.Begin() // 开始事务
  17. insert := model.SysApiData()
  18. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  19. tx.Rollback()
  20. }
  21. return tx.Commit().Error
  22. }
  23. func InitSysUser() (err error) {
  24. tx := global.GVA_DB.Begin() // 开始事务
  25. insert := model.SysUserData()
  26. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  27. tx.Rollback()
  28. }
  29. return tx.Commit().Error
  30. }
  31. func InitExaCustomer() (err error) {
  32. tx := global.GVA_DB.Begin() // 开始事务
  33. insert := model.ExaCustomerData()
  34. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  35. tx.Rollback()
  36. }
  37. return tx.Commit().Error
  38. }
  39. func InitCasbinModel() (err error) {
  40. if !global.GVA_DB.Migrator().HasTable("casbin_rule") {
  41. if err := global.GVA_DB.Migrator().CreateTable(&gormadapter.CasbinRule{}); err != nil {
  42. return err
  43. }
  44. }
  45. tx := global.GVA_DB.Begin() // 开始事务
  46. insert := model.CasbinModelData()
  47. if tx.Table("casbin_rule").Create(&insert).Error != nil { // 遇到错误时回滚事务
  48. tx.Rollback()
  49. }
  50. return tx.Commit().Error
  51. }
  52. func InitSysAuthority() (err error) {
  53. tx := global.GVA_DB.Begin() // 开始事务
  54. insert := model.SysAuthorityData()
  55. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  56. tx.Rollback()
  57. }
  58. return tx.Commit().Error
  59. }
  60. func InitSysBaseMenus() (err error) {
  61. tx := global.GVA_DB.Begin() // 开始事务
  62. insert := model.SysBaseMenusData()
  63. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  64. tx.Rollback()
  65. }
  66. return tx.Commit().Error
  67. }
  68. func InitAuthorityMenu() (err error) {
  69. 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
  70. }
  71. func InitSysDictionary() (err error) {
  72. tx := global.GVA_DB.Begin() // 开始事务
  73. insert := model.SysDictionaryData()
  74. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  75. tx.Rollback()
  76. }
  77. return tx.Commit().Error
  78. }
  79. func InitSysAuthorityMenus() (err error) {
  80. tx := global.GVA_DB.Begin() // 开始事务
  81. insert := []SysAuthorityMenus{
  82. {"888", 1},
  83. {"888", 2},
  84. {"888", 3},
  85. {"888", 4},
  86. {"888", 5},
  87. {"888", 6},
  88. {"888", 7},
  89. {"888", 8},
  90. {"888", 9},
  91. {"888", 10},
  92. {"888", 11},
  93. {"888", 12},
  94. {"888", 13},
  95. {"888", 14},
  96. {"888", 15},
  97. {"888", 16},
  98. {"888", 17},
  99. {"888", 18},
  100. {"888", 19},
  101. {"888", 20},
  102. {"888", 21},
  103. {"888", 22},
  104. {"888", 23},
  105. {"888", 24},
  106. {"888", 25},
  107. {"8881", 1},
  108. {"8881", 2},
  109. {"8881", 8},
  110. {"8881", 17},
  111. {"8881", 18},
  112. {"8881", 19},
  113. {"8881", 20},
  114. {"9528", 1},
  115. {"9528", 2},
  116. {"9528", 3},
  117. {"9528", 4},
  118. {"9528", 5},
  119. {"9528", 6},
  120. {"9528", 7},
  121. {"9528", 8},
  122. {"9528", 9},
  123. {"9528", 10},
  124. {"9528", 11},
  125. {"9528", 12},
  126. {"9528", 13},
  127. {"9528", 14},
  128. {"9528", 15},
  129. {"9528", 17},
  130. {"9528", 18},
  131. {"9528", 19},
  132. {"9528", 20},
  133. }
  134. if tx.Table("sys_authority_menus").Create(&insert).Error != nil { // 遇到错误时回滚事务
  135. tx.Rollback()
  136. }
  137. return tx.Commit().Error
  138. }
  139. func InitSysDataAuthorityId() (err error) {
  140. tx := global.GVA_DB.Begin() // 开始事务
  141. insert := []SysDataAuthorityId{
  142. {"888", "888"},
  143. {"888", "8881"},
  144. {"888", "9528"},
  145. {"9528", "8881"},
  146. {"9528", "9528"},
  147. }
  148. if tx.Table("sys_data_authority_ids").Create(&insert).Error != nil { // 遇到错误时回滚事务
  149. tx.Rollback()
  150. }
  151. return tx.Commit().Error
  152. }
  153. func InitSysDictionaryDetail() (err error) {
  154. tx := global.GVA_DB.Begin() // 开始事务
  155. insert := model.SysDictionaryDetailData()
  156. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  157. tx.Rollback()
  158. }
  159. return tx.Commit().Error
  160. }
  161. func InitExaFileUploadAndDownload() (err error) {
  162. tx := global.GVA_DB.Begin() // 开始事务
  163. insert := model.ExaFileUploadAndDownloadData()
  164. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  165. tx.Rollback()
  166. }
  167. return tx.Commit().Error
  168. }