|
@@ -1,9 +1,7 @@
|
|
|
package models
|
|
|
|
|
|
import (
|
|
|
- "eta_gn/eta_task/utils"
|
|
|
- "fmt"
|
|
|
- "github.com/beego/beego/v2/client/orm"
|
|
|
+ "eta_gn/eta_task/global"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -39,67 +37,74 @@ type Report struct {
|
|
|
ClassifyNameThird 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 GetReport() (items []*Report, err error) {
|
|
|
- sql := `SELECT * FROM report ORDER BY id ASC `
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- _, err = o.Raw(sql).QueryRows(&items)
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-func ModifyReportContentSub(id int, contentSub string) (err error) {
|
|
|
- sql := `UPDATE report SET content_sub=? WHERE id=? `
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- _, err = o.Raw(sql, contentSub, id).Exec()
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-func GetReportLimit() (items []*Report, err error) {
|
|
|
- sql := `SELECT * FROM report WHERE state=2 ORDER BY id DESC LIMIT 50 `
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- _, err = o.Raw(sql).QueryRows(&items)
|
|
|
- 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
|
|
|
-}
|
|
|
-
|
|
|
-// 删除报告日志记录-保留3个月
|
|
|
-func DeleteReportSaveLog() {
|
|
|
- startDateTime := time.Now().AddDate(0, -3, 0).Format(utils.FormatDateTime)
|
|
|
- fmt.Println(startDateTime)
|
|
|
-}
|
|
|
-
|
|
|
-func EditReportContentHtml(reportId int, content string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- sql := ` UPDATE report SET content=?,modify_time=NOW() WHERE id=? `
|
|
|
- _, err = o.Raw(sql, content, reportId).Exec()
|
|
|
- return
|
|
|
-}
|
|
|
+//
|
|
|
+//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 GetReport() (items []*Report, err error) {
|
|
|
+// sql := `SELECT * FROM report ORDER BY id ASC `
|
|
|
+// o := orm.NewOrmUsingDB("rddp")
|
|
|
+// _, err = o.Raw(sql).QueryRows(&items)
|
|
|
+// return
|
|
|
+//}
|
|
|
+//
|
|
|
+//func ModifyReportContentSub(id int, contentSub string) (err error) {
|
|
|
+// sql := `UPDATE report SET content_sub=? WHERE id=? `
|
|
|
+// o := orm.NewOrmUsingDB("rddp")
|
|
|
+// _, err = o.Raw(sql, contentSub, id).Exec()
|
|
|
+// return
|
|
|
+//}
|
|
|
+//
|
|
|
+//func GetReportLimit() (items []*Report, err error) {
|
|
|
+// sql := `SELECT * FROM report WHERE state=2 ORDER BY id DESC LIMIT 50 `
|
|
|
+// o := orm.NewOrmUsingDB("rddp")
|
|
|
+// _, err = o.Raw(sql).QueryRows(&items)
|
|
|
+// 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
|
|
|
+//}
|
|
|
+//
|
|
|
+//// 删除报告日志记录-保留3个月
|
|
|
+//func DeleteReportSaveLog() {
|
|
|
+// startDateTime := time.Now().AddDate(0, -3, 0).Format(utils.FormatDateTime)
|
|
|
+// fmt.Println(startDateTime)
|
|
|
+//}
|
|
|
+//
|
|
|
+//func EditReportContentHtml(reportId int, content string) (err error) {
|
|
|
+// o := orm.NewOrmUsingDB("rddp")
|
|
|
+// sql := ` UPDATE report SET content=?,modify_time=NOW() WHERE id=? `
|
|
|
+// _, err = o.Raw(sql, content, reportId).Exec()
|
|
|
+// return
|
|
|
+//}
|
|
|
|
|
|
// GetPrePublishedReports 获取定时发布时间为当前时间的未发布的报告列表
|
|
|
func GetPrePublishedReports(startTime, endTime, afterDate string) (list []*Report, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := `SELECT * FROM report WHERE state = 1 and pre_publish_time >= ? and pre_publish_time <=? and modify_time >= ?`
|
|
|
+ //_, err = o.Raw(sql, startTime, endTime, afterDate).QueryRows(&list)
|
|
|
+
|
|
|
sql := `SELECT * FROM report WHERE state = 1 and pre_publish_time >= ? and pre_publish_time <=? and modify_time >= ?`
|
|
|
- _, err = o.Raw(sql, startTime, endTime, afterDate).QueryRows(&list)
|
|
|
+ err = global.DmSQL["rddp"].Raw(sql, startTime, endTime, afterDate).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// PublishReportById 发布报告
|
|
|
func PublishReportById(reportId int, publishTime time.Time) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := `UPDATE report SET state = 2, publish_time = ?, modify_time = NOW() WHERE id = ? `
|
|
|
+ //_, err = o.Raw(sql, publishTime, reportId).Exec()
|
|
|
+
|
|
|
sql := `UPDATE report SET state = 2, publish_time = ?, modify_time = NOW() WHERE id = ? `
|
|
|
- _, err = o.Raw(sql, publishTime, reportId).Exec()
|
|
|
+ err = global.DmSQL["rddp"].Exec(sql, publishTime, reportId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -133,9 +138,12 @@ type ReportDetail struct {
|
|
|
}
|
|
|
|
|
|
func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //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()
|
|
|
+
|
|
|
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()
|
|
|
+ err = global.DmSQL["rddp"].Exec(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -149,13 +157,14 @@ type ReportChapterTypePermission struct {
|
|
|
CreatedTime time.Time `description:"创建时间"`
|
|
|
}
|
|
|
|
|
|
-// GetChapterTypePermissionByTypeIdAndResearchType 根据章节类型ID及研报类型获取章节类型权限列表
|
|
|
-func GetChapterTypePermissionByTypeIdAndResearchType(typeId int, researchType string) (list []*ReportChapterTypePermission, err error) {
|
|
|
- o := orm.NewOrm()
|
|
|
- sql := ` SELECT * FROM report_chapter_type_permission WHERE report_chapter_type_id = ? AND research_type = ? ORDER BY chart_permission_id ASC `
|
|
|
- _, err = o.Raw(sql, typeId, researchType).QueryRows(&list)
|
|
|
- return
|
|
|
-}
|
|
|
+//
|
|
|
+//// GetChapterTypePermissionByTypeIdAndResearchType 根据章节类型ID及研报类型获取章节类型权限列表
|
|
|
+//func GetChapterTypePermissionByTypeIdAndResearchType(typeId int, researchType string) (list []*ReportChapterTypePermission, err error) {
|
|
|
+// o := orm.NewOrm()
|
|
|
+// sql := ` SELECT * FROM report_chapter_type_permission WHERE report_chapter_type_id = ? AND research_type = ? ORDER BY chart_permission_id ASC `
|
|
|
+// _, err = o.Raw(sql, typeId, researchType).QueryRows(&list)
|
|
|
+// return
|
|
|
+//}
|
|
|
|
|
|
type ElasticReportDetail struct {
|
|
|
ReportId int `description:"报告ID"`
|
|
@@ -182,60 +191,98 @@ type ChartPermissionMappingIdName struct {
|
|
|
}
|
|
|
|
|
|
func GetChartPermissionNameFromMappingByKeyword(source string, classifyId int) (list []*ChartPermissionMappingIdName, err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := " SELECT b.chart_permission_id AS permission_id,b.permission_name FROM chart_permission_search_key_word_mapping AS a INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id WHERE a.`from` = ? AND a.classify_id = ? "
|
|
|
+ //_, err = o.Raw(sql, source, classifyId).QueryRows(&list)
|
|
|
+
|
|
|
sql := " SELECT b.chart_permission_id AS permission_id,b.permission_name FROM chart_permission_search_key_word_mapping AS a INNER JOIN chart_permission AS b ON a.chart_permission_id = b.chart_permission_id WHERE a.`from` = ? AND a.classify_id = ? "
|
|
|
- _, err = o.Raw(sql, source, classifyId).QueryRows(&list)
|
|
|
+ err = global.DmSQL["rddp"].Raw(sql, source, classifyId).Find(&list).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //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()
|
|
|
+
|
|
|
sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
|
|
|
- _, err = o.Raw(sql1, reportId).Exec()
|
|
|
+ err = global.DmSQL["rddp"].Exec(sql1, reportId).Error
|
|
|
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()
|
|
|
+ err = global.DmSQL["rddp"].Exec(sql2, reportId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //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()
|
|
|
+
|
|
|
sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
|
|
|
- _, err = o.Raw(sql1, reportId).Exec()
|
|
|
+ err = global.DmSQL["rddp"].Exec(sql1, reportId).Error
|
|
|
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()
|
|
|
+ err = global.DmSQL["rddp"].Exec(sql2, reportId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func ModifyReportMsgIsSend(reportId int) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? and msg_is_send=0`
|
|
|
+ //_, err = o.Raw(sql, reportId).Exec()
|
|
|
+
|
|
|
sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? and msg_is_send=0`
|
|
|
- _, err = o.Raw(sql, reportId).Exec()
|
|
|
+ err = global.DmSQL["rddp"].Exec(sql, reportId).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// ClearReportSaveLog 清理报告保存日志
|
|
|
func ClearReportSaveLog(date string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //sql := `DELETE FROM report_save_log WHERE create_time <= ?`
|
|
|
+ //_, err = o.Raw(sql, date).Exec()
|
|
|
+
|
|
|
sql := `DELETE FROM report_save_log WHERE create_time <= ?`
|
|
|
- _, err = o.Raw(sql, date).Exec()
|
|
|
+ err = global.DmSQL["rddp"].Exec(sql, date).Error
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// PublishReportAndChapter 发布报告及章节
|
|
|
func PublishReportAndChapter(reportInfo *Report, isPublishReport bool, cols []string) (err error) {
|
|
|
- o := orm.NewOrmUsingDB("rddp")
|
|
|
- to, err := o.Begin()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
+ //o := orm.NewOrmUsingDB("rddp")
|
|
|
+ //to, err := o.Begin()
|
|
|
+ //if err != nil {
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //defer func() {
|
|
|
+ // if err != nil {
|
|
|
+ // _ = to.Rollback()
|
|
|
+ // } else {
|
|
|
+ // _ = to.Commit()
|
|
|
+ // }
|
|
|
+ //}()
|
|
|
+
|
|
|
+ to := global.DmSQL["rddp"].Begin()
|
|
|
+
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
_ = to.Rollback()
|
|
@@ -243,17 +290,21 @@ func PublishReportAndChapter(reportInfo *Report, isPublishReport bool, cols []st
|
|
|
_ = to.Commit()
|
|
|
}
|
|
|
}()
|
|
|
+
|
|
|
// 更新报告
|
|
|
if isPublishReport {
|
|
|
- _, err = to.Update(reportInfo, cols...)
|
|
|
+ err = to.Select(cols).Updates(reportInfo).Error
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 发布该报告的所有章节
|
|
|
+ //sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? `
|
|
|
+ //_, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id).Exec()
|
|
|
+
|
|
|
sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? `
|
|
|
- _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id).Exec()
|
|
|
+ err = to.Exec(sql, reportInfo.PublishTime, reportInfo.Id).Error
|
|
|
|
|
|
// 发布章节
|
|
|
//if len(publishIds) > 0 {
|