report_chapter.go 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  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/services/data"
  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 = 2
  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.LastModifyAdminId = sysUser.AdminId
  308. reportChapterInfo.LastModifyAdminName = sysUser.RealName
  309. reportChapterInfo.ContentModifyTime = time.Now()
  310. reportChapterInfo.ContentStruct = html.EscapeString(req.ContentStruct)
  311. updateCols := make([]string, 0)
  312. updateCols = append(updateCols, "Title", "AddType", "Author", "Content", "ContentSub", "IsEdit", "CreateTime")
  313. updateCols = append(updateCols, "LastModifyAdminId", "LastModifyAdminName", "ContentModifyTime", "ContentStruct")
  314. // 章节报告更新指标
  315. tickerList := make([]*models.ReportChapterTicker, 0)
  316. if len(reqTickerList) > 0 {
  317. nowTime := time.Now()
  318. for i := 0; i < len(reqTickerList); i++ {
  319. tickerList = append(tickerList, &models.ReportChapterTicker{
  320. ReportChapterId: reportChapterInfo.ReportChapterId,
  321. Sort: reqTickerList[i].Sort,
  322. Ticker: reqTickerList[i].Ticker,
  323. CreateTime: nowTime,
  324. UpdateTime: nowTime,
  325. })
  326. }
  327. }
  328. err = models.UpdateChapterAndTicker(reportChapterInfo, updateCols, tickerList)
  329. if err != nil {
  330. br.Msg = "保存失败"
  331. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  332. return
  333. }
  334. // 标记更新中
  335. {
  336. markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  337. if err != nil {
  338. br.Msg = err.Error()
  339. return
  340. }
  341. if markStatus.Status == 1 {
  342. br.Msg = markStatus.Msg
  343. return
  344. }
  345. }
  346. // 备份关键数据
  347. chapters := make([]*models.ReportChapter, 0)
  348. chapters = append(chapters, reportChapterInfo)
  349. go services.SaveReportLogs(nil, chapters, sysUser.AdminId, sysUser.RealName)
  350. br.Ret = 200
  351. br.Success = true
  352. br.Msg = "保存成功"
  353. }
  354. // DelChapter
  355. // @Title 编辑晨周报章节内容
  356. // @Description 编辑晨周报章节内容
  357. // @Param request body models.EditReportChapterReq true "type json string"
  358. // @Success 200 Ret=200 保存成功
  359. // @router /chapter/del [post]
  360. func (this *ReportController) DelChapter() {
  361. br := new(models.BaseResponse).Init()
  362. defer func() {
  363. this.Data["json"] = br
  364. this.ServeJSON()
  365. }()
  366. sysUser := this.SysUser
  367. if sysUser == nil {
  368. br.Msg = "请登录"
  369. br.ErrMsg = "请登录,SysUser Is Empty"
  370. br.Ret = 408
  371. return
  372. }
  373. var req models.DelReportChapterReq
  374. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  375. if err != nil {
  376. br.Msg = "参数解析异常!"
  377. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  378. return
  379. }
  380. reportChapterId := req.ReportChapterId
  381. if reportChapterId <= 0 {
  382. br.Msg = "报告章节ID有误"
  383. return
  384. }
  385. // 获取章节详情
  386. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  387. if err != nil {
  388. br.Msg = "报告章节信息有误"
  389. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  390. return
  391. }
  392. // 获取报告详情
  393. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  394. if err != nil {
  395. br.Msg = "报告信息有误"
  396. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  397. return
  398. }
  399. // 操作权限校验
  400. {
  401. // 如果不是创建人,那么就要去查看是否授权
  402. if reportInfo.AdminId != sysUser.AdminId {
  403. // 授权用户权限校验
  404. chapterGrantObj := report.ReportChapterGrant{}
  405. _, tmpErr := chapterGrantObj.GetGrantByIdAndAdmin(reportChapterInfo.ReportChapterId, sysUser.AdminId)
  406. if tmpErr != nil {
  407. if tmpErr.Error() == utils.ErrNoRow() {
  408. br.Msg = "没有权限"
  409. br.ErrMsg = "没有权限"
  410. br.IsSendEmail = false
  411. return
  412. }
  413. br.Msg = "获取章节id授权用户失败"
  414. br.ErrMsg = "获取章节id授权用户失败, Err: " + tmpErr.Error()
  415. return
  416. }
  417. }
  418. // 标记更新中
  419. {
  420. markStatus, err := services.UpdateReportEditMark(reportChapterInfo.ReportId, reportChapterInfo.ReportChapterId, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  421. if err != nil {
  422. br.Msg = err.Error()
  423. return
  424. }
  425. if markStatus.Status == 1 {
  426. br.Msg = markStatus.Msg
  427. br.IsSendEmail = false
  428. return
  429. }
  430. }
  431. }
  432. if reportInfo.State == 2 {
  433. br.Msg = "该报告已发布,不允许编辑"
  434. br.ErrMsg = "该报告已发布,不允许编辑"
  435. return
  436. }
  437. // 删除章节
  438. err, errMsg := services.DelChapter(reportInfo, reportChapterInfo, sysUser)
  439. if err != nil {
  440. br.Msg = "删除失败"
  441. if errMsg != "" {
  442. br.Msg = errMsg
  443. }
  444. br.ErrMsg = "删除失败,Err:" + err.Error()
  445. return
  446. }
  447. // 备份关键数据
  448. chapters := make([]*models.ReportChapter, 0)
  449. chapters = append(chapters, reportChapterInfo)
  450. go services.SaveReportLogs(nil, chapters, sysUser.AdminId, sysUser.RealName)
  451. br.Ret = 200
  452. br.Success = true
  453. br.Msg = "删除成功"
  454. }
  455. // GetReportChapterList
  456. // @Title 获取报告章节列表
  457. // @Description 获取报告章节列表
  458. // @Param ReportId query string true "报告ID"
  459. // @Success 200 {object} company.CompanyListResp
  460. // @router /getReportChapterList [get]
  461. func (this *ReportController) GetReportChapterList() {
  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. // 获取报告信息
  481. reportInfo, err := models.GetReportByReportId(reportId)
  482. if err != nil {
  483. br.Msg = "获取报告信息失败"
  484. br.ErrMsg = "获取报告信息失败, Err: " + err.Error()
  485. return
  486. }
  487. // 权限校验
  488. isAuth, err := services.CheckReportAuthByReportChapterInfo(sysUser.AdminId, reportInfo.AdminId, reportId)
  489. if err != nil {
  490. br.Msg = "获取报告权限失败"
  491. br.ErrMsg = "获取报告权限失败,Err:" + err.Error()
  492. return
  493. }
  494. if !isAuth {
  495. br.Msg = "无操作权限"
  496. br.ErrMsg = "无操作权限"
  497. return
  498. }
  499. // 获取章节列表
  500. chapterList, err := models.GetChapterListByReportId(reportId)
  501. if err != nil {
  502. br.Msg = "获取章节列表失败"
  503. br.ErrMsg = "获取章节列表失败, Err: " + err.Error()
  504. return
  505. }
  506. typeList, err := models.GetReportChapterTypeList()
  507. if err != nil {
  508. br.Msg = "获取章节类型列表失败"
  509. br.ErrMsg = "获取章节类型列表失败, Err: " + err.Error()
  510. return
  511. }
  512. typeIdImg := make(map[int]string)
  513. for i := 0; i < len(typeList); i++ {
  514. typeIdImg[typeList[i].ReportChapterTypeId] = typeList[i].EditImgUrl
  515. }
  516. resp := make([]models.ReportChapterResp, 0)
  517. if len(chapterList) > 0 {
  518. chapterIdList := make([]int, 0)
  519. // 章节id授权用户列表map
  520. chapterIdGrandListMap := make(map[int][]int)
  521. // 章节id关联品种id列表map
  522. chapterIdPermissionListMap := make(map[int][]int)
  523. for _, v := range chapterList {
  524. chapterIdList = append(chapterIdList, v.ReportChapterId)
  525. }
  526. // 处理章节id授权用户列表
  527. {
  528. chapterGrantObj := report.ReportChapterGrant{}
  529. chapterGrantList, tmpErr := chapterGrantObj.GetGrantListByIdList(chapterIdList)
  530. if tmpErr != nil {
  531. br.Msg = "获取章节id授权用户列表失败"
  532. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  533. return
  534. }
  535. for _, v := range chapterGrantList {
  536. tmpChapterIdGrandList, ok := chapterIdGrandListMap[v.ReportChapterId]
  537. if !ok {
  538. tmpChapterIdGrandList = make([]int, 0)
  539. }
  540. chapterIdGrandListMap[v.ReportChapterId] = append(tmpChapterIdGrandList, v.AdminId)
  541. }
  542. }
  543. // 处理章节id关联品种id列表
  544. {
  545. obj := report.ReportChapterPermissionMapping{}
  546. chapterPermissionList, tmpErr := obj.GetPermissionListByIdList(chapterIdList)
  547. if tmpErr != nil {
  548. br.Msg = "获取章节id关联品种列表失败"
  549. br.ErrMsg = "获取章节id关联品种列表失败, Err: " + tmpErr.Error()
  550. return
  551. }
  552. for _, v := range chapterPermissionList {
  553. tmpChapterIdPermissionList, ok := chapterIdPermissionListMap[v.ReportChapterId]
  554. if !ok {
  555. tmpChapterIdPermissionList = make([]int, 0)
  556. }
  557. chapterIdPermissionListMap[v.ReportChapterId] = append(tmpChapterIdPermissionList, v.ChartPermissionId)
  558. }
  559. }
  560. // TODO 获取更新规则
  561. researchType := chapterList[0].ReportType
  562. chapterTypeList, tmpErr := models.GetAllReportChapterTypeListByResearchType(researchType)
  563. if tmpErr != nil {
  564. br.Msg = "获取更新规则失败"
  565. br.ErrMsg = "获取更新规则失败, Err: " + tmpErr.Error()
  566. return
  567. }
  568. // 调整章节更新
  569. nowTime := time.Now().Local()
  570. for _, item := range chapterList {
  571. stop := false
  572. for _, rule := range chapterTypeList {
  573. if rule.ReportChapterTypeId == item.TypeId {
  574. //fmt.Println("rule.Enabled :", rule.Enabled, ";name=", rule.ReportChapterTypeName, "item.IsEdit:", item.IsEdit, "rule.IsSet:", rule.IsSet)
  575. // 如果被永久暂停更新了
  576. if rule.Enabled == 0 && item.IsEdit == 0 { //该章节已被永久禁用,同时未被操作过
  577. stop = true
  578. } else if rule.PauseStartTime != "" && rule.PauseEndTime != "" && rule.PauseStartTime != utils.EmptyDateStr && rule.PauseEndTime != utils.EmptyDateStr {
  579. startTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseStartTime, time.Local)
  580. if timeErr != nil {
  581. br.Msg = "获取更新规则失败"
  582. br.ErrMsg = "更新规则时间转换失败4001, Err: " + timeErr.Error()
  583. return
  584. }
  585. endTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseEndTime, time.Local)
  586. if timeErr != nil {
  587. br.Msg = "获取更新规则失败"
  588. br.ErrMsg = "更新规则时间转换失败4002, Err: " + timeErr.Error()
  589. return
  590. }
  591. // 暂停更新
  592. if nowTime.After(startTime) && nowTime.Before(endTime.AddDate(0, 0, 1)) {
  593. stop = true
  594. }
  595. break
  596. }
  597. }
  598. }
  599. if !stop {
  600. // 授权的用户列表
  601. tmpChapterIdGrandList, ok := chapterIdGrandListMap[item.ReportChapterId]
  602. if !ok {
  603. tmpChapterIdGrandList = make([]int, 0)
  604. }
  605. // 关联的品种列表
  606. tmpChapterIdPermissionList, ok := chapterIdPermissionListMap[item.ReportChapterId]
  607. if !ok {
  608. tmpChapterIdPermissionList = make([]int, 0)
  609. }
  610. tmpChapterItem := models.ReportChapterResp{
  611. ReportChapterId: item.ReportChapterId,
  612. ReportId: item.ReportId,
  613. ReportType: item.ReportType,
  614. TypeId: item.TypeId,
  615. TypeName: item.TypeName,
  616. TypeEditImg: typeIdImg[item.TypeId],
  617. Title: item.Title,
  618. IsEdit: item.IsEdit,
  619. Trend: item.Trend,
  620. Sort: item.Sort,
  621. PublishState: item.PublishState,
  622. VideoUrl: item.VideoUrl,
  623. VideoName: item.VideoName,
  624. VideoPlaySeconds: item.VideoPlaySeconds,
  625. VideoSize: item.VideoSize,
  626. VideoKind: item.VideoKind,
  627. ModifyTime: item.ModifyTime.Format(utils.FormatDate),
  628. GrandAdminIdList: tmpChapterIdGrandList,
  629. PermissionIdList: tmpChapterIdPermissionList,
  630. }
  631. markStatus, err := services.UpdateReportEditMark(item.ReportId, item.ReportChapterId, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  632. if err != nil {
  633. br.Msg = "查询标记状态失败"
  634. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  635. return
  636. }
  637. if markStatus.Status == 0 {
  638. tmpChapterItem.CanEdit = true
  639. } else {
  640. tmpChapterItem.Editor = markStatus.Editor
  641. }
  642. // 报告章节的操作权限
  643. tmpChapterItem.IsAuth = services.CheckChapterAuthByAdminIdList(sysUser.AdminId, reportInfo.AdminId, tmpChapterIdGrandList)
  644. resp = append(resp, tmpChapterItem)
  645. }
  646. }
  647. }
  648. br.Ret = 200
  649. br.Success = true
  650. br.Msg = "获取成功"
  651. br.Data = resp
  652. }
  653. // GetDayWeekChapter
  654. // @Title 获取晨周报章节信息
  655. // @Description 获取晨周报章节信息
  656. // @Param ReportChapterId query int true "报告章节ID"
  657. // @Success 200 Ret=200 保存成功
  658. // @router /getDayWeekChapter [get]
  659. func (this *ReportController) GetDayWeekChapter() {
  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. // 获取报告详情
  689. reportInfo, err := models.GetReportById(chapterInfo.ReportId)
  690. if err != nil {
  691. br.Msg = "获取报告信息失败"
  692. br.ErrMsg = "获取报告信息失败, Err: " + err.Error()
  693. return
  694. }
  695. // 权限校验
  696. isAuth, err := services.CheckReportAuthByReportChapterInfo(sysUser.AdminId, reportInfo.AdminId, reportInfo.Id)
  697. if err != nil {
  698. br.Msg = "获取报告权限失败"
  699. br.ErrMsg = "获取报告权限失败,Err:" + err.Error()
  700. return
  701. }
  702. if !isAuth {
  703. br.Msg = "无操作权限"
  704. br.ErrMsg = "无操作权限"
  705. return
  706. }
  707. chapterInfo.Content = html.UnescapeString(chapterInfo.Content)
  708. chapterInfo.ContentSub = html.UnescapeString(chapterInfo.ContentSub)
  709. chapterInfo.ContentStruct = html.UnescapeString(chapterInfo.ContentStruct)
  710. // 授权用户列表map
  711. chapterGrantIdList := make([]int, 0)
  712. // 关联品种id列表map
  713. chapterPermissionIdList := make([]int, 0)
  714. // 处理章节id授权用户列表
  715. {
  716. chapterGrantObj := report.ReportChapterGrant{}
  717. chapterGrantList, tmpErr := chapterGrantObj.GetGrantListById(chapterInfo.ReportChapterId)
  718. if tmpErr != nil {
  719. br.Msg = "获取章节id授权用户列表失败"
  720. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  721. return
  722. }
  723. for _, v := range chapterGrantList {
  724. chapterGrantIdList = append(chapterGrantIdList, v.AdminId)
  725. }
  726. }
  727. // 处理章节id关联品种id列表
  728. {
  729. obj := report.ReportChapterPermissionMapping{}
  730. chapterPermissionList, tmpErr := obj.GetPermissionListById(chapterInfo.ReportChapterId)
  731. if tmpErr != nil {
  732. br.Msg = "获取章节id关联品种列表失败"
  733. br.ErrMsg = "获取章节id关联品种列表失败, Err: " + tmpErr.Error()
  734. return
  735. }
  736. for _, v := range chapterPermissionList {
  737. chapterPermissionIdList = append(chapterPermissionIdList, v.ChartPermissionId)
  738. }
  739. }
  740. resp := models.ReportChapterItem{
  741. ReportChapter: *chapterInfo,
  742. GrandAdminIdList: chapterGrantIdList,
  743. PermissionIdList: chapterPermissionIdList,
  744. }
  745. // 获取当前编辑状态
  746. {
  747. markStatus, err := services.UpdateReportEditMark(chapterInfo.ReportId, chapterInfo.ReportChapterId, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  748. if err != nil {
  749. br.Msg = "查询标记状态失败"
  750. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  751. return
  752. }
  753. if markStatus.Status == 0 {
  754. resp.CanEdit = true
  755. } else {
  756. resp.Editor = markStatus.Editor
  757. }
  758. }
  759. br.Ret = 200
  760. br.Success = true
  761. br.Msg = "获取成功"
  762. br.Data = resp
  763. }
  764. // ChapterMove
  765. // @Title 移动章节类型
  766. // @Description 移动章节类型
  767. // @Param request body models.PermissionMoveReq true "type json string"
  768. // @Success 200 Ret=200 操作成功
  769. // @router /chapter/move [post]
  770. func (this *ReportController) ChapterMove() {
  771. br := new(models.BaseResponse).Init()
  772. defer func() {
  773. if br.ErrMsg == "" {
  774. br.IsSendEmail = false
  775. }
  776. this.Data["json"] = br
  777. this.ServeJSON()
  778. }()
  779. sysUser := this.SysUser
  780. if sysUser == nil {
  781. br.Msg = "请登录"
  782. br.ErrMsg = "请登录,SysUser Is Empty"
  783. br.Ret = 408
  784. return
  785. }
  786. var req models.ReportChapterMoveReq
  787. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  788. br.Msg = "参数解析异常!"
  789. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  790. return
  791. }
  792. if req.ReportChapterId == 0 {
  793. br.Msg = "请选择要移动的章节"
  794. return
  795. }
  796. e, msg := services.MoveReportChapter(&req)
  797. if e != nil {
  798. br.Msg = msg
  799. br.ErrMsg = "移动品种失败, Err: " + e.Error()
  800. return
  801. }
  802. br.Ret = 200
  803. br.Success = true
  804. br.Msg = "操作成功"
  805. }
  806. // EditChapterTrendTag
  807. // @Title 编辑章节趋势标签
  808. // @Description 编辑章节趋势标签
  809. // @Param request body models.EditReportChapterReq true "type json string"
  810. // @Success 200 Ret=200 保存成功
  811. // @router /editChapterTrendTag [post]
  812. func (this *ReportController) EditChapterTrendTag() {
  813. br := new(models.BaseResponse).Init()
  814. defer func() {
  815. this.Data["json"] = br
  816. this.ServeJSON()
  817. }()
  818. sysUser := this.SysUser
  819. if sysUser == nil {
  820. br.Msg = "请登录"
  821. br.ErrMsg = "请登录,SysUser Is Empty"
  822. br.Ret = 408
  823. return
  824. }
  825. var req models.EditChapterTrendTagReq
  826. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  827. if err != nil {
  828. br.Msg = "参数解析异常!"
  829. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  830. return
  831. }
  832. if req.ReportChapterId <= 0 {
  833. br.Msg = "章节ID有误"
  834. return
  835. }
  836. if req.Trend == "" {
  837. br.Msg = "请输入标签"
  838. return
  839. }
  840. chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
  841. if err != nil {
  842. br.Msg = "获取章节信息失败"
  843. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  844. return
  845. }
  846. // 获取报告详情
  847. reportInfo, err := models.GetReportByReportId(chapterInfo.ReportId)
  848. if err != nil {
  849. br.Msg = "报告信息有误"
  850. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  851. return
  852. }
  853. // 操作权限校验
  854. {
  855. // 如果不是创建人,那么就要去查看是否授权
  856. if reportInfo.AdminId != sysUser.AdminId {
  857. // 授权用户权限校验
  858. chapterGrantObj := report.ReportChapterGrant{}
  859. _, tmpErr := chapterGrantObj.GetGrantByIdAndAdmin(chapterInfo.ReportChapterId, sysUser.AdminId)
  860. if tmpErr != nil {
  861. if tmpErr.Error() == utils.ErrNoRow() {
  862. br.Msg = "没有权限"
  863. br.ErrMsg = "没有权限"
  864. br.IsSendEmail = false
  865. return
  866. }
  867. br.Msg = "获取章节id授权用户失败"
  868. br.ErrMsg = "获取章节id授权用户失败, Err: " + tmpErr.Error()
  869. return
  870. }
  871. }
  872. }
  873. // 更新章节标签
  874. chapterInfo.Trend = req.Trend
  875. updateCols := make([]string, 0)
  876. updateCols = append(updateCols, "Trend")
  877. if err = chapterInfo.UpdateChapter(updateCols); err != nil {
  878. br.Msg = "更新标签失败"
  879. br.ErrMsg = "更新标签失败, Err: " + err.Error()
  880. return
  881. }
  882. // 添加关键词
  883. if err = models.AddTrendTagKeyWord(req.Trend); err != nil {
  884. br.Msg = "添加标签关键词失败"
  885. br.ErrMsg = "添加标签关键词失败, Err: " + err.Error()
  886. return
  887. }
  888. br.Ret = 200
  889. br.Success = true
  890. br.Msg = "保存成功"
  891. }
  892. // GetSunCode 获取太阳码
  893. // @Title 公共模块
  894. // @Description 获取分享海报
  895. // @Param request body models.SunCodeReq true "type json string"
  896. // @Success 200 {object} string "获取成功"
  897. // @failure 400 {string} string "获取失败"
  898. // @router /getSunCode [post]
  899. func (this *ReportController) GetSunCode() {
  900. br := new(models.BaseResponse).Init()
  901. defer func() {
  902. this.Data["json"] = br
  903. this.ServeJSON()
  904. }()
  905. sysUser := this.SysUser
  906. if sysUser == nil {
  907. br.Msg = "请登录"
  908. br.ErrMsg = "请登录,SysUser Is Empty"
  909. br.Ret = 408
  910. return
  911. }
  912. var req models.SunCodeReq
  913. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  914. if err != nil {
  915. br.Msg = "参数解析异常!"
  916. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  917. return
  918. }
  919. var sunCodeUrl string
  920. //先查,查不到再去生成上传
  921. item, err := models.GetYbPcSunCode(req.CodeScene, req.CodePage)
  922. if err != nil && err.Error() != utils.ErrNoRow() {
  923. br.Msg = "查询太阳码失败!"
  924. br.ErrMsg = "查询太阳码失败,Err:" + err.Error()
  925. return
  926. }
  927. if item != nil {
  928. sunCodeUrl = item.SuncodeUrl
  929. }
  930. if sunCodeUrl == "" {
  931. sunCodeUrl, err = services.PcCreateAndUploadSunCode(req.CodeScene, req.CodePage)
  932. if err != nil {
  933. br.Msg = "生成太阳码失败!"
  934. br.ErrMsg = "生成太阳码失败,Err:" + err.Error()
  935. return
  936. }
  937. }
  938. br.Data = sunCodeUrl
  939. br.Ret = 200
  940. br.Success = true
  941. br.Msg = "操作成功"
  942. }
  943. // VoiceUpload
  944. // @Title 音频上传
  945. // @Description 音频上传接口
  946. // @Param file query file true "文件"
  947. // @Param ReportChapterId query int true "报告章节ID"
  948. // @Success Ret=200 上传成功
  949. // @router /chapter/voice/upload [post]
  950. func (this *ReportController) VoiceUpload() {
  951. br := new(models.BaseResponse).Init()
  952. defer func() {
  953. this.Data["json"] = br
  954. this.ServeJSON()
  955. }()
  956. f, h, err := this.GetFile("file")
  957. if err != nil {
  958. br.Msg = "获取资源信息失败"
  959. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  960. return
  961. }
  962. // 报告章节id
  963. reportChapterId, err := this.GetInt("ReportChapterId", 0)
  964. if err != nil {
  965. br.Msg = "报告章节ID异常"
  966. br.ErrMsg = "报告章节ID异常,Err:" + err.Error()
  967. return
  968. }
  969. // 报告章节信息
  970. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  971. if err != nil {
  972. br.Msg = "获取报告章节信息失败"
  973. br.ErrMsg = "获取报告章节信息失败,Err:" + err.Error()
  974. return
  975. }
  976. // 报告信息
  977. reportInfo, err := models.GetReportByReportId(reportChapterInfo.ReportId)
  978. if err != nil {
  979. br.Msg = "获取报告信息失败"
  980. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  981. return
  982. }
  983. // 权限校验
  984. isAuth, err := services.CheckChapterAuthByReportChapterInfo(this.SysUser.AdminId, reportInfo.AdminId, reportChapterInfo)
  985. if err != nil {
  986. br.Msg = "获取报告权限失败"
  987. br.ErrMsg = "获取报告权限失败,Err:" + err.Error()
  988. return
  989. }
  990. if !isAuth {
  991. br.Msg = "无操作权限"
  992. br.ErrMsg = "无操作权限"
  993. return
  994. }
  995. ext := path.Ext(h.Filename)
  996. dateDir := time.Now().Format("20060102")
  997. uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
  998. err = os.MkdirAll(uploadDir, utils.DIR_MOD)
  999. if err != nil {
  1000. br.Msg = "存储目录创建失败"
  1001. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  1002. return
  1003. }
  1004. randStr := utils.GetRandStringNoSpecialChar(28)
  1005. fileName := randStr + ext
  1006. fpath := uploadDir + "/" + fileName
  1007. defer f.Close() //关闭上传文件
  1008. err = this.SaveToFile("file", fpath)
  1009. if err != nil {
  1010. br.Msg = "文件上传失败"
  1011. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  1012. return
  1013. }
  1014. resourceUrl := ``
  1015. //上传到阿里云 和 minio
  1016. //if utils.ObjectStorageClient == "minio" {
  1017. // resourceUrl, err = services.UploadAudioToMinIo(fileName, fpath)
  1018. // if err != nil {
  1019. // br.Msg = "文件上传失败"
  1020. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  1021. // return
  1022. // }
  1023. //} else {
  1024. // resourceUrl, err = services.UploadAudioAliyun(fileName, fpath)
  1025. // if err != nil {
  1026. // br.Msg = "文件上传失败"
  1027. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  1028. // return
  1029. // }
  1030. //}
  1031. ossClient := services.NewOssClient()
  1032. if ossClient == nil {
  1033. br.Msg = "上传失败"
  1034. br.ErrMsg = "初始化OSS服务失败"
  1035. return
  1036. }
  1037. resourceUrl, err = ossClient.UploadFile(fileName, fpath, "")
  1038. if err != nil {
  1039. br.Msg = "文件上传失败"
  1040. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  1041. return
  1042. }
  1043. defer func() {
  1044. os.Remove(fpath)
  1045. }()
  1046. item := new(models.Resource)
  1047. item.ResourceUrl = resourceUrl
  1048. item.ResourceType = 2
  1049. item.CreateTime = time.Now()
  1050. newId, err := models.AddResource(item)
  1051. if err != nil {
  1052. br.Msg = "资源上传失败"
  1053. br.ErrMsg = "资源上传失败,Err:" + err.Error()
  1054. return
  1055. }
  1056. var playSeconds float64
  1057. playSeconds, err = mp3duration.Calculate(fpath)
  1058. if playSeconds <= 0 {
  1059. playSeconds, err = utils.GetVideoPlaySeconds(fpath)
  1060. if err != nil {
  1061. br.Msg = "获取音频时间失败"
  1062. br.ErrMsg = "获取音频时间失败,Err:" + err.Error()
  1063. return
  1064. }
  1065. }
  1066. fileBody, err := ioutil.ReadFile(fpath)
  1067. videoSize := len(fileBody)
  1068. sizeFloat := (float64(videoSize) / float64(1024)) / float64(1024)
  1069. sizeStr := utils.SubFloatToFloatStr(sizeFloat, 2)
  1070. {
  1071. reportChapterCreateTime, err := time.Parse(utils.FormatDateTime, reportChapterInfo.CreateTime)
  1072. if err != nil {
  1073. br.Msg = "上传失败"
  1074. br.ErrMsg = "上传失败,Err:" + err.Error()
  1075. return
  1076. }
  1077. createTimeStr := reportChapterCreateTime.Format("0102")
  1078. videoName := reportChapterInfo.Title + "(" + createTimeStr + ")"
  1079. reportChapterInfo.VideoUrl = resourceUrl
  1080. reportChapterInfo.VideoName = videoName
  1081. reportChapterInfo.VideoPlaySeconds = fmt.Sprint(playSeconds)
  1082. reportChapterInfo.VideoSize = sizeStr
  1083. reportChapterInfo.VideoKind = 1
  1084. reportChapterInfo.LastModifyAdminId = this.SysUser.AdminId
  1085. reportChapterInfo.LastModifyAdminName = this.SysUser.RealName
  1086. reportChapterInfo.ModifyTime = time.Now()
  1087. err = reportChapterInfo.UpdateChapter([]string{"VideoUrl", "VideoName", "VideoPlaySeconds", "VideoSize", "VideoKind", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
  1088. if err != nil {
  1089. br.Msg = "上传失败"
  1090. br.ErrMsg = "修改报告章节的音频信息失败,Err:" + err.Error()
  1091. return
  1092. }
  1093. // 修改报告的最近更新人信息
  1094. reportInfo.LastModifyAdminId = this.SysUser.AdminId
  1095. reportInfo.LastModifyAdminName = this.SysUser.RealName
  1096. reportInfo.ModifyTime = time.Now()
  1097. err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
  1098. if err != nil {
  1099. br.Msg = "上传失败"
  1100. br.ErrMsg = "修改报告最后更新人信息失败,Err:" + err.Error()
  1101. return
  1102. }
  1103. }
  1104. // 处理报告中的音频文件分贝
  1105. go services.HandleVideoDecibel(reportChapterInfo)
  1106. resp := new(models.ResourceResp)
  1107. resp.Id = newId
  1108. resp.ResourceUrl = resourceUrl
  1109. br.Msg = "上传成功"
  1110. br.Ret = 200
  1111. br.Success = true
  1112. br.Data = resp
  1113. return
  1114. }
  1115. // PublishDayWeekReportChapter
  1116. // @Title 发布章节
  1117. // @Description 发布章节
  1118. // @Param request body models.PublishReportChapterReq true "type json string"
  1119. // @Success 200 Ret=200 操作成功
  1120. // @router /publishDayWeekReportChapter [post]
  1121. func (this *ReportController) PublishDayWeekReportChapter() {
  1122. br := new(models.BaseResponse).Init()
  1123. defer func() {
  1124. this.Data["json"] = br
  1125. this.ServeJSON()
  1126. }()
  1127. sysUser := this.SysUser
  1128. if sysUser == nil {
  1129. br.Msg = "请登录"
  1130. br.ErrMsg = "请登录,SysUser Is Empty"
  1131. br.Ret = 408
  1132. return
  1133. }
  1134. var req models.PublishReportChapterReq
  1135. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1136. if err != nil {
  1137. br.Msg = "参数解析异常!"
  1138. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1139. return
  1140. }
  1141. if req.ReportChapterId <= 0 {
  1142. br.Msg = "参数有误"
  1143. return
  1144. }
  1145. // 获取报告详情
  1146. chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
  1147. if err != nil {
  1148. br.Msg = "章节信息有误"
  1149. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  1150. return
  1151. }
  1152. reportInfo, err := models.GetReportByReportId(chapterInfo.ReportId)
  1153. if err != nil {
  1154. br.Msg = "查询报告有误"
  1155. br.ErrMsg = "查询报告信息失败, Err: " + err.Error()
  1156. return
  1157. }
  1158. if reportInfo.State == 2 {
  1159. br.Msg = "该报告已发布,不允许编辑"
  1160. br.ErrMsg = "该报告已发布,不允许编辑"
  1161. return
  1162. }
  1163. // 图表刷新状态
  1164. refreshResult := data.CheckBatchChartRefreshResult("report", chapterInfo.ReportId, chapterInfo.ReportChapterId)
  1165. if !refreshResult {
  1166. br.Msg = "图表刷新未完成,请稍后操作"
  1167. br.ErrMsg = "图表刷新未完成,请稍后操作"
  1168. br.IsSendEmail = false
  1169. return
  1170. }
  1171. // 如果是系统章节,那么需要校验下是否已经停更
  1172. if chapterInfo.TypeId > 0 {
  1173. // 获取规则配置
  1174. reportChapterTypeRule, err := models.GetReportChapterTypeById(chapterInfo.TypeId)
  1175. if err != nil {
  1176. br.Msg = "获取配置信息异常"
  1177. br.ErrMsg = "获取配置信息异常, Err: " + err.Error()
  1178. return
  1179. }
  1180. if reportChapterTypeRule.Enabled == 0 {
  1181. br.Msg = "该章节已永久停更"
  1182. br.ErrMsg = "该章节已永久停更 "
  1183. br.IsSendEmail = false
  1184. return
  1185. }
  1186. }
  1187. var publishTime time.Time
  1188. if reportInfo.MsgIsSend == 1 && reportInfo.PublishTime.IsZero() { //如果报告曾经发布过,并且已经发送过模版消息,则章节的发布时间为报告的发布时间
  1189. publishTime = reportInfo.PublishTime
  1190. } else {
  1191. publishTime = time.Now()
  1192. }
  1193. // 更新章节信息
  1194. chapterInfo.IsEdit = 1
  1195. chapterInfo.PublishState = 2
  1196. chapterInfo.PublishTime = publishTime
  1197. chapterInfo.LastModifyAdminId = this.SysUser.AdminId
  1198. chapterInfo.LastModifyAdminName = this.SysUser.RealName
  1199. chapterInfo.ModifyTime = time.Now()
  1200. updateCols := make([]string, 0)
  1201. updateCols = append(updateCols, "IsEdit", "PublishState", "PublishTime", "LastModifyAdminId", "LastModifyAdminName", "ModifyTime")
  1202. err = chapterInfo.UpdateChapter(updateCols)
  1203. if err != nil {
  1204. br.Msg = "发布失败"
  1205. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  1206. return
  1207. }
  1208. // 修改报告的最近更新人信息
  1209. go func() {
  1210. reportInfo.LastModifyAdminId = this.SysUser.AdminId
  1211. reportInfo.LastModifyAdminName = this.SysUser.RealName
  1212. reportInfo.ModifyTime = time.Now()
  1213. err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"})
  1214. if err != nil {
  1215. br.Msg = "上传失败"
  1216. br.ErrMsg = "修改报告最后更新人信息失败,Err:" + err.Error()
  1217. return
  1218. }
  1219. }()
  1220. // 更新章节ES
  1221. {
  1222. go services.UpdateReportChapterEs(chapterInfo.ReportChapterId)
  1223. }
  1224. // 同时发布报告
  1225. if req.PublishReport == 1 {
  1226. if _, e := services.PublishDayWeekReport(chapterInfo.ReportId); e != nil {
  1227. br.Msg = "章节发布成功,报告发布失败,请手动发布报告"
  1228. br.ErrMsg = "发布晨/周报失败, Err: " + e.Error()
  1229. return
  1230. }
  1231. }
  1232. br.Ret = 200
  1233. br.Success = true
  1234. br.Msg = "操作成功"
  1235. }