report.go 46 KB

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