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