report_chapter.go 29 KB

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