report_chapter.go 28 KB

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