浏览代码

修改数据库兼容

kobe6258 1 月之前
父节点
当前提交
2720acf96c

+ 5 - 3
models/business_conf.go

@@ -1,7 +1,8 @@
 package models
 
 import (
-	"github.com/beego/beego/v2/client/orm"
+	"eta/eta_report/global"
+	"eta/eta_report/utils"
 	"html"
 	"time"
 )
@@ -40,9 +41,10 @@ func GetBusinessConf() (list map[string]string, err error) {
 	list = make(map[string]string)
 
 	var items []*BusinessConf
-	o := orm.NewOrmUsingDB("eta")
+	//o := orm.NewOrmUsingDB("eta")
 	sql := `SELECT * FROM business_conf`
-	_, err = o.Raw(sql).QueryRows(&items)
+	//_, err = o.Raw(sql).QueryRows(&items)
+	err = global.DbMap[utils.DbNameMaster].Raw(sql).Find(&items).Error
 	if err != nil {
 		return
 	}

+ 25 - 18
models/english_company.go

@@ -1,13 +1,14 @@
 package models
 
 import (
-	"github.com/beego/beego/v2/client/orm"
+	"eta/eta_report/global"
 	"time"
 )
 
 // EnglishCompany 英文客户
 type EnglishCompany struct {
-	CompanyId   int       `orm:"column(company_id);pk" description:"英文客户ID"`
+	//CompanyId   int       `orm:"column(company_id);pk" description:"英文客户ID"`
+	CompanyId   int       `gorm:"column:company_id;primaryKey" description:"英文客户ID"`
 	CompanyName string    `description:"客户名称"`
 	CountryCode string    `description:"国家Code"`
 	Country     string    `description:"国家"`
@@ -24,12 +25,13 @@ func (item *EnglishCompany) TableName() string {
 }
 
 func (item *EnglishCompany) Create() (err error) {
-	o := orm.NewOrm()
-	id, err := o.Insert(item)
-	if err != nil {
-		return
-	}
-	item.CompanyId = int(id)
+	//o := orm.NewOrm()
+	//id, err := o.Insert(item)
+	//if err != nil {
+	//	return
+	//}
+	//item.CompanyId = int(id)
+	err = global.DEFAULT_DB.Create(&item).Error
 	return
 }
 
@@ -43,39 +45,44 @@ type EnglishCompanySaveReq struct {
 }
 
 func (item *EnglishCompany) Update(cols []string) (err error) {
-	o := orm.NewOrm()
-	_, err = o.Update(item, cols...)
+	//o := orm.NewOrm()
+	//_, err = o.Update(item, cols...)
+	err = global.DEFAULT_DB.Model(&item).Select(cols).Updates(&item).Error
 	return
 }
 
 // GetEnglishCompanyById 主键获取客户
 func GetEnglishCompanyById(id int) (item *EnglishCompany, err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `SELECT * FROM english_company WHERE is_deleted = 0 AND company_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
 }
 
 // GetEnglishCompanyByName 名称获取客户
 func GetEnglishCompanyByName(companyName string) (item *EnglishCompany, err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `SELECT * FROM english_company WHERE is_deleted = 0 AND company_name = ? LIMIT 1`
-	err = o.Raw(sql, companyName).QueryRow(&item)
+	//err = o.Raw(sql, companyName).QueryRow(&item)
+	err = global.DEFAULT_DB.Raw(sql, companyName).First(&item).Error
 	return
 }
 
 // UpdateEnglishCompanyViewTotal 更新英文客户阅读量
 func UpdateEnglishCompanyViewTotal(companyId int) (err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `UPDATE english_company SET view_total = view_total+1 WHERE company_id = ? `
-	_, err = o.Raw(sql, companyId).Exec()
+	//_, err = o.Raw(sql, companyId).Exec()
+	err = global.DEFAULT_DB.Exec(sql, companyId).Error
 	return
 }
 
 // UpdateTrialEnglishCompanyViewTotal 更新英文客户阅读量-ETA试用平台
 func UpdateTrialEnglishCompanyViewTotal(companyId int) (err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `UPDATE english_company SET view_total = view_total+1 WHERE company_id = ? `
-	_, err = o.Raw(sql, companyId).Exec()
+	//_, err = o.Raw(sql, companyId).Exec()
+	err = global.DEFAULT_DB.Exec(sql, companyId).Error
 	return
 }

+ 21 - 13
models/english_report.go

@@ -1,6 +1,8 @@
 package models
 
-import "github.com/beego/beego/v2/client/orm"
+import (
+	"eta/eta_report/global"
+)
 
 type EnglishReportDetail struct {
 	Id                 int    `orm:"column(id)" description:"报告Id"`
@@ -31,9 +33,10 @@ type EnglishReportDetail struct {
 }
 
 func GetEnglishReportByCode(reportCode string) (item *EnglishReportDetail, err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `SELECT * FROM english_report WHERE report_code=?`
-	err = o.Raw(sql, reportCode).QueryRow(&item)
+	//err = o.Raw(sql, reportCode).QueryRow(&item)
+	err = global.DEFAULT_DB.Raw(sql, reportCode).First(&item).Error
 	return
 }
 
@@ -49,36 +52,41 @@ type EnglishReportShareDetailResp struct {
 }
 
 func UpdateEnglishReportCounts(reportCode string) (err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `UPDATE english_report SET pv = pv+1 WHERE report_code = ?  `
-	_, err = o.Raw(sql, reportCode).Exec()
+	//_, err = o.Raw(sql, reportCode).Exec()
+	err = global.DEFAULT_DB.Exec(sql, reportCode).Error
 	return
 }
 
 func UpdateEnglishReportEmailCounts(reportCode string) (err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `UPDATE english_report SET pv_email = pv_email+1 WHERE report_code = ?  `
-	_, err = o.Raw(sql, reportCode).Exec()
+	//_, err = o.Raw(sql, reportCode).Exec()
+	err = global.DEFAULT_DB.Exec(sql, reportCode).Error
 	return
 }
 
 func GetTrialEnglishReportByCode(reportCode string) (item *EnglishReportDetail, err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `SELECT * FROM english_report WHERE report_code=?`
-	err = o.Raw(sql, reportCode).QueryRow(&item)
+	//err = o.Raw(sql, reportCode).QueryRow(&item)
+	err = global.DEFAULT_DB.Raw(sql, reportCode).First(&item).Error
 	return
 }
 
 func UpdateTrialEnglishReportCounts(reportCode string) (err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `UPDATE english_report SET pv = pv+1 WHERE report_code = ?  `
-	_, err = o.Raw(sql, reportCode).Exec()
+	//_, err = o.Raw(sql, reportCode).Exec()
+	err = global.DEFAULT_DB.Exec(sql, reportCode).Error
 	return
 }
 
 func UpdateTrialEnglishReportEmailCounts(reportCode string) (err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `UPDATE english_report SET pv_email = pv_email+1 WHERE report_code = ?  `
-	_, err = o.Raw(sql, reportCode).Exec()
+	//_, err = o.Raw(sql, reportCode).Exec()
+	err = global.DEFAULT_DB.Exec(sql, reportCode).Error
 	return
 }

+ 25 - 18
models/english_report_email.go

@@ -1,13 +1,14 @@
 package models
 
 import (
-	"github.com/beego/beego/v2/client/orm"
+	"eta/eta_report/global"
 	"time"
 )
 
 // EnglishReportEmail 英文研报-邮箱/客户联系人
 type EnglishReportEmail struct {
-	Id           int       `orm:"column(id);pk" description:"邮箱ID"`
+	//Id           int       `orm:"column(id);pk" description:"邮箱ID"`
+	Id           int       `gorm:"column:id;primaryKey" description:"邮箱ID"`
 	CompanyId    int       `description:"客户ID"`
 	Name         string    `description:"联系人名称"`
 	Email        string    `description:"邮箱地址"`
@@ -32,49 +33,55 @@ type EnglishReportEmailSaveReq struct {
 }
 
 func (item *EnglishReportEmail) Create() (err error) {
-	o := orm.NewOrm()
-	id, err := o.Insert(item)
-	if err != nil {
-		return
-	}
-	item.Id = int(id)
+	//o := orm.NewOrm()
+	//id, err := o.Insert(item)
+	//if err != nil {
+	//	return
+	//}
+	//item.Id = int(id)
+	err = global.DEFAULT_DB.Create(&item).Error
 	return
 }
 
 func (item *EnglishReportEmail) Update(cols []string) (err error) {
-	o := orm.NewOrm()
-	_, err = o.Update(item, cols...)
+	//o := orm.NewOrm()
+	//_, err = o.Update(item, cols...)
+	err = global.DEFAULT_DB.Model(&item).Select(cols).Updates(&item).Error
 	return
 }
 
 // GetEnglishReportEmailById 主键获取邮箱
 func GetEnglishReportEmailById(id int) (item *EnglishReportEmail, err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `SELECT * FROM english_report_email WHERE is_deleted = 0 AND 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
 }
 
 // UpdateEnglishReportEmailViewTotal 更新英文联系人阅读量
 func UpdateEnglishReportEmailViewTotal(emailId int) (err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `UPDATE english_report_email SET view_total = view_total+1, last_view_time = NOW() WHERE id = ? `
-	_, err = o.Raw(sql, emailId).Exec()
+	//_, err = o.Raw(sql, emailId).Exec()
+	err = global.DEFAULT_DB.Exec(sql, emailId).Error
 	return
 }
 
 // GetTrialEnglishReportEmailById 主键获取邮箱-ETA试用平台
 func GetTrialEnglishReportEmailById(id int) (item *EnglishReportEmail, err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `SELECT * FROM english_report_email WHERE is_deleted = 0 AND 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
 }
 
 // UpdateTrialEnglishReportEmailViewTotal 更新英文联系人阅读量-ETA试用平台
 func UpdateTrialEnglishReportEmailViewTotal(emailId int) (err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `UPDATE english_report_email SET view_total = view_total+1, last_view_time = NOW() WHERE id = ? `
-	_, err = o.Raw(sql, emailId).Exec()
+	//_, err = o.Raw(sql, emailId).Exec()
+	err = global.DEFAULT_DB.Exec(sql, emailId).Error
 	return
 }

+ 6 - 4
models/english_report_email_pv.go

@@ -1,13 +1,14 @@
 package models
 
 import (
-	"github.com/beego/beego/v2/client/orm"
+	"eta/eta_report/global"
 	"time"
 )
 
 // EnglishReportEmailPV 英文研报-邮箱pv
 type EnglishReportEmailPV struct {
-	Id         int       `orm:"column(id);pk"`
+	//Id         int       `orm:"column(id);pk"`
+	Id         int       `gorm:"column:id;primaryKey"`
 	ReportId   int       `description:"英文报告ID"`
 	EmailId    int       `description:"邮箱ID"`
 	CreateTime time.Time `description:"创建时间"`
@@ -15,8 +16,9 @@ type EnglishReportEmailPV struct {
 
 // InsertTrialEnglishReportEmailPV ETA试用平台-新增英文邮箱PV
 func InsertTrialEnglishReportEmailPV(item *EnglishReportEmailPV) (err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `INSERT INTO english_report_email_pv(report_id, email_id, create_time) VALUES(?, ?, ?)`
-	_, err = o.Raw(sql, item.ReportId, item.EmailId, item.CreateTime).Exec()
+	//_, err = o.Raw(sql, item.ReportId, item.EmailId, item.CreateTime).Exec()
+	err = global.DEFAULT_DB.Exec(sql, item.ReportId, item.EmailId, item.CreateTime).Error
 	return
 }

+ 12 - 7
models/outside_report.go

@@ -2,11 +2,13 @@
 package models
 
 import (
+	"eta/eta_report/global"
 	"github.com/beego/beego/v2/client/orm"
 )
 
 type OutsideReport struct {
-	OutsideReportId  int    `orm:"column(outside_report_id);pk" description:"外部报告ID"`
+	//OutsideReportId  int    `orm:"column(outside_report_id);pk" description:"外部报告ID"`
+	OutsideReportId  int    `gorm:"column:outside_report_id;primaryKey" description:"外部报告ID"`
 	Source           int    `orm:"column(source)" description:"来源,1:ETA系统录入;2:API接口录入;3:邮件监听录入"`
 	Title            string `orm:"column(title)" description:"报告标题"`
 	Abstract         string `orm:"column(abstract)" description:"摘要"`
@@ -23,7 +25,8 @@ type OutsideReport struct {
 }
 
 type OutsideReportBO struct {
-	OutsideReportId int    `orm:"column(outside_report_id);pk" description:"外部报告ID"`
+	//OutsideReportId int    `orm:"column(outside_report_id);pk" description:"外部报告ID"`
+	OutsideReportId int    `gorm:"column:outside_report_id;primaryKey" description:"外部报告ID"`
 	Source          int    `orm:"column(source)" description:"来源,1:ETA系统录入;2:API接口录入;3:邮件监听录入"`
 	Title           string `orm:"column(title)" description:"报告标题"`
 	Abstract        string `orm:"column(abstract)" description:"摘要"`
@@ -54,10 +57,11 @@ func init() {
 
 // GetOutsideReportListByConditionCount 根据条件查询列表条数
 func GetOutsideReportListByConditionCount(condition string, pars []interface{}) (count int, err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `select count(distinct t1.outside_report_id) from outside_report t1 left join chart_permission_search_key_word_mapping t2 on t1.classify_id = t2.classify_id  where 1 = 1 `
 	sql += condition
-	err = o.Raw(sql, pars).QueryRow(&count)
+	//err = o.Raw(sql, pars).QueryRow(&count)
+	err = global.DEFAULT_DB.Raw(sql, pars...).Scan(&count).Error
 	if err != nil {
 		return 0, err
 	}
@@ -67,9 +71,10 @@ func GetOutsideReportListByConditionCount(condition string, pars []interface{})
 
 // GetOutsideReportByReportCode 根据Code获取报告
 func GetOutsideReportByReportCode(reportCode string) (outsideReport *OutsideReport, err error) {
-	o := orm.NewOrm()
-	
+	//o := orm.NewOrm()
+
 	sql := `SELECT * FROM outside_report WHERE report_code=?`
-	err = o.Raw(sql, reportCode).QueryRow(&outsideReport)
+	//err = o.Raw(sql, reportCode).QueryRow(&outsideReport)
+	err = global.DEFAULT_DB.Raw(sql, reportCode).First(&outsideReport).Error
 	return outsideReport, err
 }

+ 9 - 4
models/outside_report_attachment.go

@@ -1,10 +1,14 @@
 // @Author gmy 2024/9/19 15:13:00
 package models
 
-import "github.com/beego/beego/v2/client/orm"
+import (
+	"eta/eta_report/global"
+	"github.com/beego/beego/v2/client/orm"
+)
 
 type OutsideReportAttachment struct {
-	OutsideReportAttachmentId int    `orm:"column(outside_report_attachment_id);pk" description:"外部报告附件ID"`
+	//OutsideReportAttachmentId int    `orm:"column(outside_report_attachment_id);pk" description:"外部报告附件ID"`
+	OutsideReportAttachmentId int    `gorm:"column:outside_report_attachment_id;primaryKey" description:"外部报告附件ID"`
 	OutsideReportId           int    `orm:"column(outside_report_id)" description:"报告id"`
 	Title                     string `orm:"column(title)" description:"附件名称"`
 	Url                       string `orm:"column(url)" description:"附件地址"`
@@ -19,11 +23,12 @@ func init() {
 
 // GetOutsideReportAttachmentListByReportId 根据报告id获取附件列表
 func GetOutsideReportAttachmentListByReportId(outsideReportId int) (attachmentList []*OutsideReportAttachment, err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	// 改写成通过ql查询
 	sql := `select * from outside_report_attachment where outside_report_id = ?`
 
-	_, err = o.Raw(sql, outsideReportId).QueryRows(&attachmentList)
+	//_, err = o.Raw(sql, outsideReportId).QueryRows(&attachmentList)
+	err = global.DEFAULT_DB.Raw(sql, outsideReportId).Find(&attachmentList).Error
 	if err != nil {
 		return nil, err
 	}

+ 7 - 5
models/report.go

@@ -1,7 +1,7 @@
 package models
 
 import (
-	"github.com/beego/beego/v2/client/orm"
+	"eta/eta_report/global"
 	"time"
 )
 
@@ -58,9 +58,10 @@ type Report struct {
 }
 
 func GetReportByCode(reportCode string) (item *Report, err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `SELECT * FROM report WHERE report_code=?`
-	err = o.Raw(sql, reportCode).QueryRow(&item)
+	//err = o.Raw(sql, reportCode).QueryRow(&item)
+	err = global.DEFAULT_DB.Raw(sql, reportCode).First(&item).Error
 	return
 }
 
@@ -87,8 +88,9 @@ type ReportItem struct {
 // @param reportId int
 // @return err error
 func UpdateReportPv(reportId int) (err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := `UPDATE report SET pv = pv + 1 WHERE id = ?`
-	_, err = o.Raw(sql, reportId).Exec()
+	//_, err = o.Raw(sql, reportId).Exec()
+	err = global.DEFAULT_DB.Exec(sql, reportId).Error
 	return
 }

+ 6 - 4
models/report_chapter.go

@@ -1,13 +1,14 @@
 package models
 
 import (
-	"github.com/beego/beego/v2/client/orm"
+	"eta/eta_report/global"
 	"time"
 )
 
 // ReportChapter 报告章节
 type ReportChapter struct {
-	ReportChapterId   int       `orm:"column(report_chapter_id);pk" description:"报告章节ID"`
+	//ReportChapterId   int       `orm:"column(report_chapter_id);pk" description:"报告章节ID"`
+	ReportChapterId   int       `gorm:"column:report_chapter_id;primaryKey" description:"报告章节ID"`
 	ReportId          int       `description:"报告ID"`
 	ReportType        string    `description:"报告类型 day-晨报 week-周报"`
 	ClassifyIdFirst   int       `description:"一级分类id"`
@@ -38,8 +39,9 @@ type ReportChapter struct {
 
 // GetPublishedChapterListByReportId 根据ReportId获取已发布章节列表
 func GetPublishedChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
-	o := orm.NewOrm()
+	//o := orm.NewOrm()
 	sql := ` SELECT * FROM report_chapter WHERE report_id = ? AND publish_state = 2 ORDER BY sort ASC`
-	_, err = o.Raw(sql, reportId).QueryRows(&list)
+	//_, err = o.Raw(sql, reportId).QueryRows(&list)
+	err = global.DEFAULT_DB.Raw(sql, reportId).Find(&list).Error
 	return
 }

+ 6 - 4
models/report_chapter_type.go

@@ -1,13 +1,14 @@
 package models
 
 import (
+	"eta/eta_report/global"
 	"eta/eta_report/utils"
-	"github.com/beego/beego/v2/client/orm"
 	"time"
 )
 
 type ReportChapterType struct {
-	ReportChapterTypeId    int       `orm:"column(report_chapter_type_id);pk" description:"报告章节类型id"`
+	//ReportChapterTypeId    int       `orm:"column(report_chapter_type_id);pk" description:"报告章节类型id"`
+	ReportChapterTypeId    int       `gorm:"column:report_chapter_type_id;primaryKey" description:"报告章节类型id"`
 	ReportChapterTypeKey   string    `description:"章节key"`
 	ReportChapterTypeThumb string    `description:"H5展示的图片"`
 	BannerUrl              string    `description:"banner显示图片"`
@@ -36,8 +37,9 @@ func GetAllReportChapterTypeListByResearchType(researchType string) (list []*Rep
 	if utils.BusinessCode != utils.BusinessCodeRelease {
 		return
 	}
-	o := orm.NewOrmUsingDB("weekly")
+	//o := orm.NewOrmUsingDB("weekly")
 	sql := ` SELECT * FROM report_chapter_type WHERE research_type = ?`
-	_, err = o.Raw(sql, researchType).QueryRows(&list)
+	//_, err = o.Raw(sql, researchType).QueryRows(&list)
+	err = global.DbMap[utils.DbNameWeekly].Raw(sql, researchType).Find(&list).Error
 	return
 }

+ 27 - 19
models/smart_report.go

@@ -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
 }