report.go 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  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. ReportCode string `description:"报告唯一编码"`
  325. // eta1.8.3(研报改版)相关内容
  326. ContentStruct string `description:"内容组件"`
  327. LastModifyAdminId int `description:"最后更新人ID"`
  328. LastModifyAdminName string `description:"最后更新人姓名"`
  329. ContentModifyTime time.Time `description:"内容更新时间"`
  330. Pv int `description:"pv"`
  331. Uv int `description:"uv"`
  332. HeadImg string `description:"报告头图地址"`
  333. EndImg string `description:"报告尾图地址"`
  334. CanvasColor string `description:"画布颜色"`
  335. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  336. HeadResourceId int `description:"版头资源ID"`
  337. EndResourceId int `description:"版尾资源ID"`
  338. ClassifyIdThird int `description:"三级分类id"`
  339. ClassifyNameThird string `description:"三级分类名称"`
  340. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  341. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  342. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  343. ReportCreateTime time.Time `description:"报告时间创建时间"`
  344. }
  345. func GetReportById(reportId int) (item *ReportDetail, err error) {
  346. o := orm.NewOrmUsingDB("rddp")
  347. sql := `SELECT * FROM report WHERE id=?`
  348. err = o.Raw(sql, reportId).QueryRow(&item)
  349. return
  350. }
  351. func GetReportByIds(reportIds string) (list []*ReportDetail, err error) {
  352. o := orm.NewOrmUsingDB("rddp")
  353. sql := `SELECT * FROM report WHERE id in ` + reportIds
  354. _, err = o.Raw(sql).QueryRows(&list)
  355. return
  356. }
  357. // GetSimpleReportByIds 根据报告ID查询报告基本信息
  358. func GetSimpleReportByIds(reportIds []int) (list []*ReportDetail, err error) {
  359. if len(reportIds) == 0 {
  360. return
  361. }
  362. o := orm.NewOrmUsingDB("rddp")
  363. sql := `SELECT id, title FROM report WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  364. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  365. return
  366. }
  367. // GetReportStage
  368. // @Description: 获取报告的最大期数(每一年的最大期数)
  369. // @author: Roc
  370. // @datetime 2024-06-03 17:44:14
  371. // @param classifyIdFirst int
  372. // @param classifyIdSecond int
  373. // @param classifyIdThird int
  374. // @return count int
  375. // @return err error
  376. func GetReportStage(classifyIdFirst, classifyIdSecond, classifyIdThird int) (count int, err error) {
  377. o := orm.NewOrmUsingDB("rddp")
  378. classifyId := classifyIdThird
  379. if classifyId <= 0 {
  380. classifyId = classifyIdSecond
  381. }
  382. if classifyId <= 0 {
  383. classifyId = classifyIdFirst
  384. }
  385. if classifyId <= 0 {
  386. err = errors.New("错误的分类id")
  387. return
  388. }
  389. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  390. sql := `SELECT MAX(stage) AS max_stage FROM report WHERE create_time > ? `
  391. if classifyIdThird > 0 {
  392. sql += " AND classify_id_third = ? "
  393. } else if classifyIdSecond > 0 {
  394. sql += " AND classify_id_second = ? "
  395. } else {
  396. sql = " AND classify_id_first = ? "
  397. }
  398. o.Raw(sql, yearStart, classifyId).QueryRow(&count)
  399. return
  400. }
  401. // GetReportStageEdit
  402. // @Description: 获取报告的最大期数(每一年的最大期数)
  403. // @author: Roc
  404. // @datetime 2024-06-04 13:50:34
  405. // @param classifyIdFirst int
  406. // @param classifyIdSecond int
  407. // @param classifyIdThird int
  408. // @param reportId int
  409. // @return count int
  410. // @return err error
  411. func GetReportStageEdit(classifyIdFirst, classifyIdSecond, classifyIdThird, reportId int) (count int, err error) {
  412. classifyId := classifyIdThird
  413. if classifyId <= 0 {
  414. classifyId = classifyIdSecond
  415. }
  416. if classifyId <= 0 {
  417. classifyId = classifyIdFirst
  418. }
  419. if classifyId <= 0 {
  420. err = errors.New("错误的分类id")
  421. return
  422. }
  423. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  424. sql := `SELECT MAX(stage) AS max_stage FROM report WHERE create_time > ? AND id<>? `
  425. if classifyIdThird > 0 {
  426. sql += " AND classify_id_third = ? "
  427. } else if classifyIdSecond > 0 {
  428. sql += " AND classify_id_second = ? "
  429. } else {
  430. sql = " AND classify_id_first = ? "
  431. }
  432. o := orm.NewOrmUsingDB("rddp")
  433. o.Raw(sql, yearStart, reportId, classifyId).QueryRow(&count)
  434. return
  435. }
  436. type PublishReq struct {
  437. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  438. ReportUrl string `description:"报告Url"`
  439. }
  440. type PublishCancelReq struct {
  441. ReportIds int `description:"报告id"`
  442. }
  443. type DeleteReq struct {
  444. ReportIds int `description:"报告id"`
  445. }
  446. type AddReq struct {
  447. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  448. ClassifyIdFirst int `description:"一级分类id"`
  449. ClassifyNameFirst string `description:"一级分类名称"`
  450. ClassifyIdSecond int `description:"二级分类id"`
  451. ClassifyNameSecond string `description:"二级分类名称"`
  452. ClassifyIdThird int `description:"三级分类id"`
  453. ClassifyNameThird string `description:"三级分类名称"`
  454. Title string `description:"标题"`
  455. Abstract string `description:"摘要"`
  456. Author string `description:"作者"`
  457. Frequency string `description:"频度"`
  458. State int `description:"状态:1:未发布,2:已发布"`
  459. Content string `description:"内容"`
  460. CreateTime string `description:"创建时间"`
  461. ReportVersion int `description:"1:旧版,2:新版"`
  462. ContentStruct string `description:"内容组件"`
  463. HeadImg string `description:"报告头图地址"`
  464. EndImg string `description:"报告尾图地址"`
  465. CanvasColor string `description:"画布颜色"`
  466. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  467. HeadResourceId int `description:"版头资源ID"`
  468. EndResourceId int `description:"版尾资源ID"`
  469. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  470. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  471. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  472. InheritReportId int `description:"待继承的报告ID"`
  473. GrantAdminIdList []int `description:"授权用户id列表"`
  474. }
  475. type PrePublishReq struct {
  476. ReportId int `description:"报告id"`
  477. PrePublishTime string `description:"预发布时间"`
  478. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  479. ReportUrl string `description:"报告Url"`
  480. }
  481. type AddResp struct {
  482. ReportId int64 `description:"报告id"`
  483. ReportCode string `description:"报告code"`
  484. }
  485. func AddReport(item *Report) (lastId int64, err error) {
  486. o := orm.NewOrmUsingDB("rddp")
  487. lastId, err = o.Insert(item)
  488. return
  489. }
  490. type EditReq struct {
  491. ReportId int64 `description:"报告id"`
  492. ClassifyIdFirst int `description:"一级分类id"`
  493. ClassifyNameFirst string `description:"一级分类名称"`
  494. ClassifyIdSecond int `description:"二级分类id"`
  495. ClassifyNameSecond string `description:"二级分类名称"`
  496. ClassifyIdThird int `description:"三级分类id"`
  497. ClassifyNameThird string `description:"三级分类名称"`
  498. Title string `description:"标题"`
  499. Abstract string `description:"摘要"`
  500. Author string `description:"作者"`
  501. Frequency string `description:"频度"`
  502. State int `description:"状态:1:未发布,2:已发布"`
  503. Content string `description:"内容"`
  504. CreateTime string `description:"创建时间"`
  505. ContentStruct string `description:"内容组件"`
  506. HeadImg string `description:"报告头图地址"`
  507. EndImg string `description:"报告尾图地址"`
  508. CanvasColor string `description:"画布颜色"`
  509. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  510. HeadResourceId int `description:"版头资源ID"`
  511. EndResourceId int `description:"版尾资源ID"`
  512. //CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  513. //ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  514. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  515. GrantAdminIdList []int `description:"授权用户id列表"`
  516. }
  517. type EditResp struct {
  518. ReportId int64 `description:"报告id"`
  519. ReportCode string `description:"报告code"`
  520. }
  521. func EditReport(item *Report, reportId int64) (err error) {
  522. o := orm.NewOrmUsingDB("rddp")
  523. sql := `UPDATE report
  524. SET
  525. classify_id_first =?,
  526. classify_name_first = ?,
  527. classify_id_second = ?,
  528. classify_name_second = ?,
  529. title = ?,
  530. abstract = ?,
  531. author = ?,
  532. frequency = ?,
  533. state = ?,
  534. content = ?,
  535. content_sub = ?,
  536. stage =?,
  537. create_time = ?,
  538. modify_time = ?
  539. WHERE id = ? `
  540. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  541. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Exec()
  542. return
  543. }
  544. func (m *Report) Update(cols []string) (err error) {
  545. o := orm.NewOrmUsingDB("rddp")
  546. _, err = o.Update(m, cols...)
  547. return
  548. }
  549. type ReportDetailReq struct {
  550. ReportId int `description:"报告id"`
  551. }
  552. type ClassifyIdDetailReq struct {
  553. ClassifyIdFirst int `description:"报告一级分类id"`
  554. ClassifyIdSecond int `description:"报告二级分类id"`
  555. }
  556. func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) {
  557. o := orm.NewOrmUsingDB("rddp")
  558. sql := ` SELECT * FROM report WHERE 1=1 `
  559. if classifyIdSecond > 0 {
  560. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  561. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  562. } else {
  563. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  564. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  565. }
  566. return
  567. }
  568. type SendTemplateMsgReq struct {
  569. ReportId int `description:"报告id"`
  570. }
  571. func ModifyReportMsgIsSend(reportId int) (err error) {
  572. o := orm.NewOrmUsingDB("rddp")
  573. report, err := GetReportById(reportId)
  574. if err != nil {
  575. return
  576. }
  577. if report.MsgIsSend == 0 {
  578. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? `
  579. _, err = o.Raw(sql, reportId).Exec()
  580. }
  581. return
  582. }
  583. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  584. o := orm.NewOrmUsingDB("rddp")
  585. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  586. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  587. return
  588. }
  589. type ReportItem struct {
  590. Id int `orm:"column(id)" description:"报告Id"`
  591. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  592. ClassifyIdFirst int `description:"一级分类id"`
  593. ClassifyNameFirst string `description:"一级分类名称"`
  594. ClassifyIdSecond int `description:"二级分类id"`
  595. ClassifyNameSecond string `description:"二级分类名称"`
  596. Title string `description:"标题"`
  597. Abstract string `description:"摘要"`
  598. Author string `description:"作者"`
  599. Frequency string `description:"频度"`
  600. CreateTime time.Time `description:"创建时间"`
  601. ModifyTime time.Time `description:"修改时间"`
  602. State int `description:"1:未发布,2:已发布"`
  603. PublishTime time.Time `description:"发布时间"`
  604. Stage int `description:"期数"`
  605. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  606. Content string `description:"内容"`
  607. VideoUrl string `description:"音频文件URL"`
  608. VideoName string `description:"音频文件名称"`
  609. VideoPlaySeconds string `description:"音频播放时长"`
  610. ContentSub string `description:"内容前两个章节"`
  611. }
  612. func GetReportItemById(reportId int) (item *ReportItem, err error) {
  613. o := orm.NewOrmUsingDB("rddp")
  614. sql := `SELECT * FROM report WHERE id=?`
  615. err = o.Raw(sql, reportId).QueryRow(&item)
  616. return
  617. }
  618. type SaveReportContent struct {
  619. Content string `description:"内容"`
  620. ReportId int `description:"报告id"`
  621. NoChange int `description:"内容是否未改变:1:内容未改变"`
  622. // 以下是智能研报相关
  623. ContentStruct string `description:"内容组件"`
  624. HeadImg string `description:"报告头图地址"`
  625. EndImg string `description:"报告尾图地址"`
  626. CanvasColor string `description:"画布颜色"`
  627. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  628. HeadResourceId int `description:"版头资源ID"`
  629. EndResourceId int `description:"版尾资源ID"`
  630. }
  631. func EditReportContent(reportId int, content, contentSub string) (err error) {
  632. o := orm.NewOrmUsingDB("rddp")
  633. sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  634. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  635. return
  636. }
  637. func AddReportSaveLog(reportId, adminId int, content, contentSub, contentStruct, canvasColor, adminName string, headResourceId, endResourceId int) (err error) {
  638. o := orm.NewOrmUsingDB("rddp")
  639. 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 (?,?,?,?,?) `
  640. _, err = o.Raw(sql, reportId, content, contentSub, contentStruct, canvasColor, headResourceId, endResourceId, adminId, adminName).Exec()
  641. return
  642. }
  643. func MultiAddReportChaptersSaveLog(items []*ReportChapter, adminId int, adminRealName string) (err error) {
  644. o := orm.NewOrmUsingDB("rddp")
  645. p, err := o.Raw(`INSERT INTO report_save_log(report_id, report_chapter_id, content, content_sub,content_struct,admin_id, admin_name) VALUES (?,?,?,?,?,?,?)`).Prepare()
  646. if err != nil {
  647. return
  648. }
  649. defer func() {
  650. _ = p.Close()
  651. }()
  652. for _, v := range items {
  653. _, err = p.Exec(v.ReportId, v.ReportChapterId, v.Content, v.ContentSub, v.ContentStruct, adminId, adminRealName)
  654. if err != nil {
  655. return
  656. }
  657. }
  658. return
  659. }
  660. type SaveReportContentResp struct {
  661. ReportId int `description:"报告id"`
  662. }
  663. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  664. o := orm.NewOrmUsingDB("rddp")
  665. sql := `UPDATE report SET report_code=? WHERE id=? `
  666. _, err = o.Raw(sql, reportCode, reportId).Exec()
  667. return
  668. }
  669. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  670. o := orm.NewOrmUsingDB("rddp")
  671. if item.ThsMsgIsSend == 0 {
  672. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  673. _, err = o.Raw(sql, item.Id).Exec()
  674. }
  675. return
  676. }
  677. type ThsSendTemplateMsgReq struct {
  678. ReportId []int `description:"报告id"`
  679. }
  680. type PublishDayWeekReportReq struct {
  681. ReportId int `description:"报告ID"`
  682. }
  683. // SaveDayWeekReportReq 新增晨报周报请求体
  684. type SaveDayWeekReportReq struct {
  685. ReportId int `description:"报告ID"`
  686. Title string `description:"标题"`
  687. ReportType string `description:"一级分类ID"`
  688. Author string `description:"作者"`
  689. CreateTime string `description:"创建时间"`
  690. }
  691. // GetDayWeekReportStage 获取晨报周报期数
  692. func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int, err error) {
  693. o := orm.NewOrmUsingDB("rddp")
  694. sql := " SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first = ? AND create_time > ? "
  695. o.Raw(sql, classifyIdFirst, yearStart).QueryRow(&count)
  696. return
  697. }
  698. // GetReportByReportId 主键获取报告
  699. func GetReportByReportId(reportId int) (item *Report, err error) {
  700. o := orm.NewOrmUsingDB("rddp")
  701. sql := `SELECT * FROM report WHERE id = ?`
  702. err = o.Raw(sql, reportId).QueryRow(&item)
  703. return
  704. }
  705. // GetReportByOldReportId 根据老报告id主键获取报告
  706. func GetReportByOldReportId(reportId int) (item *Report, err error) {
  707. o := orm.NewOrmUsingDB("rddp")
  708. sql := `SELECT * FROM report WHERE old_report_id = ?`
  709. err = o.Raw(sql, reportId).QueryRow(&item)
  710. return
  711. }
  712. // DeleteDayWeekReportAndChapter 删除晨周报及章节
  713. func DeleteDayWeekReportAndChapter(reportId int) (err error) {
  714. o := orm.NewOrmUsingDB("rddp")
  715. to, err := o.Begin()
  716. if err != nil {
  717. return
  718. }
  719. defer func() {
  720. if err != nil {
  721. _ = to.Rollback()
  722. } else {
  723. _ = to.Commit()
  724. }
  725. }()
  726. sql := ` DELETE FROM report WHERE id = ? LIMIT 1 `
  727. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  728. return
  729. }
  730. sql = ` DELETE FROM report_chapter WHERE report_id = ? `
  731. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  732. return
  733. }
  734. return
  735. }
  736. // UpdateReport 更新报告
  737. func (reportInfo *Report) UpdateReport(cols []string) (err error) {
  738. o := orm.NewOrmUsingDB("rddp")
  739. _, err = o.Update(reportInfo, cols...)
  740. return
  741. }
  742. // ReportDetailView
  743. // @Description: 晨周报详情
  744. type ReportDetailView struct {
  745. *ReportDetail
  746. ChapterList []*ReportChapter
  747. GrandAdminList []ReportDetailViewAdmin
  748. PermissionList []ReportDetailViewPermission
  749. }
  750. // ReportDetailViewAdmin
  751. // @Description: 报告里面的授权人
  752. type ReportDetailViewAdmin struct {
  753. AdminId int
  754. AdminName string
  755. }
  756. // ReportDetailViewPermission
  757. // @Description: 报告分类关联的品种权限
  758. type ReportDetailViewPermission struct {
  759. PermissionId int
  760. PermissionName string
  761. }
  762. func GetUnPublishDayReport(startTime time.Time, endTime time.Time) (item *Report, err error) {
  763. o := orm.NewOrmUsingDB("rddp")
  764. sql := ` SELECT
  765. *
  766. FROM
  767. report AS a
  768. WHERE
  769. a.has_chapter = 1
  770. AND a.chapter_type = "day"
  771. AND a.state = 1
  772. AND (
  773. a.create_time BETWEEN ? AND ?
  774. )
  775. ORDER BY
  776. a.create_time DESC
  777. LIMIT 1 `
  778. err = o.Raw(sql, startTime, endTime).QueryRow(&item)
  779. return
  780. }
  781. type ElasticReportDetail struct {
  782. ReportId int `description:"报告ID"`
  783. ReportChapterId int `description:"报告章节ID"`
  784. Title string `description:"标题"`
  785. Abstract string `description:"摘要"`
  786. BodyContent string `description:"内容"`
  787. PublishTime string `description:"发布时间"`
  788. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  789. Author string `description:"作者"`
  790. ClassifyIdFirst int `description:"一级分类ID"`
  791. ClassifyNameFirst string `description:"一级分类名称"`
  792. ClassifyIdSecond int `description:"二级分类ID"`
  793. ClassifyNameSecond string `description:"二级分类名称"`
  794. Categories string `description:"关联的品种名称(包括品种别名)"`
  795. StageStr string `description:"报告期数"`
  796. }
  797. // GetLastPublishedDayWeekReport 获取上一篇已发布的晨周报
  798. func GetLastPublishDayWeekReport(chapterType string) (item *Report, err error) {
  799. o := orm.NewOrmUsingDB("rddp")
  800. sql := ` SELECT * FROM report WHERE has_chapter = 1 AND chapter_type = ? AND state = 2 ORDER BY publish_time DESC LIMIT 1 `
  801. err = o.Raw(sql, chapterType).QueryRow(&item)
  802. return
  803. }
  804. // GetNewReportExist
  805. func GetNewReportExist(oldReportId int) (item *Report, err error) {
  806. o := orm.NewOrmUsingDB("rddp")
  807. sql := ` SELECT id FROM report WHERE old_report_id = ? LIMIT 1 `
  808. err = o.Raw(sql, oldReportId).QueryRow(&item)
  809. return
  810. }
  811. // PublishReportAndChapter 发布报告及章节
  812. func PublishReportAndChapter(reportInfo *Report, publishIds, unPublishIds []int, isPublishReport bool, cols []string) (err error) {
  813. o := orm.NewOrmUsingDB("rddp")
  814. to, err := o.Begin()
  815. if err != nil {
  816. return
  817. }
  818. defer func() {
  819. if err != nil {
  820. _ = to.Rollback()
  821. } else {
  822. _ = to.Commit()
  823. }
  824. }()
  825. // 更新报告
  826. if isPublishReport {
  827. if _, err = to.Update(reportInfo, cols...); err != nil {
  828. return
  829. }
  830. }
  831. // 发布章节
  832. if len(publishIds) > 0 {
  833. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  834. _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
  835. }
  836. if len(unPublishIds) > 0 {
  837. 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)) + `) `
  838. _, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
  839. }
  840. return
  841. }
  842. func GetSyncEmptyVideoReport() (list []*Report, err error) {
  843. o := orm.NewOrmUsingDB("rddp")
  844. sql := ` SELECT id FROM report WHERE old_report_id > 0 AND state = 2 AND chapter_type = "" AND (video_size = "" OR video_play_seconds = "")
  845. UNION ALL
  846. SELECT DISTINCT report_id FROM report_chapter WHERE publish_state = 2 AND (video_size = "" OR video_play_seconds = "") `
  847. _, err = o.Raw(sql).QueryRows(&list)
  848. return
  849. }
  850. // PublishReportById 发布报告
  851. func PublishReportById(reportId int, publishTime time.Time) (err error) {
  852. o := orm.NewOrmUsingDB("rddp")
  853. sql := `UPDATE report SET state = 2, publish_time = ?, pre_publish_time=null, pre_msg_send=0, modify_time = NOW() WHERE id = ? `
  854. _, err = o.Raw(sql, publishTime, reportId).Exec()
  855. return
  856. }
  857. // ResetReportById 重置报告状态
  858. func ResetReportById(reportId, state int) (err error) {
  859. o := orm.NewOrmUsingDB("rddp")
  860. sql := `UPDATE report SET state = ?, pre_publish_time = null, pre_msg_send = 0, modify_time = NOW() WHERE id = ?`
  861. _, err = o.Raw(sql, state, reportId).Exec()
  862. return
  863. }
  864. // GetCommentReportByReportId 查询有留言的报告列表
  865. func GetCommentReportByReportId(condition string, pars []interface{}, startSize, pageSize int) (list []*Report, err error) {
  866. o := orm.NewOrmUsingDB("rddp")
  867. sql := `SELECT
  868. id,
  869. create_time,
  870. title,
  871. classify_name_first,
  872. classify_id_first,
  873. classify_name_second,
  874. classify_id_second,
  875. state,
  876. IF
  877. ( publish_time, publish_time, create_time ) AS publish_time
  878. FROM
  879. report
  880. WHERE
  881. 1=1
  882. `
  883. if condition != "" {
  884. sql += condition
  885. }
  886. sql += ` ORDER BY publish_time DESC , title ASC LIMIT ?,?`
  887. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  888. return
  889. }
  890. // GetCommentReportByReportIdOrderBy 查询有留言的报告列表(指定排序)
  891. func GetCommentReportByReportIdOrderBy(condition string, pars []interface{}, startSize, pageSize int, orderBy string) (list []*Report, err error) {
  892. o := orm.NewOrmUsingDB("rddp")
  893. sql := `SELECT
  894. id,
  895. create_time,
  896. title,
  897. classify_name_first,
  898. classify_id_first,
  899. classify_name_second,
  900. classify_id_second,
  901. state,
  902. IF
  903. ( publish_time, publish_time, create_time ) AS publish_time
  904. FROM
  905. report
  906. WHERE
  907. 1=1
  908. `
  909. if condition != "" {
  910. sql += condition
  911. }
  912. if orderBy == `` {
  913. sql += ` ORDER BY publish_time DESC , title ASC `
  914. } else {
  915. sql += orderBy
  916. }
  917. sql += ` LIMIT ?,? `
  918. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  919. return
  920. }
  921. // GetCommentReportTotalByReportId 查询有留言的报告列表总数
  922. func GetCommentReportTotalByReportId(condition string, pars []interface{}) (total int64, err error) {
  923. o := orm.NewOrmUsingDB("rddp")
  924. sql := `SELECT count(*)
  925. FROM report WHERE 1=1`
  926. if condition != "" {
  927. sql += condition
  928. }
  929. err = o.Raw(sql, pars).QueryRow(&total)
  930. return
  931. }
  932. // 点赞相关的报告列表
  933. type LikeReportItem struct {
  934. ReportId int `description:"报告Id"`
  935. ReportChapterId int `description:"报告章节Id"`
  936. ClassifyIdFirst int `description:"一级分类id"`
  937. ClassifyNameFirst string `description:"一级分类名称"`
  938. ClassifyIdSecond int `description:"二级分类id"`
  939. ClassifyNameSecond string `description:"二级分类名称"`
  940. ReportChapterTypeId int `description:"章节类型"`
  941. ReportChapterTypeName string `description:"品种名称"`
  942. PublishTime time.Time `description:"发布时间" `
  943. Title string `description:"标题"`
  944. }
  945. // GetLikeReportByReportIdReportChapterId 获取有被点赞的报告列表
  946. func GetLikeReportByReportIdReportChapterId(reportIds string, chapterIds string, orderStr string, startSize, pageSize int) (list []*LikeReportItem, err error) {
  947. o := orm.NewOrmUsingDB("rddp")
  948. sql := `( SELECT
  949. id AS report_id,
  950. 0 AS report_chapter_id,
  951. classify_id_first,
  952. classify_id_second,
  953. classify_name_first,
  954. classify_name_second,
  955. 0 as report_chapter_type_id,
  956. "" as report_chapter_type_name,
  957. publish_time,
  958. title
  959. FROM
  960. report
  961. WHERE
  962. classify_name_first != "晨报"
  963. AND classify_name_first != "周报"
  964. AND id in (` + reportIds + `)
  965. )
  966. UNION
  967. ( SELECT
  968. report_id,
  969. report_chapter_id,
  970. classify_id_first,
  971. 0 as classify_id_second,
  972. classify_name_first,
  973. null as classify_name_second,
  974. type_id as report_chapter_type_id,
  975. type_name as report_chapter_type_name,
  976. publish_time,
  977. title
  978. FROM
  979. report_chapter
  980. WHERE
  981. report_chapter_id in (` + chapterIds + `)
  982. )`
  983. if orderStr != "" {
  984. sql += ` ORDER BY FIELD(CONCAT(report_id, "-",report_chapter_id),` + orderStr + `)`
  985. } else {
  986. sql += ` ORDER BY publish_time DESC, report_id Desc`
  987. }
  988. sql += ` LIMIT ?,?`
  989. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  990. return
  991. }
  992. // GetLikeReportTotalByReportIdReportChapterId 获取有被点赞的报告列表总数
  993. func GetLikeReportTotalByReportIdReportChapterId(reportIds string, chapterIds string) (total int64, err error) {
  994. o := orm.NewOrmUsingDB("rddp")
  995. sql := `select count(*) from (( SELECT
  996. id AS report_id,
  997. 0 AS report_chapter_id,
  998. classify_id_first,
  999. classify_id_second,
  1000. classify_name_first,
  1001. classify_name_second,
  1002. 0 as report_chapter_type_id,
  1003. publish_time,
  1004. title
  1005. FROM
  1006. report
  1007. WHERE
  1008. classify_name_first != "晨报"
  1009. AND classify_name_first != "周报"
  1010. AND id in (` + reportIds + `)
  1011. )
  1012. UNION
  1013. ( SELECT
  1014. report_id,
  1015. report_chapter_id,
  1016. classify_id_first,
  1017. 0 as classify_id_second,
  1018. classify_name_first,
  1019. null as classify_name_second,
  1020. type_id as report_chapter_type_id,
  1021. publish_time,
  1022. title
  1023. FROM
  1024. report_chapter
  1025. WHERE
  1026. report_chapter_id in (` + chapterIds + `)
  1027. )) r`
  1028. err = o.Raw(sql).QueryRow(&total)
  1029. return
  1030. }
  1031. // GetPageReportList 分页获取报告列表
  1032. func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  1033. o := orm.NewOrmUsingDB("rddp")
  1034. sql := `SELECT * FROM report WHERE 1=1 `
  1035. sql += condition
  1036. sql += ` ORDER BY modify_time DESC`
  1037. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  1038. err = o.Raw(totalSql, pars).QueryRow(&total)
  1039. if err != nil {
  1040. return
  1041. }
  1042. sql += ` LIMIT ?,? `
  1043. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1044. return
  1045. }
  1046. // SunCodeReq 获取太阳码请求体
  1047. type SunCodeReq struct {
  1048. CodePage string `json:"CodePage" description:"太阳码page"`
  1049. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  1050. }
  1051. // YbPcSuncode 活动海报表
  1052. type YbPcSuncode struct {
  1053. SuncodeID uint32 `orm:"column(suncode_id);pk" `
  1054. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  1055. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  1056. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  1057. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  1058. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  1059. }
  1060. // GetYbPcSunCode 获取太阳码
  1061. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  1062. o := orm.NewOrmUsingDB("weekly")
  1063. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  1064. err = o.Raw(sql, scene, page).QueryRow(&item)
  1065. return
  1066. }
  1067. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  1068. o := orm.NewOrmUsingDB("weekly")
  1069. _, err = o.Insert(item)
  1070. return
  1071. }
  1072. // YbSuncodePars 小程序太阳码scene参数
  1073. type YbSuncodePars struct {
  1074. ID uint32 `orm:"column(id);pk" `
  1075. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  1076. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  1077. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  1078. }
  1079. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  1080. o := orm.NewOrmUsingDB("weekly")
  1081. _, err = o.Insert(item)
  1082. return
  1083. }
  1084. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  1085. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1086. o := orm.NewOrmUsingDB("rddp")
  1087. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  1088. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1089. return
  1090. }
  1091. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  1092. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1093. o := orm.NewOrmUsingDB("rddp")
  1094. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  1095. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1096. return
  1097. }
  1098. // UpdateReportThirdClassifyNameByClassifyId 更新报告的三级分类名称字段
  1099. func UpdateReportThirdClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1100. o := orm.NewOrmUsingDB("rddp")
  1101. sql := " UPDATE report SET classify_name_third = ? WHERE classify_id_third = ? "
  1102. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1103. return
  1104. }
  1105. // UpdateReportSecondClassifyFirstNameByClassifyId 更新报告二级分类的一级分类名称和id
  1106. func UpdateReportSecondClassifyFirstNameByClassifyId(classifyId, newClassifyId int, classifyName string) (err error) {
  1107. o := orm.NewOrmUsingDB("rddp")
  1108. sql := " UPDATE report SET classify_name_first = ?, classify_id_first = ? WHERE classify_id_second = ? "
  1109. _, err = o.Raw(sql, classifyName, newClassifyId, classifyId).Exec()
  1110. return
  1111. }
  1112. // GetEmptyContentSubPPTReport 获取前两章为空的PPT报告
  1113. func GetEmptyContentSubPPTReport() (list []*Report, err error) {
  1114. sql := `SELECT
  1115. r.id,
  1116. r.content,
  1117. r.content_sub
  1118. FROM
  1119. report AS r
  1120. JOIN ppt_v2 AS p ON r.id = p.report_id
  1121. WHERE
  1122. p.report_id > 0 AND r.content_sub = ""`
  1123. _, err = orm.NewOrmUsingDB("rddp").Raw(sql).QueryRows(&list)
  1124. return
  1125. }
  1126. // ModifyReportAuthor 更改报告作者
  1127. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  1128. //产品权限
  1129. oRddp := orm.NewOrmUsingDB("rddp")
  1130. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  1131. if condition != "" {
  1132. sql += condition
  1133. }
  1134. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  1135. return
  1136. }
  1137. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  1138. o := orm.NewOrmUsingDB("rddp")
  1139. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  1140. _, err = o.Raw(sql1, reportId).Exec()
  1141. if err != nil {
  1142. return
  1143. }
  1144. //修改音频标题
  1145. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  1146. _, err = o.Raw(sql2, reportId).Exec()
  1147. return
  1148. }
  1149. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  1150. o := orm.NewOrmUsingDB("rddp")
  1151. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  1152. _, err = o.Raw(sql1, reportId).Exec()
  1153. if err != nil {
  1154. return
  1155. }
  1156. //修改音频标题
  1157. 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)`
  1158. _, err = o.Raw(sql2, reportId).Exec()
  1159. return
  1160. }
  1161. // MarkEditReport 标记编辑英文研报的请求数据
  1162. type MarkEditReport struct {
  1163. ReportId int `description:"研报id"`
  1164. ReportChapterId int `description:"研报章节id"`
  1165. Status int `description:"标记状态,1:编辑中,2:编辑完成"`
  1166. }
  1167. type MarkReportResp struct {
  1168. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  1169. Msg string `description:"提示信息"`
  1170. Editor string `description:"编辑者姓名"`
  1171. }
  1172. type MarkReportItem struct {
  1173. AdminId int `description:"编辑者ID"`
  1174. Editor string `description:"编辑者姓名"`
  1175. ReportClassifyNameFirst string
  1176. }
  1177. // GetReportByCondition 获取报告
  1178. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  1179. o := orm.NewOrmUsingDB("rddp")
  1180. fields := `*`
  1181. if len(fieldArr) > 0 {
  1182. fields = strings.Join(fieldArr, ",")
  1183. }
  1184. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  1185. sql += condition
  1186. order := ` ORDER BY modify_time DESC`
  1187. if orderRule != `` {
  1188. order = orderRule
  1189. }
  1190. sql += order
  1191. if isPage {
  1192. sql += ` LIMIT ?,?`
  1193. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1194. } else {
  1195. _, err = o.Raw(sql, pars).QueryRows(&items)
  1196. }
  1197. return
  1198. }
  1199. // ModifyReportMsgIsSendV2 更新报告消息状态
  1200. func ModifyReportMsgIsSendV2(reportId int) (err error) {
  1201. o := orm.NewOrmUsingDB("rddp")
  1202. sql := `UPDATE report SET msg_is_send = 1, ths_msg_is_send = 1, msg_send_time = NOW() WHERE id = ? LIMIT 1`
  1203. _, err = o.Raw(sql, reportId).Exec()
  1204. return
  1205. }
  1206. // SetPrePublishReportById 设置定时发布
  1207. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  1208. o := orm.NewOrmUsingDB("rddp")
  1209. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  1210. _, err = o.Raw(sql, prePublishTime, preMsgSend, reportId).Exec()
  1211. return
  1212. }
  1213. // ReportSubmitApproveReq 提交审批请求体
  1214. type ReportSubmitApproveReq struct {
  1215. ReportId int `description:"报告ID"`
  1216. }
  1217. // ReportCancelApproveReq 撤回审批请求体
  1218. type ReportCancelApproveReq struct {
  1219. ReportId int `description:"报告ID"`
  1220. }
  1221. func (m *Report) GetItemById(id int) (item *Report, err error) {
  1222. o := orm.NewOrmUsingDB("rddp")
  1223. sql := `SELECT * FROM report WHERE id = ? LIMIT 1`
  1224. err = o.Raw(sql, id).QueryRow(&item)
  1225. return
  1226. }
  1227. // GetReportStateCount 获取指定状态的报告数量
  1228. func GetReportStateCount(state int) (count int, err error) {
  1229. o := orm.NewOrmUsingDB("rddp")
  1230. sql := `SELECT COUNT(1) AS count FROM report WHERE state = ?`
  1231. err = o.Raw(sql, state).QueryRow(&count)
  1232. return
  1233. }
  1234. // UpdateReportsStateByCond 批量更新报告状态
  1235. func UpdateReportsStateByCond(classifyFirstId, classifySecondId, oldState, newState int) (err error) {
  1236. o := orm.NewOrmUsingDB("rddp")
  1237. cond := ``
  1238. if classifyFirstId > 0 {
  1239. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  1240. }
  1241. if classifySecondId > 0 {
  1242. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  1243. }
  1244. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  1245. _, err = o.Raw(sql, newState, oldState).Exec()
  1246. return
  1247. }
  1248. // UpdateReportsStateBySecondIds 批量更新二级分类报告状态
  1249. func UpdateReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  1250. if len(secondIds) <= 0 {
  1251. return
  1252. }
  1253. o := orm.NewOrmUsingDB("rddp")
  1254. // (有审批流的)未发布->待提交
  1255. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1256. _, err = o.Raw(sql, newState, oldState, secondIds).Exec()
  1257. if err != nil {
  1258. return
  1259. }
  1260. // (无审批流的)待提交->未发布
  1261. sql = fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1262. _, err = o.Raw(sql, oldState, newState, secondIds).Exec()
  1263. return
  1264. }
  1265. // GetReportPdfUrlReq 获取报告pdf地址请求体
  1266. type GetReportPdfUrlReq struct {
  1267. ReportUrl string `description:"报告Url"`
  1268. ReportCode string `description:"报告Code"`
  1269. Type int `description:"类型 1-pdf 2-图片"`
  1270. }
  1271. func ModifyReportPdfUrl(reportId int, detailPdfUrl string) (err error) {
  1272. o := orm.NewOrmUsingDB("rddp")
  1273. sql := `UPDATE report SET detail_pdf_url=? WHERE id=? `
  1274. _, err = o.Raw(sql, detailPdfUrl, reportId).Exec()
  1275. return
  1276. }
  1277. func ModifyReportImgUrl(reportId int, detailImgUrl string) (err error) {
  1278. o := orm.NewOrmUsingDB("rddp")
  1279. sql := `UPDATE report SET detail_img_url=? WHERE id=? `
  1280. _, err = o.Raw(sql, detailImgUrl, reportId).Exec()
  1281. return
  1282. }