report.go 55 KB

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