report.go 55 KB

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