report_chapter.go 39 KB

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