Browse Source

fix: 智能研报继承

hsun 1 year ago
parent
commit
81f343f3a0
2 changed files with 8 additions and 4 deletions
  1. 2 2
      controllers/smart_report/smart_report.go
  2. 6 2
      models/smart_report/smart_report.go

+ 2 - 2
controllers/smart_report/smart_report.go

@@ -101,7 +101,7 @@ func (this *SmartReportController) Add() {
 		cond := ` AND classify_id_first = ? AND classify_id_second = ? AND state = 2`
 		pars := make([]interface{}, 0)
 		pars = append(pars, req.ClassifyIdFirst, req.ClassifyIdSecond)
-		lastReport, e := ob.GetItemByCondition(cond, pars)
+		lastReport, e := ob.GetItemByCondition(cond, pars, "stage DESC")
 		if e != nil && e.Error() != utils.ErrNoRow() {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取往期研报失败, Err: " + e.Error()
@@ -1065,7 +1065,7 @@ func (this *SmartReportController) LastPublishedReport() {
 	cond := ` AND classify_id_first = ? AND classify_id_second = ? AND state = 2`
 	pars := make([]interface{}, 0)
 	pars = append(pars, firstId, secondId)
-	item, e := ob.GetItemByCondition(cond, pars)
+	item, e := ob.GetItemByCondition(cond, pars, "stage DESC")
 	if e != nil && e.Error() != utils.ErrNoRow() {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取研报失败, Err: " + e.Error()

+ 6 - 2
models/smart_report/smart_report.go

@@ -112,9 +112,13 @@ func (m *SmartReport) GetItemById(id int) (item *SmartReport, err error) {
 	return
 }
 
-func (m *SmartReport) GetItemByCondition(condition string, pars []interface{}) (item *SmartReport, err error) {
+func (m *SmartReport) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SmartReport, err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
+	order := ``
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
 	err = o.Raw(sql, pars).QueryRow(&item)
 	return
 }