Pārlūkot izejas kodu

fix:版图资源库列表

zqbao 5 mēneši atpakaļ
vecāks
revīzija
5edec8b58f

+ 123 - 79
models/smart_report/smart_report.go

@@ -1,13 +1,14 @@
 package smart_report
 
 import (
+	"eta_gn/eta_api/global"
 	"eta_gn/eta_api/utils"
 	"fmt"
-	"github.com/beego/beego/v2/client/orm"
-	"github.com/rdlucklib/rdluck_tools/paging"
 	"html"
 	"strings"
 	"time"
+
+	"github.com/rdlucklib/rdluck_tools/paging"
 )
 
 const (
@@ -16,51 +17,98 @@ const (
 )
 
 // SmartReport 智能研报
+// type SmartReport struct {
+// 	SmartReportId       int       `orm:"column(smart_report_id);pk" gorm:"primaryKey"  description:"智能研报ID"`
+// 	ReportCode          string    `description:"报告唯一编码"`
+// 	ClassifyIdFirst     int       `description:"一级分类ID"`
+// 	ClassifyNameFirst   string    `description:"一级分类名称"`
+// 	ClassifyIdSecond    int       `description:"二级分类ID"`
+// 	ClassifyNameSecond  string    `description:"二级分类名称"`
+// 	AddType             int       `description:"新增方式:1-新增报告;2-继承报告"`
+// 	Title               string    `description:"标题"`
+// 	Abstract            string    `description:"摘要"`
+// 	Author              string    `description:"作者"`
+// 	Frequency           string    `description:"频度"`
+// 	Stage               int       `description:"期数"`
+// 	Content             string    `description:"内容"`
+// 	ContentSub          string    `description:"内容前两个章节"`
+// 	ContentStruct       string    `description:"内容组件"`
+// 	VideoUrl            string    `description:"音频文件URL"`
+// 	VideoName           string    `description:"音频文件名称"`
+// 	VideoPlaySeconds    float64   `description:"音频播放时长"`
+// 	VideoSize           string    `description:"音频文件大小,单位M"`
+// 	AdminId             int       `description:"创建者ID"`
+// 	AdminRealName       string    `description:"创建者姓名"`
+// 	State               int       `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
+// 	LastModifyAdminId   int       `description:"最后更新人ID"`
+// 	LastModifyAdminName string    `description:"最后更新人姓名"`
+// 	ContentModifyTime   time.Time `description:"内容更新时间"`
+// 	Pv                  int       `description:"pv"`
+// 	Uv                  int       `description:"uv"`
+// 	PublishTime         time.Time `description:"发布时间"`
+// 	PrePublishTime      time.Time `description:"预发布时间"`
+// 	PreMsgSend          int       `description:"定时发布后是否推送模版消息:0-否;1-是"`
+// 	MsgIsSend           int       `description:"消息是否已发送:0-否;1-是"`
+// 	MsgSendTime         time.Time `description:"模版消息发送时间"`
+// 	DetailImgUrl        string    `description:"报告详情长图地址"`
+// 	DetailPdfUrl        string    `description:"报告详情PDF地址"`
+// 	CreateTime          time.Time `description:"创建时间"`
+// 	ModifyTime          time.Time `description:"修改时间"`
+// 	HeadImg             string    `description:"报告头图地址"`
+// 	EndImg              string    `description:"报告尾图地址"`
+// 	CanvasColor         string    `description:"画布颜色"`
+// 	ApproveTime         time.Time `description:"审批时间"`
+// 	ApproveId           int       `description:"审批ID"`
+// 	NeedSplice          int       `description:"0-不需要 1-需要"`
+// 	HeadResourceId      int       `description:"版头资源ID"`
+// 	EndResourceId       int       `description:"版尾资源ID"`
+// }
+
 type SmartReport struct {
-	SmartReportId       int       `orm:"column(smart_report_id);pk" gorm:"primaryKey"  description:"智能研报ID"`
-	ReportCode          string    `description:"报告唯一编码"`
-	ClassifyIdFirst     int       `description:"一级分类ID"`
-	ClassifyNameFirst   string    `description:"一级分类名称"`
-	ClassifyIdSecond    int       `description:"二级分类ID"`
-	ClassifyNameSecond  string    `description:"二级分类名称"`
-	AddType             int       `description:"新增方式:1-新增报告;2-继承报告"`
-	Title               string    `description:"标题"`
-	Abstract            string    `description:"摘要"`
-	Author              string    `description:"作者"`
-	Frequency           string    `description:"频度"`
-	Stage               int       `description:"期数"`
-	Content             string    `description:"内容"`
-	ContentSub          string    `description:"内容前两个章节"`
-	ContentStruct       string    `description:"内容组件"`
-	VideoUrl            string    `description:"音频文件URL"`
-	VideoName           string    `description:"音频文件名称"`
-	VideoPlaySeconds    float64   `description:"音频播放时长"`
-	VideoSize           string    `description:"音频文件大小,单位M"`
-	AdminId             int       `description:"创建者ID"`
-	AdminRealName       string    `description:"创建者姓名"`
-	State               int       `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
-	LastModifyAdminId   int       `description:"最后更新人ID"`
-	LastModifyAdminName string    `description:"最后更新人姓名"`
-	ContentModifyTime   time.Time `description:"内容更新时间"`
-	Pv                  int       `description:"pv"`
-	Uv                  int       `description:"uv"`
-	PublishTime         time.Time `description:"发布时间"`
-	PrePublishTime      time.Time `description:"预发布时间"`
-	PreMsgSend          int       `description:"定时发布后是否推送模版消息:0-否;1-是"`
-	MsgIsSend           int       `description:"消息是否已发送:0-否;1-是"`
-	MsgSendTime         time.Time `description:"模版消息发送时间"`
-	DetailImgUrl        string    `description:"报告详情长图地址"`
-	DetailPdfUrl        string    `description:"报告详情PDF地址"`
-	CreateTime          time.Time `description:"创建时间"`
-	ModifyTime          time.Time `description:"修改时间"`
-	HeadImg             string    `description:"报告头图地址"`
-	EndImg              string    `description:"报告尾图地址"`
-	CanvasColor         string    `description:"画布颜色"`
-	ApproveTime         time.Time `description:"审批时间"`
-	ApproveId           int       `description:"审批ID"`
-	NeedSplice          int       `description:"0-不需要 1-需要"`
-	HeadResourceId      int       `description:"版头资源ID"`
-	EndResourceId       int       `description:"版尾资源ID"`
+	SmartReportId       int       `orm:"column(smart_report_id);pk" gorm:"column:smart_report_id;primaryKey" description:"智能研报ID"`
+	ReportCode          string    `gorm:"column:report_code" description:"报告唯一编码"`
+	ClassifyIdFirst     int       `gorm:"column:classify_id_first" description:"一级分类ID"`
+	ClassifyNameFirst   string    `gorm:"column:classify_name_first" description:"一级分类名称"`
+	ClassifyIdSecond    int       `gorm:"column:classify_id_second" description:"二级分类ID"`
+	ClassifyNameSecond  string    `gorm:"column:classify_name_second" description:"二级分类名称"`
+	AddType             int       `gorm:"column:add_type" description:"新增方式:1-新增报告;2-继承报告"`
+	Title               string    `gorm:"column:title" description:"标题"`
+	Abstract            string    `gorm:"column:abstract" description:"摘要"`
+	Author              string    `gorm:"column:author" description:"作者"`
+	Frequency           string    `gorm:"column:frequency" description:"频度"`
+	Stage               int       `gorm:"column:stage" description:"期数"`
+	Content             string    `gorm:"column:content" description:"内容"`
+	ContentSub          string    `gorm:"column:content_sub" description:"内容前两个章节"`
+	ContentStruct       string    `gorm:"column:content_struct" description:"内容组件"`
+	VideoUrl            string    `gorm:"column:video_url" description:"音频文件URL"`
+	VideoName           string    `gorm:"column:video_name" description:"音频文件名称"`
+	VideoPlaySeconds    float64   `gorm:"column:video_play_seconds" description:"音频播放时长"`
+	VideoSize           string    `gorm:"column:video_size" description:"音频文件大小,单位M"`
+	AdminId             int       `gorm:"column:admin_id" description:"创建者ID"`
+	AdminRealName       string    `gorm:"column:admin_real_name" description:"创建者姓名"`
+	State               int       `gorm:"column:state" description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
+	LastModifyAdminId   int       `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
+	LastModifyAdminName string    `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
+	ContentModifyTime   time.Time `gorm:"column:content_modify_time" description:"内容更新时间"`
+	Pv                  int       `gorm:"column:pv" description:"pv"`
+	Uv                  int       `gorm:"column:uv" description:"uv"`
+	PublishTime         time.Time `gorm:"column:publish_time" description:"发布时间"`
+	PrePublishTime      time.Time `gorm:"column:pre_publish_time" description:"预发布时间"`
+	PreMsgSend          int       `gorm:"column:pre_msg_send" description:"定时发布后是否推送模版消息:0-否;1-是"`
+	MsgIsSend           int       `gorm:"column:msg_is_send" description:"消息是否已发送:0-否;1-是"`
+	MsgSendTime         time.Time `gorm:"column:msg_send_time" description:"模版消息发送时间"`
+	DetailImgUrl        string    `gorm:"column:detail_img_url" description:"报告详情长图地址"`
+	DetailPdfUrl        string    `gorm:"column:detail_pdf_url" description:"报告详情PDF地址"`
+	CreateTime          time.Time `gorm:"column:create_time" description:"创建时间"`
+	ModifyTime          time.Time `gorm:"column:modify_time" description:"修改时间"`
+	HeadImg             string    `gorm:"column:head_img" description:"报告头图地址"`
+	EndImg              string    `gorm:"column:end_img" description:"报告尾图地址"`
+	CanvasColor         string    `gorm:"column:canvas_color" description:"画布颜色"`
+	ApproveTime         time.Time `gorm:"column:approve_time" description:"审批时间"`
+	ApproveId           int       `gorm:"column:approve_id" description:"审批ID"`
+	NeedSplice          int       `gorm:"column:need_splice" description:"0-不需要 1-需要"`
+	HeadResourceId      int       `gorm:"column:head_resource_id" description:"版头资源ID"`
+	EndResourceId       int       `gorm:"column:end_resource_id" description:"版尾资源ID"`
 }
 
 func (m *SmartReport) TableName() string {
@@ -72,12 +120,8 @@ func (m *SmartReport) PrimaryId() string {
 }
 
 func (m *SmartReport) Create() (err error) {
-	o := orm.NewOrmUsingDB("rddp")
-	id, err := o.Insert(m)
-	if err != nil {
-		return
-	}
-	m.SmartReportId = int(id)
+	o := global.DmSQL["rddp"]
+	err = o.Create(m).Error
 	return
 }
 
@@ -85,21 +129,21 @@ func (m *SmartReport) CreateMulti(items []*SmartReport) (err error) {
 	if len(items) == 0 {
 		return
 	}
-	o := orm.NewOrmUsingDB("rddp")
-	_, err = o.InsertMulti(len(items), items)
+	o := global.DmSQL["rddp"]
+	err = o.CreateInBatches(items, utils.MultiAddNum).Error
 	return
 }
 
 func (m *SmartReport) Update(cols []string) (err error) {
-	o := orm.NewOrmUsingDB("rddp")
-	_, err = o.Update(m, cols...)
+	o := global.DmSQL["rddp"]
+	err = o.Model(m).Select(cols).Updates(m).Error
 	return
 }
 
 func (m *SmartReport) Del() (err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
-	_, err = o.Raw(sql, m.SmartReportId).Exec()
+	err = o.Exec(sql, m.SmartReportId).Error
 	return
 }
 
@@ -107,39 +151,39 @@ func (m *SmartReport) MultiDel(menuIds []int) (err error) {
 	if len(menuIds) == 0 {
 		return
 	}
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
-	_, err = o.Raw(sql, menuIds).Exec()
+	err = o.Exec(sql, menuIds).Error
 	return
 }
 
 func (m *SmartReport) GetItemById(id int) (item *SmartReport, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	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).First(&item).Error
 	return
 }
 
 func (m *SmartReport) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SmartReport, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	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)
