report.go 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  1. package models
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "strings"
  7. "time"
  8. )
  9. // 报告状态
  10. const (
  11. ReportStateUnpublished = 1 // 未发布
  12. ReportStatePublished = 2 // 已发布
  13. ReportStateWaitSubmit = 3 // 待提交
  14. ReportStateWaitApprove = 4 // 审批中
  15. ReportStateRefused = 5 // 已驳回
  16. ReportStatePass = 6 // 已通过
  17. )
  18. // 报告操作
  19. const (
  20. ReportOperateAdd = 1 // 新增报告
  21. ReportOperateEdit = 2 // 编辑报告
  22. ReportOperatePublish = 3 // 发布报告
  23. ReportOperateCancelPublish = 4 // 取消发布报告
  24. ReportOperateSubmitApprove = 5 // 提交审批
  25. ReportOperateCancelApprove = 6 // 撤回审批
  26. )
  27. type Report struct {
  28. Id int `orm:"column(id)" description:"报告Id"`
  29. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  30. ClassifyIdFirst int `description:"一级分类id"`
  31. ClassifyNameFirst string `description:"一级分类名称"`
  32. ClassifyIdSecond int `description:"二级分类id"`
  33. ClassifyNameSecond string `description:"二级分类名称"`
  34. Title string `description:"标题"`
  35. Abstract string `description:"摘要"`
  36. Author string `description:"作者"`
  37. Frequency string `description:"频度"`
  38. CreateTime string `description:"创建时间"`
  39. ModifyTime time.Time `description:"修改时间"`
  40. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  41. PublishTime time.Time `description:"发布时间"`
  42. Stage int `description:"期数"`
  43. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  44. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  45. Content string `description:"内容"`
  46. VideoUrl string `description:"音频文件URL"`
  47. VideoName string `description:"音频文件名称"`
  48. VideoPlaySeconds string `description:"音频播放时长"`
  49. VideoSize string `description:"音频文件大小,单位M"`
  50. ContentSub string `description:"内容前两个章节"`
  51. ReportCode string `description:"报告唯一编码"`
  52. ReportVersion int `description:"1:旧版,2:新版"`
  53. HasChapter int `description:"是否有章节 0-否 1-是"`
  54. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  55. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  56. MsgSendTime time.Time `description:"模版消息发送时间"`
  57. AdminId int `description:"创建者账号"`
  58. AdminRealName string `description:"创建者姓名"`
  59. ApproveTime time.Time `description:"审批时间"`
  60. ApproveId int `description:"审批ID"`
  61. }
  62. type ReportList struct {
  63. Id int `description:"报告Id"`
  64. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  65. ClassifyIdFirst int `description:"一级分类id"`
  66. ClassifyNameFirst string `description:"一级分类名称"`
  67. ClassifyIdSecond int `description:"二级分类id"`
  68. ClassifyNameSecond string `description:"二级分类名称"`
  69. Title string `description:"标题"`
  70. Abstract string `description:"摘要"`
  71. Author string `description:"作者"`
  72. Frequency string `description:"频度"`
  73. CreateTime string `description:"创建时间"`
  74. ModifyTime time.Time `description:"修改时间"`
  75. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  76. PublishTime string `description:"发布时间"`
  77. PrePublishTime string `description:"预发布时间"`
  78. Stage int `description:"期数"`
  79. MsgIsSend int `description:"模板消息是否已发送,0:否,1:是"`
  80. Content string `description:"内容"`
  81. VideoUrl string `description:"音频文件URL"`
  82. VideoName string `description:"音频文件名称"`
  83. VideoPlaySeconds string `description:"音频播放时长"`
  84. ContentSub string `description:"内容前两个章节"`
  85. Pv int `description:"Pv"`
  86. Uv int `description:"Uv"`
  87. ReportCode string `description:"报告唯一编码"`
  88. ReportVersion int `description:"1:旧版,2:新版"`
  89. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  90. NeedThsMsg int `description:"是否需要推送客群消息 0-否 1-是"`
  91. HasChapter int `description:"是否有章节 0-否 1-是"`
  92. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  93. ChapterVideoList []*ReportChapterVideoList `description:"章节音频列表"`
  94. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  95. MsgSendTime string `description:"模版消息发送时间"`
  96. CanEdit bool `description:"是否可编辑"`
  97. Editor string `description:"编辑人"`
  98. AdminId int `description:"创建者账号"`
  99. AdminRealName string `description:"创建者姓名"`
  100. ApproveTime string `description:"审批时间"`
  101. }
  102. type ReportListResp struct {
  103. List []*ReportList
  104. Paging *paging.PagingItem `description:"分页数据"`
  105. }
  106. func GetReportListCount(condition string, pars []interface{}, companyType string) (count int, err error) {
  107. //产品权限
  108. companyTypeSqlStr := ``
  109. if companyType == "ficc" {
  110. companyTypeSqlStr = " AND classify_id_first != 40 "
  111. } else if companyType == "权益" {
  112. companyTypeSqlStr = " AND classify_id_first = 40 "
  113. }
  114. oRddp := orm.NewOrmUsingDB("rddp")
  115. sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 ` + companyTypeSqlStr
  116. if condition != "" {
  117. sql += condition
  118. }
  119. err = oRddp.Raw(sql, pars).QueryRow(&count)
  120. return
  121. }
  122. func GetReportList(condition string, pars []interface{}, companyType string, startSize, pageSize int) (items []*ReportList, err error) {
  123. o := orm.NewOrmUsingDB("rddp")
  124. //产品权限
  125. companyTypeSqlStr := ``
  126. if companyType == "ficc" {
  127. companyTypeSqlStr = " AND classify_id_first != 40 "
  128. } else if companyType == "权益" {
  129. companyTypeSqlStr = " AND classify_id_first = 40 "
  130. }
  131. sql := `SELECT *,
  132. (SELECT COUNT(1) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS pv,
  133. (SELECT COUNT(DISTINCT user_id) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS uv
  134. FROM report WHERE 1=1 ` + companyTypeSqlStr
  135. if condition != "" {
  136. sql += condition
  137. }
  138. sql += `ORDER BY FIELD(state,3,1,2,4), modify_time DESC LIMIT ?,?`
  139. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  140. return
  141. }
  142. // PublishReport 发布报告
  143. func PublishReport(reportIds []int) (err error) {
  144. if len(reportIds) == 0 {
  145. return
  146. }
  147. o := orm.NewOrmUsingDB("rddp")
  148. sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  149. _, err = o.Raw(sql).Exec()
  150. return
  151. }
  152. // PublishCancleReport 取消发布报告
  153. func PublishCancleReport(reportIds int, publishTimeNullFlag bool) (err error) {
  154. o := orm.NewOrmUsingDB("rddp")
  155. var sql string
  156. if publishTimeNullFlag {
  157. sql = ` UPDATE report SET state=1, publish_time=null, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
  158. } else {
  159. sql = ` UPDATE report SET state=1, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
  160. }
  161. _, err = o.Raw(sql, reportIds).Exec()
  162. return
  163. }
  164. // 删除报告
  165. func DeleteReport(reportIds int) (err error) {
  166. o := orm.NewOrmUsingDB("rddp")
  167. sql := ` DELETE FROM report WHERE id =? `
  168. _, err = o.Raw(sql, reportIds).Exec()
  169. return
  170. }
  171. type ReportDetail struct {
  172. Id int `orm:"column(id)" description:"报告Id"`
  173. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  174. ClassifyIdFirst int `description:"一级分类id"`
  175. ClassifyNameFirst string `description:"一级分类名称"`
  176. ClassifyIdSecond int `description:"二级分类id"`
  177. ClassifyNameSecond string `description:"二级分类名称"`
  178. Title string `description:"标题"`
  179. Abstract string `description:"摘要"`
  180. Author string `description:"作者"`
  181. Frequency string `description:"频度"`
  182. CreateTime string `description:"创建时间"`
  183. ModifyTime string `description:"修改时间"`
  184. State int `description:"1:未发布,2:已发布"`
  185. PublishTime string `description:"发布时间"`
  186. PrePublishTime string `description:"预发布时间"`
  187. Stage int `description:"期数"`
  188. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  189. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  190. Content string `description:"内容"`
  191. VideoUrl string `description:"音频文件URL"`
  192. VideoName string `description:"音频文件名称"`
  193. VideoPlaySeconds string `description:"音频播放时长"`
  194. ContentSub string `description:"内容前两个章节"`
  195. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  196. HasChapter int `description:"是否有章节 0-否 1-是"`
  197. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  198. }
  199. func GetReportById(reportId int) (item *ReportDetail, err error) {
  200. o := orm.NewOrmUsingDB("rddp")
  201. sql := `SELECT * FROM report WHERE id=?`
  202. err = o.Raw(sql, reportId).QueryRow(&item)
  203. return
  204. }
  205. func GetReportByIds(reportIds string) (list []*ReportDetail, err error) {
  206. o := orm.NewOrmUsingDB("rddp")
  207. sql := `SELECT * FROM report WHERE id in ` + reportIds
  208. _, err = o.Raw(sql).QueryRows(&list)
  209. return
  210. }
  211. // GetSimpleReportByIds 根据报告ID查询报告基本信息
  212. func GetSimpleReportByIds(reportIds []int) (list []*ReportDetail, err error) {
  213. if len(reportIds) == 0 {
  214. return
  215. }
  216. o := orm.NewOrmUsingDB("rddp")
  217. sql := `SELECT id, title FROM report WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  218. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  219. return
  220. }
  221. func GetReportStage(classifyIdFirst, classifyIdSecond int) (count int, err error) {
  222. o := orm.NewOrmUsingDB("rddp")
  223. sql := ``
  224. if classifyIdSecond > 0 {
  225. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_second=? "
  226. o.Raw(sql, classifyIdSecond).QueryRow(&count)
  227. } else {
  228. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first=? "
  229. o.Raw(sql, classifyIdFirst).QueryRow(&count)
  230. }
  231. return
  232. }
  233. func GetReportStageEdit(classifyIdFirst, classifyIdSecond, reportId int) (count int, err error) {
  234. o := orm.NewOrmUsingDB("rddp")
  235. sql := ``
  236. if classifyIdSecond > 0 {
  237. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_second=? AND id<>? "
  238. o.Raw(sql, classifyIdSecond, reportId).QueryRow(&count)
  239. } else {
  240. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first=? AND id<>? "
  241. o.Raw(sql, classifyIdFirst, reportId).QueryRow(&count)
  242. }
  243. return
  244. }
  245. type PublishReq struct {
  246. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  247. }
  248. type PublishCancelReq struct {
  249. ReportIds int `description:"报告id"`
  250. }
  251. type DeleteReq struct {
  252. ReportIds int `description:"报告id"`
  253. }
  254. type AddReq struct {
  255. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  256. ClassifyIdFirst int `description:"一级分类id"`
  257. ClassifyNameFirst string `description:"一级分类名称"`
  258. ClassifyIdSecond int `description:"二级分类id"`
  259. ClassifyNameSecond string `description:"二级分类名称"`
  260. Title string `description:"标题"`
  261. Abstract string `description:"摘要"`
  262. Author string `description:"作者"`
  263. Frequency string `description:"频度"`
  264. State int `description:"状态:1:未发布,2:已发布"`
  265. Content string `description:"内容"`
  266. CreateTime string `description:"创建时间"`
  267. ReportVersion int `description:"1:旧版,2:新版"`
  268. }
  269. type PrePublishReq struct {
  270. ReportId int `description:"报告id"`
  271. PrePublishTime string `description:"预发布时间"`
  272. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  273. }
  274. type AddResp struct {
  275. ReportId int64 `description:"报告id"`
  276. ReportCode string `description:"报告code"`
  277. }
  278. func AddReport(item *Report) (lastId int64, err error) {
  279. o := orm.NewOrmUsingDB("rddp")
  280. lastId, err = o.Insert(item)
  281. return
  282. }
  283. type EditReq struct {
  284. ReportId int64 `description:"报告id"`
  285. ClassifyIdFirst int `description:"一级分类id"`
  286. ClassifyNameFirst string `description:"一级分类名称"`
  287. ClassifyIdSecond int `description:"二级分类id"`
  288. ClassifyNameSecond string `description:"二级分类名称"`
  289. Title string `description:"标题"`
  290. Abstract string `description:"摘要"`
  291. Author string `description:"作者"`
  292. Frequency string `description:"频度"`
  293. State int `description:"状态:1:未发布,2:已发布"`
  294. Content string `description:"内容"`
  295. CreateTime string `description:"创建时间"`
  296. }
  297. type EditResp struct {
  298. ReportId int64 `description:"报告id"`
  299. ReportCode string `description:"报告code"`
  300. }
  301. func EditReport(item *Report, reportId int64) (err error) {
  302. o := orm.NewOrmUsingDB("rddp")
  303. sql := `UPDATE report
  304. SET
  305. classify_id_first =?,
  306. classify_name_first = ?,
  307. classify_id_second = ?,
  308. classify_name_second = ?,
  309. title = ?,
  310. abstract = ?,
  311. author = ?,
  312. frequency = ?,
  313. state = ?,
  314. content = ?,
  315. content_sub = ?,
  316. stage =?,
  317. create_time = ?,
  318. modify_time = ?
  319. WHERE id = ? `
  320. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  321. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Exec()
  322. return
  323. }
  324. type ReportDetailReq struct {
  325. ReportId int `description:"报告id"`
  326. }
  327. type ClassifyIdDetailReq struct {
  328. ClassifyIdFirst int `description:"报告一级分类id"`
  329. ClassifyIdSecond int `description:"报告二级分类id"`
  330. }
  331. func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) {
  332. o := orm.NewOrmUsingDB("rddp")
  333. sql := ` SELECT * FROM report WHERE 1=1 `
  334. if classifyIdSecond > 0 {
  335. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  336. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  337. } else {
  338. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  339. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  340. }
  341. return
  342. }
  343. type SendTemplateMsgReq struct {
  344. ReportId int `description:"报告id"`
  345. }
  346. func ModifyReportMsgIsSend(reportId int) (err error) {
  347. o := orm.NewOrmUsingDB("rddp")
  348. report, err := GetReportById(reportId)
  349. if err != nil {
  350. return
  351. }
  352. if report.MsgIsSend == 0 {
  353. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? `
  354. _, err = o.Raw(sql, reportId).Exec()
  355. }
  356. return
  357. }
  358. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  359. o := orm.NewOrmUsingDB("rddp")
  360. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  361. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  362. return
  363. }
  364. type ReportItem struct {
  365. Id int `orm:"column(id)" description:"报告Id"`
  366. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  367. ClassifyIdFirst int `description:"一级分类id"`
  368. ClassifyNameFirst string `description:"一级分类名称"`
  369. ClassifyIdSecond int `description:"二级分类id"`
  370. ClassifyNameSecond string `description:"二级分类名称"`
  371. Title string `description:"标题"`
  372. Abstract string `description:"摘要"`
  373. Author string `description:"作者"`
  374. Frequency string `description:"频度"`
  375. CreateTime time.Time `description:"创建时间"`
  376. ModifyTime time.Time `description:"修改时间"`
  377. State int `description:"1:未发布,2:已发布"`
  378. PublishTime time.Time `description:"发布时间"`
  379. Stage int `description:"期数"`
  380. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  381. Content string `description:"内容"`
  382. VideoUrl string `description:"音频文件URL"`
  383. VideoName string `description:"音频文件名称"`
  384. VideoPlaySeconds string `description:"音频播放时长"`
  385. ContentSub string `description:"内容前两个章节"`
  386. }
  387. func GetReportItemById(reportId int) (item *ReportItem, err error) {
  388. o := orm.NewOrmUsingDB("rddp")
  389. sql := `SELECT * FROM report WHERE id=?`
  390. err = o.Raw(sql, reportId).QueryRow(&item)
  391. return
  392. }
  393. type SaveReportContent struct {
  394. Content string `description:"内容"`
  395. ReportId int `description:"报告id"`
  396. NoChange int `description:"内容是否未改变:1:内容未改变"`
  397. }
  398. func EditReportContent(reportId int, content, contentSub string) (err error) {
  399. o := orm.NewOrmUsingDB("rddp")
  400. sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  401. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  402. return
  403. }
  404. func AddReportSaveLog(reportId, adminId int, content, contentSub, adminName string) (err error) {
  405. o := orm.NewOrmUsingDB("rddp")
  406. sql := ` INSERT INTO report_save_log(report_id, content,content_sub,admin_id,admin_name) VALUES (?,?,?,?,?) `
  407. _, err = o.Raw(sql, reportId, content, contentSub, adminId, adminName).Exec()
  408. return
  409. }
  410. func MultiAddReportChaptersSaveLog(items []*ReportChapter, adminId int, adminRealName string) (err error) {
  411. o := orm.NewOrmUsingDB("rddp")
  412. p, err := o.Raw(`INSERT INTO report_save_log(report_id, report_chapter_id, content, content_sub, admin_id, admin_name) VALUES (?,?,?,?,?,?)`).Prepare()
  413. if err != nil {
  414. return
  415. }
  416. defer func() {
  417. _ = p.Close()
  418. }()
  419. for _, v := range items {
  420. _, err = p.Exec(v.ReportId, v.ReportChapterId, v.Content, v.ContentSub, adminId, adminRealName)
  421. if err != nil {
  422. return
  423. }
  424. }
  425. return
  426. }
  427. type SaveReportContentResp struct {
  428. ReportId int `description:"报告id"`
  429. }
  430. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  431. o := orm.NewOrmUsingDB("rddp")
  432. sql := `UPDATE report SET report_code=? WHERE id=? `
  433. _, err = o.Raw(sql, reportCode, reportId).Exec()
  434. return
  435. }
  436. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  437. o := orm.NewOrmUsingDB("rddp")
  438. if item.ThsMsgIsSend == 0 {
  439. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  440. _, err = o.Raw(sql, item.Id).Exec()
  441. }
  442. return
  443. }
  444. type ThsSendTemplateMsgReq struct {
  445. ReportId []int `description:"报告id"`
  446. }
  447. type PublishDayWeekReportReq struct {
  448. ReportId int `description:"报告ID"`
  449. }
  450. // SaveDayWeekReportReq 新增晨报周报请求体
  451. type SaveDayWeekReportReq struct {
  452. ReportId int `description:"报告ID"`
  453. Title string `description:"标题"`
  454. ReportType string `description:"一级分类ID"`
  455. Author string `description:"作者"`
  456. CreateTime string `description:"创建时间"`
  457. }
  458. // GetDayWeekReportStage 获取晨报周报期数
  459. func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int, err error) {
  460. o := orm.NewOrmUsingDB("rddp")
  461. sql := " SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first = ? AND create_time > ? "
  462. o.Raw(sql, classifyIdFirst, yearStart).QueryRow(&count)
  463. return
  464. }
  465. // AddReportAndChapter 新增报告及章节
  466. func AddReportAndChapter(reportItem *Report, chapterItemList []*ReportChapter) (reportId int64, err error) {
  467. o := orm.NewOrmUsingDB("rddp")
  468. to, err := o.Begin()
  469. if err != nil {
  470. return
  471. }
  472. defer func() {
  473. if err != nil {
  474. _ = to.Rollback()
  475. } else {
  476. _ = to.Commit()
  477. }
  478. }()
  479. if reportId, err = to.Insert(reportItem); err != nil {
  480. return
  481. }
  482. if len(chapterItemList) > 0 {
  483. for _, chapterItem := range chapterItemList {
  484. chapterItem.ReportId = int(reportId)
  485. cpId, tmpErr := to.Insert(chapterItem)
  486. if tmpErr != nil {
  487. return
  488. }
  489. chapterItem.ReportChapterId = int(cpId)
  490. }
  491. }
  492. return
  493. }
  494. // GetReportByReportId 主键获取报告
  495. func GetReportByReportId(reportId int) (item *Report, err error) {
  496. o := orm.NewOrmUsingDB("rddp")
  497. sql := `SELECT * FROM report WHERE id = ?`
  498. err = o.Raw(sql, reportId).QueryRow(&item)
  499. return
  500. }
  501. // GetReportByOldReportId 根据老报告id主键获取报告
  502. func GetReportByOldReportId(reportId int) (item *Report, err error) {
  503. o := orm.NewOrmUsingDB("rddp")
  504. sql := `SELECT * FROM report WHERE old_report_id = ?`
  505. err = o.Raw(sql, reportId).QueryRow(&item)
  506. return
  507. }
  508. // DeleteDayWeekReportAndChapter 删除晨周报及章节
  509. func DeleteDayWeekReportAndChapter(reportId int) (err error) {
  510. o := orm.NewOrmUsingDB("rddp")
  511. to, err := o.Begin()
  512. if err != nil {
  513. return
  514. }
  515. defer func() {
  516. if err != nil {
  517. _ = to.Rollback()
  518. } else {
  519. _ = to.Commit()
  520. }
  521. }()
  522. sql := ` DELETE FROM report WHERE id = ? LIMIT 1 `
  523. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  524. return
  525. }
  526. sql = ` DELETE FROM report_chapter WHERE report_id = ? `
  527. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  528. return
  529. }
  530. return
  531. }
  532. // UpdateReport 更新报告
  533. func (reportInfo *Report) UpdateReport(cols []string) (err error) {
  534. o := orm.NewOrmUsingDB("rddp")
  535. _, err = o.Update(reportInfo, cols...)
  536. return
  537. }
  538. // 晨周报详情
  539. type ReportDetailView struct {
  540. *ReportDetail
  541. ChapterList []*ReportChapter
  542. }
  543. func GetUnPublishDayReport(startTime time.Time, endTime time.Time) (item *Report, err error) {
  544. o := orm.NewOrmUsingDB("rddp")
  545. sql := ` SELECT
  546. *
  547. FROM
  548. report AS a
  549. WHERE
  550. a.has_chapter = 1
  551. AND a.chapter_type = "day"
  552. AND a.state = 1
  553. AND (
  554. a.create_time BETWEEN ? AND ?
  555. )
  556. ORDER BY
  557. a.create_time DESC
  558. LIMIT 1 `
  559. err = o.Raw(sql, startTime, endTime).QueryRow(&item)
  560. return
  561. }
  562. type ElasticReportDetail struct {
  563. ReportId int `description:"报告ID"`
  564. ReportChapterId int `description:"报告章节ID"`
  565. Title string `description:"标题"`
  566. Abstract string `description:"摘要"`
  567. BodyContent string `description:"内容"`
  568. PublishTime string `description:"发布时间"`
  569. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  570. Author string `description:"作者"`
  571. ClassifyIdFirst int `description:"一级分类ID"`
  572. ClassifyNameFirst string `description:"一级分类名称"`
  573. ClassifyIdSecond int `description:"二级分类ID"`
  574. ClassifyNameSecond string `description:"二级分类名称"`
  575. Categories string `description:"关联的品种名称(包括品种别名)"`
  576. StageStr string `description:"报告期数"`
  577. }
  578. // GetLastPublishedDayWeekReport 获取上一篇已发布的晨周报
  579. func GetLastPublishDayWeekReport(chapterType string) (item *Report, err error) {
  580. o := orm.NewOrmUsingDB("rddp")
  581. sql := ` SELECT * FROM report WHERE has_chapter = 1 AND chapter_type = ? AND state = 2 ORDER BY publish_time DESC LIMIT 1 `
  582. err = o.Raw(sql, chapterType).QueryRow(&item)
  583. return
  584. }
  585. // GetNewReportExist
  586. func GetNewReportExist(oldReportId int) (item *Report, err error) {
  587. o := orm.NewOrmUsingDB("rddp")
  588. sql := ` SELECT id FROM report WHERE old_report_id = ? LIMIT 1 `
  589. err = o.Raw(sql, oldReportId).QueryRow(&item)
  590. return
  591. }
  592. // PublishReportAndChapter 发布报告及章节
  593. func PublishReportAndChapter(reportInfo *Report, publishIds, unPublishIds []int, isPublishReport bool, cols []string) (err error) {
  594. o := orm.NewOrmUsingDB("rddp")
  595. to, err := o.Begin()
  596. if err != nil {
  597. return
  598. }
  599. defer func() {
  600. if err != nil {
  601. _ = to.Rollback()
  602. } else {
  603. _ = to.Commit()
  604. }
  605. }()
  606. // 更新报告
  607. if isPublishReport {
  608. if _, err = to.Update(reportInfo, cols...); err != nil {
  609. return
  610. }
  611. }
  612. // 发布章节
  613. if len(publishIds) > 0 {
  614. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  615. _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
  616. }
  617. if len(unPublishIds) > 0 {
  618. 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)) + `) `
  619. _, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
  620. }
  621. return
  622. }
  623. func GetSyncEmptyVideoReport() (list []*Report, err error) {
  624. o := orm.NewOrmUsingDB("rddp")
  625. sql := ` SELECT id FROM report WHERE old_report_id > 0 AND state = 2 AND chapter_type = "" AND (video_size = "" OR video_play_seconds = "")
  626. UNION ALL
  627. SELECT DISTINCT report_id FROM report_chapter WHERE publish_state = 2 AND (video_size = "" OR video_play_seconds = "") `
  628. _, err = o.Raw(sql).QueryRows(&list)
  629. return
  630. }
  631. // 发布报告
  632. func PublishReportById(reportId int, publishTime time.Time) (err error) {
  633. o := orm.NewOrmUsingDB("rddp")
  634. sql := `UPDATE report SET state = 2, publish_time = ?, pre_publish_time=null, pre_msg_send=0, modify_time = NOW() WHERE id = ? `
  635. _, err = o.Raw(sql, publishTime, reportId).Exec()
  636. return
  637. }
  638. // GetCommentReportByReportId 查询有留言的报告列表
  639. func GetCommentReportByReportId(condition string, pars []interface{}, startSize, pageSize int) (list []*Report, err error) {
  640. o := orm.NewOrmUsingDB("rddp")
  641. sql := `SELECT
  642. id,
  643. create_time,
  644. title,
  645. classify_name_first,
  646. classify_id_first,
  647. classify_name_second,
  648. classify_id_second,
  649. state,
  650. IF
  651. ( publish_time, publish_time, create_time ) AS publish_time
  652. FROM
  653. report
  654. WHERE
  655. 1=1
  656. `
  657. if condition != "" {
  658. sql += condition
  659. }
  660. sql += ` ORDER BY publish_time DESC , title ASC LIMIT ?,?`
  661. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  662. return
  663. }
  664. // GetCommentReportByReportIdOrderBy 查询有留言的报告列表(指定排序)
  665. func GetCommentReportByReportIdOrderBy(condition string, pars []interface{}, startSize, pageSize int, orderBy string) (list []*Report, err error) {
  666. o := orm.NewOrmUsingDB("rddp")
  667. sql := `SELECT
  668. id,
  669. create_time,
  670. title,
  671. classify_name_first,
  672. classify_id_first,
  673. classify_name_second,
  674. classify_id_second,
  675. state,
  676. IF
  677. ( publish_time, publish_time, create_time ) AS publish_time
  678. FROM
  679. report
  680. WHERE
  681. 1=1
  682. `
  683. if condition != "" {
  684. sql += condition
  685. }
  686. if orderBy == `` {
  687. sql += ` ORDER BY publish_time DESC , title ASC `
  688. } else {
  689. sql += orderBy
  690. }
  691. sql += ` LIMIT ?,? `
  692. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  693. return
  694. }
  695. // GetCommentReportTotalByReportId 查询有留言的报告列表总数
  696. func GetCommentReportTotalByReportId(condition string, pars []interface{}) (total int64, err error) {
  697. o := orm.NewOrmUsingDB("rddp")
  698. sql := `SELECT count(*)
  699. FROM report WHERE 1=1`
  700. if condition != "" {
  701. sql += condition
  702. }
  703. err = o.Raw(sql, pars).QueryRow(&total)
  704. return
  705. }
  706. // 点赞相关的报告列表
  707. type LikeReportItem struct {
  708. ReportId int `description:"报告Id"`
  709. ReportChapterId int `description:"报告章节Id"`
  710. ClassifyIdFirst int `description:"一级分类id"`
  711. ClassifyNameFirst string `description:"一级分类名称"`
  712. ClassifyIdSecond int `description:"二级分类id"`
  713. ClassifyNameSecond string `description:"二级分类名称"`
  714. ReportChapterTypeId int `description:"章节类型"`
  715. ReportChapterTypeName string `description:"品种名称"`
  716. PublishTime time.Time `description:"发布时间" `
  717. Title string `description:"标题"`
  718. }
  719. // GetLikeReportByReportIdReportChapterId 获取有被点赞的报告列表
  720. func GetLikeReportByReportIdReportChapterId(reportIds string, chapterIds string, orderStr string, startSize, pageSize int) (list []*LikeReportItem, err error) {
  721. o := orm.NewOrmUsingDB("rddp")
  722. sql := `( SELECT
  723. id AS report_id,
  724. 0 AS report_chapter_id,
  725. classify_id_first,
  726. classify_id_second,
  727. classify_name_first,
  728. classify_name_second,
  729. 0 as report_chapter_type_id,
  730. "" as report_chapter_type_name,
  731. publish_time,
  732. title
  733. FROM
  734. report
  735. WHERE
  736. classify_name_first != "晨报"
  737. AND classify_name_first != "周报"
  738. AND id in (` + reportIds + `)
  739. )
  740. UNION
  741. ( SELECT
  742. report_id,
  743. report_chapter_id,
  744. classify_id_first,
  745. 0 as classify_id_second,
  746. classify_name_first,
  747. null as classify_name_second,
  748. type_id as report_chapter_type_id,
  749. type_name as report_chapter_type_name,
  750. publish_time,
  751. title
  752. FROM
  753. report_chapter
  754. WHERE
  755. report_chapter_id in (` + chapterIds + `)
  756. )`
  757. if orderStr != "" {
  758. sql += ` ORDER BY FIELD(CONCAT(report_id, "-",report_chapter_id),` + orderStr + `)`
  759. } else {
  760. sql += ` ORDER BY publish_time DESC, report_id Desc`
  761. }
  762. sql += ` LIMIT ?,?`
  763. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  764. return
  765. }
  766. // GetLikeReportTotalByReportIdReportChapterId 获取有被点赞的报告列表总数
  767. func GetLikeReportTotalByReportIdReportChapterId(reportIds string, chapterIds string) (total int64, err error) {
  768. o := orm.NewOrmUsingDB("rddp")
  769. sql := `select count(*) from (( SELECT
  770. id AS report_id,
  771. 0 AS report_chapter_id,
  772. classify_id_first,
  773. classify_id_second,
  774. classify_name_first,
  775. classify_name_second,
  776. 0 as report_chapter_type_id,
  777. publish_time,
  778. title
  779. FROM
  780. report
  781. WHERE
  782. classify_name_first != "晨报"
  783. AND classify_name_first != "周报"
  784. AND id in (` + reportIds + `)
  785. )
  786. UNION
  787. ( SELECT
  788. report_id,
  789. report_chapter_id,
  790. classify_id_first,
  791. 0 as classify_id_second,
  792. classify_name_first,
  793. null as classify_name_second,
  794. type_id as report_chapter_type_id,
  795. publish_time,
  796. title
  797. FROM
  798. report_chapter
  799. WHERE
  800. report_chapter_id in (` + chapterIds + `)
  801. )) r`
  802. err = o.Raw(sql).QueryRow(&total)
  803. return
  804. }
  805. // GetPageReportList 分页获取报告列表
  806. func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  807. o := orm.NewOrmUsingDB("rddp")
  808. sql := `SELECT * FROM report WHERE 1=1 `
  809. sql += condition
  810. sql += ` ORDER BY modify_time DESC`
  811. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  812. err = o.Raw(totalSql, pars).QueryRow(&total)
  813. if err != nil {
  814. return
  815. }
  816. sql += ` LIMIT ?,? `
  817. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  818. return
  819. }
  820. // SunCodeReq 获取太阳码请求体
  821. type SunCodeReq struct {
  822. CodePage string `json:"CodePage" description:"太阳码page"`
  823. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  824. }
  825. // YbPcSuncode 活动海报表
  826. type YbPcSuncode struct {
  827. SuncodeID uint32 `orm:"column(suncode_id);pk" `
  828. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  829. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  830. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  831. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  832. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  833. }
  834. // GetYbPcSunCode 获取太阳码
  835. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  836. o := orm.NewOrmUsingDB("weekly")
  837. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  838. err = o.Raw(sql, scene, page).QueryRow(&item)
  839. return
  840. }
  841. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  842. o := orm.NewOrmUsingDB("weekly")
  843. _, err = o.Insert(item)
  844. return
  845. }
  846. // YbSuncodePars 小程序太阳码scene参数
  847. type YbSuncodePars struct {
  848. ID uint32 `orm:"column(id);pk" `
  849. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  850. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  851. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  852. }
  853. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  854. o := orm.NewOrmUsingDB("weekly")
  855. _, err = o.Insert(item)
  856. return
  857. }
  858. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  859. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  860. o := orm.NewOrmUsingDB("rddp")
  861. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  862. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  863. return
  864. }
  865. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  866. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  867. o := orm.NewOrmUsingDB("rddp")
  868. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  869. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  870. return
  871. }
  872. // UpdateReportSecondClassifyFirstNameByClassifyId 更新报告二级分类的一级分类名称和id
  873. func UpdateReportSecondClassifyFirstNameByClassifyId(classifyId, newClassifyId int, classifyName string) (err error) {
  874. o := orm.NewOrmUsingDB("rddp")
  875. sql := " UPDATE report SET classify_name_first = ?, classify_id_first = ? WHERE classify_id_second = ? "
  876. _, err = o.Raw(sql, classifyName, newClassifyId, classifyId).Exec()
  877. return
  878. }
  879. // GetEmptyContentSubPPTReport 获取前两章为空的PPT报告
  880. func GetEmptyContentSubPPTReport() (list []*Report, err error) {
  881. sql := `SELECT
  882. r.id,
  883. r.content,
  884. r.content_sub
  885. FROM
  886. report AS r
  887. JOIN ppt_v2 AS p ON r.id = p.report_id
  888. WHERE
  889. p.report_id > 0 AND r.content_sub = ""`
  890. _, err = orm.NewOrmUsingDB("rddp").Raw(sql).QueryRows(&list)
  891. return
  892. }
  893. // ModifyReportAuthor 更改报告作者
  894. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  895. //产品权限
  896. oRddp := orm.NewOrmUsingDB("rddp")
  897. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  898. if condition != "" {
  899. sql += condition
  900. }
  901. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  902. return
  903. }
  904. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  905. o := orm.NewOrmUsingDB("rddp")
  906. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  907. _, err = o.Raw(sql1, reportId).Exec()
  908. if err != nil {
  909. return
  910. }
  911. //修改音频标题
  912. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  913. _, err = o.Raw(sql2, reportId).Exec()
  914. return
  915. }
  916. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  917. o := orm.NewOrmUsingDB("rddp")
  918. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  919. _, err = o.Raw(sql1, reportId).Exec()
  920. if err != nil {
  921. return
  922. }
  923. //修改音频标题
  924. 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)`
  925. _, err = o.Raw(sql2, reportId).Exec()
  926. return
  927. }
  928. // MarkEditReport 标记编辑英文研报的请求数据
  929. type MarkEditReport struct {
  930. ReportId int `description:"研报id"`
  931. Status int `description:"标记状态,1:编辑中,2:编辑完成"`
  932. }
  933. type MarkReportResp struct {
  934. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  935. Msg string `description:"提示信息"`
  936. Editor string `description:"编辑者姓名"`
  937. }
  938. type MarkReportItem struct {
  939. AdminId int `description:"编辑者ID"`
  940. Editor string `description:"编辑者姓名"`
  941. ReportClassifyNameFirst string
  942. }
  943. // GetReportByCondition 获取报告
  944. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  945. o := orm.NewOrmUsingDB("rddp")
  946. fields := `*`
  947. if len(fieldArr) > 0 {
  948. fields = strings.Join(fieldArr, ",")
  949. }
  950. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  951. sql += condition
  952. order := ` ORDER BY modify_time DESC`
  953. if orderRule != `` {
  954. order = orderRule
  955. }
  956. sql += order
  957. if isPage {
  958. sql += ` LIMIT ?,?`
  959. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  960. } else {
  961. _, err = o.Raw(sql, pars).QueryRows(&items)
  962. }
  963. return
  964. }
  965. // ModifyReportMsgIsSendV2 更新报告消息状态
  966. func ModifyReportMsgIsSendV2(reportId int) (err error) {
  967. o := orm.NewOrmUsingDB("rddp")
  968. sql := `UPDATE report SET msg_is_send = 1, ths_msg_is_send = 1, msg_send_time = NOW() WHERE id = ? LIMIT 1`
  969. _, err = o.Raw(sql, reportId).Exec()
  970. return
  971. }
  972. // SetPrePublishReportById 设置定时发布
  973. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  974. o := orm.NewOrmUsingDB("rddp")
  975. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  976. _, err = o.Raw(sql, prePublishTime, preMsgSend, reportId).Exec()
  977. return
  978. }
  979. // ReportSubmitApproveReq 提交审批请求体
  980. type ReportSubmitApproveReq struct {
  981. ReportId int `description:"报告ID"`
  982. }
  983. // ReportCancelApproveReq 撤回审批请求体
  984. type ReportCancelApproveReq struct {
  985. ReportId int `description:"报告ID"`
  986. }
  987. func (m *Report) GetItemById(id int) (item *Report, err error) {
  988. o := orm.NewOrmUsingDB("rddp")
  989. sql := `SELECT * FROM report WHERE id = ? LIMIT 1`
  990. err = o.Raw(sql, id).QueryRow(&item)
  991. return
  992. }