Browse Source

表格转orm遗漏

xyxie 2 months ago
parent
commit
16254de4b7
1 changed files with 19 additions and 23 deletions
  1. 19 23
      models/data_manage/excel/excel_info.go

+ 19 - 23
models/data_manage/excel/excel_info.go

@@ -5,7 +5,7 @@ import (
 	"eta/eta_api/models/data_manage"
 	"eta/eta_api/utils"
 	"fmt"
-	"github.com/beego/beego/v2/client/orm"
+
 	"strconv"
 	"time"
 )
@@ -150,11 +150,11 @@ func EditExcelInfo(excelInfo *ExcelInfo, updateExcelInfoParams []string, excelEd
 
 // GetExcelInfoAll 获取所有表格列表,用于分类展示
 func GetExcelInfoAll() (items []*ExcelClassifyItems, err error) {
-	o := orm.NewOrmUsingDB("data")
+	o := global.DbMap[utils.DbNameIndex]
 	sql := ` SELECT excel_info_id,excel_classify_id,excel_name AS excel_classify_name,
              unique_code,sys_user_id,sys_user_real_name,is_join_permission
             FROM excel_info where is_delete=0 ORDER BY sort asc,create_time ASC `
-	_, err = o.Raw(sql).QueryRows(&items)
+	err = o.Raw(sql).Find(&items).Error
 	return
 }
 
@@ -200,9 +200,9 @@ func GetBalanceNoContentExcelInfoAll(source int, excelInfoIds []int, userId int)
 
 // GetAllExcelInfoBySource 根据来源获取包含content的表格列表
 func GetAllExcelInfoBySource(source int) (items []*ExcelInfo, err error) {
-	o := orm.NewOrmUsingDB("data")
+	o := global.DbMap[utils.DbNameIndex]
 	sql := ` SELECT * FROM excel_info where is_delete=0  AND source = ?  ORDER BY sort asc,create_time desc `
-	_, err = o.Raw(sql, source).QueryRows(&items)
+	err = o.Raw(sql, source).Find(&items).Error
 	return
 }
 
@@ -221,9 +221,9 @@ func GetExcelInfoByUnicode(unicode string) (item *ExcelInfo, err error) {
 }
 
 func GetExcelInfoViewById(excelInfoId int) (item *ExcelInfoView, err error) {
-	o := orm.NewOrmUsingDB("data")
+	o := global.DbMap[utils.DbNameIndex]
 	sql := ` SELECT * FROM excel_info WHERE excel_info_id=? AND is_delete=0 `
-	err = o.Raw(sql, excelInfoId).QueryRow(&item)
+	err = o.Raw(sql, excelInfoId).First(&item).Error
 	return
 }
 
@@ -299,10 +299,10 @@ func GetNextExcelInfo(classifyId, classifySort, source int) (item *ExcelInfo, er
 
 // EditExcelInfoImage 修改excel表格的图片
 func EditExcelInfoImage(excelInfoId int, imageUrl string) (err error) {
-	o := orm.NewOrmUsingDB("data")
+	o := global.DbMap[utils.DbNameIndex]
 
 	sql := ` UPDATE  excel_info SET excel_image=?, modify_time = NOW() WHERE excel_info_id = ? AND is_delete=0 `
-	_, err = o.Raw(sql, imageUrl, excelInfoId).Exec()
+	err = o.Exec(sql, imageUrl, excelInfoId).Error
 	if err != nil {
 		fmt.Println("EditExcelInfoImage Err:", err.Error())
 		return err
@@ -371,9 +371,9 @@ type ExcelInfoView struct {
 
 // GetExcelInfoByClassifyIdAndName 根据分类id和表格名获取表格信息
 func GetExcelInfoByClassifyIdAndName(classifyId int, excelName string) (item *ExcelInfo, err error) {
-	o := orm.NewOrmUsingDB("data")
+	o := global.DbMap[utils.DbNameIndex]
 	sql := ` SELECT * FROM excel_info WHERE excel_classify_id = ? and excel_name=? AND is_delete=0 `
-	err = o.Raw(sql, classifyId, excelName).QueryRow(&item)
+	err = o.Raw(sql, classifyId, excelName).First(&item).Error
 	return
 }
 
@@ -417,9 +417,9 @@ func GetExcelListCountByCondition(condition string, pars []interface{}) (count i
 
 // GetExcelViewInfoByExcelInfoId 根据excelInfoId 获取ETA表格详情
 func GetExcelViewInfoByExcelInfoId(excelInfoId int) (item *MyExcelInfoList, err error) {
-	o := orm.NewOrmUsingDB("data")
+	o := global.DbMap[utils.DbNameIndex]
 	sql := ` SELECT excel_info_id,source,excel_type,excel_name,unique_code,excel_classify_id,sys_user_id,sys_user_real_name,excel_image,file_url,sort,create_time,modify_time,is_join_permission FROM excel_info WHERE excel_info_id = ? AND is_delete=0 `
-	err = o.Raw(sql, excelInfoId).QueryRow(&item)
+	err = o.Raw(sql, excelInfoId).First(&item).Error
 	return
 }
 
@@ -432,9 +432,9 @@ func GetExcelInfoCountByClassifyId(classifyId int) (total int64, err error) {
 
 // UpdateExcelInfoClassifyId 更改表格分类
 func UpdateExcelInfoClassifyId(classifyId, excelInfoId int) (err error) {
-	o := orm.NewOrmUsingDB("data")
+	o := global.DbMap[utils.DbNameIndex]
 	sql := ` update excel_info set excel_classify_id = ? WHERE excel_info_id=? `
-	_, err = o.Raw(sql, classifyId, excelInfoId).Exec()
+	err = o.Exec(sql, classifyId, excelInfoId).Error
 
 	return
 }
@@ -787,18 +787,14 @@ type SearchExcelInfo struct {
 }
 
 func (m *ExcelInfo) Create() (err error) {
-	o := orm.NewOrmUsingDB("data")
-	id, err := o.Insert(m)
-	if err != nil {
-		return
-	}
-	m.ExcelInfoId = int(id)
+	o := global.DbMap[utils.DbNameIndex]
+	err = o.Create(m).Error
 	return
 }
 
 func (m *ExcelInfo) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
-	o := orm.NewOrmUsingDB("data")
+	o := global.DbMap[utils.DbNameIndex]
 	sql := fmt.Sprintf(`SELECT COUNT(1) FROM excel_info WHERE 1=1 %s`, condition)
-	err = o.Raw(sql, pars).QueryRow(&count)
+	err = o.Raw(sql, pars).Scan(&count).Error
 	return
 }