report.go 67 KB

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