report_chapter.go 34 KB

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