report.go 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404
  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 []*Report, err error) {
  354. if len(reportIds) == 0 {
  355. return
  356. }
  357. o := orm.NewOrmUsingDB("rddp")
  358. sql := `SELECT id, title, report_code 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. BodyMd5 string `description:"MD5加密之后的内容"`
  792. }
  793. // GetLastPublishedDayWeekReport 获取上一篇已发布的晨周报
  794. func GetLastPublishDayWeekReport(chapterType string) (item *Report, err error) {
  795. o := orm.NewOrmUsingDB("rddp")
  796. sql := ` SELECT * FROM report WHERE has_chapter = 1 AND chapter_type = ? AND state = 2 ORDER BY publish_time DESC LIMIT 1 `
  797. err = o.Raw(sql, chapterType).QueryRow(&item)
  798. return
  799. }
  800. // GetNewReportExist
  801. func GetNewReportExist(oldReportId int) (item *Report, err error) {
  802. o := orm.NewOrmUsingDB("rddp")
  803. sql := ` SELECT id FROM report WHERE old_report_id = ? LIMIT 1 `
  804. err = o.Raw(sql, oldReportId).QueryRow(&item)
  805. return
  806. }
  807. // PublishReportAndChapter 发布报告及章节
  808. func PublishReportAndChapter(reportInfo *Report, publishIds, unPublishIds []int, isPublishReport bool, cols []string) (err error) {
  809. o := orm.NewOrmUsingDB("rddp")
  810. to, err := o.Begin()
  811. if err != nil {
  812. return
  813. }
  814. defer func() {
  815. if err != nil {
  816. _ = to.Rollback()
  817. } else {
  818. _ = to.Commit()
  819. }
  820. }()
  821. // 更新报告
  822. if isPublishReport {
  823. if _, err = to.Update(reportInfo, cols...); err != nil {
  824. return
  825. }
  826. }
  827. // 发布章节
  828. if len(publishIds) > 0 {
  829. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  830. _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
  831. }
  832. if len(unPublishIds) > 0 {
  833. 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)) + `) `
  834. _, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
  835. }
  836. return
  837. }
  838. func GetSyncEmptyVideoReport() (list []*Report, err error) {
  839. o := orm.NewOrmUsingDB("rddp")
  840. sql := ` SELECT id FROM report WHERE old_report_id > 0 AND state = 2 AND chapter_type = "" AND (video_size = "" OR video_play_seconds = "")
  841. UNION ALL
  842. SELECT DISTINCT report_id FROM report_chapter WHERE publish_state = 2 AND (video_size = "" OR video_play_seconds = "") `
  843. _, err = o.Raw(sql).QueryRows(&list)
  844. return
  845. }
  846. // PublishReportById 发布报告
  847. func PublishReportById(reportId int, publishTime time.Time) (err error) {
  848. o := orm.NewOrmUsingDB("rddp")
  849. sql := `UPDATE report SET state = 2, publish_time = ?, pre_publish_time=null, pre_msg_send=0, modify_time = NOW() WHERE id = ? `
  850. _, err = o.Raw(sql, publishTime, reportId).Exec()
  851. return
  852. }
  853. // ResetReportById 重置报告状态
  854. func ResetReportById(reportId, state int) (err error) {
  855. o := orm.NewOrmUsingDB("rddp")
  856. sql := `UPDATE report SET state = ?, pre_publish_time = null, pre_msg_send = 0, modify_time = NOW() WHERE id = ?`
  857. _, err = o.Raw(sql, state, reportId).Exec()
  858. return
  859. }
  860. // GetCommentReportByReportId 查询有留言的报告列表
  861. func GetCommentReportByReportId(condition string, pars []interface{}, startSize, pageSize int) (list []*Report, err error) {
  862. o := orm.NewOrmUsingDB("rddp")
  863. sql := `SELECT
  864. id,
  865. create_time,
  866. title,
  867. classify_name_first,
  868. classify_id_first,
  869. classify_name_second,
  870. classify_id_second,
  871. state,
  872. IF
  873. ( publish_time, publish_time, create_time ) AS publish_time
  874. FROM
  875. report
  876. WHERE
  877. 1=1
  878. `
  879. if condition != "" {
  880. sql += condition
  881. }
  882. sql += ` ORDER BY publish_time DESC , title ASC LIMIT ?,?`
  883. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  884. return
  885. }
  886. // GetCommentReportByReportIdOrderBy 查询有留言的报告列表(指定排序)
  887. func GetCommentReportByReportIdOrderBy(condition string, pars []interface{}, startSize, pageSize int, orderBy string) (list []*Report, err error) {
  888. o := orm.NewOrmUsingDB("rddp")
  889. sql := `SELECT
  890. id,
  891. create_time,
  892. title,
  893. classify_name_first,
  894. classify_id_first,
  895. classify_name_second,
  896. classify_id_second,
  897. state,
  898. IF
  899. ( publish_time, publish_time, create_time ) AS publish_time
  900. FROM
  901. report
  902. WHERE
  903. 1=1
  904. `
  905. if condition != "" {
  906. sql += condition
  907. }
  908. if orderBy == `` {
  909. sql += ` ORDER BY publish_time DESC , title ASC `
  910. } else {
  911. sql += orderBy
  912. }
  913. sql += ` LIMIT ?,? `
  914. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  915. return
  916. }
  917. // GetCommentReportTotalByReportId 查询有留言的报告列表总数
  918. func GetCommentReportTotalByReportId(condition string, pars []interface{}) (total int64, err error) {
  919. o := orm.NewOrmUsingDB("rddp")
  920. sql := `SELECT count(*)
  921. FROM report WHERE 1=1`
  922. if condition != "" {
  923. sql += condition
  924. }
  925. err = o.Raw(sql, pars).QueryRow(&total)
  926. return
  927. }
  928. // 点赞相关的报告列表
  929. type LikeReportItem struct {
  930. ReportId int `description:"报告Id"`
  931. ReportChapterId int `description:"报告章节Id"`
  932. ClassifyIdFirst int `description:"一级分类id"`
  933. ClassifyNameFirst string `description:"一级分类名称"`
  934. ClassifyIdSecond int `description:"二级分类id"`
  935. ClassifyNameSecond string `description:"二级分类名称"`
  936. ReportChapterTypeId int `description:"章节类型"`
  937. ReportChapterTypeName string `description:"品种名称"`
  938. PublishTime time.Time `description:"发布时间" `
  939. Title string `description:"标题"`
  940. }
  941. // GetLikeReportByReportIdReportChapterId 获取有被点赞的报告列表
  942. func GetLikeReportByReportIdReportChapterId(reportIds string, chapterIds string, orderStr string, startSize, pageSize int) (list []*LikeReportItem, err error) {
  943. o := orm.NewOrmUsingDB("rddp")
  944. sql := `( SELECT
  945. id AS report_id,
  946. 0 AS report_chapter_id,
  947. classify_id_first,
  948. classify_id_second,
  949. classify_name_first,
  950. classify_name_second,
  951. 0 as report_chapter_type_id,
  952. "" as report_chapter_type_name,
  953. publish_time,
  954. title
  955. FROM
  956. report
  957. WHERE
  958. classify_name_first != "晨报"
  959. AND classify_name_first != "周报"
  960. AND id in (` + reportIds + `)
  961. )
  962. UNION
  963. ( SELECT
  964. report_id,
  965. report_chapter_id,
  966. classify_id_first,
  967. 0 as classify_id_second,
  968. classify_name_first,
  969. null as classify_name_second,
  970. type_id as report_chapter_type_id,
  971. type_name as report_chapter_type_name,
  972. publish_time,
  973. title
  974. FROM
  975. report_chapter
  976. WHERE
  977. report_chapter_id in (` + chapterIds + `)
  978. )`
  979. if orderStr != "" {
  980. sql += ` ORDER BY FIELD(CONCAT(report_id, "-",report_chapter_id),` + orderStr + `)`
  981. } else {
  982. sql += ` ORDER BY publish_time DESC, report_id Desc`
  983. }
  984. sql += ` LIMIT ?,?`
  985. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  986. return
  987. }
  988. // GetLikeReportTotalByReportIdReportChapterId 获取有被点赞的报告列表总数
  989. func GetLikeReportTotalByReportIdReportChapterId(reportIds string, chapterIds string) (total int64, err error) {
  990. o := orm.NewOrmUsingDB("rddp")
  991. sql := `select count(*) from (( SELECT
  992. id AS report_id,
  993. 0 AS report_chapter_id,
  994. classify_id_first,
  995. classify_id_second,
  996. classify_name_first,
  997. classify_name_second,
  998. 0 as report_chapter_type_id,
  999. publish_time,
  1000. title
  1001. FROM
  1002. report
  1003. WHERE
  1004. classify_name_first != "晨报"
  1005. AND classify_name_first != "周报"
  1006. AND id in (` + reportIds + `)
  1007. )
  1008. UNION
  1009. ( SELECT
  1010. report_id,
  1011. report_chapter_id,
  1012. classify_id_first,
  1013. 0 as classify_id_second,
  1014. classify_name_first,
  1015. null as classify_name_second,
  1016. type_id as report_chapter_type_id,
  1017. publish_time,
  1018. title
  1019. FROM
  1020. report_chapter
  1021. WHERE
  1022. report_chapter_id in (` + chapterIds + `)
  1023. )) r`
  1024. err = o.Raw(sql).QueryRow(&total)
  1025. return
  1026. }
  1027. // GetPageReportList 分页获取报告列表
  1028. func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  1029. o := orm.NewOrmUsingDB("rddp")
  1030. sql := `SELECT * FROM report WHERE 1=1 `
  1031. sql += condition
  1032. sql += ` ORDER BY modify_time DESC`
  1033. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  1034. err = o.Raw(totalSql, pars).QueryRow(&total)
  1035. if err != nil {
  1036. return
  1037. }
  1038. sql += ` LIMIT ?,? `
  1039. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1040. return
  1041. }
  1042. // SunCodeReq 获取太阳码请求体
  1043. type SunCodeReq struct {
  1044. CodePage string `json:"CodePage" description:"太阳码page"`
  1045. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  1046. }
  1047. // YbPcSuncode 活动海报表
  1048. type YbPcSuncode struct {
  1049. SuncodeID uint32 `orm:"column(suncode_id);pk" `
  1050. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  1051. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  1052. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  1053. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  1054. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  1055. }
  1056. // GetYbPcSunCode 获取太阳码
  1057. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  1058. o := orm.NewOrmUsingDB("weekly")
  1059. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  1060. err = o.Raw(sql, scene, page).QueryRow(&item)
  1061. return
  1062. }
  1063. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  1064. o := orm.NewOrmUsingDB("weekly")
  1065. _, err = o.Insert(item)
  1066. return
  1067. }
  1068. // YbSuncodePars 小程序太阳码scene参数
  1069. type YbSuncodePars struct {
  1070. ID uint32 `orm:"column(id);pk" `
  1071. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  1072. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  1073. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  1074. }
  1075. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  1076. o := orm.NewOrmUsingDB("weekly")
  1077. _, err = o.Insert(item)
  1078. return
  1079. }
  1080. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  1081. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1082. o := orm.NewOrmUsingDB("rddp")
  1083. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  1084. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1085. return
  1086. }
  1087. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  1088. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1089. o := orm.NewOrmUsingDB("rddp")
  1090. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  1091. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1092. return
  1093. }
  1094. // UpdateReportSecondClassifyFirstNameByClassifyId 更新报告二级分类的一级分类名称和id
  1095. func UpdateReportSecondClassifyFirstNameByClassifyId(classifyId, newClassifyId int, classifyName string) (err error) {
  1096. o := orm.NewOrmUsingDB("rddp")
  1097. sql := " UPDATE report SET classify_name_first = ?, classify_id_first = ? WHERE classify_id_second = ? "
  1098. _, err = o.Raw(sql, classifyName, newClassifyId, classifyId).Exec()
  1099. return
  1100. }
  1101. // GetEmptyContentSubPPTReport 获取前两章为空的PPT报告
  1102. func GetEmptyContentSubPPTReport() (list []*Report, err error) {
  1103. sql := `SELECT
  1104. r.id,
  1105. r.content,
  1106. r.content_sub
  1107. FROM
  1108. report AS r
  1109. JOIN ppt_v2 AS p ON r.id = p.report_id
  1110. WHERE
  1111. p.report_id > 0 AND r.content_sub = ""`
  1112. _, err = orm.NewOrmUsingDB("rddp").Raw(sql).QueryRows(&list)
  1113. return
  1114. }
  1115. // ModifyReportAuthor 更改报告作者
  1116. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  1117. //产品权限
  1118. oRddp := orm.NewOrmUsingDB("rddp")
  1119. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  1120. if condition != "" {
  1121. sql += condition
  1122. }
  1123. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  1124. return
  1125. }
  1126. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  1127. o := orm.NewOrmUsingDB("rddp")
  1128. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  1129. _, err = o.Raw(sql1, reportId).Exec()
  1130. if err != nil {
  1131. return
  1132. }
  1133. //修改音频标题
  1134. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  1135. _, err = o.Raw(sql2, reportId).Exec()
  1136. return
  1137. }
  1138. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  1139. o := orm.NewOrmUsingDB("rddp")
  1140. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  1141. _, err = o.Raw(sql1, reportId).Exec()
  1142. if err != nil {
  1143. return
  1144. }
  1145. //修改音频标题
  1146. 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)`
  1147. _, err = o.Raw(sql2, reportId).Exec()
  1148. return
  1149. }
  1150. // MarkEditReport 标记编辑英文研报的请求数据
  1151. type MarkEditReport struct {
  1152. ReportId int `description:"研报id"`
  1153. ReportChapterId int `description:"研报章节id"`
  1154. Status int `description:"标记状态,1:编辑中,2:编辑完成"`
  1155. }
  1156. type MarkReportResp struct {
  1157. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  1158. Msg string `description:"提示信息"`
  1159. Editor string `description:"编辑者姓名"`
  1160. }
  1161. type MarkReportItem struct {
  1162. AdminId int `description:"编辑者ID"`
  1163. Editor string `description:"编辑者姓名"`
  1164. ReportClassifyNameFirst string
  1165. }
  1166. // GetReportByCondition 获取报告
  1167. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  1168. o := orm.NewOrmUsingDB("rddp")
  1169. fields := `*`
  1170. if len(fieldArr) > 0 {
  1171. fields = strings.Join(fieldArr, ",")
  1172. }
  1173. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  1174. sql += condition
  1175. order := ` ORDER BY modify_time DESC`
  1176. if orderRule != `` {
  1177. order = orderRule
  1178. }
  1179. sql += order
  1180. if isPage {
  1181. sql += ` LIMIT ?,?`
  1182. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1183. } else {
  1184. _, err = o.Raw(sql, pars).QueryRows(&items)
  1185. }
  1186. return
  1187. }
  1188. // ModifyReportMsgIsSendV2 更新报告消息状态
  1189. func ModifyReportMsgIsSendV2(reportId int) (err error) {
  1190. o := orm.NewOrmUsingDB("rddp")
  1191. sql := `UPDATE report SET msg_is_send = 1, ths_msg_is_send = 1, msg_send_time = NOW() WHERE id = ? LIMIT 1`
  1192. _, err = o.Raw(sql, reportId).Exec()
  1193. return
  1194. }
  1195. // SetPrePublishReportById 设置定时发布
  1196. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  1197. o := orm.NewOrmUsingDB("rddp")
  1198. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  1199. _, err = o.Raw(sql, prePublishTime, preMsgSend, reportId).Exec()
  1200. return
  1201. }
  1202. // ReportSubmitApproveReq 提交审批请求体
  1203. type ReportSubmitApproveReq struct {
  1204. ReportId int `description:"报告ID"`
  1205. }
  1206. // ReportCancelApproveReq 撤回审批请求体
  1207. type ReportCancelApproveReq struct {
  1208. ReportId int `description:"报告ID"`
  1209. }
  1210. func (m *Report) GetItemById(id int) (item *Report, err error) {
  1211. o := orm.NewOrmUsingDB("rddp")
  1212. sql := `SELECT * FROM report WHERE id = ? LIMIT 1`
  1213. err = o.Raw(sql, id).QueryRow(&item)
  1214. return
  1215. }
  1216. // GetReportStateCount 获取指定状态的报告数量
  1217. func GetReportStateCount(state int) (count int, err error) {
  1218. o := orm.NewOrmUsingDB("rddp")
  1219. sql := `SELECT COUNT(1) AS count FROM report WHERE state = ?`
  1220. err = o.Raw(sql, state).QueryRow(&count)
  1221. return
  1222. }
  1223. // UpdateReportsStateByCond 批量更新报告状态
  1224. func UpdateReportsStateByCond(classifyFirstId, classifySecondId, oldState, newState int) (err error) {
  1225. o := orm.NewOrmUsingDB("rddp")
  1226. cond := ``
  1227. if classifyFirstId > 0 {
  1228. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  1229. }
  1230. if classifySecondId > 0 {
  1231. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  1232. }
  1233. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  1234. _, err = o.Raw(sql, newState, oldState).Exec()
  1235. return
  1236. }
  1237. // UpdateReportsStateBySecondIds 批量更新二级分类报告状态
  1238. func UpdateReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  1239. if len(secondIds) <= 0 {
  1240. return
  1241. }
  1242. o := orm.NewOrmUsingDB("rddp")
  1243. // (有审批流的)未发布->待提交
  1244. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1245. _, err = o.Raw(sql, newState, oldState, secondIds).Exec()
  1246. if err != nil {
  1247. return
  1248. }
  1249. // (无审批流的)待提交->未发布
  1250. sql = fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1251. _, err = o.Raw(sql, oldState, newState, secondIds).Exec()
  1252. return
  1253. }
  1254. // GetReportPdfUrlReq 获取报告pdf地址请求体
  1255. type GetReportPdfUrlReq struct {
  1256. ReportUrl string `description:"报告Url"`
  1257. ReportCode string `description:"报告Code"`
  1258. Type int `description:"类型 1-pdf 2-图片"`
  1259. }
  1260. func ModifyReportPdfUrl(reportId int, detailPdfUrl string) (err error) {
  1261. o := orm.NewOrmUsingDB("rddp")
  1262. sql := `UPDATE report SET detail_pdf_url=? WHERE id=? `
  1263. _, err = o.Raw(sql, detailPdfUrl, reportId).Exec()
  1264. return
  1265. }
  1266. func ModifyReportImgUrl(reportId int, detailImgUrl string) (err error) {
  1267. o := orm.NewOrmUsingDB("rddp")
  1268. sql := `UPDATE report SET detail_img_url=? WHERE id=? `
  1269. _, err = o.Raw(sql, detailImgUrl, reportId).Exec()
  1270. return
  1271. }
  1272. // UpdatePdfUrlReportById 清空pdf相关字段
  1273. func UpdatePdfUrlReportById(reportId int) (err error) {
  1274. o := orm.NewOrmUsingDB("rddp")
  1275. sql := `UPDATE report SET detail_img_url = '',detail_pdf_url='',modify_time=NOW() WHERE id = ? `
  1276. _, err = o.Raw(sql, reportId).Exec()
  1277. return
  1278. }