package models import ( "eta_gn/eta_report/global" "eta_gn/eta_report/utils" "fmt" "html" "log" "time" ) // SmartReport 智能研报 type SmartReport struct { SmartReportId int `gorm:"primaryKey;autoIncrement;column:smart_report_id" description:"智能研报ID"` ReportCode string `gorm:"column:banner_url" 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-已发布"` 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:"画布颜色"` 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"` HeadStyle string `gorm:"column:head_style"description:"版头样式"` EndStyle string `gorm:"column:end_style"description:"版尾样式"` } func (m *SmartReport) TableName() string { return "smart_report" } func (m *SmartReport) PrimaryId() string { return "smart_report_id" } func (m *SmartReport) Create() (err error) { // 使用 GORM 插入记录 err = global.DEFAULT_DmSQL.Create(m).Error if err != nil { log.Printf("插入失败: %v", err) return } return } func (m *SmartReport) Update(cols []string) (err error) { err = global.DEFAULT_DmSQL.Model(m).Select(cols).Updates(m).Error return } func (m *SmartReport) GetItemById(id int) (item *SmartReport, err error) { sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId()) err = global.DEFAULT_DmSQL.Raw(sql, id).Scan(&item).Error return } func (m *SmartReport) GetItemByCondition(condition string, pars []interface{}) (item *SmartReport, err error) { sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s`, m.TableName(), condition) err = global.DEFAULT_DmSQL.Raw(sql, pars).Scan(&item).Error 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:"创建者姓名"` Pv int `description:"pv"` Uv int `description:"uv"` State int `description:"发布状态:1-待发布;2-已发布"` PublishTime string `description:"发布时间"` PrePublishTime string `description:"预发布时间"` MsgIsSend int `description:"消息是否已发送:0-否;1-是"` DetailImgUrl string `description:"报告详情长图地址"` DetailPdfUrl string `description:"报告详情PDF地址"` CreateTime string `description:"创建时间"` ModifyTime string `description:"修改时间"` CanEdit bool `description:"是否可编辑"` Editor string `description:"当前编辑人"` HeadImg string `description:"报告头图地址"` EndImg string `description:"报告尾图地址"` CanvasColor string `description:"画布颜色"` NeedSplice int `description:"0-不需要 1-需要"` HeadResourceId int `description:"版头资源ID"` EndResourceId int `description:"版尾资源ID"` HeadStyle string `description:"版头样式"` EndStyle 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.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.DetailImgUrl = origin.DetailImgUrl item.DetailPdfUrl = origin.DetailPdfUrl item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime) item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime) item.CanvasColor = origin.CanvasColor item.HeadImg = origin.HeadImg item.EndImg = origin.EndImg item.NeedSplice = origin.NeedSplice item.HeadResourceId = origin.HeadResourceId item.EndResourceId = origin.EndResourceId return } // SmartReportShareDetailResp 智能研报分享详情响应体 type SmartReportShareDetailResp struct { Report *SmartReportItem `description:"智能研报"` Disclaimer string `description:"免责声明"` H5ShareName string `description:"研报分享抬头"` H5ReportShareImg string `description:"研报分享图片"` Hz int } // UpdateSmartReportPv 研报pv自增 func UpdateSmartReportPv(reportId int) (err error) { sql := `UPDATE smart_report SET pv = pv + 1 WHERE smart_report_id = ?` err = global.DEFAULT_DmSQL.Exec(sql, reportId).Error return } type SmartReportResource struct { ResourceId int `gorm:"primaryKey;autoIncrement;column:resource_id" description:"智能研报资源ID"` ImgUrl string // 图片链接 Style string // 版图样式 ImgName string // 图片名称 Type int // 类型 1-版头 2-版尾 CreateTime time.Time // 创建时间 } func GetResourceItemById(id int) (item *SmartReportResource, err error) { sql := fmt.Sprintf(`SELECT * FROM smart_report_resource WHERE resource_id = ? LIMIT 1`) err = global.DEFAULT_DmSQL.Raw(sql, id).Scan(&item).Error return } type SmartReportWechatShareDetailResp struct { H5ShareName string `description:"研报分享抬头"` H5ShareTitle string `description:"研报分享抬头"` H5ReportShareImg string `description:"研报分享图片"` }