report.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. package english_report
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_eta_api/controllers"
  7. "hongze/hz_eta_api/models"
  8. "hongze/hz_eta_api/models/company"
  9. "hongze/hz_eta_api/services"
  10. "hongze/hz_eta_api/services/alarm_msg"
  11. "hongze/hz_eta_api/utils"
  12. "html"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. // EnglishReportController 研报活动模块
  18. type EnglishReportController struct {
  19. controllers.BaseAuthController
  20. }
  21. // @Title 新增报告接口
  22. // @Description 新增报告
  23. // @Param request body models.AddEnglishReportReq true "type json string"
  24. // @Success 200 {object} models.AddEnglishReportResp
  25. // @router /add [post]
  26. func (this *EnglishReportController) Add() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. sysUser := this.SysUser
  33. if sysUser == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录,SysUser Is Empty"
  36. br.Ret = 408
  37. return
  38. }
  39. var req models.AddEnglishReportReq
  40. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  41. if err != nil {
  42. br.Msg = "参数解析异常!"
  43. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  44. return
  45. }
  46. if req.Content == "" {
  47. br.Msg = "请输入内容"
  48. return
  49. }
  50. if req.Overview == "" {
  51. br.Msg = "请输入overview"
  52. return
  53. }
  54. if req.Abstract == "" {
  55. br.Msg = "请输入摘要"
  56. return
  57. }
  58. var contentSub string
  59. if req.Content != "" {
  60. content, e := services.FilterReportContentBr(req.Content)
  61. if e != nil {
  62. br.Msg = "内容去除前后空格失败"
  63. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  64. return
  65. }
  66. req.Content = content
  67. contentSub, err = services.GetReportContentSub(req.Content)
  68. if err != nil {
  69. go alarm_msg.SendAlarmMsg("ContentSub 失败,Err:"+err.Error(), 3)
  70. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  71. }
  72. }
  73. maxStage, err := models.GetEnglishReportStage(req.ClassifyIdFirst, req.ClassifyIdSecond)
  74. if err != nil {
  75. br.Msg = "期数获取失败!"
  76. br.ErrMsg = "期数获取失败,Err:" + err.Error()
  77. return
  78. }
  79. item := new(models.EnglishReport)
  80. item.AddType = req.AddType
  81. item.ClassifyIdFirst = req.ClassifyIdFirst
  82. item.ClassifyNameFirst = req.ClassifyNameFirst
  83. item.ClassifyIdSecond = req.ClassifyIdSecond
  84. item.ClassifyNameSecond = req.ClassifyNameSecond
  85. item.Title = req.Title
  86. item.Abstract = req.Abstract
  87. item.Author = req.Author
  88. item.Frequency = req.Frequency
  89. item.State = req.State
  90. item.Content = html.EscapeString(req.Content)
  91. item.Stage = maxStage + 1
  92. item.ContentSub = html.EscapeString(contentSub)
  93. item.CreateTime = req.CreateTime
  94. item.ModifyTime = time.Now()
  95. item.Overview = req.Overview
  96. item.AdminId = sysUser.AdminId
  97. item.AdminRealName = sysUser.RealName
  98. newReportId, err := models.AddEnglishReport(item)
  99. if err != nil {
  100. br.Msg = "保存失败"
  101. br.ErrMsg = "保存失败,Err:" + err.Error()
  102. return
  103. }
  104. reportCode := utils.MD5(strconv.Itoa(int(newReportId)))
  105. //修改唯一编码
  106. {
  107. go models.ModifyEnglishReportCode(newReportId, reportCode)
  108. }
  109. resp := new(models.AddEnglishReportResp)
  110. resp.ReportId = newReportId
  111. resp.ReportCode = reportCode
  112. br.Ret = 200
  113. br.Success = true
  114. br.Msg = "保存成功"
  115. br.Data = resp
  116. }
  117. // @Title 编辑报告接口
  118. // @Description 编辑报告
  119. // @Param request body models.EditEnglishReportReq true "type json string"
  120. // @Success 200 {object} models.EditEnglishReportResp
  121. // @router /edit [post]
  122. func (this *EnglishReportController) Edit() {
  123. br := new(models.BaseResponse).Init()
  124. defer func() {
  125. this.Data["json"] = br
  126. this.ServeJSON()
  127. }()
  128. sysUser := this.SysUser
  129. if sysUser == nil {
  130. br.Msg = "请登录"
  131. br.ErrMsg = "请登录,SysUser Is Empty"
  132. br.Ret = 408
  133. return
  134. }
  135. var req models.EditEnglishReportReq
  136. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  137. if err != nil {
  138. br.Msg = "参数解析异常!"
  139. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  140. return
  141. }
  142. if req.Content == "" {
  143. br.Msg = "请输入内容"
  144. return
  145. }
  146. if req.Overview == "" {
  147. br.Msg = "请输入overview"
  148. return
  149. }
  150. if req.Abstract == "" {
  151. br.Msg = "请输入摘要"
  152. return
  153. }
  154. markStatus, err := services.UpdateEnReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName)
  155. if err != nil {
  156. br.Msg = err.Error()
  157. return
  158. }
  159. if markStatus.Status == 1 {
  160. br.Msg = markStatus.Msg
  161. return
  162. }
  163. var contentSub string
  164. if req.Content != "" {
  165. content, e := services.FilterReportContentBr(req.Content)
  166. if e != nil {
  167. br.Msg = "内容去除前后空格失败"
  168. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  169. return
  170. }
  171. req.Content = content
  172. contentSub, err = services.GetReportContentSub(req.Content)
  173. if err != nil {
  174. go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
  175. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  176. }
  177. }
  178. var stage int
  179. report, _ := models.GetEnglishReportById(int(req.ReportId))
  180. if report != nil {
  181. if report.ClassifyNameFirst != req.ClassifyNameFirst || report.ClassifyNameSecond != req.ClassifyNameSecond {
  182. maxStage, _ := models.GetEnglishReportStageEdit(req.ClassifyIdFirst, req.ClassifyIdSecond, int(req.ReportId))
  183. maxStage = maxStage + 1
  184. stage = maxStage
  185. } else {
  186. stage = report.Stage
  187. }
  188. }
  189. item := new(models.EnglishReport)
  190. item.ClassifyIdFirst = req.ClassifyIdFirst
  191. item.ClassifyNameFirst = req.ClassifyNameFirst
  192. item.ClassifyIdSecond = req.ClassifyIdSecond
  193. item.ClassifyNameSecond = req.ClassifyNameSecond
  194. item.Title = req.Title
  195. item.Abstract = req.Abstract
  196. item.Author = req.Author
  197. item.Frequency = req.Frequency
  198. item.State = req.State
  199. item.Stage = stage
  200. item.Content = html.EscapeString(req.Content)
  201. item.ContentSub = html.EscapeString(contentSub)
  202. item.CreateTime = req.CreateTime
  203. item.Overview = req.Overview
  204. err = models.EditEnglishReport(item, req.ReportId)
  205. if err != nil {
  206. br.Msg = "保存失败"
  207. br.ErrMsg = "保存失败,Err:" + err.Error()
  208. return
  209. }
  210. reportCode := utils.MD5(strconv.Itoa(int(req.ReportId)))
  211. resp := new(models.EditEnglishReportResp)
  212. resp.ReportId = req.ReportId
  213. resp.ReportCode = reportCode
  214. br.Ret = 200
  215. br.Success = true
  216. br.Msg = "保存成功"
  217. br.Data = resp
  218. }
  219. // @Title 获取报告详情接口
  220. // @Description 获取报告详情
  221. // @Param request body models.ReportDetailReq true "type json string"
  222. // @Success 200 {object} models.EnglishReportDetailView
  223. // @router /detail [get]
  224. func (this *EnglishReportController) Detail() {
  225. br := new(models.BaseResponse).Init()
  226. defer func() {
  227. this.Data["json"] = br
  228. this.ServeJSON()
  229. }()
  230. /*var req models.ReportDetailReq
  231. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  232. if err != nil {
  233. br.Msg = "参数解析异常!"
  234. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  235. return
  236. }
  237. if req.ReportId <= 0 {
  238. br.Msg = "参数错误"
  239. return
  240. }*/
  241. reportId, err := this.GetInt("ReportId")
  242. if err != nil {
  243. br.Msg = "获取参数失败!"
  244. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  245. return
  246. }
  247. if reportId <= 0 {
  248. br.Msg = "参数错误"
  249. return
  250. }
  251. item, err := models.GetEnglishReportById(reportId)
  252. if err != nil {
  253. br.Msg = "获取失败"
  254. br.ErrMsg = "获取失败,Err:" + err.Error()
  255. return
  256. }
  257. item.Content = html.UnescapeString(item.Content)
  258. item.ContentSub = html.UnescapeString(item.ContentSub)
  259. br.Ret = 200
  260. br.Success = true
  261. br.Msg = "获取成功"
  262. br.Data = item
  263. }
  264. // @Title 获取报告列表接口
  265. // @Description 获取报告列表
  266. // @Param PageSize query int true "每页数据条数"
  267. // @Param CurrentIndex query int true "当前页页码,从1开始"
  268. // @Param StartDate query string true "开始时间"
  269. // @Param EndDate query string true "结束时间"
  270. // @Param Frequency query string true "频度"
  271. // @Param ClassifyNameFirst query string true "一级分类名称"
  272. // @Param ClassifyNameSecond query string true "二级分类名称"
  273. // @Param State query int true "状态"
  274. // @Param KeyWord query string true "搜索关键词"
  275. // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
  276. // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
  277. // @Success 200 {object} models.ReportListResp
  278. // @router /list [get]
  279. func (this *EnglishReportController) ListReport() {
  280. br := new(models.BaseResponse).Init()
  281. defer func() {
  282. this.Data["json"] = br
  283. this.ServeJSON()
  284. }()
  285. sysUser := this.SysUser
  286. if sysUser == nil {
  287. br.Msg = "请登录"
  288. br.ErrMsg = "请登录,SysUser Is Empty"
  289. br.Ret = 408
  290. return
  291. }
  292. pageSize, _ := this.GetInt("PageSize")
  293. currentIndex, _ := this.GetInt("CurrentIndex")
  294. startDate := this.GetString("StartDate")
  295. endDate := this.GetString("EndDate")
  296. frequency := this.GetString("Frequency")
  297. classifyNameFirst := this.GetString("ClassifyNameFirst")
  298. classifyNameSecond := this.GetString("ClassifyNameSecond")
  299. state, _ := this.GetInt("State")
  300. keyWord := this.GetString("KeyWord")
  301. companyType := this.GetString("CompanyType")
  302. // 群发邮件状态筛选
  303. emailState, _ := this.GetInt("EmailState")
  304. var startSize int
  305. if pageSize <= 0 {
  306. pageSize = utils.PageSize20
  307. }
  308. if currentIndex <= 0 {
  309. currentIndex = 1
  310. }
  311. startSize = utils.StartIndex(currentIndex, pageSize)
  312. var condition string
  313. var pars []interface{}
  314. if keyWord != "" {
  315. condition += ` AND (title LIKE '%` + keyWord + `%' OR author LIKE '%` + keyWord + `%' ) `
  316. }
  317. if startDate != "" {
  318. condition += ` AND create_time >= ? `
  319. pars = append(pars, startDate)
  320. }
  321. if endDate != "" {
  322. condition += ` AND create_time <= ? `
  323. pars = append(pars, endDate)
  324. }
  325. if frequency != "" {
  326. condition += ` AND frequency = ? `
  327. pars = append(pars, frequency)
  328. }
  329. if classifyNameFirst != "" {
  330. condition += ` AND classify_name_first = ? `
  331. pars = append(pars, classifyNameFirst)
  332. }
  333. if classifyNameSecond != "" {
  334. condition += ` AND classify_name_second = ? `
  335. pars = append(pars, classifyNameSecond)
  336. }
  337. if state > 0 {
  338. condition += ` AND state = ? `
  339. pars = append(pars, state)
  340. }
  341. // 未群发邮件(包含推送邮件失败的)
  342. if emailState == 1 {
  343. failIds, e := models.GetHasFailEmailLogReportIds()
  344. if e != nil {
  345. br.Msg = "获取失败"
  346. br.ErrMsg = "获取存在邮件推送失败记录的英文报告IDs失败, Err:" + e.Error()
  347. return
  348. }
  349. condition += ` AND email_state = 0`
  350. if len(failIds) > 0 {
  351. condition += ` OR id IN (` + utils.GetOrmInReplace(len(failIds)) + `)`
  352. pars = append(pars, failIds)
  353. }
  354. }
  355. // 已群发邮件
  356. if emailState == 2 {
  357. successIds, e := models.GetSuccessEmailLogReportIds()
  358. if e != nil {
  359. br.Msg = "获取失败"
  360. br.ErrMsg = "获取邮件推送记录均为成功的英文报告IDs失败, Err:" + e.Error()
  361. return
  362. }
  363. condition += ` AND email_state = 1`
  364. if len(successIds) > 0 {
  365. condition += ` AND id IN (` + utils.GetOrmInReplace(len(successIds)) + `)`
  366. pars = append(pars, successIds)
  367. }
  368. }
  369. total, err := models.GetEnglishReportListCount(condition, pars, companyType)
  370. if err != nil {
  371. br.Msg = "获取失败"
  372. br.ErrMsg = "获取失败,Err:" + err.Error()
  373. return
  374. }
  375. list, err := models.GetEnglishReportList(condition, pars, companyType, startSize, pageSize)
  376. if err != nil {
  377. br.Msg = "获取失败"
  378. br.ErrMsg = "获取失败,Err:" + err.Error()
  379. return
  380. }
  381. // 获取邮件配置-是否有权限群发
  382. conf := new(models.EnglishReportEmailConf)
  383. authKey := "english_report_email_conf"
  384. confAuth, e := company.GetConfigDetailByCode(authKey)
  385. if e != nil {
  386. br.Msg = "获取失败"
  387. br.ErrMsg = "获取群发邮件权限失败, Err: " + e.Error()
  388. return
  389. }
  390. if confAuth.ConfigValue == "" {
  391. br.Msg = "获取失败"
  392. br.ErrMsg = "群发邮件配置为空"
  393. return
  394. }
  395. if e := json.Unmarshal([]byte(confAuth.ConfigValue), &conf); e != nil {
  396. br.Msg = "获取失败"
  397. br.ErrMsg = "群发邮件配置有误"
  398. return
  399. }
  400. authOk := false
  401. authArr := strings.Split(conf.SendAuthGroup, ",")
  402. if utils.InArrayByStr(authArr, sysUser.RoleTypeCode) {
  403. authOk = true
  404. }
  405. // 是否有群发邮件失败的记录,标记红点
  406. failList, e := models.GetEnglishReportEmailLogFailList(0)
  407. if e != nil {
  408. br.Msg = "获取失败"
  409. br.ErrMsg = "获取群发邮件记录失败, Err: " + e.Error()
  410. return
  411. }
  412. failMap := make(map[int]bool, 0)
  413. for i := range failList {
  414. failMap[failList[i].ReportId] = true
  415. }
  416. for _, item := range list {
  417. if item.State == 2 {
  418. item.ShareUrl = "https://share.hzinsights.com/reportEn?code=" + item.ReportCode
  419. }
  420. item.EmailAuth = authOk
  421. item.EmailHasFail = failMap[item.Id]
  422. // 邮箱PV大于0的时候, 不展示最初版本的PV
  423. if item.PvEmail > 0 {
  424. item.Pv = 0
  425. }
  426. /*key := fmt.Sprint(`crm:enReport:edit:`, item.Id)
  427. opUserId, _ := utils.Rc.RedisInt(key)
  428. //如果当前没有人操作,获取当前操作人是本人,那么编辑按钮可用
  429. if opUserId <= 0 || (opUserId == this.SysUser.AdminId) {
  430. item.CanEdit = true
  431. } else {
  432. adminInfo, errAdmin := system.GetSysUserById(opUserId)
  433. if errAdmin != nil {
  434. br.Msg = "获取失败"
  435. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  436. return
  437. }
  438. item.Editor = adminInfo.RealName
  439. }*/
  440. markStatus, err := services.UpdateEnReportEditMark(item.Id, this.SysUser.AdminId, 2, this.SysUser.RealName)
  441. if err != nil {
  442. br.Msg = "查询标记状态失败"
  443. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  444. return
  445. }
  446. if markStatus.Status == 0 {
  447. item.CanEdit = true
  448. } else {
  449. item.Editor = markStatus.Editor
  450. }
  451. }
  452. page := paging.GetPaging(currentIndex, pageSize, total)
  453. resp := new(models.EnglishReportListResp)
  454. resp.Paging = page
  455. resp.List = list
  456. br.Ret = 200
  457. br.Success = true
  458. br.Msg = "获取成功"
  459. br.Data = resp
  460. }
  461. // @Title 发布报告接口
  462. // @Description 发布报告
  463. // @Param request body models.PublishReq true "type json string"
  464. // @Success 200 Ret=200 发布成功
  465. // @router /publish [post]
  466. func (this *EnglishReportController) PublishReport() {
  467. br := new(models.BaseResponse).Init()
  468. defer func() {
  469. this.Data["json"] = br
  470. this.ServeJSON()
  471. }()
  472. var req models.PublishReq
  473. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  474. if err != nil {
  475. br.Msg = "参数解析异常!"
  476. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  477. return
  478. }
  479. reportIds := req.ReportIds
  480. if reportIds == "" {
  481. br.Msg = "参数错误"
  482. br.ErrMsg = "参数错误,报告id不可为空"
  483. return
  484. }
  485. reportArr := strings.Split(reportIds, ",")
  486. for _, v := range reportArr {
  487. vint, err := strconv.Atoi(v)
  488. if err != nil {
  489. br.Msg = "参数错误"
  490. br.ErrMsg = "参数错误,Err:" + err.Error()
  491. return
  492. }
  493. report, err := models.GetEnglishReportById(vint)
  494. if err != nil {
  495. br.Msg = "获取报告信息失败"
  496. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  497. return
  498. }
  499. if report == nil {
  500. br.Msg = "报告不存在"
  501. return
  502. }
  503. var tmpErr error
  504. if report.Content == "" {
  505. br.Msg = "报告内容为空,不可发布"
  506. br.ErrMsg = "报告内容为空,不需要生成,report_id:" + strconv.Itoa(report.Id)
  507. return
  508. }
  509. if tmpErr = models.PublishEnglishReportById(report.Id); tmpErr != nil {
  510. br.Msg = "报告发布失败"
  511. br.ErrMsg = "报告发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
  512. return
  513. }
  514. go func() {
  515. _ = services.UpdateEnglishReportEs(report.Id, 2)
  516. }()
  517. }
  518. br.Ret = 200
  519. br.Success = true
  520. br.Msg = "发布成功"
  521. }
  522. // @Title 取消发布报告接口
  523. // @Description 取消发布报告
  524. // @Param request body models.PublishCancelReq true "type json string"
  525. // @Success 200 Ret=200 取消发布成功
  526. // @router /publish/cancel [post]
  527. func (this *EnglishReportController) PublishCancleReport() {
  528. br := new(models.BaseResponse).Init()
  529. defer func() {
  530. this.Data["json"] = br
  531. this.ServeJSON()
  532. }()
  533. var req models.PublishCancelReq
  534. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  535. if err != nil {
  536. br.Msg = "参数解析异常!"
  537. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  538. return
  539. }
  540. if req.ReportIds <= 0 {
  541. br.Msg = "参数错误"
  542. br.ErrMsg = "参数错误,报告id不可为空"
  543. return
  544. }
  545. err = models.PublishCancelEnglishReport(req.ReportIds)
  546. if err != nil {
  547. br.Msg = "取消发布失败"
  548. br.ErrMsg = "取消发布失败,Err:" + err.Error()
  549. return
  550. }
  551. // 更新es里的报告状态
  552. go func() {
  553. _ = services.UpdateEnglishReportEs(req.ReportIds, 1)
  554. }()
  555. br.Ret = 200
  556. br.Success = true
  557. br.Msg = "取消发布成功"
  558. }
  559. // @Title 删除报告接口
  560. // @Description 删除报告
  561. // @Param request body models.DeleteReq true "type json string"
  562. // @Success 200 Ret=200 删除成功
  563. // @router /delete [post]
  564. func (this *EnglishReportController) Delete() {
  565. br := new(models.BaseResponse).Init()
  566. defer func() {
  567. this.Data["json"] = br
  568. this.ServeJSON()
  569. }()
  570. var req models.DeleteReq
  571. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  572. if err != nil {
  573. br.Msg = "参数解析异常!"
  574. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  575. return
  576. }
  577. if req.ReportIds <= 0 {
  578. br.Msg = "参数错误"
  579. br.ErrMsg = "参数错误,报告id不可为空"
  580. return
  581. }
  582. reportInfo, err := models.GetEnglishReportById(req.ReportIds)
  583. if err != nil {
  584. if err.Error() == utils.ErrNoRow() {
  585. br.Msg = "报告不存在"
  586. return
  587. }
  588. br.Msg = "查询报告信息失败"
  589. br.ErrMsg = "查询报告信息失败, Err" + err.Error()
  590. return
  591. }
  592. // 更新es里的报告状态
  593. _ = services.UpdateEnglishReportEs(req.ReportIds, 1)
  594. if err = models.DeleteEnglishReportAndChapter(reportInfo); err != nil {
  595. br.Msg = "删除失败"
  596. br.ErrMsg = "删除报告失败, Err: " + err.Error()
  597. return
  598. }
  599. // 重置PPT关联报告
  600. go func() {
  601. _ = services.ResetPPTReport(req.ReportIds, true)
  602. }()
  603. go func() {
  604. _ = services.EnglishPolicyReportSyncCancel(reportInfo)
  605. }()
  606. br.Ret = 200
  607. br.Success = true
  608. br.Msg = "删除成功"
  609. }
  610. // @Title 保存草稿
  611. // @Description 保存草稿
  612. // @Param request body models.SaveReportContent true "type json string"
  613. // @Success 200 {object} models.ReportAuthorResp
  614. // @router /saveReportContent [post]
  615. func (this *EnglishReportController) SaveReportContent() {
  616. br := new(models.BaseResponse).Init()
  617. br.IsSendEmail = false
  618. defer func() {
  619. this.Data["json"] = br
  620. this.ServeJSON()
  621. }()
  622. var req models.SaveReportContent
  623. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  624. if err != nil {
  625. br.Msg = "参数解析异常!"
  626. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  627. return
  628. }
  629. sysUser := this.SysUser
  630. if sysUser == nil {
  631. br.Msg = "请登录"
  632. br.ErrMsg = "请登录,SysUser Is Empty"
  633. br.Ret = 408
  634. return
  635. }
  636. reportId := req.ReportId
  637. noChangeFlag := req.NoChange
  638. fmt.Println("reportId:", reportId)
  639. if reportId <= 0 {
  640. br.Msg = "请输入报告ID"
  641. return
  642. }
  643. markStatus, err := services.UpdateEnReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName)
  644. if err != nil {
  645. br.Msg = err.Error()
  646. return
  647. }
  648. if markStatus.Status == 1 {
  649. br.Msg = markStatus.Msg
  650. return
  651. }
  652. if noChangeFlag != 1 {
  653. content := req.Content
  654. if content == "" {
  655. content = this.GetString("Content")
  656. }
  657. if content != "" {
  658. contentClean, e := services.FilterReportContentBr(req.Content)
  659. if e != nil {
  660. br.Msg = "内容去除前后空格失败"
  661. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  662. return
  663. }
  664. content = contentClean
  665. contentSub, err := services.GetReportContentSub(content)
  666. if err != nil {
  667. go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
  668. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  669. }
  670. content = html.EscapeString(content)
  671. contentSub = html.EscapeString(contentSub)
  672. err = models.EditEnglishReportContent(reportId, content, contentSub)
  673. if err != nil {
  674. br.Msg = "保存失败"
  675. br.ErrMsg = "保存失败,Err:" + err.Error()
  676. return
  677. }
  678. go models.AddEnglishReportSaveLog(reportId, this.SysUser.AdminId, content, contentSub, this.SysUser.AdminName)
  679. }
  680. }
  681. resp := new(models.SaveReportContentResp)
  682. resp.ReportId = reportId
  683. br.Ret = 200
  684. br.Success = true
  685. br.Msg = "保存成功成功"
  686. br.Data = resp
  687. }
  688. // @Title 根据分类获取最近一次报告详情接口
  689. // @Description 根据分类获取最近一次报告详情
  690. // @Param request body models.ClassifyIdDetailReq true "type json string"
  691. // @Success 200 {object} models.Report
  692. // @router /classifyIdDetail [get]
  693. func (this *EnglishReportController) ClassifyIdDetail() {
  694. br := new(models.BaseResponse).Init()
  695. defer func() {
  696. this.Data["json"] = br
  697. this.ServeJSON()
  698. }()
  699. //classify_id_first=34&classify_id_second=36
  700. /*var req models.ClassifyIdDetailReq
  701. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  702. if err != nil {
  703. br.Msg = "参数解析异常!"
  704. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  705. return
  706. }*/
  707. classifyIdFirst, _ := this.GetInt("classify_id_first")
  708. if classifyIdFirst <= 0 {
  709. classifyIdFirst, _ = this.GetInt("ClassifyIdFirst")
  710. }
  711. classifyIdSecond, _ := this.GetInt("classify_id_second")
  712. if classifyIdSecond <= 0 {
  713. classifyIdSecond, _ = this.GetInt("ClassifyIdSecond")
  714. }
  715. item, err := models.GetEnglishReportDetailByClassifyId(classifyIdFirst, classifyIdSecond)
  716. if err != nil && err.Error() != utils.ErrNoRow() {
  717. br.Msg = "获取失败!"
  718. br.ErrMsg = "获取失败,Err:" + err.Error()
  719. return
  720. }
  721. if item != nil {
  722. item.Content = html.UnescapeString(item.Content)
  723. item.ContentSub = html.UnescapeString(item.ContentSub)
  724. }
  725. br.Ret = 200
  726. br.Success = true
  727. br.Msg = "获取成功"
  728. br.Data = item
  729. }
  730. // Author
  731. // @Title 获取报告作者接口
  732. // @Description 获取报告作者
  733. // @Param AuthorType query int true "来源类型,1:中文,2:英文"
  734. // @Param Keyword query string true "搜索关键词"
  735. // @Param CurrentIndex query int true "当前页页码,从1开始"
  736. // @Param StartDate query string true "开始时间"
  737. // @Success 200 {object} models.ReportAuthorResp
  738. // @router /author [get]
  739. func (this *EnglishReportController) Author() {
  740. br := new(models.BaseResponse).Init()
  741. defer func() {
  742. this.Data["json"] = br
  743. this.ServeJSON()
  744. }()
  745. keyword := this.GetString("Keyword")
  746. var condition string
  747. var pars []interface{}
  748. condition += ` AND author_type = 2 AND enable = 1`
  749. if keyword != `` {
  750. condition += ` AND report_author like ? `
  751. pars = append(pars, "%"+keyword+"%")
  752. }
  753. _, items, err := models.GetReportAuthorList(condition, pars, 0, 10000)
  754. if err != nil {
  755. br.Msg = "获取失败!"
  756. br.ErrMsg = "获取失败,Err:" + err.Error()
  757. return
  758. }
  759. resp := models.ReportAuthorResp{
  760. List: items,
  761. }
  762. br.Ret = 200
  763. br.Success = true
  764. br.Msg = "获取成功"
  765. br.Data = resp
  766. }
  767. // MarkEditStatus
  768. // @Title 标记报告编辑状态
  769. // @Description 标记报告编辑状态接口
  770. // @Param request body request.MarkEditEnReport true "type json string"
  771. // @Success 200 标记成功 ;202 标记成功
  772. // @router /mark [post]
  773. func (this *EnglishReportController) MarkEditStatus() {
  774. br := new(models.BaseResponse).Init()
  775. defer func() {
  776. this.Data["json"] = br
  777. this.ServeJSON()
  778. }()
  779. sysUser := this.SysUser
  780. if sysUser == nil {
  781. br.Msg = "请登录"
  782. br.ErrMsg = "请登录,SysUser Is Empty"
  783. br.Ret = 408
  784. return
  785. }
  786. var req models.MarkEditEnReport
  787. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  788. if err != nil {
  789. br.Msg = "参数解析异常!"
  790. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  791. return
  792. }
  793. if req.ReportId <= 0 {
  794. br.Msg = "缺少报告Id"
  795. return
  796. }
  797. if req.Status <= 0 {
  798. br.Msg = "标记状态异常"
  799. return
  800. }
  801. //更新标记key
  802. data, err := services.UpdateEnReportEditMark(req.ReportId, sysUser.AdminId, req.Status, sysUser.RealName)
  803. if err != nil {
  804. br.Msg = err.Error()
  805. return
  806. }
  807. msg := "标记成功"
  808. br.Ret = 200
  809. br.Success = true
  810. br.Msg = msg
  811. br.Data = data
  812. }
  813. // @Title 编辑来自策略报告的报告
  814. // @Description 编辑来自策略报告的报告
  815. // @Param request body models.EditEnglishReportFromPolicyReq true "type json string"
  816. // @Success 200 {object} models.EditEnglishReportResp
  817. // @router /edit_policy [post]
  818. func (this *EnglishReportController) EditPolicy() {
  819. br := new(models.BaseResponse).Init()
  820. defer func() {
  821. this.Data["json"] = br
  822. this.ServeJSON()
  823. }()
  824. sysUser := this.SysUser
  825. if sysUser == nil {
  826. br.Msg = "请登录"
  827. br.ErrMsg = "请登录,SysUser Is Empty"
  828. br.Ret = 408
  829. return
  830. }
  831. var req models.EditEnglishReportFromPolicyReq
  832. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  833. if err != nil {
  834. br.Msg = "参数解析异常!"
  835. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  836. return
  837. }
  838. if req.ReportId <= 0 {
  839. br.Msg = "请选择报告ID"
  840. return
  841. }
  842. if req.Title == "" {
  843. br.Msg = "请输入标题"
  844. return
  845. }
  846. if req.Abstract == "" {
  847. br.Msg = "请输入摘要"
  848. return
  849. }
  850. if req.Frequency == "" {
  851. br.Msg = "请输入频度"
  852. return
  853. }
  854. if req.Author == "" {
  855. br.Msg = "请输入作者"
  856. return
  857. }
  858. if req.CreateTime == "" {
  859. br.Msg = "请输入创建时间"
  860. return
  861. }
  862. //查询报告是否存在
  863. reportInfo, err := models.GetEnglishReportItemById(int(req.ReportId))
  864. if err != nil {
  865. if err.Error() == utils.ErrNoRow() {
  866. br.Msg = "报告不存在"
  867. return
  868. }
  869. br.Msg = "查询报告信息失败"
  870. br.ErrMsg = "查询报告信息失败, Err" + err.Error()
  871. return
  872. }
  873. if reportInfo.State == 2 {
  874. br.Msg = "报告已发布不允许编辑"
  875. return
  876. }
  877. markStatus, err := services.UpdateEnReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName)
  878. if err != nil {
  879. br.Msg = err.Error()
  880. return
  881. }
  882. if markStatus.Status == 1 {
  883. br.Msg = markStatus.Msg
  884. return
  885. }
  886. item := reportInfo
  887. item.Title = req.Title
  888. item.Abstract = req.Abstract
  889. item.Author = req.Author
  890. item.Frequency = req.Frequency
  891. item.CreateTime = req.CreateTime
  892. item.ModifyTime = time.Now()
  893. err = item.Update([]string{"Title", "Abstract", "Author", "Frequency", "CreateTime", "ModifyTime"})
  894. if err != nil {
  895. br.Msg = "保存失败"
  896. br.ErrMsg = "保存失败,Err:" + err.Error()
  897. return
  898. }
  899. reportCode := reportInfo.ReportCode
  900. resp := new(models.EditEnglishReportResp)
  901. resp.ReportId = req.ReportId
  902. resp.ReportCode = reportCode
  903. br.Ret = 200
  904. br.Success = true
  905. br.Msg = "保存成功"
  906. br.Data = resp
  907. }