report_pdf.go 20 KB

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