report.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. package models
  2. import (
  3. "eta/eta_hub/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "html"
  7. "strings"
  8. "time"
  9. )
  10. // 报告状态
  11. const (
  12. ReportStateUnpublished = 1 // 未发布
  13. ReportStatePublished = 2 // 已发布
  14. ReportStateWaitSubmit = 3 // 待提交
  15. ReportStateWaitApprove = 4 // 审批中
  16. ReportStateRefused = 5 // 已驳回
  17. ReportStatePass = 6 // 已通过
  18. )
  19. // 报告操作
  20. const (
  21. ReportOperateAdd = 1 // 新增报告
  22. ReportOperateEdit = 2 // 编辑报告
  23. ReportOperatePublish = 3 // 发布报告
  24. ReportOperateCancelPublish = 4 // 取消发布报告
  25. ReportOperateSubmitApprove = 5 // 提交审批
  26. ReportOperateCancelApprove = 6 // 撤回审批
  27. )
  28. // 报告类型
  29. const (
  30. ReportTypeChinese = 1 // 中文研报
  31. ReportTypeEnglish = 2 // 英文研报
  32. ReportTypeSmart = 3 // 智能研报
  33. )
  34. type Report struct {
  35. Id int `orm:"column(id)" description:"报告Id"`
  36. AddType int `json:"-" description:"新增方式:1:新增报告,2:继承报告"`
  37. ClassifyIdFirst int `description:"一级分类id"`
  38. ClassifyNameFirst string `description:"一级分类名称"`
  39. ClassifyIdSecond int `description:"二级分类id"`
  40. ClassifyNameSecond string `description:"二级分类名称"`
  41. Title string `description:"标题"`
  42. Abstract string `description:"摘要"`
  43. Author string `description:"作者"`
  44. Frequency string `description:"频度"`
  45. State int `description:"状态:1-未提交 2-待审核 3-驳回 4-审核"`
  46. Stage int `description:"期数"`
  47. MsgIsSend int `json:"-" description:"消息是否已发送,0:否,1:是"`
  48. ThsMsgIsSend int `json:"-" description:"客户群消息是否已发送,0:否,1:是"`
  49. Content string `description:"内容"`
  50. VideoUrl string `description:"音频文件URL"`
  51. VideoName string `description:"音频文件名称"`
  52. VideoPlaySeconds string `description:"音频播放时长"`
  53. VideoSize string `description:"音频文件大小,单位M"`
  54. ContentSub string `json:"-" description:"内容前两个章节"`
  55. ReportCode string `description:"报告唯一编码"`
  56. ReportVersion int `json:"-" description:"1:旧版,2:新版"`
  57. HasChapter int `json:"-" description:"是否有章节 0-否 1-是"`
  58. ChapterType string `json:"-" description:"章节类型 day-晨报 week-周报"`
  59. OldReportId int `json:"-" description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  60. MsgSendTime time.Time `json:"-" description:"模版消息发送时间"`
  61. AdminId int `description:"创建者账号"`
  62. AdminRealName string `description:"创建者姓名"`
  63. ApproveTime time.Time `description:"审批时间"`
  64. PublishTime time.Time `description:"发布时间"`
  65. CreateTime time.Time `description:"创建时间"`
  66. ModifyTime time.Time `description:"修改时间"`
  67. }
  68. type ReportListResp struct {
  69. List []*ReportItem
  70. Paging *paging.PagingItem `description:"分页数据"`
  71. }
  72. func GetReportListCount(condition string, pars []interface{}, companyType string) (count int, err error) {
  73. //产品权限
  74. companyTypeSqlStr := ``
  75. if companyType == "ficc" {
  76. companyTypeSqlStr = " AND classify_id_first != 40 "
  77. } else if companyType == "权益" {
  78. companyTypeSqlStr = " AND classify_id_first = 40 "
  79. }
  80. oRddp := orm.NewOrmUsingDB("rddp")
  81. sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 ` + companyTypeSqlStr
  82. if condition != "" {
  83. sql += condition
  84. }
  85. err = oRddp.Raw(sql, pars).QueryRow(&count)
  86. return
  87. }
  88. func GetReportList(condition string, pars []interface{}, startSize, pageSize int) (items []*Report, err error) {
  89. o := orm.NewOrmUsingDB("rddp")
  90. sql := `SELECT * FROM report WHERE 1=1 `
  91. if condition != "" {
  92. sql += condition
  93. }
  94. sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  95. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  96. return
  97. }
  98. // PublishReport 发布报告
  99. func PublishReport(reportIds []int) (err error) {
  100. if len(reportIds) == 0 {
  101. return
  102. }
  103. o := orm.NewOrmUsingDB("rddp")
  104. sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  105. _, err = o.Raw(sql).Exec()
  106. return
  107. }
  108. // PublishCancleReport 取消发布报告
  109. func PublishCancleReport(reportIds int, publishTimeNullFlag bool) (err error) {
  110. o := orm.NewOrmUsingDB("rddp")
  111. var sql string
  112. if publishTimeNullFlag {
  113. sql = ` UPDATE report SET state=1, publish_time=null, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
  114. } else {
  115. sql = ` UPDATE report SET state=1, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
  116. }
  117. _, err = o.Raw(sql, reportIds).Exec()
  118. return
  119. }
  120. // 删除报告
  121. func DeleteReport(reportIds int) (err error) {
  122. o := orm.NewOrmUsingDB("rddp")
  123. sql := ` DELETE FROM report WHERE id =? `
  124. _, err = o.Raw(sql, reportIds).Exec()
  125. return
  126. }
  127. type ReportDetail struct {
  128. Id int `orm:"column(id)" description:"报告Id"`
  129. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  130. ClassifyIdFirst int `description:"一级分类id"`
  131. ClassifyNameFirst string `description:"一级分类名称"`
  132. ClassifyIdSecond int `description:"二级分类id"`
  133. ClassifyNameSecond string `description:"二级分类名称"`
  134. Title string `description:"标题"`
  135. Abstract string `description:"摘要"`
  136. Author string `description:"作者"`
  137. Frequency string `description:"频度"`
  138. CreateTime string `description:"创建时间"`
  139. ModifyTime string `description:"修改时间"`
  140. State int `description:"状态:1-未提交 2-待审核 3-驳回 4-审核"`
  141. PublishTime string `description:"发布时间"`
  142. PrePublishTime string `description:"预发布时间"`
  143. Stage int `description:"期数"`
  144. MsgIsSend int `json:"-" description:"消息是否已发送,0:否,1:是"`
  145. PreMsgSend int `json:"-" description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  146. Content string `description:"内容"`
  147. VideoUrl string `description:"音频文件URL"`
  148. VideoName string `description:"音频文件名称"`
  149. VideoPlaySeconds string `description:"音频播放时长"`
  150. ContentSub string `json:"-" description:"内容前两个章节"`
  151. ThsMsgIsSend int `json:"-" description:"客户群消息是否已发送,0:否,1:是"`
  152. HasChapter int `json:"-" description:"是否有章节 0-否 1-是"`
  153. ChapterType string `json:"-" description:"章节类型 day-晨报 week-周报"`
  154. }
  155. func GetReportById(reportId int) (item *Report, err error) {
  156. o := orm.NewOrmUsingDB("rddp")
  157. sql := `SELECT * FROM report WHERE id=?`
  158. err = o.Raw(sql, reportId).QueryRow(&item)
  159. return
  160. }
  161. func GetReportStage(classifyIdFirst, classifyIdSecond int) (count int, err error) {
  162. o := orm.NewOrmUsingDB("rddp")
  163. sql := ``
  164. if classifyIdSecond > 0 {
  165. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_second=? "
  166. o.Raw(sql, classifyIdSecond).QueryRow(&count)
  167. } else {
  168. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first=? "
  169. o.Raw(sql, classifyIdFirst).QueryRow(&count)
  170. }
  171. return
  172. }
  173. func GetReportStageEdit(classifyIdFirst, classifyIdSecond, reportId int) (count int, err error) {
  174. o := orm.NewOrmUsingDB("rddp")
  175. sql := ``
  176. if classifyIdSecond > 0 {
  177. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_second=? AND id<>? "
  178. o.Raw(sql, classifyIdSecond, reportId).QueryRow(&count)
  179. } else {
  180. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first=? AND id<>? "
  181. o.Raw(sql, classifyIdFirst, reportId).QueryRow(&count)
  182. }
  183. return
  184. }
  185. type PublishReq struct {
  186. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  187. State int `description:"状态:1-未提交 2-待审核 3-驳回 4-审核"`
  188. }
  189. type PublishCancelReq struct {
  190. ReportIds int `description:"报告id"`
  191. }
  192. type DeleteReq struct {
  193. ReportIds int `description:"报告id"`
  194. }
  195. type AddReq struct {
  196. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  197. ClassifyIdFirst int `description:"一级分类id"`
  198. ClassifyNameFirst string `description:"一级分类名称"`
  199. ClassifyIdSecond int `description:"二级分类id"`
  200. ClassifyNameSecond string `description:"二级分类名称"`
  201. Title string `description:"标题"`
  202. Abstract string `description:"摘要"`
  203. Author string `description:"作者"`
  204. Frequency string `description:"频度"`
  205. State int `description:"状态:1:未发布,2:已发布"`
  206. Content string `description:"内容"`
  207. CreateTime string `description:"创建时间"`
  208. ReportVersion int `description:"1:旧版,2:新版"`
  209. }
  210. type PrePublishReq struct {
  211. ReportId int `description:"报告id"`
  212. PrePublishTime string `description:"预发布时间"`
  213. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  214. }
  215. type AddResp struct {
  216. ReportId int64 `description:"报告id"`
  217. ReportCode string `description:"报告code"`
  218. }
  219. func AddReport(item *Report) (lastId int64, err error) {
  220. o := orm.NewOrmUsingDB("rddp")
  221. lastId, err = o.Insert(item)
  222. return
  223. }
  224. type EditReq struct {
  225. ReportId int64 `description:"报告id"`
  226. ClassifyIdFirst int `description:"一级分类id"`
  227. ClassifyNameFirst string `description:"一级分类名称"`
  228. ClassifyIdSecond int `description:"二级分类id"`
  229. ClassifyNameSecond string `description:"二级分类名称"`
  230. Title string `description:"标题"`
  231. Abstract string `description:"摘要"`
  232. Author string `description:"作者"`
  233. Frequency string `description:"频度"`
  234. State int `description:"状态:1:未发布,2:已发布"`
  235. Content string `description:"内容"`
  236. CreateTime string `description:"创建时间"`
  237. }
  238. type EditResp struct {
  239. ReportId int64 `description:"报告id"`
  240. ReportCode string `description:"报告code"`
  241. }
  242. func EditReport(item *Report, reportId int64) (err error) {
  243. o := orm.NewOrmUsingDB("rddp")
  244. sql := `UPDATE report
  245. SET
  246. classify_id_first =?,
  247. classify_name_first = ?,
  248. classify_id_second = ?,
  249. classify_name_second = ?,
  250. title = ?,
  251. abstract = ?,
  252. author = ?,
  253. frequency = ?,
  254. state = ?,
  255. content = ?,
  256. content_sub = ?,
  257. stage =?,
  258. create_time = ?,
  259. modify_time = ?
  260. WHERE id = ? `
  261. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  262. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Exec()
  263. return
  264. }
  265. type ReportDetailReq struct {
  266. ReportId int `description:"报告id"`
  267. }
  268. type ClassifyIdDetailReq struct {
  269. ClassifyIdFirst int `description:"报告一级分类id"`
  270. ClassifyIdSecond int `description:"报告二级分类id"`
  271. }
  272. type SendTemplateMsgReq struct {
  273. ReportId int `description:"报告id"`
  274. }
  275. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  276. o := orm.NewOrmUsingDB("rddp")
  277. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  278. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  279. return
  280. }
  281. func EditReportContent(reportId int, content, contentSub string) (err error) {
  282. o := orm.NewOrmUsingDB("rddp")
  283. sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  284. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  285. return
  286. }
  287. func AddReportSaveLog(reportId, adminId int, content, contentSub, adminName string) (err error) {
  288. o := orm.NewOrmUsingDB("rddp")
  289. sql := ` INSERT INTO report_save_log(report_id, content,content_sub,admin_id,admin_name) VALUES (?,?,?,?,?) `
  290. _, err = o.Raw(sql, reportId, content, contentSub, adminId, adminName).Exec()
  291. return
  292. }
  293. type SaveReportContentResp struct {
  294. ReportId int `description:"报告id"`
  295. }
  296. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  297. o := orm.NewOrmUsingDB("rddp")
  298. sql := `UPDATE report SET report_code=? WHERE id=? `
  299. _, err = o.Raw(sql, reportCode, reportId).Exec()
  300. return
  301. }
  302. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  303. o := orm.NewOrmUsingDB("rddp")
  304. if item.ThsMsgIsSend == 0 {
  305. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  306. _, err = o.Raw(sql, item.Id).Exec()
  307. }
  308. return
  309. }
  310. // GetDayWeekReportStage 获取晨报周报期数
  311. func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int, err error) {
  312. o := orm.NewOrmUsingDB("rddp")
  313. sql := " SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first = ? AND create_time > ? "
  314. o.Raw(sql, classifyIdFirst, yearStart).QueryRow(&count)
  315. return
  316. }
  317. // GetReportByReportId 主键获取报告
  318. func GetReportByReportId(reportId int) (item *Report, err error) {
  319. o := orm.NewOrmUsingDB("rddp")
  320. sql := `SELECT * FROM report WHERE id = ?`
  321. err = o.Raw(sql, reportId).QueryRow(&item)
  322. return
  323. }
  324. // 发布报告
  325. func PublishReportById(reportId, state int, publishTime time.Time) (err error) {
  326. o := orm.NewOrmUsingDB("rddp")
  327. sql := `UPDATE report SET state = ?, publish_time = ?, pre_publish_time = null, pre_msg_send=0, modify_time = NOW() WHERE id = ? `
  328. _, err = o.Raw(sql, state, publishTime, reportId).Exec()
  329. return
  330. }
  331. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  332. o := orm.NewOrmUsingDB("rddp")
  333. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  334. _, err = o.Raw(sql1, reportId).Exec()
  335. if err != nil {
  336. return
  337. }
  338. //修改音频标题
  339. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  340. _, err = o.Raw(sql2, reportId).Exec()
  341. return
  342. }
  343. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  344. o := orm.NewOrmUsingDB("rddp")
  345. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  346. _, err = o.Raw(sql1, reportId).Exec()
  347. if err != nil {
  348. return
  349. }
  350. //修改音频标题
  351. 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)`
  352. _, err = o.Raw(sql2, reportId).Exec()
  353. return
  354. }
  355. // GetReportByCondition 获取报告
  356. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  357. o := orm.NewOrmUsingDB("rddp")
  358. fields := `*`
  359. if len(fieldArr) > 0 {
  360. fields = strings.Join(fieldArr, ",")
  361. }
  362. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  363. sql += condition
  364. order := ` ORDER BY modify_time DESC`
  365. if orderRule != `` {
  366. order = orderRule
  367. }
  368. sql += order
  369. if isPage {
  370. sql += ` LIMIT ?,?`
  371. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  372. } else {
  373. _, err = o.Raw(sql, pars).QueryRows(&items)
  374. }
  375. return
  376. }
  377. type ElasticReportDetail struct {
  378. ReportId int `description:"报告ID"`
  379. ReportChapterId int `description:"报告章节ID"`
  380. Title string `description:"标题"`
  381. Abstract string `description:"摘要"`
  382. BodyContent string `description:"内容"`
  383. PublishTime string `description:"发布时间"`
  384. PublishState int `description:"状态:1-未提交 2-待审核 3-驳回 4-审核"`
  385. Author string `description:"作者"`
  386. ClassifyIdFirst int `description:"一级分类ID"`
  387. ClassifyNameFirst string `description:"一级分类名称"`
  388. ClassifyIdSecond int `description:"二级分类ID"`
  389. ClassifyNameSecond string `description:"二级分类名称"`
  390. Categories string `description:"关联的品种名称(包括品种别名)"`
  391. StageStr string `description:"报告期数"`
  392. }
  393. type ReportItem struct {
  394. Id int `description:"报告Id"`
  395. ReportCode string `description:"报告唯一编码"`
  396. ClassifyIdFirst int `description:"一级分类id"`
  397. ClassifyNameFirst string `description:"一级分类名称"`
  398. ClassifyIdSecond int `description:"二级分类id"`
  399. ClassifyNameSecond string `description:"二级分类名称"`
  400. Title string `description:"标题"`
  401. Abstract string `description:"摘要"`
  402. Author string `description:"作者"`
  403. Frequency string `description:"频度"`
  404. State int `description:"状态:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  405. Stage int `description:"期数"`
  406. Content string `description:"内容"`
  407. VideoUrl string `description:"音频文件URL"`
  408. VideoName string `description:"音频文件名称"`
  409. VideoPlaySeconds string `description:"音频播放时长"`
  410. VideoSize string `description:"音频文件大小,单位M"`
  411. AdminId int `description:"创建者账号"`
  412. AdminRealName string `description:"创建者姓名"`
  413. PublishTime string `description:"发布时间"`
  414. ApproveTime string `description:"审批时间"`
  415. CreateTime string `description:"创建时间"`
  416. ModifyTime string `description:"修改时间"`
  417. }
  418. func FormatReport2Item(origin *Report) (item *ReportItem) {
  419. if origin == nil {
  420. return
  421. }
  422. item = new(ReportItem)
  423. item.Id = origin.Id
  424. item.ReportCode = origin.ReportCode
  425. item.ClassifyIdFirst = origin.ClassifyIdFirst
  426. item.ClassifyNameFirst = origin.ClassifyNameFirst
  427. item.ClassifyIdSecond = origin.ClassifyIdSecond
  428. item.ClassifyNameSecond = origin.ClassifyNameSecond
  429. item.Title = origin.Title
  430. item.Abstract = origin.Abstract
  431. item.Author = origin.Author
  432. item.Frequency = origin.Frequency
  433. item.State = origin.State
  434. item.Stage = origin.Stage
  435. item.Content = html.UnescapeString(origin.Content)
  436. item.VideoUrl = origin.VideoUrl
  437. item.VideoName = origin.VideoName
  438. item.VideoPlaySeconds = origin.VideoPlaySeconds
  439. item.VideoSize = origin.VideoSize
  440. item.AdminId = origin.AdminId
  441. item.AdminRealName = origin.AdminRealName
  442. item.PublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PublishTime)
  443. item.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, origin.ApproveTime)
  444. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  445. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  446. return
  447. }
  448. // ReportApproveReq 报告审批请求体
  449. type ReportApproveReq struct {
  450. ReportId int `description:"报告ID"`
  451. Pass bool `description:"是否通过审批"`
  452. }
  453. // UpdateReport 更新报告
  454. func (m *Report) UpdateReport(cols []string) (err error) {
  455. o := orm.NewOrmUsingDB("rddp")
  456. _, err = o.Update(m, cols...)
  457. return
  458. }