report_chapter.go 40 KB

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