Pārlūkot izejas kodu

修改mysql为达梦数据库

genlong 1 mēnesi atpakaļ
vecāks
revīzija
30b206ef51

+ 44 - 27
models/data_manage/chart_theme/chart_theme.go

@@ -2,7 +2,7 @@ package chart_theme
 
 import (
 	"errors"
-	"github.com/beego/beego/v2/client/orm"
+	"eta_gn/eta_api/global"
 	"time"
 )
 
@@ -30,9 +30,13 @@ type ChartTheme struct {
 // @return item *ChartTheme
 // @return err error
 func GetChartThemeId(chartThemeId int) (item *ChartTheme, err error) {
-	o := orm.NewOrmUsingDB("data")
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT * FROM chart_theme where chart_theme_id = ? AND is_delete = 0`
+	//err = o.Raw(sql, chartThemeId).QueryRow(&item)
+
 	sql := `SELECT * FROM chart_theme where chart_theme_id = ? AND is_delete = 0`
-	err = o.Raw(sql, chartThemeId).QueryRow(&item)
+	err = global.DmSQL["data"].Raw(sql, chartThemeId).First(&item).Error
+	return
 
 	return
 }
@@ -49,13 +53,13 @@ func (m *ChartTheme) Add() (err error) {
 		err = errors.New("该配置已存在")
 		return
 	}
-	o := orm.NewOrmUsingDB("data")
-	lastId, err := o.Insert(m)
-	if err != nil {
-		return
-	}
-	m.ChartThemeId = int(lastId)
-
+	//o := orm.NewOrmUsingDB("data")
+	//lastId, err := o.Insert(m)
+	//if err != nil {
+	//	return
+	//}
+	//m.ChartThemeId = int(lastId)
+	err = global.DmSQL["data"].Create(m).Error
 	return
 }
 
@@ -67,8 +71,9 @@ func (m *ChartTheme) Add() (err error) {
 // @param cols []string
 // @return err error
 func (m *ChartTheme) Update(cols []string) (err error) {
-	o := orm.NewOrmUsingDB("data")
-	_, err = o.Update(m, cols...)
+	//o := orm.NewOrmUsingDB("data")
+	//_, err = o.Update(m, cols...)
+	err = global.DmSQL["data"].Select(cols).Updates(m).Error
 	return
 }
 
@@ -79,10 +84,12 @@ func (m *ChartTheme) Update(cols []string) (err error) {
 // @return list []*ChartTheme
 // @return err error
 func GetChartThemeListByTypeId(chartThemeTypeId int) (list []*ChartTheme, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT * FROM chart_theme WHERE chart_theme_type_id = ? AND  is_delete=0 ORDER BY chart_theme_id ASC `
-	_, err = o.Raw(sql, chartThemeTypeId).QueryRows(&list)
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT * FROM chart_theme WHERE chart_theme_type_id = ? AND  is_delete=0 ORDER BY chart_theme_id ASC `
+	//_, err = o.Raw(sql, chartThemeTypeId).QueryRows(&list)
 
+	sql := `SELECT * FROM chart_theme WHERE chart_theme_type_id = ? AND  is_delete=0 ORDER BY chart_theme_id ASC `
+	err = global.DmSQL["data"].Raw(sql, chartThemeTypeId).Find(&list).Error
 	return
 }
 
@@ -93,10 +100,12 @@ func GetChartThemeListByTypeId(chartThemeTypeId int) (list []*ChartTheme, err er
 // @return list []*ChartTheme
 // @return err error
 func GetAllChartThemeList() (list []*ChartTheme, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT * FROM chart_theme WHERE  is_delete=0 ORDER BY chart_theme_id ASC `
-	_, err = o.Raw(sql).QueryRows(&list)
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT * FROM chart_theme WHERE  is_delete=0 ORDER BY chart_theme_id ASC `
+	//_, err = o.Raw(sql).QueryRows(&list)
 
+	sql := `SELECT * FROM chart_theme WHERE  is_delete=0 ORDER BY chart_theme_id ASC `
+	err = global.DmSQL["data"].Raw(sql).Find(&list).Error
 	return
 }
 
@@ -125,12 +134,16 @@ type ChartThemeItem struct {
 // @return list []*ChartThemeConfig
 // @return err error
 func GetChartThemeItemList(chartThemeTypeId int) (list []*ChartThemeItem, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT a.*,b.default_chart_theme_id FROM chart_theme a 
-         JOIN chart_theme_type b on a.chart_theme_type_id =b.chart_theme_type_id 
-         WHERE a.chart_theme_type_id = ? AND a.is_delete=0 ORDER BY a.chart_theme_id ASC `
-	_, err = o.Raw(sql, chartThemeTypeId).QueryRows(&list)
-
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT a.*,b.default_chart_theme_id FROM chart_theme a
+	//     JOIN chart_theme_type b on a.chart_theme_type_id =b.chart_theme_type_id
+	//     WHERE a.chart_theme_type_id = ? AND a.is_delete=0 ORDER BY a.chart_theme_id ASC `
+	//_, err = o.Raw(sql, chartThemeTypeId).QueryRows(&list)
+
+	sql := `SELECT a.*,b.default_chart_theme_id FROM chart_theme a
+	    JOIN chart_theme_type b on a.chart_theme_type_id =b.chart_theme_type_id
+	    WHERE a.chart_theme_type_id = ? AND a.is_delete=0 ORDER BY a.chart_theme_id ASC `
+	err = global.DmSQL["data"].Raw(sql).Find(&list).Error
 	return
 }
 
@@ -142,10 +155,14 @@ func GetChartThemeItemList(chartThemeTypeId int) (list []*ChartThemeItem, err er
 // @return item *ChartTheme
 // @return err error
 func GetSystemChartTheme(chartThemeTypeId int) (item *ChartTheme, err error) {
-	o := orm.NewOrmUsingDB("data")
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT a.* FROM chart_theme a
+	//     WHERE a.chart_theme_type_id = ? AND a.is_system_theme=1 ORDER BY a.chart_theme_id ASC `
+	//err = o.Raw(sql, chartThemeTypeId).QueryRow(&item)
+
 	sql := `SELECT a.* FROM chart_theme a
-         WHERE a.chart_theme_type_id = ? AND a.is_system_theme=1 ORDER BY a.chart_theme_id ASC `
-	err = o.Raw(sql, chartThemeTypeId).QueryRow(&item)
+	    WHERE a.chart_theme_type_id = ? AND a.is_system_theme=1 ORDER BY a.chart_theme_id ASC `
 
+	err = global.DmSQL["data"].Raw(sql).First(&item).Error
 	return
 }

+ 30 - 12
models/data_manage/chart_theme/chart_theme_default_data.go

@@ -1,9 +1,9 @@
 package chart_theme
 
 import (
+	"eta_gn/eta_api/global"
 	"eta_gn/eta_api/models/data_manage"
 	"eta_gn/eta_api/utils"
-	"github.com/beego/beego/v2/client/orm"
 	"time"
 )
 
@@ -28,11 +28,16 @@ type ChartThemeDefaultData struct {
 // @return list []*ChartThemeDefaultData
 // @return err error
 func GetChartThemeDefaultDataList(endInfoId int) (list []*ChartThemeDefaultData, err error) {
+	//sql := `SELECT * FROM chart_theme_default_data WHERE edb_info_id=? `
+	//
+	//sql += ` ORDER BY data_time ASC `
+	//o := orm.NewOrmUsingDB("data")
+	//_, err = o.Raw(sql, endInfoId).QueryRows(&list)
+
 	sql := `SELECT * FROM chart_theme_default_data WHERE edb_info_id=? `
 
 	sql += ` ORDER BY data_time ASC `
-	o := orm.NewOrmUsingDB("data")
-	_, err = o.Raw(sql, endInfoId).QueryRows(&list)
+	err = global.DmSQL["data"].Raw(sql, endInfoId).Find(&list).Error
 	return
 }
 
@@ -44,9 +49,9 @@ func GetChartThemeDefaultDataList(endInfoId int) (list []*ChartThemeDefaultData,
 // @param cols []string
 // @return err error
 func (m *ChartThemeDefaultData) Update(cols []string) (err error) {
-	o := orm.NewOrmUsingDB("data")
-	_, err = o.Update(m, cols...)
-
+	//o := orm.NewOrmUsingDB("data")
+	//_, err = o.Update(m, cols...)
+	err = global.DmSQL["data"].Select(cols).Updates(m).Error
 	return
 }
 
@@ -58,6 +63,17 @@ func (m *ChartThemeDefaultData) Update(cols []string) (err error) {
 // @return list []*ChartThemeDefaultDataItem
 // @return err error
 func GetChartThemeDefaultDataItemList(endInfoId int, startDate string) (list []*data_manage.EdbDataList, err error) {
+	//sql := `SELECT edb_data_id,edb_info_id,data_time,value,data_timestamp FROM chart_theme_default_data WHERE edb_info_id=? `
+	//var pars []interface{}
+	//if startDate != "" {
+	//	sql += ` AND data_time>=? `
+	//	pars = append(pars, startDate)
+	//}
+	//
+	//sql += ` ORDER BY data_time ASC `
+	//o := orm.NewOrmUsingDB("data")
+	//_, err = o.Raw(sql, endInfoId, pars).QueryRows(&list)
+
 	sql := `SELECT edb_data_id,edb_info_id,data_time,value,data_timestamp FROM chart_theme_default_data WHERE edb_info_id=? `
 	var pars []interface{}
 	if startDate != "" {
@@ -66,8 +82,8 @@ func GetChartThemeDefaultDataItemList(endInfoId int, startDate string) (list []*
 	}
 
 	sql += ` ORDER BY data_time ASC `
-	o := orm.NewOrmUsingDB("data")
-	_, err = o.Raw(sql, endInfoId, pars).QueryRows(&list)
+
+	err = global.DmSQL["data"].Raw(sql, endInfoId, pars).Find(&list).Error
 	return
 }
 
@@ -83,10 +99,12 @@ func GetChartEdbMappingListByEdbInfoId(edbInfoIdList []int) (list []*data_manage
 	if num <= 0 {
 		return
 	}
-	o := orm.NewOrmUsingDB("data")
-	sql := ` SELECT * FROM chart_theme_default_edb_info WHERE edb_info_id IN(` + utils.GetOrmInReplace(num) + `)
-              `
-	_, err = o.Raw(sql, edbInfoIdList).QueryRows(&list)
+	//o := orm.NewOrmUsingDB("data")
+	//sql := ` SELECT * FROM chart_theme_default_edb_info WHERE edb_info_id IN(` + utils.GetOrmInReplace(num) + `)
+	//          `
+	//_, err = o.Raw(sql, edbInfoIdList).QueryRows(&list)
 
+	sql := ` SELECT * FROM chart_theme_default_edb_info WHERE edb_info_id IN(` + utils.GetOrmInReplace(num) + `) `
+	err = global.DmSQL["data"].Raw(sql, edbInfoIdList).Find(&list).Error
 	return
 }

+ 34 - 19
models/data_manage/chart_theme/chart_theme_type.go

@@ -1,7 +1,7 @@
 package chart_theme
 
 import (
-	"github.com/beego/beego/v2/client/orm"
+	"eta_gn/eta_api/global"
 	"time"
 )
 
@@ -36,8 +36,10 @@ type ChartThemeTypeList struct {
 // @param cols []string
 // @return err error
 func (m *ChartThemeType) Update(cols []string) (err error) {
-	o := orm.NewOrmUsingDB("data")
-	_, err = o.Update(m, cols...)
+	//o := orm.NewOrmUsingDB("data")
+	//_, err = o.Update(m, cols...)
+
+	err = global.DmSQL["data"].Select(cols).Updates(m).Error
 	return
 }
 
@@ -48,12 +50,16 @@ func (m *ChartThemeType) Update(cols []string) (err error) {
 // @return list []*ChartThemeType
 // @return err error
 func GetAllChartThemeTypeList() (list []*ChartThemeTypeList, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT c.chart_type_id AS chart_type, c.chart_type_name,c.chart_type_name_en, parent_id, t.chart_theme_type_id,t.chart_source,t.default_chart_theme_id FROM chart_type c 
-left JOIN chart_theme_type t on c.chart_type_id=t.chart_type
-ORDER BY c.sort ASC`
-	_, err = o.Raw(sql).QueryRows(&list)
+	//	o := orm.NewOrmUsingDB("data")
+	//	sql := `SELECT c.chart_type_id AS chart_type, c.chart_type_name,c.chart_type_name_en, parent_id, t.chart_theme_type_id,t.chart_source,t.default_chart_theme_id FROM chart_type c
+	//left JOIN chart_theme_type t on c.chart_type_id=t.chart_type
+	//ORDER BY c.sort ASC`
+	//	_, err = o.Raw(sql).QueryRows(&list)
 
+	sql := `SELECT c.chart_type_id AS chart_type, c.chart_type_name,c.chart_type_name_en, parent_id, t.chart_theme_type_id,t.chart_source,t.default_chart_theme_id FROM chart_type c 
+	left JOIN chart_theme_type t on c.chart_type_id=t.chart_type
+	ORDER BY c.sort ASC`
+	err = global.DmSQL["data"].Raw(sql).Find(&list).Error
 	return
 }
 
@@ -65,10 +71,12 @@ ORDER BY c.sort ASC`
 // @return list []*ChartThemeType
 // @return err error
 func GetChartThemeTypeListBySource(source int) (list []*ChartThemeType, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT * FROM chart_theme_type WHERE chart_source = ?  ORDER BY chart_theme_type_id ASC `
-	_, err = o.Raw(sql, source).QueryRows(&list)
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT * FROM chart_theme_type WHERE chart_source = ?  ORDER BY chart_theme_type_id ASC `
+	//_, err = o.Raw(sql, source).QueryRows(&list)
 
+	sql := `SELECT * FROM chart_theme_type WHERE chart_source = ?  ORDER BY chart_theme_type_id ASC `
+	err = global.DmSQL["data"].Raw(sql, source).Find(&list).Error
 	return
 }
 
@@ -80,10 +88,13 @@ func GetChartThemeTypeListBySource(source int) (list []*ChartThemeType, err erro
 // @return item *ChartThemeType
 // @return err error
 func GetChartThemeTypeById(chartThemeTypeId int) (item *ChartThemeType, err error) {
-	o := orm.NewOrmUsingDB("data")
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT * FROM chart_theme_type where chart_theme_type_id = ? `
+	//err = o.Raw(sql, chartThemeTypeId).QueryRow(&item)
+
 	sql := `SELECT * FROM chart_theme_type where chart_theme_type_id = ? `
-	err = o.Raw(sql, chartThemeTypeId).QueryRow(&item)
 
+	err = global.DmSQL["data"].Raw(sql, chartThemeTypeId).First(&item).Error
 	return
 }
 
@@ -95,10 +106,12 @@ func GetChartThemeTypeById(chartThemeTypeId int) (item *ChartThemeType, err erro
 // @return item *ChartThemeType
 // @return err error
 func GetChartThemeTypeByChartTypeAndSource(chartType, source int) (item *ChartThemeType, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT * FROM chart_theme_type where chart_type = ? AND chart_source = ? `
-	err = o.Raw(sql, chartType, source).QueryRow(&item)
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT * FROM chart_theme_type where chart_type = ? AND chart_source = ? `
+	//err = o.Raw(sql, chartType, source).QueryRow(&item)
 
+	sql := `SELECT * FROM chart_theme_type where chart_type = ? AND chart_source = ? `
+	err = global.DmSQL["data"].Raw(sql, chartType, source).First(&item).Error
 	return
 }
 
@@ -110,9 +123,11 @@ func GetChartThemeTypeByChartTypeAndSource(chartType, source int) (item *ChartTh
 // @return item *ChartThemeType
 // @return err error
 func GetChartThemeTypeByChartType(chartType int) (item *ChartThemeType, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT * FROM chart_theme_type where chart_type = ?`
-	err = o.Raw(sql, chartType).QueryRow(&item)
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT * FROM chart_theme_type where chart_type = ?`
+	//err = o.Raw(sql, chartType).QueryRow(&item)
 
+	sql := `SELECT * FROM chart_theme_type where chart_type = ?`
+	err = global.DmSQL["data"].Raw(sql, chartType).First(&item).Error
 	return
 }

+ 174 - 65
models/data_manage/cross_variety/chart_info_cross_variety.go

@@ -1,11 +1,11 @@
 package cross_variety
 
 import (
+	"eta_gn/eta_api/global"
 	"eta_gn/eta_api/models/data_manage"
 	"eta_gn/eta_api/models/data_manage/cross_variety/request"
 	"eta_gn/eta_api/utils"
 	"fmt"
-	"github.com/beego/beego/v2/client/orm"
 	"strings"
 	"time"
 )
@@ -31,12 +31,16 @@ type ChartInfoCrossVariety struct {
 // @return total int64
 // @return err error
 func GetCountChartByTagId(tagId int) (total int64, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT count(1) total FROM chart_info AS a JOIN
-    chart_info_cross_variety AS b on a.chart_info_id = b.chart_info_id 
-    WHERE b.chart_x_tag_id = ? or b.chart_y_tag_id=?`
-	err = o.Raw(sql, tagId, tagId).QueryRow(&total)
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT count(1) total FROM chart_info AS a JOIN
+	//chart_info_cross_variety AS b on a.chart_info_id = b.chart_info_id
+	//WHERE b.chart_x_tag_id = ? or b.chart_y_tag_id=?`
+	//err = o.Raw(sql, tagId, tagId).QueryRow(&total)
 
+	sql := `SELECT count(1) total FROM chart_info AS a JOIN
+	chart_info_cross_variety AS b on a.chart_info_id = b.chart_info_id
+	WHERE b.chart_x_tag_id = ? or b.chart_y_tag_id=?`
+	err = global.DmSQL["data"].Raw(sql, tagId, tagId).Scan(&total).Error
 	return
 }
 
@@ -48,11 +52,16 @@ func GetCountChartByTagId(tagId int) (total int64, err error) {
 // @return items []*ChartInfoCrossVariety
 // @return err error
 func GeChartInfoCrossVarietyListByTagId(tagId int) (items []*ChartInfoCrossVariety, err error) {
-	o := orm.NewOrmUsingDB("data")
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT b.* FROM chart_info AS a JOIN
+	//chart_info_cross_variety AS b on a.chart_info_id = b.chart_info_id
+	//WHERE b.chart_x_tag_id = ? or b.chart_y_tag_id=?`
+	//_, err = o.Raw(sql, tagId, tagId).QueryRows(&items)
+
 	sql := `SELECT b.* FROM chart_info AS a JOIN
-    chart_info_cross_variety AS b on a.chart_info_id = b.chart_info_id 
-    WHERE b.chart_x_tag_id = ? or b.chart_y_tag_id=?`
-	_, err = o.Raw(sql, tagId, tagId).QueryRows(&items)
+	chart_info_cross_variety AS b on a.chart_info_id = b.chart_info_id 
+	WHERE b.chart_x_tag_id = ? or b.chart_y_tag_id=?`
+	err = global.DmSQL["data"].Raw(sql, tagId, tagId).Find(&items).Error
 
 	return
 }
@@ -65,26 +74,36 @@ func GeChartInfoCrossVarietyListByTagId(tagId int) (items []*ChartInfoCrossVarie
 // @return item *ChartInfoCrossVariety
 // @return err error
 func GetChartInfoCrossVarietyByChartInfoId(id int) (item *ChartInfoCrossVariety, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT * FROM chart_info_cross_variety WHERE chart_info_id = ?`
-	err = o.Raw(sql, id).QueryRow(&item)
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT * FROM chart_info_cross_variety WHERE chart_info_id = ?`
+	//err = o.Raw(sql, id).QueryRow(&item)
 
+	sql := `SELECT * FROM chart_info_cross_variety WHERE chart_info_id = ?`
+	err = global.DmSQL["data"].Raw(sql, id).First(&item).Error
 	return
 }
 
 func GetChartInfoCrossVarietyByXEdbInfoId(edbInfoId int) (items []*ChartInfoCrossVariety, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT a.* FROM chart_info_cross_variety a 
-         join chart_tag_variety b on a.chart_x_tag_id=b.chart_tag_id WHERE b.edb_info_id = ? `
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&items)
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT a.* FROM chart_info_cross_variety a
+	//     join chart_tag_variety b on a.chart_x_tag_id=b.chart_tag_id WHERE b.edb_info_id = ? `
+	//_, err = o.Raw(sql, edbInfoId).QueryRows(&items)
+
+	sql := `SELECT a.* FROM chart_info_cross_variety a
+	    join chart_tag_variety b on a.chart_x_tag_id=b.chart_tag_id WHERE b.edb_info_id = ? `
+	err = global.DmSQL["data"].Raw(sql, edbInfoId).Find(&items).Error
 	return
 }
 
 func GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId int) (items []*ChartInfoCrossVariety, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT a.* FROM chart_info_cross_variety a 
-         join chart_tag_variety b on a.chart_y_tag_id=b.chart_tag_id WHERE b.edb_info_id = ? `
-	_, err = o.Raw(sql, edbInfoId).QueryRows(&items)
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT a.* FROM chart_info_cross_variety a
+	//     join chart_tag_variety b on a.chart_y_tag_id=b.chart_tag_id WHERE b.edb_info_id = ? `
+	//_, err = o.Raw(sql, edbInfoId).QueryRows(&items)
+	//return
+	sql := `SELECT a.* FROM chart_info_cross_variety a
+	    join chart_tag_variety b on a.chart_y_tag_id=b.chart_tag_id WHERE b.edb_info_id = ? `
+	err = global.DmSQL["data"].Raw(sql, edbInfoId).Find(&items).Error
 	return
 }
 
@@ -99,44 +118,52 @@ func GetChartInfoCrossVarietyByYEdbInfoId(edbInfoId int) (items []*ChartInfoCros
 // @return chartInfoId int
 // @return err error
 func CreateChart(chartInfo *data_manage.ChartInfo, classify *data_manage.ChartClassify, chartVarietyMappingList []*ChartVarietyMapping, chartInfoCrossVariety *ChartInfoCrossVariety) (chartInfoId int, err error) {
-	o := orm.NewOrmUsingDB("data")
-	tx, err := o.Begin()
-	if err != nil {
-		return
-	}
+	////o := orm.NewOrmUsingDB("data")
+	//tx, err := o.Begin()
+	//if err != nil {
+	//	return
+	//}
+	//defer func() {
+	//	if err != nil {
+	//		_ = tx.Rollback()
+	//	} else {
+	//		_ = tx.Commit()
+	//	}
+	//}()
+
+	to := global.DmSQL["data"].Begin()
 	defer func() {
 		if err != nil {
-			_ = tx.Rollback()
+			_ = to.Rollback()
 		} else {
-			_ = tx.Commit()
+			_ = to.Commit()
 		}
 	}()
 
 	// 判断是否分类已存在,不存在的话,先添加分类
 	if classify.ChartClassifyId <= 0 {
-		newId, tmpErr := tx.Insert(classify)
+		tmpErr := to.Create(classify).Error
 		if tmpErr != nil {
 			err = tmpErr
 			return
 		}
-		classify.ChartClassifyId = int(newId)
 	}
 
 	// 新增图表信息
 	chartInfo.ChartClassifyId = classify.ChartClassifyId
-	newId, err := tx.Insert(chartInfo)
+	err = to.Create(chartInfo).Error
 	if err != nil {
 		return
 	}
 	// 品种列表
-	chartInfo.ChartInfoId = int(newId)
-	chartInfoId = int(newId)
+	//chartInfo.ChartInfoId = int(newId)
+	chartInfoId = chartInfo.ChartInfoId
 
 	if len(chartVarietyMappingList) > 0 {
 		for i := range chartVarietyMappingList {
 			chartVarietyMappingList[i].ChartInfoId = chartInfoId
 		}
-		_, err = tx.InsertMulti(len(chartVarietyMappingList), chartVarietyMappingList)
+		err = to.CreateInBatches(chartVarietyMappingList, len(chartVarietyMappingList)).Error
 		if err != nil {
 			return
 		}
@@ -144,7 +171,7 @@ func CreateChart(chartInfo *data_manage.ChartInfo, classify *data_manage.ChartCl
 
 	// 图表配置
 	chartInfoCrossVariety.ChartInfoId = chartInfoId
-	if _, err = tx.Insert(chartInfoCrossVariety); err != nil {
+	if err = to.Create(chartInfoCrossVariety).Error; err != nil {
 		return
 	}
 
@@ -153,11 +180,21 @@ func CreateChart(chartInfo *data_manage.ChartInfo, classify *data_manage.ChartCl
 
 // EditChart 修改相关性图表的 图表与指标 的关系
 func EditChart(chartInfo *data_manage.ChartInfo, chartVarietyMappingList []*ChartVarietyMapping, chartInfoCrossVariety *ChartInfoCrossVariety, chartUpdateCols, chartInfoCrossVarietyUpdateCols []string) (err error) {
-	o := orm.NewOrmUsingDB("data")
-	to, err := o.Begin()
-	if err != nil {
-		return
-	}
+	//o := orm.NewOrmUsingDB("data")
+	//to, err := o.Begin()
+	//if err != nil {
+	//	return
+	//}
+	//defer func() {
+	//	if err != nil {
+	//		_ = to.Rollback()
+	//	} else {
+	//		_ = to.Commit()
+	//	}
+	//}()
+
+	to := global.DmSQL["data"].Begin()
+
 	defer func() {
 		if err != nil {
 			_ = to.Rollback()
@@ -167,7 +204,7 @@ func EditChart(chartInfo *data_manage.ChartInfo, chartVarietyMappingList []*Char
 	}()
 
 	// 更新图表信息
-	_, err = to.Update(chartInfo, chartUpdateCols...)
+	err = to.Select(chartUpdateCols).Updates(chartInfo).Error
 	if err != nil {
 		fmt.Println("UPDATE  chart_info Err:", err.Error())
 		return err
@@ -175,8 +212,9 @@ func EditChart(chartInfo *data_manage.ChartInfo, chartVarietyMappingList []*Char
 
 	// 查找现有的品种列表
 	currVarietyMappingList := make([]*ChartVarietyMapping, 0)
+	//sql := `SELECT * FROM chart_variety_mapping WHERE chart_info_id = ? `
 	sql := `SELECT * FROM chart_variety_mapping WHERE chart_info_id = ? `
-	_, err = to.Raw(sql, chartInfo.ChartInfoId).QueryRows(&currVarietyMappingList)
+	err = to.Raw(sql, chartInfo.ChartInfoId).Find(currVarietyMappingList).Error
 	if err != nil {
 		return
 	}
@@ -203,7 +241,7 @@ func EditChart(chartInfo *data_manage.ChartInfo, chartVarietyMappingList []*Char
 
 	// 添加品种
 	if len(addVarietyMappingList) > 0 {
-		_, err = to.InsertMulti(len(addVarietyMappingList), addVarietyMappingList)
+		err = to.CreateInBatches(addVarietyMappingList, len(addVarietyMappingList)).Error
 		if err != nil {
 			return
 		}
@@ -216,16 +254,18 @@ func EditChart(chartInfo *data_manage.ChartInfo, chartVarietyMappingList []*Char
 			idStrList = append(idStrList, fmt.Sprint(id))
 		}
 		removeIdStr := strings.Join(idStrList, `,`)
+		//sql = fmt.Sprintf(` DELETE FROM chart_variety_mapping WHERE id in (%s) `, removeIdStr)
 		sql = fmt.Sprintf(` DELETE FROM chart_variety_mapping WHERE id in (%s) `, removeIdStr)
-		_, err = to.Raw(sql).Exec()
+		err = to.Exec(sql).Error
 		if err != nil {
 			return
 		}
 	}
 
 	// 跨品种分析图表配置
-	_, err = to.Update(chartInfoCrossVariety, chartInfoCrossVarietyUpdateCols...)
+	//_, err = to.Update(chartInfoCrossVariety, chartInfoCrossVarietyUpdateCols...)
 
+	err = to.Select(chartInfoCrossVarietyUpdateCols).Updates(chartInfoCrossVariety).Error
 	return
 }
 
@@ -237,11 +277,21 @@ func EditChart(chartInfo *data_manage.ChartInfo, chartVarietyMappingList []*Char
 // @param req request.EditChartEnInfoReq
 // @return err error
 func EditChartEn(chartInfo *data_manage.ChartInfo, req request.EditChartEnInfoReq) (err error) {
-	o := orm.NewOrmUsingDB("data")
-	to, err := o.Begin()
-	if err != nil {
-		return
-	}
+	//o := orm.NewOrmUsingDB("data")
+	//to, err := o.Begin()
+	//if err != nil {
+	//	return
+	//}
+	//defer func() {
+	//	if err != nil {
+	//		_ = to.Rollback()
+	//	} else {
+	//		_ = to.Commit()
+	//	}
+	//}()
+
+	to := global.DmSQL["data"].Begin()
+
 	defer func() {
 		if err != nil {
 			_ = to.Rollback()
@@ -253,16 +303,22 @@ func EditChartEn(chartInfo *data_manage.ChartInfo, req request.EditChartEnInfoRe
 	// 更新图表信息
 	chartInfo.ChartNameEn = req.ChartNameEn
 	chartInfo.ModifyTime = time.Now().Local()
-	_, err = to.Update(chartInfo, "ChartNameEn", "ModifyTime")
-	if err != nil {
-		fmt.Println("UPDATE  chart_info Err:", err.Error())
-		return err
-	}
+	//_, err = to.Update(chartInfo, "ChartNameEn", "ModifyTime")
+	//if err != nil {
+	//	fmt.Println("UPDATE  chart_info Err:", err.Error())
+	//	return err
+	//}
+
+	err = to.Select("ChartNameEn", "ModifyTime").Updates(chartInfo).Error
 
 	// 更新标签英文名
 	for _, v := range req.TagList {
+		//sql := `UPDATE chart_tag SET chart_tag_name_en = ?,modify_time= NOW() WHERE chart_tag_id = ? `
+		//_, err = o.Raw(sql, v.TagNameEn, v.ChartTagId).Exec()
+
 		sql := `UPDATE chart_tag SET chart_tag_name_en = ?,modify_time= NOW() WHERE chart_tag_id = ? `
-		_, err = o.Raw(sql, v.TagNameEn, v.ChartTagId).Exec()
+
+		err = to.Exec(sql, v.TagNameEn, v.ChartTagId).Error
 		if err != nil {
 			return
 		}
@@ -270,8 +326,14 @@ func EditChartEn(chartInfo *data_manage.ChartInfo, req request.EditChartEnInfoRe
 
 	// 更新品种英文名
 	for _, v := range req.VarietyList {
+		//sql := `UPDATE chart_variety SET chart_variety_name_en = ?,modify_time= NOW() WHERE chart_variety_id = ? `
+		//_, err = o.Raw(sql, v.VarietyNameEn, v.ChartVarietyId).Exec()
+		//if err != nil {
+		//	return
+		//}
+
 		sql := `UPDATE chart_variety SET chart_variety_name_en = ?,modify_time= NOW() WHERE chart_variety_id = ? `
-		_, err = o.Raw(sql, v.VarietyNameEn, v.ChartVarietyId).Exec()
+		err = to.Exec(sql, v.VarietyNameEn, v.ChartVarietyId).Error
 		if err != nil {
 			return
 		}
@@ -289,11 +351,21 @@ func EditChartEn(chartInfo *data_manage.ChartInfo, req request.EditChartEnInfoRe
 // @param lang string
 // @return err error
 func EditChartBase(chartInfo *data_manage.ChartInfo, req request.EditChartBaseInfoReq, lang string) (err error) {
-	o := orm.NewOrmUsingDB("data")
-	to, err := o.Begin()
-	if err != nil {
-		return
-	}
+	//o := orm.NewOrmUsingDB("data")
+	//to, err := o.Begin()
+	//if err != nil {
+	//	return
+	//}
+	//defer func() {
+	//	if err != nil {
+	//		_ = to.Rollback()
+	//	} else {
+	//		_ = to.Commit()
+	//	}
+	//}()
+
+	to := global.DmSQL["data"].Begin()
+
 	defer func() {
 		if err != nil {
 			_ = to.Rollback()
@@ -310,7 +382,13 @@ func EditChartBase(chartInfo *data_manage.ChartInfo, req request.EditChartBaseIn
 		chartInfo.ChartName = req.ChartName
 	}
 	chartInfo.ModifyTime = time.Now().Local()
-	_, err = to.Update(chartInfo, "ChartName", "ChartNameEn", "ModifyTime")
+	//_, err = to.Update(chartInfo, "ChartName", "ChartNameEn", "ModifyTime")
+	//if err != nil {
+	//	fmt.Println("UPDATE  chart_info Err:", err.Error())
+	//	return err
+	//}
+
+	err = to.Select("ChartName", "ChartNameEn", "ModifyTime").Updates(chartInfo).Error
 	if err != nil {
 		fmt.Println("UPDATE  chart_info Err:", err.Error())
 		return err
@@ -318,6 +396,20 @@ func EditChartBase(chartInfo *data_manage.ChartInfo, req request.EditChartBaseIn
 
 	// 更新标签名
 	for _, v := range req.TagList {
+		//var sql string
+		//switch lang {
+		//case utils.EnLangVersion:
+		//	sql = `UPDATE chart_tag SET chart_tag_name_en = ?,modify_time= NOW() WHERE chart_tag_id = ? `
+		//default:
+		//	sql = `UPDATE chart_tag SET chart_tag_name = ?,modify_time= NOW() WHERE chart_tag_id = ? `
+		//}
+		//if sql != `` {
+		//	_, err = o.Raw(sql, v.TagName, v.ChartTagId).Exec()
+		//	if err != nil {
+		//		return
+		//	}
+		//}
+
 		var sql string
 		switch lang {
 		case utils.EnLangVersion:
@@ -326,7 +418,12 @@ func EditChartBase(chartInfo *data_manage.ChartInfo, req request.EditChartBaseIn
 			sql = `UPDATE chart_tag SET chart_tag_name = ?,modify_time= NOW() WHERE chart_tag_id = ? `
 		}
 		if sql != `` {
-			_, err = o.Raw(sql, v.TagName, v.ChartTagId).Exec()
+			//_, err = o.Raw(sql, v.TagName, v.ChartTagId).Exec()
+			//if err != nil {
+			//	return
+			//}
+
+			err = to.Exec(sql, v.TagName, v.ChartTagId).Error
 			if err != nil {
 				return
 			}
@@ -335,6 +432,18 @@ func EditChartBase(chartInfo *data_manage.ChartInfo, req request.EditChartBaseIn
 
 	// 更新品种名
 	for _, v := range req.VarietyList {
+		//var sql string
+		//switch lang {
+		//case utils.EnLangVersion:
+		//	sql = `UPDATE chart_variety SET chart_variety_name_en = ?,modify_time= NOW() WHERE chart_variety_id = ? `
+		//default:
+		//	sql = `UPDATE chart_variety SET chart_variety_name = ?,modify_time= NOW() WHERE chart_variety_id = ? `
+		//}
+		//_, err = o.Raw(sql, v.VarietyName, v.ChartVarietyId).Exec()
+		//if err != nil {
+		//	return
+		//}
+
 		var sql string
 		switch lang {
 		case utils.EnLangVersion:
@@ -342,7 +451,7 @@ func EditChartBase(chartInfo *data_manage.ChartInfo, req request.EditChartBaseIn
 		default:
 			sql = `UPDATE chart_variety SET chart_variety_name = ?,modify_time= NOW() WHERE chart_variety_id = ? `
 		}
-		_, err = o.Raw(sql, v.VarietyName, v.ChartVarietyId).Exec()
+		err = to.Exec(sql, v.VarietyName, v.ChartVarietyId).Error
 		if err != nil {
 			return
 		}

+ 41 - 29
models/data_manage/cross_variety/chart_tag.go

@@ -1,8 +1,8 @@
 package cross_variety
 
 import (
+	"eta_gn/eta_api/global"
 	"eta_gn/eta_api/utils"
-	"github.com/beego/beego/v2/client/orm"
 	"time"
 )
 
@@ -26,10 +26,12 @@ type ChartTag struct {
 // @return item *ChartTag
 // @return err error
 func GetTagById(id int) (item *ChartTag, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT * FROM chart_tag WHERE chart_tag_id = ?`
-	err = o.Raw(sql, id).QueryRow(&item)
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT * FROM chart_tag WHERE chart_tag_id = ?`
+	//err = o.Raw(sql, id).QueryRow(&item)
 
+	sql := `SELECT * FROM chart_tag WHERE chart_tag_id = ?`
+	err = global.DmSQL["data"].Raw(sql, id).First(&item).Error
 	return
 }
 
@@ -41,10 +43,12 @@ func GetTagById(id int) (item *ChartTag, err error) {
 // @return item *ChartTag
 // @return err error
 func GetTagByName(name string) (item *ChartTag, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT * FROM chart_tag WHERE chart_tag_name = ?`
-	err = o.Raw(sql, name).QueryRow(&item)
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT * FROM chart_tag WHERE chart_tag_name = ?`
+	//err = o.Raw(sql, name).QueryRow(&item)
 
+	sql := `SELECT * FROM chart_tag WHERE chart_tag_name = ?`
+	err = global.DmSQL["data"].Raw(sql, name).First(&item).Error
 	return
 }
 
@@ -55,14 +59,14 @@ func GetTagByName(name string) (item *ChartTag, err error) {
 // @param item *ChartTag
 // @return err error
 func AddTag(item *ChartTag) (err error) {
-	o := orm.NewOrmUsingDB("data")
-	lastId, err := o.Insert(item)
-	if err != nil {
-		return
-	}
-
-	item.ChartTagId = int(lastId)
-
+	//o := orm.NewOrmUsingDB("data")
+	//lastId, err := o.Insert(item)
+	//if err != nil {
+	//	return
+	//}
+	//
+	//item.ChartTagId = int(lastId)
+	err = global.DmSQL["data"].Create(item).Error
 	return
 }
 
@@ -73,10 +77,12 @@ func AddTag(item *ChartTag) (err error) {
 // @return items []*ChartTag
 // @return err error
 func GetTagList() (items []*ChartTag, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT * FROM chart_tag WHERE 1 = 1 `
-	_, err = o.Raw(sql).QueryRows(&items)
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT * FROM chart_tag WHERE 1 = 1 `
+	//_, err = o.Raw(sql).QueryRows(&items)
 
+	sql := `SELECT * FROM chart_tag WHERE 1 = 1 `
+	err = global.DmSQL["data"].Raw(sql).Find(&items).Error
 	return
 }
 
@@ -88,16 +94,18 @@ func GetTagList() (items []*ChartTag, err error) {
 // @param updateColList []string
 // @return err error
 func (item *ChartTag) Update(updateColList []string) (err error) {
-	to := orm.NewOrmUsingDB("data")
-	_, err = to.Update(item, updateColList...)
-
+	//to := orm.NewOrmUsingDB("data")
+	//_, err = to.Update(item, updateColList...)
+	err = global.DmSQL["data"].Select(updateColList).Updates(item).Error
 	return
 }
 
 // Delete 删除
 func (item *ChartTag) Delete() (err error) {
-	o := orm.NewOrmUsingDB("data")
-	_, err = o.Delete(item)
+	//o := orm.NewOrmUsingDB("data")
+	//_, err = o.Delete(item)
+
+	err = global.DmSQL["data"].Exec("DELETE FROM chart_tag WHERE chart_tag_id = ?", item.ChartTagId).Error
 	return
 }
 
@@ -113,10 +121,12 @@ func GetTagListByIdList(idList []int) (items []*ChartTag, err error) {
 	if num <= 0 {
 		return
 	}
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT * FROM chart_tag WHERE 1 = 1 AND chart_tag_id in (` + utils.GetOrmInReplace(num) + `)`
-	_, err = o.Raw(sql, idList).QueryRows(&items)
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT * FROM chart_tag WHERE 1 = 1 AND chart_tag_id in (` + utils.GetOrmInReplace(num) + `)`
+	//_, err = o.Raw(sql, idList).QueryRows(&items)
 
+	sql := `SELECT * FROM chart_tag WHERE 1 = 1 AND chart_tag_id in (` + utils.GetOrmInReplace(num) + `)`
+	err = global.DmSQL["data"].Raw(sql, idList).Find(&items).Error
 	return
 }
 
@@ -140,9 +150,11 @@ type ChartTagItem struct {
 // @return items []*ChartTag
 // @return err error
 func GetTagItemList() (items []*ChartTagItem, err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `SELECT * FROM chart_tag WHERE 1 = 1 `
-	_, err = o.Raw(sql).QueryRows(&items)
+	//o := orm.NewOrmUsingDB("data")
+	//sql := `SELECT * FROM chart_tag WHERE 1 = 1 `
+	//_, err = o.Raw(sql).QueryRows(&items)
 
+	sql := `SELECT * FROM chart_tag WHERE 1 = 1 `
+	err = global.DmSQL["data"].Raw(sql).Find(&items).Error
 	return
 }