report.go 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  1. package models
  2. import (
  3. "errors"
  4. "eta/eta_api/utils"
  5. "fmt"
  6. "github.com/beego/beego/v2/client/orm"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  8. "strings"
  9. "time"
  10. )
  11. // 报告状态
  12. const (
  13. ReportStateUnpublished = 1 // 未发布
  14. ReportStatePublished = 2 // 已发布
  15. ReportStateWaitSubmit = 3 // 待提交
  16. ReportStateWaitApprove = 4 // 审批中
  17. ReportStateRefused = 5 // 已驳回
  18. ReportStatePass = 6 // 已通过
  19. )
  20. // 报告操作
  21. const (
  22. ReportOperateAdd = 1 // 新增报告
  23. ReportOperateEdit = 2 // 编辑报告
  24. ReportOperatePublish = 3 // 发布报告
  25. ReportOperateCancelPublish = 4 // 取消发布报告
  26. ReportOperateSubmitApprove = 5 // 提交审批
  27. ReportOperateCancelApprove = 6 // 撤回审批
  28. )
  29. type Report struct {
  30. Id int `orm:"column(id)" description:"报告Id"`
  31. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  32. ClassifyIdFirst int `description:"一级分类id"`
  33. ClassifyNameFirst string `description:"一级分类名称"`
  34. ClassifyIdSecond int `description:"二级分类id"`
  35. ClassifyNameSecond string `description:"二级分类名称"`
  36. Title string `description:"标题"`
  37. Abstract string `description:"摘要"`
  38. Author string `description:"作者"`
  39. Frequency string `description:"频度"`
  40. CreateTime string `description:"创建时间"`
  41. ModifyTime time.Time `description:"修改时间"`
  42. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  43. PublishTime time.Time `description:"发布时间"`
  44. Stage int `description:"期数"`
  45. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  46. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  47. Content string `description:"内容"`
  48. VideoUrl string `description:"音频文件URL"`
  49. VideoName string `description:"音频文件名称"`
  50. VideoPlaySeconds string `description:"音频播放时长"`
  51. VideoSize string `description:"音频文件大小,单位M"`
  52. ContentSub string `description:"内容前两个章节"`
  53. ReportCode string `description:"报告唯一编码"`
  54. ReportVersion int `description:"1:旧版,2:新版"`
  55. HasChapter int `description:"是否有章节 0-否 1-是"`
  56. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  57. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  58. MsgSendTime time.Time `description:"模版消息发送时间"`
  59. AdminId int `description:"创建者账号"`
  60. AdminRealName string `description:"创建者姓名"`
  61. ApproveTime time.Time `description:"审批时间"`
  62. ApproveId int `description:"审批ID"`
  63. DetailImgUrl string `description:"报告详情长图地址"`
  64. DetailPdfUrl string `description:"报告详情PDF地址"`
  65. ContentStruct string `description:"内容组件"`
  66. LastModifyAdminId int `description:"最后更新人ID"`
  67. LastModifyAdminName string `description:"最后更新人姓名"`
  68. ContentModifyTime time.Time `description:"内容更新时间"`
  69. Pv int `description:"pv"`
  70. Uv int `description:"uv"`
  71. HeadImg string `description:"报告头图地址"`
  72. EndImg string `description:"报告尾图地址"`
  73. CanvasColor string `description:"画布颜色"`
  74. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  75. HeadResourceId int `description:"版头资源ID"`
  76. EndResourceId int `description:"版尾资源ID"`
  77. ClassifyIdThird int `description:"三级分类id"`
  78. ClassifyNameThird string `description:"三级分类名称"`
  79. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  80. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  81. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  82. ReportCreateTime time.Time `description:"报告时间创建时间"`
  83. InheritReportId int `description:"待继承的报告ID"`
  84. }
  85. type ReportList struct {
  86. Id int `description:"报告Id"`
  87. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  88. ClassifyIdFirst int `description:"一级分类id"`
  89. ClassifyNameFirst string `description:"一级分类名称"`
  90. ClassifyIdSecond int `description:"二级分类id"`
  91. ClassifyNameSecond string `description:"二级分类名称"`
  92. Title string `description:"标题"`
  93. Abstract string `description:"摘要"`
  94. Author string `description:"作者"`
  95. Frequency string `description:"频度"`
  96. CreateTime string `description:"创建时间"`
  97. ModifyTime time.Time `description:"修改时间"`
  98. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  99. PublishTime string `description:"发布时间"`
  100. PrePublishTime string `description:"预发布时间"`
  101. Stage int `description:"期数"`
  102. MsgIsSend int `description:"模板消息是否已发送,0:否,1:是"`
  103. Content string `description:"内容"`
  104. VideoUrl string `description:"音频文件URL"`
  105. VideoName string `description:"音频文件名称"`
  106. VideoPlaySeconds string `description:"音频播放时长"`
  107. ContentSub string `description:"内容前两个章节"`
  108. Pv int `description:"Pv"`
  109. Uv int `description:"Uv"`
  110. ReportCode string `description:"报告唯一编码"`
  111. ReportVersion int `description:"1:旧版,2:新版"`
  112. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  113. NeedThsMsg int `description:"是否需要推送客群消息 0-否 1-是"`
  114. HasChapter int `description:"是否有章节 0-否 1-是"`
  115. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  116. ChapterVideoList []*ReportChapterVideoList `description:"章节音频列表"`
  117. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  118. MsgSendTime string `description:"模版消息发送时间"`
  119. CanEdit bool `description:"是否可编辑"`
  120. Editor string `description:"编辑人"`
  121. AdminId int `description:"创建者账号"`
  122. AdminRealName string `description:"创建者姓名"`
  123. ApproveTime string `description:"审批时间"`
  124. DetailImgUrl string `description:"报告详情长图地址"`
  125. DetailPdfUrl string `description:"报告详情PDF地址"`
  126. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  127. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  128. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  129. ReportCreateTime time.Time `description:"报告时间创建时间"`
  130. ContentStruct string `description:"内容组件"`
  131. LastModifyAdminId int `description:"最后更新人ID"`
  132. LastModifyAdminName string `description:"最后更新人姓名"`
  133. ContentModifyTime time.Time `description:"内容更新时间"`
  134. HeadImg string `description:"报告头图地址"`
  135. EndImg string `description:"报告尾图地址"`
  136. CanvasColor string `description:"画布颜色"`
  137. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  138. HeadResourceId int `description:"版头资源ID"`
  139. EndResourceId int `description:"版尾资源ID"`
  140. ClassifyIdThird int `description:"三级分类id"`
  141. ClassifyNameThird string `description:"三级分类名称"`
  142. InheritReportId int `description:"待继承的报告ID"`
  143. }
  144. type ReportListResp struct {
  145. List []*ReportList
  146. Paging *paging.PagingItem `description:"分页数据"`
  147. }
  148. // GetReportListCountV1
  149. // @Description: 获取普通报告列表的报告数量
  150. // @author: Roc
  151. // @datetime 2024-05-30 15:14:43
  152. // @param condition string
  153. // @param pars []interface{}
  154. // @return count int
  155. // @return err error
  156. func GetReportListCountV1(condition string, pars []interface{}) (count int, err error) {
  157. o := orm.NewOrmUsingDB("rddp")
  158. sql := `SELECT COUNT(1) AS count FROM report as a WHERE 1=1 `
  159. if condition != "" {
  160. sql += condition
  161. }
  162. err = o.Raw(sql, pars).QueryRow(&count)
  163. return
  164. }
  165. // GetReportListV1
  166. // @Description: 获取普通报告列表的数据
  167. // @author: Roc
  168. // @datetime 2024-05-30 15:14:25
  169. // @param condition string
  170. // @param pars []interface{}
  171. // @param startSize int
  172. // @param pageSize int
  173. // @return items []*ReportList
  174. // @return err error
  175. func GetReportListV1(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  176. o := orm.NewOrmUsingDB("rddp")
  177. sql := `SELECT * FROM report as a WHERE 1=1 `
  178. if condition != "" {
  179. sql += condition
  180. }
  181. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  182. sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  183. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  184. return
  185. }
  186. type ReportPvUv struct {
  187. ReportId int
  188. PvTotal int
  189. UvTotal int
  190. }
  191. func GetReportPvUvByReportIdList(reportIdList []string) (items []ReportPvUv, err error) {
  192. num := len(reportIdList)
  193. if num <= 0 {
  194. return
  195. }
  196. o := orm.NewOrmUsingDB("rddp")
  197. sql := `SELECT report_id, COUNT(1) as pv_total,COUNT(DISTINCT user_id) as uv_total FROM report_view_record WHERE report_id in (` + utils.GetOrmInReplace(num) + `) GROUP BY report_id`
  198. _, err = o.Raw(sql, reportIdList).QueryRows(&items)
  199. return
  200. }
  201. // GetReportListCountByGrant
  202. // @Description: 获取共享报告列表的报告数量
  203. // @author: Roc
  204. // @datetime 2024-05-30 15:14:01
  205. // @param condition string
  206. // @param pars []interface{}
  207. // @return count int
  208. // @return err error
  209. func GetReportListCountByGrant(condition string, pars []interface{}) (count int, err error) {
  210. o := orm.NewOrmUsingDB("rddp")
  211. sql := `SELECT a.id FROM report as a
  212. JOIN report_grant b on a.id=b.report_id
  213. WHERE 1=1 `
  214. if condition != "" {
  215. sql += condition
  216. }
  217. sql += " GROUP BY a.id "
  218. sql = `SELECT COUNT(1) AS count FROM (` + sql + `) d`
  219. err = o.Raw(sql, pars).QueryRow(&count)
  220. return
  221. }
  222. // GetReportListByGrant
  223. // @Description: 获取共享报告列表的数据
  224. // @author: Roc
  225. // @datetime 2024-05-30 15:15:07
  226. // @param condition string
  227. // @param pars []interface{}
  228. // @param startSize int
  229. // @param pageSize int
  230. // @return items []*ReportList
  231. // @return err error
  232. func GetReportListByGrant(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  233. o := orm.NewOrmUsingDB("rddp")
  234. sql := `SELECT * FROM report as a JOIN report_grant b on a.id = b.report_id WHERE 1=1 `
  235. if condition != "" {
  236. sql += condition
  237. }
  238. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  239. sql += ` GROUP BY a.id ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  240. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  241. return
  242. }
  243. func GetReportListCount(condition string, pars []interface{}) (count int, err error) {
  244. oRddp := orm.NewOrmUsingDB("rddp")
  245. sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 `
  246. if condition != "" {
  247. sql += condition
  248. }
  249. err = oRddp.Raw(sql, pars).QueryRow(&count)
  250. return
  251. }
  252. func GetReportList(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  253. o := orm.NewOrmUsingDB("rddp")
  254. sql := `SELECT *,
  255. (SELECT COUNT(1) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS pv,
  256. (SELECT COUNT(DISTINCT user_id) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS uv
  257. FROM report WHERE 1=1 `
  258. if condition != "" {
  259. sql += condition
  260. }
  261. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  262. sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  263. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  264. return
  265. }
  266. // PublishReport 发布报告
  267. func PublishReport(reportIds []int) (err error) {
  268. if len(reportIds) == 0 {
  269. return
  270. }
  271. o := orm.NewOrmUsingDB("rddp")
  272. sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  273. _, err = o.Raw(sql).Exec()
  274. return
  275. }
  276. // PublishCancelReport 取消发布报告
  277. func PublishCancelReport(reportId, state int, publishTimeNullFlag bool) (err error) {
  278. o := orm.NewOrmUsingDB("rddp")
  279. var sql string
  280. if publishTimeNullFlag {
  281. sql = ` UPDATE report SET state=?, publish_time=null, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
  282. } else {
  283. sql = ` UPDATE report SET state=?, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
  284. }
  285. _, err = o.Raw(sql, state, reportId).Exec()
  286. return
  287. }
  288. // 删除报告
  289. func DeleteReport(reportIds int) (err error) {
  290. o := orm.NewOrmUsingDB("rddp")
  291. sql := ` DELETE FROM report WHERE id =? `
  292. _, err = o.Raw(sql, reportIds).Exec()
  293. return
  294. }
  295. type ReportDetail struct {
  296. Id int `orm:"column(id)" description:"报告Id"`
  297. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  298. ClassifyIdFirst int `description:"一级分类id"`
  299. ClassifyNameFirst string `description:"一级分类名称"`
  300. ClassifyIdSecond int `description:"二级分类id"`
  301. ClassifyNameSecond string `description:"二级分类名称"`
  302. Title string `description:"标题"`
  303. Abstract string `description:"摘要"`
  304. Author string `description:"作者"`
  305. Frequency string `description:"频度"`
  306. CreateTime string `description:"创建时间"`
  307. ModifyTime string `description:"修改时间"`
  308. State int `description:"1:未发布,2:已发布"`
  309. PublishTime string `description:"发布时间"`
  310. PrePublishTime string `description:"预发布时间"`
  311. Stage int `description:"期数"`
  312. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  313. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  314. Content string `description:"内容"`
  315. VideoUrl string `description:"音频文件URL"`
  316. VideoName string `description:"音频文件名称"`
  317. VideoPlaySeconds string `description:"音频播放时长"`
  318. ContentSub string `description:"内容前两个章节"`
  319. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  320. HasChapter int `description:"是否有章节 0-否 1-是"`
  321. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  322. AdminId int `description:"创建者账号"`
  323. AdminRealName string `description:"创建者姓名"`
  324. // eta1.8.3(研报改版)相关内容
  325. ContentStruct string `description:"内容组件"`
  326. LastModifyAdminId int `description:"最后更新人ID"`
  327. LastModifyAdminName string `description:"最后更新人姓名"`
  328. ContentModifyTime time.Time `description:"内容更新时间"`
  329. Pv int `description:"pv"`
  330. Uv int `description:"uv"`
  331. HeadImg string `description:"报告头图地址"`
  332. EndImg string `description:"报告尾图地址"`
  333. CanvasColor string `description:"画布颜色"`
  334. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  335. HeadResourceId int `description:"版头资源ID"`
  336. EndResourceId int `description:"版尾资源ID"`
  337. ClassifyIdThird int `description:"三级分类id"`
  338. ClassifyNameThird string `description:"三级分类名称"`
  339. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  340. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  341. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  342. ReportCreateTime time.Time `description:"报告时间创建时间"`
  343. }
  344. func GetReportById(reportId int) (item *ReportDetail, err error) {
  345. o := orm.NewOrmUsingDB("rddp")
  346. sql := `SELECT * FROM report WHERE id=?`
  347. err = o.Raw(sql, reportId).QueryRow(&item)
  348. return
  349. }
  350. func GetReportByIds(reportIds string) (list []*ReportDetail, err error) {
  351. o := orm.NewOrmUsingDB("rddp")
  352. sql := `SELECT * FROM report WHERE id in ` + reportIds
  353. _, err = o.Raw(sql).QueryRows(&list)
  354. return
  355. }
  356. // GetSimpleReportByIds 根据报告ID查询报告基本信息
  357. func GetSimpleReportByIds(reportIds []int) (list []*ReportDetail, err error) {
  358. if len(reportIds) == 0 {
  359. return
  360. }
  361. o := orm.NewOrmUsingDB("rddp")
  362. sql := `SELECT id, title FROM report WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  363. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  364. return
  365. }
  366. // GetReportStage
  367. // @Description: 获取报告的最大期数(每一年的最大期数)
  368. // @author: Roc
  369. // @datetime 2024-06-03 17:44:14
  370. // @param classifyIdFirst int
  371. // @param classifyIdSecond int
  372. // @param classifyIdThird int
  373. // @return count int
  374. // @return err error
  375. func GetReportStage(classifyIdFirst, classifyIdSecond, classifyIdThird int) (count int, err error) {
  376. o := orm.NewOrmUsingDB("rddp")
  377. classifyId := classifyIdThird
  378. if classifyId <= 0 {
  379. classifyId = classifyIdSecond
  380. }
  381. if classifyId <= 0 {
  382. classifyId = classifyIdFirst
  383. }
  384. if classifyId <= 0 {
  385. err = errors.New("错误的分类id")
  386. return
  387. }
  388. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  389. sql := `SELECT MAX(stage) AS max_stage FROM report WHERE create_time > ? `
  390. if classifyIdThird > 0 {
  391. sql += " AND classify_id_third = ? "
  392. } else if classifyIdSecond > 0 {
  393. sql += " AND classify_id_second = ? "
  394. } else {
  395. sql = " AND classify_id_first = ? "
  396. }
  397. o.Raw(sql, yearStart, classifyId).QueryRow(&count)
  398. return
  399. }
  400. // GetReportStageEdit
  401. // @Description: 获取报告的最大期数(每一年的最大期数)
  402. // @author: Roc
  403. // @datetime 2024-06-04 13:50:34
  404. // @param classifyIdFirst int
  405. // @param classifyIdSecond int
  406. // @param classifyIdThird int
  407. // @param reportId int
  408. // @return count int
  409. // @return err error
  410. func GetReportStageEdit(classifyIdFirst, classifyIdSecond, classifyIdThird, reportId int) (count int, err error) {
  411. classifyId := classifyIdThird
  412. if classifyId <= 0 {
  413. classifyId = classifyIdSecond
  414. }
  415. if classifyId <= 0 {
  416. classifyId = classifyIdFirst
  417. }
  418. if classifyId <= 0 {
  419. err = errors.New("错误的分类id")
  420. return
  421. }
  422. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  423. sql := `SELECT MAX(stage) AS max_stage FROM report WHERE create_time > ? AND id<>? `
  424. if classifyIdThird > 0 {
  425. sql += " AND classify_id_third = ? "
  426. } else if classifyIdSecond > 0 {
  427. sql += " AND classify_id_second = ? "
  428. } else {
  429. sql = " AND classify_id_first = ? "
  430. }
  431. o := orm.NewOrmUsingDB("rddp")
  432. o.Raw(sql, yearStart, reportId, classifyId).QueryRow(&count)
  433. return
  434. }
  435. type PublishReq struct {
  436. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  437. ReportUrl string `description:"报告Url"`
  438. }
  439. type PublishCancelReq struct {
  440. ReportIds int `description:"报告id"`
  441. }
  442. type DeleteReq struct {
  443. ReportIds int `description:"报告id"`
  444. }
  445. type AddReq struct {
  446. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  447. ClassifyIdFirst int `description:"一级分类id"`
  448. ClassifyNameFirst string `description:"一级分类名称"`
  449. ClassifyIdSecond int `description:"二级分类id"`
  450. ClassifyNameSecond string `description:"二级分类名称"`
  451. ClassifyIdThird int `description:"三级分类id"`
  452. ClassifyNameThird string `description:"三级分类名称"`
  453. Title string `description:"标题"`
  454. Abstract string `description:"摘要"`
  455. Author string `description:"作者"`
  456. Frequency string `description:"频度"`
  457. State int `description:"状态:1:未发布,2:已发布"`
  458. Content string `description:"内容"`
  459. CreateTime string `description:"创建时间"`
  460. ReportVersion int `description:"1:旧版,2:新版"`
  461. ContentStruct string `description:"内容组件"`
  462. HeadImg string `description:"报告头图地址"`
  463. EndImg string `description:"报告尾图地址"`
  464. CanvasColor string `description:"画布颜色"`
  465. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  466. HeadResourceId int `description:"版头资源ID"`
  467. EndResourceId int `description:"版尾资源ID"`
  468. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  469. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  470. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  471. InheritReportId int `description:"待继承的报告ID"`
  472. GrantAdminIdList []int `description:"授权用户id列表"`
  473. }
  474. type PrePublishReq struct {
  475. ReportId int `description:"报告id"`
  476. PrePublishTime string `description:"预发布时间"`
  477. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  478. ReportUrl string `description:"报告Url"`
  479. }
  480. type AddResp struct {
  481. ReportId int64 `description:"报告id"`
  482. ReportCode string `description:"报告code"`
  483. }
  484. func AddReport(item *Report) (lastId int64, err error) {
  485. o := orm.NewOrmUsingDB("rddp")
  486. lastId, err = o.Insert(item)
  487. return
  488. }
  489. type EditReq struct {
  490. ReportId int64 `description:"报告id"`
  491. ClassifyIdFirst int `description:"一级分类id"`
  492. ClassifyNameFirst string `description:"一级分类名称"`
  493. ClassifyIdSecond int `description:"二级分类id"`
  494. ClassifyNameSecond string `description:"二级分类名称"`
  495. ClassifyIdThird int `description:"三级分类id"`
  496. ClassifyNameThird string `description:"三级分类名称"`
  497. Title string `description:"标题"`
  498. Abstract string `description:"摘要"`
  499. Author string `description:"作者"`
  500. Frequency string `description:"频度"`
  501. State int `description:"状态:1:未发布,2:已发布"`
  502. Content string `description:"内容"`
  503. CreateTime string `description:"创建时间"`
  504. ContentStruct string `description:"内容组件"`
  505. HeadImg string `description:"报告头图地址"`
  506. EndImg string `description:"报告尾图地址"`
  507. CanvasColor string `description:"画布颜色"`
  508. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  509. HeadResourceId int `description:"版头资源ID"`
  510. EndResourceId int `description:"版尾资源ID"`
  511. //CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  512. //ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  513. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  514. GrantAdminIdList []int `description:"授权用户id列表"`
  515. }
  516. type EditResp struct {
  517. ReportId int64 `description:"报告id"`
  518. ReportCode string `description:"报告code"`
  519. }
  520. func EditReport(item *Report, reportId int64) (err error) {
  521. o := orm.NewOrmUsingDB("rddp")
  522. sql := `UPDATE report
  523. SET
  524. classify_id_first =?,
  525. classify_name_first = ?,
  526. classify_id_second = ?,
  527. classify_name_second = ?,
  528. title = ?,
  529. abstract = ?,
  530. author = ?,
  531. frequency = ?,
  532. state = ?,
  533. content = ?,
  534. content_sub = ?,
  535. stage =?,
  536. create_time = ?,
  537. modify_time = ?
  538. WHERE id = ? `
  539. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  540. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Exec()
  541. return
  542. }
  543. func (m *Report) Update(cols []string) (err error) {
  544. o := orm.NewOrmUsingDB("rddp")
  545. _, err = o.Update(m, cols...)
  546. return
  547. }
  548. type ReportDetailReq struct {
  549. ReportId int `description:"报告id"`
  550. }
  551. type ClassifyIdDetailReq struct {
  552. ClassifyIdFirst int `description:"报告一级分类id"`
  553. ClassifyIdSecond int `description:"报告二级分类id"`
  554. }
  555. func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) {
  556. o := orm.NewOrmUsingDB("rddp")
  557. sql := ` SELECT * FROM report WHERE 1=1 `
  558. if classifyIdSecond > 0 {
  559. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  560. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  561. } else {
  562. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  563. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  564. }
  565. return
  566. }
  567. type SendTemplateMsgReq struct {
  568. ReportId int `description:"报告id"`
  569. }
  570. func ModifyReportMsgIsSend(reportId int) (err error) {
  571. o := orm.NewOrmUsingDB("rddp")
  572. report, err := GetReportById(reportId)
  573. if err != nil {
  574. return
  575. }
  576. if report.MsgIsSend == 0 {
  577. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? `
  578. _, err = o.Raw(sql, reportId).Exec()
  579. }
  580. return
  581. }
  582. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  583. o := orm.NewOrmUsingDB("rddp")
  584. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  585. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  586. return
  587. }
  588. type ReportItem struct {
  589. Id int `orm:"column(id)" description:"报告Id"`
  590. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  591. ClassifyIdFirst int `description:"一级分类id"`
  592. ClassifyNameFirst string `description:"一级分类名称"`
  593. ClassifyIdSecond int `description:"二级分类id"`
  594. ClassifyNameSecond string `description:"二级分类名称"`
  595. Title string `description:"标题"`
  596. Abstract string `description:"摘要"`
  597. Author string `description:"作者"`
  598. Frequency string `description:"频度"`
  599. CreateTime time.Time `description:"创建时间"`
  600. ModifyTime time.Time `description:"修改时间"`
  601. State int `description:"1:未发布,2:已发布"`
  602. PublishTime time.Time `description:"发布时间"`
  603. Stage int `description:"期数"`
  604. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  605. Content string `description:"内容"`
  606. VideoUrl string `description:"音频文件URL"`
  607. VideoName string `description:"音频文件名称"`
  608. VideoPlaySeconds string `description:"音频播放时长"`
  609. ContentSub string `description:"内容前两个章节"`
  610. }
  611. func GetReportItemById(reportId int) (item *ReportItem, err error) {
  612. o := orm.NewOrmUsingDB("rddp")
  613. sql := `SELECT * FROM report WHERE id=?`
  614. err = o.Raw(sql, reportId).QueryRow(&item)
  615. return
  616. }
  617. type SaveReportContent struct {
  618. Content string `description:"内容"`
  619. ReportId int `description:"报告id"`
  620. NoChange int `description:"内容是否未改变:1:内容未改变"`
  621. // 以下是智能研报相关
  622. ContentStruct string `description:"内容组件"`
  623. HeadImg string `description:"报告头图地址"`
  624. EndImg string `description:"报告尾图地址"`
  625. CanvasColor string `description:"画布颜色"`
  626. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  627. HeadResourceId int `description:"版头资源ID"`
  628. EndResourceId int `description:"版尾资源ID"`
  629. }
  630. func EditReportContent(reportId int, content, contentSub string) (err error) {
  631. o := orm.NewOrmUsingDB("rddp")
  632. sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  633. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  634. return
  635. }
  636. func AddReportSaveLog(reportId, adminId int, content, contentSub, contentStruct, canvasColor, adminName string, headResourceId, endResourceId int) (err error) {
  637. o := orm.NewOrmUsingDB("rddp")
  638. sql := ` INSERT INTO report_save_log(report_id, content,content_sub,content_struct,canvas_color,head_resource_id,end_resource_id,admin_id,admin_name) VALUES (?,?,?,?,?) `
  639. _, err = o.Raw(sql, reportId, content, contentSub, contentStruct, canvasColor, headResourceId, endResourceId, adminId, adminName).Exec()
  640. return
  641. }
  642. func MultiAddReportChaptersSaveLog(items []*ReportChapter, adminId int, adminRealName string) (err error) {
  643. o := orm.NewOrmUsingDB("rddp")
  644. p, err := o.Raw(`INSERT INTO report_save_log(report_id, report_chapter_id, content, content_sub,content_struct,canvas_color,head_resource_id,end_resource_id, admin_id, admin_name) VALUES (?,?,?,?,?,?,?,?,?,?)`).Prepare()
  645. if err != nil {
  646. return
  647. }
  648. defer func() {
  649. _ = p.Close()
  650. }()
  651. for _, v := range items {
  652. _, err = p.Exec(v.ReportId, v.ReportChapterId, v.Content, v.ContentSub, v.ContentStruct, v.CanvasColor, v.HeadResourceId, v.EndResourceId, adminId, adminRealName)
  653. if err != nil {
  654. return
  655. }
  656. }
  657. return
  658. }
  659. type SaveReportContentResp struct {
  660. ReportId int `description:"报告id"`
  661. }
  662. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  663. o := orm.NewOrmUsingDB("rddp")
  664. sql := `UPDATE report SET report_code=? WHERE id=? `
  665. _, err = o.Raw(sql, reportCode, reportId).Exec()
  666. return
  667. }
  668. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  669. o := orm.NewOrmUsingDB("rddp")
  670. if item.ThsMsgIsSend == 0 {
  671. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  672. _, err = o.Raw(sql, item.Id).Exec()
  673. }
  674. return
  675. }
  676. type ThsSendTemplateMsgReq struct {
  677. ReportId []int `description:"报告id"`
  678. }
  679. type PublishDayWeekReportReq struct {
  680. ReportId int `description:"报告ID"`
  681. }
  682. // SaveDayWeekReportReq 新增晨报周报请求体
  683. type SaveDayWeekReportReq struct {
  684. ReportId int `description:"报告ID"`
  685. Title string `description:"标题"`
  686. ReportType string `description:"一级分类ID"`
  687. Author string `description:"作者"`
  688. CreateTime string `description:"创建时间"`
  689. }
  690. // GetDayWeekReportStage 获取晨报周报期数
  691. func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int, err error) {
  692. o := orm.NewOrmUsingDB("rddp")
  693. sql := " SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first = ? AND create_time > ? "
  694. o.Raw(sql, classifyIdFirst, yearStart).QueryRow(&count)
  695. return
  696. }
  697. // GetReportByReportId 主键获取报告
  698. func GetReportByReportId(reportId int) (item *Report, err error) {
  699. o := orm.NewOrmUsingDB("rddp")
  700. sql := `SELECT * FROM report WHERE id = ?`
  701. err = o.Raw(sql, reportId).QueryRow(&item)
  702. return
  703. }
  704. // GetReportByOldReportId 根据老报告id主键获取报告
  705. func GetReportByOldReportId(reportId int) (item *Report, err error) {
  706. o := orm.NewOrmUsingDB("rddp")
  707. sql := `SELECT * FROM report WHERE old_report_id = ?`
  708. err = o.Raw(sql, reportId).QueryRow(&item)
  709. return
  710. }
  711. // DeleteDayWeekReportAndChapter 删除晨周报及章节
  712. func DeleteDayWeekReportAndChapter(reportId int) (err error) {
  713. o := orm.NewOrmUsingDB("rddp")
  714. to, err := o.Begin()
  715. if err != nil {
  716. return
  717. }
  718. defer func() {
  719. if err != nil {
  720. _ = to.Rollback()
  721. } else {
  722. _ = to.Commit()
  723. }
  724. }()
  725. sql := ` DELETE FROM report WHERE id = ? LIMIT 1 `
  726. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  727. return
  728. }
  729. sql = ` DELETE FROM report_chapter WHERE report_id = ? `
  730. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  731. return
  732. }
  733. return
  734. }
  735. // UpdateReport 更新报告
  736. func (reportInfo *Report) UpdateReport(cols []string) (err error) {
  737. o := orm.NewOrmUsingDB("rddp")
  738. _, err = o.Update(reportInfo, cols...)
  739. return
  740. }
  741. // ReportDetailView
  742. // @Description: 晨周报详情
  743. type ReportDetailView struct {
  744. *ReportDetail
  745. ChapterList []*ReportChapter
  746. GrandAdminList []ReportDetailViewAdmin
  747. PermissionList []ReportDetailViewPermission
  748. }
  749. // ReportDetailViewAdmin
  750. // @Description: 报告里面的授权人
  751. type ReportDetailViewAdmin struct {
  752. AdminId int
  753. AdminName string
  754. }
  755. // ReportDetailViewPermission
  756. // @Description: 报告分类关联的品种权限
  757. type ReportDetailViewPermission struct {
  758. PermissionId int
  759. PermissionName string
  760. }
  761. func GetUnPublishDayReport(startTime time.Time, endTime time.Time) (item *Report, err error) {
  762. o := orm.NewOrmUsingDB("rddp")
  763. sql := ` SELECT
  764. *
  765. FROM
  766. report AS a
  767. WHERE
  768. a.has_chapter = 1
  769. AND a.chapter_type = "day"
  770. AND a.state = 1
  771. AND (
  772. a.create_time BETWEEN ? AND ?
  773. )
  774. ORDER BY
  775. a.create_time DESC
  776. LIMIT 1 `
  777. err = o.Raw(sql, startTime, endTime).QueryRow(&item)
  778. return
  779. }
  780. type ElasticReportDetail struct {
  781. ReportId int `description:"报告ID"`
  782. ReportChapterId int `description:"报告章节ID"`
  783. Title string `description:"标题"`
  784. Abstract string `description:"摘要"`
  785. BodyContent string `description:"内容"`
  786. PublishTime string `description:"发布时间"`
  787. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  788. Author string `description:"作者"`
  789. ClassifyIdFirst int `description:"一级分类ID"`
  790. ClassifyNameFirst string `description:"一级分类名称"`
  791. ClassifyIdSecond int `description:"二级分类ID"`
  792. ClassifyNameSecond string `description:"二级分类名称"`
  793. Categories string `description:"关联的品种名称(包括品种别名)"`
  794. StageStr string `description:"报告期数"`
  795. }
  796. // GetLastPublishedDayWeekReport 获取上一篇已发布的晨周报
  797. func GetLastPublishDayWeekReport(chapterType string) (item *Report, err error) {
  798. o := orm.NewOrmUsingDB("rddp")
  799. sql := ` SELECT * FROM report WHERE has_chapter = 1 AND chapter_type = ? AND state = 2 ORDER BY publish_time DESC LIMIT 1 `
  800. err = o.Raw(sql, chapterType).QueryRow(&item)
  801. return
  802. }
  803. // GetNewReportExist
  804. func GetNewReportExist(oldReportId int) (item *Report, err error) {
  805. o := orm.NewOrmUsingDB("rddp")
  806. sql := ` SELECT id FROM report WHERE old_report_id = ? LIMIT 1 `
  807. err = o.Raw(sql, oldReportId).QueryRow(&item)
  808. return
  809. }
  810. // PublishReportAndChapter 发布报告及章节
  811. func PublishReportAndChapter(reportInfo *Report, publishIds, unPublishIds []int, isPublishReport bool, cols []string) (err error) {
  812. o := orm.NewOrmUsingDB("rddp")
  813. to, err := o.Begin()
  814. if err != nil {
  815. return
  816. }
  817. defer func() {
  818. if err != nil {
  819. _ = to.Rollback()
  820. } else {
  821. _ = to.Commit()
  822. }
  823. }()
  824. // 更新报告
  825. if isPublishReport {
  826. if _, err = to.Update(reportInfo, cols...); err != nil {
  827. return
  828. }
  829. }
  830. // 发布章节
  831. if len(publishIds) > 0 {
  832. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  833. _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
  834. }
  835. if len(unPublishIds) > 0 {
  836. 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)) + `) `
  837. _, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
  838. }
  839. return
  840. }
  841. func GetSyncEmptyVideoReport() (list []*Report, err error) {
  842. o := orm.NewOrmUsingDB("rddp")
  843. sql := ` SELECT id FROM report WHERE old_report_id > 0 AND state = 2 AND chapter_type = "" AND (video_size = "" OR video_play_seconds = "")
  844. UNION ALL
  845. SELECT DISTINCT report_id FROM report_chapter WHERE publish_state = 2 AND (video_size = "" OR video_play_seconds = "") `
  846. _, err = o.Raw(sql).QueryRows(&list)
  847. return
  848. }
  849. // PublishReportById 发布报告
  850. func PublishReportById(reportId int, publishTime time.Time) (err error) {
  851. o := orm.NewOrmUsingDB("rddp")
  852. sql := `UPDATE report SET state = 2, publish_time = ?, pre_publish_time=null, pre_msg_send=0, modify_time = NOW() WHERE id = ? `
  853. _, err = o.Raw(sql, publishTime, reportId).Exec()
  854. return
  855. }
  856. // ResetReportById 重置报告状态
  857. func ResetReportById(reportId, state int) (err error) {
  858. o := orm.NewOrmUsingDB("rddp")
  859. sql := `UPDATE report SET state = ?, pre_publish_time = null, pre_msg_send = 0, modify_time = NOW() WHERE id = ?`
  860. _, err = o.Raw(sql, state, reportId).Exec()
  861. return
  862. }
  863. // GetCommentReportByReportId 查询有留言的报告列表
  864. func GetCommentReportByReportId(condition string, pars []interface{}, startSize, pageSize int) (list []*Report, err error) {
  865. o := orm.NewOrmUsingDB("rddp")
  866. sql := `SELECT
  867. id,
  868. create_time,
  869. title,
  870. classify_name_first,
  871. classify_id_first,
  872. classify_name_second,
  873. classify_id_second,
  874. state,
  875. IF
  876. ( publish_time, publish_time, create_time ) AS publish_time
  877. FROM
  878. report
  879. WHERE
  880. 1=1
  881. `
  882. if condition != "" {
  883. sql += condition
  884. }
  885. sql += ` ORDER BY publish_time DESC , title ASC LIMIT ?,?`
  886. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  887. return
  888. }
  889. // GetCommentReportByReportIdOrderBy 查询有留言的报告列表(指定排序)
  890. func GetCommentReportByReportIdOrderBy(condition string, pars []interface{}, startSize, pageSize int, orderBy string) (list []*Report, err error) {
  891. o := orm.NewOrmUsingDB("rddp")
  892. sql := `SELECT
  893. id,
  894. create_time,
  895. title,
  896. classify_name_first,
  897. classify_id_first,
  898. classify_name_second,
  899. classify_id_second,
  900. state,
  901. IF
  902. ( publish_time, publish_time, create_time ) AS publish_time
  903. FROM
  904. report
  905. WHERE
  906. 1=1
  907. `
  908. if condition != "" {
  909. sql += condition
  910. }
  911. if orderBy == `` {
  912. sql += ` ORDER BY publish_time DESC , title ASC `
  913. } else {
  914. sql += orderBy
  915. }
  916. sql += ` LIMIT ?,? `
  917. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  918. return
  919. }
  920. // GetCommentReportTotalByReportId 查询有留言的报告列表总数
  921. func GetCommentReportTotalByReportId(condition string, pars []interface{}) (total int64, err error) {
  922. o := orm.NewOrmUsingDB("rddp")
  923. sql := `SELECT count(*)
  924. FROM report WHERE 1=1`
  925. if condition != "" {
  926. sql += condition
  927. }
  928. err = o.Raw(sql, pars).QueryRow(&total)
  929. return
  930. }
  931. // 点赞相关的报告列表
  932. type LikeReportItem struct {
  933. ReportId int `description:"报告Id"`
  934. ReportChapterId int `description:"报告章节Id"`
  935. ClassifyIdFirst int `description:"一级分类id"`
  936. ClassifyNameFirst string `description:"一级分类名称"`
  937. ClassifyIdSecond int `description:"二级分类id"`
  938. ClassifyNameSecond string `description:"二级分类名称"`
  939. ReportChapterTypeId int `description:"章节类型"`
  940. ReportChapterTypeName string `description:"品种名称"`
  941. PublishTime time.Time `description:"发布时间" `
  942. Title string `description:"标题"`
  943. }
  944. // GetLikeReportByReportIdReportChapterId 获取有被点赞的报告列表
  945. func GetLikeReportByReportIdReportChapterId(reportIds string, chapterIds string, orderStr string, startSize, pageSize int) (list []*LikeReportItem, err error) {
  946. o := orm.NewOrmUsingDB("rddp")
  947. sql := `( SELECT
  948. id AS report_id,
  949. 0 AS report_chapter_id,
  950. classify_id_first,
  951. classify_id_second,
  952. classify_name_first,
  953. classify_name_second,
  954. 0 as report_chapter_type_id,
  955. "" as report_chapter_type_name,
  956. publish_time,
  957. title
  958. FROM
  959. report
  960. WHERE
  961. classify_name_first != "晨报"
  962. AND classify_name_first != "周报"
  963. AND id in (` + reportIds + `)
  964. )
  965. UNION
  966. ( SELECT
  967. report_id,
  968. report_chapter_id,
  969. classify_id_first,
  970. 0 as classify_id_second,
  971. classify_name_first,
  972. null as classify_name_second,
  973. type_id as report_chapter_type_id,
  974. type_name as report_chapter_type_name,
  975. publish_time,
  976. title
  977. FROM
  978. report_chapter
  979. WHERE
  980. report_chapter_id in (` + chapterIds + `)
  981. )`
  982. if orderStr != "" {
  983. sql += ` ORDER BY FIELD(CONCAT(report_id, "-",report_chapter_id),` + orderStr + `)`
  984. } else {
  985. sql += ` ORDER BY publish_time DESC, report_id Desc`
  986. }
  987. sql += ` LIMIT ?,?`
  988. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  989. return
  990. }
  991. // GetLikeReportTotalByReportIdReportChapterId 获取有被点赞的报告列表总数
  992. func GetLikeReportTotalByReportIdReportChapterId(reportIds string, chapterIds string) (total int64, err error) {
  993. o := orm.NewOrmUsingDB("rddp")
  994. sql := `select count(*) from (( SELECT
  995. id AS report_id,
  996. 0 AS report_chapter_id,
  997. classify_id_first,
  998. classify_id_second,
  999. classify_name_first,
  1000. classify_name_second,
  1001. 0 as report_chapter_type_id,
  1002. publish_time,
  1003. title
  1004. FROM
  1005. report
  1006. WHERE
  1007. classify_name_first != "晨报"
  1008. AND classify_name_first != "周报"
  1009. AND id in (` + reportIds + `)
  1010. )
  1011. UNION
  1012. ( SELECT
  1013. report_id,
  1014. report_chapter_id,
  1015. classify_id_first,
  1016. 0 as classify_id_second,
  1017. classify_name_first,
  1018. null as classify_name_second,
  1019. type_id as report_chapter_type_id,
  1020. publish_time,
  1021. title
  1022. FROM
  1023. report_chapter
  1024. WHERE
  1025. report_chapter_id in (` + chapterIds + `)
  1026. )) r`
  1027. err = o.Raw(sql).QueryRow(&total)
  1028. return
  1029. }
  1030. // GetPageReportList 分页获取报告列表
  1031. func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  1032. o := orm.NewOrmUsingDB("rddp")
  1033. sql := `SELECT * FROM report WHERE 1=1 `
  1034. sql += condition
  1035. sql += ` ORDER BY modify_time DESC`
  1036. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  1037. err = o.Raw(totalSql, pars).QueryRow(&total)
  1038. if err != nil {
  1039. return
  1040. }
  1041. sql += ` LIMIT ?,? `
  1042. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1043. return
  1044. }
  1045. // SunCodeReq 获取太阳码请求体
  1046. type SunCodeReq struct {
  1047. CodePage string `json:"CodePage" description:"太阳码page"`
  1048. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  1049. }
  1050. // YbPcSuncode 活动海报表
  1051. type YbPcSuncode struct {
  1052. SuncodeID uint32 `orm:"column(suncode_id);pk" `
  1053. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  1054. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  1055. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  1056. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  1057. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  1058. }
  1059. // GetYbPcSunCode 获取太阳码
  1060. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  1061. o := orm.NewOrmUsingDB("weekly")
  1062. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  1063. err = o.Raw(sql, scene, page).QueryRow(&item)
  1064. return
  1065. }
  1066. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  1067. o := orm.NewOrmUsingDB("weekly")
  1068. _, err = o.Insert(item)
  1069. return
  1070. }
  1071. // YbSuncodePars 小程序太阳码scene参数
  1072. type YbSuncodePars struct {
  1073. ID uint32 `orm:"column(id);pk" `
  1074. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  1075. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  1076. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  1077. }
  1078. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  1079. o := orm.NewOrmUsingDB("weekly")
  1080. _, err = o.Insert(item)
  1081. return
  1082. }
  1083. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  1084. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1085. o := orm.NewOrmUsingDB("rddp")
  1086. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  1087. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1088. return
  1089. }
  1090. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  1091. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1092. o := orm.NewOrmUsingDB("rddp")
  1093. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  1094. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1095. return
  1096. }
  1097. // UpdateReportSecondClassifyFirstNameByClassifyId 更新报告二级分类的一级分类名称和id
  1098. func UpdateReportSecondClassifyFirstNameByClassifyId(classifyId, newClassifyId int, classifyName string) (err error) {
  1099. o := orm.NewOrmUsingDB("rddp")
  1100. sql := " UPDATE report SET classify_name_first = ?, classify_id_first = ? WHERE classify_id_second = ? "
  1101. _, err = o.Raw(sql, classifyName, newClassifyId, classifyId).Exec()
  1102. return
  1103. }
  1104. // GetEmptyContentSubPPTReport 获取前两章为空的PPT报告
  1105. func GetEmptyContentSubPPTReport() (list []*Report, err error) {
  1106. sql := `SELECT
  1107. r.id,
  1108. r.content,
  1109. r.content_sub
  1110. FROM
  1111. report AS r
  1112. JOIN ppt_v2 AS p ON r.id = p.report_id
  1113. WHERE
  1114. p.report_id > 0 AND r.content_sub = ""`
  1115. _, err = orm.NewOrmUsingDB("rddp").Raw(sql).QueryRows(&list)
  1116. return
  1117. }
  1118. // ModifyReportAuthor 更改报告作者
  1119. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  1120. //产品权限
  1121. oRddp := orm.NewOrmUsingDB("rddp")
  1122. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  1123. if condition != "" {
  1124. sql += condition
  1125. }
  1126. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  1127. return
  1128. }
  1129. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  1130. o := orm.NewOrmUsingDB("rddp")
  1131. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  1132. _, err = o.Raw(sql1, reportId).Exec()
  1133. if err != nil {
  1134. return
  1135. }
  1136. //修改音频标题
  1137. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  1138. _, err = o.Raw(sql2, reportId).Exec()
  1139. return
  1140. }
  1141. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  1142. o := orm.NewOrmUsingDB("rddp")
  1143. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  1144. _, err = o.Raw(sql1, reportId).Exec()
  1145. if err != nil {
  1146. return
  1147. }
  1148. //修改音频标题
  1149. 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)`
  1150. _, err = o.Raw(sql2, reportId).Exec()
  1151. return
  1152. }
  1153. // MarkEditReport 标记编辑英文研报的请求数据
  1154. type MarkEditReport struct {
  1155. ReportId int `description:"研报id"`
  1156. ReportChapterId int `description:"研报章节id"`
  1157. Status int `description:"标记状态,1:编辑中,2:编辑完成"`
  1158. }
  1159. type MarkReportResp struct {
  1160. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  1161. Msg string `description:"提示信息"`
  1162. Editor string `description:"编辑者姓名"`
  1163. }
  1164. type MarkReportItem struct {
  1165. AdminId int `description:"编辑者ID"`
  1166. Editor string `description:"编辑者姓名"`
  1167. ReportClassifyNameFirst string
  1168. }
  1169. // GetReportByCondition 获取报告
  1170. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  1171. o := orm.NewOrmUsingDB("rddp")
  1172. fields := `*`
  1173. if len(fieldArr) > 0 {
  1174. fields = strings.Join(fieldArr, ",")
  1175. }
  1176. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  1177. sql += condition
  1178. order := ` ORDER BY modify_time DESC`
  1179. if orderRule != `` {
  1180. order = orderRule
  1181. }
  1182. sql += order
  1183. if isPage {
  1184. sql += ` LIMIT ?,?`
  1185. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1186. } else {
  1187. _, err = o.Raw(sql, pars).QueryRows(&items)
  1188. }
  1189. return
  1190. }
  1191. // ModifyReportMsgIsSendV2 更新报告消息状态
  1192. func ModifyReportMsgIsSendV2(reportId int) (err error) {
  1193. o := orm.NewOrmUsingDB("rddp")
  1194. sql := `UPDATE report SET msg_is_send = 1, ths_msg_is_send = 1, msg_send_time = NOW() WHERE id = ? LIMIT 1`
  1195. _, err = o.Raw(sql, reportId).Exec()
  1196. return
  1197. }
  1198. // SetPrePublishReportById 设置定时发布
  1199. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  1200. o := orm.NewOrmUsingDB("rddp")
  1201. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  1202. _, err = o.Raw(sql, prePublishTime, preMsgSend, reportId).Exec()
  1203. return
  1204. }
  1205. // ReportSubmitApproveReq 提交审批请求体
  1206. type ReportSubmitApproveReq struct {
  1207. ReportId int `description:"报告ID"`
  1208. }
  1209. // ReportCancelApproveReq 撤回审批请求体
  1210. type ReportCancelApproveReq struct {
  1211. ReportId int `description:"报告ID"`
  1212. }
  1213. func (m *Report) GetItemById(id int) (item *Report, err error) {
  1214. o := orm.NewOrmUsingDB("rddp")
  1215. sql := `SELECT * FROM report WHERE id = ? LIMIT 1`
  1216. err = o.Raw(sql, id).QueryRow(&item)
  1217. return
  1218. }
  1219. // GetReportStateCount 获取指定状态的报告数量
  1220. func GetReportStateCount(state int) (count int, err error) {
  1221. o := orm.NewOrmUsingDB("rddp")
  1222. sql := `SELECT COUNT(1) AS count FROM report WHERE state = ?`
  1223. err = o.Raw(sql, state).QueryRow(&count)
  1224. return
  1225. }
  1226. // UpdateReportsStateByCond 批量更新报告状态
  1227. func UpdateReportsStateByCond(classifyFirstId, classifySecondId, oldState, newState int) (err error) {
  1228. o := orm.NewOrmUsingDB("rddp")
  1229. cond := ``
  1230. if classifyFirstId > 0 {
  1231. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  1232. }
  1233. if classifySecondId > 0 {
  1234. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  1235. }
  1236. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  1237. _, err = o.Raw(sql, newState, oldState).Exec()
  1238. return
  1239. }
  1240. // UpdateReportsStateBySecondIds 批量更新二级分类报告状态
  1241. func UpdateReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  1242. if len(secondIds) <= 0 {
  1243. return
  1244. }
  1245. o := orm.NewOrmUsingDB("rddp")
  1246. // (有审批流的)未发布->待提交
  1247. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1248. _, err = o.Raw(sql, newState, oldState, secondIds).Exec()
  1249. if err != nil {
  1250. return
  1251. }
  1252. // (无审批流的)待提交->未发布
  1253. sql = fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1254. _, err = o.Raw(sql, oldState, newState, secondIds).Exec()
  1255. return
  1256. }
  1257. // GetReportPdfUrlReq 获取报告pdf地址请求体
  1258. type GetReportPdfUrlReq struct {
  1259. ReportUrl string `description:"报告Url"`
  1260. ReportCode string `description:"报告Code"`
  1261. Type int `description:"类型 1-pdf 2-图片"`
  1262. }
  1263. func ModifyReportPdfUrl(reportId int, detailPdfUrl string) (err error) {
  1264. o := orm.NewOrmUsingDB("rddp")
  1265. sql := `UPDATE report SET detail_pdf_url=? WHERE id=? `
  1266. _, err = o.Raw(sql, detailPdfUrl, reportId).Exec()
  1267. return
  1268. }
  1269. func ModifyReportImgUrl(reportId int, detailImgUrl string) (err error) {
  1270. o := orm.NewOrmUsingDB("rddp")
  1271. sql := `UPDATE report SET detail_img_url=? WHERE id=? `
  1272. _, err = o.Raw(sql, detailImgUrl, reportId).Exec()
  1273. return
  1274. }