report_chapter.go 44 KB

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