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.1 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. "gorm.io/gorm"
  9. )
  10. var Files = []model.ExaFileUploadAndDownload{
  11. {global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "10.png", "http://qmplusimg.henrongyi.top/gvalogo.png", "png", "158787308910.png"},
  12. {global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "logo.png", "http://qmplusimg.henrongyi.top/1576554439myAvatar.png", "png", "1587973709logo.png"},
  13. }
  14. func InitExaFileUploadAndDownload(db *gorm.DB) {
  15. if err := db.Transaction(func(tx *gorm.DB) error {
  16. if tx.Where("id IN ?", []int{1, 2}).Find(&[]model.ExaFileUploadAndDownload{}).RowsAffected == 2 {
  17. color.Danger.Println("exa_file_upload_and_downloads表的初始数据已存在!")
  18. return nil
  19. }
  20. if err := tx.Create(&Files).Error; err != nil { // 遇到错误时回滚事务
  21. return err
  22. }
  23. color.Info.Println("[Mysql]-->初始化数据成功")
  24. return nil
  25. }); err != nil {
  26. color.Warn.Printf("[Mysql]--> exa_file_upload_and_downloads 表的初始数据失败,err: %v\n", err)
  27. os.Exit(0)
  28. }
  29. }