report_chapter.go 52 KB

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