report_chapter.go 43 KB

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