report.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "strings"
  6. "time"
  7. )
  8. type Report struct {
  9. Id int `orm:"column(id)" description:"报告Id"`
  10. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  11. ClassifyIdFirst int `description:"一级分类id"`
  12. ClassifyNameFirst string `description:"一级分类名称"`
  13. ClassifyIdSecond int `description:"二级分类id"`
  14. ClassifyNameSecond string `description:"二级分类名称"`
  15. Title string `description:"标题"`
  16. Abstract string `description:"摘要"`
  17. Author string `description:"作者"`
  18. Frequency string `description:"频度"`
  19. CreateTime string `description:"创建时间"`
  20. ModifyTime time.Time `description:"修改时间"`
  21. State int `description:"1:未发布,2:已发布"`
  22. PublishTime time.Time `description:"发布时间"`
  23. Stage int `description:"期数"`
  24. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  25. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  26. Content string `description:"内容"`
  27. VideoUrl string `description:"音频文件URL"`
  28. VideoName string `description:"音频文件名称"`
  29. VideoPlaySeconds string `description:"音频播放时长"`
  30. VideoSize string `description:"音频文件大小,单位M"`
  31. ContentSub string `description:"内容前两个章节"`
  32. ReportCode string `description:"报告唯一编码"`
  33. ReportVersion int `description:"1:旧版,2:新版"`
  34. HasChapter int `description:"是否有章节 0-否 1-是"`
  35. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  36. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  37. MsgSendTime time.Time `description:"模版消息发送时间"`
  38. AdminId int `description:"创建者账号"`
  39. AdminRealName string `description:"创建者姓名"`
  40. }
  41. type ReportList struct {
  42. Id int `description:"报告Id"`
  43. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  44. ClassifyIdFirst int `description:"一级分类id"`
  45. ClassifyNameFirst string `description:"一级分类名称"`
  46. ClassifyIdSecond int `description:"二级分类id"`
  47. ClassifyNameSecond string `description:"二级分类名称"`
  48. Title string `description:"标题"`
  49. Abstract string `description:"摘要"`
  50. Author string `description:"作者"`
  51. Frequency string `description:"频度"`
  52. CreateTime string `description:"创建时间"`
  53. ModifyTime time.Time `description:"修改时间"`
  54. State int `description:"1:未发布,2:已发布"`
  55. PublishTime string `description:"发布时间"`
  56. PrePublishTime string `description:"预发布时间"`
  57. Stage int `description:"期数"`
  58. MsgIsSend int `description:"模板消息是否已发送,0:否,1:是"`
  59. Content string `description:"内容"`
  60. VideoUrl string `description:"音频文件URL"`
  61. VideoName string `description:"音频文件名称"`
  62. VideoPlaySeconds string `description:"音频播放时长"`
  63. ContentSub string `description:"内容前两个章节"`
  64. Pv int `description:"Pv"`
  65. Uv int `description:"Uv"`
  66. ReportCode string `description:"报告唯一编码"`
  67. ReportVersion int `description:"1:旧版,2:新版"`
  68. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  69. NeedThsMsg int `description:"是否需要推送客群消息 0-否 1-是"`
  70. HasChapter int `description:"是否有章节 0-否 1-是"`
  71. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  72. ChapterVideoList []*ReportChapterVideoList `description:"章节音频列表"`
  73. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  74. MsgSendTime string `description:"模版消息发送时间"`
  75. CanEdit bool `description:"是否可编辑"`
  76. Editor string `description:"编辑人"`
  77. AdminId int `description:"创建者账号"`
  78. AdminRealName string `description:"创建者姓名"`
  79. }
  80. type ReportListResp struct {
  81. List []*ReportList
  82. Paging *paging.PagingItem `description:"分页数据"`
  83. }
  84. func GetReportListCount(condition string, pars []interface{}, companyType string) (count int, err error) {
  85. //产品权限
  86. companyTypeSqlStr := ``
  87. if companyType == "ficc" {
  88. companyTypeSqlStr = " AND classify_id_first != 40 "
  89. } else if companyType == "权益" {
  90. companyTypeSqlStr = " AND classify_id_first = 40 "
  91. }
  92. oRddp := orm.NewOrmUsingDB("rddp")
  93. sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 ` + companyTypeSqlStr
  94. if condition != "" {
  95. sql += condition
  96. }
  97. err = oRddp.Raw(sql, pars).QueryRow(&count)
  98. return
  99. }
  100. func GetReportList(condition string, pars []interface{}, companyType string, startSize, pageSize int) (items []*ReportList, err error) {
  101. o := orm.NewOrmUsingDB("rddp")
  102. //产品权限
  103. companyTypeSqlStr := ``
  104. if companyType == "ficc" {
  105. companyTypeSqlStr = " AND classify_id_first != 40 "
  106. } else if companyType == "权益" {
  107. companyTypeSqlStr = " AND classify_id_first = 40 "
  108. }
  109. sql := `SELECT *,
  110. (SELECT COUNT(1) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS pv,
  111. (SELECT COUNT(DISTINCT user_id) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS uv
  112. FROM report WHERE 1=1 ` + companyTypeSqlStr
  113. if condition != "" {
  114. sql += condition
  115. }
  116. sql += `ORDER BY FIELD(state,3,1,2,4), modify_time DESC LIMIT ?,?`
  117. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  118. return
  119. }
  120. // 发布报告
  121. func PublishReport(reportIds string) (err error) {
  122. o := orm.NewOrmUsingDB("rddp")
  123. sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + reportIds + `)`
  124. _, err = o.Raw(sql).Exec()
  125. return
  126. }
  127. // 取消发布报告
  128. func PublishCancleReport(reportIds int, publishTimeNullFlag bool) (err error) {
  129. o := orm.NewOrmUsingDB("rddp")
  130. var sql string
  131. if publishTimeNullFlag {
  132. sql = ` UPDATE report SET state=1, publish_time=null, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
  133. } else {
  134. sql = ` UPDATE report SET state=1, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
  135. }
  136. _, err = o.Raw(sql, reportIds).Exec()
  137. return
  138. }
  139. // 删除报告
  140. func DeleteReport(reportIds int) (err error) {
  141. o := orm.NewOrmUsingDB("rddp")
  142. sql := ` DELETE FROM report WHERE id =? `
  143. _, err = o.Raw(sql, reportIds).Exec()
  144. return
  145. }
  146. type ReportDetail struct {
  147. Id int `orm:"column(id)" description:"报告Id"`
  148. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  149. ClassifyIdFirst int `description:"一级分类id"`
  150. ClassifyNameFirst string `description:"一级分类名称"`
  151. ClassifyIdSecond int `description:"二级分类id"`
  152. ClassifyNameSecond string `description:"二级分类名称"`
  153. Title string `description:"标题"`
  154. Abstract string `description:"摘要"`
  155. Author string `description:"作者"`
  156. Frequency string `description:"频度"`
  157. CreateTime string `description:"创建时间"`
  158. ModifyTime string `description:"修改时间"`
  159. State int `description:"1:未发布,2:已发布"`
  160. PublishTime string `description:"发布时间"`
  161. PrePublishTime string `description:"预发布时间"`
  162. Stage int `description:"期数"`
  163. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  164. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  165. Content string `description:"内容"`
  166. VideoUrl string `description:"音频文件URL"`
  167. VideoName string `description:"音频文件名称"`
  168. VideoPlaySeconds string `description:"音频播放时长"`
  169. ContentSub string `description:"内容前两个章节"`
  170. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  171. HasChapter int `description:"是否有章节 0-否 1-是"`
  172. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  173. }
  174. func GetReportById(reportId int) (item *ReportDetail, err error) {
  175. o := orm.NewOrmUsingDB("rddp")
  176. sql := `SELECT * FROM report WHERE id=?`
  177. err = o.Raw(sql, reportId).QueryRow(&item)
  178. return
  179. }
  180. func GetReportStage(classifyIdFirst, classifyIdSecond int) (count int, err error) {
  181. o := orm.NewOrmUsingDB("rddp")
  182. sql := ``
  183. if classifyIdSecond > 0 {
  184. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_second=? "
  185. o.Raw(sql, classifyIdSecond).QueryRow(&count)
  186. } else {
  187. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first=? "
  188. o.Raw(sql, classifyIdFirst).QueryRow(&count)
  189. }
  190. return
  191. }
  192. func GetReportStageEdit(classifyIdFirst, classifyIdSecond, reportId int) (count int, err error) {
  193. o := orm.NewOrmUsingDB("rddp")
  194. sql := ``
  195. if classifyIdSecond > 0 {
  196. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_second=? AND id<>? "
  197. o.Raw(sql, classifyIdSecond, reportId).QueryRow(&count)
  198. } else {
  199. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first=? AND id<>? "
  200. o.Raw(sql, classifyIdFirst, reportId).QueryRow(&count)
  201. }
  202. return
  203. }
  204. type PublishReq struct {
  205. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  206. }
  207. type PublishCancelReq struct {
  208. ReportIds int `description:"报告id"`
  209. }
  210. type DeleteReq struct {
  211. ReportIds int `description:"报告id"`
  212. }
  213. type AddReq struct {
  214. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  215. ClassifyIdFirst int `description:"一级分类id"`
  216. ClassifyNameFirst string `description:"一级分类名称"`
  217. ClassifyIdSecond int `description:"二级分类id"`
  218. ClassifyNameSecond string `description:"二级分类名称"`
  219. Title string `description:"标题"`
  220. Abstract string `description:"摘要"`
  221. Author string `description:"作者"`
  222. Frequency string `description:"频度"`
  223. State int `description:"状态:1:未发布,2:已发布"`
  224. Content string `description:"内容"`
  225. CreateTime string `description:"创建时间"`
  226. ReportVersion int `description:"1:旧版,2:新版"`
  227. }
  228. type PrePublishReq struct {
  229. ReportId int `description:"报告id"`
  230. PrePublishTime string `description:"预发布时间"`
  231. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  232. }
  233. type AddResp struct {
  234. ReportId int64 `description:"报告id"`
  235. ReportCode string `description:"报告code"`
  236. }
  237. func AddReport(item *Report) (lastId int64, err error) {
  238. o := orm.NewOrmUsingDB("rddp")
  239. lastId, err = o.Insert(item)
  240. return
  241. }
  242. type EditReq struct {
  243. ReportId int64 `description:"报告id"`
  244. ClassifyIdFirst int `description:"一级分类id"`
  245. ClassifyNameFirst string `description:"一级分类名称"`
  246. ClassifyIdSecond int `description:"二级分类id"`
  247. ClassifyNameSecond string `description:"二级分类名称"`
  248. Title string `description:"标题"`
  249. Abstract string `description:"摘要"`
  250. Author string `description:"作者"`
  251. Frequency string `description:"频度"`
  252. State int `description:"状态:1:未发布,2:已发布"`
  253. Content string `description:"内容"`
  254. CreateTime string `description:"创建时间"`
  255. }
  256. type EditResp struct {
  257. ReportId int64 `description:"报告id"`
  258. ReportCode string `description:"报告code"`
  259. }
  260. func EditReport(item *Report, reportId int64) (err error) {
  261. o := orm.NewOrmUsingDB("rddp")
  262. sql := `UPDATE report
  263. SET
  264. classify_id_first =?,
  265. classify_name_first = ?,
  266. classify_id_second = ?,
  267. classify_name_second = ?,
  268. title = ?,
  269. abstract = ?,
  270. author = ?,
  271. frequency = ?,
  272. state = ?,
  273. content = ?,
  274. content_sub = ?,
  275. stage =?,
  276. create_time = ?,
  277. modify_time = ?
  278. WHERE id = ? `
  279. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  280. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Exec()
  281. return
  282. }
  283. type ReportDetailReq struct {
  284. ReportId int `description:"报告id"`
  285. }
  286. type ClassifyIdDetailReq struct {
  287. ClassifyIdFirst int `description:"报告一级分类id"`
  288. ClassifyIdSecond int `description:"报告二级分类id"`
  289. }
  290. func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) {
  291. o := orm.NewOrmUsingDB("rddp")
  292. sql := ` SELECT * FROM report WHERE 1=1 `
  293. if classifyIdSecond > 0 {
  294. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  295. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  296. } else {
  297. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  298. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  299. }
  300. return
  301. }
  302. type SendTemplateMsgReq struct {
  303. ReportId int `description:"报告id"`
  304. }
  305. func ModifyReportMsgIsSend(reportId int) (err error) {
  306. o := orm.NewOrmUsingDB("rddp")
  307. report, err := GetReportById(reportId)
  308. if err != nil {
  309. return
  310. }
  311. if report.MsgIsSend == 0 {
  312. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? `
  313. _, err = o.Raw(sql, reportId).Exec()
  314. }
  315. return
  316. }
  317. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  318. o := orm.NewOrmUsingDB("rddp")
  319. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  320. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  321. return
  322. }
  323. type ReportItem struct {
  324. Id int `orm:"column(id)" description:"报告Id"`
  325. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  326. ClassifyIdFirst int `description:"一级分类id"`
  327. ClassifyNameFirst string `description:"一级分类名称"`
  328. ClassifyIdSecond int `description:"二级分类id"`
  329. ClassifyNameSecond string `description:"二级分类名称"`
  330. Title string `description:"标题"`
  331. Abstract string `description:"摘要"`
  332. Author string `description:"作者"`
  333. Frequency string `description:"频度"`
  334. CreateTime time.Time `description:"创建时间"`
  335. ModifyTime time.Time `description:"修改时间"`
  336. State int `description:"1:未发布,2:已发布"`
  337. PublishTime time.Time `description:"发布时间"`
  338. Stage int `description:"期数"`
  339. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  340. Content string `description:"内容"`
  341. VideoUrl string `description:"音频文件URL"`
  342. VideoName string `description:"音频文件名称"`
  343. VideoPlaySeconds string `description:"音频播放时长"`
  344. ContentSub string `description:"内容前两个章节"`
  345. }
  346. func GetReportItemById(reportId int) (item *ReportItem, err error) {
  347. o := orm.NewOrmUsingDB("rddp")
  348. sql := `SELECT * FROM report WHERE id=?`
  349. err = o.Raw(sql, reportId).QueryRow(&item)
  350. return
  351. }
  352. type SaveReportContent struct {
  353. Content string `description:"内容"`
  354. ReportId int `description:"报告id"`
  355. NoChange int `description:"内容是否未改变:1:内容未改变"`
  356. }
  357. func EditReportContent(reportId int, content, contentSub string) (err error) {
  358. o := orm.NewOrmUsingDB("rddp")
  359. sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  360. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  361. return
  362. }
  363. func AddReportSaveLog(reportId, adminId int, content, contentSub, adminName string) (err error) {
  364. o := orm.NewOrmUsingDB("rddp")
  365. sql := ` INSERT INTO report_save_log(report_id, content,content_sub,admin_id,admin_name) VALUES (?,?,?,?,?) `
  366. _, err = o.Raw(sql, reportId, content, contentSub, adminId, adminName).Exec()
  367. return
  368. }
  369. func MultiAddReportChaptersSaveLog(items []*ReportChapter, adminId int, adminRealName string) (err error) {
  370. o := orm.NewOrmUsingDB("rddp")
  371. p, err := o.Raw(`INSERT INTO report_save_log(report_id, report_chapter_id, content, content_sub, admin_id, admin_name) VALUES (?,?,?,?,?,?)`).Prepare()
  372. if err != nil {
  373. return
  374. }
  375. defer func() {
  376. _ = p.Close()
  377. }()
  378. for _, v := range items {
  379. _, err = p.Exec(v.ReportId, v.ReportChapterId, v.Content, v.ContentSub, adminId, adminRealName)
  380. if err != nil {
  381. return
  382. }
  383. }
  384. return
  385. }
  386. type SaveReportContentResp struct {
  387. ReportId int `description:"报告id"`
  388. }
  389. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  390. o := orm.NewOrmUsingDB("rddp")
  391. sql := `UPDATE report SET report_code=? WHERE id=? `
  392. _, err = o.Raw(sql, reportCode, reportId).Exec()
  393. return
  394. }
  395. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  396. o := orm.NewOrmUsingDB("rddp")
  397. if item.ThsMsgIsSend == 0 {
  398. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  399. _, err = o.Raw(sql, item.Id).Exec()
  400. }
  401. return
  402. }
  403. type ThsSendTemplateMsgReq struct {
  404. ReportId []int `description:"报告id"`
  405. }
  406. type PublishDayWeekReportReq struct {
  407. ReportId int `description:"报告ID"`
  408. }
  409. // SaveDayWeekReportReq 新增晨报周报请求体
  410. type SaveDayWeekReportReq struct {
  411. ReportId int `description:"报告ID"`
  412. Title string `description:"标题"`
  413. ReportType string `description:"一级分类ID"`
  414. Author string `description:"作者"`
  415. CreateTime string `description:"创建时间"`
  416. }
  417. // GetDayWeekReportStage 获取晨报周报期数
  418. func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int, err error) {
  419. o := orm.NewOrmUsingDB("rddp")
  420. sql := " SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first = ? AND create_time > ? "
  421. o.Raw(sql, classifyIdFirst, yearStart).QueryRow(&count)
  422. return
  423. }
  424. // AddReportAndChapter 新增报告及章节
  425. func AddReportAndChapter(reportItem *Report, chapterItemList []*ReportChapter) (reportId int64, err error) {
  426. o := orm.NewOrmUsingDB("rddp")
  427. to, err := o.Begin()
  428. if err != nil {
  429. return
  430. }
  431. defer func() {
  432. if err != nil {
  433. _ = to.Rollback()
  434. } else {
  435. _ = to.Commit()
  436. }
  437. }()
  438. if reportId, err = to.Insert(reportItem); err != nil {
  439. return
  440. }
  441. if len(chapterItemList) > 0 {
  442. for _, chapterItem := range chapterItemList {
  443. chapterItem.ReportId = int(reportId)
  444. cpId, tmpErr := to.Insert(chapterItem)
  445. if tmpErr != nil {
  446. return
  447. }
  448. chapterItem.ReportChapterId = int(cpId)
  449. }
  450. }
  451. return
  452. }
  453. // GetReportByReportId 主键获取报告
  454. func GetReportByReportId(reportId int) (item *Report, err error) {
  455. o := orm.NewOrmUsingDB("rddp")
  456. sql := `SELECT * FROM report WHERE id = ?`
  457. err = o.Raw(sql, reportId).QueryRow(&item)
  458. return
  459. }
  460. // DeleteDayWeekReportAndChapter 删除晨周报及章节
  461. func DeleteDayWeekReportAndChapter(reportId int) (err error) {
  462. o := orm.NewOrmUsingDB("rddp")
  463. to, err := o.Begin()
  464. if err != nil {
  465. return
  466. }
  467. defer func() {
  468. if err != nil {
  469. _ = to.Rollback()
  470. } else {
  471. _ = to.Commit()
  472. }
  473. }()
  474. sql := ` DELETE FROM report WHERE id = ? LIMIT 1 `
  475. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  476. return
  477. }
  478. sql = ` DELETE FROM report_chapter WHERE report_id = ? `
  479. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  480. return
  481. }
  482. return
  483. }
  484. // UpdateReport 更新报告
  485. func (reportInfo *Report) UpdateReport(cols []string) (err error) {
  486. o := orm.NewOrmUsingDB("rddp")
  487. _, err = o.Update(reportInfo, cols...)
  488. return
  489. }
  490. // 晨周报详情
  491. type ReportDetailView struct {
  492. *ReportDetail
  493. ChapterList []*ReportChapter
  494. }
  495. type ElasticReportDetail struct {
  496. ReportId int `description:"报告ID"`
  497. ReportChapterId int `description:"报告章节ID"`
  498. Title string `description:"标题"`
  499. Abstract string `description:"摘要"`
  500. BodyContent string `description:"内容"`
  501. PublishTime string `description:"发布时间"`
  502. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  503. Author string `description:"作者"`
  504. ClassifyIdFirst int `description:"一级分类ID"`
  505. ClassifyNameFirst string `description:"一级分类名称"`
  506. ClassifyIdSecond int `description:"二级分类ID"`
  507. ClassifyNameSecond string `description:"二级分类名称"`
  508. Categories string `description:"关联的品种名称(包括品种别名)"`
  509. StageStr string `description:"报告期数"`
  510. }
  511. // GetLastPublishedDayWeekReport 获取上一篇已发布的晨周报
  512. func GetLastPublishDayWeekReport(chapterType string) (item *Report, err error) {
  513. o := orm.NewOrmUsingDB("rddp")
  514. sql := ` SELECT * FROM report WHERE has_chapter = 1 AND chapter_type = ? AND state = 2 ORDER BY publish_time DESC LIMIT 1 `
  515. err = o.Raw(sql, chapterType).QueryRow(&item)
  516. return
  517. }
  518. // PublishReportAndChapter 发布报告及章节
  519. func PublishReportAndChapter(reportInfo *Report, publishIds string, unPublishIds string, isPublishReport bool, cols []string) (err error) {
  520. o := orm.NewOrmUsingDB("rddp")
  521. to, err := o.Begin()
  522. if err != nil {
  523. return
  524. }
  525. defer func() {
  526. if err != nil {
  527. _ = to.Rollback()
  528. } else {
  529. _ = to.Commit()
  530. }
  531. }()
  532. // 更新报告
  533. if isPublishReport {
  534. if _, err = to.Update(reportInfo, cols...); err != nil {
  535. return
  536. }
  537. }
  538. // 发布章节
  539. if publishIds != "" {
  540. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + publishIds + `) `
  541. _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id).Exec()
  542. }
  543. if unPublishIds != "" {
  544. sql := ` UPDATE report_chapter SET publish_state = 1, publish_time = NULL, is_edit = 0 WHERE report_id = ? AND report_chapter_id IN (` + unPublishIds + `) `
  545. _, err = to.Raw(sql, reportInfo.Id).Exec()
  546. }
  547. return
  548. }
  549. // 发布报告
  550. func PublishReportById(reportId int, publishTime time.Time) (err error) {
  551. o := orm.NewOrmUsingDB("rddp")
  552. sql := `UPDATE report SET state = 2, publish_time = ?, pre_publish_time=null, pre_msg_send=0, modify_time = NOW() WHERE id = ? `
  553. _, err = o.Raw(sql, publishTime, reportId).Exec()
  554. return
  555. }
  556. // GetPageReportList 分页获取报告列表
  557. func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  558. o := orm.NewOrmUsingDB("rddp")
  559. sql := `SELECT * FROM report WHERE 1=1 `
  560. sql += condition
  561. sql += ` ORDER BY modify_time DESC`
  562. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  563. err = o.Raw(totalSql, pars).QueryRow(&total)
  564. if err != nil {
  565. return
  566. }
  567. sql += ` LIMIT ?,? `
  568. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  569. return
  570. }
  571. // SunCodeReq 获取太阳码请求体
  572. type SunCodeReq struct {
  573. CodePage string `json:"CodePage" description:"太阳码page"`
  574. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  575. }
  576. // YbPcSuncode 活动海报表
  577. type YbPcSuncode struct {
  578. SuncodeID uint32 `orm:"column(suncode_id);pk" `
  579. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  580. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  581. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  582. SuncodeURL string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  583. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  584. }
  585. // GetYbPcSunCode 获取太阳码
  586. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  587. o := orm.NewOrmUsingDB("weekly")
  588. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  589. err = o.Raw(sql, scene, page).QueryRow(&item)
  590. return
  591. }
  592. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  593. o := orm.NewOrmUsingDB("weekly")
  594. _, err = o.Insert(item)
  595. return
  596. }
  597. // YbSuncodePars 小程序太阳码scene参数
  598. type YbSuncodePars struct {
  599. ID uint32 `orm:"column(id);pk" `
  600. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  601. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  602. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  603. }
  604. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  605. o := orm.NewOrmUsingDB("weekly")
  606. _, err = o.Insert(item)
  607. return
  608. }
  609. // GetEmptyContentSubPPTReport 获取前两章为空的PPT报告
  610. func GetEmptyContentSubPPTReport() (list []*Report, err error) {
  611. sql := `SELECT
  612. r.id,
  613. r.content,
  614. r.content_sub
  615. FROM
  616. report AS r
  617. JOIN ppt_v2 AS p ON r.id = p.report_id
  618. WHERE
  619. p.report_id > 0 AND r.content_sub = ""`
  620. _, err = orm.NewOrmUsingDB("rddp").Raw(sql).QueryRows(&list)
  621. return
  622. }
  623. // ModifyReportAuthor 更改报告作者
  624. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  625. //产品权限
  626. oRddp := orm.NewOrmUsingDB("rddp")
  627. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  628. if condition != "" {
  629. sql += condition
  630. }
  631. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  632. return
  633. }
  634. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  635. o := orm.NewOrmUsingDB("rddp")
  636. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  637. _, err = o.Raw(sql1, reportId).Exec()
  638. if err != nil {
  639. return
  640. }
  641. //修改音频标题
  642. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  643. _, err = o.Raw(sql2, reportId).Exec()
  644. return
  645. }
  646. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  647. o := orm.NewOrmUsingDB("rddp")
  648. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  649. _, err = o.Raw(sql1, reportId).Exec()
  650. if err != nil {
  651. return
  652. }
  653. //修改音频标题
  654. 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)`
  655. _, err = o.Raw(sql2, reportId).Exec()
  656. return
  657. }
  658. // MarkEditReport 标记编辑英文研报的请求数据
  659. type MarkEditReport struct {
  660. ReportId int `description:"研报id"`
  661. Status int `description:"标记状态,1:编辑中,2:编辑完成"`
  662. }
  663. type MarkReportResp struct {
  664. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  665. Msg string `description:"提示信息"`
  666. Editor string `description:"编辑者姓名"`
  667. }
  668. type MarkReportItem struct {
  669. AdminId int `description:"编辑者ID"`
  670. Editor string `description:"编辑者姓名"`
  671. ReportClassifyNameFirst string
  672. }
  673. // GetReportByCondition 获取报告
  674. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  675. o := orm.NewOrmUsingDB("rddp")
  676. fields := `*`
  677. if len(fieldArr) > 0 {
  678. fields = strings.Join(fieldArr, ",")
  679. }
  680. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  681. sql += condition
  682. order := ` ORDER BY modify_time DESC`
  683. if orderRule != `` {
  684. order = orderRule
  685. }
  686. sql += order
  687. if isPage {
  688. sql += ` LIMIT ?,?`
  689. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  690. } else {
  691. _, err = o.Raw(sql, pars).QueryRows(&items)
  692. }
  693. return
  694. }
  695. // ModifyReportMsgIsSendV2 更新报告消息状态
  696. func ModifyReportMsgIsSendV2(reportId int) (err error) {
  697. o := orm.NewOrmUsingDB("rddp")
  698. sql := `UPDATE report SET msg_is_send = 1, ths_msg_is_send = 1, msg_send_time = NOW() WHERE id = ? LIMIT 1`
  699. _, err = o.Raw(sql, reportId).Exec()
  700. return
  701. }
  702. // SetPrePublishReportById 设置定时发布
  703. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  704. o := orm.NewOrmUsingDB("rddp")
  705. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  706. _, err = o.Raw(sql, prePublishTime, preMsgSend, reportId).Exec()
  707. return
  708. }