+	err = o.Raw(sql, pars...).First(&item).Error
 	return
 }
 
 func (m *SmartReport) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
-	err = o.Raw(sql, pars...).QueryRow(&count)
+	err = o.Raw(sql, pars...).Scan(&count).Error
 	return
 }
 
 func (m *SmartReport) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SmartReport, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	fields := strings.Join(fieldArr, ",")
 	if len(fieldArr) == 0 {
 		fields = `*`
@@ -149,12 +193,12 @@ func (m *SmartReport) GetItemsByCondition(condition string, pars []interface{},
 		order = ` ORDER BY ` + orderRule
 	}
 	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
-	_, err = o.Raw(sql, pars...).QueryRows(&items)
+	err = o.Raw(sql, pars...).Find(&items).Error
 	return
 }
 
 func (m *SmartReport) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SmartReport, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	fields := strings.Join(fieldArr, ",")
 	if len(fieldArr) == 0 {
 		fields = `*`
@@ -165,14 +209,14 @@ func (m *SmartReport) GetPageItemsByCondition(condition string, pars []interface
 		order = ` ORDER BY ` + orderRule
 	}
 	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
-	_, err = o.Raw(sql, pars...).QueryRows(&items)
+	err = o.Raw(sql, pars...).Find(&items).Error
 	return
 }
 
 func (m *SmartReport) GetMaxStageByClassifyId(classifyId int) (stage int, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	sql := fmt.Sprintf(`SELECT MAX(stage) AS max_stage FROM %s WHERE classify_id_second = ?`, m.TableName())
-	err = o.Raw(sql, classifyId).QueryRow(&stage)
+	err = o.Raw(sql, classifyId).Scan(&stage).Error
 	return
 }
 
