Browse Source

Merge remote-tracking branch 'origin/dm' into dm

Roc 1 month ago
parent
commit
00c5cedac6

+ 3 - 3
controllers/hisugar_data.go

@@ -693,9 +693,9 @@ func (this *TradeCommonController) HisugarExporthisugarList() {
 			return
 		}
 		if classifyIds != "" {
-			//condition += ` AND classify_id IN (` + classifyIds + `)`
-			condition += ` AND classify_id IN (?)`
-			pars = append(pars, classifyIds)
+			condition += ` AND classify_id IN (` + classifyIds + `)`
+			//condition += ` AND classify_id IN (?)`
+			//pars = append(pars, classifyIds)
 		}
 	}
 	frequencies, err := data_manage.GetHisugarFrequencyByCondition(condition, pars)

+ 4 - 2
models/data_manage/baiinfo_data.go

@@ -5,6 +5,7 @@ import (
 	"eta/eta_api/global"
 	"eta/eta_api/utils"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"github.com/shopspring/decimal"
 	"gorm.io/gorm"
 )
 
@@ -137,8 +138,8 @@ type BaiinfoIndexList struct {
 }
 
 type BaiinfoIndexData struct {
-	Value    string `orm:"column(value)" description:"日期"`
-	DataTime string `orm:"column(data_time)" description:"值"`
+	Value    decimal.Decimal `gorm:"column:value" description:"日期"`
+	DataTime string          `gorm:"column:data_time" description:"值"`
 }
 
 func (obj *BaiinfoIndexData) AfterFind(tx *gorm.DB) (err error) {
@@ -147,6 +148,7 @@ func (obj *BaiinfoIndexData) AfterFind(tx *gorm.DB) (err error) {
 			obj.DataTime = utils.GormDateStrToDateStr(obj.DataTime)
 		}
 	}
