report_chapter.go 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/report"
  6. "eta/eta_api/services"
  7. "eta/eta_api/utils"
  8. "html"
  9. "strconv"
  10. "time"
  11. )
  12. // EditDayWeekChapter
  13. // @Title 编辑晨周报章节内容
  14. // @Description 编辑晨周报章节内容
  15. // @Param request body models.EditReportChapterReq true "type json string"
  16. // @Success 200 Ret=200 保存成功
  17. // @router /addChapter [post]
  18. func (this *ReportController) AddDayWeekChapter() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. sysUser := this.SysUser
  25. if sysUser == nil {
  26. br.Msg = "请登录"
  27. br.ErrMsg = "请登录,SysUser Is Empty"
  28. br.Ret = 408
  29. return
  30. }
  31. var req models.AddReportChapterReq
  32. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  33. if err != nil {
  34. br.Msg = "参数解析异常!"
  35. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  36. return
  37. }
  38. if req.ReportId <= 0 {
  39. br.Msg = "报告ID有误"
  40. return
  41. }
  42. // 获取报告详情
  43. reportInfo, err := models.GetReportById(req.ReportId)
  44. if err != nil {
  45. br.Msg = "报告信息有误"
  46. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  47. return
  48. }
  49. if reportInfo.State == 2 {
  50. br.Msg = "该报告已发布,不允许编辑"
  51. br.ErrMsg = "该报告已发布,不允许编辑"
  52. return
  53. }
  54. newContent := req.Content
  55. // 更新章节及指标
  56. contentSub := ""
  57. if req.Content != "" {
  58. e := utils.ContentXssCheck(req.Content)
  59. if e != nil {
  60. br.Msg = "存在非法标签"
  61. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  62. return
  63. }
  64. contentClean, e := services.FilterReportContentBr(req.Content)
  65. if e != nil {
  66. br.Msg = "内容去除前后空格失败"
  67. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  68. return
  69. }
  70. req.Content = contentClean
  71. contentSub, err = services.GetReportContentSub(req.Content)
  72. if err != nil {
  73. br.Msg = "内容分段解析失败"
  74. br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
  75. return
  76. }
  77. }
  78. if req.Content == "" {
  79. req.Content = newContent
  80. }
  81. reportChapterInfo := new(models.ReportChapter)
  82. reportChapterInfo.ReportId = reportInfo.Id
  83. reportChapterInfo.ClassifyIdFirst = reportInfo.ClassifyIdFirst
  84. reportChapterInfo.ClassifyNameFirst = reportInfo.ClassifyNameFirst
  85. reportChapterInfo.Title = req.Title
  86. reportChapterInfo.AddType = 1
  87. reportChapterInfo.Author = req.Author
  88. reportChapterInfo.Content = html.EscapeString(req.Content)
  89. reportChapterInfo.ContentSub = html.EscapeString(contentSub)
  90. reportChapterInfo.IsEdit = 1
  91. reportChapterInfo.CreateTime = req.CreateTime
  92. reportChapterInfo.VideoKind = 1
  93. reportChapterInfo.ClassifyIdSecond = reportInfo.ClassifyIdSecond
  94. reportChapterInfo.ClassifyNameSecond = reportInfo.ClassifyNameSecond
  95. reportChapterInfo.ClassifyIdThird = reportInfo.ClassifyIdThird
  96. reportChapterInfo.ClassifyNameThird = reportInfo.ClassifyNameThird
  97. reportChapterInfo.LastModifyAdminId = sysUser.AdminId
  98. reportChapterInfo.LastModifyAdminName = sysUser.RealName
  99. reportChapterInfo.ContentModifyTime = time.Now()
  100. reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
  101. reportChapterInfo.CanvasColor = req.CanvasColor
  102. reportChapterInfo.HeadResourceId = req.HeadResourceId
  103. reportChapterInfo.EndResourceId = req.EndResourceId
  104. err = reportChapterInfo.Add()
  105. if err != nil {
  106. br.Msg = "新增失败"
  107. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  108. return
  109. }
  110. // 备份关键数据
  111. chapters := make([]*models.ReportChapter, 0)
  112. chapters = append(chapters, reportChapterInfo)
  113. go services.SaveReportLogs(nil, chapters, sysUser.AdminId, sysUser.RealName)
  114. br.Ret = 200
  115. br.Success = true
  116. br.Msg = "保存成功"
  117. }
  118. // EditDayWeekChapter
  119. // @Title 编辑晨周报章节内容
  120. // @Description 编辑晨周报章节内容
  121. // @Param request body models.EditReportChapterReq true "type json string"
  122. // @Success 200 Ret=200 保存成功
  123. // @router /editDayWeekChapter [post]
  124. func (this *ReportController) EditDayWeekChapter() {
  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.EditReportChapterReq
  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. reportChapterId := req.ReportChapterId
  145. if reportChapterId <= 0 {
  146. br.Msg = "报告章节ID有误"
  147. return
  148. }
  149. if req.Content == "" {
  150. br.Msg = "请输入内容"
  151. return
  152. }
  153. // 获取章节详情
  154. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  155. if err != nil {
  156. br.Msg = "报告章节信息有误"
  157. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  158. return
  159. }
  160. // 获取报告详情
  161. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  162. if err != nil {
  163. br.Msg = "报告信息有误"
  164. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  165. return
  166. }
  167. // 操作权限校验
  168. {
  169. // 如果不是创建人,那么就要去查看是否授权
  170. if reportInfo.AdminId != sysUser.AdminId {
  171. // 授权用户权限校验
  172. chapterGrantObj := report.ReportChapterGrant{}
  173. _, tmpErr := chapterGrantObj.GetGrantByIdAndAdmin(reportChapterInfo.ReportChapterId, sysUser.AdminId)
  174. if tmpErr != nil {
  175. if tmpErr.Error() == utils.ErrNoRow() {
  176. br.Msg = "没有权限"
  177. br.ErrMsg = "没有权限"
  178. br.IsSendEmail = false
  179. return
  180. }
  181. br.Msg = "获取章节id授权用户失败"
  182. br.ErrMsg = "获取章节id授权用户失败, Err: " + tmpErr.Error()
  183. return
  184. }
  185. }
  186. // 标记更新中
  187. {
  188. markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  189. if err != nil {
  190. br.Msg = err.Error()
  191. return
  192. }
  193. if markStatus.Status == 1 {
  194. br.Msg = markStatus.Msg
  195. br.IsSendEmail = false
  196. return
  197. }
  198. }
  199. }
  200. if reportInfo.State == 2 {
  201. br.Msg = "该报告已发布,不允许编辑"
  202. br.ErrMsg = "该报告已发布,不允许编辑"
  203. return
  204. }
  205. reqTickerList := req.TickerList
  206. // 更新章节及指标
  207. contentSub := ""
  208. if req.Content != "" {
  209. e := utils.ContentXssCheck(req.Content)
  210. if e != nil {
  211. br.Msg = "存在非法标签"
  212. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  213. return
  214. }
  215. contentClean, e := services.FilterReportContentBr(req.Content)
  216. if e != nil {
  217. br.Msg = "内容去除前后空格失败"
  218. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  219. return
  220. }
  221. req.Content = contentClean
  222. contentSub, err = services.GetReportContentSub(req.Content)
  223. if err != nil {
  224. br.Msg = "内容分段解析失败"
  225. br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
  226. return
  227. }
  228. }
  229. reportChapterInfo.Title = req.Title
  230. //reportChapterInfo.AddType = req.AddType
  231. reportChapterInfo.Author = req.Author
  232. reportChapterInfo.Content = html.EscapeString(req.Content)
  233. reportChapterInfo.ContentSub = html.EscapeString(contentSub)
  234. reportChapterInfo.IsEdit = 1
  235. reportChapterInfo.CreateTime = req.CreateTime
  236. reportChapterInfo.VideoUrl = req.VideoUrl
  237. reportChapterInfo.VideoName = req.VideoName
  238. reportChapterInfo.VideoPlaySeconds = req.VideoPlaySeconds
  239. reportChapterInfo.VideoSize = req.VideoSize
  240. reportChapterInfo.VideoKind = 1
  241. reportChapterInfo.LastModifyAdminId = sysUser.AdminId
  242. reportChapterInfo.LastModifyAdminName = sysUser.RealName
  243. reportChapterInfo.ContentModifyTime = time.Now()
  244. reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
  245. reportChapterInfo.CanvasColor = req.CanvasColor
  246. reportChapterInfo.HeadResourceId = req.HeadResourceId
  247. reportChapterInfo.EndResourceId = req.EndResourceId
  248. updateCols := make([]string, 0)
  249. updateCols = append(updateCols, "Title", "AddType", "Author", "Content", "ContentSub", "IsEdit", "CreateTime")
  250. if req.VideoUrl != "" {
  251. updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
  252. }
  253. updateCols = append(updateCols, "LastModifyAdminId", "LastModifyAdminName", "ContentModifyTime", "ContentStruct", "CanvasColor", "HeadResourceId", "EndResourceId")
  254. // 章节报告更新指标
  255. tickerList := make([]*models.ReportChapterTicker, 0)
  256. if len(reqTickerList) > 0 {
  257. nowTime := time.Now()
  258. for i := 0; i < len(reqTickerList); i++ {
  259. tickerList = append(tickerList, &models.ReportChapterTicker{
  260. ReportChapterId: reportChapterInfo.ReportChapterId,
  261. Sort: reqTickerList[i].Sort,
  262. Ticker: reqTickerList[i].Ticker,
  263. CreateTime: nowTime,
  264. UpdateTime: nowTime,
  265. })
  266. }
  267. }
  268. err = models.UpdateChapterAndTicker(reportChapterInfo, updateCols, tickerList)
  269. if err != nil {
  270. br.Msg = "保存失败"
  271. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  272. return
  273. }
  274. // 标记更新中
  275. {
  276. markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  277. if err != nil {
  278. br.Msg = err.Error()
  279. return
  280. }
  281. if markStatus.Status == 1 {
  282. br.Msg = markStatus.Msg
  283. return
  284. }
  285. }
  286. // 备份关键数据
  287. chapters := make([]*models.ReportChapter, 0)
  288. chapters = append(chapters, reportChapterInfo)
  289. go services.SaveReportLogs(nil, chapters, sysUser.AdminId, sysUser.RealName)
  290. br.Ret = 200
  291. br.Success = true
  292. br.Msg = "保存成功"
  293. }
  294. // DelChapter
  295. // @Title 编辑晨周报章节内容
  296. // @Description 编辑晨周报章节内容
  297. // @Param request body models.EditReportChapterReq true "type json string"
  298. // @Success 200 Ret=200 保存成功
  299. // @router /chapter/del [post]
  300. //func (this *ReportController) DelChapter() {
  301. // br := new(models.BaseResponse).Init()
  302. // defer func() {
  303. // this.Data["json"] = br
  304. // this.ServeJSON()
  305. // }()
  306. //
  307. // sysUser := this.SysUser
  308. // if sysUser == nil {
  309. // br.Msg = "请登录"
  310. // br.ErrMsg = "请登录,SysUser Is Empty"
  311. // br.Ret = 408
  312. // return
  313. // }
  314. //
  315. // var req models.DelReportChapterReq
  316. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  317. // if err != nil {
  318. // br.Msg = "参数解析异常!"
  319. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  320. // return
  321. // }
  322. // reportChapterId := req.ReportChapterId
  323. // if reportChapterId <= 0 {
  324. // br.Msg = "报告章节ID有误"
  325. // return
  326. // }
  327. // if req.Content == "" {
  328. // br.Msg = "请输入内容"
  329. // return
  330. // }
  331. //
  332. // // 获取章节详情
  333. // reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  334. // if err != nil {
  335. // br.Msg = "报告章节信息有误"
  336. // br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  337. // return
  338. // }
  339. //
  340. // // 获取报告详情
  341. // reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  342. // if err != nil {
  343. // br.Msg = "报告信息有误"
  344. // br.ErrMsg = "报告信息有误, Err: " + err.Error()
  345. // return
  346. // }
  347. //
  348. // // 操作权限校验
  349. // {
  350. // // 如果不是创建人,那么就要去查看是否授权
  351. // if reportInfo.AdminId != sysUser.AdminId {
  352. // // 授权用户权限校验
  353. // chapterGrantObj := report.ReportChapterGrant{}
  354. // _, tmpErr := chapterGrantObj.GetGrantByIdAndAdmin(reportChapterInfo.ReportChapterId, sysUser.AdminId)
  355. // if tmpErr != nil {
  356. // if tmpErr.Error() == utils.ErrNoRow() {
  357. // br.Msg = "没有权限"
  358. // br.ErrMsg = "没有权限"
  359. // br.IsSendEmail = false
  360. // return
  361. // }
  362. // br.Msg = "获取章节id授权用户失败"
  363. // br.ErrMsg = "获取章节id授权用户失败, Err: " + tmpErr.Error()
  364. // return
  365. // }
  366. // }
  367. //
  368. // // 标记更新中
  369. // {
  370. // markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  371. // if err != nil {
  372. // br.Msg = err.Error()
  373. // return
  374. // }
  375. // if markStatus.Status == 1 {
  376. // br.Msg = markStatus.Msg
  377. // br.IsSendEmail = false
  378. // return
  379. // }
  380. // }
  381. // }
  382. //
  383. // if reportInfo.State == 2 {
  384. // br.Msg = "该报告已发布,不允许编辑"
  385. // br.ErrMsg = "该报告已发布,不允许编辑"
  386. // return
  387. // }
  388. //
  389. // reqTickerList := req.TickerList
  390. // // 更新章节及指标
  391. // contentSub := ""
  392. // if req.Content != "" {
  393. // e := utils.ContentXssCheck(req.Content)
  394. // if e != nil {
  395. // br.Msg = "存在非法标签"
  396. // br.ErrMsg = "存在非法标签, Err: " + e.Error()
  397. // return
  398. // }
  399. // contentClean, e := services.FilterReportContentBr(req.Content)
  400. // if e != nil {
  401. // br.Msg = "内容去除前后空格失败"
  402. // br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  403. // return
  404. // }
  405. // req.Content = contentClean
  406. //
  407. // contentSub, err = services.GetReportContentSub(req.Content)
  408. // if err != nil {
  409. // br.Msg = "内容分段解析失败"
  410. // br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
  411. // return
  412. // }
  413. // }
  414. //
  415. // reportChapterInfo.Title = req.Title
  416. // //reportChapterInfo.AddType = req.AddType
  417. // reportChapterInfo.Author = req.Author
  418. // reportChapterInfo.Content = html.EscapeString(req.Content)
  419. // reportChapterInfo.ContentSub = html.EscapeString(contentSub)
  420. // reportChapterInfo.IsEdit = 1
  421. // reportChapterInfo.CreateTime = req.CreateTime
  422. // reportChapterInfo.VideoUrl = req.VideoUrl
  423. // reportChapterInfo.VideoName = req.VideoName
  424. // reportChapterInfo.VideoPlaySeconds = req.VideoPlaySeconds
  425. // reportChapterInfo.VideoSize = req.VideoSize
  426. // reportChapterInfo.VideoKind = 1
  427. //
  428. // reportChapterInfo.LastModifyAdminId = sysUser.AdminId
  429. // reportChapterInfo.LastModifyAdminName = sysUser.RealName
  430. // reportChapterInfo.ContentModifyTime = time.Now()
  431. // reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
  432. // reportChapterInfo.CanvasColor = req.CanvasColor
  433. // reportChapterInfo.HeadResourceId = req.HeadResourceId
  434. // reportChapterInfo.EndResourceId = req.EndResourceId
  435. //
  436. // updateCols := make([]string, 0)
  437. // updateCols = append(updateCols, "Title", "AddType", "Author", "Content", "ContentSub", "IsEdit", "CreateTime")
  438. // if req.VideoUrl != "" {
  439. // updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
  440. // }
  441. //
  442. // updateCols = append(updateCols, "LastModifyAdminId", "LastModifyAdminName", "ContentModifyTime", "ContentStruct", "CanvasColor", "HeadResourceId", "EndResourceId")
  443. //
  444. // // 章节报告更新指标
  445. // tickerList := make([]*models.ReportChapterTicker, 0)
  446. // if len(reqTickerList) > 0 {
  447. // nowTime := time.Now()
  448. // for i := 0; i < len(reqTickerList); i++ {
  449. // tickerList = append(tickerList, &models.ReportChapterTicker{
  450. // ReportChapterId: reportChapterInfo.ReportChapterId,
  451. // Sort: reqTickerList[i].Sort,
  452. // Ticker: reqTickerList[i].Ticker,
  453. // CreateTime: nowTime,
  454. // UpdateTime: nowTime,
  455. // })
  456. // }
  457. // }
  458. // err = models.UpdateChapterAndTicker(reportChapterInfo, updateCols, tickerList)
  459. // if err != nil {
  460. // br.Msg = "保存失败"
  461. // br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  462. // return
  463. // }
  464. //
  465. // // 标记更新中
  466. // {
  467. // markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  468. // if err != nil {
  469. // br.Msg = err.Error()
  470. // return
  471. // }
  472. // if markStatus.Status == 1 {
  473. // br.Msg = markStatus.Msg
  474. // return
  475. // }
  476. // }
  477. //
  478. // // 备份关键数据
  479. // chapters := make([]*models.ReportChapter, 0)
  480. // chapters = append(chapters, reportChapterInfo)
  481. // go services.SaveReportLogs(nil, chapters, sysUser.AdminId, sysUser.RealName)
  482. //
  483. // br.Ret = 200
  484. // br.Success = true
  485. // br.Msg = "保存成功"
  486. //}
  487. // EditChapterBaseInfoAndPermission
  488. // @Title 修改报告章节的基础信息、授权用户权限、品种权限
  489. // @Description 修改报告章节的基础信息、授权用户权限、品种权限
  490. // @Param request body models.EditReportChapterReq true "type json string"
  491. // @Success 200 Ret=200 保存成功
  492. // @router /chapter/base_info/edit [post]
  493. func (this *ReportController) EditChapterBaseInfoAndPermission() {
  494. br := new(models.BaseResponse).Init()
  495. defer func() {
  496. this.Data["json"] = br
  497. this.ServeJSON()
  498. }()
  499. sysUser := this.SysUser
  500. if sysUser == nil {
  501. br.Msg = "请登录"
  502. br.ErrMsg = "请登录,SysUser Is Empty"
  503. br.Ret = 408
  504. return
  505. }
  506. var req models.EditReportChapterBaseInfoAndPermissionReq
  507. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  508. if err != nil {
  509. br.Msg = "参数解析异常!"
  510. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  511. return
  512. }
  513. reportChapterId := req.ReportChapterId
  514. if reportChapterId <= 0 {
  515. br.Msg = "报告章节ID有误"
  516. return
  517. }
  518. // 获取章节详情
  519. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  520. if err != nil {
  521. br.Msg = "报告章节信息有误"
  522. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  523. return
  524. }
  525. // 获取报告详情
  526. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  527. if err != nil {
  528. br.Msg = "报告信息有误"
  529. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  530. return
  531. }
  532. if reportInfo.State == 2 {
  533. br.Msg = "该报告已发布,不允许编辑"
  534. br.ErrMsg = "该报告已发布,不允许编辑"
  535. return
  536. }
  537. err, errMsg := services.EditChapterBaseInfoAndPermission(reportInfo, reportChapterInfo, req.Title, req.PermissionIdList, req.AdminIdList)
  538. if err != nil {
  539. br.Msg = "保存失败"
  540. if errMsg != "" {
  541. br.Msg = errMsg
  542. }
  543. br.ErrMsg = "保存失败,Err:" + err.Error()
  544. return
  545. }
  546. br.Ret = 200
  547. br.Success = true
  548. br.Msg = "保存成功"
  549. }
  550. // GetReportChapterList
  551. // @Title 获取报告章节列表
  552. // @Description 获取报告章节列表
  553. // @Param ReportId query string true "报告ID"
  554. // @Success 200 {object} company.CompanyListResp
  555. // @router /getReportChapterList [get]
  556. func (this *ReportController) GetReportChapterList() {
  557. // TODO 授权用户校验
  558. br := new(models.BaseResponse).Init()
  559. defer func() {
  560. this.Data["json"] = br
  561. this.ServeJSON()
  562. }()
  563. sysUser := this.SysUser
  564. if sysUser == nil {
  565. br.Msg = "请登录"
  566. br.ErrMsg = "请登录,SysUser Is Empty"
  567. br.Ret = 408
  568. return
  569. }
  570. reqReportId := this.GetString("ReportId")
  571. reportId, _ := strconv.Atoi(reqReportId)
  572. if reportId <= 0 {
  573. br.Msg = "报告ID有误"
  574. return
  575. }
  576. // 获取章节列表
  577. chapterList, err := models.GetChapterListByReportId(reportId)
  578. if err != nil {
  579. br.Msg = "获取章节列表失败"
  580. br.ErrMsg = "获取章节列表失败, Err: " + err.Error()
  581. return
  582. }
  583. typeList, err := models.GetReportChapterTypeList()
  584. if err != nil {
  585. br.Msg = "获取章节类型列表失败"
  586. br.ErrMsg = "获取章节类型列表失败, Err: " + err.Error()
  587. return
  588. }
  589. typeIdImg := make(map[int]string)
  590. for i := 0; i < len(typeList); i++ {
  591. typeIdImg[typeList[i].ReportChapterTypeId] = typeList[i].EditImgUrl
  592. }
  593. resp := make([]models.ReportChapterResp, 0)
  594. if len(chapterList) > 0 {
  595. chapterIdList := make([]int, 0)
  596. // 章节id授权用户列表map
  597. chapterIdGrandListMap := make(map[int][]int)
  598. // 章节id关联品种id列表map
  599. chapterIdPermissionListMap := make(map[int][]int)
  600. for _, v := range chapterList {
  601. chapterIdList = append(chapterIdList, v.ReportChapterId)
  602. }
  603. // 处理章节id授权用户列表
  604. {
  605. chapterGrantObj := report.ReportChapterGrant{}
  606. chapterGrantList, tmpErr := chapterGrantObj.GetGrantListByIdList(chapterIdList)
  607. if tmpErr != nil {
  608. br.Msg = "获取章节id授权用户列表失败"
  609. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  610. return
  611. }
  612. for _, v := range chapterGrantList {
  613. tmpChapterIdGrandList, ok := chapterIdGrandListMap[v.ReportChapterId]
  614. if !ok {
  615. tmpChapterIdGrandList = make([]int, 0)
  616. }
  617. chapterIdGrandListMap[v.ReportChapterId] = append(tmpChapterIdGrandList, v.AdminId)
  618. }
  619. }
  620. // 处理章节id关联品种id列表
  621. {
  622. obj := report.ReportChapterPermissionMapping{}
  623. chapterPermissionList, tmpErr := obj.GetPermissionListByIdList(chapterIdList)
  624. if tmpErr != nil {
  625. br.Msg = "获取章节id关联品种列表失败"
  626. br.ErrMsg = "获取章节id关联品种列表失败, Err: " + tmpErr.Error()
  627. return
  628. }
  629. for _, v := range chapterPermissionList {
  630. tmpChapterIdPermissionList, ok := chapterIdPermissionListMap[v.ReportChapterId]
  631. if !ok {
  632. tmpChapterIdPermissionList = make([]int, 0)
  633. }
  634. chapterIdPermissionListMap[v.ReportChapterId] = append(tmpChapterIdPermissionList, v.ChartPermissionId)
  635. }
  636. }
  637. // TODO 获取更新规则
  638. researchType := chapterList[0].ReportType
  639. chapterTypeList, tmpErr := models.GetAllReportChapterTypeListByResearchType(researchType)
  640. if tmpErr != nil {
  641. br.Msg = "获取更新规则失败"
  642. br.ErrMsg = "获取更新规则失败, Err: " + tmpErr.Error()
  643. return
  644. }
  645. // 调整章节更新
  646. nowTime := time.Now().Local()
  647. for _, item := range chapterList {
  648. stop := false
  649. for _, rule := range chapterTypeList {
  650. if rule.ReportChapterTypeId == item.TypeId {
  651. //fmt.Println("rule.Enabled :", rule.Enabled, ";name=", rule.ReportChapterTypeName, "item.IsEdit:", item.IsEdit, "rule.IsSet:", rule.IsSet)
  652. // 如果被永久暂停更新了
  653. if rule.Enabled == 0 && item.IsEdit == 0 { //该章节已被永久禁用,同时未被操作过
  654. stop = true
  655. } else if rule.PauseStartTime != "" && rule.PauseEndTime != "" && rule.PauseStartTime != utils.EmptyDateStr && rule.PauseEndTime != utils.EmptyDateStr {
  656. startTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseStartTime, time.Local)
  657. if timeErr != nil {
  658. br.Msg = "获取更新规则失败"
  659. br.ErrMsg = "更新规则时间转换失败4001, Err: " + timeErr.Error()
  660. return
  661. }
  662. endTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseEndTime, time.Local)
  663. if timeErr != nil {
  664. br.Msg = "获取更新规则失败"
  665. br.ErrMsg = "更新规则时间转换失败4002, Err: " + timeErr.Error()
  666. return
  667. }
  668. // 暂停更新
  669. if nowTime.After(startTime) && nowTime.Before(endTime.AddDate(0, 0, 1)) {
  670. stop = true
  671. }
  672. break
  673. }
  674. }
  675. }
  676. if !stop {
  677. // 授权的用户列表
  678. tmpChapterIdGrandList, ok := chapterIdGrandListMap[item.ReportChapterId]
  679. if !ok {
  680. tmpChapterIdGrandList = make([]int, 0)
  681. }
  682. // 关联的品种列表
  683. tmpChapterIdPermissionList, ok := chapterIdPermissionListMap[item.ReportChapterId]
  684. if !ok {
  685. tmpChapterIdPermissionList = make([]int, 0)
  686. }
  687. tmpChapterItem := models.ReportChapterResp{
  688. ReportChapterId: item.ReportChapterId,
  689. ReportId: item.ReportId,
  690. ReportType: item.ReportType,
  691. TypeId: item.TypeId,
  692. TypeName: item.TypeName,
  693. TypeEditImg: typeIdImg[item.TypeId],
  694. Title: item.Title,
  695. IsEdit: item.IsEdit,
  696. Trend: item.Trend,
  697. Sort: item.Sort,
  698. PublishState: item.PublishState,
  699. VideoUrl: item.VideoUrl,
  700. VideoName: item.VideoName,
  701. VideoPlaySeconds: item.VideoPlaySeconds,
  702. VideoSize: item.VideoSize,
  703. VideoKind: item.VideoKind,
  704. ModifyTime: item.ModifyTime.Format(utils.FormatDate),
  705. GrandAdminIdList: tmpChapterIdGrandList,
  706. PermissionIdList: tmpChapterIdPermissionList,
  707. }
  708. markStatus, err := services.UpdateReportEditMark(item.ReportId, item.ReportChapterId, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  709. if err != nil {
  710. br.Msg = "查询标记状态失败"
  711. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  712. return
  713. }
  714. if markStatus.Status == 0 {
  715. tmpChapterItem.CanEdit = true
  716. } else {
  717. tmpChapterItem.Editor = markStatus.Editor
  718. }
  719. resp = append(resp, tmpChapterItem)
  720. }
  721. }
  722. }
  723. br.Ret = 200
  724. br.Success = true
  725. br.Msg = "获取成功"
  726. br.Data = resp
  727. }
  728. // GetDayWeekChapter
  729. // @Title 获取晨周报章节信息
  730. // @Description 获取晨周报章节信息
  731. // @Param ReportChapterId query int true "报告章节ID"
  732. // @Success 200 Ret=200 保存成功
  733. // @router /getDayWeekChapter [get]
  734. func (this *ReportController) GetDayWeekChapter() {
  735. // TODO 授权用户校验
  736. br := new(models.BaseResponse).Init()
  737. defer func() {
  738. this.Data["json"] = br
  739. this.ServeJSON()
  740. }()
  741. sysUser := this.SysUser
  742. if sysUser == nil {
  743. br.Msg = "请登录"
  744. br.ErrMsg = "请登录,SysUser Is Empty"
  745. br.Ret = 408
  746. return
  747. }
  748. reportChapterId, _ := this.GetInt("ReportChapterId")
  749. if reportChapterId <= 0 {
  750. br.Msg = "参数有误"
  751. return
  752. }
  753. chapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  754. if err != nil {
  755. br.Msg = "获取章节信息失败"
  756. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  757. return
  758. }
  759. if chapterInfo != nil {
  760. chapterInfo.Content = html.UnescapeString(chapterInfo.Content)
  761. chapterInfo.ContentSub = html.UnescapeString(chapterInfo.ContentSub)
  762. chapterInfo.ContentStruct = html.UnescapeString(chapterInfo.ContentStruct)
  763. }
  764. // 授权用户列表map
  765. chapterGrantIdList := make([]int, 0)
  766. // 关联品种id列表map
  767. chapterPermissionIdList := make([]int, 0)
  768. // 处理章节id授权用户列表
  769. {
  770. chapterGrantObj := report.ReportChapterGrant{}
  771. chapterGrantList, tmpErr := chapterGrantObj.GetGrantListById(chapterInfo.ReportChapterId)
  772. if tmpErr != nil {
  773. br.Msg = "获取章节id授权用户列表失败"
  774. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  775. return
  776. }
  777. for _, v := range chapterGrantList {
  778. chapterGrantIdList = append(chapterGrantIdList, v.AdminId)
  779. }
  780. }
  781. // 处理章节id关联品种id列表
  782. {
  783. obj := report.ReportChapterPermissionMapping{}
  784. chapterPermissionList, tmpErr := obj.GetPermissionListById(chapterInfo.ReportChapterId)
  785. if tmpErr != nil {
  786. br.Msg = "获取章节id关联品种列表失败"
  787. br.ErrMsg = "获取章节id关联品种列表失败, Err: " + tmpErr.Error()
  788. return
  789. }
  790. for _, v := range chapterPermissionList {
  791. chapterPermissionIdList = append(chapterPermissionIdList, v.ChartPermissionId)
  792. }
  793. }
  794. resp := models.ReportChapterItem{
  795. ReportChapter: *chapterInfo,
  796. GrandAdminIdList: chapterGrantIdList,
  797. PermissionIdList: chapterPermissionIdList,
  798. }
  799. // 获取当前编辑状态
  800. {
  801. markStatus, err := services.UpdateReportEditMark(chapterInfo.ReportId, chapterInfo.ReportChapterId, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  802. if err != nil {
  803. br.Msg = "查询标记状态失败"
  804. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  805. return
  806. }
  807. if markStatus.Status == 0 {
  808. resp.CanEdit = true
  809. } else {
  810. resp.Editor = markStatus.Editor
  811. }
  812. }
  813. br.Ret = 200
  814. br.Success = true
  815. br.Msg = "获取成功"
  816. br.Data = resp
  817. }
  818. // ChapterMove
  819. // @Title 移动章节类型
  820. // @Description 移动章节类型
  821. // @Param request body models.PermissionMoveReq true "type json string"
  822. // @Success 200 Ret=200 操作成功
  823. // @router /chapter/move [post]
  824. func (this *ReportController) ChapterMove() {
  825. br := new(models.BaseResponse).Init()
  826. defer func() {
  827. if br.ErrMsg == "" {
  828. br.IsSendEmail = false
  829. }
  830. this.Data["json"] = br
  831. this.ServeJSON()
  832. }()
  833. sysUser := this.SysUser
  834. if sysUser == nil {
  835. br.Msg = "请登录"
  836. br.ErrMsg = "请登录,SysUser Is Empty"
  837. br.Ret = 408
  838. return
  839. }
  840. var req models.ReportChapterMoveReq
  841. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  842. br.Msg = "参数解析异常!"
  843. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  844. return
  845. }
  846. if req.ReportChapterId == 0 {
  847. br.Msg = "请选择要移动的章节"
  848. return
  849. }
  850. e, msg := services.MoveReportChapter(&req)
  851. if e != nil {
  852. br.Msg = msg
  853. br.ErrMsg = "移动品种失败, Err: " + e.Error()
  854. return
  855. }
  856. br.Ret = 200
  857. br.Success = true
  858. br.Msg = "操作成功"
  859. }
  860. // EditChapterTrendTag
  861. // @Title 编辑章节趋势标签
  862. // @Description 编辑章节趋势标签
  863. // @Param request body models.EditReportChapterReq true "type json string"
  864. // @Success 200 Ret=200 保存成功
  865. // @router /editChapterTrendTag [post]
  866. func (this *ReportController) EditChapterTrendTag() {
  867. br := new(models.BaseResponse).Init()
  868. defer func() {
  869. this.Data["json"] = br
  870. this.ServeJSON()
  871. }()
  872. sysUser := this.SysUser
  873. if sysUser == nil {
  874. br.Msg = "请登录"
  875. br.ErrMsg = "请登录,SysUser Is Empty"
  876. br.Ret = 408
  877. return
  878. }
  879. var req models.EditChapterTrendTagReq
  880. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  881. if err != nil {
  882. br.Msg = "参数解析异常!"
  883. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  884. return
  885. }
  886. if req.ReportChapterId <= 0 {
  887. br.Msg = "章节ID有误"
  888. return
  889. }
  890. if req.Trend == "" {
  891. br.Msg = "请输入标签"
  892. return
  893. }
  894. chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
  895. if err != nil {
  896. br.Msg = "获取章节信息失败"
  897. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  898. return
  899. }
  900. // 获取报告详情
  901. reportInfo, err := models.GetReportByReportId(chapterInfo.ReportId)
  902. if err != nil {
  903. br.Msg = "报告信息有误"
  904. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  905. return
  906. }
  907. // 操作权限校验
  908. {
  909. // 如果不是创建人,那么就要去查看是否授权
  910. if reportInfo.AdminId != sysUser.AdminId {
  911. // 授权用户权限校验
  912. chapterGrantObj := report.ReportChapterGrant{}
  913. _, tmpErr := chapterGrantObj.GetGrantByIdAndAdmin(chapterInfo.ReportChapterId, sysUser.AdminId)
  914. if tmpErr != nil {
  915. if tmpErr.Error() == utils.ErrNoRow() {
  916. br.Msg = "没有权限"
  917. br.ErrMsg = "没有权限"
  918. br.IsSendEmail = false
  919. return
  920. }
  921. br.Msg = "获取章节id授权用户失败"
  922. br.ErrMsg = "获取章节id授权用户失败, Err: " + tmpErr.Error()
  923. return
  924. }
  925. }
  926. }
  927. // 更新章节标签
  928. chapterInfo.Trend = req.Trend
  929. updateCols := make([]string, 0)
  930. updateCols = append(updateCols, "Trend")
  931. if err = chapterInfo.UpdateChapter(updateCols); err != nil {
  932. br.Msg = "更新标签失败"
  933. br.ErrMsg = "更新标签失败, Err: " + err.Error()
  934. return
  935. }
  936. // 添加关键词
  937. if err = models.AddTrendTagKeyWord(req.Trend); err != nil {
  938. br.Msg = "添加标签关键词失败"
  939. br.ErrMsg = "添加标签关键词失败, Err: " + err.Error()
  940. return
  941. }
  942. br.Ret = 200
  943. br.Success = true
  944. br.Msg = "保存成功"
  945. }
  946. // GetSunCode 获取太阳码
  947. // @Title 公共模块
  948. // @Description 获取分享海报
  949. // @Param request body models.SunCodeReq true "type json string"
  950. // @Success 200 {object} string "获取成功"
  951. // @failure 400 {string} string "获取失败"
  952. // @router /getSunCode [post]
  953. func (this *ReportController) GetSunCode() {
  954. br := new(models.BaseResponse).Init()
  955. defer func() {
  956. this.Data["json"] = br
  957. this.ServeJSON()
  958. }()
  959. sysUser := this.SysUser
  960. if sysUser == nil {
  961. br.Msg = "请登录"
  962. br.ErrMsg = "请登录,SysUser Is Empty"
  963. br.Ret = 408
  964. return
  965. }
  966. var req models.SunCodeReq
  967. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  968. if err != nil {
  969. br.Msg = "参数解析异常!"
  970. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  971. return
  972. }
  973. var sunCodeUrl string
  974. //先查,查不到再去生成上传
  975. item, err := models.GetYbPcSunCode(req.CodeScene, req.CodePage)
  976. if err != nil && err.Error() != utils.ErrNoRow() {
  977. br.Msg = "查询太阳码失败!"
  978. br.ErrMsg = "查询太阳码失败,Err:" + err.Error()
  979. return
  980. }
  981. if item != nil {
  982. sunCodeUrl = item.SuncodeUrl
  983. }
  984. if sunCodeUrl == "" {
  985. sunCodeUrl, err = services.PcCreateAndUploadSunCode(req.CodeScene, req.CodePage)
  986. if err != nil {
  987. br.Msg = "生成太阳码失败!"
  988. br.ErrMsg = "生成太阳码失败,Err:" + err.Error()
  989. return
  990. }
  991. }
  992. br.Data = sunCodeUrl
  993. br.Ret = 200
  994. br.Success = true
  995. br.Msg = "操作成功"
  996. }