package models import ( "eta/eta_hub/utils" "github.com/beego/beego/v2/client/orm" "github.com/rdlucklib/rdluck_tools/paging" "strings" "time" ) type Report struct { Id int `orm:"column(id)" description:"报告Id"` AddType int `json:"-" 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:"频度"` CreateTime string `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` State int `description:"状态:1-未提交 2-待审核 3-驳回 4-审核"` PublishTime time.Time `description:"发布时间"` Stage int `description:"期数"` MsgIsSend int `json:"-" description:"消息是否已发送,0:否,1:是"` ThsMsgIsSend int `json:"-" description:"客户群消息是否已发送,0:否,1:是"` Content string `description:"内容"` VideoUrl string `description:"音频文件URL"` VideoName string `description:"音频文件名称"` VideoPlaySeconds string `description:"音频播放时长"` VideoSize string `description:"音频文件大小,单位M"` ContentSub string `json:"-" description:"内容前两个章节"` ReportCode string `description:"报告唯一编码"` ReportVersion int `json:"-" description:"1:旧版,2:新版"` HasChapter int `json:"-" description:"是否有章节 0-否 1-是"` ChapterType string `json:"-" description:"章节类型 day-晨报 week-周报"` OldReportId int `json:"-" description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"` MsgSendTime time.Time `json:"-" description:"模版消息发送时间"` AdminId int `description:"创建者账号"` AdminRealName string `description:"创建者姓名"` } type ReportListResp struct { List []*Report Paging *paging.PagingItem `description:"分页数据"` } func GetReportListCount(condition string, pars []interface{}, companyType string) (count int, err error) { //产品权限 companyTypeSqlStr := `` if companyType == "ficc" { companyTypeSqlStr = " AND classify_id_first != 40 " } else if companyType == "权益" { companyTypeSqlStr = " AND classify_id_first = 40 " } oRddp := orm.NewOrmUsingDB("rddp") sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 ` + companyTypeSqlStr if condition != "" { sql += condition } err = oRddp.Raw(sql, pars).QueryRow(&count) return } func GetReportList(condition string, pars []interface{}, companyType string, startSize, pageSize int) (items []*Report, err error) { o := orm.NewOrmUsingDB("rddp") //产品权限 companyTypeSqlStr := `` if companyType == "ficc" { companyTypeSqlStr = " AND classify_id_first != 40 " } else if companyType == "权益" { companyTypeSqlStr = " AND classify_id_first = 40 " } sql := `SELECT * FROM report WHERE 1=1 ` + companyTypeSqlStr if condition != "" { sql += condition } sql += `ORDER BY state ASC, modify_time DESC LIMIT ?,?` _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items) return } // PublishReport 发布报告 func PublishReport(reportIds []int) (err error) { if len(reportIds) == 0 { return } o := orm.NewOrmUsingDB("rddp") sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)` _, err = o.Raw(sql).Exec() return } // PublishCancleReport 取消发布报告 func PublishCancleReport(reportIds int, publishTimeNullFlag bool) (err error) { o := orm.NewOrmUsingDB("rddp") var sql string if publishTimeNullFlag { sql = ` UPDATE report SET state=1, publish_time=null, pre_publish_time=null, pre_msg_send=0 WHERE id =?` } else { sql = ` UPDATE report SET state=1, pre_publish_time=null, pre_msg_send=0 WHERE id =?` } _, err = o.Raw(sql, reportIds).Exec() return } // 删除报告 func DeleteReport(reportIds int) (err error) { o := orm.NewOrmUsingDB("rddp") sql := ` DELETE FROM report WHERE id =? ` _, err = o.Raw(sql, reportIds).Exec() return } type ReportDetail struct { Id int `orm:"column(id)" description:"报告Id"` 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:"频度"` CreateTime string `description:"创建时间"` ModifyTime string `description:"修改时间"` State int `description:"状态:1-未提交 2-待审核 3-驳回 4-审核"` PublishTime string `description:"发布时间"` PrePublishTime string `description:"预发布时间"` Stage int `description:"期数"` MsgIsSend int `json:"-" description:"消息是否已发送,0:否,1:是"` PreMsgSend int `json:"-" description:"定时发布成功后是否立即推送模版消息:0否,1是"` Content string `description:"内容"` VideoUrl string `description:"音频文件URL"` VideoName string `description:"音频文件名称"` VideoPlaySeconds string `description:"音频播放时长"` ContentSub string `json:"-" description:"内容前两个章节"` ThsMsgIsSend int `json:"-" description:"客户群消息是否已发送,0:否,1:是"` HasChapter int `json:"-" description:"是否有章节 0-否 1-是"` ChapterType string `json:"-" description:"章节类型 day-晨报 week-周报"` } func GetReportById(reportId int) (item *Report, err error) { o := orm.NewOrmUsingDB("rddp") sql := `SELECT * FROM report WHERE id=?` err = o.Raw(sql, reportId).QueryRow(&item) return } func GetReportStage(classifyIdFirst, classifyIdSecond int) (count int, err error) { o := orm.NewOrmUsingDB("rddp") sql := `` if classifyIdSecond > 0 { sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_second=? " o.Raw(sql, classifyIdSecond).QueryRow(&count) } else { sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first=? " o.Raw(sql, classifyIdFirst).QueryRow(&count) } return } func GetReportStageEdit(classifyIdFirst, classifyIdSecond, reportId int) (count int, err error) { o := orm.NewOrmUsingDB("rddp") sql := `` if classifyIdSecond > 0 { sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_second=? AND id<>? " o.Raw(sql, classifyIdSecond, reportId).QueryRow(&count) } else { sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first=? AND id<>? " o.Raw(sql, classifyIdFirst, reportId).QueryRow(&count) } return } type PublishReq struct { ReportIds string `description:"报告id,多个用英文逗号隔开"` State int `description:"状态:1-未提交 2-待审核 3-驳回 4-审核"` } type PublishCancelReq struct { ReportIds int `description:"报告id"` } type DeleteReq struct { ReportIds int `description:"报告id"` } type AddReq 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:"频度"` State int `description:"状态:1:未发布,2:已发布"` Content string `description:"内容"` CreateTime string `description:"创建时间"` ReportVersion int `description:"1:旧版,2:新版"` } type PrePublishReq struct { ReportId int `description:"报告id"` PrePublishTime string `description:"预发布时间"` PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"` } type AddResp struct { ReportId int64 `description:"报告id"` ReportCode string `description:"报告code"` } func AddReport(item *Report) (lastId int64, err error) { o := orm.NewOrmUsingDB("rddp") lastId, err = o.Insert(item) return } type EditReq struct { ReportId int64 `description:"报告id"` 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:"频度"` State int `description:"状态:1:未发布,2:已发布"` Content string `description:"内容"` CreateTime string `description:"创建时间"` } type EditResp struct { ReportId int64 `description:"报告id"` ReportCode string `description:"报告code"` } func EditReport(item *Report, reportId int64) (err error) { o := orm.NewOrmUsingDB("rddp") sql := `UPDATE report SET classify_id_first =?, classify_name_first = ?, classify_id_second = ?, classify_name_second = ?, title = ?, abstract = ?, author = ?, frequency = ?, state = ?, content = ?, content_sub = ?, stage =?, create_time = ?, modify_time = ? WHERE id = ? ` _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title, item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Exec() return } type ReportDetailReq struct { ReportId int `description:"报告id"` } type ClassifyIdDetailReq struct { ClassifyIdFirst int `description:"报告一级分类id"` ClassifyIdSecond int `description:"报告二级分类id"` } type SendTemplateMsgReq struct { ReportId int `description:"报告id"` } func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) { o := orm.NewOrmUsingDB("rddp") sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? ` _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec() return } func EditReportContent(reportId int, content, contentSub string) (err error) { o := orm.NewOrmUsingDB("rddp") sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? ` _, err = o.Raw(sql, content, contentSub, reportId).Exec() return } func AddReportSaveLog(reportId, adminId int, content, contentSub, adminName string) (err error) { o := orm.NewOrmUsingDB("rddp") sql := ` INSERT INTO report_save_log(report_id, content,content_sub,admin_id,admin_name) VALUES (?,?,?,?,?) ` _, err = o.Raw(sql, reportId, content, contentSub, adminId, adminName).Exec() return } type SaveReportContentResp struct { ReportId int `description:"报告id"` } func ModifyReportCode(reportId int64, reportCode string) (err error) { o := orm.NewOrmUsingDB("rddp") sql := `UPDATE report SET report_code=? WHERE id=? ` _, err = o.Raw(sql, reportCode, reportId).Exec() return } func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) { o := orm.NewOrmUsingDB("rddp") if item.ThsMsgIsSend == 0 { sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? ` _, err = o.Raw(sql, item.Id).Exec() } return } // GetDayWeekReportStage 获取晨报周报期数 func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int, err error) { o := orm.NewOrmUsingDB("rddp") sql := " SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first = ? AND create_time > ? " o.Raw(sql, classifyIdFirst, yearStart).QueryRow(&count) return } // GetReportByReportId 主键获取报告 func GetReportByReportId(reportId int) (item *Report, err error) { o := orm.NewOrmUsingDB("rddp") sql := `SELECT * FROM report WHERE id = ?` err = o.Raw(sql, reportId).QueryRow(&item) return } // 发布报告 func PublishReportById(reportId, state int, publishTime time.Time) (err error) { o := orm.NewOrmUsingDB("rddp") sql := `UPDATE report SET state = ?, publish_time = ?, pre_publish_time=null, pre_msg_send=0, modify_time = NOW() WHERE id = ? ` _, err = o.Raw(sql, state,publishTime, reportId).Exec() return } func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) { o := orm.NewOrmUsingDB("rddp") sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? ` _, err = o.Raw(sql1, reportId).Exec() if err != nil { return } //修改音频标题 sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)` _, err = o.Raw(sql2, reportId).Exec() return } func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) { o := orm.NewOrmUsingDB("rddp") sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? ` _, err = o.Raw(sql1, reportId).Exec() if err != nil { return } //修改音频标题 sql2 := ` UPDATE report_chapter SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE report_id = ? and (video_name !="" and video_name is not null)` _, err = o.Raw(sql2, reportId).Exec() return } // GetReportByCondition 获取报告 func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) { o := orm.NewOrmUsingDB("rddp") fields := `*` if len(fieldArr) > 0 { fields = strings.Join(fieldArr, ",") } sql := `SELECT ` + fields + ` FROM report WHERE 1=1 ` sql += condition order := ` ORDER BY modify_time DESC` if orderRule != `` { order = orderRule } sql += order if isPage { sql += ` LIMIT ?,?` _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items) } else { _, err = o.Raw(sql, pars).QueryRows(&items) } return } type ElasticReportDetail struct { ReportId int `description:"报告ID"` ReportChapterId int `description:"报告章节ID"` Title string `description:"标题"` Abstract string `description:"摘要"` BodyContent string `description:"内容"` PublishTime string `description:"发布时间"` PublishState int `description:"状态:1-未提交 2-待审核 3-驳回 4-审核"` Author string `description:"作者"` ClassifyIdFirst int `description:"一级分类ID"` ClassifyNameFirst string `description:"一级分类名称"` ClassifyIdSecond int `description:"二级分类ID"` ClassifyNameSecond string `description:"二级分类名称"` Categories string `description:"关联的品种名称(包括品种别名)"` StageStr string `description:"报告期数"` }