report.go 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893
  1. package models
  2. import (
  3. "errors"
  4. "eta/eta_mobile/utils"
  5. "fmt"
  6. "github.com/beego/beego/v2/client/orm"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  8. "strings"
  9. "time"
  10. )
  11. // 报告状态
  12. const (
  13. ReportStateUnpublished = 1 // 未发布
  14. ReportStatePublished = 2 // 已发布
  15. ReportStateWaitSubmit = 3 // 待提交
  16. ReportStateWaitApprove = 4 // 审批中
  17. ReportStateRefused = 5 // 已驳回
  18. ReportStatePass = 6 // 已通过
  19. )
  20. // 报告操作
  21. const (
  22. ReportOperateAdd = 1 // 新增报告
  23. ReportOperateEdit = 2 // 编辑报告
  24. ReportOperatePublish = 3 // 发布报告
  25. ReportOperateCancelPublish = 4 // 取消发布报告
  26. ReportOperateSubmitApprove = 5 // 提交审批
  27. ReportOperateCancelApprove = 6 // 撤回审批
  28. )
  29. type Report struct {
  30. Id int `orm:"column(id)" description:"报告Id"`
  31. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  32. ClassifyIdFirst int `description:"一级分类id"`
  33. ClassifyNameFirst string `description:"一级分类名称"`
  34. ClassifyIdSecond int `description:"二级分类id"`
  35. ClassifyNameSecond string `description:"二级分类名称"`
  36. Title string `description:"标题"`
  37. Abstract string `description:"摘要"`
  38. Author string `description:"作者"`
  39. Frequency string `description:"频度"`
  40. CreateTime string `description:"创建时间"`
  41. ModifyTime time.Time `description:"修改时间"`
  42. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  43. PublishTime time.Time `description:"发布时间"`
  44. Stage int `description:"期数"`
  45. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  46. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  47. Content string `description:"内容"`
  48. VideoUrl string `description:"音频文件URL"`
  49. VideoName string `description:"音频文件名称"`
  50. VideoPlaySeconds string `description:"音频播放时长"`
  51. VideoSize string `description:"音频文件大小,单位M"`
  52. ContentSub string `description:"内容前两个章节"`
  53. ReportCode string `description:"报告唯一编码"`
  54. ReportVersion int `description:"1:旧版,2:新版"`
  55. HasChapter int `description:"是否有章节 0-否 1-是"`
  56. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  57. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  58. MsgSendTime time.Time `description:"模版消息发送时间"`
  59. AdminId int `description:"创建者账号"`
  60. AdminRealName string `description:"创建者姓名"`
  61. ApproveTime time.Time `description:"审批时间"`
  62. ApproveId int `description:"审批ID"`
  63. DetailImgUrl string `description:"报告详情长图地址"`
  64. DetailPdfUrl string `description:"报告详情PDF地址"`
  65. 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. Author string `description:"作者"`
  805. ClassifyIdFirst int `description:"一级分类ID"`
  806. ClassifyNameFirst string `description:"一级分类名称"`
  807. ClassifyIdSecond int `description:"二级分类ID"`
  808. ClassifyNameSecond string `description:"二级分类名称"`
  809. ClassifyId int `description:"最小单元的分类ID"`
  810. ClassifyName string `description:"最小单元的分类名称"`
  811. Categories string `description:"关联的品种名称(包括品种别名)"`
  812. StageStr string `description:"报告期数"`
  813. }
  814. // GetLastPublishedDayWeekReport 获取上一篇已发布的晨周报
  815. func GetLastPublishDayWeekReport(chapterType string) (item *Report, err error) {
  816. o := orm.NewOrmUsingDB("rddp")
  817. sql := ` SELECT * FROM report WHERE has_chapter = 1 AND chapter_type = ? AND state = 2 ORDER BY publish_time DESC LIMIT 1 `
  818. err = o.Raw(sql, chapterType).QueryRow(&item)
  819. return
  820. }
  821. // GetNewReportExist
  822. func GetNewReportExist(oldReportId int) (item *Report, err error) {
  823. o := orm.NewOrmUsingDB("rddp")
  824. sql := ` SELECT id FROM report WHERE old_report_id = ? LIMIT 1 `
  825. err = o.Raw(sql, oldReportId).QueryRow(&item)
  826. return
  827. }
  828. // PublishReportAndChapter 发布报告及章节
  829. func PublishReportAndChapter(reportInfo *Report, isPublishReport bool, cols []string) (err error) {
  830. o := orm.NewOrmUsingDB("rddp")
  831. to, err := o.Begin()
  832. if err != nil {
  833. return
  834. }
  835. defer func() {
  836. if err != nil {
  837. _ = to.Rollback()
  838. } else {
  839. _ = to.Commit()
  840. }
  841. }()
  842. // 更新报告
  843. if isPublishReport {
  844. _, err = to.Update(reportInfo, cols...)
  845. if err != nil {
  846. return
  847. }
  848. }
  849. // 发布该报告的所有章节
  850. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? `
  851. _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id).Exec()
  852. // 发布章节
  853. //if len(publishIds) > 0 {
  854. // sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  855. // _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
  856. //}
  857. //if len(unPublishIds) > 0 {
  858. // 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)) + `) `
  859. // _, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
  860. //}
  861. return
  862. }
  863. func GetSyncEmptyVideoReport() (list []*Report, err error) {
  864. o := orm.NewOrmUsingDB("rddp")
  865. sql := ` SELECT id FROM report WHERE old_report_id > 0 AND state = 2 AND chapter_type = "" AND (video_size = "" OR video_play_seconds = "")
  866. UNION ALL
  867. SELECT DISTINCT report_id FROM report_chapter WHERE publish_state = 2 AND (video_size = "" OR video_play_seconds = "") `
  868. _, err = o.Raw(sql).QueryRows(&list)
  869. return
  870. }
  871. // PublishReportById 发布报告
  872. func PublishReportById(reportId int, publishTime time.Time, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  873. o := orm.NewOrmUsingDB("rddp")
  874. 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 = ? `
  875. _, err = o.Raw(sql, publishTime, lastModifyAdminId, lastModifyAdminName, reportId).Exec()
  876. return
  877. }
  878. // ResetReportById 重置报告状态
  879. func ResetReportById(reportId, state int, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  880. o := orm.NewOrmUsingDB("rddp")
  881. 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 = ?`
  882. _, err = o.Raw(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Exec()
  883. return
  884. }
  885. // GetCommentReportByReportId 查询有留言的报告列表
  886. func GetCommentReportByReportId(condition string, pars []interface{}, startSize, pageSize int) (list []*Report, err error) {
  887. o := orm.NewOrmUsingDB("rddp")
  888. sql := `SELECT
  889. id,
  890. create_time,
  891. title,
  892. classify_name_first,
  893. classify_id_first,
  894. classify_name_second,
  895. classify_id_second,
  896. state,
  897. IF
  898. ( publish_time, publish_time, create_time ) AS publish_time
  899. FROM
  900. report
  901. WHERE
  902. 1=1
  903. `
  904. if condition != "" {
  905. sql += condition
  906. }
  907. sql += ` ORDER BY publish_time DESC , title ASC LIMIT ?,?`
  908. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  909. return
  910. }
  911. // GetCommentReportByReportIdOrderBy 查询有留言的报告列表(指定排序)
  912. func GetCommentReportByReportIdOrderBy(condition string, pars []interface{}, startSize, pageSize int, orderBy string) (list []*Report, err error) {
  913. o := orm.NewOrmUsingDB("rddp")
  914. sql := `SELECT
  915. id,
  916. create_time,
  917. title,
  918. classify_name_first,
  919. classify_id_first,
  920. classify_name_second,
  921. classify_id_second,
  922. state,
  923. IF
  924. ( publish_time, publish_time, create_time ) AS publish_time
  925. FROM
  926. report
  927. WHERE
  928. 1=1
  929. `
  930. if condition != "" {
  931. sql += condition
  932. }
  933. if orderBy == `` {
  934. sql += ` ORDER BY publish_time DESC , title ASC `
  935. } else {
  936. sql += orderBy
  937. }
  938. sql += ` LIMIT ?,? `
  939. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  940. return
  941. }
  942. // GetCommentReportTotalByReportId 查询有留言的报告列表总数
  943. func GetCommentReportTotalByReportId(condition string, pars []interface{}) (total int64, err error) {
  944. o := orm.NewOrmUsingDB("rddp")
  945. sql := `SELECT count(*)
  946. FROM report WHERE 1=1`
  947. if condition != "" {
  948. sql += condition
  949. }
  950. err = o.Raw(sql, pars).QueryRow(&total)
  951. return
  952. }
  953. // 点赞相关的报告列表
  954. type LikeReportItem struct {
  955. ReportId int `description:"报告Id"`
  956. ReportChapterId int `description:"报告章节Id"`
  957. ClassifyIdFirst int `description:"一级分类id"`
  958. ClassifyNameFirst string `description:"一级分类名称"`
  959. ClassifyIdSecond int `description:"二级分类id"`
  960. ClassifyNameSecond string `description:"二级分类名称"`
  961. ReportChapterTypeId int `description:"章节类型"`
  962. ReportChapterTypeName string `description:"品种名称"`
  963. PublishTime time.Time `description:"发布时间" `
  964. Title string `description:"标题"`
  965. }
  966. // GetLikeReportByReportIdReportChapterId 获取有被点赞的报告列表
  967. func GetLikeReportByReportIdReportChapterId(reportIds string, chapterIds string, orderStr string, startSize, pageSize int) (list []*LikeReportItem, err error) {
  968. o := orm.NewOrmUsingDB("rddp")
  969. sql := `( SELECT
  970. id AS report_id,
  971. 0 AS report_chapter_id,
  972. classify_id_first,
  973. classify_id_second,
  974. classify_name_first,
  975. classify_name_second,
  976. 0 as report_chapter_type_id,
  977. "" as report_chapter_type_name,
  978. publish_time,
  979. title
  980. FROM
  981. report
  982. WHERE
  983. classify_name_first != "晨报"
  984. AND classify_name_first != "周报"
  985. AND id in (` + reportIds + `)
  986. )
  987. UNION
  988. ( SELECT
  989. report_id,
  990. report_chapter_id,
  991. classify_id_first,
  992. 0 as classify_id_second,
  993. classify_name_first,
  994. null as classify_name_second,
  995. type_id as report_chapter_type_id,
  996. type_name as report_chapter_type_name,
  997. publish_time,
  998. title
  999. FROM
  1000. report_chapter
  1001. WHERE
  1002. report_chapter_id in (` + chapterIds + `)
  1003. )`
  1004. if orderStr != "" {
  1005. sql += ` ORDER BY FIELD(CONCAT(report_id, "-",report_chapter_id),` + orderStr + `)`
  1006. } else {
  1007. sql += ` ORDER BY publish_time DESC, report_id Desc`
  1008. }
  1009. sql += ` LIMIT ?,?`
  1010. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  1011. return
  1012. }
  1013. // GetLikeReportTotalByReportIdReportChapterId 获取有被点赞的报告列表总数
  1014. func GetLikeReportTotalByReportIdReportChapterId(reportIds string, chapterIds string) (total int64, err error) {
  1015. o := orm.NewOrmUsingDB("rddp")
  1016. sql := `select count(*) from (( SELECT
  1017. id AS report_id,
  1018. 0 AS report_chapter_id,
  1019. classify_id_first,
  1020. classify_id_second,
  1021. classify_name_first,
  1022. classify_name_second,
  1023. 0 as report_chapter_type_id,
  1024. publish_time,
  1025. title
  1026. FROM
  1027. report
  1028. WHERE
  1029. classify_name_first != "晨报"
  1030. AND classify_name_first != "周报"
  1031. AND id in (` + reportIds + `)
  1032. )
  1033. UNION
  1034. ( SELECT
  1035. report_id,
  1036. report_chapter_id,
  1037. classify_id_first,
  1038. 0 as classify_id_second,
  1039. classify_name_first,
  1040. null as classify_name_second,
  1041. type_id as report_chapter_type_id,
  1042. publish_time,
  1043. title
  1044. FROM
  1045. report_chapter
  1046. WHERE
  1047. report_chapter_id in (` + chapterIds + `)
  1048. )) r`
  1049. err = o.Raw(sql).QueryRow(&total)
  1050. return
  1051. }
  1052. // GetPageReportList 分页获取报告列表
  1053. func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  1054. o := orm.NewOrmUsingDB("rddp")
  1055. sql := `SELECT * FROM report WHERE 1=1 `
  1056. sql += condition
  1057. sql += ` ORDER BY modify_time DESC`
  1058. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  1059. err = o.Raw(totalSql, pars).QueryRow(&total)
  1060. if err != nil {
  1061. return
  1062. }
  1063. sql += ` LIMIT ?,? `
  1064. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1065. return
  1066. }
  1067. // SunCodeReq 获取太阳码请求体
  1068. type SunCodeReq struct {
  1069. CodePage string `json:"CodePage" description:"太阳码page"`
  1070. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  1071. }
  1072. // YbPcSuncode 活动海报表
  1073. type YbPcSuncode struct {
  1074. SuncodeID uint32 `orm:"column(suncode_id);pk" `
  1075. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  1076. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  1077. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  1078. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  1079. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  1080. }
  1081. // GetYbPcSunCode 获取太阳码
  1082. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  1083. o := orm.NewOrmUsingDB("weekly")
  1084. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  1085. err = o.Raw(sql, scene, page).QueryRow(&item)
  1086. return
  1087. }
  1088. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  1089. o := orm.NewOrmUsingDB("weekly")
  1090. _, err = o.Insert(item)
  1091. return
  1092. }
  1093. // YbSuncodePars 小程序太阳码scene参数
  1094. type YbSuncodePars struct {
  1095. ID uint32 `orm:"column(id);pk" `
  1096. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  1097. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  1098. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  1099. }
  1100. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  1101. o := orm.NewOrmUsingDB("weekly")
  1102. _, err = o.Insert(item)
  1103. return
  1104. }
  1105. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  1106. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1107. o := orm.NewOrmUsingDB("rddp")
  1108. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  1109. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1110. return
  1111. }
  1112. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  1113. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1114. o := orm.NewOrmUsingDB("rddp")
  1115. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  1116. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1117. return
  1118. }
  1119. // UpdateReportThirdClassifyNameByClassifyId 更新报告的三级分类名称字段
  1120. func UpdateReportThirdClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1121. o := orm.NewOrmUsingDB("rddp")
  1122. sql := " UPDATE report SET classify_name_third = ? WHERE classify_id_third = ? "
  1123. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1124. return
  1125. }
  1126. // UpdateReportSecondClassifyFirstNameByClassifyId 更新报告二级分类的一级分类名称和id
  1127. func UpdateReportSecondClassifyFirstNameByClassifyId(classifyId, newClassifyId int, classifyName string) (err error) {
  1128. o := orm.NewOrmUsingDB("rddp")
  1129. sql := " UPDATE report SET classify_name_first = ?, classify_id_first = ? WHERE classify_id_second = ? "
  1130. _, err = o.Raw(sql, classifyName, newClassifyId, classifyId).Exec()
  1131. return
  1132. }
  1133. // GetEmptyContentSubPPTReport 获取前两章为空的PPT报告
  1134. func GetEmptyContentSubPPTReport() (list []*Report, err error) {
  1135. sql := `SELECT
  1136. r.id,
  1137. r.content,
  1138. r.content_sub
  1139. FROM
  1140. report AS r
  1141. JOIN ppt_v2 AS p ON r.id = p.report_id
  1142. WHERE
  1143. p.report_id > 0 AND r.content_sub = ""`
  1144. _, err = orm.NewOrmUsingDB("rddp").Raw(sql).QueryRows(&list)
  1145. return
  1146. }
  1147. // ModifyReportAuthor 更改报告作者
  1148. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  1149. //产品权限
  1150. oRddp := orm.NewOrmUsingDB("rddp")
  1151. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  1152. if condition != "" {
  1153. sql += condition
  1154. }
  1155. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  1156. return
  1157. }
  1158. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  1159. o := orm.NewOrmUsingDB("rddp")
  1160. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  1161. _, err = o.Raw(sql1, reportId).Exec()
  1162. if err != nil {
  1163. return
  1164. }
  1165. //修改音频标题
  1166. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  1167. _, err = o.Raw(sql2, reportId).Exec()
  1168. return
  1169. }
  1170. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  1171. o := orm.NewOrmUsingDB("rddp")
  1172. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  1173. _, err = o.Raw(sql1, reportId).Exec()
  1174. if err != nil {
  1175. return
  1176. }
  1177. //修改音频标题
  1178. 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)`
  1179. _, err = o.Raw(sql2, reportId).Exec()
  1180. return
  1181. }
  1182. // MarkEditReport 标记编辑英文研报的请求数据
  1183. type MarkEditReport struct {
  1184. ReportId int `description:"研报id"`
  1185. ReportChapterId int `description:"研报章节id"`
  1186. Status int `description:"标记状态,1:编辑中,2:查询状态,3:编辑完成"`
  1187. }
  1188. type MarkReportResp struct {
  1189. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  1190. Msg string `description:"提示信息"`
  1191. Editor string `description:"编辑者姓名"`
  1192. }
  1193. type MarkReportItem struct {
  1194. AdminId int `description:"编辑者ID"`
  1195. Editor string `description:"编辑者姓名"`
  1196. ReportClassifyNameFirst string
  1197. }
  1198. // GetReportByCondition 获取报告
  1199. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  1200. o := orm.NewOrmUsingDB("rddp")
  1201. fields := `*`
  1202. if len(fieldArr) > 0 {
  1203. fields = strings.Join(fieldArr, ",")
  1204. }
  1205. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  1206. sql += condition
  1207. order := ` ORDER BY modify_time DESC`
  1208. if orderRule != `` {
  1209. order = orderRule
  1210. }
  1211. sql += order
  1212. if isPage {
  1213. sql += ` LIMIT ?,?`
  1214. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1215. } else {
  1216. _, err = o.Raw(sql, pars).QueryRows(&items)
  1217. }
  1218. return
  1219. }
  1220. // ModifyReportMsgIsSendV2 更新报告消息状态
  1221. func ModifyReportMsgIsSendV2(reportId int) (err error) {
  1222. o := orm.NewOrmUsingDB("rddp")
  1223. sql := `UPDATE report SET msg_is_send = 1, ths_msg_is_send = 1, msg_send_time = NOW() WHERE id = ? LIMIT 1`
  1224. _, err = o.Raw(sql, reportId).Exec()
  1225. return
  1226. }
  1227. // SetPrePublishReportById 设置定时发布
  1228. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  1229. o := orm.NewOrmUsingDB("rddp")
  1230. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  1231. _, err = o.Raw(sql, prePublishTime, preMsgSend, reportId).Exec()
  1232. return
  1233. }
  1234. // ReportSubmitApproveReq 提交审批请求体
  1235. type ReportSubmitApproveReq struct {
  1236. ReportId int `description:"报告ID"`
  1237. }
  1238. // ReportCancelApproveReq 撤回审批请求体
  1239. type ReportCancelApproveReq struct {
  1240. ReportId int `description:"报告ID"`
  1241. }
  1242. func (m *Report) GetItemById(id int) (item *Report, err error) {
  1243. o := orm.NewOrmUsingDB("rddp")
  1244. sql := `SELECT * FROM report WHERE id = ? LIMIT 1`
  1245. err = o.Raw(sql, id).QueryRow(&item)
  1246. return
  1247. }
  1248. // GetReportStateCount 获取指定状态的报告数量
  1249. func GetReportStateCount(state int) (count int, err error) {
  1250. o := orm.NewOrmUsingDB("rddp")
  1251. sql := `SELECT COUNT(1) AS count FROM report WHERE state = ?`
  1252. err = o.Raw(sql, state).QueryRow(&count)
  1253. return
  1254. }
  1255. // UpdateReportsStateByCond 批量更新报告状态
  1256. func UpdateReportsStateByCond(classifyFirstId, classifySecondId, classifyThirdId, oldState, newState int) (err error) {
  1257. o := orm.NewOrmUsingDB("rddp")
  1258. cond := ``
  1259. if classifyFirstId > 0 {
  1260. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  1261. }
  1262. if classifySecondId > 0 {
  1263. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  1264. }
  1265. if classifyThirdId > 0 {
  1266. cond += fmt.Sprintf(` AND classify_id_third = %d`, classifyThirdId)
  1267. }
  1268. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  1269. _, err = o.Raw(sql, newState, oldState).Exec()
  1270. return
  1271. }
  1272. // UpdateReportsStateBySecondIds 批量更新二级分类报告状态
  1273. func UpdateReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  1274. if len(secondIds) <= 0 {
  1275. return
  1276. }
  1277. o := orm.NewOrmUsingDB("rddp")
  1278. // (有审批流的)未发布->待提交
  1279. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1280. _, err = o.Raw(sql, newState, oldState, secondIds).Exec()
  1281. if err != nil {
  1282. return
  1283. }
  1284. // (无审批流的)待提交->未发布
  1285. sql = fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1286. _, err = o.Raw(sql, oldState, newState, secondIds).Exec()
  1287. return
  1288. }
  1289. // GetReportPdfUrlReq 获取报告pdf地址请求体
  1290. type GetReportPdfUrlReq struct {
  1291. ReportUrl string `description:"报告Url"`
  1292. ReportCode string `description:"报告Code"`
  1293. Type int `description:"类型 1-pdf 2-图片"`
  1294. }
  1295. func ModifyReportPdfUrl(reportId int, detailPdfUrl string) (err error) {
  1296. o := orm.NewOrmUsingDB("rddp")
  1297. sql := `UPDATE report SET detail_pdf_url=? WHERE id=? `
  1298. _, err = o.Raw(sql, detailPdfUrl, reportId).Exec()
  1299. return
  1300. }
  1301. func ModifyReportImgUrl(reportId int, detailImgUrl string) (err error) {
  1302. o := orm.NewOrmUsingDB("rddp")
  1303. sql := `UPDATE report SET detail_img_url=? WHERE id=? `
  1304. _, err = o.Raw(sql, detailImgUrl, reportId).Exec()
  1305. return
  1306. }
  1307. func ModifyReportPdfUrlMobile(reportId int, detailPdfUrlMobile string) (err error) {
  1308. o := orm.NewOrmUsingDB("rddp")
  1309. sql := `UPDATE report SET detail_pdf_url_mobile=? WHERE id=? `
  1310. _, err = o.Raw(sql, detailPdfUrlMobile, reportId).Exec()
  1311. return
  1312. }
  1313. func ModifyReportImgUrlMobile(reportId int, detailImgUrlMobile string) (err error) {
  1314. o := orm.NewOrmUsingDB("rddp")
  1315. sql := `UPDATE report SET detail_img_url_mobile=? WHERE id=? `
  1316. _, err = o.Raw(sql, detailImgUrlMobile, reportId).Exec()
  1317. return
  1318. }
  1319. // UpdatePdfUrlReportById 清空pdf相关字段
  1320. func UpdatePdfUrlReportById(reportId int) (err error) {
  1321. o := orm.NewOrmUsingDB("rddp")
  1322. sql := `UPDATE report SET detail_img_url = '',detail_pdf_url='',modify_time=NOW() WHERE id = ? `
  1323. _, err = o.Raw(sql, reportId).Exec()
  1324. return
  1325. }
  1326. // InsertMultiReport
  1327. // @Description: 批量新增报告
  1328. // @author: Roc
  1329. // @datetime 2024-06-27 15:55:25
  1330. // @param items []*Report
  1331. // @return err error
  1332. func InsertMultiReport(items []*Report) (err error) {
  1333. o := orm.NewOrmUsingDB("rddp")
  1334. _, err = o.InsertMulti(500, items)
  1335. return
  1336. }
  1337. func GetReportListByCollectCount(classifyIdFirst, classifyIdSecond, classifyIdThird []string, keyword, author string, state int) (count int, err error) {
  1338. o := orm.NewOrmUsingDB("rddp")
  1339. var params []interface{}
  1340. // SQL 主体
  1341. sql := `
  1342. SELECT COUNT(DISTINCT t.id) AS totalCount
  1343. FROM (
  1344. SELECT b.id
  1345. FROM report AS b
  1346. LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_first
  1347. WHERE 1 = 1
  1348. `
  1349. // 处理 classifyIdFirst
  1350. if len(classifyIdFirst) > 0 {
  1351. sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdFirst)) + " ) "
  1352. for _, id := range classifyIdFirst {
  1353. params = append(params, id)
  1354. }
  1355. }
  1356. // 处理关键词
  1357. if keyword != "" {
  1358. sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
  1359. params = append(params, "%"+keyword+"%", "%"+keyword+"%")
  1360. }
  1361. if author != "" {
  1362. sql += " AND b.author = ? "
  1363. params = append(params, author)
  1364. }
  1365. if state > 0 {
  1366. sql += " AND b.state = ? "
  1367. params = append(params, state)
  1368. }
  1369. // 第二段 SQL
  1370. sql += `
  1371. UNION ALL
  1372. SELECT b.id
  1373. FROM report AS b
  1374. LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_second
  1375. WHERE 1 = 1
  1376. `
  1377. // 处理 classifyIdSecond
  1378. if len(classifyIdSecond) > 0 {
  1379. sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdSecond)) + " ) "
  1380. for _, id := range classifyIdSecond {
  1381. params = append(params, id)
  1382. }
  1383. }
  1384. // 处理关键词
  1385. if keyword != "" {
  1386. sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
  1387. params = append(params, "%"+keyword+"%", "%"+keyword+"%")
  1388. }
  1389. if author != "" {
  1390. sql += " AND b.author = ? "
  1391. params = append(params, author)
  1392. }
  1393. if state > 0 {
  1394. sql += " AND b.state = ? "
  1395. params = append(params, state)
  1396. }
  1397. // 第三段 SQL
  1398. sql += `
  1399. UNION ALL
  1400. SELECT b.id
  1401. FROM report AS b
  1402. LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_third
  1403. WHERE 1 = 1
  1404. `
  1405. // 处理 classifyIdThird
  1406. if len(classifyIdThird) > 0 {
  1407. sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdThird)) + " ) "
  1408. for _, id := range classifyIdThird {
  1409. params = append(params, id)
  1410. }
  1411. }
  1412. // 处理关键词
  1413. if keyword != "" {
  1414. sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
  1415. params = append(params, "%"+keyword+"%", "%"+keyword+"%")
  1416. }
  1417. if author != "" {
  1418. sql += " AND b.author = ? "
  1419. params = append(params, author)
  1420. }
  1421. if state > 0 {
  1422. sql += " AND b.state = ? "
  1423. params = append(params, state)
  1424. }
  1425. sql += ") AS t"
  1426. // 执行 SQL 查询获取总数
  1427. err = o.Raw(sql, params...).QueryRow(&count)
  1428. return count, err
  1429. }
  1430. func GetReportListByCollectList(classifyIdFirst, classifyIdSecond, classifyIdThird []string, keyword, orderField, orderType string, startSize, pageSize int, author string, state int) (items []*ReportList, err error) {
  1431. o := orm.NewOrmUsingDB("rddp")
  1432. var params []interface{}
  1433. // SQL 主体
  1434. sql := `
  1435. SELECT DISTINCT t.id, t.title, t.author, t.modify_time, t.publish_time
  1436. FROM (
  1437. SELECT b.id, b.title, b.author, b.modify_time, b.publish_time
  1438. FROM report AS b
  1439. LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_first
  1440. WHERE 1 = 1
  1441. `
  1442. // 处理 classifyIdFirst
  1443. if len(classifyIdFirst) > 0 {
  1444. sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdFirst)) + " ) "
  1445. for _, id := range classifyIdFirst {
  1446. params = append(params, id)
  1447. }
  1448. }
  1449. // 处理关键词
  1450. if keyword != "" {
  1451. sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
  1452. params = append(params, "%"+keyword+"%", "%"+keyword+"%")
  1453. }
  1454. if author != "" {
  1455. sql += " AND b.author = ? "
  1456. params = append(params, author)
  1457. }
  1458. if state > 0 {
  1459. sql += " AND b.state = ? "
  1460. params = append(params, state)
  1461. }
  1462. // 第二段 SQL
  1463. sql += `
  1464. UNION ALL
  1465. SELECT b.id, b.title, b.author, b.modify_time, b.publish_time
  1466. FROM report AS b
  1467. LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_second
  1468. WHERE 1 = 1
  1469. `
  1470. // 处理 classifyIdSecond
  1471. if len(classifyIdSecond) > 0 {
  1472. sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdSecond)) + " ) "
  1473. for _, id := range classifyIdSecond {
  1474. params = append(params, id)
  1475. }
  1476. }
  1477. // 处理关键词
  1478. if keyword != "" {
  1479. sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
  1480. params = append(params, "%"+keyword+"%", "%"+keyword+"%")
  1481. }
  1482. if author != "" {
  1483. sql += " AND b.author = ? "
  1484. params = append(params, author)
  1485. }
  1486. if state > 0 {
  1487. sql += " AND b.state = ? "
  1488. params = append(params, state)
  1489. }
  1490. // 第三段 SQL
  1491. sql += `
  1492. UNION ALL
  1493. SELECT b.id, b.title, b.author, b.modify_time, b.publish_time
  1494. FROM report AS b
  1495. LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_third
  1496. WHERE 1 = 1
  1497. `
  1498. // 处理 classifyIdThird
  1499. if len(classifyIdThird) > 0 {
  1500. sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdThird)) + " ) "
  1501. for _, id := range classifyIdThird {
  1502. params = append(params, id)
  1503. }
  1504. }
  1505. // 处理关键词
  1506. if keyword != "" {
  1507. sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
  1508. params = append(params, "%"+keyword+"%", "%"+keyword+"%")
  1509. }
  1510. if author != "" {
  1511. sql += " AND b.author = ? "
  1512. params = append(params, author)
  1513. }
  1514. if state > 0 {
  1515. sql += " AND b.state = ? "
  1516. params = append(params, state)
  1517. }
  1518. sql += ") AS t "
  1519. // 排序处理
  1520. if orderField != "" && orderType != "" {
  1521. sql += " ORDER BY " + orderField + " " + orderType
  1522. } else {
  1523. sql += " ORDER BY t.modify_time DESC, t.publish_time DESC "
  1524. }
  1525. // 分页
  1526. sql += " LIMIT ?, ?"
  1527. params = append(params, (startSize-1)*pageSize, pageSize)
  1528. // 执行 SQL 查询
  1529. _, err = o.Raw(sql, params...).QueryRows(&items)
  1530. return items, err
  1531. }
  1532. func GetReportListByCollectCountV2(classifyIdFirst, classifyIdSecond, classifyIdThird, chartPermissionIdList []string, keyword, author string, state int) (count int, err error) {
  1533. o := orm.NewOrmUsingDB("rddp")
  1534. var params []interface{}
  1535. // SQL 主体
  1536. sql := `
  1537. SELECT COUNT(DISTINCT t.id) AS totalCount
  1538. FROM (
  1539. SELECT b.id
  1540. FROM report AS b WHERE 1 = 1
  1541. `
  1542. if len(chartPermissionIdList) > 0 {
  1543. classifyIds, e := GetClassifyIdsByPermissionId(chartPermissionIdList)
  1544. if e != nil {
  1545. err = e
  1546. return
  1547. }
  1548. if len(classifyIds) > 0 {
  1549. sql += ` AND ( (b.classify_id_first IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) AND b.classify_id_second = 0)
  1550. OR (b.classify_id_second IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) AND b.classify_id_third = 0)
  1551. OR b.classify_id_third IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) )`
  1552. for _, classifyId := range classifyIds {
  1553. params = append(params, classifyId)
  1554. }
  1555. for _, classifyId := range classifyIds {
  1556. params = append(params, classifyId)
  1557. }
  1558. for _, classifyId := range classifyIds {
  1559. params = append(params, classifyId)
  1560. }
  1561. }
  1562. }
  1563. // 处理关键词
  1564. if keyword != "" {
  1565. sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
  1566. params = append(params, "%"+keyword+"%", "%"+keyword+"%")
  1567. }
  1568. if author != "" {
  1569. sql += " AND b.author = ? "
  1570. params = append(params, author)
  1571. }
  1572. if state > 0 {
  1573. sql += " AND b.state = ? "
  1574. params = append(params, state)
  1575. }
  1576. // 分类id判断
  1577. classifyIdSqlList := make([]string, 0)
  1578. // 处理 classifyIdFirst
  1579. if len(classifyIdFirst) > 0 {
  1580. classifyIdSqlList = append(classifyIdSqlList, " ( b.classify_id_first IN ( "+utils.GetOrmInReplace(len(classifyIdFirst))+" ) AND classify_id_second = 0 AND classify_id_third = 0 ) ")
  1581. for _, id := range classifyIdFirst {
  1582. params = append(params, id)
  1583. }
  1584. }
  1585. // 处理 classifyIdSecond
  1586. if len(classifyIdSecond) > 0 {
  1587. classifyIdSqlList = append(classifyIdSqlList, " ( b.classify_id_second IN ( "+utils.GetOrmInReplace(len(classifyIdSecond))+" ) AND classify_id_third = 0) ")
  1588. for _, id := range classifyIdSecond {
  1589. params = append(params, id)
  1590. }
  1591. }
  1592. // 处理 classifyIdThird
  1593. if len(classifyIdThird) > 0 {
  1594. classifyIdSqlList = append(classifyIdSqlList, " ( b.classify_id_third IN ( "+utils.GetOrmInReplace(len(classifyIdThird))+" ) ) ")
  1595. for _, id := range classifyIdThird {
  1596. params = append(params, id)
  1597. }
  1598. }
  1599. if len(classifyIdSqlList) > 0 {
  1600. sql += ` AND (` + strings.Join(classifyIdSqlList, " OR ") + `) `
  1601. }
  1602. sql += ") AS t"
  1603. // 执行 SQL 查询获取总数
  1604. err = o.Raw(sql, params...).QueryRow(&count)
  1605. return count, err
  1606. }
  1607. func GetReportListByCollectListV2(classifyIdFirst, classifyIdSecond, classifyIdThird, chartPermissionIdList []string, keyword, orderField, orderType string, startSize, pageSize int, author string, state int) (items []*ReportList, err error) {
  1608. o := orm.NewOrmUsingDB("rddp")
  1609. var params []interface{}
  1610. // SQL 主体
  1611. sql := `
  1612. SELECT DISTINCT t.id, t.title, t.author, t.modify_time, t.publish_time,t.classify_id_first,t.classify_name_first,
  1613. t.classify_id_second,t.classify_name_second,t.classify_id_third,t.classify_name_third,
  1614. t.abstract,t.admin_id,t.admin_real_name,t.last_modify_admin_id,t.last_modify_admin_name
  1615. FROM (
  1616. SELECT b.id, b.title, b.author, b.modify_time, b.publish_time,b.classify_id_first,b.classify_name_first,
  1617. b.classify_id_second,b.classify_name_second,b.classify_id_third,b.classify_name_third,
  1618. b.abstract,b.admin_id,b.admin_real_name,b.last_modify_admin_id,b.last_modify_admin_name
  1619. FROM report AS b WHERE 1 = 1
  1620. `
  1621. // 处理关键词
  1622. if keyword != "" {
  1623. sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
  1624. params = append(params, "%"+keyword+"%", "%"+keyword+"%")
  1625. }
  1626. if author != "" {
  1627. sql += " AND b.author = ? "
  1628. params = append(params, author)
  1629. }
  1630. if state > 0 {
  1631. sql += " AND b.state = ? "
  1632. params = append(params, state)
  1633. }
  1634. // 分类id判断
  1635. classifyIdSqlList := make([]string, 0)
  1636. // 处理 classifyIdFirst
  1637. if len(classifyIdFirst) > 0 {
  1638. classifyIdSqlList = append(classifyIdSqlList, " ( b.classify_id_first IN ( "+utils.GetOrmInReplace(len(classifyIdFirst))+" ) AND classify_id_second = 0 AND classify_id_third = 0 ) ")
  1639. for _, id := range classifyIdFirst {
  1640. params = append(params, id)
  1641. }
  1642. }
  1643. // 处理 classifyIdSecond
  1644. if len(classifyIdSecond) > 0 {
  1645. classifyIdSqlList = append(classifyIdSqlList, " ( b.classify_id_second IN ( "+utils.GetOrmInReplace(len(classifyIdSecond))+" ) AND classify_id_third = 0) ")
  1646. for _, id := range classifyIdSecond {
  1647. params = append(params, id)
  1648. }
  1649. }
  1650. // 处理 classifyIdThird
  1651. if len(classifyIdThird) > 0 {
  1652. classifyIdSqlList = append(classifyIdSqlList, " ( b.classify_id_third IN ( "+utils.GetOrmInReplace(len(classifyIdThird))+" ) ) ")
  1653. for _, id := range classifyIdThird {
  1654. params = append(params, id)
  1655. }
  1656. }
  1657. if len(classifyIdSqlList) > 0 {
  1658. sql += ` AND (` + strings.Join(classifyIdSqlList, " OR ") + `) `
  1659. }
  1660. if len(chartPermissionIdList) > 0 {
  1661. classifyIds, e := GetClassifyIdsByPermissionId(chartPermissionIdList)
  1662. if e != nil {
  1663. err = e
  1664. return nil, err
  1665. }
  1666. if len(classifyIds) > 0 {
  1667. sql += ` AND ( (b.classify_id_first IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) AND b.classify_id_second = 0)
  1668. OR (b.classify_id_second IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) AND b.classify_id_third = 0)
  1669. OR b.classify_id_third IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) )`
  1670. for _, classifyId := range classifyIds {
  1671. params = append(params, classifyId)
  1672. }
  1673. for _, classifyId := range classifyIds {
  1674. params = append(params, classifyId)
  1675. }
  1676. for _, classifyId := range classifyIds {
  1677. params = append(params, classifyId)
  1678. }
  1679. }
  1680. }
  1681. sql += ") AS t "
  1682. // 排序处理
  1683. if orderField != "" && orderType != "" {
  1684. sql += " ORDER BY " + orderField + " " + orderType
  1685. } else {
  1686. sql += " ORDER BY t.modify_time DESC, t.publish_time DESC "
  1687. }
  1688. // 分页
  1689. sql += " LIMIT ?, ?"
  1690. params = append(params, (startSize-1)*pageSize, pageSize)
  1691. // 执行 SQL 查询
  1692. _, err = o.Raw(sql, params...).QueryRows(&items)
  1693. return items, err
  1694. }