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.

31 lines
861 B

  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 Customers = []model.ExaCustomer{
  11. {GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, CustomerName: "测试客户", CustomerPhoneData: "1761111111", SysUserID: 1, SysUserAuthorityID: "888"},
  12. }
  13. func InitExaCustomer(db *gorm.DB) {
  14. if err := db.Transaction(func(tx *gorm.DB) error {
  15. if tx.Where("id IN ? ", []int{1}).Find(&[]model.ExaCustomer{}).RowsAffected == 1 {
  16. color.Danger.Println("exa_customers表的初始数据已存在!")
  17. return nil
  18. }
  19. if err := tx.Create(&Customers).Error; err != nil { // 遇到错误时回滚事务
  20. return err
  21. }
  22. return nil
  23. }); err != nil {
  24. color.Warn.Printf("[Mysql]--> exa_customers 表的初始数据失败,err: %v\n", err)
  25. os.Exit(0)
  26. }
  27. }