report_chapter.go 36 KB

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