浏览代码

修复gorm

kobe6258 3 周之前
父节点
当前提交
7fca78b3ab
共有 3 个文件被更改,包括 4 次插入12 次删除
  1. 0 1
      controllers/cloud_disk.go
  2. 0 6
      models/cloud_disk_menu.go
  3. 4 5
      models/cloud_disk_resource.go

+ 0 - 1
controllers/cloud_disk.go

@@ -1288,7 +1288,6 @@ func (this *CloudDiskController) Page() {
 	fmt.Printf("初始化查询参数耗时: %v\n", time.Since(startTime))
 	//等待完成建树
 	wg.Wait()
-	fmt.Println()
 	if len(menuIdList) > 0 {
 		if subMenu {
 			menuIdChan := make(chan []int, len(menuIdList))

+ 0 - 6
models/cloud_disk_menu.go

@@ -1,15 +1,9 @@
 package models
 
 import (
-<<<<<<< HEAD
 	"eta/eta_api/utils"
 	"fmt"
-	"github.com/beego/beego/v2/client/orm"
-=======
 	"eta/eta_api/global"
-	"eta/eta_api/utils"
-	"fmt"
->>>>>>> master
 	"strings"
 	"time"
 )

+ 4 - 5
models/cloud_disk_resource.go

@@ -1,11 +1,11 @@
 package models
 
 import (
+	"eta/eta_api/global"
 	"eta/eta_api/utils"
 	"fmt"
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/rdlucklib/rdluck_tools/paging"
-	"eta/eta_api/global"
 	"gorm.io/gorm"
 	"strings"
 	"time"
@@ -241,16 +241,15 @@ func BatchDeleteCloudDiskMenuAndResource(menuIds, resourceIds []int) (err error)
 }
 
 func GetCloudDiskResourcePageCount(resourceCond string, resourcePars []interface{}) (total int, err error) {
-	o := orm.NewOrm()
 	sql := fmt.Sprintf(`SELECT COUNT(1) FROM cloud_disk_resource WHERE 1=1 %s `, resourceCond)
-	err = o.Raw(sql, resourcePars).QueryRow(&total)
+	err = global.DEFAULT_DB.Raw(sql, resourcePars...).Scan(&total).Error
 	return
 }
 func GetCloudDiskResourcePageList(resourceCond string, resourcePars []interface{}, orderRule string, startSize, pageSize int, menuNameMap map[int]string) (resourceList []*CloudDiskResourcePageItem, err error) {
-	o := orm.NewOrm()
 	sql := fmt.Sprintf(`SELECT resource_id , resource_name, resource_suffix, menu_id, size, admin_name, create_time FROM cloud_disk_resource WHERE 1=1 %s order by  %s LIMIT ?,?`, resourceCond, orderRule)
 	var ormList []*CloudDiskResource
-	_, err = o.Raw(sql, resourcePars, startSize, pageSize).QueryRows(&ormList)
+	resourcePars = append(resourcePars, startSize, pageSize)
+	err = global.DEFAULT_DB.Raw(sql, resourcePars...).Find(&ormList).Error
 	if err != nil {
 		return
 	}