report_chapter.go 48 KB

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