report_chapter.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  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. err, errMsg := services.DelChapter(reportInfo, reportChapterInfo, sysUser)
  379. if err != nil {
  380. br.Msg = "删除失败"
  381. if errMsg != "" {
  382. br.Msg = errMsg
  383. }
  384. br.ErrMsg = "删除失败,Err:" + err.Error()
  385. return
  386. }
  387. // 备份关键数据
  388. chapters := make([]*models.ReportChapter, 0)
  389. chapters = append(chapters, reportChapterInfo)
  390. go services.SaveReportLogs(nil, chapters, sysUser.AdminId, sysUser.RealName)
  391. br.Ret = 200
  392. br.Success = true
  393. br.Msg = "删除成功"
  394. }
  395. // EditChapterBaseInfoAndPermission
  396. // @Title 修改报告章节的基础信息、授权用户权限、品种权限
  397. // @Description 修改报告章节的基础信息、授权用户权限、品种权限
  398. // @Param request body models.EditReportChapterReq true "type json string"
  399. // @Success 200 Ret=200 保存成功
  400. // @router /chapter/base_info/edit [post]
  401. func (this *ReportController) EditChapterBaseInfoAndPermission() {
  402. br := new(models.BaseResponse).Init()
  403. defer func() {
  404. this.Data["json"] = br
  405. this.ServeJSON()
  406. }()
  407. sysUser := this.SysUser
  408. if sysUser == nil {
  409. br.Msg = "请登录"
  410. br.ErrMsg = "请登录,SysUser Is Empty"
  411. br.Ret = 408
  412. return
  413. }
  414. var req models.EditReportChapterBaseInfoAndPermissionReq
  415. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  416. if err != nil {
  417. br.Msg = "参数解析异常!"
  418. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  419. return
  420. }
  421. reportChapterId := req.ReportChapterId
  422. if reportChapterId <= 0 {
  423. br.Msg = "报告章节ID有误"
  424. return
  425. }
  426. // 获取章节详情
  427. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  428. if err != nil {
  429. br.Msg = "报告章节信息有误"
  430. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  431. return
  432. }
  433. // 获取报告详情
  434. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  435. if err != nil {
  436. br.Msg = "报告信息有误"
  437. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  438. return
  439. }
  440. if reportInfo.State == 2 {
  441. br.Msg = "该报告已发布,不允许编辑"
  442. br.ErrMsg = "该报告已发布,不允许编辑"
  443. return
  444. }
  445. err, errMsg := services.EditChapterBaseInfoAndPermission(reportInfo, reportChapterInfo, req.Title, req.PermissionIdList, req.AdminIdList)
  446. if err != nil {
  447. br.Msg = "保存失败"
  448. if errMsg != "" {
  449. br.Msg = errMsg
  450. }
  451. br.ErrMsg = "保存失败,Err:" + err.Error()
  452. return
  453. }
  454. br.Ret = 200
  455. br.Success = true
  456. br.Msg = "保存成功"
  457. }
  458. // GetReportChapterList
  459. // @Title 获取报告章节列表
  460. // @Description 获取报告章节列表
  461. // @Param ReportId query string true "报告ID"
  462. // @Success 200 {object} company.CompanyListResp
  463. // @router /getReportChapterList [get]
  464. func (this *ReportController) GetReportChapterList() {
  465. // TODO 授权用户校验
  466. br := new(models.BaseResponse).Init()
  467. defer func() {
  468. this.Data["json"] = br
  469. this.ServeJSON()
  470. }()
  471. sysUser := this.SysUser
  472. if sysUser == nil {
  473. br.Msg = "请登录"
  474. br.ErrMsg = "请登录,SysUser Is Empty"
  475. br.Ret = 408
  476. return
  477. }
  478. reqReportId := this.GetString("ReportId")
  479. reportId, _ := strconv.Atoi(reqReportId)
  480. if reportId <= 0 {
  481. br.Msg = "报告ID有误"
  482. return
  483. }
  484. // 获取章节列表
  485. chapterList, err := models.GetChapterListByReportId(reportId)
  486. if err != nil {
  487. br.Msg = "获取章节列表失败"
  488. br.ErrMsg = "获取章节列表失败, Err: " + err.Error()
  489. return
  490. }
  491. typeList, err := models.GetReportChapterTypeList()
  492. if err != nil {
  493. br.Msg = "获取章节类型列表失败"
  494. br.ErrMsg = "获取章节类型列表失败, Err: " + err.Error()
  495. return
  496. }
  497. typeIdImg := make(map[int]string)
  498. for i := 0; i < len(typeList); i++ {
  499. typeIdImg[typeList[i].ReportChapterTypeId] = typeList[i].EditImgUrl
  500. }
  501. resp := make([]models.ReportChapterResp, 0)
  502. if len(chapterList) > 0 {
  503. chapterIdList := make([]int, 0)
  504. // 章节id授权用户列表map
  505. chapterIdGrandListMap := make(map[int][]int)
  506. // 章节id关联品种id列表map
  507. chapterIdPermissionListMap := make(map[int][]int)
  508. for _, v := range chapterList {
  509. chapterIdList = append(chapterIdList, v.ReportChapterId)
  510. }
  511. // 处理章节id授权用户列表
  512. {
  513. chapterGrantObj := report.ReportChapterGrant{}
  514. chapterGrantList, tmpErr := chapterGrantObj.GetGrantListByIdList(chapterIdList)
  515. if tmpErr != nil {
  516. br.Msg = "获取章节id授权用户列表失败"
  517. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  518. return
  519. }
  520. for _, v := range chapterGrantList {
  521. tmpChapterIdGrandList, ok := chapterIdGrandListMap[v.ReportChapterId]
  522. if !ok {
  523. tmpChapterIdGrandList = make([]int, 0)
  524. }
  525. chapterIdGrandListMap[v.ReportChapterId] = append(tmpChapterIdGrandList, v.AdminId)
  526. }
  527. }
  528. // 处理章节id关联品种id列表
  529. {
  530. obj := report.ReportChapterPermissionMapping{}
  531. chapterPermissionList, tmpErr := obj.GetPermissionListByIdList(chapterIdList)
  532. if tmpErr != nil {
  533. br.Msg = "获取章节id关联品种列表失败"
  534. br.ErrMsg = "获取章节id关联品种列表失败, Err: " + tmpErr.Error()
  535. return
  536. }
  537. for _, v := range chapterPermissionList {
  538. tmpChapterIdPermissionList, ok := chapterIdPermissionListMap[v.ReportChapterId]
  539. if !ok {
  540. tmpChapterIdPermissionList = make([]int, 0)
  541. }
  542. chapterIdPermissionListMap[v.ReportChapterId] = append(tmpChapterIdPermissionList, v.ChartPermissionId)
  543. }
  544. }
  545. // TODO 获取更新规则
  546. researchType := chapterList[0].ReportType
  547. chapterTypeList, tmpErr := models.GetAllReportChapterTypeListByResearchType(researchType)
  548. if tmpErr != nil {
  549. br.Msg = "获取更新规则失败"
  550. br.ErrMsg = "获取更新规则失败, Err: " + tmpErr.Error()
  551. return
  552. }
  553. // 调整章节更新
  554. nowTime := time.Now().Local()
  555. for _, item := range chapterList {
  556. stop := false
  557. for _, rule := range chapterTypeList {
  558. if rule.ReportChapterTypeId == item.TypeId {
  559. //fmt.Println("rule.Enabled :", rule.Enabled, ";name=", rule.ReportChapterTypeName, "item.IsEdit:", item.IsEdit, "rule.IsSet:", rule.IsSet)
  560. // 如果被永久暂停更新了
  561. if rule.Enabled == 0 && item.IsEdit == 0 { //该章节已被永久禁用,同时未被操作过
  562. stop = true
  563. } else if rule.PauseStartTime != "" && rule.PauseEndTime != "" && rule.PauseStartTime != utils.EmptyDateStr && rule.PauseEndTime != utils.EmptyDateStr {
  564. startTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseStartTime, time.Local)
  565. if timeErr != nil {
  566. br.Msg = "获取更新规则失败"
  567. br.ErrMsg = "更新规则时间转换失败4001, Err: " + timeErr.Error()
  568. return
  569. }
  570. endTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseEndTime, time.Local)
  571. if timeErr != nil {
  572. br.Msg = "获取更新规则失败"
  573. br.ErrMsg = "更新规则时间转换失败4002, Err: " + timeErr.Error()
  574. return
  575. }
  576. // 暂停更新
  577. if nowTime.After(startTime) && nowTime.Before(endTime.AddDate(0, 0, 1)) {
  578. stop = true
  579. }
  580. break
  581. }
  582. }
  583. }
  584. if !stop {
  585. // 授权的用户列表
  586. tmpChapterIdGrandList, ok := chapterIdGrandListMap[item.ReportChapterId]
  587. if !ok {
  588. tmpChapterIdGrandList = make([]int, 0)
  589. }
  590. // 关联的品种列表
  591. tmpChapterIdPermissionList, ok := chapterIdPermissionListMap[item.ReportChapterId]
  592. if !ok {
  593. tmpChapterIdPermissionList = make([]int, 0)
  594. }
  595. tmpChapterItem := models.ReportChapterResp{
  596. ReportChapterId: item.ReportChapterId,
  597. ReportId: item.ReportId,
  598. ReportType: item.ReportType,
  599. TypeId: item.TypeId,
  600. TypeName: item.TypeName,
  601. TypeEditImg: typeIdImg[item.TypeId],
  602. Title: item.Title,
  603. IsEdit: item.IsEdit,
  604. Trend: item.Trend,
  605. Sort: item.Sort,
  606. PublishState: item.PublishState,
  607. VideoUrl: item.VideoUrl,
  608. VideoName: item.VideoName,
  609. VideoPlaySeconds: item.VideoPlaySeconds,
  610. VideoSize: item.VideoSize,
  611. VideoKind: item.VideoKind,
  612. ModifyTime: item.ModifyTime.Format(utils.FormatDate),
  613. GrandAdminIdList: tmpChapterIdGrandList,
  614. PermissionIdList: tmpChapterIdPermissionList,
  615. }
  616. markStatus, err := services.UpdateReportEditMark(item.ReportId, item.ReportChapterId, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  617. if err != nil {
  618. br.Msg = "查询标记状态失败"
  619. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  620. return
  621. }
  622. if markStatus.Status == 0 {
  623. tmpChapterItem.CanEdit = true
  624. } else {
  625. tmpChapterItem.Editor = markStatus.Editor
  626. }
  627. resp = append(resp, tmpChapterItem)
  628. }
  629. }
  630. }
  631. br.Ret = 200
  632. br.Success = true
  633. br.Msg = "获取成功"
  634. br.Data = resp
  635. }
  636. // GetDayWeekChapter
  637. // @Title 获取晨周报章节信息
  638. // @Description 获取晨周报章节信息
  639. // @Param ReportChapterId query int true "报告章节ID"
  640. // @Success 200 Ret=200 保存成功
  641. // @router /getDayWeekChapter [get]
  642. func (this *ReportController) GetDayWeekChapter() {
  643. // TODO 授权用户校验
  644. br := new(models.BaseResponse).Init()
  645. defer func() {
  646. this.Data["json"] = br
  647. this.ServeJSON()
  648. }()
  649. sysUser := this.SysUser
  650. if sysUser == nil {
  651. br.Msg = "请登录"
  652. br.ErrMsg = "请登录,SysUser Is Empty"
  653. br.Ret = 408
  654. return
  655. }
  656. reportChapterId, _ := this.GetInt("ReportChapterId")
  657. if reportChapterId <= 0 {
  658. br.Msg = "参数有误"
  659. return
  660. }
  661. chapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  662. if err != nil {
  663. br.Msg = "获取章节信息失败"
  664. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  665. return
  666. }
  667. if chapterInfo != nil {
  668. chapterInfo.Content = html.UnescapeString(chapterInfo.Content)
  669. chapterInfo.ContentSub = html.UnescapeString(chapterInfo.ContentSub)
  670. chapterInfo.ContentStruct = html.UnescapeString(chapterInfo.ContentStruct)
  671. }
  672. // 授权用户列表map
  673. chapterGrantIdList := make([]int, 0)
  674. // 关联品种id列表map
  675. chapterPermissionIdList := make([]int, 0)
  676. // 处理章节id授权用户列表
  677. {
  678. chapterGrantObj := report.ReportChapterGrant{}
  679. chapterGrantList, tmpErr := chapterGrantObj.GetGrantListById(chapterInfo.ReportChapterId)
  680. if tmpErr != nil {
  681. br.Msg = "获取章节id授权用户列表失败"
  682. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  683. return
  684. }
  685. for _, v := range chapterGrantList {
  686. chapterGrantIdList = append(chapterGrantIdList, v.AdminId)
  687. }
  688. }
  689. // 处理章节id关联品种id列表
  690. {
  691. obj := report.ReportChapterPermissionMapping{}
  692. chapterPermissionList, tmpErr := obj.GetPermissionListById(chapterInfo.ReportChapterId)
  693. if tmpErr != nil {
  694. br.Msg = "获取章节id关联品种列表失败"
  695. br.ErrMsg = "获取章节id关联品种列表失败, Err: " + tmpErr.Error()
  696. return
  697. }
  698. for _, v := range chapterPermissionList {
  699. chapterPermissionIdList = append(chapterPermissionIdList, v.ChartPermissionId)
  700. }
  701. }
  702. resp := models.ReportChapterItem{
  703. ReportChapter: *chapterInfo,
  704. GrandAdminIdList: chapterGrantIdList,
  705. PermissionIdList: chapterPermissionIdList,
  706. }
  707. // 获取当前编辑状态
  708. {
  709. markStatus, err := services.UpdateReportEditMark(chapterInfo.ReportId, chapterInfo.ReportChapterId, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  710. if err != nil {
  711. br.Msg = "查询标记状态失败"
  712. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  713. return
  714. }
  715. if markStatus.Status == 0 {
  716. resp.CanEdit = true
  717. } else {
  718. resp.Editor = markStatus.Editor
  719. }
  720. }
  721. br.Ret = 200
  722. br.Success = true
  723. br.Msg = "获取成功"
  724. br.Data = resp
  725. }
  726. // ChapterMove
  727. // @Title 移动章节类型
  728. // @Description 移动章节类型
  729. // @Param request body models.PermissionMoveReq true "type json string"
  730. // @Success 200 Ret=200 操作成功
  731. // @router /chapter/move [post]
  732. func (this *ReportController) ChapterMove() {
  733. br := new(models.BaseResponse).Init()
  734. defer func() {
  735. if br.ErrMsg == "" {
  736. br.IsSendEmail = false
  737. }
  738. this.Data["json"] = br
  739. this.ServeJSON()
  740. }()
  741. sysUser := this.SysUser
  742. if sysUser == nil {
  743. br.Msg = "请登录"
  744. br.ErrMsg = "请登录,SysUser Is Empty"
  745. br.Ret = 408
  746. return
  747. }
  748. var req models.ReportChapterMoveReq
  749. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  750. br.Msg = "参数解析异常!"
  751. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  752. return
  753. }
  754. if req.ReportChapterId == 0 {
  755. br.Msg = "请选择要移动的章节"
  756. return
  757. }
  758. e, msg := services.MoveReportChapter(&req)
  759. if e != nil {
  760. br.Msg = msg
  761. br.ErrMsg = "移动品种失败, Err: " + e.Error()
  762. return
  763. }
  764. br.Ret = 200
  765. br.Success = true
  766. br.Msg = "操作成功"
  767. }
  768. // EditChapterTrendTag
  769. // @Title 编辑章节趋势标签
  770. // @Description 编辑章节趋势标签
  771. // @Param request body models.EditReportChapterReq true "type json string"
  772. // @Success 200 Ret=200 保存成功
  773. // @router /editChapterTrendTag [post]
  774. func (this *ReportController) EditChapterTrendTag() {
  775. br := new(models.BaseResponse).Init()
  776. defer func() {
  777. this.Data["json"] = br
  778. this.ServeJSON()
  779. }()
  780. sysUser := this.SysUser
  781. if sysUser == nil {
  782. br.Msg = "请登录"
  783. br.ErrMsg = "请登录,SysUser Is Empty"
  784. br.Ret = 408
  785. return
  786. }
  787. var req models.EditChapterTrendTagReq
  788. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  789. if err != nil {
  790. br.Msg = "参数解析异常!"
  791. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  792. return
  793. }
  794. if req.ReportChapterId <= 0 {
  795. br.Msg = "章节ID有误"
  796. return
  797. }
  798. if req.Trend == "" {
  799. br.Msg = "请输入标签"
  800. return
  801. }
  802. chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
  803. if err != nil {
  804. br.Msg = "获取章节信息失败"
  805. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  806. return
  807. }
  808. // 获取报告详情
  809. reportInfo, err := models.GetReportByReportId(chapterInfo.ReportId)
  810. if err != nil {
  811. br.Msg = "报告信息有误"
  812. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  813. return
  814. }
  815. // 操作权限校验
  816. {
  817. // 如果不是创建人,那么就要去查看是否授权
  818. if reportInfo.AdminId != sysUser.AdminId {
  819. // 授权用户权限校验
  820. chapterGrantObj := report.ReportChapterGrant{}
  821. _, tmpErr := chapterGrantObj.GetGrantByIdAndAdmin(chapterInfo.ReportChapterId, sysUser.AdminId)
  822. if tmpErr != nil {
  823. if tmpErr.Error() == utils.ErrNoRow() {
  824. br.Msg = "没有权限"
  825. br.ErrMsg = "没有权限"
  826. br.IsSendEmail = false
  827. return
  828. }
  829. br.Msg = "获取章节id授权用户失败"
  830. br.ErrMsg = "获取章节id授权用户失败, Err: " + tmpErr.Error()
  831. return
  832. }
  833. }
  834. }
  835. // 更新章节标签
  836. chapterInfo.Trend = req.Trend
  837. updateCols := make([]string, 0)
  838. updateCols = append(updateCols, "Trend")
  839. if err = chapterInfo.UpdateChapter(updateCols); err != nil {
  840. br.Msg = "更新标签失败"
  841. br.ErrMsg = "更新标签失败, Err: " + err.Error()
  842. return
  843. }
  844. // 添加关键词
  845. if err = models.AddTrendTagKeyWord(req.Trend); err != nil {
  846. br.Msg = "添加标签关键词失败"
  847. br.ErrMsg = "添加标签关键词失败, Err: " + err.Error()
  848. return
  849. }
  850. br.Ret = 200
  851. br.Success = true
  852. br.Msg = "保存成功"
  853. }
  854. // GetSunCode 获取太阳码
  855. // @Title 公共模块
  856. // @Description 获取分享海报
  857. // @Param request body models.SunCodeReq true "type json string"
  858. // @Success 200 {object} string "获取成功"
  859. // @failure 400 {string} string "获取失败"
  860. // @router /getSunCode [post]
  861. func (this *ReportController) GetSunCode() {
  862. br := new(models.BaseResponse).Init()
  863. defer func() {
  864. this.Data["json"] = br
  865. this.ServeJSON()
  866. }()
  867. sysUser := this.SysUser
  868. if sysUser == nil {
  869. br.Msg = "请登录"
  870. br.ErrMsg = "请登录,SysUser Is Empty"
  871. br.Ret = 408
  872. return
  873. }
  874. var req models.SunCodeReq
  875. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  876. if err != nil {
  877. br.Msg = "参数解析异常!"
  878. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  879. return
  880. }
  881. var sunCodeUrl string
  882. //先查,查不到再去生成上传
  883. item, err := models.GetYbPcSunCode(req.CodeScene, req.CodePage)
  884. if err != nil && err.Error() != utils.ErrNoRow() {
  885. br.Msg = "查询太阳码失败!"
  886. br.ErrMsg = "查询太阳码失败,Err:" + err.Error()
  887. return
  888. }
  889. if item != nil {
  890. sunCodeUrl = item.SuncodeUrl
  891. }
  892. if sunCodeUrl == "" {
  893. sunCodeUrl, err = services.PcCreateAndUploadSunCode(req.CodeScene, req.CodePage)
  894. if err != nil {
  895. br.Msg = "生成太阳码失败!"
  896. br.ErrMsg = "生成太阳码失败,Err:" + err.Error()
  897. return
  898. }
  899. }
  900. br.Data = sunCodeUrl
  901. br.Ret = 200
  902. br.Success = true
  903. br.Msg = "操作成功"
  904. }