report_chapter.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  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. // EditChapterBaseInfoAndPermission
  295. // @Title 修改报告章节的基础信息、授权用户权限、品种权限
  296. // @Description 修改报告章节的基础信息、授权用户权限、品种权限
  297. // @Param request body models.EditReportChapterReq true "type json string"
  298. // @Success 200 Ret=200 保存成功
  299. // @router /chapter/base_info/edit [post]
  300. func (this *ReportController) EditChapterBaseInfoAndPermission() {
  301. br := new(models.BaseResponse).Init()
  302. defer func() {
  303. this.Data["json"] = br
  304. this.ServeJSON()
  305. }()
  306. sysUser := this.SysUser
  307. if sysUser == nil {
  308. br.Msg = "请登录"
  309. br.ErrMsg = "请登录,SysUser Is Empty"
  310. br.Ret = 408
  311. return
  312. }
  313. var req models.EditReportChapterBaseInfoAndPermissionReq
  314. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  315. if err != nil {
  316. br.Msg = "参数解析异常!"
  317. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  318. return
  319. }
  320. reportChapterId := req.ReportChapterId
  321. if reportChapterId <= 0 {
  322. br.Msg = "报告章节ID有误"
  323. return
  324. }
  325. // 获取章节详情
  326. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  327. if err != nil {
  328. br.Msg = "报告章节信息有误"
  329. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  330. return
  331. }
  332. // 获取报告详情
  333. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  334. if err != nil {
  335. br.Msg = "报告信息有误"
  336. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  337. return
  338. }
  339. if reportInfo.State == 2 {
  340. br.Msg = "该报告已发布,不允许编辑"
  341. br.ErrMsg = "该报告已发布,不允许编辑"
  342. return
  343. }
  344. err, errMsg := services.EditChapterBaseInfoAndPermission(reportInfo, reportChapterInfo, req.Title, req.PermissionIdList, req.AdminIdList)
  345. if err != nil {
  346. br.Msg = "保存失败"
  347. if errMsg != "" {
  348. br.Msg = errMsg
  349. }
  350. br.ErrMsg = "保存失败,Err:" + err.Error()
  351. return
  352. }
  353. br.Ret = 200
  354. br.Success = true
  355. br.Msg = "保存成功"
  356. }
  357. // GetReportChapterList
  358. // @Title 获取报告章节列表
  359. // @Description 获取报告章节列表
  360. // @Param ReportId query string true "报告ID"
  361. // @Success 200 {object} company.CompanyListResp
  362. // @router /getReportChapterList [get]
  363. func (this *ReportController) GetReportChapterList() {
  364. // TODO 授权用户校验
  365. br := new(models.BaseResponse).Init()
  366. defer func() {
  367. this.Data["json"] = br
  368. this.ServeJSON()
  369. }()
  370. sysUser := this.SysUser
  371. if sysUser == nil {
  372. br.Msg = "请登录"
  373. br.ErrMsg = "请登录,SysUser Is Empty"
  374. br.Ret = 408
  375. return
  376. }
  377. reqReportId := this.GetString("ReportId")
  378. reportId, _ := strconv.Atoi(reqReportId)
  379. if reportId <= 0 {
  380. br.Msg = "报告ID有误"
  381. return
  382. }
  383. // 获取章节列表
  384. chapterList, err := models.GetChapterListByReportId(reportId)
  385. if err != nil {
  386. br.Msg = "获取章节列表失败"
  387. br.ErrMsg = "获取章节列表失败, Err: " + err.Error()
  388. return
  389. }
  390. typeList, err := models.GetReportChapterTypeList()
  391. if err != nil {
  392. br.Msg = "获取章节类型列表失败"
  393. br.ErrMsg = "获取章节类型列表失败, Err: " + err.Error()
  394. return
  395. }
  396. typeIdImg := make(map[int]string)
  397. for i := 0; i < len(typeList); i++ {
  398. typeIdImg[typeList[i].ReportChapterTypeId] = typeList[i].EditImgUrl
  399. }
  400. resp := make([]models.ReportChapterResp, 0)
  401. if len(chapterList) > 0 {
  402. chapterIdList := make([]int, 0)
  403. // 章节id授权用户列表map
  404. chapterIdGrandListMap := make(map[int][]int)
  405. // 章节id关联品种id列表map
  406. chapterIdPermissionListMap := make(map[int][]int)
  407. for _, v := range chapterList {
  408. chapterIdList = append(chapterIdList, v.ReportChapterId)
  409. }
  410. // 处理章节id授权用户列表
  411. {
  412. chapterGrantObj := report.ReportChapterGrant{}
  413. chapterGrantList, tmpErr := chapterGrantObj.GetGrantListByIdList(chapterIdList)
  414. if tmpErr != nil {
  415. br.Msg = "获取章节id授权用户列表失败"
  416. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  417. return
  418. }
  419. for _, v := range chapterGrantList {
  420. tmpChapterIdGrandList, ok := chapterIdGrandListMap[v.ReportChapterId]
  421. if !ok {
  422. tmpChapterIdGrandList = make([]int, 0)
  423. }
  424. chapterIdGrandListMap[v.ReportChapterId] = append(tmpChapterIdGrandList, v.AdminId)
  425. }
  426. }
  427. // 处理章节id关联品种id列表
  428. {
  429. obj := report.ReportChapterPermissionMapping{}
  430. chapterPermissionList, tmpErr := obj.GetPermissionListByIdList(chapterIdList)
  431. if tmpErr != nil {
  432. br.Msg = "获取章节id关联品种列表失败"
  433. br.ErrMsg = "获取章节id关联品种列表失败, Err: " + tmpErr.Error()
  434. return
  435. }
  436. for _, v := range chapterPermissionList {
  437. tmpChapterIdPermissionList, ok := chapterIdPermissionListMap[v.ReportChapterId]
  438. if !ok {
  439. tmpChapterIdPermissionList = make([]int, 0)
  440. }
  441. chapterIdPermissionListMap[v.ReportChapterId] = append(tmpChapterIdPermissionList, v.ChartPermissionId)
  442. }
  443. }
  444. // TODO 获取更新规则
  445. researchType := chapterList[0].ReportType
  446. chapterTypeList, tmpErr := models.GetAllReportChapterTypeListByResearchType(researchType)
  447. if tmpErr != nil {
  448. br.Msg = "获取更新规则失败"
  449. br.ErrMsg = "获取更新规则失败, Err: " + tmpErr.Error()
  450. return
  451. }
  452. // 调整章节更新
  453. nowTime := time.Now().Local()
  454. for _, item := range chapterList {
  455. stop := false
  456. for _, rule := range chapterTypeList {
  457. if rule.ReportChapterTypeId == item.TypeId {
  458. //fmt.Println("rule.Enabled :", rule.Enabled, ";name=", rule.ReportChapterTypeName, "item.IsEdit:", item.IsEdit, "rule.IsSet:", rule.IsSet)
  459. // 如果被永久暂停更新了
  460. if rule.Enabled == 0 && item.IsEdit == 0 { //该章节已被永久禁用,同时未被操作过
  461. stop = true
  462. } else if rule.PauseStartTime != "" && rule.PauseEndTime != "" && rule.PauseStartTime != utils.EmptyDateStr && rule.PauseEndTime != utils.EmptyDateStr {
  463. startTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseStartTime, time.Local)
  464. if timeErr != nil {
  465. br.Msg = "获取更新规则失败"
  466. br.ErrMsg = "更新规则时间转换失败4001, Err: " + timeErr.Error()
  467. return
  468. }
  469. endTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseEndTime, time.Local)
  470. if timeErr != nil {
  471. br.Msg = "获取更新规则失败"
  472. br.ErrMsg = "更新规则时间转换失败4002, Err: " + timeErr.Error()
  473. return
  474. }
  475. // 暂停更新
  476. if nowTime.After(startTime) && nowTime.Before(endTime.AddDate(0, 0, 1)) {
  477. stop = true
  478. }
  479. break
  480. }
  481. }
  482. }
  483. if !stop {
  484. // 授权的用户列表
  485. tmpChapterIdGrandList, ok := chapterIdGrandListMap[item.ReportChapterId]
  486. if !ok {
  487. tmpChapterIdGrandList = make([]int, 0)
  488. }
  489. // 关联的品种列表
  490. tmpChapterIdPermissionList, ok := chapterIdPermissionListMap[item.ReportChapterId]
  491. if !ok {
  492. tmpChapterIdPermissionList = make([]int, 0)
  493. }
  494. tmpChapterItem := models.ReportChapterResp{
  495. ReportChapterId: item.ReportChapterId,
  496. ReportId: item.ReportId,
  497. ReportType: item.ReportType,
  498. TypeId: item.TypeId,
  499. TypeName: item.TypeName,
  500. TypeEditImg: typeIdImg[item.TypeId],
  501. Title: item.Title,
  502. IsEdit: item.IsEdit,
  503. Trend: item.Trend,
  504. Sort: item.Sort,
  505. PublishState: item.PublishState,
  506. VideoUrl: item.VideoUrl,
  507. VideoName: item.VideoName,
  508. VideoPlaySeconds: item.VideoPlaySeconds,
  509. VideoSize: item.VideoSize,
  510. VideoKind: item.VideoKind,
  511. ModifyTime: item.ModifyTime.Format(utils.FormatDate),
  512. GrandAdminIdList: tmpChapterIdGrandList,
  513. PermissionIdList: tmpChapterIdPermissionList,
  514. }
  515. markStatus, err := services.UpdateReportEditMark(item.ReportId, item.ReportChapterId, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  516. if err != nil {
  517. br.Msg = "查询标记状态失败"
  518. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  519. return
  520. }
  521. if markStatus.Status == 0 {
  522. tmpChapterItem.CanEdit = true
  523. } else {
  524. tmpChapterItem.Editor = markStatus.Editor
  525. }
  526. resp = append(resp, tmpChapterItem)
  527. }
  528. }
  529. }
  530. br.Ret = 200
  531. br.Success = true
  532. br.Msg = "获取成功"
  533. br.Data = resp
  534. }
  535. // GetDayWeekChapter
  536. // @Title 获取晨周报章节信息
  537. // @Description 获取晨周报章节信息
  538. // @Param ReportChapterId query int true "报告章节ID"
  539. // @Success 200 Ret=200 保存成功
  540. // @router /getDayWeekChapter [get]
  541. func (this *ReportController) GetDayWeekChapter() {
  542. // TODO 授权用户校验
  543. br := new(models.BaseResponse).Init()
  544. defer func() {
  545. this.Data["json"] = br
  546. this.ServeJSON()
  547. }()
  548. sysUser := this.SysUser
  549. if sysUser == nil {
  550. br.Msg = "请登录"
  551. br.ErrMsg = "请登录,SysUser Is Empty"
  552. br.Ret = 408
  553. return
  554. }
  555. reportChapterId, _ := this.GetInt("ReportChapterId")
  556. if reportChapterId <= 0 {
  557. br.Msg = "参数有误"
  558. return
  559. }
  560. chapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  561. if err != nil {
  562. br.Msg = "获取章节信息失败"
  563. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  564. return
  565. }
  566. if chapterInfo != nil {
  567. chapterInfo.Content = html.UnescapeString(chapterInfo.Content)
  568. chapterInfo.ContentSub = html.UnescapeString(chapterInfo.ContentSub)
  569. chapterInfo.ContentStruct = html.UnescapeString(chapterInfo.ContentStruct)
  570. }
  571. // 授权用户列表map
  572. chapterGrantIdList := make([]int, 0)
  573. // 关联品种id列表map
  574. chapterPermissionIdList := make([]int, 0)
  575. // 处理章节id授权用户列表
  576. {
  577. chapterGrantObj := report.ReportChapterGrant{}
  578. chapterGrantList, tmpErr := chapterGrantObj.GetGrantListById(chapterInfo.ReportChapterId)
  579. if tmpErr != nil {
  580. br.Msg = "获取章节id授权用户列表失败"
  581. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  582. return
  583. }
  584. for _, v := range chapterGrantList {
  585. chapterGrantIdList = append(chapterGrantIdList, v.AdminId)
  586. }
  587. }
  588. // 处理章节id关联品种id列表
  589. {
  590. obj := report.ReportChapterPermissionMapping{}
  591. chapterPermissionList, tmpErr := obj.GetPermissionListById(chapterInfo.ReportChapterId)
  592. if tmpErr != nil {
  593. br.Msg = "获取章节id关联品种列表失败"
  594. br.ErrMsg = "获取章节id关联品种列表失败, Err: " + tmpErr.Error()
  595. return
  596. }
  597. for _, v := range chapterPermissionList {
  598. chapterPermissionIdList = append(chapterPermissionIdList, v.ChartPermissionId)
  599. }
  600. }
  601. resp := models.ReportChapterItem{
  602. ReportChapter: *chapterInfo,
  603. GrandAdminIdList: chapterGrantIdList,
  604. PermissionIdList: chapterPermissionIdList,
  605. }
  606. // 获取当前编辑状态
  607. {
  608. markStatus, err := services.UpdateReportEditMark(chapterInfo.ReportId, chapterInfo.ReportChapterId, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  609. if err != nil {
  610. br.Msg = "查询标记状态失败"
  611. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  612. return
  613. }
  614. if markStatus.Status == 0 {
  615. resp.CanEdit = true
  616. } else {
  617. resp.Editor = markStatus.Editor
  618. }
  619. }
  620. br.Ret = 200
  621. br.Success = true
  622. br.Msg = "获取成功"
  623. br.Data = resp
  624. }
  625. // ChapterMove
  626. // @Title 移动章节类型
  627. // @Description 移动章节类型
  628. // @Param request body models.PermissionMoveReq true "type json string"
  629. // @Success 200 Ret=200 操作成功
  630. // @router /chapter/move [post]
  631. func (this *ReportController) ChapterMove() {
  632. br := new(models.BaseResponse).Init()
  633. defer func() {
  634. if br.ErrMsg == "" {
  635. br.IsSendEmail = false
  636. }
  637. this.Data["json"] = br
  638. this.ServeJSON()
  639. }()
  640. sysUser := this.SysUser
  641. if sysUser == nil {
  642. br.Msg = "请登录"
  643. br.ErrMsg = "请登录,SysUser Is Empty"
  644. br.Ret = 408
  645. return
  646. }
  647. var req models.ReportChapterMoveReq
  648. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  649. br.Msg = "参数解析异常!"
  650. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  651. return
  652. }
  653. if req.ReportChapterId == 0 {
  654. br.Msg = "请选择要移动的章节"
  655. return
  656. }
  657. e, msg := services.MoveReportChapter(&req)
  658. if e != nil {
  659. br.Msg = msg
  660. br.ErrMsg = "移动品种失败, Err: " + e.Error()
  661. return
  662. }
  663. br.Ret = 200
  664. br.Success = true
  665. br.Msg = "操作成功"
  666. }
  667. // EditChapterTrendTag
  668. // @Title 编辑章节趋势标签
  669. // @Description 编辑章节趋势标签
  670. // @Param request body models.EditReportChapterReq true "type json string"
  671. // @Success 200 Ret=200 保存成功
  672. // @router /editChapterTrendTag [post]
  673. func (this *ReportController) EditChapterTrendTag() {
  674. br := new(models.BaseResponse).Init()
  675. defer func() {
  676. this.Data["json"] = br
  677. this.ServeJSON()
  678. }()
  679. sysUser := this.SysUser
  680. if sysUser == nil {
  681. br.Msg = "请登录"
  682. br.ErrMsg = "请登录,SysUser Is Empty"
  683. br.Ret = 408
  684. return
  685. }
  686. var req models.EditChapterTrendTagReq
  687. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  688. if err != nil {
  689. br.Msg = "参数解析异常!"
  690. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  691. return
  692. }
  693. if req.ReportChapterId <= 0 {
  694. br.Msg = "章节ID有误"
  695. return
  696. }
  697. if req.Trend == "" {
  698. br.Msg = "请输入标签"
  699. return
  700. }
  701. chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
  702. if err != nil {
  703. br.Msg = "获取章节信息失败"
  704. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  705. return
  706. }
  707. // 更新章节标签
  708. chapterInfo.Trend = req.Trend
  709. updateCols := make([]string, 0)
  710. updateCols = append(updateCols, "Trend")
  711. if err = chapterInfo.UpdateChapter(updateCols); err != nil {
  712. br.Msg = "更新标签失败"
  713. br.ErrMsg = "更新标签失败, Err: " + err.Error()
  714. return
  715. }
  716. // 添加关键词
  717. if err = models.AddTrendTagKeyWord(req.Trend); err != nil {
  718. br.Msg = "添加标签关键词失败"
  719. br.ErrMsg = "添加标签关键词失败, Err: " + err.Error()
  720. return
  721. }
  722. br.Ret = 200
  723. br.Success = true
  724. br.Msg = "保存成功"
  725. }
  726. // GetSunCode 获取太阳码
  727. // @Title 公共模块
  728. // @Description 获取分享海报
  729. // @Param request body models.SunCodeReq true "type json string"
  730. // @Success 200 {object} string "获取成功"
  731. // @failure 400 {string} string "获取失败"
  732. // @router /getSunCode [post]
  733. func (this *ReportController) GetSunCode() {
  734. br := new(models.BaseResponse).Init()
  735. defer func() {
  736. this.Data["json"] = br
  737. this.ServeJSON()
  738. }()
  739. sysUser := this.SysUser
  740. if sysUser == nil {
  741. br.Msg = "请登录"
  742. br.ErrMsg = "请登录,SysUser Is Empty"
  743. br.Ret = 408
  744. return
  745. }
  746. var req models.SunCodeReq
  747. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  748. if err != nil {
  749. br.Msg = "参数解析异常!"
  750. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  751. return
  752. }
  753. var sunCodeUrl string
  754. //先查,查不到再去生成上传
  755. item, err := models.GetYbPcSunCode(req.CodeScene, req.CodePage)
  756. if err != nil && err.Error() != utils.ErrNoRow() {
  757. br.Msg = "查询太阳码失败!"
  758. br.ErrMsg = "查询太阳码失败,Err:" + err.Error()
  759. return
  760. }
  761. if item != nil {
  762. sunCodeUrl = item.SuncodeUrl
  763. }
  764. if sunCodeUrl == "" {
  765. sunCodeUrl, err = services.PcCreateAndUploadSunCode(req.CodeScene, req.CodePage)
  766. if err != nil {
  767. br.Msg = "生成太阳码失败!"
  768. br.ErrMsg = "生成太阳码失败,Err:" + err.Error()
  769. return
  770. }
  771. }
  772. br.Data = sunCodeUrl
  773. br.Ret = 200
  774. br.Success = true
  775. br.Msg = "操作成功"
  776. }