report.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. package models
  2. import (
  3. "eta_gn/eta_task/global"
  4. "time"
  5. )
  6. type Report struct {
  7. Id int `orm:"column(id)" description:"报告Id"`
  8. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  9. ClassifyIdFirst int `description:"一级分类id"`
  10. ClassifyNameFirst string `description:"一级分类名称"`
  11. ClassifyIdSecond int `description:"二级分类id"`
  12. ClassifyNameSecond string `description:"二级分类名称"`
  13. Title string `description:"标题"`
  14. Abstract string `description:"摘要"`
  15. Author string `description:"作者"`
  16. Frequency string `description:"频度"`
  17. CreateTime string `description:"创建时间"`
  18. ModifyTime time.Time `description:"修改时间"`
  19. State int `description:"1:未发布,2:已发布"`
  20. PublishTime time.Time `description:"发布时间"`
  21. Stage int `description:"期数"`
  22. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  23. Content string `description:"内容"`
  24. VideoUrl string `description:"音频文件URL"`
  25. VideoName string `description:"音频文件名称"`
  26. VideoPlaySeconds string `description:"音频播放时长"`
  27. ContentSub string `description:"内容前两个章节"`
  28. HasChapter int `description:"是否有章节 0-否 1-是"`
  29. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  30. OldReportId int `description:"research_report表ID(后续一两个版本过渡需要,之后可移除)"`
  31. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  32. AdminId int
  33. AdminName string `description:"系统用户名称"`
  34. ClassifyIdThird int `description:"三级分类id"`
  35. ClassifyNameThird string `description:"三级分类名称"`
  36. }
  37. //
  38. //func GetReportById(reportId int) (item *ReportDetail, err error) {
  39. // o := orm.NewOrmUsingDB("rddp")
  40. // sql := `SELECT * FROM report WHERE id=?`
  41. // err = o.Raw(sql, reportId).QueryRow(&item)
  42. // return
  43. //}
  44. //
  45. //func GetReport() (items []*Report, err error) {
  46. // sql := `SELECT * FROM report ORDER BY id ASC `
  47. // o := orm.NewOrmUsingDB("rddp")
  48. // _, err = o.Raw(sql).QueryRows(&items)
  49. // return
  50. //}
  51. //
  52. //func ModifyReportContentSub(id int, contentSub string) (err error) {
  53. // sql := `UPDATE report SET content_sub=? WHERE id=? `
  54. // o := orm.NewOrmUsingDB("rddp")
  55. // _, err = o.Raw(sql, contentSub, id).Exec()
  56. // return
  57. //}
  58. //
  59. //func GetReportLimit() (items []*Report, err error) {
  60. // sql := `SELECT * FROM report WHERE state=2 ORDER BY id DESC LIMIT 50 `
  61. // o := orm.NewOrmUsingDB("rddp")
  62. // _, err = o.Raw(sql).QueryRows(&items)
  63. // return
  64. //}
  65. //
  66. //func EditReportContent(reportId int, content, contentSub string) (err error) {
  67. // o := orm.NewOrmUsingDB("rddp")
  68. // sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  69. // _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  70. // return
  71. //}
  72. //
  73. //// 删除报告日志记录-保留3个月
  74. //func DeleteReportSaveLog() {
  75. // startDateTime := time.Now().AddDate(0, -3, 0).Format(utils.FormatDateTime)
  76. // fmt.Println(startDateTime)
  77. //}
  78. //
  79. //func EditReportContentHtml(reportId int, content string) (err error) {
  80. // o := orm.NewOrmUsingDB("rddp")
  81. // sql := ` UPDATE report SET content=?,modify_time=NOW() WHERE id=? `
  82. // _, err = o.Raw(sql, content, reportId).Exec()
  83. // return
  84. //}
  85. // GetPrePublishedReports 获取定时发布时间为当前时间的未发布的报告列表
  86. func GetPrePublishedReports(startTime, endTime, afterDate string) (list []*Report, err error) {
  87. //o := orm.NewOrmUsingDB("rddp")
  88. //sql := `SELECT * FROM report WHERE state = 1 and pre_publish_time >= ? and pre_publish_time <=? and modify_time >= ?`
  89. //_, err = o.Raw(sql, startTime, endTime, afterDate).QueryRows(&list)
  90. sql := `SELECT * FROM report WHERE state = 1 and pre_publish_time >= ? and pre_publish_time <=? and modify_time >= ?`
  91. err = global.DmSQL["rddp"].Raw(sql, startTime, endTime, afterDate).Find(&list).Error
  92. return
  93. }
  94. // PublishReportById 发布报告
  95. func PublishReportById(reportId int, publishTime time.Time) (err error) {
  96. //o := orm.NewOrmUsingDB("rddp")
  97. //sql := `UPDATE report SET state = 2, publish_time = ?, modify_time = NOW() WHERE id = ? `
  98. //_, err = o.Raw(sql, publishTime, reportId).Exec()
  99. sql := `UPDATE report SET state = 2, publish_time = ?, modify_time = NOW() WHERE id = ? `
  100. err = global.DmSQL["rddp"].Exec(sql, publishTime, reportId).Error
  101. return
  102. }
  103. type ReportDetail struct {
  104. Id int `orm:"column(id)" description:"报告Id"`
  105. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  106. ClassifyIdFirst int `description:"一级分类id"`
  107. ClassifyNameFirst string `description:"一级分类名称"`
  108. ClassifyIdSecond int `description:"二级分类id"`
  109. ClassifyNameSecond string `description:"二级分类名称"`
  110. Title string `description:"标题"`
  111. Abstract string `description:"摘要"`
  112. Author string `description:"作者"`
  113. Frequency string `description:"频度"`
  114. CreateTime string `description:"创建时间"`
  115. ModifyTime string `description:"修改时间"`
  116. State int `description:"1:未发布,2:已发布"`
  117. PublishTime string `description:"发布时间"`
  118. Stage int `description:"期数"`
  119. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  120. Content string `description:"内容"`
  121. VideoUrl string `description:"音频文件URL"`
  122. VideoName string `description:"音频文件名称"`
  123. VideoPlaySeconds string `description:"音频播放时长"`
  124. ContentSub string `description:"内容前两个章节"`
  125. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  126. HasChapter int `description:"是否有章节 0-否 1-是"`
  127. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  128. OldReportId int `description:"research_report表ID(后续一两个版本过渡需要,之后可移除)"`
  129. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  130. }
  131. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  132. //o := orm.NewOrmUsingDB("rddp")
  133. //sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  134. //_, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  135. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  136. err = global.DmSQL["rddp"].Exec(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Error
  137. return
  138. }
  139. type ReportChapterTypePermission struct {
  140. Id int `gorm:"column:id;primaryKey"` // `orm:"column(id);pk" description:"主键ID"`
  141. ReportChapterTypeId int `description:"报告章节类型ID"`
  142. ReportChapterTypeName string `description:"章节名称"`
  143. ChartPermissionId int `description:"大分类ID"`
  144. PermissionName string `description:"权限名称"`
  145. ResearchType string `description:"研报类型"`
  146. CreatedTime time.Time `description:"创建时间"`
  147. }
  148. //
  149. //// GetChapterTypePermissionByTypeIdAndResearchType 根据章节类型ID及研报类型获取章节类型权限列表
  150. //func GetChapterTypePermissionByTypeIdAndResearchType(typeId int, researchType string) (list []*ReportChapterTypePermission, err error) {
  151. // o := orm.NewOrm()
  152. // sql := ` SELECT * FROM report_chapter_type_permission WHERE report_chapter_type_id = ? AND research_type = ? ORDER BY chart_permission_id ASC `
  153. // _, err = o.Raw(sql, typeId, researchType).QueryRows(&list)
  154. // return
  155. //}
  156. type ElasticReportDetail struct {
  157. ReportId int `description:"报告ID"`
  158. ReportChapterId int `description:"报告章节ID"`
  159. Title string `description:"标题"`
  160. Abstract string `description:"摘要"`
  161. BodyContent string `description:"内容"`
  162. PublishTime string `description:"发布时间"`
  163. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  164. Author string `description:"作者"`
  165. ClassifyIdFirst int `description:"一级分类ID"`
  166. ClassifyNameFirst string `description:"一级分类名称"`
  167. ClassifyIdSecond int `description:"二级分类ID"`
  168. ClassifyNameSecond string `description:"二级分类名称"`
  169. ClassifyId int `description:"最小单元的分类ID"`
  170. ClassifyName string `description:"最小单元的分类名称"`
  171. Categories string `description:"关联的品种名称(包括品种别名)"`
  172. StageStr string `description:"报告期数"`
  173. }
  174. type ChartPermissionMappingIdName struct {
  175. PermissionId int
  176. PermissionName string
  177. }
  178. func GetChartPermissionNameFromMappingByKeyword(source string, classifyId int) (list []*ChartPermissionMappingIdName, err error) {
  179. //o := orm.NewOrmUsingDB("rddp")
  180. //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 = ? "
  181. //_, err = o.Raw(sql, source, classifyId).QueryRows(&list)
  182. 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 = ? "
  183. err = global.DmSQL["rddp"].Raw(sql, source, classifyId).Find(&list).Error
  184. return
  185. }
  186. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  187. //o := orm.NewOrmUsingDB("rddp")
  188. //sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  189. //_, err = o.Raw(sql1, reportId).Exec()
  190. //if err != nil {
  191. // return
  192. //}
  193. ////修改音频标题
  194. //sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  195. //_, err = o.Raw(sql2, reportId).Exec()
  196. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  197. err = global.DmSQL["rddp"].Exec(sql1, reportId).Error
  198. if err != nil {
  199. return
  200. }
  201. //修改音频标题
  202. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !='' and video_name is not null)`
  203. err = global.DmSQL["rddp"].Exec(sql2, reportId).Error
  204. return
  205. }
  206. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  207. //o := orm.NewOrmUsingDB("rddp")
  208. //sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  209. //_, err = o.Raw(sql1, reportId).Exec()
  210. //if err != nil {
  211. // return
  212. //}
  213. ////修改音频标题
  214. //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)`
  215. //_, err = o.Raw(sql2, reportId).Exec()
  216. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  217. err = global.DmSQL["rddp"].Exec(sql1, reportId).Error
  218. if err != nil {
  219. return
  220. }
  221. //修改音频标题
  222. 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)`
  223. err = global.DmSQL["rddp"].Exec(sql2, reportId).Error
  224. return
  225. }
  226. func ModifyReportMsgIsSend(reportId int) (err error) {
  227. //o := orm.NewOrmUsingDB("rddp")
  228. //sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? and msg_is_send=0`
  229. //_, err = o.Raw(sql, reportId).Exec()
  230. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? and msg_is_send=0`
  231. err = global.DmSQL["rddp"].Exec(sql, reportId).Error
  232. return
  233. }
  234. // ClearReportSaveLog 清理报告保存日志
  235. func ClearReportSaveLog(date string) (err error) {
  236. //o := orm.NewOrmUsingDB("rddp")
  237. //sql := `DELETE FROM report_save_log WHERE create_time <= ?`
  238. //_, err = o.Raw(sql, date).Exec()
  239. sql := `DELETE FROM report_save_log WHERE create_time <= ?`
  240. err = global.DmSQL["rddp"].Exec(sql, date).Error
  241. return
  242. }
  243. // PublishReportAndChapter 发布报告及章节
  244. func PublishReportAndChapter(reportInfo *Report, isPublishReport bool, cols []string) (err error) {
  245. //o := orm.NewOrmUsingDB("rddp")
  246. //to, err := o.Begin()
  247. //if err != nil {
  248. // return
  249. //}
  250. //defer func() {
  251. // if err != nil {
  252. // _ = to.Rollback()
  253. // } else {
  254. // _ = to.Commit()
  255. // }
  256. //}()
  257. to := global.DmSQL["rddp"].Begin()
  258. defer func() {
  259. if err != nil {
  260. _ = to.Rollback()
  261. } else {
  262. _ = to.Commit()
  263. }
  264. }()
  265. // 更新报告
  266. if isPublishReport {
  267. err = to.Select(cols).Updates(reportInfo).Error
  268. if err != nil {
  269. return
  270. }
  271. }
  272. // 发布该报告的所有章节
  273. //sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? `
  274. //_, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id).Exec()
  275. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? `
  276. err = to.Exec(sql, reportInfo.PublishTime, reportInfo.Id).Error
  277. // 发布章节
  278. //if len(publishIds) > 0 {
  279. // sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  280. // _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
  281. //}
  282. //if len(unPublishIds) > 0 {
  283. // sql := ` UPDATE report_chapter SET publish_state = 1, publish_time = NULL, is_edit = 0 WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(unPublishIds)) + `) `
  284. // _, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
  285. //}
  286. return
  287. }