report.go 67 KB

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