Explorar o código

修改数据库为达梦数据库

genlong hai 1 mes
pai
achega
55a62b053f
Modificáronse 2 ficheiros con 124 adicións e 40 borrados
  1. 98 29
      models/data_manage/gl_data.go
  2. 26 11
      models/data_manage/lz_data.go

+ 98 - 29
models/data_manage/gl_data.go

@@ -1,8 +1,8 @@
 package data_manage
 
 import (
+	"eta_gn/eta_api/global"
 	"eta_gn/eta_api/utils"
-	"github.com/beego/beego/v2/client/orm"
 	"github.com/rdlucklib/rdluck_tools/paging"
 )
 
@@ -11,9 +11,12 @@ type GlClassify struct {
 }
 
 func GetGlSurveyClassify() (items []*GlClassify, err error) {
+	//sql := ` SELECT CASE WHEN BREED_SHORT_NAME IS NULL THEN '无' ELSE BREED_SHORT_NAME END BREED_SHORT_NAME  FROM mb_index_main_info GROUP BY BREED_SHORT_NAME ORDER BY BREED_SHORT_NAME ASC `
+	//o := orm.NewOrmUsingDB("gl")
+	//o.Raw(sql).QueryRows(&items)
+
 	sql := ` SELECT CASE WHEN BREED_SHORT_NAME IS NULL THEN '无' ELSE BREED_SHORT_NAME END BREED_SHORT_NAME  FROM mb_index_main_info GROUP BY BREED_SHORT_NAME ORDER BY BREED_SHORT_NAME ASC `
-	o := orm.NewOrmUsingDB("gl")
-	o.Raw(sql).QueryRows(&items)
+	err = global.DmSQL["gl"].Raw(sql).Find(&items).Error
 	return
 }
 
@@ -22,14 +25,27 @@ type GlFrequency struct {
 }
 
 func GetGlFrequencyByClassifyId(breedShortName string) (items []*GlFrequency, err error) {
-	o := orm.NewOrmUsingDB("gl")
+	//o := orm.NewOrmUsingDB("gl")
+	//if breedShortName == "无" {
+	//	sql := ` SELECT FREQUENCY_NAME AS frequency FROM mb_index_main_info WHERE BREED_SHORT_NAME IS NULL GROUP BY FREQUENCY_CODE ORDER BY FREQUENCY_CODE ASC `
+	//	_, err = o.Raw(sql).QueryRows(&items)
+	//	return
+	//} else {
+	//	sql := ` SELECT FREQUENCY_NAME AS frequency FROM mb_index_main_info WHERE BREED_SHORT_NAME=? GROUP BY FREQUENCY_CODE ORDER BY FREQUENCY_CODE ASC `
+	//	_, err = o.Raw(sql, breedShortName).QueryRows(&items)
+	//	return
+	//}
+
 	if breedShortName == "无" {
 		sql := ` SELECT FREQUENCY_NAME AS frequency FROM mb_index_main_info WHERE BREED_SHORT_NAME IS NULL GROUP BY FREQUENCY_CODE ORDER BY FREQUENCY_CODE ASC `
-		_, err = o.Raw(sql).QueryRows(&items)
+		err = global.DmSQL["gl"].Raw(sql).Find(&items).Error
 		return
 	} else {
+		//sql := ` SELECT FREQUENCY_NAME AS frequency FROM mb_index_main_info WHERE BREED_SHORT_NAME=? GROUP BY FREQUENCY_CODE ORDER BY FREQUENCY_CODE ASC `
+		//_, err = o.Raw(sql, breedShortName).QueryRows(&items)
+
 		sql := ` SELECT FREQUENCY_NAME AS frequency FROM mb_index_main_info WHERE BREED_SHORT_NAME=? GROUP BY FREQUENCY_CODE ORDER BY FREQUENCY_CODE ASC `
-		_, err = o.Raw(sql, breedShortName).QueryRows(&items)
+		err = global.DmSQL["gl"].Raw(sql, breedShortName).Find(&items).Error
 		return
 	}
 }
