report.go 64 KB

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