report.go 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438
  1. package english_report
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/controllers"
  5. "eta/eta_mobile/models"
  6. "eta/eta_mobile/models/company"
  7. "eta/eta_mobile/services"
  8. "eta/eta_mobile/services/alarm_msg"
  9. "eta/eta_mobile/services/data"
  10. "eta/eta_mobile/utils"
  11. "fmt"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. "html"
  14. "sort"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. // EnglishReportController 研报活动模块
  20. type EnglishReportController struct {
  21. controllers.BaseAuthController
  22. }
  23. // @Title 新增报告接口
  24. // @Description 新增报告
  25. // @Param request body models.AddEnglishReportReq true "type json string"
  26. // @Success 200 {object} models.AddEnglishReportResp
  27. // @router /add [post]
  28. func (this *EnglishReportController) Add() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. sysUser := this.SysUser
  35. if sysUser == nil {
  36. br.Msg = "请登录"
  37. br.ErrMsg = "请登录,SysUser Is Empty"
  38. br.Ret = 408
  39. return
  40. }
  41. var req models.AddEnglishReportReq
  42. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  43. if err != nil {
  44. br.Msg = "参数解析异常!"
  45. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  46. return
  47. }
  48. if req.Content == "" {
  49. br.Msg = "请输入内容"
  50. return
  51. }
  52. if req.Overview == "" {
  53. br.Msg = "请输入overview"
  54. return
  55. }
  56. if req.Abstract == "" {
  57. br.Msg = "请输入摘要"
  58. return
  59. }
  60. var contentSub string
  61. if req.Content != "" {
  62. content, e := services.FilterReportContentBr(req.Content)
  63. if e != nil {
  64. br.Msg = "内容去除前后空格失败"
  65. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  66. return
  67. }
  68. req.Content = content
  69. contentSub, err = services.GetReportContentSub(req.Content)
  70. if err != nil {
  71. go alarm_msg.SendAlarmMsg("ContentSub 失败,Err:"+err.Error(), 3)
  72. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  73. }
  74. }
  75. maxStage, err := models.GetEnglishReportStage(req.ClassifyIdFirst, req.ClassifyIdSecond)
  76. if err != nil {
  77. br.Msg = "期数获取失败!"
  78. br.ErrMsg = "期数获取失败,Err:" + err.Error()
  79. return
  80. }
  81. item := new(models.EnglishReport)
  82. item.AddType = req.AddType
  83. item.ClassifyIdFirst = req.ClassifyIdFirst
  84. item.ClassifyNameFirst = req.ClassifyNameFirst
  85. item.ClassifyIdSecond = req.ClassifyIdSecond
  86. item.ClassifyNameSecond = req.ClassifyNameSecond
  87. item.Title = req.Title
  88. item.Abstract = req.Abstract
  89. item.Author = req.Author
  90. item.Frequency = req.Frequency
  91. item.State = req.State
  92. item.Content = html.EscapeString(req.Content)
  93. item.Stage = maxStage + 1
  94. item.ContentSub = html.EscapeString(contentSub)
  95. item.CreateTime = req.CreateTime
  96. item.ModifyTime = time.Now()
  97. item.Overview = req.Overview
  98. item.AdminId = sysUser.AdminId
  99. item.AdminRealName = sysUser.RealName
  100. newReportId, err := models.AddEnglishReport(item)
  101. if err != nil {
  102. br.Msg = "保存失败"
  103. br.ErrMsg = "保存失败,Err:" + err.Error()
  104. return
  105. }
  106. reportCode := utils.MD5(strconv.Itoa(int(newReportId)))
  107. //修改唯一编码
  108. {
  109. go models.ModifyEnglishReportCode(newReportId, reportCode)
  110. }
  111. resp := new(models.AddEnglishReportResp)
  112. resp.ReportId = newReportId
  113. resp.ReportCode = reportCode
  114. br.Ret = 200
  115. br.Success = true
  116. br.Msg = "保存成功"
  117. br.Data = resp
  118. }
  119. // @Title 编辑报告接口
  120. // @Description 编辑报告
  121. // @Param request body models.EditEnglishReportReq true "type json string"
  122. // @Success 200 {object} models.EditEnglishReportResp
  123. // @router /edit [post]
  124. func (this *EnglishReportController) Edit() {
  125. br := new(models.BaseResponse).Init()
  126. defer func() {
  127. this.Data["json"] = br
  128. this.ServeJSON()
  129. }()
  130. sysUser := this.SysUser
  131. if sysUser == nil {
  132. br.Msg = "请登录"
  133. br.ErrMsg = "请登录,SysUser Is Empty"
  134. br.Ret = 408
  135. return
  136. }
  137. var req models.EditEnglishReportReq
  138. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  139. if err != nil {
  140. br.Msg = "参数解析异常!"
  141. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  142. return
  143. }
  144. if req.Content == "" {
  145. br.Msg = "请输入内容"
  146. return
  147. }
  148. if req.Overview == "" {
  149. br.Msg = "请输入overview"
  150. return
  151. }
  152. if req.Abstract == "" {
  153. br.Msg = "请输入摘要"
  154. return
  155. }
  156. markStatus, err := services.UpdateEnReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName)
  157. if err != nil {
  158. br.Msg = err.Error()
  159. return
  160. }
  161. if markStatus.Status == 1 {
  162. br.Msg = markStatus.Msg
  163. return
  164. }
  165. var contentSub string
  166. if req.Content != "" {
  167. content, e := services.FilterReportContentBr(req.Content)
  168. if e != nil {
  169. br.Msg = "内容去除前后空格失败"
  170. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  171. return
  172. }
  173. req.Content = content
  174. contentSub, err = services.GetReportContentSub(req.Content)
  175. if err != nil {
  176. go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
  177. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  178. }
  179. }
  180. var stage int
  181. report, _ := models.GetEnglishReportById(int(req.ReportId))
  182. if report != nil {
  183. if report.ClassifyNameFirst != req.ClassifyNameFirst || report.ClassifyNameSecond != req.ClassifyNameSecond {
  184. maxStage, _ := models.GetEnglishReportStageEdit(req.ClassifyIdFirst, req.ClassifyIdSecond, int(req.ReportId))
  185. maxStage = maxStage + 1
  186. stage = maxStage
  187. } else {
  188. stage = report.Stage
  189. }
  190. }
  191. item := new(models.EnglishReport)
  192. item.ClassifyIdFirst = req.ClassifyIdFirst
  193. item.ClassifyNameFirst = req.ClassifyNameFirst
  194. item.ClassifyIdSecond = req.ClassifyIdSecond
  195. item.ClassifyNameSecond = req.ClassifyNameSecond
  196. item.Title = req.Title
  197. item.Abstract = req.Abstract
  198. item.Author = req.Author
  199. item.Frequency = req.Frequency
  200. item.State = req.State
  201. item.Stage = stage
  202. item.Content = html.EscapeString(req.Content)
  203. item.ContentSub = html.EscapeString(contentSub)
  204. item.CreateTime = req.CreateTime
  205. item.Overview = req.Overview
  206. err = models.EditEnglishReport(item, req.ReportId)
  207. if err != nil {
  208. br.Msg = "保存失败"
  209. br.ErrMsg = "保存失败,Err:" + err.Error()
  210. return
  211. }
  212. reportCode := utils.MD5(strconv.Itoa(int(req.ReportId)))
  213. resp := new(models.EditEnglishReportResp)
  214. resp.ReportId = req.ReportId
  215. resp.ReportCode = reportCode
  216. br.Ret = 200
  217. br.Success = true
  218. br.Msg = "保存成功"
  219. br.Data = resp
  220. }
  221. // @Title 获取报告详情接口
  222. // @Description 获取报告详情
  223. // @Param request body models.ReportDetailReq true "type json string"
  224. // @Success 200 {object} models.EnglishReportDetailView
  225. // @router /detail [get]
  226. func (this *EnglishReportController) Detail() {
  227. br := new(models.BaseResponse).Init()
  228. defer func() {
  229. this.Data["json"] = br
  230. this.ServeJSON()
  231. }()
  232. sysUser := this.SysUser
  233. if sysUser == nil {
  234. br.Msg = "请登录"
  235. br.ErrMsg = "请登录,SysUser Is Empty"
  236. br.Ret = 408
  237. return
  238. }
  239. reportId, err := this.GetInt("ReportId")
  240. if err != nil {
  241. br.Msg = "获取参数失败!"
  242. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  243. return
  244. }
  245. if reportId <= 0 {
  246. br.Msg = "参数错误"
  247. return
  248. }
  249. item, err := models.GetEnglishReportById(reportId)
  250. if err != nil {
  251. br.Msg = "获取失败"
  252. br.ErrMsg = "获取失败,Err:" + err.Error()
  253. return
  254. }
  255. item.Content = html.UnescapeString(item.Content)
  256. item.ContentSub = html.UnescapeString(item.ContentSub)
  257. classifyNameMap := make(map[int]*models.EnglishClassifyFullName)
  258. if item.ClassifyIdSecond > 0 {
  259. nameList, tErr := models.GetEnglishClassifyFullNameByIds([]int{item.ClassifyIdSecond})
  260. if tErr != nil {
  261. br.Msg = "获取分类名称失败"
  262. br.ErrMsg = "获取分类名称失败, ERR:" + tErr.Error()
  263. return
  264. }
  265. for _, v := range nameList {
  266. classifyNameMap[v.Id] = v
  267. }
  268. //处理分类名
  269. if n, ok := classifyNameMap[item.ClassifyIdSecond]; ok {
  270. item.ClassifyNameRoot = n.RootName
  271. item.ClassifyIdRoot = n.RootId
  272. }
  273. }
  274. // 获取邮件配置-是否有权限群发
  275. conf := new(models.EnglishReportEmailConf)
  276. authKey := "english_report_email_conf"
  277. confAuth, e := company.GetConfigDetailByCode(authKey)
  278. if e != nil {
  279. br.Msg = "获取失败"
  280. br.ErrMsg = "获取群发邮件权限失败, Err: " + e.Error()
  281. return
  282. }
  283. if confAuth.ConfigValue == "" {
  284. br.Msg = "获取失败"
  285. br.ErrMsg = "群发邮件配置为空"
  286. return
  287. }
  288. if e := json.Unmarshal([]byte(confAuth.ConfigValue), &conf); e != nil {
  289. br.Msg = "获取失败"
  290. br.ErrMsg = "群发邮件配置有误"
  291. return
  292. }
  293. authOk := false
  294. authArr := strings.Split(conf.SendAuthGroup, ",")
  295. if utils.InArrayByStr(authArr, sysUser.RoleTypeCode) {
  296. authOk = true
  297. }
  298. item.EmailAuth = authOk
  299. // 是否有群发邮件失败的记录,标记红点
  300. failList, e := models.GetEnglishReportEmailLogFailList(0)
  301. if e != nil {
  302. br.Msg = "获取失败"
  303. br.ErrMsg = "获取群发邮件记录失败, Err: " + e.Error()
  304. return
  305. }
  306. failMap := make(map[int]bool, 0)
  307. for i := range failList {
  308. failMap[failList[i].ReportId] = true
  309. }
  310. item.EmailHasFail = failMap[item.Id]
  311. br.Ret = 200
  312. br.Success = true
  313. br.Msg = "获取成功"
  314. br.Data = item
  315. }
  316. // ListReport
  317. // @Title 获取报告列表接口
  318. // @Description 获取报告列表
  319. // @Param PageSize query int true "每页数据条数"
  320. // @Param CurrentIndex query int true "当前页页码,从1开始"
  321. // @Param TimeType query string true "筛选的时间类别:publish_time(发布时间),modify_time(更新时间)"
  322. // @Param StartDate query string true "开始时间"
  323. // @Param EndDate query string true "结束时间"
  324. // @Param Frequency query string true "频度"
  325. // @Param ClassifyNameFirst query string true "一级分类名称"
  326. // @Param ClassifyNameSecond query string true "二级分类名称"
  327. // @Param State query int true "状态"
  328. // @Param KeyWord query string true "搜索关键词"
  329. // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
  330. // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
  331. // @Success 200 {object} models.ReportListResp
  332. // @router /list [get]
  333. func (this *EnglishReportController) ListReport() {
  334. br := new(models.BaseResponse).Init()
  335. defer func() {
  336. this.Data["json"] = br
  337. this.ServeJSON()
  338. }()
  339. sysUser := this.SysUser
  340. if sysUser == nil {
  341. br.Msg = "请登录"
  342. br.ErrMsg = "请登录,SysUser Is Empty"
  343. br.Ret = 408
  344. return
  345. }
  346. pageSize, _ := this.GetInt("PageSize")
  347. currentIndex, _ := this.GetInt("CurrentIndex")
  348. timeType := this.GetString("TimeType")
  349. startDate := this.GetString("StartDate")
  350. endDate := this.GetString("EndDate")
  351. frequency := this.GetString("Frequency")
  352. classifyIdFirst, _ := this.GetInt("ClassifyIdFirst")
  353. classifyIdSecond, _ := this.GetInt("ClassifyIdSecond")
  354. classifyIdRoot, _ := this.GetInt("ClassifyIdRoot")
  355. state, _ := this.GetInt("State")
  356. keyWord := this.GetString("KeyWord")
  357. companyType := this.GetString("CompanyType")
  358. // 群发邮件状态筛选
  359. emailState, _ := this.GetInt("EmailState")
  360. var startSize int
  361. if pageSize <= 0 {
  362. pageSize = utils.PageSize20
  363. }
  364. if currentIndex <= 0 {
  365. currentIndex = 1
  366. }
  367. startSize = utils.StartIndex(currentIndex, pageSize)
  368. var condition string
  369. var pars []interface{}
  370. if keyWord != "" {
  371. condition += ` AND (title LIKE '%` + keyWord + `%' OR admin_real_name LIKE '%` + keyWord + `%' ) `
  372. }
  373. if timeType == "" {
  374. timeType = "publish_time"
  375. }
  376. if timeType != "publish_time" && timeType != "modify_time" {
  377. br.Msg = "请选择正确的时间"
  378. br.ErrMsg = "请选择正确的时间"
  379. return
  380. }
  381. if startDate != "" {
  382. condition += ` AND ` + timeType + ` >= ? `
  383. pars = append(pars, startDate)
  384. }
  385. if endDate != "" {
  386. condition += ` AND ` + timeType + ` <= ? `
  387. pars = append(pars, endDate)
  388. }
  389. if frequency != "" {
  390. condition += ` AND frequency = ? `
  391. pars = append(pars, frequency)
  392. }
  393. if classifyIdFirst != 0 {
  394. condition += ` AND classify_id_first = ? `
  395. pars = append(pars, classifyIdFirst)
  396. }
  397. if classifyIdSecond != 0 {
  398. condition += ` AND classify_id_second = ? `
  399. pars = append(pars, classifyIdSecond)
  400. }
  401. if state > 0 {
  402. condition += ` AND state = ? `
  403. pars = append(pars, state)
  404. }
  405. if classifyIdRoot > 0 && classifyIdFirst == 0 && classifyIdSecond == 0 {
  406. //查询顶级分类下的所有二级分类ID
  407. childClassify, err := models.GetEnglishSecondClassifyList([]int{classifyIdRoot})
  408. if err != nil {
  409. br.Msg = "查询子分类出错"
  410. br.ErrMsg = "查询子分类出错, Err:" + err.Error()
  411. return
  412. }
  413. var childClassifyIds []int
  414. if len(childClassify) > 0 {
  415. for _, v := range childClassify {
  416. childClassifyIds = append(childClassifyIds, v.Id)
  417. }
  418. condition += ` AND classify_id_first IN (` + utils.GetOrmInReplace(len(childClassifyIds)) + `)`
  419. pars = append(pars, childClassifyIds)
  420. } else {
  421. //一级分类下没有子分类,直接返回空列表
  422. page := paging.GetPaging(currentIndex, pageSize, 0)
  423. resp := new(models.EnglishReportListResp)
  424. resp.Paging = page
  425. resp.List = make([]*models.EnglishReportList, 0)
  426. br.Ret = 200
  427. br.Success = true
  428. br.Msg = "获取成功"
  429. br.Data = resp
  430. return
  431. }
  432. }
  433. // 未群发邮件(包含推送邮件失败的)
  434. if emailState == 1 {
  435. failIds, e := models.GetHasFailEmailLogReportIds()
  436. if e != nil {
  437. br.Msg = "获取失败"
  438. br.ErrMsg = "获取存在邮件推送失败记录的英文报告IDs失败, Err:" + e.Error()
  439. return
  440. }
  441. condition += ` AND email_state = 0`
  442. if len(failIds) > 0 {
  443. condition += ` OR id IN (` + utils.GetOrmInReplace(len(failIds)) + `)`
  444. pars = append(pars, failIds)
  445. }
  446. }
  447. // 已群发邮件
  448. if emailState == 2 {
  449. successIds, e := models.GetSuccessEmailLogReportIds()
  450. if e != nil {
  451. br.Msg = "获取失败"
  452. br.ErrMsg = "获取邮件推送记录均为成功的英文报告IDs失败, Err:" + e.Error()
  453. return
  454. }
  455. condition += ` AND email_state = 1`
  456. if len(successIds) > 0 {
  457. condition += ` AND id IN (` + utils.GetOrmInReplace(len(successIds)) + `)`
  458. pars = append(pars, successIds)
  459. }
  460. }
  461. total, err := models.GetEnglishReportListCount(condition, pars, companyType)
  462. if err != nil {
  463. br.Msg = "获取失败"
  464. br.ErrMsg = "获取失败,Err:" + err.Error()
  465. return
  466. }
  467. list, err := models.GetEnglishReportList(condition, pars, companyType, startSize, pageSize)
  468. if err != nil {
  469. br.Msg = "获取失败"
  470. br.ErrMsg = "获取失败,Err:" + err.Error()
  471. return
  472. }
  473. // 获取邮件配置-是否有权限群发
  474. conf := new(models.EnglishReportEmailConf)
  475. authKey := "english_report_email_conf"
  476. confAuth, e := company.GetConfigDetailByCode(authKey)
  477. if e != nil {
  478. br.Msg = "获取失败"
  479. br.ErrMsg = "获取群发邮件权限失败, Err: " + e.Error()
  480. return
  481. }
  482. if confAuth.ConfigValue == "" {
  483. br.Msg = "获取失败"
  484. br.ErrMsg = "群发邮件配置为空"
  485. return
  486. }
  487. if e := json.Unmarshal([]byte(confAuth.ConfigValue), &conf); e != nil {
  488. br.Msg = "获取失败"
  489. br.ErrMsg = "群发邮件配置有误"
  490. return
  491. }
  492. authOk := false
  493. authArr := strings.Split(conf.SendAuthGroup, ",")
  494. if utils.InArrayByStr(authArr, sysUser.RoleTypeCode) {
  495. authOk = true
  496. }
  497. // 是否有群发邮件失败的记录,标记红点
  498. failList, e := models.GetEnglishReportEmailLogFailList(0)
  499. if e != nil {
  500. br.Msg = "获取失败"
  501. br.ErrMsg = "获取群发邮件记录失败, Err: " + e.Error()
  502. return
  503. }
  504. failMap := make(map[int]bool, 0)
  505. for i := range failList {
  506. failMap[failList[i].ReportId] = true
  507. }
  508. // 查询分类信息
  509. var classifyIdSecondSlice []int
  510. for _, item := range list {
  511. classifyIdSecondSlice = append(classifyIdSecondSlice, item.ClassifyIdSecond)
  512. }
  513. classifyNameMap := make(map[int]*models.EnglishClassifyFullName)
  514. if len(classifyIdSecondSlice) > 0 {
  515. nameList, err := models.GetEnglishClassifyFullNameByIds(classifyIdSecondSlice)
  516. if err != nil {
  517. br.Msg = "获取分类名称失败"
  518. br.ErrMsg = "获取分类名称失败, ERR:" + err.Error()
  519. return
  520. }
  521. for _, v := range nameList {
  522. classifyNameMap[v.Id] = v
  523. }
  524. }
  525. for _, item := range list {
  526. if item.State == 2 {
  527. item.ShareUrl = "https://share.hzinsights.com/reportEn?code=" + item.ReportCode
  528. }
  529. item.EmailAuth = authOk
  530. item.EmailHasFail = failMap[item.Id]
  531. // 邮箱PV大于0的时候, 不展示最初版本的PV
  532. if item.PvEmail > 0 {
  533. item.Pv = 0
  534. }
  535. /*key := fmt.Sprint(`crm:enReport:edit:`, item.Id)
  536. opUserId, _ := utils.Rc.RedisInt(key)
  537. //如果当前没有人操作,获取当前操作人是本人,那么编辑按钮可用
  538. if opUserId <= 0 || (opUserId == this.SysUser.AdminId) {
  539. item.CanEdit = true
  540. } else {
  541. adminInfo, errAdmin := system.GetSysUserById(opUserId)
  542. if errAdmin != nil {
  543. br.Msg = "获取失败"
  544. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  545. return
  546. }
  547. item.Editor = adminInfo.RealName
  548. }*/
  549. markStatus, err := services.UpdateEnReportEditMark(item.Id, this.SysUser.AdminId, 2, this.SysUser.RealName)
  550. if err != nil {
  551. br.Msg = "查询标记状态失败"
  552. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  553. return
  554. }
  555. if markStatus.Status == 0 {
  556. item.CanEdit = true
  557. } else {
  558. item.Editor = markStatus.Editor
  559. }
  560. //处理分类名
  561. if n, ok := classifyNameMap[item.ClassifyIdSecond]; ok {
  562. if n.RootId == 0 {
  563. item.FullClassifyName = strings.Join([]string{n.ParentName, n.ClassifyName}, "/")
  564. } else {
  565. item.FullClassifyName = strings.Join([]string{n.RootName, n.ParentName, n.ClassifyName}, "/")
  566. }
  567. item.ClassifyIdRoot = n.RootId
  568. item.ClassifyNameRoot = n.RootName
  569. }
  570. }
  571. page := paging.GetPaging(currentIndex, pageSize, total)
  572. resp := new(models.EnglishReportListResp)
  573. resp.Paging = page
  574. resp.List = list
  575. br.Ret = 200
  576. br.Success = true
  577. br.Msg = "获取成功"
  578. br.Data = resp
  579. }
  580. // ListClassify
  581. // @Title 获取分类列表
  582. // @Description 获取分类列表
  583. // @Param PageSize query int true "每页数据条数"
  584. // @Param CurrentIndex query int true "当前页页码,从1开始"
  585. // @Param KeyWord query string true "检索关键词"
  586. // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
  587. // @Success 200 {object} models.EnglishClassifyListResp
  588. // @router /classify/list [get]
  589. func (this *EnglishReportController) ListClassify() {
  590. br := new(models.BaseResponse).Init()
  591. defer func() {
  592. this.Data["json"] = br
  593. this.ServeJSON()
  594. }()
  595. pageSize, _ := this.GetInt("PageSize")
  596. currentIndex, _ := this.GetInt("CurrentIndex")
  597. keyWord := this.GetString("KeyWord")
  598. var startSize int
  599. if pageSize <= 0 {
  600. pageSize = utils.PageSize20
  601. }
  602. if currentIndex <= 0 {
  603. currentIndex = 1
  604. }
  605. startSize = utils.StartIndex(currentIndex, pageSize)
  606. page := paging.GetPaging(currentIndex, pageSize, 0)
  607. resp := new(models.EnglishClassifyListResp)
  608. // 处理一级分类分页的情况
  609. rootList, err := models.GetEnglishClassifyRootId(startSize, pageSize, keyWord)
  610. if err != nil {
  611. br.Msg = "获取失败"
  612. br.ErrMsg = "获取失败,Err:" + err.Error()
  613. return
  614. }
  615. var ids []int
  616. var rootIds []int
  617. rootMap := make(map[int]struct{}, 0)
  618. for _, v := range rootList {
  619. rootIds = append(rootIds, v.Id)
  620. rootMap[v.Id] = struct{}{}
  621. }
  622. total, err := models.GetEnglishClassifyListCount(keyWord)
  623. if err != nil {
  624. br.Msg = "获取失败"
  625. br.ErrMsg = "获取失败,Err:" + err.Error()
  626. return
  627. }
  628. if total == 0 {
  629. resp.List = make([]*models.EnglishClassifyList, 0)
  630. resp.Paging = page
  631. br.Data = resp
  632. br.Ret = 200
  633. br.Success = true
  634. br.Msg = "获取成功"
  635. return
  636. }
  637. page = paging.GetPaging(currentIndex, pageSize, total)
  638. //获取相关的分类ID
  639. idList, err := models.GetEnglishClassifyListByRootId(rootIds, keyWord)
  640. if err != nil {
  641. br.Msg = "获取失败"
  642. br.ErrMsg = "获取失败,Err:" + err.Error()
  643. return
  644. }
  645. secondListMap := make(map[int][]*models.EnglishClassifyList)
  646. thirdListMap := make(map[int][]*models.EnglishClassifyList)
  647. var thirdIds []int
  648. var sortChildList models.RSChildClassifyList
  649. // 三级分类-品种权限
  650. permissionMap := make(map[int][]int)
  651. if len(idList) > 0 {
  652. childIdMap := make(map[int]struct{}, 0)
  653. for _, v := range idList {
  654. if _, ok := childIdMap[v.ParentId]; !ok {
  655. ids = append(ids, v.ParentId)
  656. }
  657. if _, ok := childIdMap[v.Id]; !ok {
  658. ids = append(ids, v.Id)
  659. }
  660. }
  661. tmpList, err := models.GetEnglishClassifyChildByIds(ids)
  662. if err != nil {
  663. br.Msg = "获取二级分类失败"
  664. br.ErrMsg = "获取二级分类失败,Err:" + err.Error()
  665. return
  666. }
  667. for _, v := range tmpList {
  668. if _, ok := rootMap[v.ParentId]; !ok {
  669. thirdIds = append(thirdIds, v.Id)
  670. }
  671. }
  672. {
  673. classifyIds := thirdIds
  674. if len(classifyIds) > 0 {
  675. cond := fmt.Sprintf(` AND %s IN (%s)`, models.EnClassifyPermissionColumns.EnClassifyId, utils.GetOrmInReplace(len(classifyIds)))
  676. pars := make([]interface{}, 0)
  677. pars = append(pars, classifyIds)
  678. ob := new(models.EnClassifyPermission)
  679. items, e := ob.GetItemsByCondition(cond, pars, []string{}, "")
  680. if e != nil {
  681. br.Msg = "获取失败"
  682. br.ErrMsg = "获取客户权限列表失败, Err: " + e.Error()
  683. return
  684. }
  685. for _, v := range items {
  686. if permissionMap[v.EnClassifyId] == nil {
  687. permissionMap[v.EnClassifyId] = make([]int, 0)
  688. }
  689. permissionMap[v.EnClassifyId] = append(permissionMap[v.EnClassifyId], v.EnPermissionId)
  690. }
  691. }
  692. }
  693. // 处理三级分类
  694. for _, v := range tmpList {
  695. if _, ok := rootMap[v.ParentId]; !ok {
  696. if p, ok1 := permissionMap[v.Id]; ok1 {
  697. v.EnPermissions = p
  698. }
  699. thirdListMap[v.ParentId] = append(thirdListMap[v.ParentId], v)
  700. }
  701. }
  702. //处理二级分类
  703. for _, v := range tmpList {
  704. if _, ok := rootMap[v.ParentId]; ok {
  705. if child, ok1 := thirdListMap[v.Id]; ok1 {
  706. sortChildList = child
  707. sort.Sort(sortChildList)
  708. v.Child = sortChildList
  709. }
  710. secondListMap[v.ParentId] = append(secondListMap[v.ParentId], v)
  711. }
  712. }
  713. }
  714. //处理一级分类
  715. var sortList models.RSClassifyList
  716. for _, v := range rootList {
  717. if child, ok := secondListMap[v.Id]; ok {
  718. sortChildList = child
  719. sort.Sort(sortChildList)
  720. v.Child = sortChildList
  721. }
  722. sortList = append(sortList, v)
  723. }
  724. sort.Sort(sortList)
  725. resp.List = sortList
  726. resp.Paging = page
  727. br.Data = resp
  728. br.Ret = 200
  729. br.Success = true
  730. br.Msg = "获取成功"
  731. }
  732. // @Title 删除分类列表
  733. // @Description 删除分类列表
  734. // @Param ClassifyId int true "分类名称"
  735. // @Param ParentId query int true "父级Id"
  736. // @Success 200 保存成功
  737. // @router /classify/delete [get]
  738. func (this *EnglishReportController) DelClassify() {
  739. br := new(models.BaseResponse).Init()
  740. defer func() {
  741. this.Data["json"] = br
  742. this.ServeJSON()
  743. }()
  744. classifyId, _ := this.GetInt("ClassifyId")
  745. //parentId, _ := this.GetInt("ParentId")
  746. classifyInfo, err := models.GetEnglishReportClassifyById(classifyId)
  747. if err != nil {
  748. if err.Error() == utils.ErrNoRow() {
  749. br.Msg = "当前分类不存在"
  750. br.ErrMsg = "当前分类不存在"
  751. return
  752. }
  753. br.Msg = "获取分类信息失败"
  754. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  755. return
  756. }
  757. count, err := models.GetEnglishClassifyChildCounts(classifyId)
  758. if err != nil && err.Error() != utils.ErrNoRow() {
  759. br.Msg = "获取信息失败"
  760. br.ErrMsg = "获取失败,Err:" + err.Error()
  761. return
  762. }
  763. if count > 0 {
  764. br.Msg = "请先删除该分类下关联分类"
  765. br.Ret = 403
  766. return
  767. }
  768. reportCount, e := models.GetEnglishReportCounts(classifyId, classifyInfo.ParentId)
  769. if e != nil && e.Error() != utils.ErrNoRow() {
  770. br.Msg = "获取信息失败"
  771. br.ErrMsg = "获取失败,Err:" + e.Error()
  772. return
  773. }
  774. if reportCount > 0 {
  775. br.Msg = "该分类有关联报告,不允许删除"
  776. br.Ret = 403
  777. return
  778. }
  779. videoCount, e := models.GetEnglishVideoCounts(classifyId, classifyInfo.ParentId)
  780. if e != nil && e.Error() != utils.ErrNoRow() {
  781. br.Msg = "获取信息失败"
  782. br.ErrMsg = "获取失败,Err:" + e.Error()
  783. return
  784. }
  785. if videoCount > 0 {
  786. br.Msg = "该分类有关联的路演视频,不允许删除"
  787. br.Ret = 403
  788. return
  789. }
  790. if err = models.DeleteEnglishClassify(classifyId); err != nil {
  791. br.Msg = "删除失败"
  792. br.ErrMsg = "删除报告失败, Err: " + err.Error()
  793. return
  794. }
  795. br.Ret = 200
  796. br.Success = true
  797. br.Msg = "删除成功"
  798. }
  799. // @Title 发布报告接口
  800. // @Description 发布报告
  801. // @Param request body models.PublishReq true "type json string"
  802. // @Success 200 Ret=200 发布成功
  803. // @router /publish [post]
  804. func (this *EnglishReportController) PublishReport() {
  805. br := new(models.BaseResponse).Init()
  806. defer func() {
  807. this.Data["json"] = br
  808. this.ServeJSON()
  809. }()
  810. var req models.PublishReq
  811. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  812. if err != nil {
  813. br.Msg = "参数解析异常!"
  814. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  815. return
  816. }
  817. reportIds := req.ReportIds
  818. if reportIds == "" {
  819. br.Msg = "参数错误"
  820. br.ErrMsg = "参数错误,报告id不可为空"
  821. return
  822. }
  823. reportArr := strings.Split(reportIds, ",")
  824. for _, v := range reportArr {
  825. vint, err := strconv.Atoi(v)
  826. if err != nil {
  827. br.Msg = "参数错误"
  828. br.ErrMsg = "参数错误,Err:" + err.Error()
  829. return
  830. }
  831. report, err := models.GetEnglishReportById(vint)
  832. if err != nil {
  833. br.Msg = "获取报告信息失败"
  834. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  835. return
  836. }
  837. if report == nil {
  838. br.Msg = "报告不存在"
  839. return
  840. }
  841. // 图表刷新状态
  842. refreshResult := data.CheckBatchChartRefreshResult("report", vint, 0)
  843. if !refreshResult {
  844. br.Msg = "图表刷新未完成,请稍后操作"
  845. br.ErrMsg = "图表刷新未完成,请稍后操作"
  846. br.IsSendEmail = false
  847. return
  848. }
  849. var tmpErr error
  850. if report.Content == "" {
  851. br.Msg = "报告内容为空,不可发布"
  852. br.ErrMsg = "报告内容为空,不需要生成,report_id:" + strconv.Itoa(report.Id)
  853. return
  854. }
  855. var publishTime string
  856. if report.PublishTime != "" {
  857. // 发布时间固定为首次发布时间
  858. publishTime = report.PublishTime
  859. } else {
  860. publishTime = time.Now().Format(utils.FormatDateTime)
  861. }
  862. if tmpErr = models.PublishEnglishReportById(report.Id, publishTime); tmpErr != nil {
  863. br.Msg = "报告发布失败"
  864. br.ErrMsg = "报告发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
  865. return
  866. }
  867. go func() {
  868. _ = services.UpdateEnglishReportEs(report.Id, 2)
  869. }()
  870. }
  871. br.Ret = 200
  872. br.Success = true
  873. br.Msg = "发布成功"
  874. }
  875. // PrePublishReport
  876. // @Title 设置定时发布接口
  877. // @Description 设置定时发布接口
  878. // @Param request body models.PrePublishReq true "type json string"
  879. // @Success 200 Ret=200 发布成功
  880. // @router /pre_publish [post]
  881. func (this *EnglishReportController) PrePublishReport() {
  882. br := new(models.BaseResponse).Init()
  883. defer func() {
  884. this.Data["json"] = br
  885. this.ServeJSON()
  886. }()
  887. var req models.PrePublishReq
  888. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  889. if err != nil {
  890. br.Msg = "参数解析异常!"
  891. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  892. return
  893. }
  894. reportId := req.ReportId
  895. if reportId == 0 {
  896. br.Msg = "参数错误"
  897. br.ErrMsg = "参数错误,报告id不可为空"
  898. return
  899. }
  900. if req.PrePublishTime == "" {
  901. br.Msg = "发布时间不能为空"
  902. return
  903. }
  904. prePublishTime, err := time.ParseInLocation(utils.FormatDateTime, req.PrePublishTime, time.Local)
  905. if err != nil {
  906. br.Msg = "发布时间格式错误"
  907. br.ErrMsg = "发布时间格式错误,Err:" + err.Error()
  908. return
  909. }
  910. if prePublishTime.Before(time.Now()) {
  911. br.Msg = "发布时间不允许选择过去时间"
  912. return
  913. }
  914. if prePublishTime.Before(time.Now().Add(2 * time.Minute)) {
  915. br.Msg = "发布时间距离当前时间太近了"
  916. return
  917. }
  918. report, err := models.GetEnglishReportById(reportId)
  919. if err != nil {
  920. br.Msg = "获取报告信息失败"
  921. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  922. return
  923. }
  924. if report == nil {
  925. br.Msg = "报告不存在"
  926. return
  927. }
  928. if report.Content == "" {
  929. br.Msg = "报告内容为空,不可发布"
  930. br.ErrMsg = "报告内容为空,不需要生成,report_id:" + strconv.Itoa(report.Id)
  931. return
  932. }
  933. if report.State == 2 {
  934. br.Msg = "报告已发布,不可设置定时发布"
  935. return
  936. }
  937. var tmpErr error
  938. if tmpErr = models.SetPrePublishEnglishReportById(report.Id, req.PrePublishTime); tmpErr != nil {
  939. br.Msg = "设置定时发布失败"
  940. br.ErrMsg = "设置定时发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
  941. return
  942. }
  943. br.Ret = 200
  944. br.Success = true
  945. br.Msg = "定时发布成功"
  946. }
  947. // @Title 取消发布报告接口
  948. // @Description 取消发布报告
  949. // @Param request body models.PublishCancelReq true "type json string"
  950. // @Success 200 Ret=200 取消发布成功
  951. // @router /publish/cancel [post]
  952. func (this *EnglishReportController) PublishCancleReport() {
  953. br := new(models.BaseResponse).Init()
  954. defer func() {
  955. this.Data["json"] = br
  956. this.ServeJSON()
  957. }()
  958. var req models.PublishCancelReq
  959. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  960. if err != nil {
  961. br.Msg = "参数解析异常!"
  962. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  963. return
  964. }
  965. if req.ReportIds <= 0 {
  966. br.Msg = "参数错误"
  967. br.ErrMsg = "参数错误,报告id不可为空"
  968. return
  969. }
  970. err = models.PublishCancelEnglishReport(req.ReportIds)
  971. if err != nil {
  972. br.Msg = "取消发布失败"
  973. br.ErrMsg = "取消发布失败,Err:" + err.Error()
  974. return
  975. }
  976. // 更新es里的报告状态
  977. go func() {
  978. _ = services.UpdateEnglishReportEs(req.ReportIds, 1)
  979. }()
  980. br.Ret = 200
  981. br.Success = true
  982. br.Msg = "取消发布成功"
  983. }
  984. // @Title 删除报告接口
  985. // @Description 删除报告
  986. // @Param request body models.DeleteReq true "type json string"
  987. // @Success 200 Ret=200 删除成功
  988. // @router /delete [post]
  989. func (this *EnglishReportController) Delete() {
  990. br := new(models.BaseResponse).Init()
  991. defer func() {
  992. this.Data["json"] = br
  993. this.ServeJSON()
  994. }()
  995. var req models.DeleteReq
  996. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  997. if err != nil {
  998. br.Msg = "参数解析异常!"
  999. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1000. return
  1001. }
  1002. if req.ReportIds <= 0 {
  1003. br.Msg = "参数错误"
  1004. br.ErrMsg = "参数错误,报告id不可为空"
  1005. return
  1006. }
  1007. reportInfo, err := models.GetEnglishReportById(req.ReportIds)
  1008. if err != nil {
  1009. if err.Error() == utils.ErrNoRow() {
  1010. br.Msg = "报告不存在"
  1011. return
  1012. }
  1013. br.Msg = "查询报告信息失败"
  1014. br.ErrMsg = "查询报告信息失败, Err" + err.Error()
  1015. return
  1016. }
  1017. // 更新es里的报告状态
  1018. _ = services.UpdateEnglishReportEs(req.ReportIds, 1)
  1019. if err = models.DeleteEnglishReportAndChapter(reportInfo); err != nil {
  1020. br.Msg = "删除失败"
  1021. br.ErrMsg = "删除报告失败, Err: " + err.Error()
  1022. return
  1023. }
  1024. // 重置PPT关联报告
  1025. go func() {
  1026. _ = services.ResetPPTReport(req.ReportIds, true)
  1027. }()
  1028. go func() {
  1029. _ = services.EnglishPolicyReportSyncCancel(reportInfo)
  1030. }()
  1031. br.Ret = 200
  1032. br.Success = true
  1033. br.Msg = "删除成功"
  1034. }
  1035. // @Title 保存草稿
  1036. // @Description 保存草稿
  1037. // @Param request body models.SaveReportContent true "type json string"
  1038. // @Success 200 {object} models.ReportAuthorResp
  1039. // @router /saveReportContent [post]
  1040. func (this *EnglishReportController) SaveReportContent() {
  1041. br := new(models.BaseResponse).Init()
  1042. br.IsSendEmail = false
  1043. defer func() {
  1044. this.Data["json"] = br
  1045. this.ServeJSON()
  1046. }()
  1047. var req models.SaveReportContent
  1048. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1049. if err != nil {
  1050. br.Msg = "参数解析异常!"
  1051. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1052. return
  1053. }
  1054. sysUser := this.SysUser
  1055. if sysUser == nil {
  1056. br.Msg = "请登录"
  1057. br.ErrMsg = "请登录,SysUser Is Empty"
  1058. br.Ret = 408
  1059. return
  1060. }
  1061. reportId := req.ReportId
  1062. noChangeFlag := req.NoChange
  1063. fmt.Println("reportId:", reportId)
  1064. if reportId <= 0 {
  1065. br.Msg = "请输入报告ID"
  1066. return
  1067. }
  1068. markStatus, err := services.UpdateEnReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName)
  1069. if err != nil {
  1070. br.Msg = err.Error()
  1071. return
  1072. }
  1073. if markStatus.Status == 1 {
  1074. br.Msg = markStatus.Msg
  1075. return
  1076. }
  1077. if noChangeFlag != 1 {
  1078. content := req.Content
  1079. if content == "" {
  1080. content = this.GetString("Content")
  1081. }
  1082. if content != "" {
  1083. contentClean, e := services.FilterReportContentBr(req.Content)
  1084. if e != nil {
  1085. br.Msg = "内容去除前后空格失败"
  1086. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  1087. return
  1088. }
  1089. content = contentClean
  1090. contentSub, err := services.GetReportContentSub(content)
  1091. if err != nil {
  1092. go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
  1093. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  1094. }
  1095. content = html.EscapeString(content)
  1096. contentSub = html.EscapeString(contentSub)
  1097. err = models.EditEnglishReportContent(reportId, content, contentSub)
  1098. if err != nil {
  1099. br.Msg = "保存失败"
  1100. br.ErrMsg = "保存失败,Err:" + err.Error()
  1101. return
  1102. }
  1103. go models.AddEnglishReportSaveLog(reportId, this.SysUser.AdminId, content, contentSub, this.SysUser.AdminName)
  1104. }
  1105. }
  1106. resp := new(models.SaveReportContentResp)
  1107. resp.ReportId = reportId
  1108. br.Ret = 200
  1109. br.Success = true
  1110. br.Msg = "保存成功成功"
  1111. br.Data = resp
  1112. }
  1113. // @Title 根据分类获取最近一次报告详情接口
  1114. // @Description 根据分类获取最近一次报告详情
  1115. // @Param request body models.ClassifyIdDetailReq true "type json string"
  1116. // @Success 200 {object} models.Report
  1117. // @router /classifyIdDetail [get]
  1118. func (this *EnglishReportController) ClassifyIdDetail() {
  1119. br := new(models.BaseResponse).Init()
  1120. defer func() {
  1121. this.Data["json"] = br
  1122. this.ServeJSON()
  1123. }()
  1124. //classify_id_first=34&classify_id_second=36
  1125. /*var req models.ClassifyIdDetailReq
  1126. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1127. if err != nil {
  1128. br.Msg = "参数解析异常!"
  1129. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1130. return
  1131. }*/
  1132. classifyIdFirst, _ := this.GetInt("classify_id_first")
  1133. if classifyIdFirst <= 0 {
  1134. classifyIdFirst, _ = this.GetInt("ClassifyIdFirst")
  1135. }
  1136. classifyIdSecond, _ := this.GetInt("classify_id_second")
  1137. if classifyIdSecond <= 0 {
  1138. classifyIdSecond, _ = this.GetInt("ClassifyIdSecond")
  1139. }
  1140. item, err := models.GetEnglishReportDetailByClassifyId(classifyIdFirst, classifyIdSecond)
  1141. if err != nil && err.Error() != utils.ErrNoRow() {
  1142. br.Msg = "获取失败!"
  1143. br.ErrMsg = "获取失败,Err:" + err.Error()
  1144. return
  1145. }
  1146. if item != nil {
  1147. item.Content = html.UnescapeString(item.Content)
  1148. item.ContentSub = html.UnescapeString(item.ContentSub)
  1149. classifyNameMap := make(map[int]*models.EnglishClassifyFullName)
  1150. if item.ClassifyIdSecond > 0 {
  1151. nameList, tErr := models.GetEnglishClassifyFullNameByIds([]int{item.ClassifyIdSecond})
  1152. if tErr != nil {
  1153. br.Msg = "获取分类名称失败"
  1154. br.ErrMsg = "获取分类名称失败, ERR:" + tErr.Error()
  1155. return
  1156. }
  1157. for _, v := range nameList {
  1158. classifyNameMap[v.Id] = v
  1159. }
  1160. //处理分类名
  1161. if n, ok := classifyNameMap[item.ClassifyIdSecond]; ok {
  1162. item.ClassifyNameRoot = n.RootName
  1163. item.ClassifyIdRoot = n.RootId
  1164. }
  1165. }
  1166. }
  1167. br.Ret = 200
  1168. br.Success = true
  1169. br.Msg = "获取成功"
  1170. br.Data = item
  1171. }
  1172. // Author
  1173. // @Title 获取报告作者接口
  1174. // @Description 获取报告作者
  1175. // @Param AuthorType query int true "来源类型,1:中文,2:英文"
  1176. // @Param Keyword query string true "搜索关键词"
  1177. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1178. // @Param StartDate query string true "开始时间"
  1179. // @Success 200 {object} models.ReportAuthorResp
  1180. // @router /author [get]
  1181. func (this *EnglishReportController) Author() {
  1182. br := new(models.BaseResponse).Init()
  1183. defer func() {
  1184. this.Data["json"] = br
  1185. this.ServeJSON()
  1186. }()
  1187. keyword := this.GetString("Keyword")
  1188. var condition string
  1189. var pars []interface{}
  1190. condition += ` AND author_type = 2 AND enable = 1`
  1191. if keyword != `` {
  1192. condition += ` AND report_author like ? `
  1193. pars = append(pars, "%"+keyword+"%")
  1194. }
  1195. _, items, err := models.GetReportAuthorList(condition, pars, 0, 10000)
  1196. if err != nil {
  1197. br.Msg = "获取失败!"
  1198. br.ErrMsg = "获取失败,Err:" + err.Error()
  1199. return
  1200. }
  1201. resp := models.ReportAuthorResp{
  1202. List: items,
  1203. }
  1204. br.Ret = 200
  1205. br.Success = true
  1206. br.Msg = "获取成功"
  1207. br.Data = resp
  1208. }
  1209. // MarkEditStatus
  1210. // @Title 标记报告编辑状态
  1211. // @Description 标记报告编辑状态接口
  1212. // @Param request body request.MarkEditEnReport true "type json string"
  1213. // @Success 200 标记成功 ;202 标记成功
  1214. // @router /mark [post]
  1215. func (this *EnglishReportController) MarkEditStatus() {
  1216. br := new(models.BaseResponse).Init()
  1217. defer func() {
  1218. this.Data["json"] = br
  1219. this.ServeJSON()
  1220. }()
  1221. sysUser := this.SysUser
  1222. if sysUser == nil {
  1223. br.Msg = "请登录"
  1224. br.ErrMsg = "请登录,SysUser Is Empty"
  1225. br.Ret = 408
  1226. return
  1227. }
  1228. var req models.MarkEditEnReport
  1229. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1230. if err != nil {
  1231. br.Msg = "参数解析异常!"
  1232. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1233. return
  1234. }
  1235. if req.ReportId <= 0 {
  1236. br.Msg = "缺少报告Id"
  1237. return
  1238. }
  1239. if req.Status <= 0 {
  1240. br.Msg = "标记状态异常"
  1241. return
  1242. }
  1243. //更新标记key
  1244. data, err := services.UpdateEnReportEditMark(req.ReportId, sysUser.AdminId, req.Status, sysUser.RealName)
  1245. if err != nil {
  1246. br.Msg = err.Error()
  1247. return
  1248. }
  1249. msg := "标记成功"
  1250. br.Ret = 200
  1251. br.Success = true
  1252. br.Msg = msg
  1253. br.Data = data
  1254. }
  1255. // @Title 编辑来自策略报告的报告
  1256. // @Description 编辑来自策略报告的报告
  1257. // @Param request body models.EditEnglishReportFromPolicyReq true "type json string"
  1258. // @Success 200 {object} models.EditEnglishReportResp
  1259. // @router /edit_policy [post]
  1260. func (this *EnglishReportController) EditPolicy() {
  1261. br := new(models.BaseResponse).Init()
  1262. defer func() {
  1263. this.Data["json"] = br
  1264. this.ServeJSON()
  1265. }()
  1266. sysUser := this.SysUser
  1267. if sysUser == nil {
  1268. br.Msg = "请登录"
  1269. br.ErrMsg = "请登录,SysUser Is Empty"
  1270. br.Ret = 408
  1271. return
  1272. }
  1273. var req models.EditEnglishReportFromPolicyReq
  1274. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1275. if err != nil {
  1276. br.Msg = "参数解析异常!"
  1277. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1278. return
  1279. }
  1280. if req.ReportId <= 0 {
  1281. br.Msg = "请选择报告ID"
  1282. return
  1283. }
  1284. if req.Title == "" {
  1285. br.Msg = "请输入标题"
  1286. return
  1287. }
  1288. if req.Abstract == "" {
  1289. br.Msg = "请输入摘要"
  1290. return
  1291. }
  1292. if req.Frequency == "" {
  1293. br.Msg = "请输入频度"
  1294. return
  1295. }
  1296. if req.Author == "" {
  1297. br.Msg = "请输入作者"
  1298. return
  1299. }
  1300. if req.CreateTime == "" {
  1301. br.Msg = "请输入创建时间"
  1302. return
  1303. }
  1304. //查询报告是否存在
  1305. reportInfo, err := models.GetEnglishReportItemById(int(req.ReportId))
  1306. if err != nil {
  1307. if err.Error() == utils.ErrNoRow() {
  1308. br.Msg = "报告不存在"
  1309. return
  1310. }
  1311. br.Msg = "查询报告信息失败"
  1312. br.ErrMsg = "查询报告信息失败, Err" + err.Error()
  1313. return
  1314. }
  1315. if reportInfo.State == 2 {
  1316. br.Msg = "报告已发布不允许编辑"
  1317. return
  1318. }
  1319. markStatus, err := services.UpdateEnReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName)
  1320. if err != nil {
  1321. br.Msg = err.Error()
  1322. return
  1323. }
  1324. if markStatus.Status == 1 {
  1325. br.Msg = markStatus.Msg
  1326. return
  1327. }
  1328. item := reportInfo
  1329. item.Title = req.Title
  1330. item.Abstract = req.Abstract
  1331. item.Author = req.Author
  1332. item.Frequency = req.Frequency
  1333. item.CreateTime = req.CreateTime
  1334. item.ModifyTime = time.Now()
  1335. err = item.Update([]string{"Title", "Abstract", "Author", "Frequency", "CreateTime", "ModifyTime"})
  1336. if err != nil {
  1337. br.Msg = "保存失败"
  1338. br.ErrMsg = "保存失败,Err:" + err.Error()
  1339. return
  1340. }
  1341. reportCode := reportInfo.ReportCode
  1342. resp := new(models.EditEnglishReportResp)
  1343. resp.ReportId = req.ReportId
  1344. resp.ReportCode = reportCode
  1345. br.Ret = 200
  1346. br.Success = true
  1347. br.Msg = "保存成功"
  1348. br.Data = resp
  1349. }