report.go 68 KB

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