report_chapter.go 47 KB

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