report_chapter.go 47 KB

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