report_chapter.go 45 KB

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