report_chapter.go 29 KB

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