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.

491 lines
33 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. }
  87. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  88. tx.Rollback()
  89. }
  90. return tx.Commit().Error
  91. }
  92. func InitSysUser() (err error) {
  93. tx := global.GVA_DB.Begin() // 开始事务
  94. insert := []model.SysUser{
  95. {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"},
  96. {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"},
  97. }
  98. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  99. tx.Rollback()
  100. }
  101. return tx.Commit().Error
  102. }
  103. func InitExaCustomer() (err error) {
  104. tx := global.GVA_DB.Begin() // 开始事务
  105. insert := []model.ExaCustomer{
  106. {Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, CustomerName: "测试客户", CustomerPhoneData: "1761111111", SysUserID: 1, SysUserAuthorityID: "888"},
  107. }
  108. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  109. tx.Rollback()
  110. }
  111. return tx.Commit().Error
  112. }
  113. func InitCasbinModel() (err error) {
  114. if !global.GVA_DB.Migrator().HasTable("casbin_rule") {
  115. if err := global.GVA_DB.Migrator().CreateTable(&gormadapter.CasbinRule{}); err != nil {
  116. return err
  117. }
  118. }
  119. tx := global.GVA_DB.Begin() // 开始事务
  120. insert := []model.CasbinModel{
  121. {"p", "888", "/base/login", "POST"},
  122. {"p", "888", "/base/register", "POST"},
  123. {"p", "888", "/api/createApi", "POST"},
  124. {"p", "888", "/api/getApiList", "POST"},
  125. {"p", "888", "/api/getApiById", "POST"},
  126. {"p", "888", "/api/deleteApi", "POST"},
  127. {"p", "888", "/api/updateApi", "POST"},
  128. {"p", "888", "/api/getAllApis", "POST"},
  129. {"p", "888", "/authority/createAuthority", "POST"},
  130. {"p", "888", "/authority/deleteAuthority", "POST"},
  131. {"p", "888", "/authority/getAuthorityList", "POST"},
  132. {"p", "888", "/authority/setDataAuthority", "POST"},
  133. {"p", "888", "/authority/updateAuthority", "PUT"},
  134. {"p", "888", "/authority/copyAuthority", "POST"},
  135. {"p", "888", "/menu/getMenu", "POST"},
  136. {"p", "888", "/menu/getMenuList", "POST"},
  137. {"p", "888", "/menu/addBaseMenu", "POST"},
  138. {"p", "888", "/menu/getBaseMenuTree", "POST"},
  139. {"p", "888", "/menu/addMenuAuthority", "POST"},
  140. {"p", "888", "/menu/getMenuAuthority", "POST"},
  141. {"p", "888", "/menu/deleteBaseMenu", "POST"},
  142. {"p", "888", "/menu/updateBaseMenu", "POST"},
  143. {"p", "888", "/menu/getBaseMenuById", "POST"},
  144. {"p", "888", "/user/changePassword", "POST"},
  145. {"p", "888", "/user/getUserList", "POST"},
  146. {"p", "888", "/user/setUserAuthority", "POST"},
  147. {"p", "888", "/user/deleteUser", "DELETE"},
  148. {"p", "888", "/fileUploadAndDownload/upload", "POST"},
  149. {"p", "888", "/fileUploadAndDownload/getFileList", "POST"},
  150. {"p", "888", "/fileUploadAndDownload/deleteFile", "POST"},
  151. {"p", "888", "/casbin/updateCasbin", "POST"},
  152. {"p", "888", "/casbin/getPolicyPathByAuthorityId", "POST"},
  153. {"p", "888", "/casbin/casbinTest/:pathParam", "GET"},
  154. {"p", "888", "/jwt/jsonInBlacklist", "POST"},
  155. {"p", "888", "/system/getSystemConfig", "POST"},
  156. {"p", "888", "/system/setSystemConfig", "POST"},
  157. {"p", "888", "/customer/customer", "POST"},
  158. {"p", "888", "/customer/customer", "PUT"},
  159. {"p", "888", "/customer/customer", "DELETE"},
  160. {"p", "888", "/customer/customer", "GET"},
  161. {"p", "888", "/customer/customerList", "GET"},
  162. {"p", "888", "/autoCode/createTemp", "POST"},
  163. {"p", "888", "/autoCode/getTables", "GET"},
  164. {"p", "888", "/autoCode/getDB", "GET"},
  165. {"p", "888", "/autoCode/getColume", "GET"},
  166. {"p", "888", "/sysDictionaryDetail/createSysDictionaryDetail", "POST"},
  167. {"p", "888", "/sysDictionaryDetail/deleteSysDictionaryDetail", "DELETE"},
  168. {"p", "888", "/sysDictionaryDetail/updateSysDictionaryDetail", "PUT"},
  169. {"p", "888", "/sysDictionaryDetail/findSysDictionaryDetail", "GET"},
  170. {"p", "888", "/sysDictionaryDetail/getSysDictionaryDetailList", "GET"},
  171. {"p", "888", "/sysDictionary/createSysDictionary", "POST"},
  172. {"p", "888", "/sysDictionary/deleteSysDictionary", "DELETE"},
  173. {"p", "888", "/sysDictionary/updateSysDictionary", "PUT"},
  174. {"p", "888", "/sysDictionary/findSysDictionary", "GET"},
  175. {"p", "888", "/sysDictionary/getSysDictionaryList", "GET"},
  176. {"p", "888", "/sysOperationRecord/createSysOperationRecord", "POST"},
  177. {"p", "888", "/sysOperationRecord/deleteSysOperationRecord", "DELETE"},
  178. {"p", "888", "/sysOperationRecord/updateSysOperationRecord", "PUT"},
  179. {"p", "888", "/sysOperationRecord/findSysOperationRecord", "GET"},
  180. {"p", "888", "/sysOperationRecord/getSysOperationRecordList", "GET"},
  181. {"p", "888", "/sysOperationRecord/deleteSysOperationRecordByIds", "DELETE"},
  182. {"p", "888", "/user/setUserInfo", "PUT"},
  183. {"p", "8881", "/base/login", "POST"},
  184. {"p", "8881", "/base/register", "POST"},
  185. {"p", "8881", "/api/createApi", "POST"},
  186. {"p", "8881", "/api/getApiList", "POST"},
  187. {"p", "8881", "/api/getApiById", "POST"},
  188. {"p", "8881", "/api/deleteApi", "POST"},
  189. {"p", "8881", "/api/updateApi", "POST"},
  190. {"p", "8881", "/api/getAllApis", "POST"},
  191. {"p", "8881", "/authority/createAuthority", "POST"},
  192. {"p", "8881", "/authority/deleteAuthority", "POST"},
  193. {"p", "8881", "/authority/getAuthorityList", "POST"},
  194. {"p", "8881", "/authority/setDataAuthority", "POST"},
  195. {"p", "8881", "/menu/getMenu", "POST"},
  196. {"p", "8881", "/menu/getMenuList", "POST"},
  197. {"p", "8881", "/menu/addBaseMenu", "POST"},
  198. {"p", "8881", "/menu/getBaseMenuTree", "POST"},
  199. {"p", "8881", "/menu/addMenuAuthority", "POST"},
  200. {"p", "8881", "/menu/getMenuAuthority", "POST"},
  201. {"p", "8881", "/menu/deleteBaseMenu", "POST"},
  202. {"p", "8881", "/menu/updateBaseMenu", "POST"},
  203. {"p", "8881", "/menu/getBaseMenuById", "POST"},
  204. {"p", "8881", "/user/changePassword", "POST"},
  205. {"p", "8881", "/user/getUserList", "POST"},
  206. {"p", "8881", "/user/setUserAuthority", "POST"},
  207. {"p", "8881", "/fileUploadAndDownload/upload", "POST"},
  208. {"p", "8881", "/fileUploadAndDownload/getFileList", "POST"},
  209. {"p", "8881", "/fileUploadAndDownload/deleteFile", "POST"},
  210. {"p", "8881", "/casbin/updateCasbin", "POST"},
  211. {"p", "8881", "/casbin/getPolicyPathByAuthorityId", "POST"},
  212. {"p", "8881", "/jwt/jsonInBlacklist", "POST"},
  213. {"p", "8881", "/system/getSystemConfig", "POST"},
  214. {"p", "8881", "/system/setSystemConfig", "POST"},
  215. {"p", "8881", "/customer/customer", "POST"},
  216. {"p", "8881", "/customer/customer", "PUT"},
  217. {"p", "8881", "/customer/customer", "DELETE"},
  218. {"p", "8881", "/customer/customer", "GET"},
  219. {"p", "8881", "/customer/customerList", "GET"},
  220. {"p", "9528", "/base/login", "POST"},
  221. {"p", "9528", "/base/register", "POST"},
  222. {"p", "9528", "/api/createApi", "POST"},
  223. {"p", "9528", "/api/getApiList", "POST"},
  224. {"p", "9528", "/api/getApiById", "POST"},
  225. {"p", "9528", "/api/deleteApi", "POST"},
  226. {"p", "9528", "/api/updateApi", "POST"},
  227. {"p", "9528", "/api/getAllApis", "POST"},
  228. {"p", "9528", "/authority/createAuthority", "POST"},
  229. {"p", "9528", "/authority/deleteAuthority", "POST"},
  230. {"p", "9528", "/authority/getAuthorityList", "POST"},
  231. {"p", "9528", "/authority/setDataAuthority", "POST"},
  232. {"p", "9528", "/menu/getMenu", "POST"},
  233. {"p", "9528", "/menu/getMenuList", "POST"},
  234. {"p", "9528", "/menu/addBaseMenu", "POST"},
  235. {"p", "9528", "/menu/getBaseMenuTree", "POST"},
  236. {"p", "9528", "/menu/addMenuAuthority", "POST"},
  237. {"p", "9528", "/menu/getMenuAuthority", "POST"},
  238. {"p", "9528", "/menu/deleteBaseMenu", "POST"},
  239. {"p", "9528", "/menu/updateBaseMenu", "POST"},
  240. {"p", "9528", "/menu/getBaseMenuById", "POST"},
  241. {"p", "9528", "/user/changePassword", "POST"},
  242. {"p", "9528", "/user/getUserList", "POST"},
  243. {"p", "9528", "/user/setUserAuthority", "POST"},
  244. {"p", "9528", "/fileUploadAndDownload/upload", "POST"},
  245. {"p", "9528", "/fileUploadAndDownload/getFileList", "POST"},
  246. {"p", "9528", "/fileUploadAndDownload/deleteFile", "POST"},
  247. {"p", "9528", "/casbin/updateCasbin", "POST"},
  248. {"p", "9528", "/casbin/getPolicyPathByAuthorityId", "POST"},
  249. {"p", "9528", "/jwt/jsonInBlacklist", "POST"},
  250. {"p", "9528", "/system/getSystemConfig", "POST"},
  251. {"p", "9528", "/system/setSystemConfig", "POST"},
  252. {"p", "9528", "/customer/customer", "POST"},
  253. {"p", "9528", "/customer/customer", "PUT"},
  254. {"p", "9528", "/customer/customer", "DELETE"},
  255. {"p", "9528", "/customer/customer", "GET"},
  256. {"p", "9528", "/customer/customerList", "GET"},
  257. {"p", "9528", "/autoCode/createTemp", "POST"},
  258. }
  259. if tx.Table("casbin_rule").Create(&insert).Error != nil { // 遇到错误时回滚事务
  260. tx.Rollback()
  261. }
  262. return tx.Commit().Error
  263. }
  264. func InitSysAuthority() (err error) {
  265. tx := global.GVA_DB.Begin() // 开始事务
  266. insert := []model.SysAuthority{
  267. {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "888", AuthorityName: "普通用户", ParentId: "0"},
  268. {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "8881", AuthorityName: "普通用户子角色", ParentId: "888"},
  269. {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "9528", AuthorityName: "测试角色", ParentId: "0"},
  270. }
  271. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  272. tx.Rollback()
  273. }
  274. return tx.Commit().Error
  275. }
  276. func InitSysBaseMenus() (err error) {
  277. tx := global.GVA_DB.Begin() // 开始事务
  278. insert := []model.SysBaseMenu{
  279. {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"}},
  280. {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"}},
  281. {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"}},
  282. {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"}},
  283. {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}},
  284. {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}},
  285. {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"}},
  286. {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"}},
  287. {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"}},
  288. {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"}},
  289. {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"}},
  290. {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"}},
  291. {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"}},
  292. {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"}},
  293. {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"}},
  294. {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"}},
  295. {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"}},
  296. {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}},
  297. {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}},
  298. {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"}},
  299. {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"}},
  300. {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"}},
  301. {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"}},
  302. {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"}},
  303. {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"}},
  304. {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"}},
  305. }
  306. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  307. tx.Rollback()
  308. }
  309. return tx.Commit().Error
  310. }
  311. func InitAuthorityMenu() (err error) {
  312. 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
  313. }
  314. func InitSysDictionary() (err error) {
  315. status := new(bool)
  316. *status = true
  317. tx := global.GVA_DB.Begin() // 开始事务
  318. insert := []model.SysDictionary{
  319. {Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "性别", Type: "sex", Status: status, Desc: "性别字典"},
  320. {Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库int类型", Type: "int", Status: status, Desc: "int类型对应的数据库类型"},
  321. {Model: gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库时间日期类型", Type: "time.Time", Status: status, Desc: "数据库时间日期类型"},
  322. {Model: gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库浮点型", Type: "float64", Status: status, Desc: "数据库浮点型"},
  323. {Model: gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库字符串", Type: "string", Status: status, Desc: "数据库字符串"},
  324. {Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Desc: "数据库bool类型"},
  325. }
  326. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  327. tx.Rollback()
  328. }
  329. return tx.Commit().Error
  330. }
  331. func InitSysAuthorityMenus() (err error) {
  332. tx := global.GVA_DB.Begin() // 开始事务
  333. insert := []SysAuthorityMenus{
  334. {"888", 1},
  335. {"888", 2},
  336. {"888", 3},
  337. {"888", 4},
  338. {"888", 5},
  339. {"888", 6},
  340. {"888", 7},
  341. {"888", 8},
  342. {"888", 9},
  343. {"888", 10},
  344. {"888", 11},
  345. {"888", 12},
  346. {"888", 13},
  347. {"888", 14},
  348. {"888", 15},
  349. {"888", 16},
  350. {"888", 17},
  351. {"888", 18},
  352. {"888", 19},
  353. {"888", 20},
  354. {"888", 21},
  355. {"888", 22},
  356. {"888", 23},
  357. {"888", 24},
  358. {"888", 25},
  359. {"888", 26},
  360. {"8881", 1},
  361. {"8881", 2},
  362. {"8881", 8},
  363. {"8881", 17},
  364. {"8881", 18},
  365. {"8881", 19},
  366. {"8881", 20},
  367. {"9528", 1},
  368. {"9528", 2},
  369. {"9528", 3},
  370. {"9528", 4},
  371. {"9528", 5},
  372. {"9528", 6},
  373. {"9528", 7},
  374. {"9528", 8},
  375. {"9528", 9},
  376. {"9528", 10},
  377. {"9528", 11},
  378. {"9528", 12},
  379. {"9528", 13},
  380. {"9528", 14},
  381. {"9528", 15},
  382. {"9528", 17},
  383. {"9528", 18},
  384. {"9528", 19},
  385. {"9528", 20},
  386. }
  387. if tx.Table("sys_authority_menus").Create(&insert).Error != nil { // 遇到错误时回滚事务
  388. tx.Rollback()
  389. }
  390. return tx.Commit().Error
  391. }
  392. func InitSysDataAuthorityId() (err error) {
  393. tx := global.GVA_DB.Begin() // 开始事务
  394. insert := []SysDataAuthorityId{
  395. {"888", "888"},
  396. {"888", "8881"},
  397. {"888", "9528"},
  398. {"9528", "8881"},
  399. {"9528", "9528"},
  400. }
  401. if global.GVA_DB.Migrator().HasTable("sys_data_authority_ids") {
  402. if tx.Table("sys_data_authority_ids").Create(&insert).Error != nil { // 遇到错误时回滚事务
  403. tx.Rollback()
  404. }
  405. return tx.Commit().Error
  406. }
  407. if tx.Table("sys_data_authority_id").Create(&insert).Error != nil { // 遇到错误时回滚事务
  408. tx.Rollback()
  409. }
  410. return tx.Commit().Error
  411. }
  412. func InitSysDictionaryDetail() (err error) {
  413. status := new(bool)
  414. *status = true
  415. tx := global.GVA_DB.Begin() // 开始事务
  416. insert := []model.SysDictionaryDetail{
  417. {gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "smallint", 1, status, 1, 2},
  418. {gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumint", 2, status, 2, 2},
  419. {gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "int", 3, status, 3, 2},
  420. {gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "bigint", 4, status, 4, 2},
  421. {gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "data", 0, status, 0, 3},
  422. {gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "time", 1, status, 1, 3},
  423. {gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "year", 2, status, 2, 3},
  424. {gorm.Model{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "datetime", 3, status, 3, 3},
  425. {gorm.Model{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "timestamp", 5, status, 5, 3},
  426. {gorm.Model{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "float", 0, status, 0, 4},
  427. {gorm.Model{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "double", 1, status, 1, 4},
  428. {gorm.Model{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "decimal", 2, status, 2, 4},
  429. {gorm.Model{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "char", 0, status, 0, 5},
  430. {gorm.Model{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "varchar", 1, status, 1, 5},
  431. {gorm.Model{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyblob", 2, status, 2, 5},
  432. {gorm.Model{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinytext", 3, status, 3, 5},
  433. {gorm.Model{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "text", 4, status, 4, 5},
  434. {gorm.Model{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "blob", 5, status, 5, 5},
  435. {gorm.Model{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumblob", 6, status, 6, 5},
  436. {gorm.Model{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumtext", 7, status, 7, 5},
  437. {gorm.Model{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "longblob", 8, status, 8, 5},
  438. {gorm.Model{ID: 22, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "longtext", 9, status, 9, 5},
  439. {gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyint", 0, status, 0, 6},
  440. }
  441. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  442. tx.Rollback()
  443. }
  444. return tx.Commit().Error
  445. }
  446. func InitExaFileUploadAndDownload() (err error) {
  447. tx := global.GVA_DB.Begin() // 开始事务
  448. insert := []model.ExaFileUploadAndDownload{
  449. {gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "10.png", "http://qmplusimg.henrongyi.top/gvalogo.png", "png", "158787308910.png"},
  450. {gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "logo.png", "http://qmplusimg.henrongyi.top/1576554439myAvatar.png", "png", "1587973709logo.png"},
  451. }
  452. if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
  453. tx.Rollback()
  454. }
  455. return tx.Commit().Error
  456. }
  457. func InitData() {
  458. var err error
  459. err = InitSysApi()
  460. err = InitSysUser()
  461. err = InitExaCustomer()
  462. err = InitCasbinModel()
  463. err = InitSysAuthority()
  464. err = InitSysBaseMenus()
  465. err = InitAuthorityMenu()
  466. err = InitSysDictionary()
  467. err = InitSysAuthorityMenus()
  468. err = InitSysDataAuthorityId()
  469. err = InitSysDictionaryDetail()
  470. err = InitExaFileUploadAndDownload()
  471. if err != nil {
  472. global.GVA_LOG.Error("initialize data failed", zap.Any("err", err))
  473. }
  474. global.GVA_LOG.Info("initialize data success")
  475. }