report.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. package models
  2. import (
  3. "eta/eta_hub/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "html"
  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. // 报告类型
  29. const (
  30. ReportTypeChinese = 1 // 中文研报
  31. ReportTypeEnglish = 2 // 英文研报
  32. ReportTypeSmart = 3 // 智能研报
  33. )
  34. type Report struct {
  35. Id int `orm:"column(id)" description:"报告Id"`
  36. AddType int `json:"-" description:"新增方式:1:新增报告,2:继承报告"`
  37. ClassifyIdFirst int `description:"一级分类id"`
  38. ClassifyNameFirst string `description:"一级分类名称"`
  39. ClassifyIdSecond int `description:"二级分类id"`
  40. ClassifyNameSecond string `description:"二级分类名称"`
  41. Title string `description:"标题"`
  42. Abstract string `description:"摘要"`
  43. Author string `description:"作者"`
  44. Frequency string `description:"频度"`
  45. State int `description:"状态:1-未提交 2-待审核 3-驳回 4-审核"`
  46. Stage int `description:"期数"`
  47. MsgIsSend int `json:"-" description:"消息是否已发送,0:否,1:是"`
  48. ThsMsgIsSend int `json:"-" description:"客户群消息是否已发送,0:否,1:是"`
  49. Content string `description:"内容"`
  50. VideoUrl string `description:"音频文件URL"`
  51. VideoName string `description:"音频文件名称"`
  52. VideoPlaySeconds string `description:"音频播放时长"`
  53. VideoSize string `description:"音频文件大小,单位M"`
  54. ContentSub string `json:"-" description:"内容前两个章节"`
  55. ReportCode string `description:"报告唯一编码"`
  56. ReportVersion int `json:"-" description:"1:旧版,2:新版"`
  57. HasChapter int `json:"-" description:"是否有章节 0-否 1-是"`
  58. ChapterType string `json:"-" description:"章节类型 day-晨报 week-周报"`
  59. OldReportId int `json:"-" description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  60. MsgSendTime time.Time `json:"-" description:"模版消息发送时间"`
  61. AdminId int `description:"创建者账号"`
  62. AdminRealName string `description:"创建者姓名"`
  63. ApproveTime time.Time `description:"审批时间"`
  64. PublishTime time.Time `description:"发布时间"`
  65. CreateTime time.Time `description:"创建时间"`
  66. ModifyTime time.Time `description:"修改时间"`
  67. // eta1.8.3(研报改版)相关内容
  68. ContentStruct string `description:"内容组件"`
  69. LastModifyAdminId int `description:"最后更新人ID"`
  70. LastModifyAdminName string `description:"最后更新人姓名"`
  71. ContentModifyTime time.Time `description:"内容更新时间"`
  72. Pv int `description:"pv"`
  73. Uv int `description:"uv"`
  74. HeadImg string `description:"报告头图地址"`
  75. EndImg string `description:"报告尾图地址"`
  76. HeadStyle string `description:"版头样式"`
  77. EndStyle string `description:"版尾样式"`
  78. CanvasColor string `description:"画布颜色"`
  79. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  80. HeadResourceId int `description:"版头资源ID"`
  81. EndResourceId int `description:"版尾资源ID"`
  82. ClassifyIdThird int `description:"三级分类id"`
  83. ClassifyNameThird string `description:"三级分类名称"`
  84. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  85. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  86. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  87. ReportCreateTime time.Time `description:"报告时间创建时间"`
  88. DetailImgUrl string `description:"报告详情长图地址"`
  89. DetailPdfUrl string `description:"报告详情PDF地址"`
  90. }
  91. type ReportListResp struct {
  92. List []*ReportItem
  93. Paging *paging.PagingItem `description:"分页数据"`
  94. }
  95. func GetReportListCount(condition string, pars []interface{}, companyType string) (count int, err error) {
  96. //产品权限
  97. companyTypeSqlStr := ``
  98. if companyType == "ficc" {
  99. companyTypeSqlStr = " AND classify_id_first != 40 "
  100. } else if companyType == "权益" {
  101. companyTypeSqlStr = " AND classify_id_first = 40 "
  102. }
  103. oRddp := orm.NewOrmUsingDB("rddp")
  104. sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 ` + companyTypeSqlStr
  105. if condition != "" {
  106. sql += condition
  107. }
  108. err = oRddp.Raw(sql, pars).QueryRow(&count)
  109. return
  110. }
  111. func GetReportList(condition string, pars []interface{}, startSize, pageSize int) (items []*Report, err error) {
  112. o := orm.NewOrmUsingDB("rddp")
  113. sql := `SELECT * FROM report WHERE 1=1 `
  114. if condition != "" {
  115. sql += condition
  116. }
  117. sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  118. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  119. return
  120. }
  121. // PublishReport 发布报告
  122. func PublishReport(reportIds []int) (err error) {
  123. if len(reportIds) == 0 {
  124. return
  125. }
  126. o := orm.NewOrmUsingDB("rddp")
  127. sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  128. _, err = o.Raw(sql).Exec()
  129. return
  130. }
  131. // PublishCancleReport 取消发布报告
  132. func PublishCancleReport(reportIds int, publishTimeNullFlag bool) (err error) {
  133. o := orm.NewOrmUsingDB("rddp")
  134. var sql string
  135. if publishTimeNullFlag {
  136. sql = ` UPDATE report SET state=1, publish_time=null, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
  137. } else {
  138. sql = ` UPDATE report SET state=1, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
  139. }
  140. _, err = o.Raw(sql, reportIds).Exec()
  141. return
  142. }
  143. // 删除报告
  144. func DeleteReport(reportIds int) (err error) {
  145. o := orm.NewOrmUsingDB("rddp")
  146. sql := ` DELETE FROM report WHERE id =? `
  147. _, err = o.Raw(sql, reportIds).Exec()
  148. return
  149. }
  150. type ReportDetail struct {
  151. Id int `orm:"column(id)" description:"报告Id"`
  152. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  153. ClassifyIdFirst int `description:"一级分类id"`
  154. ClassifyNameFirst string `description:"一级分类名称"`
  155. ClassifyIdSecond int `description:"二级分类id"`
  156. ClassifyNameSecond string `description:"二级分类名称"`
  157. Title string `description:"标题"`
  158. Abstract string `description:"摘要"`
  159. Author string `description:"作者"`
  160. Frequency string `description:"频度"`
  161. CreateTime string `description:"创建时间"`
  162. ModifyTime string `description:"修改时间"`
  163. State int `description:"状态:1-未提交 2-待审核 3-驳回 4-审核"`
  164. PublishTime string `description:"发布时间"`
  165. PrePublishTime string `description:"预发布时间"`
  166. Stage int `description:"期数"`
  167. MsgIsSend int `json:"-" description:"消息是否已发送,0:否,1:是"`
  168. PreMsgSend int `json:"-" description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  169. Content string `description:"内容"`
  170. VideoUrl string `description:"音频文件URL"`
  171. VideoName string `description:"音频文件名称"`
  172. VideoPlaySeconds string `description:"音频播放时长"`
  173. ContentSub string `json:"-" description:"内容前两个章节"`
  174. ThsMsgIsSend int `json:"-" description:"客户群消息是否已发送,0:否,1:是"`
  175. HasChapter int `json:"-" description:"是否有章节 0-否 1-是"`
  176. ChapterType string `json:"-" description:"章节类型 day-晨报 week-周报"`
  177. }
  178. func GetReportById(reportId int) (item *Report, err error) {
  179. o := orm.NewOrmUsingDB("rddp")
  180. sql := `SELECT * FROM report WHERE id=?`
  181. err = o.Raw(sql, reportId).QueryRow(&item)
  182. return
  183. }
  184. func GetReportStage(classifyIdFirst, classifyIdSecond int) (count int, err error) {
  185. o := orm.NewOrmUsingDB("rddp")
  186. sql := ``
  187. if classifyIdSecond > 0 {
  188. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_second=? "
  189. o.Raw(sql, classifyIdSecond).QueryRow(&count)
  190. } else {
  191. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first=? "
  192. o.Raw(sql, classifyIdFirst).QueryRow(&count)
  193. }
  194. return
  195. }
  196. func GetReportStageEdit(classifyIdFirst, classifyIdSecond, reportId int) (count int, err error) {
  197. o := orm.NewOrmUsingDB("rddp")
  198. sql := ``
  199. if classifyIdSecond > 0 {
  200. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_second=? AND id<>? "
  201. o.Raw(sql, classifyIdSecond, reportId).QueryRow(&count)
  202. } else {
  203. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first=? AND id<>? "
  204. o.Raw(sql, classifyIdFirst, reportId).QueryRow(&count)
  205. }
  206. return
  207. }
  208. type PublishReq struct {
  209. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  210. State int `description:"状态:1-未提交 2-待审核 3-驳回 4-审核"`
  211. }
  212. type PublishCancelReq struct {
  213. ReportIds int `description:"报告id"`
  214. }
  215. type DeleteReq struct {
  216. ReportIds int `description:"报告id"`
  217. }
  218. type AddReq struct {
  219. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  220. ClassifyIdFirst int `description:"一级分类id"`
  221. ClassifyNameFirst string `description:"一级分类名称"`
  222. ClassifyIdSecond int `description:"二级分类id"`
  223. ClassifyNameSecond string `description:"二级分类名称"`
  224. Title string `description:"标题"`
  225. Abstract string `description:"摘要"`
  226. Author string `description:"作者"`
  227. Frequency string `description:"频度"`
  228. State int `description:"状态:1:未发布,2:已发布"`
  229. Content string `description:"内容"`
  230. CreateTime string `description:"创建时间"`
  231. ReportVersion int `description:"1:旧版,2:新版"`
  232. }
  233. type PrePublishReq struct {
  234. ReportId int `description:"报告id"`
  235. PrePublishTime string `description:"预发布时间"`
  236. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  237. }
  238. type AddResp struct {
  239. ReportId int64 `description:"报告id"`
  240. ReportCode string `description:"报告code"`
  241. }
  242. func AddReport(item *Report) (lastId int64, err error) {
  243. o := orm.NewOrmUsingDB("rddp")
  244. lastId, err = o.Insert(item)
  245. return
  246. }
  247. type EditReq struct {
  248. ReportId int64 `description:"报告id"`
  249. ClassifyIdFirst int `description:"一级分类id"`
  250. ClassifyNameFirst string `description:"一级分类名称"`
  251. ClassifyIdSecond int `description:"二级分类id"`
  252. ClassifyNameSecond string `description:"二级分类名称"`
  253. Title string `description:"标题"`
  254. Abstract string `description:"摘要"`
  255. Author string `description:"作者"`
  256. Frequency string `description:"频度"`
  257. State int `description:"状态:1:未发布,2:已发布"`
  258. Content string `description:"内容"`
  259. CreateTime string `description:"创建时间"`
  260. }
  261. type EditResp struct {
  262. ReportId int64 `description:"报告id"`
  263. ReportCode string `description:"报告code"`
  264. }
  265. func EditReport(item *Report, reportId int64) (err error) {
  266. o := orm.NewOrmUsingDB("rddp")
  267. sql := `UPDATE report
  268. SET
  269. classify_id_first =?,
  270. classify_name_first = ?,
  271. classify_id_second = ?,
  272. classify_name_second = ?,
  273. title = ?,
  274. abstract = ?,
  275. author = ?,
  276. frequency = ?,
  277. state = ?,
  278. content = ?,
  279. content_sub = ?,
  280. stage =?,
  281. create_time = ?,
  282. modify_time = ?
  283. WHERE id = ? `
  284. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  285. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Exec()
  286. return
  287. }
  288. type ReportDetailReq struct {
  289. ReportId int `description:"报告id"`
  290. }
  291. type ClassifyIdDetailReq struct {
  292. ClassifyIdFirst int `description:"报告一级分类id"`
  293. ClassifyIdSecond int `description:"报告二级分类id"`
  294. }
  295. type SendTemplateMsgReq struct {
  296. ReportId int `description:"报告id"`
  297. }
  298. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  299. o := orm.NewOrmUsingDB("rddp")
  300. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  301. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  302. return
  303. }
  304. func EditReportContent(reportId int, content, contentSub string) (err error) {
  305. o := orm.NewOrmUsingDB("rddp")
  306. sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  307. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  308. return
  309. }
  310. func AddReportSaveLog(reportId, adminId int, content, contentSub, adminName string) (err error) {
  311. o := orm.NewOrmUsingDB("rddp")
  312. sql := ` INSERT INTO report_save_log(report_id, content,content_sub,admin_id,admin_name) VALUES (?,?,?,?,?) `
  313. _, err = o.Raw(sql, reportId, content, contentSub, adminId, adminName).Exec()
  314. return
  315. }
  316. type SaveReportContentResp struct {
  317. ReportId int `description:"报告id"`
  318. }
  319. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  320. o := orm.NewOrmUsingDB("rddp")
  321. sql := `UPDATE report SET report_code=? WHERE id=? `
  322. _, err = o.Raw(sql, reportCode, reportId).Exec()
  323. return
  324. }
  325. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  326. o := orm.NewOrmUsingDB("rddp")
  327. if item.ThsMsgIsSend == 0 {
  328. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  329. _, err = o.Raw(sql, item.Id).Exec()
  330. }
  331. return
  332. }
  333. // GetDayWeekReportStage 获取晨报周报期数
  334. func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int, err error) {
  335. o := orm.NewOrmUsingDB("rddp")
  336. sql := " SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first = ? AND create_time > ? "
  337. o.Raw(sql, classifyIdFirst, yearStart).QueryRow(&count)
  338. return
  339. }
  340. // GetReportByReportId 主键获取报告
  341. func GetReportByReportId(reportId int) (item *Report, err error) {
  342. o := orm.NewOrmUsingDB("rddp")
  343. sql := `SELECT * FROM report WHERE id = ?`
  344. err = o.Raw(sql, reportId).QueryRow(&item)
  345. return
  346. }
  347. // 发布报告
  348. func PublishReportById(reportId, state int, publishTime time.Time) (err error) {
  349. o := orm.NewOrmUsingDB("rddp")
  350. sql := `UPDATE report SET state = ?, publish_time = ?, pre_publish_time = null, pre_msg_send=0, modify_time = NOW() WHERE id = ? `
  351. _, err = o.Raw(sql, state, publishTime, reportId).Exec()
  352. return
  353. }
  354. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  355. o := orm.NewOrmUsingDB("rddp")
  356. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  357. _, err = o.Raw(sql1, reportId).Exec()
  358. if err != nil {
  359. return
  360. }
  361. //修改音频标题
  362. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  363. _, err = o.Raw(sql2, reportId).Exec()
  364. return
  365. }
  366. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  367. o := orm.NewOrmUsingDB("rddp")
  368. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  369. _, err = o.Raw(sql1, reportId).Exec()
  370. if err != nil {
  371. return
  372. }
  373. //修改音频标题
  374. 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)`
  375. _, err = o.Raw(sql2, reportId).Exec()
  376. return
  377. }
  378. // GetReportByCondition 获取报告
  379. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  380. o := orm.NewOrmUsingDB("rddp")
  381. fields := `*`
  382. if len(fieldArr) > 0 {
  383. fields = strings.Join(fieldArr, ",")
  384. }
  385. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  386. sql += condition
  387. order := ` ORDER BY modify_time DESC`
  388. if orderRule != `` {
  389. order = orderRule
  390. }
  391. sql += order
  392. if isPage {
  393. sql += ` LIMIT ?,?`
  394. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  395. } else {
  396. _, err = o.Raw(sql, pars).QueryRows(&items)
  397. }
  398. return
  399. }
  400. type ElasticReportDetail struct {
  401. ReportId int `description:"报告ID"`
  402. ReportChapterId int `description:"报告章节ID"`
  403. Title string `description:"标题"`
  404. Abstract string `description:"摘要"`
  405. BodyContent string `description:"内容"`
  406. PublishTime string `description:"发布时间"`
  407. PublishState int `description:"状态:1-未提交 2-待审核 3-驳回 4-审核"`
  408. Author string `description:"作者"`
  409. ClassifyIdFirst int `description:"一级分类ID"`
  410. ClassifyNameFirst string `description:"一级分类名称"`
  411. ClassifyIdSecond int `description:"二级分类ID"`
  412. ClassifyNameSecond string `description:"二级分类名称"`
  413. ClassifyId int `description:"最小单元的分类ID"`
  414. ClassifyName string `description:"最小单元的分类名称"`
  415. Categories string `description:"关联的品种名称(包括品种别名)"`
  416. StageStr string `description:"报告期数"`
  417. }
  418. type ReportItem struct {
  419. Id int `description:"报告Id"`
  420. ReportCode string `description:"报告唯一编码"`
  421. ClassifyIdFirst int `description:"一级分类id"`
  422. ClassifyNameFirst string `description:"一级分类名称"`
  423. ClassifyIdSecond int `description:"二级分类id"`
  424. ClassifyNameSecond string `description:"二级分类名称"`
  425. Title string `description:"标题"`
  426. Abstract string `description:"摘要"`
  427. Author string `description:"作者"`
  428. Frequency string `description:"频度"`
  429. State int `description:"状态:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  430. Stage int `description:"期数"`
  431. Content string `description:"内容"`
  432. VideoUrl string `description:"音频文件URL"`
  433. VideoName string `description:"音频文件名称"`
  434. VideoPlaySeconds string `description:"音频播放时长"`
  435. VideoSize string `description:"音频文件大小,单位M"`
  436. AdminId int `description:"创建者账号"`
  437. AdminRealName string `description:"创建者姓名"`
  438. PublishTime string `description:"发布时间"`
  439. ApproveTime string `description:"审批时间"`
  440. CreateTime string `description:"创建时间"`
  441. ModifyTime string `description:"修改时间"`
  442. // eta1.8.3(研报改版)相关内容
  443. //ContentStruct string `description:"内容组件"`
  444. //LastModifyAdminId int `description:"最后更新人ID"`
  445. //LastModifyAdminName string `description:"最后更新人姓名"`
  446. ContentModifyTime string `description:"内容更新时间"`
  447. //Pv int `description:"pv"`
  448. //Uv int `description:"uv"`
  449. HeadImg string `description:"报告头图地址"`
  450. EndImg string `description:"报告尾图地址"`
  451. HeadStyle string `description:"版头样式"`
  452. EndStyle string `description:"版尾样式"`
  453. CanvasColor string `description:"画布颜色"`
  454. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  455. //HeadResourceId int `description:"版头资源ID"`
  456. //EndResourceId int `description:"版尾资源ID"`
  457. ClassifyIdThird int `description:"三级分类id"`
  458. ClassifyNameThird string `description:"三级分类名称"`
  459. //CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  460. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  461. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  462. ReportCreateTime string `description:"报告时间创建时间"`
  463. ChapterList []*ReportChapterItem `description:"章节列表"`
  464. HasChapter int `description:"是否有章节 0-否 1-是"`
  465. DetailImgUrl string `description:"报告详情长图地址"`
  466. DetailPdfUrl string `description:"报告详情PDF地址"`
  467. }
  468. func FormatReport2Item(origin *Report, chapterList []*ReportChapterItem) (item *ReportItem) {
  469. if origin == nil {
  470. return
  471. }
  472. item = new(ReportItem)
  473. item.Id = origin.Id
  474. item.ReportCode = origin.ReportCode
  475. item.ClassifyIdFirst = origin.ClassifyIdFirst
  476. item.ClassifyNameFirst = origin.ClassifyNameFirst
  477. item.ClassifyIdSecond = origin.ClassifyIdSecond
  478. item.ClassifyNameSecond = origin.ClassifyNameSecond
  479. item.Title = origin.Title
  480. item.Abstract = origin.Abstract
  481. item.Author = origin.Author
  482. item.Frequency = origin.Frequency
  483. item.State = origin.State
  484. item.Stage = origin.Stage
  485. item.Content = html.UnescapeString(origin.Content)
  486. item.VideoUrl = origin.VideoUrl
  487. item.VideoName = origin.VideoName
  488. item.VideoPlaySeconds = origin.VideoPlaySeconds
  489. item.VideoSize = origin.VideoSize
  490. item.AdminId = origin.AdminId
  491. item.AdminRealName = origin.AdminRealName
  492. item.PublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PublishTime)
  493. item.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, origin.ApproveTime)
  494. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  495. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  496. // eta1.8.3(研报改版)相关内容
  497. item.HeadImg = origin.HeadImg
  498. item.EndImg = origin.EndImg
  499. item.HeadStyle = origin.HeadStyle
  500. item.EndStyle = origin.EndStyle
  501. item.CanvasColor = origin.CanvasColor
  502. item.NeedSplice = origin.NeedSplice
  503. item.ClassifyIdThird = origin.ClassifyIdThird
  504. item.ClassifyNameThird = origin.ClassifyNameThird
  505. item.ReportLayout = origin.ReportLayout
  506. item.IsPublicPublish = origin.IsPublicPublish
  507. item.ContentModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ContentModifyTime)
  508. item.ReportCreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.ReportCreateTime)
  509. item.ChapterList = chapterList
  510. item.HasChapter = origin.HasChapter
  511. item.DetailImgUrl = origin.DetailImgUrl
  512. item.DetailPdfUrl = origin.DetailPdfUrl
  513. return
  514. }
  515. // ReportApproveReq 报告审批请求体
  516. type ReportApproveReq struct {
  517. ReportId int `description:"报告ID"`
  518. Pass bool `description:"是否通过审批"`
  519. }
  520. // UpdateReport 更新报告
  521. func (m *Report) UpdateReport(cols []string) (err error) {
  522. o := orm.NewOrmUsingDB("rddp")
  523. _, err = o.Update(m, cols...)
  524. return
  525. }
  526. // 获取分类列表
  527. func GetClassifyList(startSize, pageSize int, keyWord, companyType string) (items []*ClassifyList, err error) {
  528. sql := ``
  529. companyTypeSqlStr := ``
  530. if companyType == "ficc" {
  531. companyTypeSqlStr = " AND id != 40 AND parent_id != 40 "
  532. } else if companyType == "权益" {
  533. companyTypeSqlStr = " AND (id = 40 or parent_id = 40) "
  534. }
  535. pars := make([]interface{}, 0)
  536. if keyWord != "" {
  537. sql = `SELECT * FROM (
  538. SELECT * FROM classify
  539. WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE ?
  540. UNION
  541. SELECT * FROM classify
  542. WHERE id IN( SELECT parent_id FROM classify
  543. WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE ? )
  544. )AS t
  545. ORDER BY sort ASC,create_time ASC
  546. LIMIT ?,? `
  547. pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  548. } else {
  549. sql = `SELECT * FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
  550. sql += ` ORDER BY sort ASC, create_time ASC LIMIT ?,? `
  551. }
  552. pars = append(pars, startSize, pageSize)
  553. o := orm.NewOrmUsingDB("rddp")
  554. _, err = o.Raw(sql, pars...).QueryRows(&items)
  555. return
  556. }
  557. func GetClassifyListCount(keyWord, companyType string) (count int, err error) {
  558. sqlCount := ``
  559. companyTypeSqlStr := ``
  560. if companyType == "ficc" {
  561. companyTypeSqlStr = " AND id != 40 AND parent_id != 40 "
  562. } else if companyType == "权益" {
  563. companyTypeSqlStr = " AND (id = 40 or parent_id = 40) "
  564. }
  565. pars := make([]interface{}, 0)
  566. if keyWord != "" {
  567. sqlCount = `SELECT COUNT(1) AS count FROM (
  568. SELECT * FROM classify
  569. WHERE parent_id=0 ` + companyTypeSqlStr + ` AND classify_name LIKE ?
  570. UNION
  571. SELECT * FROM classify
  572. WHERE id IN(SELECT parent_id FROM classify
  573. WHERE parent_id>0 ` + companyTypeSqlStr + ` AND classify_name LIKE ? )
  574. )AS t `
  575. pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  576. } else {
  577. sqlCount = `SELECT COUNT(1) AS count FROM classify WHERE parent_id=0 ` + companyTypeSqlStr
  578. }
  579. o := orm.NewOrmUsingDB("rddp")
  580. err = o.Raw(sqlCount, pars...).QueryRow(&count)
  581. return
  582. }
  583. // GetClassifyListByKeywordV2
  584. // @Description: 获取分类列表
  585. // @author: Roc
  586. // @datetime 2024-06-19 09:49:33
  587. // @param keyWord string
  588. // @param enabled int
  589. // @return items []*ClassifyList
  590. // @return err error
  591. func GetClassifyListByKeywordV2(keyWord string, enabled int) (items []*ClassifyListV2, err error) {
  592. sql := ``
  593. pars := make([]interface{}, 0)
  594. sql = `SELECT * FROM classify WHERE 1=1 `
  595. if enabled == 1 {
  596. sql += ` AND enabled = 1 `
  597. }
  598. if keyWord != `` {
  599. sql += ` AND classify_name LIKE ? `
  600. pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
  601. }
  602. sql += ` ORDER BY sort ASC, create_time ASC`
  603. o := orm.NewOrmUsingDB("rddp")
  604. _, err = o.Raw(sql, pars...).QueryRows(&items)
  605. return
  606. }