report.go 53 KB

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