report.go 53 KB

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