@@ -388,7 +432,7 @@ type Report2ImgQueueReq struct {
 
 // UpdateSmartReportsStateByCond 批量更新报告状态
 func UpdateSmartReportsStateByCond(classifyFirstId, classifySecondId, oldState, newState int) (err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	cond := ``
 	if classifyFirstId > 0 {
 		cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
@@ -397,7 +441,7 @@ func UpdateSmartReportsStateByCond(classifyFirstId, classifySecondId, oldState,
 		cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
 	}
 	sql := fmt.Sprintf(`UPDATE smart_report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
-	_, err = o.Raw(sql, newState, oldState).Exec()
+	err = o.Exec(sql, newState, oldState).Error
 	return
 }
 
@@ -406,23 +450,23 @@ func UpdateSmartReportsStateBySecondIds(oldState, newState int, secondIds []int)
 	if len(secondIds) <= 0 {
 		return
 	}
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	// (有审批流的)未发布->待提交
 	sql := fmt.Sprintf(`UPDATE smart_report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
-	_, err = o.Raw(sql, newState, oldState, secondIds).Exec()
+	err = o.Exec(sql, newState, oldState, secondIds).Error
 	if err != nil {
 		return
 	}
 	// (无审批流的)待提交->未发布
 	sql = fmt.Sprintf(`UPDATE smart_report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
-	_, err = o.Raw(sql, oldState, newState, secondIds).Exec()
+	err = o.Exec(sql, oldState, newState, secondIds).Error
 	return
 }
 
 // UpdatePdfUrlSmartReportById 清空pdf相关字段
 func UpdatePdfUrlSmartReportById(reportId int) (err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	sql := `UPDATE smart_report SET detail_img_url = '',detail_pdf_url='',modify_time=NOW() WHERE smart_report_id = ? `
-	_, err = o.Raw(sql, reportId).Exec()
+	err = o.Exec(sql, reportId).Error
 	return
 }

+ 40 - 33
models/smart_report/smart_report_save_log.go

@@ -1,23 +1,34 @@
 package smart_report
 
 import (
+	"eta_gn/eta_api/global"
 	"eta_gn/eta_api/utils"
 	"fmt"
-	"github.com/beego/beego/v2/client/orm"
 	"strings"
 	"time"
 )
 
 // SmartReportSaveLog 智能研报保存记录
+//
+//	type SmartReportSaveLog struct {
+//		Id            int       `orm:"column(id);pk" gorm:"primaryKey" `
+//		SmartReportId int       `description:"智能研报ID"`
+//		Content       string    `description:"内容"`
+//		ContentSub    string    `description:"内容前两个章节"`
+//		ContentStruct string    `description:"内容组件"`
+//		AdminId       int       `description:"操作人ID"`
+//		AdminName     string    `description:"操作人姓名"`
+//		CreateTime    time.Time `description:"创建时间"`
+//	}
 type SmartReportSaveLog struct {
-	Id            int       `orm:"column(id);pk" gorm:"primaryKey" `
-	SmartReportId int       `description:"智能研报ID"`
-	Content       string    `description:"内容"`
-	ContentSub    string    `description:"内容前两个章节"`
-	ContentStruct string    `description:"内容组件"`
-	AdminId       int       `description:"操作人ID"`
-	AdminName     string    `description:"操作人姓名"`
-	CreateTime    time.Time `description:"创建时间"`
+	Id            int       `orm:"column(id);pk" gorm:"column:id;primaryKey" description:"日志ID"`
+	SmartReportId int       `gorm:"column:smart_report_id" description:"智能研报ID"`
+	Content       string    `gorm:"column:content" description:"内容"`
+	ContentSub    string    `gorm:"column:content_sub" description:"内容前两个章节"`
+	ContentStruct string    `gorm:"column:content_struct" description:"内容组件"`
+	AdminId       int       `gorm:"column:admin_id" description:"操作人ID"`
+	AdminName     string    `gorm:"column:admin_name" description:"操作人姓名"`
+	CreateTime    time.Time `gorm:"column:create_time" description:"创建时间"`
 }
 
 func (m *SmartReportSaveLog) TableName() string {
@@ -29,12 +40,8 @@ func (m *SmartReportSaveLog) PrimaryId() string {
 }
 
 func (m *SmartReportSaveLog) Create() (err error) {
-	o := orm.NewOrmUsingDB("rddp")
-	id, err := o.Insert(m)
-	if err != nil {
-		return
-	}
-	m.Id = int(id)
+	o := global.DmSQL["rddp"]
+	err = o.Create(m).Error
 	return
 }
 
@@ -42,21 +49,21 @@ func (m *SmartReportSaveLog) CreateMulti(items []*SmartReportSaveLog) (err error
 	if len(items) == 0 {
 		return
 	}
-	o := orm.NewOrmUsingDB("rddp")
-	_, err = o.InsertMulti(len(items), items)
+	o := global.DmSQL["rddp"]
+	err = o.CreateInBatches(items, utils.MultiAddNum).Error
 	return
 }
 
 func (m *SmartReportSaveLog) Update(cols []string) (err error) {
-	o := orm.NewOrmUsingDB("rddp")
-	_, err = o.Update(m, cols...)
+	o := global.DmSQL["rddp"]
+	err = o.Model(m).Select(cols).Updates(m).Error
 	return
 }
 
 func (m *SmartReportSaveLog) Del() (err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
-	_, err = o.Raw(sql, m.Id).Exec()
+	err = o.Exec(sql, m.Id).Error
 	return
 }
 
@@ -64,35 +71,35 @@ func (m *SmartReportSaveLog) MultiDel(menuIds []int) (err error) {
 	if len(menuIds) == 0 {
 		return
 	}
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
-	_, err = o.Raw(sql, menuIds).Exec()
+	err = o.Exec(sql, menuIds).Error
 	return
 }
 
 func (m *SmartReportSaveLog) GetItemById(id int) (item *SmartReportSaveLog, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	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).First(&item).Error
 	return
 }
 
 func (m *SmartReportSaveLog) GetItemByCondition(condition string, pars []interface{}) (item *SmartReportSaveLog, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	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).First(&item).Error
 	return
 }
 
 func (m *SmartReportSaveLog) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
-	err = o.Raw(sql, pars...).QueryRow(&count)
+	err = o.Raw(sql, pars...).Scan(&count).Error
 	return
 }
 
 func (m *SmartReportSaveLog) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SmartReportSaveLog, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	fields := strings.Join(fieldArr, ",")
 	if len(fieldArr) == 0 {
 		fields = `*`
@@ -102,12 +109,12 @@ func (m *SmartReportSaveLog) GetItemsByCondition(condition string, pars []interf
 		order = ` ORDER BY ` + orderRule
 	}
 	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
-	_, err = o.Raw(sql, pars...).QueryRows(&items)
+	err = o.Raw(sql, pars...).First(&items).Error
 	return
 }
 
 func (m *SmartReportSaveLog) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SmartReportSaveLog, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	fields := strings.Join(fieldArr, ",")
 	if len(fieldArr) == 0 {
 		fields = `*`
@@ -117,6 +124,6 @@ func (m *SmartReportSaveLog) GetPageItemsByCondition(condition string, pars []in
 		order = ` ORDER BY ` + orderRule
 	}
 	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
-	_, err = o.Raw(sql, pars...).QueryRows(&items)
+	err = o.Raw(sql, pars...).Find(&items).Error
 	return
 }

+ 48 - 34
models/smart_report/smart_resource.go

@@ -1,20 +1,29 @@
 package smart_report
 
 import (
+	"eta_gn/eta_api/global"
 	"fmt"
-	"github.com/beego/beego/v2/client/orm"
-	"github.com/rdlucklib/rdluck_tools/paging"
 	"strings"
 	"time"
+
+	"github.com/rdlucklib/rdluck_tools/paging"
 )
 
+//	type SmartReportResource struct {
+//		ResourceId int       `orm:"column(resource_id);pk" gorm:"primaryKey"  description:"智能研报资源ID"`
+//		ImgUrl     string    // 图片链接
+//		Style      string    // 版图样式
+//		ImgName    string    // 图片名称
+//		Type       int       // 类型 1-版头 2-版尾
+//		CreateTime time.Time // 创建时间
+//	}
 type SmartReportResource struct {
-	ResourceId int       `orm:"column(resource_id);pk" gorm:"primaryKey"  description:"智能研报资源ID"`
-	ImgUrl     string    // 图片链接
-	Style      string    // 版图样式
-	ImgName    string    // 图片名称
-	Type       int       // 类型 1-版头 2-版尾
-	CreateTime time.Time // 创建时间
+	ResourceId int       `orm:"column(resource_id);pk" gorm:"column:resource_id;primaryKey" description:"智能研报资源ID"`
+	ImgUrl     string    `gorm:"column:img_url" description:"图片链接"`      // 图片链接
+	Style      string    `gorm:"column:style" description:"版图样式"`        // 版图样式
+	ImgName    string    `gorm:"column:img_name" description:"图片名称"`     // 图片名称
+	Type       int       `gorm:"column:type" description:"类型 1-版头 2-版尾"` // 类型 1-版头 2-版尾
+	CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`  // 创建时间
 }
 
 func (m *SmartReportResource) TableName() string {
@@ -26,35 +35,39 @@ func (m *SmartReportResource) PrimaryId() string {
 }
 
 func (m *SmartReportResource) Create() (err error) {
-	o := orm.NewOrmUsingDB("rddp")
-	id, err := o.Insert(m)
-	if err != nil {
-		return
-	}
-	m.ResourceId = int(id)
+	o := global.DmSQL["rddp"]
+	err = o.Create(m).Error
 	return
 }
 
 func (m *SmartReportResource) Update(cols []string) (err error) {
-	o := orm.NewOrmUsingDB("rddp")
-	_, err = o.Update(m, cols...)
+	o := global.DmSQL["rddp"]
+	err = o.Model(m).Select(cols).Updates(m).Error
 	return
 }
 
 func (m *SmartReportResource) Del() (err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
-	_, err = o.Raw(sql, m.ResourceId).Exec()
+	err = o.Exec(sql, m.ResourceId).Error
 	return
 }
 
+//	type SmartReportResourceItem struct {
+//		ResourceId int    `orm:"column(resource_id);pk" gorm:"primaryKey"  description:"智能研报资源ID"`
+//		ImgUrl     string // 图片链接
+//		ImgName    string // 图片名称
+//		Style      string // 版图样式
+//		Type       int    // 类型 1-版头 2-版尾
+//		CreateTime string // 创建时间
+//	}
 type SmartReportResourceItem struct {
-	ResourceId int    `orm:"column(resource_id);pk" gorm:"primaryKey"  description:"智能研报资源ID"`
-	ImgUrl     string // 图片链接
-	ImgName    string // 图片名称
-	Style      string // 版图样式
-	Type       int    // 类型 1-版头 2-版尾
-	CreateTime string // 创建时间
+	ResourceId int    `orm:"column(resource_id);pk" gorm:"column:resource_id;primaryKey" description:"智能研报资源ID"`
+	ImgUrl     string `gorm:"column:img_url" description:"图片链接"`      // 图片链接
+	ImgName    string `gorm:"column:img_name" description:"图片名称"`     // 图片名称
+	Style      string `gorm:"column:style" description:"版图样式"`        // 版图样式
+	Type       int    `gorm:"column:type" description:"类型 1-版头 2-版尾"` // 类型 1-版头 2-版尾
+	CreateTime string `gorm:"column:create_time" description:"创建时间"`  // 创建时间
 }
 
 // SmartReportResourceListResp 智能研报资源库
@@ -64,14 +77,14 @@ type SmartReportResourceListResp struct {
 }
 
 func (m *SmartReportResource) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
-	err = o.Raw(sql, pars...).QueryRow(&count)
+	err = o.Raw(sql, pars...).Scan(&count).Error
 	return
 }
 
 func (m *SmartReportResource) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, startSize, pageSize int) (items []*SmartReportResourceItem, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	fields := strings.Join(fieldArr, ",")
 	if len(fieldArr) == 0 {
 		fields = `*`
@@ -79,7 +92,8 @@ func (m *SmartReportResource) GetPageItemsByCondition(condition string, pars []i
 	order := ` ORDER BY create_time DESC`
 
 	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
-	_, err = o.Raw(sql, pars...).QueryRows(&items)
+	pars = append(pars, startSize, pageSize)
+	err = o.Raw(sql, pars...).Find(&items).Error
 	return
 }
 
@@ -94,7 +108,7 @@ func (m *SmartReportResource) GetPageItemsByCondition(condition string, pars []i
 // @return items []*SmartReportResourceItem
 // @return err error
 func (m *SmartReportResource) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string) (items []*SmartReportResourceItem, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	fields := strings.Join(fieldArr, ",")
 	if len(fieldArr) == 0 {
 		fields = `*`
@@ -102,7 +116,7 @@ func (m *SmartReportResource) GetItemsByCondition(condition string, pars []inter
 	order := ` ORDER BY create_time DESC`
 
 	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s `, fields, m.TableName(), condition, order)
-	_, err = o.Raw(sql, pars...).QueryRows(&items)
+	err = o.Raw(sql, pars...).Find(&items).Error
 	return
 }
 
@@ -114,9 +128,9 @@ type SmartReportResourceEditReq struct {
 }
 
 func (m *SmartReportResource) GetItemById(id int) (item *SmartReportResource, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	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).First(&item).Error
 	return
 }
 
@@ -134,8 +148,8 @@ type SmartReportResourceAddReq struct {
 }
 
 func GetResourceItemById(id int) (item *SmartReportResource, err error) {
-	o := orm.NewOrmUsingDB("rddp")
+	o := global.DmSQL["rddp"]
 	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).First(&item).Error
 	return
 }