|
@@ -1,16 +1,17 @@
|
|
|
package models
|
|
|
|
|
|
import (
|
|
|
+ "eta/eta_report/global"
|
|
|
"eta/eta_report/utils"
|
|
|
"fmt"
|
|
|
- "github.com/beego/beego/v2/client/orm"
|
|
|
"html"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// SmartReport 智能研报
|
|
|
type SmartReport struct {
|
|
|
- SmartReportId int `orm:"column(smart_report_id);pk" description:"智能研报ID"`
|
|
|
+ //SmartReportId int `orm:"column(smart_report_id);pk" description:"智能研报ID"`
|
|
|
+ SmartReportId int `gorm:"column:smart_report_id;primaryKey" description:"智能研报ID"`
|
|
|
ReportCode string `description:"报告唯一编码"`
|
|
|
ClassifyIdFirst int `description:"一级分类ID"`
|
|
|
ClassifyNameFirst string `description:"一级分类名称"`
|
|
@@ -65,32 +66,36 @@ func (m *SmartReport) PrimaryId() string {
|
|
|
}
|
|
|
|
|
|
func (m *SmartReport) Create() (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- id, err := o.Insert(m)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- m.SmartReportId = int(id)
|
|
|
+ //o := orm.NewOrm()
|
|
|
+ //id, err := o.Insert(m)
|
|
|
+ //if err != nil {
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //m.SmartReportId = int(id)
|
|
|
+ err = global.DEFAULT_DB.Create(&m).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *SmartReport) Update(cols []string) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- _, err = o.Update(m, cols...)
|
|
|
+ //o := orm.NewOrm()
|
|
|
+ //_, err = o.Update(m, cols...)
|
|
|
+ err = global.DEFAULT_DB.Model(&m).Select(cols).Updates(&m).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *SmartReport) GetItemById(id int) (item *SmartReport, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
|
|
|
- err = o.Raw(sql, id).QueryRow(&item)
|
|
|
+ //err = o.Raw(sql, id).QueryRow(&item)
|
|
|
+ err = global.DEFAULT_DB.Where(sql, id).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (m *SmartReport) GetItemByCondition(condition string, pars []interface{}) (item *SmartReport, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
|
|
|
- err = o.Raw(sql, pars).QueryRow(&item)
|
|
|
+ //err = o.Raw(sql, pars).QueryRow(&item)
|
|
|
+ err = global.DEFAULT_DB.Where(sql, pars...).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -196,14 +201,16 @@ type SmartReportShareDetailResp struct {
|
|
|
|
|
|
// UpdateSmartReportPv 研报pv自增
|
|
|
func UpdateSmartReportPv(reportId int) (err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := `UPDATE smart_report SET pv = pv + 1 WHERE smart_report_id = ?`
|
|
|
- _, err = o.Raw(sql, reportId).Exec()
|
|
|
+ //_, err = o.Raw(sql, reportId).Exec()
|
|
|
+ err = global.DEFAULT_DB.Exec(sql, reportId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
type SmartReportResource struct {
|
|
|
- ResourceId int `orm:"column(resource_id);pk" description:"智能研报资源ID"`
|
|
|
+ //ResourceId int `orm:"column(resource_id);pk" description:"智能研报资源ID"`
|
|
|
+ ResourceId int `gorm:"column:resource_id;primaryKey" description:"智能研报资源ID"`
|
|
|
ImgUrl string // 图片链接
|
|
|
Style string // 版图样式
|
|
|
ImgName string // 图片名称
|
|
@@ -212,9 +219,10 @@ type SmartReportResource struct {
|
|
|
}
|
|
|
|
|
|
func GetResourceItemById(id int) (item *SmartReportResource, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
+ //o := orm.NewOrm()
|
|
|
sql := fmt.Sprintf(`SELECT * FROM smart_report_resource WHERE resource_id = ? LIMIT 1`)
|
|
|
- err = o.Raw(sql, id).QueryRow(&item)
|
|
|
+ //err = o.Raw(sql, id).QueryRow(&item)
|
|
|
+ err = global.DEFAULT_DB.Raw(sql, id).First(&item).Error
|
|
|
return
|
|
|
}
|
|
|
|