seed.go 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. package initialize
  2. import (
  3. "time"
  4. "wails-app/internal/dao"
  5. "wails-app/internal/global"
  6. "github.com/gofrs/uuid/v5"
  7. )
  8. // SeedSystemData seeds system base data if not already present.
  9. // Idempotent: checks if admin user exists, skips if so.
  10. func SeedSystemData() {
  11. db := global.GVA_DB
  12. if db == nil {
  13. return
  14. }
  15. var count int64
  16. db.Model(&dao.SysUser{}).Where("username = ?", "admin").Count(&count)
  17. if count > 0 {
  18. return
  19. }
  20. now := time.Date(2024, 5, 5, 9, 33, 22, 0, time.UTC)
  21. // --- sys_users ---
  22. users := []dao.SysUser{
  23. {
  24. UUID: uuid.Must(uuid.FromString("07c9149c-6a9a-4126-8d8a-dd11c7b914a1")),
  25. Username: "admin",
  26. Password: "$2a$10$WTDQCqEQzEi/FU2UKejgGuWDK3PtHT0yb6xwY.yhx4ugjAmS6iTNa",
  27. NickName: "龙弛管理员",
  28. SideMode: "dark",
  29. HeaderImg: "uploads/file/70b1e321d2ec7357cb1b948f5bde35a6_20240606094912.jpg",
  30. BaseColor: "#fff",
  31. ActiveColor: "#1890ff",
  32. AuthorityId: 888,
  33. Phone: "17611111111",
  34. Email: "333333333@qq.com",
  35. Enable: 1,
  36. },
  37. {
  38. UUID: uuid.Must(uuid.FromString("0a5db918-c3cc-4034-a32a-6c15f37e78cb")),
  39. Username: "xuwenhao",
  40. Password: "$2a$10$EL7QgO5cVNdB6N2rYqAQNOLj8w3mSh9noKpjmPfFO98ip0GyR9x3y",
  41. NickName: "许文浩",
  42. SideMode: "dark",
  43. HeaderImg: "uploads/file/c67b3af7ed83579cc083089fc0bbefd0_20240505115511.jpg",
  44. BaseColor: "#fff",
  45. ActiveColor: "#1890ff",
  46. AuthorityId: 888,
  47. Phone: "17365743261",
  48. Email: "sn3115614529@163.com",
  49. Enable: 1,
  50. },
  51. {
  52. UUID: uuid.Must(uuid.FromString("9fce89d6-8552-4637-9cd1-9ffd6c8d4dbd")),
  53. Username: "chengqian",
  54. Password: "$2a$10$0qbv0aeavXAxdqUNIAhIC.TK/hfgC8Ky.sP0dK9fAw9lIsR9cIive",
  55. NickName: "程潜",
  56. SideMode: "dark",
  57. HeaderImg: "https://qmplusimg.henrongyi.top/1576554439myAvatar.png",
  58. BaseColor: "#fff",
  59. ActiveColor: "#1890ff",
  60. AuthorityId: 618,
  61. Phone: "18574363259",
  62. Email: "",
  63. Enable: 1,
  64. },
  65. }
  66. for i := range users {
  67. users[i].CreatedAt = now
  68. users[i].UpdatedAt = now
  69. }
  70. db.Create(&users)
  71. // --- sys_authorities ---
  72. authorities := []dao.SysAuthority{
  73. {AuthorityId: 618, AuthorityName: "普通用户", ParentId: ptr(uint(0)), DefaultRouter: "dashboard", CreatedAt: now, UpdatedAt: now},
  74. {AuthorityId: 888, AuthorityName: "管理员", ParentId: ptr(uint(0)), DefaultRouter: "dashboard", CreatedAt: now, UpdatedAt: now},
  75. {AuthorityId: 9527, AuthorityName: "开发", ParentId: ptr(uint(0)), DefaultRouter: "dashboard", CreatedAt: now, UpdatedAt: now},
  76. }
  77. db.Create(&authorities)
  78. // --- sys_user_authority ---
  79. db.Create(&dao.SysUserAuthority{SysUserId: 1, SysAuthorityAuthorityId: 888})
  80. db.Create(&dao.SysUserAuthority{SysUserId: 3, SysAuthorityAuthorityId: 888})
  81. db.Create(&dao.SysUserAuthority{SysUserId: 4, SysAuthorityAuthorityId: 618})
  82. // --- sys_base_menus (active only, skipping soft-deleted; ParentId refs = new seq IDs) ---
  83. // New ID seq: 1=dashboard, 2=superAdmin, 3=authority, 4=menu, 5=api, 6=user, 7=dictionary, 8=operation,
  84. // 9=person, 10=systemTools, 11=autoCode, 12=formCreate, 13=system, 14=autoCodeAdmin,
  85. // 15=autoCodeEdit, 16=autoPkg, 17=state, 18=plugin, 19=exportTemplate
  86. menus := []dao.SysBaseMenu{
  87. {MenuLevel: 0, ParentId: 0, Path: "dashboard", Name: "dashboard", Hidden: false, Component: "view/dashboard/index.vue", Sort: 1, Meta: dao.Meta{Title: "仪表盘", Icon: "odometer"}},
  88. {MenuLevel: 0, ParentId: 0, Path: "admin", Name: "superAdmin", Hidden: false, Component: "view/superAdmin/index.vue", Sort: 3, Meta: dao.Meta{Title: "超级管理员", Icon: "user"}},
  89. {MenuLevel: 0, ParentId: 2, Path: "authority", Name: "authority", Hidden: false, Component: "view/superAdmin/authority/authority.vue", Sort: 1, Meta: dao.Meta{Title: "角色管理", Icon: "avatar"}},
  90. {MenuLevel: 0, ParentId: 2, Path: "menu", Name: "menu", Hidden: false, Component: "view/superAdmin/menu/menu.vue", Sort: 2, Meta: dao.Meta{KeepAlive: true, Title: "菜单管理", Icon: "tickets"}},
  91. {MenuLevel: 0, ParentId: 2, Path: "api", Name: "api", Hidden: false, Component: "view/superAdmin/api/api.vue", Sort: 3, Meta: dao.Meta{KeepAlive: true, Title: "api管理", Icon: "platform"}},
  92. {MenuLevel: 0, ParentId: 2, Path: "user", Name: "user", Hidden: false, Component: "view/superAdmin/user/user.vue", Sort: 4, Meta: dao.Meta{Title: "用户管理", Icon: "coordinate"}},
  93. {MenuLevel: 0, ParentId: 2, Path: "dictionary", Name: "dictionary", Hidden: false, Component: "view/superAdmin/dictionary/sysDictionary.vue", Sort: 5, Meta: dao.Meta{Title: "字典管理", Icon: "notebook"}},
  94. {MenuLevel: 0, ParentId: 2, Path: "operation", Name: "operation", Hidden: false, Component: "view/superAdmin/operation/sysOperationRecord.vue", Sort: 6, Meta: dao.Meta{Title: "操作历史", Icon: "pie-chart"}},
  95. {MenuLevel: 0, ParentId: 0, Path: "person", Name: "person", Hidden: true, Component: "view/person/person.vue", Sort: 4, Meta: dao.Meta{Title: "个人信息", Icon: "message"}},
  96. {MenuLevel: 0, ParentId: 0, Path: "systemTools", Name: "systemTools", Hidden: false, Component: "view/systemTools/index.vue", Sort: 5, Meta: dao.Meta{Title: "系统工具", Icon: "tools"}},
  97. {MenuLevel: 0, ParentId: 10, Path: "autoCode", Name: "autoCode", Hidden: false, Component: "view/systemTools/autoCode/index.vue", Sort: 1, Meta: dao.Meta{KeepAlive: true, Title: "代码生成器", Icon: "cpu"}},
  98. {MenuLevel: 0, ParentId: 10, Path: "formCreate", Name: "formCreate", Hidden: false, Component: "view/systemTools/formCreate/index.vue", Sort: 2, Meta: dao.Meta{KeepAlive: true, Title: "表单生成器", Icon: "magic-stick"}},
  99. {MenuLevel: 0, ParentId: 10, Path: "system", Name: "system", Hidden: false, Component: "view/systemTools/system/system.vue", Sort: 3, Meta: dao.Meta{Title: "系统配置", Icon: "operation"}},
  100. {MenuLevel: 0, ParentId: 10, Path: "autoCodeAdmin", Name: "autoCodeAdmin", Hidden: false, Component: "view/systemTools/autoCodeAdmin/index.vue", Sort: 1, Meta: dao.Meta{Title: "自动化代码管理", Icon: "magic-stick"}},
  101. {MenuLevel: 0, ParentId: 10, Path: "autoCodeEdit/:id", Name: "autoCodeEdit", Hidden: true, Component: "view/systemTools/autoCode/index.vue", Sort: 0, Meta: dao.Meta{Title: "自动化代码-${id}", Icon: "magic-stick"}},
  102. {MenuLevel: 0, ParentId: 10, Path: "autoPkg", Name: "autoPkg", Hidden: false, Component: "view/systemTools/autoPkg/autoPkg.vue", Sort: 0, Meta: dao.Meta{Title: "自动化package", Icon: "folder"}},
  103. {MenuLevel: 0, ParentId: 0, Path: "state", Name: "state", Hidden: false, Component: "view/system/state.vue", Sort: 8, Meta: dao.Meta{Title: "服务器状态", Icon: "cloudy"}},
  104. {MenuLevel: 0, ParentId: 0, Path: "plugin", Name: "plugin", Hidden: false, Component: "view/routerHolder.vue", Sort: 6, Meta: dao.Meta{Title: "插件系统", Icon: "cherry"}},
  105. {MenuLevel: 0, ParentId: 10, Path: "exportTemplate", Name: "exportTemplate", Hidden: false, Component: "view/systemTools/exportTemplate/exportTemplate.vue", Sort: 10, Meta: dao.Meta{Title: "表格模板", Icon: "reading"}},
  106. // 停车管理 (ID=20)
  107. {MenuLevel: 0, ParentId: 0, Path: "parking", Name: "parking", Hidden: false, Component: "", Sort: 2, Meta: dao.Meta{Title: "停车管理", Icon: "van"}},
  108. {MenuLevel: 0, ParentId: 20, Path: "parkingInfo", Name: "parkingInfo", Hidden: false, Component: "view/parking/parkingInfo/index.vue", Sort: 0, Meta: dao.Meta{Title: "停车场信息", Icon: "van"}},
  109. {MenuLevel: 0, ParentId: 20, Path: "carInfo", Name: "carInfo", Hidden: false, Component: "view/parking/carInfo.vue", Sort: 1, Meta: dao.Meta{Title: "车辆信息", Icon: "notebook"}},
  110. {MenuLevel: 0, ParentId: 20, Path: "carOwner", Name: "carOwner", Hidden: false, Component: "view/parking/carOwner.vue", Sort: 2, Meta: dao.Meta{Title: "车主管理", Icon: "stamp"}},
  111. {MenuLevel: 0, ParentId: 20, Path: "roster", Name: "roster", Hidden: false, Component: "view/parking/roster.vue", Sort: 3, Meta: dao.Meta{Title: "黑白名单", Icon: "memo"}},
  112. {MenuLevel: 0, ParentId: 20, Path: "pricing", Name: "pricing", Hidden: false, Component: "view/parking/pricing.vue", Sort: 4, Meta: dao.Meta{Title: "收费配置", Icon: "office-building"}},
  113. {MenuLevel: 0, ParentId: 20, Path: "entryExit", Name: "entryExit", Hidden: false, Component: "view/parking/entryExit.vue", Sort: 5, Meta: dao.Meta{Title: "进出场操作", Icon: "switch"}},
  114. {MenuLevel: 0, ParentId: 20, Path: "monthlyCard", Name: "monthlyCard", Hidden: false, Component: "view/parking/monthlyCard.vue", Sort: 6, Meta: dao.Meta{Title: "包月车管理", Icon: "calendar"}},
  115. // 报表查询 (ID=26)
  116. {MenuLevel: 0, ParentId: 0, Path: "report", Name: "report", Hidden: false, Component: "", Sort: 3, Meta: dao.Meta{Title: "报表查询", Icon: "data-analysis"}},
  117. {MenuLevel: 0, ParentId: 25, Path: "enter", Name: "enter", Hidden: false, Component: "view/report/enter.vue", Sort: 1, Meta: dao.Meta{Title: "进出记录", Icon: "sort"}},
  118. {MenuLevel: 0, ParentId: 25, Path: "sheet", Name: "sheet", Hidden: false, Component: "view/report/sheet.vue", Sort: 2, Meta: dao.Meta{Title: "异常报表", Icon: "document-copy"}},
  119. {MenuLevel: 0, ParentId: 25, Path: "paymentRecord", Name: "paymentRecord", Hidden: false, Component: "view/report/paymentRecord.vue", Sort: 3, Meta: dao.Meta{Title: "收费记录", Icon: "money"}},
  120. // 统计查询 (ID=28)
  121. {MenuLevel: 0, ParentId: 0, Path: "statistics", Name: "statistics", Hidden: false, Component: "", Sort: 4, Meta: dao.Meta{Title: "统计查询", Icon: "chat-line-round"}},
  122. {MenuLevel: 0, ParentId: 28, Path: "vehicle", Name: "vehicle", Hidden: false, Component: "view/statistics/vehicle.vue", Sort: 1, Meta: dao.Meta{Title: "在线车辆统计", Icon: "van"}},
  123. }
  124. for i := range menus {
  125. menus[i].CreatedAt = now
  126. menus[i].UpdatedAt = now
  127. }
  128. db.Create(&menus)
  129. // --- sys_authority_menus (new seq IDs: 1=dashboard,2=superAdmin,3-8=subs,9=person,
  130. // 20=parking,21-24=parking subs, 25=report,26-27=report subs, 28=statistics,29=stats sub) ---
  131. authMenus := []dao.SysAuthorityMenu{
  132. {MenuId: "1", AuthorityId: "618"},
  133. {MenuId: "1", AuthorityId: "888"},
  134. {MenuId: "1", AuthorityId: "9527"},
  135. {MenuId: "2", AuthorityId: "888"},
  136. {MenuId: "2", AuthorityId: "9527"},
  137. {MenuId: "3", AuthorityId: "888"},
  138. {MenuId: "3", AuthorityId: "9527"},
  139. {MenuId: "4", AuthorityId: "888"},
  140. {MenuId: "4", AuthorityId: "9527"},
  141. {MenuId: "5", AuthorityId: "888"},
  142. {MenuId: "5", AuthorityId: "9527"},
  143. {MenuId: "6", AuthorityId: "888"},
  144. {MenuId: "6", AuthorityId: "9527"},
  145. {MenuId: "7", AuthorityId: "888"},
  146. {MenuId: "7", AuthorityId: "9527"},
  147. {MenuId: "8", AuthorityId: "888"},
  148. {MenuId: "8", AuthorityId: "9527"},
  149. {MenuId: "9", AuthorityId: "618"},
  150. {MenuId: "9", AuthorityId: "888"},
  151. {MenuId: "9", AuthorityId: "9527"},
  152. // 停车管理 + 子菜单 (20-24,30) — admin + operator
  153. {MenuId: "20", AuthorityId: "618"}, {MenuId: "20", AuthorityId: "888"}, {MenuId: "20", AuthorityId: "9527"},
  154. {MenuId: "30", AuthorityId: "618"}, {MenuId: "30", AuthorityId: "888"}, {MenuId: "30", AuthorityId: "9527"},
  155. {MenuId: "21", AuthorityId: "618"}, {MenuId: "21", AuthorityId: "888"}, {MenuId: "21", AuthorityId: "9527"},
  156. {MenuId: "22", AuthorityId: "618"}, {MenuId: "22", AuthorityId: "888"}, {MenuId: "22", AuthorityId: "9527"},
  157. {MenuId: "23", AuthorityId: "618"}, {MenuId: "23", AuthorityId: "888"}, {MenuId: "23", AuthorityId: "9527"},
  158. {MenuId: "24", AuthorityId: "618"}, {MenuId: "24", AuthorityId: "888"}, {MenuId: "24", AuthorityId: "9527"},
  159. // 报表查询 + 子菜单 (25-27) — admin + operator
  160. {MenuId: "25", AuthorityId: "618"}, {MenuId: "25", AuthorityId: "888"}, {MenuId: "25", AuthorityId: "9527"},
  161. {MenuId: "26", AuthorityId: "618"}, {MenuId: "26", AuthorityId: "888"}, {MenuId: "26", AuthorityId: "9527"},
  162. {MenuId: "27", AuthorityId: "618"}, {MenuId: "27", AuthorityId: "888"}, {MenuId: "27", AuthorityId: "9527"},
  163. // 收费记录 (32) — admin + operator
  164. {MenuId: "32", AuthorityId: "618"}, {MenuId: "32", AuthorityId: "888"}, {MenuId: "32", AuthorityId: "9527"},
  165. // 统计查询 + 子菜单 (28-29) — admin + operator
  166. {MenuId: "28", AuthorityId: "618"}, {MenuId: "28", AuthorityId: "888"}, {MenuId: "28", AuthorityId: "9527"},
  167. {MenuId: "29", AuthorityId: "618"}, {MenuId: "29", AuthorityId: "888"}, {MenuId: "29", AuthorityId: "9527"},
  168. // 进出场操作 (31) — admin + operator
  169. {MenuId: "31", AuthorityId: "618"}, {MenuId: "31", AuthorityId: "888"}, {MenuId: "31", AuthorityId: "9527"},
  170. // 包月车管理 (33) — admin + operator
  171. {MenuId: "33", AuthorityId: "618"}, {MenuId: "33", AuthorityId: "888"}, {MenuId: "33", AuthorityId: "9527"},
  172. }
  173. db.Create(&authMenus)
  174. // --- vehicle_type (默认车辆类型:临时车,标记为系统内置) ---
  175. db.FirstOrCreate(&dao.VehicleType{},
  176. dao.VehicleType{Name: "临时车", IsSystem: true, Remarks: "系统内置"},
  177. )
  178. // --- sys_apis (active only, skipping soft-deleted ids 44-66,84,90-98) ---
  179. apis := []dao.SysApi{
  180. {Path: "/jwt/jsonInBlacklist", Description: "jwt加入黑名单(退出,必选)", ApiGroup: "jwt", Method: "POST"},
  181. {Path: "/user/deleteUser", Description: "删除用户", ApiGroup: "系统用户", Method: "DELETE"},
  182. {Path: "/user/admin_register", Description: "用户注册", ApiGroup: "系统用户", Method: "POST"},
  183. {Path: "/user/getUserList", Description: "获取用户列表", ApiGroup: "系统用户", Method: "POST"},
  184. {Path: "/user/setUserInfo", Description: "设置用户信息", ApiGroup: "系统用户", Method: "PUT"},
  185. {Path: "/user/setSelfInfo", Description: "设置自身信息(必选)", ApiGroup: "系统用户", Method: "PUT"},
  186. {Path: "/user/getUserInfo", Description: "获取自身信息(必选)", ApiGroup: "系统用户", Method: "GET"},
  187. {Path: "/user/setUserAuthorities", Description: "设置权限组", ApiGroup: "系统用户", Method: "POST"},
  188. {Path: "/user/changePassword", Description: "修改密码(建议选择)", ApiGroup: "系统用户", Method: "POST"},
  189. {Path: "/user/setUserAuthority", Description: "修改用户角色(必选)", ApiGroup: "系统用户", Method: "POST"},
  190. {Path: "/user/resetPassword", Description: "重置用户密码", ApiGroup: "系统用户", Method: "POST"},
  191. {Path: "/api/createApi", Description: "创建api", ApiGroup: "api", Method: "POST"},
  192. {Path: "/api/deleteApi", Description: "删除Api", ApiGroup: "api", Method: "POST"},
  193. {Path: "/api/updateApi", Description: "更新Api", ApiGroup: "api", Method: "POST"},
  194. {Path: "/api/getApiList", Description: "获取api列表", ApiGroup: "api", Method: "POST"},
  195. {Path: "/api/getAllApis", Description: "获取所有api", ApiGroup: "api", Method: "POST"},
  196. {Path: "/api/getApiById", Description: "获取api详细信息", ApiGroup: "api", Method: "POST"},
  197. {Path: "/api/deleteApisByIds", Description: "批量删除api", ApiGroup: "api", Method: "DELETE"},
  198. {Path: "/authority/copyAuthority", Description: "拷贝角色", ApiGroup: "角色", Method: "POST"},
  199. {Path: "/authority/createAuthority", Description: "创建角色", ApiGroup: "角色", Method: "POST"},
  200. {Path: "/authority/deleteAuthority", Description: "删除角色", ApiGroup: "角色", Method: "POST"},
  201. {Path: "/authority/updateAuthority", Description: "更新角色信息", ApiGroup: "角色", Method: "PUT"},
  202. {Path: "/authority/getAuthorityList", Description: "获取角色列表", ApiGroup: "角色", Method: "POST"},
  203. {Path: "/authority/setDataAuthority", Description: "设置角色资源权限", ApiGroup: "角色", Method: "POST"},
  204. {Path: "/casbin/updateCasbin", Description: "更改角色api权限", ApiGroup: "casbin", Method: "POST"},
  205. {Path: "/casbin/getPolicyPathByAuthorityId", Description: "获取权限列表", ApiGroup: "casbin", Method: "POST"},
  206. {Path: "/menu/addBaseMenu", Description: "新增菜单", ApiGroup: "菜单", Method: "POST"},
  207. {Path: "/menu/getMenu", Description: "获取菜单树(必选)", ApiGroup: "菜单", Method: "POST"},
  208. {Path: "/menu/deleteBaseMenu", Description: "删除菜单", ApiGroup: "菜单", Method: "POST"},
  209. {Path: "/menu/updateBaseMenu", Description: "更新菜单", ApiGroup: "菜单", Method: "POST"},
  210. {Path: "/menu/getBaseMenuById", Description: "根据id获取菜单", ApiGroup: "菜单", Method: "POST"},
  211. {Path: "/menu/getMenuList", Description: "分页获取基础menu列表", ApiGroup: "菜单", Method: "POST"},
  212. {Path: "/menu/getBaseMenuTree", Description: "获取用户动态路由", ApiGroup: "菜单", Method: "POST"},
  213. {Path: "/menu/getMenuAuthority", Description: "获取指定角色menu", ApiGroup: "菜单", Method: "POST"},
  214. {Path: "/menu/addMenuAuthority", Description: "增加menu和角色关联关系", ApiGroup: "菜单", Method: "POST"},
  215. {Path: "/fileUploadAndDownload/findFile", Description: "寻找目标文件(秒传)", ApiGroup: "分片上传", Method: "GET"},
  216. {Path: "/fileUploadAndDownload/breakpointContinue", Description: "断点续传", ApiGroup: "分片上传", Method: "POST"},
  217. {Path: "/fileUploadAndDownload/breakpointContinueFinish", Description: "断点续传完成", ApiGroup: "分片上传", Method: "POST"},
  218. {Path: "/fileUploadAndDownload/removeChunk", Description: "上传完成移除文件", ApiGroup: "分片上传", Method: "POST"},
  219. {Path: "/fileUploadAndDownload/upload", Description: "文件上传示例", ApiGroup: "文件上传与下载", Method: "POST"},
  220. {Path: "/fileUploadAndDownload/deleteFile", Description: "删除文件", ApiGroup: "文件上传与下载", Method: "POST"},
  221. {Path: "/fileUploadAndDownload/editFileName", Description: "文件名或者备注编辑", ApiGroup: "文件上传与下载", Method: "POST"},
  222. {Path: "/fileUploadAndDownload/getFileList", Description: "获取上传文件列表", ApiGroup: "文件上传与下载", Method: "POST"},
  223. {Path: "/sysDictionaryDetail/updateSysDictionaryDetail", Description: "更新字典内容", ApiGroup: "系统字典详情", Method: "PUT"},
  224. {Path: "/sysDictionaryDetail/createSysDictionaryDetail", Description: "新增字典内容", ApiGroup: "系统字典详情", Method: "POST"},
  225. {Path: "/sysDictionaryDetail/deleteSysDictionaryDetail", Description: "删除字典内容", ApiGroup: "系统字典详情", Method: "DELETE"},
  226. {Path: "/sysDictionaryDetail/findSysDictionaryDetail", Description: "根据ID获取字典内容", ApiGroup: "系统字典详情", Method: "GET"},
  227. {Path: "/sysDictionaryDetail/getSysDictionaryDetailList", Description: "获取字典内容列表", ApiGroup: "系统字典详情", Method: "GET"},
  228. {Path: "/sysDictionary/createSysDictionary", Description: "新增字典", ApiGroup: "系统字典", Method: "POST"},
  229. {Path: "/sysDictionary/deleteSysDictionary", Description: "删除字典", ApiGroup: "系统字典", Method: "DELETE"},
  230. {Path: "/sysDictionary/updateSysDictionary", Description: "更新字典", ApiGroup: "系统字典", Method: "PUT"},
  231. {Path: "/sysDictionary/findSysDictionary", Description: "根据ID获取字典", ApiGroup: "系统字典", Method: "GET"},
  232. {Path: "/sysDictionary/getSysDictionaryList", Description: "获取字典列表", ApiGroup: "系统字典", Method: "GET"},
  233. {Path: "/sysOperationRecord/createSysOperationRecord", Description: "新增操作记录", ApiGroup: "操作记录", Method: "POST"},
  234. {Path: "/sysOperationRecord/findSysOperationRecord", Description: "根据ID获取操作记录", ApiGroup: "操作记录", Method: "GET"},
  235. {Path: "/sysOperationRecord/getSysOperationRecordList", Description: "获取操作记录列表", ApiGroup: "操作记录", Method: "GET"},
  236. {Path: "/sysOperationRecord/deleteSysOperationRecord", Description: "删除操作记录", ApiGroup: "操作记录", Method: "DELETE"},
  237. {Path: "/sysOperationRecord/deleteSysOperationRecordByIds", Description: "批量删除操作历史", ApiGroup: "操作记录", Method: "DELETE"},
  238. {Path: "/simpleUploader/upload", Description: "插件版分片上传", ApiGroup: "断点续传(插件版)", Method: "POST"},
  239. {Path: "/simpleUploader/checkFileMd5", Description: "文件完整度验证", ApiGroup: "断点续传(插件版)", Method: "GET"},
  240. {Path: "/email/emailTest", Description: "发送测试邮件", ApiGroup: "email", Method: "POST"},
  241. {Path: "/email/emailSend", Description: "发送邮件示例", ApiGroup: "email", Method: "POST"},
  242. {Path: "/authorityBtn/setAuthorityBtn", Description: "设置按钮权限", ApiGroup: "按钮权限", Method: "POST"},
  243. {Path: "/authorityBtn/getAuthorityBtn", Description: "获取已有按钮权限", ApiGroup: "按钮权限", Method: "POST"},
  244. {Path: "/authorityBtn/canRemoveAuthorityBtn", Description: "删除按钮", ApiGroup: "按钮权限", Method: "POST"},
  245. }
  246. for i := range apis {
  247. apis[i].CreatedAt = now
  248. apis[i].UpdatedAt = now
  249. }
  250. db.Create(&apis)
  251. // --- casbin_rule ---
  252. type casbinRule struct {
  253. Ptype string `gorm:"column:ptype"`
  254. V0 string `gorm:"column:v0"`
  255. V1 string `gorm:"column:v1"`
  256. V2 string `gorm:"column:v2"`
  257. V3 string `gorm:"column:v3"`
  258. V4 string `gorm:"column:v4"`
  259. V5 string `gorm:"column:v5"`
  260. }
  261. casbinRules := []casbinRule{
  262. // 618 (普通用户)
  263. {"p", "618", "/base/login", "POST", "", "", ""},
  264. {"p", "618", "/jwt/jsonInBlacklist", "POST", "", "", ""},
  265. {"p", "618", "/menu/getMenu", "POST", "", "", ""},
  266. {"p", "618", "/user/admin_register", "POST", "", "", ""},
  267. {"p", "618", "/user/changePassword", "POST", "", "", ""},
  268. {"p", "618", "/user/getUserInfo", "GET", "", "", ""},
  269. {"p", "618", "/user/setUserAuthority", "POST", "", "", ""},
  270. {"p", "618", "/user/setUserInfo", "PUT", "", "", ""},
  271. // 888 (管理员)
  272. {"p", "888", "/user/admin_register", "POST", "", "", ""},
  273. {"p", "888", "/api/createApi", "POST", "", "", ""},
  274. {"p", "888", "/api/getApiList", "POST", "", "", ""},
  275. {"p", "888", "/api/getApiById", "POST", "", "", ""},
  276. {"p", "888", "/api/deleteApi", "POST", "", "", ""},
  277. {"p", "888", "/api/updateApi", "POST", "", "", ""},
  278. {"p", "888", "/api/getAllApis", "POST", "", "", ""},
  279. {"p", "888", "/api/deleteApisByIds", "DELETE", "", "", ""},
  280. {"p", "888", "/authority/copyAuthority", "POST", "", "", ""},
  281. {"p", "888", "/authority/updateAuthority", "PUT", "", "", ""},
  282. {"p", "888", "/authority/createAuthority", "POST", "", "", ""},
  283. {"p", "888", "/authority/deleteAuthority", "POST", "", "", ""},
  284. {"p", "888", "/authority/getAuthorityList", "POST", "", "", ""},
  285. {"p", "888", "/authority/setDataAuthority", "POST", "", "", ""},
  286. {"p", "888", "/menu/getMenu", "POST", "", "", ""},
  287. {"p", "888", "/menu/getMenuList", "POST", "", "", ""},
  288. {"p", "888", "/menu/addBaseMenu", "POST", "", "", ""},
  289. {"p", "888", "/menu/getBaseMenuTree", "POST", "", "", ""},
  290. {"p", "888", "/menu/addMenuAuthority", "POST", "", "", ""},
  291. {"p", "888", "/menu/getMenuAuthority", "POST", "", "", ""},
  292. {"p", "888", "/menu/deleteBaseMenu", "POST", "", "", ""},
  293. {"p", "888", "/menu/updateBaseMenu", "POST", "", "", ""},
  294. {"p", "888", "/menu/getBaseMenuById", "POST", "", "", ""},
  295. {"p", "888", "/user/getUserInfo", "GET", "", "", ""},
  296. {"p", "888", "/user/setUserInfo", "PUT", "", "", ""},
  297. {"p", "888", "/user/setSelfInfo", "PUT", "", "", ""},
  298. {"p", "888", "/user/getUserList", "POST", "", "", ""},
  299. {"p", "888", "/user/deleteUser", "DELETE", "", "", ""},
  300. {"p", "888", "/user/changePassword", "POST", "", "", ""},
  301. {"p", "888", "/user/setUserAuthority", "POST", "", "", ""},
  302. {"p", "888", "/user/setUserAuthorities", "POST", "", "", ""},
  303. {"p", "888", "/user/resetPassword", "POST", "", "", ""},
  304. {"p", "888", "/fileUploadAndDownload/findFile", "GET", "", "", ""},
  305. {"p", "888", "/fileUploadAndDownload/breakpointContinueFinish", "POST", "", "", ""},
  306. {"p", "888", "/fileUploadAndDownload/breakpointContinue", "POST", "", "", ""},
  307. {"p", "888", "/fileUploadAndDownload/removeChunk", "POST", "", "", ""},
  308. {"p", "888", "/fileUploadAndDownload/upload", "POST", "", "", ""},
  309. {"p", "888", "/fileUploadAndDownload/deleteFile", "POST", "", "", ""},
  310. {"p", "888", "/fileUploadAndDownload/editFileName", "POST", "", "", ""},
  311. {"p", "888", "/fileUploadAndDownload/getFileList", "POST", "", "", ""},
  312. {"p", "888", "/casbin/updateCasbin", "POST", "", "", ""},
  313. {"p", "888", "/casbin/getPolicyPathByAuthorityId", "POST", "", "", ""},
  314. {"p", "888", "/jwt/jsonInBlacklist", "POST", "", "", ""},
  315. {"p", "888", "/sysDictionaryDetail/findSysDictionaryDetail", "GET", "", "", ""},
  316. {"p", "888", "/sysDictionaryDetail/updateSysDictionaryDetail", "PUT", "", "", ""},
  317. {"p", "888", "/sysDictionaryDetail/createSysDictionaryDetail", "POST", "", "", ""},
  318. {"p", "888", "/sysDictionaryDetail/getSysDictionaryDetailList", "GET", "", "", ""},
  319. {"p", "888", "/sysDictionaryDetail/deleteSysDictionaryDetail", "DELETE", "", "", ""},
  320. {"p", "888", "/sysDictionary/findSysDictionary", "GET", "", "", ""},
  321. {"p", "888", "/sysDictionary/updateSysDictionary", "PUT", "", "", ""},
  322. {"p", "888", "/sysDictionary/createSysDictionary", "POST", "", "", ""},
  323. {"p", "888", "/sysDictionary/deleteSysDictionary", "DELETE", "", "", ""},
  324. {"p", "888", "/sysDictionary/getSysDictionaryList", "GET", "", "", ""},
  325. {"p", "888", "/sysOperationRecord/findSysOperationRecord", "GET", "", "", ""},
  326. {"p", "888", "/sysOperationRecord/updateSysOperationRecord", "PUT", "", "", ""},
  327. {"p", "888", "/sysOperationRecord/createSysOperationRecord", "POST", "", "", ""},
  328. {"p", "888", "/sysOperationRecord/getSysOperationRecordList", "GET", "", "", ""},
  329. {"p", "888", "/sysOperationRecord/deleteSysOperationRecord", "DELETE", "", "", ""},
  330. {"p", "888", "/sysOperationRecord/deleteSysOperationRecordByIds", "DELETE", "", "", ""},
  331. {"p", "888", "/simpleUploader/upload", "POST", "", "", ""},
  332. {"p", "888", "/simpleUploader/checkFileMd5", "GET", "", "", ""},
  333. {"p", "888", "/email/emailTest", "POST", "", "", ""},
  334. {"p", "888", "/authorityBtn/setAuthorityBtn", "POST", "", "", ""},
  335. {"p", "888", "/authorityBtn/getAuthorityBtn", "POST", "", "", ""},
  336. {"p", "888", "/authorityBtn/canRemoveAuthorityBtn", "POST", "", "", ""},
  337. // 9527 (开发)
  338. {"p", "9527", "/jwt/jsonInBlacklist", "POST", "", "", ""},
  339. {"p", "9527", "/user/deleteUser", "DELETE", "", "", ""},
  340. {"p", "9527", "/user/admin_register", "POST", "", "", ""},
  341. {"p", "9527", "/user/getUserList", "POST", "", "", ""},
  342. {"p", "9527", "/user/setUserInfo", "PUT", "", "", ""},
  343. {"p", "9527", "/user/setSelfInfo", "PUT", "", "", ""},
  344. {"p", "9527", "/user/getUserInfo", "GET", "", "", ""},
  345. {"p", "9527", "/user/setUserAuthorities", "POST", "", "", ""},
  346. {"p", "9527", "/user/changePassword", "POST", "", "", ""},
  347. {"p", "9527", "/user/setUserAuthority", "POST", "", "", ""},
  348. {"p", "9527", "/user/resetPassword", "POST", "", "", ""},
  349. {"p", "9527", "/api/createApi", "POST", "", "", ""},
  350. {"p", "9527", "/api/deleteApi", "POST", "", "", ""},
  351. {"p", "9527", "/api/updateApi", "POST", "", "", ""},
  352. {"p", "9527", "/api/getApiList", "POST", "", "", ""},
  353. {"p", "9527", "/api/getAllApis", "POST", "", "", ""},
  354. {"p", "9527", "/api/getApiById", "POST", "", "", ""},
  355. {"p", "9527", "/api/deleteApisByIds", "DELETE", "", "", ""},
  356. {"p", "9527", "/authority/copyAuthority", "POST", "", "", ""},
  357. {"p", "9527", "/authority/createAuthority", "POST", "", "", ""},
  358. {"p", "9527", "/authority/deleteAuthority", "POST", "", "", ""},
  359. {"p", "9527", "/authority/updateAuthority", "PUT", "", "", ""},
  360. {"p", "9527", "/authority/getAuthorityList", "POST", "", "", ""},
  361. {"p", "9527", "/authority/setDataAuthority", "POST", "", "", ""},
  362. {"p", "9527", "/casbin/updateCasbin", "POST", "", "", ""},
  363. {"p", "9527", "/casbin/getPolicyPathByAuthorityId", "POST", "", "", ""},
  364. {"p", "9527", "/menu/addBaseMenu", "POST", "", "", ""},
  365. {"p", "9527", "/menu/getMenu", "POST", "", "", ""},
  366. {"p", "9527", "/menu/deleteBaseMenu", "POST", "", "", ""},
  367. {"p", "9527", "/menu/updateBaseMenu", "POST", "", "", ""},
  368. {"p", "9527", "/menu/getBaseMenuById", "POST", "", "", ""},
  369. {"p", "9527", "/menu/getMenuList", "POST", "", "", ""},
  370. {"p", "9527", "/menu/getBaseMenuTree", "POST", "", "", ""},
  371. {"p", "9527", "/menu/getMenuAuthority", "POST", "", "", ""},
  372. {"p", "9527", "/menu/addMenuAuthority", "POST", "", "", ""},
  373. {"p", "9527", "/fileUploadAndDownload/findFile", "GET", "", "", ""},
  374. {"p", "9527", "/fileUploadAndDownload/breakpointContinue", "POST", "", "", ""},
  375. {"p", "9527", "/fileUploadAndDownload/breakpointContinueFinish", "POST", "", "", ""},
  376. {"p", "9527", "/fileUploadAndDownload/removeChunk", "POST", "", "", ""},
  377. {"p", "9527", "/fileUploadAndDownload/upload", "POST", "", "", ""},
  378. {"p", "9527", "/fileUploadAndDownload/deleteFile", "POST", "", "", ""},
  379. {"p", "9527", "/fileUploadAndDownload/editFileName", "POST", "", "", ""},
  380. {"p", "9527", "/fileUploadAndDownload/getFileList", "POST", "", "", ""},
  381. {"p", "9527", "/sysDictionaryDetail/updateSysDictionaryDetail", "PUT", "", "", ""},
  382. {"p", "9527", "/sysDictionaryDetail/createSysDictionaryDetail", "POST", "", "", ""},
  383. {"p", "9527", "/sysDictionaryDetail/deleteSysDictionaryDetail", "DELETE", "", "", ""},
  384. {"p", "9527", "/sysDictionaryDetail/findSysDictionaryDetail", "GET", "", "", ""},
  385. {"p", "9527", "/sysDictionaryDetail/getSysDictionaryDetailList", "GET", "", "", ""},
  386. {"p", "9527", "/sysDictionary/createSysDictionary", "POST", "", "", ""},
  387. {"p", "9527", "/sysDictionary/deleteSysDictionary", "DELETE", "", "", ""},
  388. {"p", "9527", "/sysDictionary/updateSysDictionary", "PUT", "", "", ""},
  389. {"p", "9527", "/sysDictionary/findSysDictionary", "GET", "", "", ""},
  390. {"p", "9527", "/sysDictionary/getSysDictionaryList", "GET", "", "", ""},
  391. {"p", "9527", "/sysOperationRecord/createSysOperationRecord", "POST", "", "", ""},
  392. {"p", "9527", "/sysOperationRecord/findSysOperationRecord", "GET", "", "", ""},
  393. {"p", "9527", "/sysOperationRecord/getSysOperationRecordList", "GET", "", "", ""},
  394. {"p", "9527", "/sysOperationRecord/deleteSysOperationRecord", "DELETE", "", "", ""},
  395. {"p", "9527", "/sysOperationRecord/deleteSysOperationRecordByIds", "DELETE", "", "", ""},
  396. {"p", "9527", "/simpleUploader/upload", "POST", "", "", ""},
  397. {"p", "9527", "/simpleUploader/checkFileMd5", "GET", "", "", ""},
  398. {"p", "9527", "/email/emailTest", "POST", "", "", ""},
  399. {"p", "9527", "/email/emailSend", "POST", "", "", ""},
  400. {"p", "9527", "/authorityBtn/setAuthorityBtn", "POST", "", "", ""},
  401. {"p", "9527", "/authorityBtn/getAuthorityBtn", "POST", "", "", ""},
  402. {"p", "9527", "/authorityBtn/canRemoveAuthorityBtn", "POST", "", "", ""},
  403. // 收费结算 (vehicle/exit/preview, vehicle/exit/confirm) — admin + operator
  404. {"p", "888", "/vehicle/exit/preview", "POST", "", "", ""},
  405. {"p", "618", "/vehicle/exit/preview", "POST", "", "", ""},
  406. {"p", "888", "/vehicle/exit/confirm", "POST", "", "", ""},
  407. {"p", "618", "/vehicle/exit/confirm", "POST", "", "", ""},
  408. // 包月车管理
  409. {"p", "888", "/monthly-card/create", "POST", "", "", ""},
  410. {"p", "618", "/monthly-card/create", "POST", "", "", ""},
  411. {"p", "888", "/monthly-card/renew", "POST", "", "", ""},
  412. {"p", "618", "/monthly-card/renew", "POST", "", "", ""},
  413. {"p", "888", "/monthly-card/refund", "DELETE", "", "", ""},
  414. {"p", "618", "/monthly-card/refund", "DELETE", "", "", ""},
  415. {"p", "888", "/monthly-card/list", "GET", "", "", ""},
  416. {"p", "618", "/monthly-card/list", "GET", "", "", ""},
  417. // 收费记录查询
  418. {"p", "888", "/payment/list", "GET", "", "", ""},
  419. {"p", "618", "/payment/list", "GET", "", "", ""},
  420. }
  421. // Ensure casbin_rule table exists before seeding
  422. db.Exec(`CREATE TABLE IF NOT EXISTS casbin_rule (
  423. id INTEGER PRIMARY KEY AUTOINCREMENT,
  424. ptype TEXT,
  425. v0 TEXT,
  426. v1 TEXT,
  427. v2 TEXT,
  428. v3 TEXT,
  429. v4 TEXT,
  430. v5 TEXT
  431. )`)
  432. // Use raw SQL to insert casbin rules
  433. for _, r := range casbinRules {
  434. db.Exec("INSERT INTO casbin_rule (ptype, v0, v1, v2, v3, v4, v5) VALUES (?, ?, ?, ?, ?, ?, ?)",
  435. r.Ptype, r.V0, r.V1, r.V2, r.V3, r.V4, r.V5)
  436. }
  437. // --- sys_dictionaries (active only) ---
  438. dictionaries := []dao.SysDictionary{
  439. {Name: "性别", Type: "sex", Status: ptr(true), Desc: "性别字典", SysDictionaryDetails: []dao.SysDictionaryDetail{
  440. {Label: "男", Value: "1", Status: ptr(true), Sort: 1},
  441. {Label: "女", Value: "2", Status: ptr(true), Sort: 2},
  442. }},
  443. {Name: "数据库int类型", Type: "int", Status: ptr(true), Desc: "int类型对应的数据库类型", SysDictionaryDetails: []dao.SysDictionaryDetail{
  444. {Label: "smallint", Value: "1", Extend: "mysql", Status: ptr(true), Sort: 1},
  445. {Label: "mediumint", Value: "2", Extend: "mysql", Status: ptr(true), Sort: 2},
  446. {Label: "int", Value: "3", Extend: "mysql", Status: ptr(true), Sort: 3},
  447. {Label: "bigint", Value: "4", Extend: "mysql", Status: ptr(true), Sort: 4},
  448. {Label: "int2", Value: "5", Extend: "pgsql", Status: ptr(true), Sort: 5},
  449. {Label: "int4", Value: "6", Extend: "pgsql", Status: ptr(true), Sort: 6},
  450. {Label: "int6", Value: "7", Extend: "pgsql", Status: ptr(true), Sort: 7},
  451. {Label: "int8", Value: "8", Extend: "pgsql", Status: ptr(true), Sort: 8},
  452. }},
  453. {Name: "数据库时间日期类型", Type: "time.Time", Status: ptr(true), Desc: "数据库时间日期类型", SysDictionaryDetails: []dao.SysDictionaryDetail{
  454. {Label: "date", Value: "", Status: ptr(true), Sort: 0},
  455. {Label: "time", Value: "1", Extend: "mysql", Status: ptr(true), Sort: 1},
  456. {Label: "year", Value: "2", Extend: "mysql", Status: ptr(true), Sort: 2},
  457. {Label: "datetime", Value: "3", Extend: "mysql", Status: ptr(true), Sort: 3},
  458. {Label: "timestamp", Value: "5", Extend: "mysql", Status: ptr(true), Sort: 5},
  459. {Label: "timestamptz", Value: "6", Extend: "pgsql", Status: ptr(true), Sort: 5},
  460. }},
  461. {Name: "数据库浮点型", Type: "float64", Status: ptr(true), Desc: "数据库浮点型", SysDictionaryDetails: []dao.SysDictionaryDetail{
  462. {Label: "float", Value: "", Status: ptr(true), Sort: 0},
  463. {Label: "double", Value: "1", Extend: "mysql", Status: ptr(true), Sort: 1},
  464. {Label: "decimal", Value: "2", Extend: "mysql", Status: ptr(true), Sort: 2},
  465. {Label: "numeric", Value: "3", Extend: "pgsql", Status: ptr(true), Sort: 3},
  466. {Label: "smallserial", Value: "4", Extend: "pgsql", Status: ptr(true), Sort: 4},
  467. }},
  468. {Name: "数据库字符串", Type: "string", Status: ptr(true), Desc: "数据库字符串", SysDictionaryDetails: []dao.SysDictionaryDetail{
  469. {Label: "char", Value: "", Status: ptr(true), Sort: 0},
  470. {Label: "varchar", Value: "1", Extend: "mysql", Status: ptr(true), Sort: 1},
  471. {Label: "tinyblob", Value: "2", Extend: "mysql", Status: ptr(true), Sort: 2},
  472. {Label: "tinytext", Value: "3", Extend: "mysql", Status: ptr(true), Sort: 3},
  473. {Label: "text", Value: "4", Extend: "mysql", Status: ptr(true), Sort: 4},
  474. {Label: "blob", Value: "5", Extend: "mysql", Status: ptr(true), Sort: 5},
  475. {Label: "mediumblob", Value: "6", Extend: "mysql", Status: ptr(true), Sort: 6},
  476. {Label: "mediumtext", Value: "7", Extend: "mysql", Status: ptr(true), Sort: 7},
  477. {Label: "longblob", Value: "8", Extend: "mysql", Status: ptr(true), Sort: 8},
  478. {Label: "longtext", Value: "9", Extend: "mysql", Status: ptr(true), Sort: 9},
  479. }},
  480. {Name: "数据库bool类型", Type: "bool", Status: ptr(true), Desc: "数据库bool类型", SysDictionaryDetails: []dao.SysDictionaryDetail{
  481. {Label: "tinyint", Value: "1", Extend: "mysql", Status: ptr(true), Sort: 0},
  482. {Label: "bool", Value: "2", Extend: "pgsql", Status: ptr(true), Sort: 0},
  483. }},
  484. }
  485. for i := range dictionaries {
  486. dictionaries[i].CreatedAt = now
  487. dictionaries[i].UpdatedAt = now
  488. for j := range dictionaries[i].SysDictionaryDetails {
  489. dictionaries[i].SysDictionaryDetails[j].CreatedAt = now
  490. dictionaries[i].SysDictionaryDetails[j].UpdatedAt = now
  491. }
  492. }
  493. db.Create(&dictionaries)
  494. global.GVA_LOG.Info("system data seeded successfully")
  495. }
  496. // ptr returns a pointer to the given value.
  497. func ptr[T any](v T) *T {
  498. return &v
  499. }