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.

33 lines
1.2 KiB

  1. package datas
  2. import (
  3. "gin-vue-admin/global"
  4. "github.com/gookit/color"
  5. "os"
  6. "time"
  7. "gin-vue-admin/model"
  8. uuid "github.com/satori/go.uuid"
  9. "gorm.io/gorm"
  10. )
  11. var Users = []model.SysUser{
  12. {GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, UUID: uuid.NewV4(), Username: "admin", Password: "e10adc3949ba59abbe56e057f20f883e", NickName: "超级管理员", HeaderImg: "http://qmplusimg.henrongyi.top/gva_header.jpg", AuthorityId: "888"},
  13. {GVA_MODEL: global.GVA_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"},
  14. }
  15. func InitSysUser(db *gorm.DB) {
  16. if err := db.Transaction(func(tx *gorm.DB) error {
  17. if tx.Where("id IN ?", []int{1, 2}).Find(&[]model.SysUser{}).RowsAffected == 2 {
  18. color.Danger.Println("sys_users表的初始数据已存在!")
  19. return nil
  20. }
  21. if err := tx.Create(&Users).Error; err != nil { // 遇到错误时回滚事务
  22. return err
  23. }
  24. return nil
  25. }); err != nil {
  26. color.Warn.Printf("[Mysql]--> sys_users 表的初始数据失败,err: %v\n", err)
  27. os.Exit(0)
  28. }
  29. }