report.go 51 KB

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