@@ -44,22 +60,35 @@ type GlIndex struct {
 }
 
 func GetGlIndex(breedShortName, frequency string) (items []*GlIndex, err error) {
-	o := orm.NewOrmUsingDB("gl")
+	//o := orm.NewOrmUsingDB("gl")
+	//if breedShortName == "无" {
+	//	sql := ` SELECT * FROM mb_index_main_info WHERE BREED_SHORT_NAME IS NULL AND FREQUENCY_NAME=? ORDER BY INDEX_CODE ASC `
+	//	_, err = o.Raw(sql, frequency).QueryRows(&items)
+	//	return
+	//} else {
+	//	sql := ` SELECT * FROM mb_index_main_info WHERE BREED_SHORT_NAME=? AND FREQUENCY_NAME=? ORDER BY INDEX_CODE ASC `
+	//	_, err = o.Raw(sql, breedShortName, frequency).QueryRows(&items)
+	//	return
+	//}
+
 	if breedShortName == "无" {
 		sql := ` SELECT * FROM mb_index_main_info WHERE BREED_SHORT_NAME IS NULL AND FREQUENCY_NAME=? ORDER BY INDEX_CODE ASC `
-		_, err = o.Raw(sql, frequency).QueryRows(&items)
+		err = global.DmSQL["gl"].Raw(sql, frequency).Find(&items).Error
 		return
 	} else {
 		sql := ` SELECT * FROM mb_index_main_info WHERE BREED_SHORT_NAME=? AND FREQUENCY_NAME=? ORDER BY INDEX_CODE ASC `
-		_, err = o.Raw(sql, breedShortName, frequency).QueryRows(&items)
+		err = global.DmSQL["gl"].Raw(sql, breedShortName, frequency).Find(&items).Error
 		return
 	}
 }
 
 func GetGlFrequency(productName string) (items []*string, err error) {
+	//sql := `SELECT DISTINCT FREQUENCY_NAME FROM mb_index_main_info WHERE BREED_SHORT_NAME=? ORDER BY FIELD(FREQUENCY_NAME,'日度','周度','旬度','月度','季度','半年','年度') `
+	//o := orm.NewOrmUsingDB("gl")
+	//_, err = o.Raw(sql, productName).QueryRows(&items)
+
 	sql := `SELECT DISTINCT FREQUENCY_NAME FROM mb_index_main_info WHERE BREED_SHORT_NAME=? ORDER BY FIELD(FREQUENCY_NAME,'日度','周度','旬度','月度','季度','半年','年度') `
-	o := orm.NewOrmUsingDB("gl")
-	_, err = o.Raw(sql, productName).QueryRows(&items)
+	err = global.DmSQL["gl"].Raw(sql, productName).Find(&items).Error
 	return
 }
 
