report.go 64 KB

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