package report import ( "github.com/beego/beego/v2/client/orm" "github.com/rdlucklib/rdluck_tools/paging" "time" ) type Report 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 time.Time `description:"修改时间"` State int `description:"1:未发布,2:已发布"` PublishTime time.Time `description:"发布时间"` Stage int `description:"期数"` MsgIsSend int `description:"消息是否已发送,0:否,1:是"` Content string `description:"内容"` VideoUrl string `description:"音频文件URL"` VideoName string `description:"音频文件名称"` VideoPlaySeconds string `description:"音频播放时长"` ContentSub string `description:"内容前两个章节"` } type ReportList struct { Id int `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 time.Time `description:"修改时间"` State int `description:"1:未发布,2:已发布"` PublishTime string `description:"发布时间"` Stage int `description:"期数"` MsgIsSend int `description:"消息是否已发送,0:否,1:是"` Content string `description:"内容"` VideoUrl string `description:"音频文件URL"` VideoName string `description:"音频文件名称"` VideoPlaySeconds string `description:"音频播放时长"` ContentSub string `description:"内容前两个章节"` Pv int `description:"Pv"` Uv int `description:"Uv"` ReportCode string `description:"报告唯一编码"` } type ReportListResp struct { List []*ReportList 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 " } o := orm.NewOrmUsingDB("rddp") sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 ` + companyTypeSqlStr if condition != "" { sql += condition } err = o.Raw(sql, pars).QueryRow(&count) return } func GetReportList(condition string, pars []interface{}, companyType string, startSize, pageSize int) (items []*ReportList, 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 *, (SELECT COUNT(1) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS pv, (SELECT COUNT(DISTINCT user_id) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS uv FROM report WHERE 1=1 ` + companyTypeSqlStr if condition != "" { sql += condition } sql += `ORDER BY modify_time DESC LIMIT ?,?` _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items) return } //发布报告 func PublishReport(reportIds string) (err error) { o := orm.NewOrmUsingDB("rddp") sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + reportIds + `)` _, err = o.Raw(sql).Exec() return } //取消发布报告 func PublishCancleReport(reportIds int) (err error) { o := orm.NewOrmUsingDB("rddp") sql := ` UPDATE report SET state=1,publish_time=null 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:已发布"` PublishTime string `description:"发布时间"` Stage int `description:"期数"` MsgIsSend int `description:"消息是否已发送,0:否,1:是"` Content string `description:"内容"` VideoUrl string `description:"音频文件URL"` VideoName string `description:"音频文件名称"` VideoPlaySeconds string `description:"音频播放时长"` ContentSub string `description:"内容前两个章节"` } func GetReportById(reportId int) (item *ReportDetail, 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,多个用英文逗号隔开"` } 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:"创建时间"` } 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=?, 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, time.Now(), reportId).Exec() return } type ReportDetailReq struct { ReportId int `description:"报告id"` } type ClassifyIdDetailReq struct { ClassifyIdFirst int `description:"报告一级分类id"` ClassifyIdSecond int `description:"报告二级分类id"` } func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) { o := orm.NewOrmUsingDB("rddp") sql := ` SELECT * FROM report WHERE 1=1 ` if classifyIdSecond > 0 { sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1` err = o.Raw(sql, classifyIdSecond).QueryRow(&item) } else { sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1` err = o.Raw(sql, classifyIdFirst).QueryRow(&item) } return } type SendTemplateMsgReq struct { ReportId int `description:"报告id"` } func ModifyReportMsgIsSend(reportId int) (err error) { o := orm.NewOrmUsingDB("rddp") report, err := GetReportById(reportId) if err != nil { return } if report.MsgIsSend == 0 { sql := `UPDATE report SET msg_is_send = 1 WHERE id = ? ` _, err = o.Raw(sql, reportId).Exec() } return } 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 } type ReportItem 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 time.Time `description:"创建时间"` ModifyTime time.Time `description:"修改时间"` State int `description:"1:未发布,2:已发布"` PublishTime time.Time `description:"发布时间"` Stage int `description:"期数"` MsgIsSend int `description:"消息是否已发送,0:否,1:是"` Content string `description:"内容"` VideoUrl string `description:"音频文件URL"` VideoName string `description:"音频文件名称"` VideoPlaySeconds string `description:"音频播放时长"` ContentSub string `description:"内容前两个章节"` } func GetReportItemById(reportId int) (item *ReportItem, err error) { o := orm.NewOrmUsingDB("rddp") sql := `SELECT * FROM report WHERE id=?` err = o.Raw(sql, reportId).QueryRow(&item) return } type SaveReportContent struct { Content string `description:"内容"` ReportId int `description:"报告id"` } 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 int, content, contentSub string) (err error) { o := orm.NewOrmUsingDB("rddp") sql := ` INSERT INTO report_save_log(report_id, content,content_sub) VALUES (?,?,?) ` _, err = o.Raw(sql, reportId, content, contentSub).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 }