media.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_mini_crm_ht/models"
  5. "eta/eta_mini_crm_ht/models/request"
  6. "eta/eta_mini_crm_ht/models/response"
  7. "eta/eta_mini_crm_ht/services"
  8. "eta/eta_mini_crm_ht/services/elastic"
  9. "eta/eta_mini_crm_ht/utils"
  10. "github.com/rdlucklib/rdluck_tools/paging"
  11. "os"
  12. "path"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. type MediaPdfController struct {
  18. BaseAuthController
  19. }
  20. // Author
  21. // @Title 获取报告作者接口
  22. // @Description 获取报告作者
  23. // @Success 200 {object} models.ReportAuthorResp
  24. // @router /author [get]
  25. func (this *MediaPdfController) Author() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. items, err := models.GetReportAuthorList()
  32. if err != nil {
  33. br.Msg = "获取失败!"
  34. br.ErrMsg = "获取失败,Err:" + err.Error()
  35. return
  36. }
  37. br.Ret = 200
  38. br.Success = true
  39. br.Msg = "获取成功"
  40. br.Data = items
  41. }
  42. // Add
  43. // @Title 添加研报
  44. // @Description 添加研报
  45. // @Param request body request.ReportPdfAddReq true "type json string"
  46. // @Success 200 {object} models.ReportAuthorResp
  47. // @router /add [post]
  48. func (this *MediaPdfController) Add() {
  49. br := new(models.BaseResponse).Init()
  50. defer func() {
  51. this.Data["json"] = br
  52. this.ServeJSON()
  53. }()
  54. var req request.ReportPdfAddReq
  55. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  56. br.Msg = "参数解析失败"
  57. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  58. return
  59. }
  60. if req.ClassifyIdFirst <= 0 && req.ClassifyIdSecond <= 0 && req.ClassifyIdThird <= 0 {
  61. br.Msg = "请选择研报所属分类"
  62. return
  63. }
  64. if req.PdfName == "" {
  65. br.Msg = "pdf名称为空"
  66. return
  67. }
  68. var nameFirst, nameSecond, nameThird *models.ClassifyView
  69. var err error
  70. if req.ClassifyIdFirst > 0 {
  71. nameFirst, err = models.GetClassifyById(req.ClassifyIdFirst)
  72. if err != nil {
  73. br.Msg = "添加失败"
  74. br.ErrMsg = "一级类名获取失败,Err:" + err.Error()
  75. return
  76. }
  77. } else {
  78. br.Msg = "该分类不存在或已删除,请刷新重试"
  79. return
  80. }
  81. if req.ClassifyIdSecond > 0 {
  82. nameSecond, err = models.GetClassifyById(req.ClassifyIdSecond)
  83. if err != nil {
  84. br.Msg = "添加失败"
  85. br.ErrMsg = "二级类名获取失败,Err:" + err.Error()
  86. return
  87. }
  88. }
  89. if req.ClassifyIdThird > 0 {
  90. nameThird, err = models.GetClassifyById(req.ClassifyIdThird)
  91. if err != nil {
  92. br.Msg = "添加失败"
  93. br.ErrMsg = "三级类名获取失败,Err:" + err.Error()
  94. return
  95. }
  96. }
  97. pdf := &models.ReportPdf{
  98. PdfUrl: req.PdfUrl,
  99. PdfName: req.PdfName,
  100. Title: req.Title,
  101. Author: req.Author,
  102. Abstract: req.Abstract,
  103. ClassifyIdFirst: req.ClassifyIdFirst,
  104. ClassifyNameFirst: nameFirst.ClassifyName,
  105. PublishTime: time.Now(),
  106. ModifyTime: time.Now(),
  107. SysUserId: this.SysUser.SysUserId,
  108. SysRealName: this.SysUser.SysRealName,
  109. State: utils.ReportStatusUp,
  110. }
  111. if nameSecond != nil {
  112. pdf.ClassifyIdSecond = nameSecond.Id
  113. pdf.ClassifyNameSecond = nameSecond.ClassifyName
  114. }
  115. if nameThird != nil {
  116. pdf.ClassifyIdThird = nameThird.Id
  117. pdf.ClassifyNameThird = nameThird.ClassifyName
  118. }
  119. insertId, err := pdf.Insert()
  120. if err != nil {
  121. br.Msg = "添加失败"
  122. br.ErrMsg = "pdf研报新增失败,Err:" + err.Error()
  123. return
  124. }
  125. pdf.ReportPdfId = int(insertId)
  126. // 添加es
  127. go func(reportPdf *models.ReportPdf) {
  128. reportpdfView := reportPdf.ToView()
  129. docId := strconv.Itoa(reportpdfView.ReportPdfId)
  130. err = elastic.EsAddOrEditReportPdf(utils.MINI_REPORT_INDEX_NAME, docId, reportpdfView)
  131. if err != nil {
  132. utils.FileLog.Info("pdf研报es新增失败,Err:" + err.Error())
  133. return
  134. }
  135. utils.FileLog.Info("pdf研报es新增成功, pdfId:" + docId)
  136. }(pdf)
  137. br.Msg = "添加成功"
  138. br.Ret = 200
  139. br.Success = true
  140. }
  141. // @Title 上传pdf研报
  142. // @Description 上传pdf研报
  143. // @Param File query file true "文件"
  144. // @Success 200 {object} models.ReportAuthorResp
  145. // @router /uploadPdf [post]
  146. func (this *MediaPdfController) UploadPdf() {
  147. br := new(models.BaseResponse).Init()
  148. defer func() {
  149. this.Data["json"] = br
  150. this.ServeJSON()
  151. }()
  152. f, h, err := this.GetFile("File")
  153. if err != nil {
  154. br.Msg = "获取资源信息失败"
  155. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  156. return
  157. }
  158. defer f.Close()
  159. ext := path.Ext(h.Filename)
  160. if ext != ".pdf" {
  161. br.Msg = "文件格式不正确"
  162. return
  163. }
  164. size, err := strconv.Atoi(utils.UPLOAD_PDF_SIZE)
  165. if err != nil {
  166. size = 15
  167. }
  168. if h.Size > 1024*1024*int64(size) {
  169. br.Msg = "文件大小不能超过15M"
  170. return
  171. }
  172. dateDir := time.Now().Format("20060102")
  173. uploadDir := utils.STATIC_DIR + "dongwu/" + dateDir
  174. err = os.MkdirAll(uploadDir, utils.DIR_MOD)
  175. if err != nil {
  176. br.Msg = "存储目录创建失败"
  177. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  178. return
  179. }
  180. randStr := utils.GetRandStringNoSpecialChar(28)
  181. fileName := randStr + ext
  182. fpath := uploadDir + "/" + fileName
  183. err = this.SaveToFile("File", fpath)
  184. if err != nil {
  185. br.Msg = "文件上传失败"
  186. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  187. return
  188. }
  189. pdfUploadDir := utils.RESOURCE_DIR + "pdf/"
  190. savePdfToOssPath := pdfUploadDir + time.Now().Format("200601/20060102/")
  191. pptName := utils.GetRandStringNoSpecialChar(28)
  192. savePdfToOssPath += pptName + ".pdf"
  193. defer func() {
  194. _ = os.Remove(fpath)
  195. }()
  196. ossClient := services.NewOssClient()
  197. if ossClient == nil {
  198. br.Msg = "文件上传失败"
  199. br.ErrMsg = "初始化OSS服务失败"
  200. return
  201. }
  202. pdfUrl, err := ossClient.UploadFile("", fpath, savePdfToOssPath)
  203. if err != nil {
  204. br.Msg = "文件上传失败"
  205. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  206. return
  207. }
  208. base := path.Base(h.Filename)
  209. resp := new(response.ReportPdfUploadResp)
  210. resp.Url = pdfUrl
  211. resp.FileName = base
  212. br.Data = resp
  213. br.Msg = "上传成功"
  214. br.Ret = 200
  215. br.Success = true
  216. }
  217. // List
  218. // @Title pdf研报列表
  219. // @Description pdf研报列表
  220. // @Param PageSize query int true "每页数据条数"
  221. // @Param CurrentIndex query int true "当前页页码,从1开始"
  222. // @Param ClassifyIds query string true "二级分类id,可多选用英文,隔开"
  223. // @Param State query int true "研报状态, 1:已发布 2:未发布"
  224. // @Param PublishStartDate query string true "发布开始时间"
  225. // @Param PublishEndDate query string true "发布结束时间"
  226. // @Param ModifyStartDate query string true "更新开始时间"
  227. // @Param ModifyEndDate query string true "更新结束时间"
  228. // @Param KeyWord query string true "报告标题/创建人"
  229. // @Param SortParam query string true "排序字段"
  230. // @Param SortType query string true "排序方式"
  231. // @Success 200 {object} models.ReportAuthorResp
  232. // @router /list [get]
  233. func (this *MediaPdfController) List() {
  234. br := new(models.BaseResponse).Init()
  235. defer func() {
  236. this.Data["json"] = br
  237. this.ServeJSON()
  238. }()
  239. pageSize, _ := this.GetInt("PageSize")
  240. currentIndex, _ := this.GetInt("CurrentIndex")
  241. classifyIds := this.GetString("ClassifyIds")
  242. state, _ := this.GetInt("State")
  243. publishStartDate := this.GetString("PublishStartDate")
  244. publishEndDate := this.GetString("PublishEndDate")
  245. modifyStartDate := this.GetString("ModifyStartDate")
  246. modifyEndDate := this.GetString("ModifyEndDate")
  247. keyWord := this.GetString("KeyWord")
  248. sortParam := this.GetString("SortParam")
  249. sortType := this.GetString("SortType")
  250. var condition string
  251. var pars []interface{}
  252. if pageSize <= 0 {
  253. pageSize = utils.PageSize20
  254. }
  255. if currentIndex <= 0 {
  256. currentIndex = 1
  257. }
  258. if classifyIds != "" {
  259. classifyArr := strings.Split(classifyIds, ",")
  260. condition += " AND classify_id_second in (" + utils.GetOrmReplaceHolder(len(classifyArr)) + ")"
  261. pars = append(pars, classifyArr)
  262. }
  263. switch state {
  264. case utils.ReportStatusUp:
  265. condition += " AND state = ?"
  266. pars = append(pars, state)
  267. case utils.ReportStatusDown:
  268. condition += " AND state = ?"
  269. pars = append(pars, state)
  270. }
  271. if publishStartDate != "" && publishEndDate != "" {
  272. condition += " AND publish_time >= ?"
  273. publishStartTime, err := time.Parse(utils.FormatDate, publishStartDate)
  274. if err != nil {
  275. br.Msg = "日期格式有误"
  276. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  277. return
  278. }
  279. publishStartDateStr := publishStartTime.Format(utils.FormatDateTime)
  280. pars = append(pars, publishStartDateStr)
  281. condition += " AND publish_time <= ?"
  282. publishEndTime, err := time.Parse(utils.FormatDate, publishEndDate)
  283. if err != nil {
  284. br.Msg = "日期格式有误"
  285. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  286. return
  287. }
  288. publishEndTime = publishEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
  289. publishEndDateStr := publishEndTime.Format(utils.FormatDateTime)
  290. pars = append(pars, publishEndDateStr)
  291. }
  292. if modifyStartDate != "" && modifyEndDate != "" {
  293. condition += " AND modify_time >= ?"
  294. modifyStartTime, err := time.Parse(utils.FormatDate, modifyStartDate)
  295. if err != nil {
  296. br.Msg = "日期格式有误"
  297. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  298. return
  299. }
  300. modifyStartDateStr := modifyStartTime.Format(utils.FormatDateTime)
  301. pars = append(pars, modifyStartDateStr)
  302. condition += " AND modify_time <= ?"
  303. modifyEndTime, err := time.Parse(utils.FormatDate, modifyEndDate)
  304. if err != nil {
  305. br.Msg = "日期格式有误"
  306. br.ErrMsg = "日期格式有误,Err:" + err.Error()
  307. return
  308. }
  309. modifyEndTime = modifyEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
  310. modifyEndDateStr := modifyEndTime.Format(utils.FormatDateTime)
  311. pars = append(pars, modifyEndDateStr)
  312. }
  313. if keyWord != "" {
  314. condition += ` AND (title like ? OR sys_real_name like ?) `
  315. pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  316. }
  317. var sortCondition string
  318. if sortParam != "" && sortType != "" {
  319. sortCondition = " ORDER BY "
  320. var param, sort string
  321. switch sortParam {
  322. case "PublishTime":
  323. param = "publish_time"
  324. case "ModifyTime":
  325. param = "modify_time"
  326. }
  327. switch sortType {
  328. case "asc":
  329. sort = " ASC "
  330. case "desc":
  331. sort = " DESC "
  332. }
  333. if param != "" && sort != "" {
  334. sortCondition += param + " " + sort
  335. } else {
  336. sortCondition = ""
  337. }
  338. }
  339. if sortCondition == "" {
  340. sortCondition = ` ORDER BY modify_time DESC `
  341. }
  342. total, err := models.GetReportPdfCountByCondition(condition, pars)
  343. if err != nil {
  344. br.Msg = "获取研报列表失败"
  345. br.ErrMsg = "获取研报列表统计失败,Err:" + err.Error()
  346. return
  347. }
  348. startSize := utils.StartIndex(currentIndex, pageSize)
  349. reportList, err := models.GetReportPdfByCondition(condition, sortCondition, pars, startSize, pageSize)
  350. if err != nil {
  351. br.Msg = "获取研报列表失败"
  352. br.ErrMsg = "获取研报列表失败,Err:" + err.Error()
  353. return
  354. }
  355. page := paging.GetPaging(currentIndex, pageSize, total)
  356. resp := new(response.ReportPdfListResp)
  357. resp.List = reportList
  358. resp.Paging = page
  359. br.Ret = 200
  360. br.Success = true
  361. br.Data = resp
  362. br.Msg = "获取成功"
  363. }
  364. // Edit
  365. // @Title 编辑研报
  366. // @Description 编辑研报
  367. // @Param request body request.ReportPdfEditReq true "type json string"
  368. // @Success 200 {object} models.ReportAuthorResp
  369. // @router /edit [post]
  370. func (this *MediaPdfController) Edit() {
  371. br := new(models.BaseResponse).Init()
  372. defer func() {
  373. this.Data["json"] = br
  374. this.ServeJSON()
  375. }()
  376. var req request.ReportPdfEditReq
  377. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  378. br.Msg = "参数错误"
  379. br.ErrMsg = "参数错误,Err:" + err.Error()
  380. return
  381. }
  382. if req.ClassifyIdFirst <= 0 {
  383. br.Msg = "请选择研报所属的一级分类"
  384. return
  385. }
  386. if req.ClassifyIdSecond <= 0 {
  387. br.Msg = "请选择研报所属的二级分类"
  388. return
  389. }
  390. if req.PdfUrl == "" {
  391. br.Msg = "请上传研报文件"
  392. return
  393. }
  394. if req.PdfName == "" {
  395. br.Msg = "请填写研报名称"
  396. return
  397. }
  398. reportPdf, err := models.GetReportPdfById(req.ReportPdfId)
  399. if err != nil {
  400. if err.Error() == utils.ErrNoRow() {
  401. br.Msg = "研报不存在或已删除,请刷新页面"
  402. return
  403. }
  404. br.Msg = "获取研报失败"
  405. br.ErrMsg = "获取研报失败,系统错误,Err:" + err.Error()
  406. return
  407. }
  408. nameFirst, err := models.GetClassifyById(req.ClassifyIdFirst)
  409. if err != nil {
  410. br.Msg = "文件编辑失败"
  411. br.ErrMsg = "一级类名获取失败,Err:" + err.Error()
  412. return
  413. }
  414. nameSecond, err := models.GetClassifyById(req.ClassifyIdSecond)
  415. if err != nil {
  416. br.Msg = "文件编辑失败"
  417. br.ErrMsg = "二级类名获取失败,Err:" + err.Error()
  418. return
  419. }
  420. if reportPdf.PdfName != req.PdfName || reportPdf.Title != req.Title || reportPdf.ClassifyIdFirst != req.ClassifyIdFirst || reportPdf.ClassifyIdSecond != req.ClassifyIdSecond || reportPdf.Author != req.Author || reportPdf.Abstract != req.Abstract || reportPdf.PdfUrl != req.PdfUrl {
  421. reportPdf.Title = req.Title
  422. reportPdf.PdfName = req.PdfName
  423. reportPdf.ClassifyIdFirst = req.ClassifyIdFirst
  424. reportPdf.ClassifyIdSecond = req.ClassifyIdSecond
  425. reportPdf.ClassifyNameFirst = nameFirst.ClassifyName
  426. reportPdf.ClassifyNameSecond = nameSecond.ClassifyName
  427. reportPdf.Author = req.Author
  428. reportPdf.Abstract = req.Abstract
  429. reportPdf.PdfUrl = req.PdfUrl
  430. reportPdf.ModifyTime = time.Now()
  431. err = reportPdf.Update([]string{"pdf_name", "title", "classify_id_first", "classify_id_second", "classify_name_first", "classify_name_second", "author", "abstract", "pdf_url", "modify_time"})
  432. if err != nil {
  433. br.Msg = "文件更新失败"
  434. br.ErrMsg = "文件更新失败,Err:" + err.Error()
  435. return
  436. }
  437. // 编辑es
  438. go func(reportPdf *models.ReportPdf) {
  439. reportpdfView := reportPdf.ToView()
  440. docId := strconv.Itoa(reportpdfView.ReportPdfId)
  441. err = elastic.EsAddOrEditReportPdf(utils.MINI_REPORT_INDEX_NAME, docId, reportpdfView)
  442. if err != nil {
  443. utils.FileLog.Info("pdf研报es编辑失败,Err:" + err.Error())
  444. return
  445. }
  446. utils.FileLog.Info("pdf研报es编辑成功, pdfId:" + docId)
  447. }(reportPdf)
  448. }
  449. br.Msg = "研报编辑成功"
  450. br.Ret = 200
  451. br.Success = true
  452. }
  453. // Publish
  454. // @Title 发布研报
  455. // @Description 发布研报
  456. // @Param ReportPdfId query string true "pdf研报id"
  457. // @Success 200 {object} models.BaseResponse
  458. // @router /publish [get]
  459. func (this *MediaPdfController) Publish() {
  460. br := new(models.BaseResponse).Init()
  461. defer func() {
  462. this.Data["json"] = br
  463. this.ServeJSON()
  464. }()
  465. ReportPdfId, _ := this.GetInt("ReportPdfId")
  466. reportPdf, err := models.GetReportPdfById(ReportPdfId)
  467. if err != nil {
  468. if err.Error() == utils.ErrNoRow() {
  469. br.Msg = "研报不存在或已删除,请刷新页面"
  470. return
  471. }
  472. br.Msg = "获取研报失败"
  473. br.ErrMsg = "获取研报失败,系统错误,Err:" + err.Error()
  474. return
  475. }
  476. if reportPdf.State == utils.ReportStatusUp {
  477. br.Msg = "研报已发布"
  478. return
  479. }
  480. reportPdf.State = utils.ReportStatusUp
  481. reportPdf.PublishTime = time.Now()
  482. err = reportPdf.Update([]string{"state", "publish_time"})
  483. if err != nil {
  484. br.Msg = "发布研报失败"
  485. br.ErrMsg = "发布研报失败,系统错误,Err:" + err.Error()
  486. return
  487. }
  488. // 修改es
  489. go func(reportPdf *models.ReportPdf) {
  490. reportpdfView := reportPdf.ToView()
  491. docId := strconv.Itoa(reportpdfView.ReportPdfId)
  492. err = elastic.EsAddOrEditReportPdf(utils.MINI_REPORT_INDEX_NAME, docId, reportpdfView)
  493. if err != nil {
  494. utils.FileLog.Info("pdf研报es发布失败,Err:" + err.Error())
  495. return
  496. }
  497. utils.FileLog.Info("pdf研报es发布成功, pdfId:" + docId)
  498. }(reportPdf)
  499. br.Msg = "发布研报成功"
  500. br.Ret = 200
  501. br.Success = true
  502. }
  503. // PublishCancel
  504. // @Title 取消发布研报
  505. // @Description 取消发布研报
  506. // @Param ReportPdfId query string true "pdf研报id"
  507. // @Success 200 {object} models.BaseResponse
  508. // @router /publishCancel [get]
  509. func (this *MediaPdfController) PublishCancel() {
  510. br := new(models.BaseResponse).Init()
  511. defer func() {
  512. this.Data["json"] = br
  513. this.ServeJSON()
  514. }()
  515. ReportPdfId, _ := this.GetInt("ReportPdfId")
  516. reportPdf, err := models.GetReportPdfById(ReportPdfId)
  517. if err != nil {
  518. if err.Error() == utils.ErrNoRow() {
  519. br.Msg = "研报不存在或已删除,请刷新页面"
  520. return
  521. }
  522. br.Msg = "获取研报失败"
  523. br.ErrMsg = "获取研报失败,系统错误,Err:" + err.Error()
  524. return
  525. }
  526. if reportPdf.State == utils.ReportStatusDown {
  527. br.Msg = "研报已撤销"
  528. return
  529. }
  530. reportPdf.State = utils.ReportStatusDown
  531. err = reportPdf.Update([]string{"state"})
  532. if err != nil {
  533. br.Msg = "发布研报失败"
  534. br.ErrMsg = "发布研报失败,系统错误,Err:" + err.Error()
  535. return
  536. }
  537. // 修改es
  538. go func(reportPdf *models.ReportPdf) {
  539. reportpdfView := reportPdf.ToView()
  540. docId := strconv.Itoa(reportpdfView.ReportPdfId)
  541. err = elastic.EsAddOrEditReportPdf(utils.MINI_REPORT_INDEX_NAME, docId, reportpdfView)
  542. if err != nil {
  543. utils.FileLog.Info("pdf研报es取消发布失败,Err:" + err.Error())
  544. return
  545. }
  546. utils.FileLog.Info("pdf研报es取消发布成功, pdfId:" + docId)
  547. }(reportPdf)
  548. br.Msg = "撤销研报成功"
  549. br.Ret = 200
  550. br.Success = true
  551. }
  552. // delete
  553. // @Title 删除研报
  554. // @Description 删除研报
  555. // @Param ReportPdfId query string true "pdf研报id"
  556. // @Success 200 {object} models.BaseResponse
  557. // @router /delete [get]
  558. func (this *MediaPdfController) Delete() {
  559. br := new(models.BaseResponse).Init()
  560. defer func() {
  561. this.Data["json"] = br
  562. this.ServeJSON()
  563. }()
  564. ReportPdfId, _ := this.GetInt("ReportPdfId")
  565. reportPdf, err := models.GetReportPdfById(ReportPdfId)
  566. if err != nil {
  567. if err.Error() == utils.ErrNoRow() {
  568. br.Msg = "研报不存在或已删除,请刷新页面"
  569. return
  570. }
  571. br.Msg = "获取研报失败"
  572. br.ErrMsg = "获取研报失败,系统错误,Err:" + err.Error()
  573. return
  574. }
  575. if reportPdf.State == utils.ReportStatusUp {
  576. br.Msg = "研报已发布,不可以删除"
  577. return
  578. }
  579. reportPdf.State = utils.ReportStatusDown
  580. err = reportPdf.Delete()
  581. if err != nil {
  582. br.Msg = "研报删除失败"
  583. br.ErrMsg = "研报删除失败,系统错误,Err:" + err.Error()
  584. return
  585. }
  586. // 删除es
  587. go func(reportPdf *models.ReportPdf) {
  588. reportpdfView := reportPdf.ToView()
  589. docId := strconv.Itoa(reportpdfView.ReportPdfId)
  590. err = elastic.EsDeleteData(utils.MINI_REPORT_INDEX_NAME, docId)
  591. if err != nil {
  592. utils.FileLog.Info("pdf研报es删除失败,Err:" + err.Error())
  593. return
  594. }
  595. utils.FileLog.Info("pdf研报es删除成功, pdfId:" + docId)
  596. }(reportPdf)
  597. br.Msg = "删除研报成功"
  598. br.Ret = 200
  599. br.Success = true
  600. }
  601. // Detail
  602. // @Title 研报详情
  603. // @Description 研报详情
  604. // @Param ReportPdfId query string true "pdf研报id"
  605. // @Success 200 {object} models.BaseResponse
  606. // @router /detail [get]
  607. func (this *MediaPdfController) Detail() {
  608. br := new(models.BaseResponse).Init()
  609. defer func() {
  610. this.Data["json"] = br
  611. this.ServeJSON()
  612. }()
  613. ReportPdfId, _ := this.GetInt("ReportPdfId")
  614. reportPdf, err := models.GetReportPdfById(ReportPdfId)
  615. if err != nil {
  616. if err.Error() == utils.ErrNoRow() {
  617. br.Msg = "研报不存在或已删除,请刷新页面"
  618. return
  619. }
  620. br.Msg = "获取研报失败"
  621. br.ErrMsg = "获取研报失败,系统错误,Err:" + err.Error()
  622. return
  623. }
  624. br.Data = reportPdf
  625. br.Ret = 200
  626. br.Success = true
  627. br.Msg = "获取研报成功"
  628. }