report.go 36 KB

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