report_chapter.go 39 KB

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