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.

28 lines
935 B

  1. package datas
  2. import (
  3. "gin-vue-admin/global"
  4. "github.com/gookit/color"
  5. "time"
  6. "gin-vue-admin/model"
  7. "gorm.io/gorm"
  8. )
  9. var Files = []model.ExaFileUploadAndDownload{
  10. {global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "10.png", "http://qmplusimg.henrongyi.top/gvalogo.png", "png", "158787308910.png"},
  11. {global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "logo.png", "http://qmplusimg.henrongyi.top/1576554439myAvatar.png", "png", "1587973709logo.png"},
  12. }
  13. func InitExaFileUploadAndDownload(db *gorm.DB) (err error) {
  14. return db.Transaction(func(tx *gorm.DB) error {
  15. if tx.Where("id IN ?", []int{1, 2}).Find(&[]model.ExaFileUploadAndDownload{}).RowsAffected == 2 {
  16. color.Danger.Println("exa_file_upload_and_downloads表的初始数据已存在!")
  17. return nil
  18. }
  19. if err := tx.Create(&Files).Error; err != nil { // 遇到错误时回滚事务
  20. return err
  21. }
  22. return nil
  23. })
  24. }