+
 	return
 }
 func GetBaiinfoIndexData(indexCode string, startSize, pageSize int) (items []*BaiinfoIndexData, err error) {

+ 4 - 3
models/data_manage/base_from_rzd_index.go

@@ -180,9 +180,10 @@ func GetRzdIndexByCodeAndClassify(indexCode string, classifyIdList []int, freque
 
 	if len(classifyIdList) > 0 {
 		sql += ` AND a.base_from_rzd_classify_id in (` + utils.GetOrmInReplace(len(classifyIdList)) + `)`
-		for _, id := range classifyIdList {
-			params = append(params, id)
-		}
+		//for _, id := range classifyIdList {
+		//	params = append(params, id)
+		//}
+		params = append(params, classifyIdList)
 	}
 
 	// 如果 indexCode 不为空,增加过滤条件

+ 30 - 4
models/data_manage/base_from_smm.go

@@ -61,15 +61,15 @@ func GetBaseFromSmmBySmmCode(smmCode string) (item *BaseFromSmm, err error) {
 }
 
 type BaseFromSmmIndex struct {
-	BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk" gorm:"primaryKey"`
+	BaseFromSmmIndexId int `gorm:"column:base_from_smm_index_id;primaryKey"`
 	ClassifyId         int
 	Interface          string
 	Name               string
 	IndexCode          string
 	IndexName          string
-	Type1              string `orm:"column(type_1)"`
-	Type2              string `orm:"column(type_2)"`
-	Type3              string `orm:"column(type_3)"`
+	Type1              string `gorm:"column:type_1"`
+	Type2              string `gorm:"column:type_2"`
+	Type3              string `gorm:"column:type_3"`
 	Frequency          string
 	Unit               string
 	ApiStartTime       string
@@ -87,6 +87,32 @@ type BaseFromSmmIndex struct {
 	TerminalCode       string `description:"终端编码"`
 }
 
+func (m *BaseFromSmmIndex) AfterFind(tx *gorm.DB) (err error) {
+	if utils.NeedDateOrTimeFormat(utils.DbDriverName) {
+		if m.ApiStartTime != "" {
+			m.ApiStartTime = utils.GormDateStrToDateTimeStr(m.ApiStartTime)
+		}
+		if m.ApiUpdateTime != "" {
+			m.ApiUpdateTime = utils.GormDateStrToDateTimeStr(m.ApiUpdateTime)
+		}
+		if m.StartTime != "" {
+			m.StartTime = utils.GormDateStrToDateTimeStr(m.StartTime)
+		}
+		if m.FinishTime != "" {
+			m.FinishTime = utils.GormDateStrToDateTimeStr(m.FinishTime)
+		}
+		if m.ReleaseTime != "" {
+			m.ReleaseTime = utils.GormDateStrToDateTimeStr(m.ReleaseTime)
+		}
+		if m.StartDate != "" {
+			m.StartDate = utils.GormDateStrToDateStr(m.StartDate)
+		}
+		if m.EndDate != "" {
+			m.EndDate = utils.GormDateStrToDateStr(m.EndDate)
+		}
+	}
+	return
+}
 func AddBaseFromSmmIndex(item *BaseFromSmmIndex) (lastId int64, err error) {
 	o := global.DbMap[utils.DbNameIndex]
 	err = o.Create(item).Error

+ 43 - 10
models/data_manage/smm_data.go

@@ -4,6 +4,7 @@ import (
 	"eta/eta_api/global"
 	"eta/eta_api/utils"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"gorm.io/gorm"
 	"time"
 )
 
@@ -32,14 +33,14 @@ func GetSmmFrequencyByClassifyId(classifyId int) (items []*GlFrequency, err erro
 }
 
 type SmmIndex struct {
-	BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk" gorm:"primaryKey"`
+	BaseFromSmmIndexId int `gorm:"column:base_from_smm_index_id;primaryKey"`
 	Interface          string
 	Name               string
 	IndexCode          string
 	IndexName          string
-	Type1              string `orm:"column(type_1)"`
-	Type2              string `orm:"column(type_2)"`
-	Type3              string `orm:"column(type_3)"`
+	Type1              string `gorm:"column:type_1"`
+	Type2              string `gorm:"column:type_2"`
+	Type3              string `gorm:"column:type_3"`
 	Frequency          string
 	Unit               string
 	ApiStartTime       string
@@ -52,6 +53,30 @@ type SmmIndex struct {
 	EndValue           float64 `description:"指标的最新值"`
 }
 
+func (obj *SmmIndex) AfterFind(tx *gorm.DB) (err error) {
+	if utils.NeedDateOrTimeFormat(utils.DbDriverName) {
+		if obj.CreateTime != "" {
+			obj.CreateTime = utils.GormDateStrToDateTimeStr(obj.CreateTime)
+		}
+		if obj.ModifyTime != "" {
+			obj.ModifyTime = utils.GormDateStrToDateTimeStr(obj.ModifyTime)
+		}
+		if obj.StartTime != "" {
+			obj.StartTime = utils.GormDateStrToDateTimeStr(obj.StartTime)
+		}
+		if obj.FinishTime != "" {
+			obj.FinishTime = utils.GormDateStrToDateTimeStr(obj.FinishTime)
+		}
+		if obj.ApiStartTime != "" {
+			obj.ApiStartTime = utils.GormDateStrToDateTimeStr(obj.ApiStartTime)
+		}
+		if obj.ApiUpdateTime != "" {
+			obj.ApiUpdateTime = utils.GormDateStrToDateTimeStr(obj.ApiUpdateTime)
+		}
+	}
+	return
+}
+
 type SmmIndexItem struct {
 	BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk" gorm:"primaryKey"`
 	ClassifyId         int
@@ -60,9 +85,9 @@ type SmmIndexItem struct {
 	Name               string
 	IndexCode          string
 	IndexName          string
-	Type1              string `orm:"column(type_1)"`
-	Type2              string `orm:"column(type_2)"`
-	Type3              string `orm:"column(type_3)"`
+	Type1              string `gorm:"column:type_1"`
+	Type2              string `gorm:"column:type_2"`
+	Type3              string `gorm:"column:type_3"`
 	Frequency          string
 	Unit               string
 	ApiStartTime       string
@@ -138,7 +163,7 @@ func GetSmmFrequencyByCode(code string) (items []*string, err error) {
 }
 
 type SmmIndexList struct {
-	BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk" gorm:"primaryKey"`
+	BaseFromSmmIndexId int `gorm:"column:base_from_smm_index_id);primaryKey"`
 	Interface          string
 	Name               string
 	IndexCode          string
@@ -158,10 +183,18 @@ type SmmIndexList struct {
 }
 
 type SmmIndexData struct {
-	Value    string `orm:"column(value)" description:"日期"`
-	DataTime string `orm:"column(data_time)" description:"值"`
+	Value    string `gorm:"column:value" description:"日期"`
+	DataTime string `gorm:"column:data_time" description:"值"`
 }
 
+func (m *SmmIndexData) AfterFind(tx *gorm.DB) (err error) {
+	if utils.NeedDateOrTimeFormat(utils.DbDriverName) {
+		if m.DataTime != "" {
+			m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
+		}
+	}
+	return
+}
 func GetSmmIndexData(indexCode string, startSize, pageSize int) (items []*SmmIndexData, err error) {
 	o := global.DbMap[utils.DbNameIndex]
 	sql := ` SELECT *  FROM base_from_smm_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `

+ 7 - 0
models/data_manage/supply_analysis/variety.go

@@ -5,6 +5,7 @@ import (
 	"eta/eta_api/global"
 	"eta/eta_api/utils"
 	"fmt"
+	"gorm.io/gorm"
 	"time"
 )
 
@@ -128,6 +129,12 @@ type VarietyItem struct {
 	Button                    VarietyButton `gorm:"-" description:"操作按钮权限"`
 }
 
+func (m *VarietyItem) AfterFind(db *gorm.DB) (err error) {
+	m.CreateTime = utils.GormDateStrToDateTimeStr(m.CreateTime)
+	m.ModifyTime = utils.GormDateStrToDateTimeStr(m.ModifyTime)
+	return
+}
+
 type VarietyButton struct {
 	Edit    bool `description:"操作权限"`
 	Delete  bool `description:"删除权限"`

+ 15 - 1
models/data_source/longzhong.go

@@ -1,9 +1,11 @@
 package data_source
 
 import (
+	sql2 "database/sql"
 	"eta/eta_api/global"
 	"eta/eta_api/models/data_manage"
 	"eta/eta_api/utils"
+	"gorm.io/gorm"
 	"time"
 )
 
@@ -69,13 +71,17 @@ func GetLongzhongSurveyDataMaxCount(classifyName string) (count int, err error)
 
 func GetLongzhongSurveyDataMaxCountByFrequency(classifyName string, frequency int) (count int, err error) {
 	o := global.DbMap[utils.DbNameManualIndex]
+	var sqlCount sql2.NullInt64
 	sql := `SELECT MAX(t.num) AS count FROM (
 				SELECT COUNT(1) AS num  FROM longzhong_survey_product AS a
 				INNER JOIN longzhong_survey_data AS b ON a.survey_product_id=b.survey_product_id
 				WHERE a.breed_name=? AND a.frequency=?
 				GROUP BY a.survey_product_id
 			)AS t `
-	err = o.Raw(sql, classifyName, frequency).Scan(&count).Error
+	err = o.Raw(sql, classifyName, frequency).Scan(&sqlCount).Error
+	if sqlCount.Valid {
+		count = int(sqlCount.Int64)
+	}
 	return
 }
 
@@ -156,6 +162,14 @@ type LongzhongSurveyData struct {
 	DataTime             string
 }
 
+func (obj *LongzhongSurveyData) AfterFind(tx *gorm.DB) (err error) {
+	if utils.NeedDateOrTimeFormat(utils.DbDriverName) {
+		if obj.DataTime != "" {
+			obj.DataTime = utils.GormDateStrToDateStr(obj.DataTime)
+		}
+	}
+	return
+}
 func GetLongzhongSurveyDataById(lzInfoId int) (items []*LongzhongSurveyData, err error) {
 	o := global.DbMap[utils.DbNameManualIndex]
 	sql := `SELECT * FROM longzhong_survey_data WHERE survey_product_id=? ORDER BY data_time DESC `

+ 11 - 0
models/target.go

@@ -1335,6 +1335,17 @@ type LongzhongSurveyProduct struct {
 	LzCode               string
 }
 
+func (obj *LongzhongSurveyProduct) AfterFind(tx *gorm.DB) (err error) {
+	if utils.NeedDateOrTimeFormat(utils.DbDriverName) {
+		if obj.StartDate != "" {
+			obj.StartDate = utils.GormDateStrToDateStr(obj.StartDate)
+		}
+		if obj.EndDate != "" {
+			obj.EndDate = utils.GormDateStrToDateStr(obj.EndDate)
+		}
+	}
+	return
+}
 func GetLongzhongSurveyProductByClassifyName(productName string) (items []*LongzhongSurveyProduct, err error) {
 	sql := `SELECT * FROM longzhong_survey_product WHERE breed_name=? ORDER BY survey_product_id ASC `
 	o := global.DbMap[utils.DbNameManualIndex]