report_chapter.go 47 KB

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