report_chapter.go 29 KB

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