|
@@ -0,0 +1,347 @@
|
|
|
+package models
|
|
|
+
|
|
|
+import (
|
|
|
+ "eta/eta_hub/utils"
|
|
|
+ "fmt"
|
|
|
+ "github.com/beego/beego/v2/client/orm"
|
|
|
+ "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
+ "html"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+const (
|
|
|
+ SmartReportStateWaitPublish = 1
|
|
|
+ SmartReportStatePublished = 2
|
|
|
+ SmartReportStateRejected = 3
|
|
|
+ SmartReportStateApprovaled = 4
|
|
|
+)
|
|
|
+
|
|
|
+// SmartReport 智能研报
|
|
|
+type SmartReport struct {
|
|
|
+ SmartReportId int `orm:"column(smart_report_id);pk" 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-已发布"`
|
|
|
+ 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:"修改时间"`
|
|
|
+}
|
|
|
+
|
|
|
+func (m *SmartReport) TableName() string {
|
|
|
+ return "smart_report"
|
|
|
+}
|
|
|
+
|
|
|
+func (m *SmartReport) PrimaryId() string {
|
|
|
+ return "smart_report_id"
|
|
|
+}
|
|
|
+
|
|
|
+func (m *SmartReport) Create() (err error) {
|
|
|
+ o := orm.NewOrmUsingDB("rddp")
|
|
|
+ id, err := o.Insert(m)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ m.SmartReportId = int(id)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *SmartReport) CreateMulti(items []*SmartReport) (err error) {
|
|
|
+ if len(items) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ o := orm.NewOrmUsingDB("rddp")
|
|
|
+ _, err = o.InsertMulti(len(items), items)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *SmartReport) Update(cols []string) (err error) {
|
|
|
+ o := orm.NewOrmUsingDB("rddp")
|
|
|
+ _, err = o.Update(m, cols...)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *SmartReport) Del() (err error) {
|
|
|
+ o := orm.NewOrmUsingDB("rddp")
|
|
|
+ sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
|
|
|
+ _, err = o.Raw(sql, m.SmartReportId).Exec()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *SmartReport) MultiDel(menuIds []int) (err error) {
|
|
|
+ if len(menuIds) == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ o := orm.NewOrmUsingDB("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()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *SmartReport) GetItemById(id int) (item *SmartReport, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("rddp")
|
|
|
+ sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
|
|
|
+ err = o.Raw(sql, id).QueryRow(&item)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *SmartReport) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SmartReport, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("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)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *SmartReport) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("rddp")
|
|
|
+ sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
|
|
|
+ err = o.Raw(sql, pars).QueryRow(&count)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *SmartReport) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SmartReport, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("rddp")
|
|
|
+ fields := strings.Join(fieldArr, ",")
|
|
|
+ if len(fieldArr) == 0 {
|
|
|
+ fields = `*`
|
|
|
+ }
|
|
|
+ order := `ORDER BY create_time DESC`
|
|
|
+ if orderRule != "" {
|
|
|
+ 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)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *SmartReport) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SmartReport, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("rddp")
|
|
|
+ fields := strings.Join(fieldArr, ",")
|
|
|
+ if len(fieldArr) == 0 {
|
|
|
+ fields = `*`
|
|
|
+ }
|
|
|
+ order := `ORDER BY create_time DESC`
|
|
|
+ if orderRule != "" {
|
|
|
+ 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, startSize, pageSize).QueryRows(&items)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (m *SmartReport) GetMaxStageByClassifyId(classifyId int) (stage int, err error) {
|
|
|
+ o := orm.NewOrmUsingDB("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)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// SmartReportItem 智能研报信息
|
|
|
+type SmartReportItem struct {
|
|
|
+ SmartReportId int `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:"创建者姓名"`
|
|
|
+ AdminRealName string `description:"创建者姓名"`
|
|
|
+ LastModifyAdminId int `description:"最后更新人ID"`
|
|
|
+ LastModifyAdminName string `description:"最后更新人姓名"`
|
|
|
+ ContentModifyTime string `description:"内容更新时间"`
|
|
|
+ Pv int `description:"pv"`
|
|
|
+ Uv int `description:"uv"`
|
|
|
+ State int `description:"发布状态:1-待发布;2-已发布"`
|
|
|
+ PublishTime string `description:"发布时间"`
|
|
|
+ PrePublishTime string `description:"预发布时间"`
|
|
|
+ MsgIsSend int `description:"消息是否已发送:0-否;1-是"`
|
|
|
+ MsgSendTime string `description:"模版消息发送时间"`
|
|
|
+ DetailImgUrl string `description:"报告详情长图地址"`
|
|
|
+ DetailPdfUrl string `description:"报告详情PDF地址"`
|
|
|
+ CreateTime string `description:"创建时间"`
|
|
|
+ ModifyTime string `description:"修改时间"`
|
|
|
+ CanEdit bool `description:"是否可编辑"`
|
|
|
+ Editor string `description:"当前编辑人"`
|
|
|
+}
|
|
|
+
|
|
|
+// FormatSmartReport2Item 格式化智能研报数据格式
|
|
|
+func FormatSmartReport2Item(origin *SmartReport) (item *SmartReportItem) {
|
|
|
+ item = new(SmartReportItem)
|
|
|
+ if origin == nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item.SmartReportId = origin.SmartReportId
|
|
|
+ item.ReportCode = origin.ReportCode
|
|
|
+ item.ClassifyIdFirst = origin.ClassifyIdFirst
|
|
|
+ item.ClassifyNameFirst = origin.ClassifyNameFirst
|
|
|
+ item.ClassifyIdSecond = origin.ClassifyIdSecond
|
|
|
+ item.ClassifyNameSecond = origin.ClassifyNameSecond
|
|
|
+ item.AddType = origin.AddType
|
|
|
+ item.Title = origin.Title
|
|
|
+ item.Abstract = origin.Abstract
|
|
|
+ item.Author = origin.Author
|
|
|
+ item.Frequency = origin.Frequency
|
|
|
+ item.Stage = origin.Stage
|
|
|
+ item.Content = html.UnescapeString(origin.Content)
|
|
|
+ item.ContentSub = html.UnescapeString(origin.ContentSub)
|
|
|
+ item.ContentStruct = html.UnescapeString(origin.ContentStruct)
|
|
|
+ item.VideoUrl = origin.VideoUrl
|
|
|
+ item.VideoName = origin.VideoName
|
|
|
+ item.VideoPlaySeconds = origin.VideoPlaySeconds
|
|
|
+ item.VideoSize = origin.VideoSize
|
|
|
+ item.AdminId = origin.AdminId
|
|
|
+ item.AdminRealName = origin.AdminRealName
|
|
|
+ item.LastModifyAdminId = origin.LastModifyAdminId
|
|
|
+ item.LastModifyAdminName = origin.LastModifyAdminName
|
|
|
+ item.ContentModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ContentModifyTime)
|
|
|
+ item.Pv = origin.Pv
|
|
|
+ item.Uv = origin.Uv
|
|
|
+ item.State = origin.State
|
|
|
+ item.PublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PublishTime)
|
|
|
+ item.PrePublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PrePublishTime)
|
|
|
+ item.MsgIsSend = origin.MsgIsSend
|
|
|
+ item.MsgSendTime = utils.TimeTransferString(utils.FormatDateTime, origin.MsgSendTime)
|
|
|
+ item.DetailImgUrl = origin.DetailImgUrl
|
|
|
+ item.DetailPdfUrl = origin.DetailPdfUrl
|
|
|
+ item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
|
|
|
+ item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// SmartReportAddReq 新增智能研报请求体
|
|
|
+type SmartReportAddReq struct {
|
|
|
+ AddType int `description:"新增方式:1:新增报告,2:继承报告"`
|
|
|
+ ClassifyIdFirst int `description:"一级分类ID"`
|
|
|
+ ClassifyNameFirst string `description:"一级分类名称"`
|
|
|
+ ClassifyIdSecond int `description:"二级分类ID"`
|
|
|
+ ClassifyNameSecond string `description:"二级分类名称"`
|
|
|
+ Title string `description:"标题"`
|
|
|
+ Abstract string `description:"摘要"`
|
|
|
+ Author string `description:"作者"`
|
|
|
+ Frequency string `description:"频度"`
|
|
|
+}
|
|
|
+
|
|
|
+// SmartReportEditReq 编辑智能研报请求体
|
|
|
+type SmartReportEditReq struct {
|
|
|
+ SmartReportAddReq
|
|
|
+ SmartReportId int `description:"智能研报ID"`
|
|
|
+ Content string `description:"内容"`
|
|
|
+ ContentStruct string `description:"内容结构"`
|
|
|
+}
|
|
|
+
|
|
|
+// SmartReportRemoveReq 删除智能研报请求体
|
|
|
+type SmartReportRemoveReq struct {
|
|
|
+ SmartReportId int `description:"智能研报ID"`
|
|
|
+}
|
|
|
+
|
|
|
+// SmartReportPublishReq 审核智能研报请求体
|
|
|
+type SmartReportPublishReq struct {
|
|
|
+ SmartReportIds string `description:"智能研报ID,多个用英文逗号隔开"`
|
|
|
+ PublishState int `description:"3-驳回; 4-审核"`
|
|
|
+}
|
|
|
+
|
|
|
+// SmartReportPrePublishReq 预发布智能研报请求体
|
|
|
+type SmartReportPrePublishReq struct {
|
|
|
+ SmartReportId int `description:"智能研报ID"`
|
|
|
+ PrePublishTime string `description:"预发布时间"`
|
|
|
+ PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
|
|
|
+}
|
|
|
+
|
|
|
+// SmartReportSaveContentReq 保存草稿请求体
|
|
|
+type SmartReportSaveContentReq struct {
|
|
|
+ SmartReportId int `description:"智能研报ID"`
|
|
|
+ Content string `description:"内容"`
|
|
|
+ ContentStruct string `description:"内容结构"`
|
|
|
+ NoChange int `description:"内容是否未改变:1:内容未改变"`
|
|
|
+}
|
|
|
+
|
|
|
+// SmartReportSaveContentResp 保存草稿响应体
|
|
|
+type SmartReportSaveContentResp struct {
|
|
|
+ SmartReportId int `description:"智能研报ID"`
|
|
|
+}
|
|
|
+
|
|
|
+// SmartReportSendMsgReq 消息推送请求体
|
|
|
+type SmartReportSendMsgReq struct {
|
|
|
+ SmartReportId int `description:"智能研报ID"`
|
|
|
+}
|
|
|
+
|
|
|
+// SmartReportMarkEditReq 标记编辑英文研报的请求数据
|
|
|
+type SmartReportMarkEditReq struct {
|
|
|
+ SmartReportId int `description:"智能研报ID"`
|
|
|
+ Status int `description:"标记状态: 1-编辑中; 2-编辑完成"`
|
|
|
+}
|
|
|
+
|
|
|
+// SmartReportListResp 智能研报
|
|
|
+type SmartReportListResp struct {
|
|
|
+ List []*SmartReport
|
|
|
+ Paging *paging.PagingItem `description:"分页数据"`
|
|
|
+}
|
|
|
+
|
|
|
+// ElasticSmartReport 智能研报es
|
|
|
+type ElasticSmartReport struct {
|
|
|
+ SmartReportId int `description:"智能研报ID"`
|
|
|
+ Title string `description:"标题"`
|
|
|
+ Abstract string `description:"摘要"`
|
|
|
+ BodyContent string `description:"内容"`
|
|
|
+ PublishTime string `description:"发布时间"`
|
|
|
+ PublishState int `description:"发布状态 1-未发布 2-已发布"`
|
|
|
+ Author string `description:"作者"`
|
|
|
+ ClassifyIdFirst int `description:"一级分类ID"`
|
|
|
+ ClassifyNameFirst string `description:"一级分类名称"`
|
|
|
+ ClassifyIdSecond int `description:"二级分类ID"`
|
|
|
+ ClassifyNameSecond string `description:"二级分类名称"`
|
|
|
+ StageStr string `description:"报告期数"`
|
|
|
+ Frequency string `description:"频度"`
|
|
|
+}
|
|
|
+
|
|
|
+// Report2ImgQueueReq 报告详情生成长图队列请求体
|
|
|
+type Report2ImgQueueReq struct {
|
|
|
+ ReportType int `description:"报告类型: 1-研报; 2-智能研报"`
|
|
|
+ ReportCode string `description:"报告唯一编码"`
|
|
|
+}
|