report.go 36 KB

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