report.go 38 KB

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