report.go 67 KB

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