report.go 56 KB

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