report_chapter.go 38 KB

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