소스 검색

change gorm

Roc 4 주 전
부모
커밋
1157f7526f

+ 2 - 4
controllers/edb_info.go

@@ -306,10 +306,8 @@ func (this *EdbInfoController) RefreshCheck() {
 
 	if req.FrequencyBatch != "" {
 		frequency := strings.Split(req.FrequencyBatch, ",")
-		condition += ` and frequency in (` + utils.GetOrmInReplace(len(frequency)) + `)`
-		for _, v := range frequency {
-			pars = append(pars, v)
-		}
+		condition += ` and frequency in (?)`
+		pars = append(pars, frequency)
 	}
 	updateCondition := condition + ` and latest_date = ?`
 	pars = append(pars, req.LatestDate)

+ 4 - 0
global/initDb.go

@@ -13,6 +13,7 @@ import (
 	"io"
 	"log"
 	"os"
+	"strings"
 	"time"
 )
 
@@ -67,6 +68,9 @@ func connectDb(dsn, aliasName string, newLogger logger.Interface, dbMap map[stri
 	var dialector gorm.Dialector
 	switch utils.DbDriverName {
 	case utils.DbDriverByMysql:
+		if !strings.Contains(dsn, `parseTime`) {
+			dsn += `&parseTime=true`
+		}
 		dialector = mysql.Open(dsn)
 	case utils.DbDriverByDm:
 		dialector = dm.Open(dsn)

+ 1 - 5
models/edb_data_residual_analysis.go

@@ -68,11 +68,7 @@ func RefreshAllCalculateResidualAnalysis(edbInfoId, source, subSource, formulaIn
 
 	//清空原有数据
 	sql := ` DELETE FROM edb_data_residual_analysis WHERE edb_info_id in (` + utils.GetOrmInReplace(len(edbInfoIdList)) + `) `
-	var params []interface{}
-	for _, i := range edbInfoIdList {
-		params = append(params, i)
-	}
-	err = to.Exec(sql, params...).Error
+	err = to.Exec(sql, edbInfoIdList).Error
 	if err != nil {
 		return
 	}

+ 1 - 1
models/edb_info.go

@@ -279,7 +279,7 @@ func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
 	}
 
 	sql := ` SELECT * FROM edb_info WHERE edb_info_id in (` + utils.GetOrmInReplace(num) + `) `
-	err = global.DEFAULT_DB.Raw(sql, edbInfoIdList).Scan(&items).Error
+	err = global.DEFAULT_DB.Raw(sql, edbInfoIdList).Find(&items).Error
 	// 日期格式转换
 	for _, v := range items {
 		v.ConvertDate()

+ 1 - 1
models/edb_info_relation.go

@@ -53,7 +53,7 @@ func GetEdbInfoRelationEdbIdsByParentRelationId(relationId, edbInfoId int) (item
 // GetEdbInfoRelationByRelationIds 查询引用的指标ID
 func GetEdbInfoRelationByRelationIds(ids []int) (items []*EdbInfoRelation, err error) {
 	msql := ` SELECT * FROM edb_info_relation WHERE edb_info_relation_id in (` + utils.GetOrmInReplace(len(ids)) + `) `
-	err = global.DEFAULT_DB.Raw(msql, ids).Scan(&items).Error
+	err = global.DEFAULT_DB.Raw(msql, ids).Find(&items).Error
 	return
 }
 

+ 1 - 2
models/edb_refresh/edb_refresh_default_config.go

@@ -3,7 +3,6 @@ package edb_refresh
 import (
 	"errors"
 	"eta/eta_index_lib/global"
-	"eta/eta_index_lib/utils"
 	"time"
 )
 
@@ -119,7 +118,7 @@ func GetDefaultRefreshEdbInfoListBySourceAndSubSource(source, subSource int, fre
 
 	sql := `SELECT a.* FROM edb_info a 
 LEFT JOIN edb_refresh_mapping b ON a.edb_info_id = b.edb_info_id
-WHERE a.source = ? AND a.sub_source = ? AND a.frequency IN (` + utils.GetOrmInReplace(num) + `)  AND b.edb_info_id is null`
+WHERE a.source = ? AND a.sub_source = ? AND a.frequency IN (?)  AND b.edb_info_id is null`
 	err = global.DEFAULT_DB.Raw(sql, source, subSource, frequencyList).Scan(&list).Error
 
 	return

+ 1 - 1
models/edb_refresh/edb_refresh_mapping.go

@@ -110,7 +110,7 @@ WHERE b.edb_refresh_config_id IN (` + utils.GetOrmInReplace(num) + `) `
 		sql += ` AND b.source not in (` + utils.GetOrmInReplace(sourceNum) + `) `
 		pars = append(pars, sourceList)
 	}
-	err = global.DEFAULT_DB.Raw(sql, pars...).Scan(&list).Error
+	err = global.DEFAULT_DB.Raw(sql, pars).Scan(&list).Error
 
 	return
 }

+ 0 - 2
models/predict_edb.go

@@ -288,7 +288,6 @@ func CalculateByRuleBy9(to *gorm.DB, rule CalculateRule) (resultDataList []*EdbI
 		}
 		//如果拼接指标变更了,那么需要删除所有的指标数据
 		sql := ` DELETE FROM predict_edb_rule_data WHERE config_id = ? and data_time in (` + utils.GetOrmInReplace(lenRemoveDateList) + `) `
-
 		err = to.Exec(sql, rule.ConfigId, removeDateList).Error
 		if err != nil {
 			err = fmt.Errorf("删除计算失败的预测规则计算指标数据失败,Err:" + err.Error())
@@ -447,7 +446,6 @@ func CalculateByRuleByRuleLineNh(to *gorm.DB, predictEdbInfo EdbInfo, predictEdb
 		if lenRemoveDateList > 0 {
 			//如果拼接指标变更了,那么需要删除所有的指标数据
 			sql := ` DELETE FROM predict_edb_rule_data WHERE config_id = ? and data_time in (` + utils.GetOrmInReplace(lenRemoveDateList) + `) `
-
 			err = to.Exec(sql, rule.ConfigId, removeDateList).Error
 			if err != nil {
 				err = fmt.Errorf("删除计算失败的预测规则计算指标数据失败,Err:" + err.Error())

+ 1 - 1
models/predict_edb_conf.go

@@ -137,7 +137,7 @@ func ModifyPredictEdbInfoMaxAndMinInfoBySourceEdbInfoId(sourceEdbInfoId int, ite
 
 		//sql := ` UPDATE edb_info SET start_date=?,min_value=?,max_value=?,is_update=2,latest_date=?,latest_value=?,modify_time=NOW() WHERE edb_info_id in (` + utils.GetOrmInReplace(int(total)) + `) `
 		//_, err = o.Raw(sql, item.MinDate, item.MinValue, item.MaxValue, item.MaxDate, item.LatestValue, idList).Exec()
-		sql := ` UPDATE edb_info SET start_date=?,is_update=2,latest_date=?,latest_value=?,end_value=?,modify_time=NOW() WHERE edb_info_id in (` + utils.GetOrmInReplace(int(total)) + `) `
+		sql := ` UPDATE edb_info SET start_date=?,is_update=2,latest_date=?,latest_value=?,end_value=?,modify_time=NOW() WHERE edb_info_id in (?) `
 		err = o.Exec(sql, item.MinDate, item.MaxDate, item.LatestValue, item.LatestValue, idList).Error
 
 	}