@@ -81,35 +110,56 @@ type GlIndexData struct {
 
 func GetGlIndexData(indexCode string, startSize, pageSize int) (items []*GlIndexData, err error) {
 	//sql := ` SELECT *  FROM mb_index_main_data WHERE INDEX_CODE=? ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC LIMIT ?,?`
+	//sql := ` SELECT * FROM (
+	//SELECT DISTINCT a.INDEX_CODE,a.DATA_VALUE,a.DATA_DATE FROM mb_index_main_data AS a WHERE INDEX_CODE=? AND IS_DELETE=0
+	//ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC
+	//)AS t
+	//GROUP BY t.DATA_DATE
+	//ORDER BY t.DATA_DATE DESC LIMIT ?,? `
+	//o := orm.NewOrmUsingDB("gl")
+	//_, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
+
 	sql := ` SELECT * FROM (
 	SELECT DISTINCT a.INDEX_CODE,a.DATA_VALUE,a.DATA_DATE FROM mb_index_main_data AS a WHERE INDEX_CODE=? AND IS_DELETE=0
 	ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC 
 	)AS t
 	GROUP BY t.DATA_DATE
 	ORDER BY t.DATA_DATE DESC LIMIT ?,? `
-	o := orm.NewOrmUsingDB("gl")
-	_, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
+	err = global.DmSQL["gl"].Raw(sql, indexCode, startSize, pageSize).Find(&items).Error
 	return
 }
 
 func GetGlIndexByCode(indexCode string) (items *GlIndex, err error) {
+	//sql := ` SELECT *  FROM mb_index_main_info WHERE INDEX_CODE=? `
+	//o := orm.NewOrmUsingDB("gl")
+	//err = o.Raw(sql, indexCode).QueryRow(&items)
+
 	sql := ` SELECT *  FROM mb_index_main_info WHERE INDEX_CODE=? `
-	o := orm.NewOrmUsingDB("gl")
-	err = o.Raw(sql, indexCode).QueryRow(&items)
+	err = global.DmSQL["gl"].Raw(sql, indexCode).First(&items).Error
 	return
 }
 
 func GetGlIndexDataCount(indexCode string) (count int, err error) {
-	o := orm.NewOrmUsingDB("gl")
+	//o := orm.NewOrmUsingDB("gl")
+	//sql := `SELECT COUNT(1) AS count FROM (
+	//		SELECT * FROM (
+	//			SELECT DISTINCT a.INDEX_CODE,a.DATA_VALUE,a.DATA_DATE FROM mb_index_main_data AS a WHERE INDEX_CODE=? AND IS_DELETE=0
+	//			ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC
+	//			)AS t
+	//			GROUP BY t.DATA_DATE
+	//			ORDER BY t.DATA_DATE DESC
+	//		)AS n `
+	//err = o.Raw(sql, indexCode).QueryRow(&count)
+
 	sql := `SELECT COUNT(1) AS count FROM (
 			SELECT * FROM (
 				SELECT DISTINCT a.INDEX_CODE,a.DATA_VALUE,a.DATA_DATE FROM mb_index_main_data AS a WHERE INDEX_CODE=? AND IS_DELETE=0
-				ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC 
+				ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC
 				)AS t
 				GROUP BY t.DATA_DATE
 				ORDER BY t.DATA_DATE DESC
 			)AS n `
-	err = o.Raw(sql, indexCode).QueryRow(&count)
+	err = global.DmSQL["gl"].Raw(sql, indexCode).Scan(&count).Error
 	return
 }
 
@@ -125,33 +175,52 @@ type GlSearchIndex struct {
 
 // GetGlItemList 模糊查询隆众数据库指标列表
 func GetGlItemList(keyword string) (items []*GlSearchIndex, err error) {
-	o := orm.NewOrmUsingDB("gl")
+	//o := orm.NewOrmUsingDB("gl")
+	//sql := "SELECT * FROM mb_index_main_info WHERE CONCAT(INDEX_NAME,INDEX_CODE) LIKE ? "
+	//_, err = o.Raw(sql, utils.GetLikeKeyword(keyword)).QueryRows(&items)
+
 	sql := "SELECT * FROM mb_index_main_info WHERE CONCAT(INDEX_NAME,INDEX_CODE) LIKE ? "
-	_, err = o.Raw(sql, utils.GetLikeKeyword(keyword)).QueryRows(&items)
+	err = global.DmSQL["gl"].Raw(sql, utils.GetLikeKeyword(keyword)).Find(&items).Error
 	return
 
 }
 
 func GetGlDataMaxCount(classifyName string) (count int, err error) {
-	o := orm.NewOrmUsingDB("gl")
+	//o := orm.NewOrmUsingDB("gl")
+	//sql := `SELECT MAX(t.num) AS count FROM (
+	//			SELECT COUNT(1) AS num  FROM mb_index_main_info AS a
+	//			INNER JOIN mb_index_main_data AS b ON a.INDEX_CODE=b.INDEX_CODE
+	//			WHERE a.BREED_SHORT_NAME=?
+	//			GROUP BY a.INDEX_CODE
+	//		)AS t `
+	//err = o.Raw(sql, classifyName).QueryRow(&count)
+
 	sql := `SELECT MAX(t.num) AS count FROM (
 				SELECT COUNT(1) AS num  FROM mb_index_main_info AS a
 				INNER JOIN mb_index_main_data AS b ON a.INDEX_CODE=b.INDEX_CODE
 				WHERE a.BREED_SHORT_NAME=?
 				GROUP BY a.INDEX_CODE
 			)AS t `
-	err = o.Raw(sql, classifyName).QueryRow(&count)
+	err = global.DmSQL["gl"].Raw(sql, classifyName).Scan(&count).Error
 	return
 }
 
 func GetGlDataByCode(indexCode string) (items []*GlIndexData, err error) {
-	o := orm.NewOrmUsingDB("gl")
+	//	o := orm.NewOrmUsingDB("gl")
+	//	sql := `SELECT
+	//	*
+	//FROM
+	//	( SELECT * FROM mb_index_main_data WHERE INDEX_CODE = ? GROUP BY UPDATE_TIME DESC, DATA_DATE DESC ) a
+	//GROUP BY
+	//	a.DATA_DATE DESC `
+	//	_, err = o.Raw(sql, indexCode).QueryRows(&items)
+
 	sql := `SELECT
-	* 
-FROM
-	( SELECT * FROM mb_index_main_data WHERE INDEX_CODE = ? GROUP BY UPDATE_TIME DESC, DATA_DATE DESC ) a 
-GROUP BY
-	a.DATA_DATE DESC `
-	_, err = o.Raw(sql, indexCode).QueryRows(&items)
+		* 
+	FROM
+		( SELECT * FROM mb_index_main_data WHERE INDEX_CODE = ? GROUP BY UPDATE_TIME DESC, DATA_DATE DESC ) a 
+	GROUP BY
+		a.DATA_DATE DESC `
+	err = global.DmSQL["gl"].Raw(sql, indexCode).Find(&items).Error
 	return
 }

+ 26 - 11
models/data_manage/lz_data.go

@@ -1,7 +1,7 @@
 package data_manage
 
 import (
-	"github.com/beego/beego/v2/client/orm"
+	"eta_gn/eta_api/global"
 	"time"
 )
 
@@ -11,9 +11,12 @@ type LzClassify struct {
 }
 
 func GetLzSurveyClassify() (items []*LzClassify, err error) {
+	//sql := ` SELECT breed_id,breed_name FROM longzhong_survey_product GROUP BY breed_name ORDER BY breed_name DESC `
+	//o := orm.NewOrmUsingDB("edb")
+	//o.Raw(sql).QueryRows(&items)
+
 	sql := ` SELECT breed_id,breed_name FROM longzhong_survey_product GROUP BY breed_name ORDER BY breed_name DESC `
-	o := orm.NewOrmUsingDB("edb")
-	o.Raw(sql).QueryRows(&items)
+	err = global.DmSQL["data"].Raw(sql).Find(&items).Error
 	return
 }
 
@@ -22,9 +25,12 @@ type LzFrequency struct {
 }
 
 func GetLzFrequencyByClassifyId(breedId int) (items []*LzFrequency, err error) {
+	//sql := ` SELECT frequency  FROM longzhong_survey_product WHERE breed_id=? GROUP BY frequency ORDER BY frequency ASC `
+	//o := orm.NewOrmUsingDB("edb")
+	//_, err = o.Raw(sql, breedId).QueryRows(&items)
+
 	sql := ` SELECT frequency  FROM longzhong_survey_product WHERE breed_id=? GROUP BY frequency ORDER BY frequency ASC `
-	o := orm.NewOrmUsingDB("edb")
-	_, err = o.Raw(sql, breedId).QueryRows(&items)
+	err = global.DmSQL["data"].Raw(sql, breedId).Find(&items).Error
 	return
 }
 
@@ -60,9 +66,12 @@ type LongzhongSurveyProduct struct {
 }
 
 func GetLongzhongSurveyProduct(breedId, frequency int) (items []*LongzhongSurveyProduct, err error) {
+	//sql := ` SELECT *  FROM longzhong_survey_product WHERE breed_id=? AND frequency=? ORDER BY survey_product_id ASC `
+	//o := orm.NewOrmUsingDB("edb")
+	//_, err = o.Raw(sql, breedId, frequency).QueryRows(&items)
+
 	sql := ` SELECT *  FROM longzhong_survey_product WHERE breed_id=? AND frequency=? ORDER BY survey_product_id ASC `
-	o := orm.NewOrmUsingDB("edb")
-	_, err = o.Raw(sql, breedId, frequency).QueryRows(&items)
+	err = global.DmSQL["data"].Raw(sql, breedId, frequency).Find(&items).Error
 	return
 }
 
@@ -89,15 +98,21 @@ type LzProductData struct {
 }
 
 func GetLongzhongSurveyProductData(surveyProductId int) (items []*LzProductData, err error) {
+	//sql := ` SELECT *  FROM longzhong_survey_data WHERE survey_product_id=? ORDER BY data_time DESC `
+	//o := orm.NewOrmUsingDB("edb")
+	//_, err = o.Raw(sql, surveyProductId).QueryRows(&items)
+
 	sql := ` SELECT *  FROM longzhong_survey_data WHERE survey_product_id=? ORDER BY data_time DESC `
-	o := orm.NewOrmUsingDB("edb")
-	_, err = o.Raw(sql, surveyProductId).QueryRows(&items)
+	err = global.DmSQL["data"].Raw(sql, surveyProductId).Find(&items).Error
 	return
 }
 
 func GetLongzhongSurveyProductByCode(lzCode string) (items *LongzhongSurveyProduct, err error) {
+	//sql := ` SELECT *  FROM longzhong_survey_product WHERE lz_code=? `
+	//o := orm.NewOrmUsingDB("edb")
+	//err = o.Raw(sql, lzCode).QueryRow(&items)
+
 	sql := ` SELECT *  FROM longzhong_survey_product WHERE lz_code=? `
-	o := orm.NewOrmUsingDB("edb")
-	err = o.Raw(sql, lzCode).QueryRow(&items)
+	err = global.DmSQL["data"].Raw(sql, lzCode).First(&items).Error
 	return
 }