report.go 67 KB

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