report.go 35 KB

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