report_v2.go 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/report"
  6. "eta/eta_api/models/report_approve"
  7. "eta/eta_api/models/system"
  8. "eta/eta_api/services"
  9. "eta/eta_api/services/alarm_msg"
  10. "eta/eta_api/services/data"
  11. "eta/eta_api/utils"
  12. "fmt"
  13. "github.com/rdlucklib/rdluck_tools/paging"
  14. "html"
  15. "strconv"
  16. "time"
  17. )
  18. // TODO 报告的权限校验(跳过列表页,直接进入详情页,不管是普通报告还是章节报告)
  19. // ListReport
  20. // @Title 获取报告列表接口
  21. // @Description 获取报告列表
  22. // @Param PageSize query int true "每页数据条数"
  23. // @Param CurrentIndex query int true "当前页页码,从1开始"
  24. // @Param TimeType query string true "筛选的时间类别:publish_time(发布时间),modify_time(更新时间);approve_time(审批时间)"
  25. // @Param StartDate query string true "开始时间"
  26. // @Param EndDate query string true "结束时间"
  27. // @Param Frequency query string true "频度"
  28. // @Param ClassifyIdFirst query int true "一级分类id"
  29. // @Param ClassifyIdSecond query int true "二级分类id"
  30. // @Param ClassifyIdThird query int true "三级分类id"
  31. // @Param State query int true "状态"
  32. // @Param KeyWord query string true "搜索关键词"
  33. // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
  34. // @Param FilterReportType query string true "筛选报告类型,1:公共研报,2:共享研报,3:我的研报"
  35. // @Success 200 {object} models.ReportListResp
  36. // @router /list [get]
  37. func (this *ReportController) ListReport() {
  38. br := new(models.BaseResponse).Init()
  39. defer func() {
  40. this.Data["json"] = br
  41. this.ServeJSON()
  42. }()
  43. pageSize, _ := this.GetInt("PageSize")
  44. currentIndex, _ := this.GetInt("CurrentIndex")
  45. timeType := this.GetString("TimeType")
  46. startDate := this.GetString("StartDate")
  47. endDate := this.GetString("EndDate")
  48. frequency := this.GetString("Frequency")
  49. classifyIdFirst, _ := this.GetInt("ClassifyIdFirst", 0)
  50. classifyIdSecond, _ := this.GetInt("ClassifyIdSecond", 0)
  51. classifyIdThird, _ := this.GetInt("ClassifyIdThird", 0)
  52. state, _ := this.GetInt("State")
  53. keyWord := this.GetString("KeyWord")
  54. msgIsSend, _ := this.GetInt("MsgIsSend")
  55. filterReportType, _ := this.GetInt("FilterReportType", 1)
  56. var startSize int
  57. if pageSize <= 0 {
  58. pageSize = utils.PageSize20
  59. }
  60. if currentIndex <= 0 {
  61. currentIndex = 1
  62. }
  63. startSize = utils.StartIndex(currentIndex, pageSize)
  64. if timeType == "" {
  65. timeType = "publish_time"
  66. }
  67. if timeType != "publish_time" && timeType != "modify_time" && timeType != "approve_time" {
  68. br.Msg = "请选择正确的时间"
  69. br.ErrMsg = "请选择正确的时间"
  70. return
  71. }
  72. var condition string
  73. var pars []interface{}
  74. if keyWord != "" {
  75. condition += ` AND (a.title LIKE ? OR a.admin_real_name LIKE ? ) `
  76. pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  77. }
  78. if startDate != "" {
  79. condition += ` AND a.` + timeType + ` >= ? `
  80. pars = append(pars, startDate)
  81. }
  82. if endDate != "" {
  83. condition += ` AND a.` + timeType + ` <= ? `
  84. pars = append(pars, endDate)
  85. }
  86. if frequency != "" {
  87. condition += ` AND a.frequency = ? `
  88. pars = append(pars, frequency)
  89. }
  90. if classifyIdFirst > 0 {
  91. condition += ` AND a.classify_id_first = ? `
  92. pars = append(pars, classifyIdFirst)
  93. }
  94. if classifyIdSecond > 0 {
  95. condition += ` AND a.classify_id_second = ? `
  96. pars = append(pars, classifyIdSecond)
  97. }
  98. if classifyIdThird > 0 {
  99. condition += ` AND a.classify_id_third = ? `
  100. pars = append(pars, classifyIdSecond)
  101. }
  102. if state > 0 {
  103. condition += ` AND a.state = ? `
  104. pars = append(pars, state)
  105. }
  106. // 消息是否已推送 1-未推送; 2-已推送
  107. if msgIsSend == 1 {
  108. condition += ` AND (a.msg_is_send = 0 OR a.ths_msg_is_send = 0) `
  109. }
  110. if msgIsSend == 2 {
  111. condition += ` AND a.msg_is_send = 1 AND a.ths_msg_is_send = 1 `
  112. }
  113. var err error
  114. var total int
  115. var list []*models.ReportList
  116. switch filterReportType {
  117. // 筛选报告类型,1:公共研报,2:共享研报,3:我的研报
  118. case 1:
  119. condition += ` AND a.is_public_publish = ? `
  120. // TODO 临时使用,提测上线前得打开注释
  121. //condition += ` AND a.state in (2,6) `
  122. pars = append(pars, 1)
  123. case 3:
  124. condition += ` AND a.admin_id = ? `
  125. pars = append(pars, this.SysUser.AdminId)
  126. case 2:
  127. condition += ` AND (a.admin_id = ? or b.admin_id = ?) `
  128. pars = append(pars, this.SysUser.AdminId, this.SysUser.AdminId)
  129. }
  130. // 共享报告需要连表查询,所以需要单独写
  131. if filterReportType == 2 {
  132. total, err = models.GetReportListCountByGrant(condition, pars)
  133. if err != nil {
  134. br.Msg = "获取失败"
  135. br.ErrMsg = "获取失败,Err:" + err.Error()
  136. return
  137. }
  138. list, err = models.GetReportListByGrant(condition, pars, startSize, pageSize)
  139. if err != nil {
  140. br.Msg = "获取失败"
  141. br.ErrMsg = "获取失败,Err:" + err.Error()
  142. return
  143. }
  144. } else {
  145. total, err = models.GetReportListCountV1(condition, pars)
  146. if err != nil {
  147. br.Msg = "获取失败"
  148. br.ErrMsg = "获取失败,Err:" + err.Error()
  149. return
  150. }
  151. list, err = models.GetReportListV1(condition, pars, startSize, pageSize)
  152. if err != nil {
  153. br.Msg = "获取失败"
  154. br.ErrMsg = "获取失败,Err:" + err.Error()
  155. return
  156. }
  157. }
  158. listLen := len(list)
  159. if listLen > 0 {
  160. pvMap := make(map[int]int)
  161. uvMap := make(map[int]int)
  162. reportIdArr := make([]string, 0)
  163. syncReportIdArr := make([]string, 0) // 同步过来的报告IDs
  164. oldAndNewReportIdMap := make(map[int]int) // 旧报告和新报告的id对应关系
  165. for i := 0; i < listLen; i++ {
  166. reportIdArr = append(reportIdArr, strconv.Itoa(list[i].Id))
  167. if list[i].OldReportId > 0 {
  168. syncReportIdArr = append(syncReportIdArr, strconv.Itoa(list[i].OldReportId))
  169. oldAndNewReportIdMap[list[i].OldReportId] = list[i].Id
  170. }
  171. pvMap[list[i].Id] = list[i].Pv
  172. uvMap[list[i].Id] = list[i].Uv
  173. }
  174. // 当下报告的pv,uv
  175. if len(reportIdArr) > 0 {
  176. pvList, e := models.GetReportPvUvByReportIdList(reportIdArr)
  177. if e != nil {
  178. br.Msg = "获取失败"
  179. br.ErrMsg = "获取同步报告对应的PV、UV失败, Err: " + e.Error()
  180. return
  181. }
  182. for _, v := range pvList {
  183. pv := pvMap[v.ReportId]
  184. uv := uvMap[v.ReportId]
  185. pvMap[v.ReportId] = v.PvTotal + pv
  186. uvMap[v.ReportId] = v.UvTotal + uv
  187. }
  188. }
  189. //reportIds := strings.Join(reportIdArr, ",")
  190. //syncReportIds := strings.Join(syncReportIdArr, ",")
  191. // 查询同步过来的报告对应的老报告PV+UV
  192. if len(syncReportIdArr) > 0 {
  193. puvList, e := models.GetPUVByResearchReportIds(syncReportIdArr)
  194. if e != nil {
  195. br.Msg = "获取失败"
  196. br.ErrMsg = "获取同步报告对应的PV、UV失败, Err: " + e.Error()
  197. return
  198. }
  199. puvLen := len(puvList)
  200. for i := 0; i < puvLen; i++ {
  201. newReportId, ok := oldAndNewReportIdMap[puvList[i].ResearchReportId]
  202. if ok {
  203. pv := pvMap[newReportId]
  204. uv := uvMap[newReportId]
  205. pvMap[newReportId] = puvList[i].Pv + pv
  206. uvMap[newReportId] = puvList[i].Uv + uv
  207. }
  208. }
  209. }
  210. // 晨周报音频列表
  211. videoList, err := models.GetReportChapterVideoListByReportIds(reportIdArr)
  212. if err != nil {
  213. br.Msg = "获取失败"
  214. br.ErrMsg = "获取报告音频文件失败,Err:" + err.Error()
  215. return
  216. }
  217. for i := 0; i < listLen; i++ {
  218. list[i].Content = html.UnescapeString(list[i].Content)
  219. list[i].ContentSub = html.UnescapeString(list[i].ContentSub)
  220. // 除周报外其余报告均可推送客群
  221. list[i].NeedThsMsg = 1
  222. //if list[i].HasChapter == 1 && list[i].ChapterType == utils.REPORT_TYPE_WEEK {
  223. // list[i].NeedThsMsg = 0
  224. //}
  225. chapterList := make([]*models.ReportChapterVideoList, 0)
  226. for ii := 0; ii < len(videoList); ii++ {
  227. if list[i].Id == videoList[ii].ReportId {
  228. chapterList = append(chapterList, videoList[ii])
  229. }
  230. }
  231. list[i].ChapterVideoList = chapterList
  232. list[i].Pv += pvMap[list[i].Id]
  233. list[i].Uv += uvMap[list[i].Id]
  234. }
  235. }
  236. for _, item := range list {
  237. /*key := fmt.Sprint(`crm:report:edit:`, item.Id)
  238. opUserId, _ := utils.Rc.RedisInt(key)
  239. //如果当前没有人操作,获取当前操作人是本人,那么编辑按钮可用
  240. if opUserId <= 0 || (opUserId == this.SysUser.AdminId) || item.ClassifyNameFirst == "周报" || item.ClassifyNameFirst == "晨报" {
  241. item.CanEdit = true
  242. } else {
  243. adminInfo, errAdmin := system.GetSysUserById(opUserId)
  244. if errAdmin != nil {
  245. br.Msg = "获取失败"
  246. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  247. return
  248. }
  249. item.Editor = adminInfo.RealName
  250. }*/
  251. if item.HasChapter == 1 {
  252. item.CanEdit = true
  253. continue
  254. }
  255. markStatus, err := services.UpdateReportEditMark(item.Id, 0, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  256. if err != nil {
  257. br.Msg = "查询标记状态失败"
  258. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  259. return
  260. }
  261. if markStatus.Status == 0 {
  262. item.CanEdit = true
  263. } else {
  264. item.Editor = markStatus.Editor
  265. }
  266. }
  267. page := paging.GetPaging(currentIndex, pageSize, total)
  268. resp := new(models.ReportListResp)
  269. resp.Paging = page
  270. resp.List = list
  271. br.Ret = 200
  272. br.Success = true
  273. br.Msg = "获取成功"
  274. br.Data = resp
  275. }
  276. // Add
  277. // @Title 新增报告接口
  278. // @Description 新增报告(不区分报告类型)
  279. // @Param request body models.AddReq true "type json string"
  280. // @Success 200 {object} models.AddResp
  281. // @router /add [post]
  282. func (this *ReportController) Add() {
  283. br := new(models.BaseResponse).Init()
  284. defer func() {
  285. this.Data["json"] = br
  286. this.ServeJSON()
  287. }()
  288. sysUser := this.SysUser
  289. if sysUser == nil {
  290. br.Msg = "请登录"
  291. br.ErrMsg = "请登录,SysUser Is Empty"
  292. br.Ret = 408
  293. return
  294. }
  295. var req models.AddReq
  296. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  297. if err != nil {
  298. br.Msg = "参数解析异常!"
  299. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  300. return
  301. }
  302. if req.Title == `` {
  303. br.Msg = "标题不能为空"
  304. br.ErrMsg = "标题不能为空"
  305. br.IsSendEmail = false
  306. return
  307. }
  308. if req.ClassifyIdFirst <= 0 {
  309. br.Msg = "分类必填"
  310. br.ErrMsg = "分类必填"
  311. br.IsSendEmail = false
  312. return
  313. }
  314. var contentSub string
  315. if req.Content != "" {
  316. e := utils.ContentXssCheck(req.Content)
  317. if e != nil {
  318. br.Msg = "存在非法标签"
  319. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  320. return
  321. }
  322. content, e := services.FilterReportContentBr(req.Content)
  323. if e != nil {
  324. br.Msg = "内容去除前后空格失败"
  325. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  326. return
  327. }
  328. req.Content = content
  329. contentSub, err = services.GetReportContentSub(req.Content)
  330. if err != nil {
  331. go alarm_msg.SendAlarmMsg("ContentSub 失败,Err:"+err.Error(), 3)
  332. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  333. }
  334. }
  335. // 报告期数
  336. maxStage, err := models.GetReportStage(req.ClassifyIdFirst, req.ClassifyIdSecond, req.ClassifyIdThird)
  337. if err != nil {
  338. br.Msg = "期数获取失败!"
  339. br.ErrMsg = "期数获取失败,Err:" + err.Error()
  340. return
  341. }
  342. // 根据审批开关及审批流判断当前报告状态
  343. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, req.ClassifyIdFirst, req.ClassifyIdSecond, models.ReportOperateAdd)
  344. if e != nil {
  345. br.Msg = "操作失败"
  346. br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
  347. return
  348. }
  349. item := new(models.Report)
  350. item.AddType = req.AddType
  351. item.ReportVersion = 2
  352. item.ClassifyIdFirst = req.ClassifyIdFirst
  353. item.ClassifyNameFirst = req.ClassifyNameFirst
  354. item.ClassifyIdSecond = req.ClassifyIdSecond
  355. item.ClassifyNameSecond = req.ClassifyNameSecond
  356. item.Title = req.Title
  357. item.Abstract = req.Abstract
  358. item.Author = req.Author
  359. item.Frequency = req.Frequency
  360. item.State = state
  361. item.Content = html.EscapeString(req.Content)
  362. item.Stage = maxStage + 1
  363. item.ContentSub = html.EscapeString(contentSub)
  364. item.CreateTime = req.CreateTime
  365. item.ModifyTime = time.Now()
  366. item.ReportVersion = req.ReportVersion
  367. item.AdminId = sysUser.AdminId
  368. item.AdminRealName = sysUser.RealName
  369. item.ClassifyIdThird = req.ClassifyIdThird
  370. item.ClassifyNameThird = req.ClassifyNameThird
  371. // 产品要求,如果是多人协作,那么就是章节类型的报告
  372. if req.CollaborateType == 2 {
  373. item.HasChapter = 1
  374. item.ChapterType = ""
  375. }
  376. item.LastModifyAdminId = sysUser.AdminId
  377. item.LastModifyAdminName = sysUser.RealName
  378. item.ContentModifyTime = time.Now()
  379. item.NeedSplice = 0
  380. item.ContentStruct = html.EscapeString(req.ContentStruct)
  381. item.HeadImg = req.HeadImg
  382. item.EndImg = req.EndImg
  383. item.CanvasColor = req.CanvasColor
  384. item.HeadResourceId = req.HeadResourceId
  385. item.EndResourceId = req.EndResourceId
  386. item.CollaborateType = req.CollaborateType
  387. item.ReportLayout = req.ReportLayout
  388. item.IsPublicPublish = req.IsPublicPublish
  389. item.ReportCreateTime = time.Now()
  390. err, errMsg := services.AddReportAndChapter(item, req.InheritReportId, req.GrantAdminIdList)
  391. if err != nil {
  392. br.Msg = "保存失败"
  393. if errMsg != "" {
  394. br.Msg = errMsg
  395. }
  396. br.ErrMsg = "保存失败,Err:" + err.Error()
  397. return
  398. }
  399. recordItem := &models.ReportStateRecord{
  400. ReportId: item.Id,
  401. ReportType: 1,
  402. State: 1,
  403. AdminId: this.SysUser.AdminId,
  404. AdminName: this.SysUser.AdminName,
  405. CreateTime: time.Now(),
  406. }
  407. go func() {
  408. _, _ = models.AddReportStateRecord(recordItem)
  409. }()
  410. resp := new(models.AddResp)
  411. resp.ReportId = int64(item.Id)
  412. resp.ReportCode = item.ReportCode
  413. br.Ret = 200
  414. br.Success = true
  415. br.Msg = "保存成功"
  416. br.Data = resp
  417. }
  418. // Edit
  419. // @Title 编辑报告基础信息接口
  420. // @Description 编辑报告基础信息(不区分报告类型)
  421. // @Param request body models.EditReq true "type json string"
  422. // @Success 200 {object} models.EditResp
  423. // @router /edit [post]
  424. func (this *ReportController) Edit() {
  425. br := new(models.BaseResponse).Init()
  426. defer func() {
  427. this.Data["json"] = br
  428. this.ServeJSON()
  429. }()
  430. sysUser := this.SysUser
  431. if sysUser == nil {
  432. br.Msg = "请登录"
  433. br.ErrMsg = "请登录,SysUser Is Empty"
  434. br.Ret = 408
  435. return
  436. }
  437. var req models.EditReq
  438. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  439. if err != nil {
  440. br.Msg = "参数解析异常!"
  441. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  442. return
  443. }
  444. //if req.Content == "" {
  445. // br.Msg = "报告内容不能为空"
  446. // return
  447. //}
  448. //更新标记key
  449. markStatus, err := services.UpdateReportEditMark(int(req.ReportId), 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  450. if err != nil {
  451. br.Msg = err.Error()
  452. return
  453. }
  454. if markStatus.Status == 1 {
  455. br.Msg = markStatus.Msg
  456. //br.Ret = 202 //202 服务器已接受请求,但尚未处理。
  457. return
  458. }
  459. reportInfo, e := models.GetReportByReportId(int(req.ReportId))
  460. if e != nil {
  461. if e.Error() == utils.ErrNoRow() {
  462. br.Msg = "报告已被删除, 请刷新页面"
  463. return
  464. }
  465. br.Msg = "操作失败"
  466. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  467. return
  468. }
  469. if reportInfo.State == models.ReportStatePublished || reportInfo.State == models.ReportStatePass {
  470. br.Msg = "该报告已发布,不允许编辑"
  471. br.ErrMsg = "该报告已发布,不允许编辑"
  472. return
  473. }
  474. // 编辑报告信息
  475. err, errMsg := services.EditReport(reportInfo, req, sysUser)
  476. if err != nil {
  477. br.Msg = "保存失败"
  478. if errMsg != "" {
  479. br.Msg = errMsg
  480. }
  481. br.ErrMsg = "保存失败,Err:" + err.Error()
  482. return
  483. }
  484. reportCode := utils.MD5(strconv.Itoa(int(req.ReportId)))
  485. resp := new(models.EditResp)
  486. resp.ReportId = req.ReportId
  487. resp.ReportCode = reportCode
  488. br.Ret = 200
  489. br.Success = true
  490. br.Msg = "保存成功"
  491. br.Data = resp
  492. }
  493. // Detail
  494. // @Title 获取报告详情接口
  495. // @Description 获取报告详情
  496. // @Param request body models.ReportDetailReq true "type json string"
  497. // @Success 200 {object} models.Report
  498. // @router /detail [get]
  499. func (this *ReportController) Detail() {
  500. br := new(models.BaseResponse).Init()
  501. defer func() {
  502. this.Data["json"] = br
  503. this.ServeJSON()
  504. }()
  505. /*var req models.ReportDetailReq
  506. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  507. if err != nil {
  508. br.Msg = "参数解析异常!"
  509. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  510. return
  511. }
  512. if req.ReportId <= 0 {
  513. br.Msg = "参数错误"
  514. return
  515. }*/
  516. reportId, err := this.GetInt("ReportId")
  517. if err != nil {
  518. br.Msg = "获取参数失败!"
  519. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  520. return
  521. }
  522. if reportId <= 0 {
  523. br.Msg = "参数错误"
  524. return
  525. }
  526. item, err := models.GetReportById(reportId)
  527. if err != nil {
  528. if err.Error() == utils.ErrNoRow() {
  529. br.Msg = "报告已被删除"
  530. return
  531. }
  532. br.Msg = "获取失败"
  533. br.ErrMsg = "获取失败,Err:" + err.Error()
  534. return
  535. }
  536. chapterList := make([]*models.ReportChapter, 0)
  537. if item.HasChapter == 1 {
  538. // 获取章节内容
  539. tmpChapterList, err := models.GetPublishedChapterListByReportId(item.Id)
  540. if err != nil {
  541. br.Msg = "获取失败"
  542. br.ErrMsg = "获取晨/周报章节列表失败, Err: " + err.Error()
  543. return
  544. }
  545. // TODO 更新规则
  546. if len(tmpChapterList) > 0 {
  547. // 获取更新规则
  548. researchType := tmpChapterList[0].ReportType
  549. chapterTypeList, tmpErr := models.GetAllReportChapterTypeListByResearchType(researchType)
  550. if tmpErr != nil {
  551. br.Msg = "获取更新规则失败"
  552. br.ErrMsg = "获取更新规则失败, Err: " + tmpErr.Error()
  553. return
  554. }
  555. // 调整章节更新
  556. nowTime := time.Now().Local()
  557. for _, item := range tmpChapterList {
  558. stop := false
  559. for _, rule := range chapterTypeList {
  560. if rule.ReportChapterTypeId == item.TypeId {
  561. //fmt.Println("rule.Enabled :", rule.Enabled, ";name=", rule.ReportChapterTypeName, "item.IsEdit:", item.IsEdit, "rule.IsSet:", rule.IsSet)
  562. // 如果被永久暂停更新了
  563. if rule.Enabled == 0 && item.IsEdit == 0 { //该章节已被永久禁用,同时未被操作过
  564. stop = true
  565. } else if rule.PauseStartTime != "" && rule.PauseEndTime != "" && rule.PauseStartTime != utils.EmptyDateStr && rule.PauseEndTime != utils.EmptyDateStr {
  566. startTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseStartTime, time.Local)
  567. if timeErr != nil {
  568. br.Msg = "获取更新规则失败"
  569. br.ErrMsg = "更新规则时间转换失败4001, Err: " + timeErr.Error()
  570. return
  571. }
  572. endTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseEndTime, time.Local)
  573. if timeErr != nil {
  574. br.Msg = "获取更新规则失败"
  575. br.ErrMsg = "更新规则时间转换失败4002, Err: " + timeErr.Error()
  576. return
  577. }
  578. // 暂停更新
  579. if nowTime.After(startTime) && nowTime.Before(endTime.AddDate(0, 0, 1)) {
  580. stop = true
  581. }
  582. break
  583. }
  584. }
  585. }
  586. if !stop {
  587. item.Content = html.UnescapeString(item.Content)
  588. item.ContentSub = html.UnescapeString(item.ContentSub)
  589. chapterList = append(chapterList, item)
  590. }
  591. }
  592. }
  593. item.Abstract = item.Title
  594. }
  595. item.Content = html.UnescapeString(item.Content)
  596. item.ContentSub = html.UnescapeString(item.ContentSub)
  597. resp := &models.ReportDetailView{
  598. ReportDetail: item,
  599. ChapterList: chapterList,
  600. }
  601. br.Ret = 200
  602. br.Success = true
  603. br.Msg = "获取成功"
  604. br.Data = resp
  605. }
  606. // SaveReportContent
  607. // @Title 保存草稿
  608. // @Description 保存草稿
  609. // @Param request body models.SaveReportContent true "type json string"
  610. // @Success 200 {object} models.ReportAuthorResp
  611. // @router /saveReportContent [post]
  612. func (this *ReportController) SaveReportContent() {
  613. br := new(models.BaseResponse).Init()
  614. br.IsSendEmail = false
  615. defer func() {
  616. this.Data["json"] = br
  617. this.ServeJSON()
  618. }()
  619. sysUser := this.SysUser
  620. if sysUser == nil {
  621. br.Msg = "请登录"
  622. br.ErrMsg = "请登录,SysUser Is Empty"
  623. br.Ret = 408
  624. return
  625. }
  626. var req models.SaveReportContent
  627. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  628. if err != nil {
  629. br.Msg = "参数解析异常!"
  630. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  631. return
  632. }
  633. reportId := req.ReportId
  634. noChangeFlag := req.NoChange
  635. if reportId <= 0 {
  636. resp := new(models.SaveReportContentResp)
  637. resp.ReportId = reportId
  638. br.Ret = 200
  639. br.Success = true
  640. br.Msg = "保存成功"
  641. br.Data = resp
  642. return
  643. }
  644. // 获取报告详情
  645. reportInfo, _ := models.GetReportByReportId(int(req.ReportId))
  646. if reportInfo != nil && reportInfo.State == 2 {
  647. br.Msg = "该报告已发布,不允许编辑"
  648. br.ErrMsg = "该报告已发布,不允许编辑"
  649. return
  650. }
  651. // 标记更新中
  652. {
  653. markStatus, err := services.UpdateReportEditMark(int(req.ReportId), 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  654. if err != nil {
  655. br.Msg = err.Error()
  656. return
  657. }
  658. if markStatus.Status == 1 {
  659. br.Msg = markStatus.Msg
  660. return
  661. }
  662. }
  663. // 内容有过修改的话,那么逻辑处理
  664. if noChangeFlag != 1 {
  665. content := req.Content
  666. if content == "" {
  667. content = this.GetString("Content")
  668. }
  669. if content != "" {
  670. e := utils.ContentXssCheck(req.Content)
  671. if e != nil {
  672. br.Msg = "存在非法标签"
  673. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  674. return
  675. }
  676. contentClean, e := services.FilterReportContentBr(req.Content)
  677. if e != nil {
  678. br.Msg = "内容去除前后空格失败"
  679. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  680. return
  681. }
  682. content = contentClean
  683. contentSub, err := services.GetReportContentSub(content)
  684. if err != nil {
  685. go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
  686. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  687. }
  688. reportInfo.Content = html.EscapeString(content)
  689. reportInfo.ContentSub = html.EscapeString(contentSub)
  690. reportInfo.ContentStruct = html.EscapeString(req.ContentStruct)
  691. reportInfo.HeadImg = req.HeadImg
  692. reportInfo.EndImg = req.EndImg
  693. reportInfo.CanvasColor = req.CanvasColor
  694. reportInfo.HeadResourceId = req.HeadResourceId
  695. reportInfo.EndResourceId = req.EndResourceId
  696. reportInfo.ModifyTime = time.Now()
  697. reportInfo.ContentModifyTime = time.Now()
  698. updateCols := []string{"Content", "ContentSub", "HeadImg", "EndImg", "CanvasColor", "HeadResourceId", "EndResourceId", "ModifyTime", "ContentModifyTime"}
  699. err = reportInfo.UpdateReport(updateCols)
  700. if err != nil {
  701. br.Msg = "保存失败"
  702. br.ErrMsg = "保存失败,Err:" + err.Error()
  703. return
  704. }
  705. go models.AddReportSaveLog(reportId, this.SysUser.AdminId, reportInfo.Content, reportInfo.ContentSub, reportInfo.ContentStruct, reportInfo.CanvasColor, this.SysUser.AdminName, reportInfo.HeadResourceId, reportInfo.EndResourceId)
  706. }
  707. }
  708. resp := new(models.SaveReportContentResp)
  709. resp.ReportId = reportId
  710. br.Ret = 200
  711. br.Success = true
  712. br.Msg = "保存成功"
  713. br.Data = resp
  714. }
  715. // PublishDayWeekReportChapter
  716. // @Title 发布晨周报章节
  717. // @Description 发布晨周报章节
  718. // @Param request body models.PublishReportChapterReq true "type json string"
  719. // @Success 200 Ret=200 操作成功
  720. // @router /publishDayWeekReportChapter [post]
  721. func (this *ReportController) PublishDayWeekReportChapter() {
  722. br := new(models.BaseResponse).Init()
  723. defer func() {
  724. this.Data["json"] = br
  725. this.ServeJSON()
  726. }()
  727. sysUser := this.SysUser
  728. if sysUser == nil {
  729. br.Msg = "请登录"
  730. br.ErrMsg = "请登录,SysUser Is Empty"
  731. br.Ret = 408
  732. return
  733. }
  734. var req models.PublishReportChapterReq
  735. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  736. if err != nil {
  737. br.Msg = "参数解析异常!"
  738. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  739. return
  740. }
  741. if req.ReportChapterId <= 0 {
  742. br.Msg = "参数有误"
  743. return
  744. }
  745. if req.Title == "" {
  746. br.Msg = "请输入标题"
  747. return
  748. }
  749. if req.Content == "" {
  750. br.Msg = "请输入内容"
  751. return
  752. }
  753. if req.AddType == 0 {
  754. br.Msg = "请选择新增方式"
  755. return
  756. }
  757. reqTickerList := req.TickerList
  758. chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
  759. if err != nil {
  760. br.Msg = "章节信息有误"
  761. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  762. return
  763. }
  764. reportInfo, err := models.GetReportById(chapterInfo.ReportId)
  765. if err != nil {
  766. br.Msg = "查询报告有误"
  767. br.ErrMsg = "查询报告信息失败, Err: " + err.Error()
  768. return
  769. }
  770. if reportInfo.State == 2 {
  771. br.Msg = "该报告已发布,不允许编辑"
  772. br.ErrMsg = "该报告已发布,不允许编辑"
  773. return
  774. }
  775. // 图表刷新状态
  776. refreshResult := data.CheckBatchChartRefreshResult("report", chapterInfo.ReportId, chapterInfo.ReportChapterId)
  777. if !refreshResult {
  778. br.Msg = "图表刷新未完成,请稍后操作"
  779. br.ErrMsg = "图表刷新未完成,请稍后操作"
  780. br.IsSendEmail = false
  781. return
  782. }
  783. // 获取规则配置
  784. reportChapterTypeRule, err := models.GetReportChapterTypeById(chapterInfo.TypeId)
  785. if err != nil {
  786. br.Msg = "获取配置信息异常"
  787. br.ErrMsg = "获取配置信息异常, Err: " + err.Error()
  788. return
  789. }
  790. if reportChapterTypeRule.Enabled == 0 {
  791. br.Msg = "该章节已永久停更"
  792. br.ErrMsg = "该章节已永久停更 "
  793. br.IsSendEmail = false
  794. return
  795. }
  796. updateCols := make([]string, 0)
  797. updateCols = append(updateCols, "Title", "AddType", "Author", "Content", "ContentSub", "IsEdit", "CreateTime", "PublishState", "PublishTime")
  798. var needHandleVideo bool // 是否需要处理音频文件
  799. nowTime := time.Now()
  800. var publishTime time.Time
  801. if reportInfo.MsgIsSend == 1 && reportInfo.PublishTime != "" { //如果报告曾经发布过,并且已经发送过模版消息,则章节的发布时间为报告的发布时间
  802. publishTime, _ = time.ParseInLocation(utils.FormatDateTime, reportInfo.PublishTime, time.Local)
  803. } else {
  804. publishTime = time.Now()
  805. }
  806. if req.VideoUrl != "" {
  807. chapterInfo.VideoUrl = req.VideoUrl
  808. chapterInfo.VideoName = req.VideoName
  809. chapterInfo.VideoSize = req.VideoSize
  810. chapterInfo.VideoPlaySeconds = req.VideoPlaySeconds
  811. chapterInfo.VideoKind = 1
  812. updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
  813. // 手动上传的音频需要处理音频文件
  814. needHandleVideo = true
  815. } else {
  816. if chapterInfo.VideoUrl == "" {
  817. // 生成video
  818. videoUrl, videoName, videoSize, videoPlaySeconds, err := services.CreateReportVideo(req.Title, req.Content, publishTime.Format(utils.FormatDateTime))
  819. if err != nil {
  820. br.Msg = "生成video失败"
  821. br.ErrMsg = "生成video失败, Err: " + err.Error()
  822. return
  823. }
  824. chapterInfo.VideoUrl = videoUrl
  825. chapterInfo.VideoName = videoName
  826. chapterInfo.VideoSize = videoSize
  827. chapterInfo.VideoPlaySeconds = fmt.Sprintf("%.2f", videoPlaySeconds)
  828. chapterInfo.VideoKind = 2
  829. updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
  830. }
  831. }
  832. // 更新章节信息
  833. contentSub := ""
  834. if req.Content != "" {
  835. e := utils.ContentXssCheck(req.Content)
  836. if e != nil {
  837. br.Msg = "存在非法标签"
  838. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  839. return
  840. }
  841. contentClean, e := services.FilterReportContentBr(req.Content)
  842. if e != nil {
  843. br.Msg = "内容去除前后空格失败"
  844. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  845. return
  846. }
  847. req.Content = contentClean
  848. contentSub, err = services.GetReportContentSub(req.Content)
  849. if err != nil {
  850. br.Msg = "内容分段解析失败"
  851. br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
  852. return
  853. }
  854. }
  855. chapterInfo.Title = req.Title
  856. chapterInfo.AddType = req.AddType
  857. chapterInfo.Author = req.Author
  858. chapterInfo.Content = html.EscapeString(req.Content)
  859. chapterInfo.ContentSub = html.EscapeString(contentSub)
  860. chapterInfo.IsEdit = 1
  861. chapterInfo.CreateTime = req.CreateTime
  862. chapterInfo.PublishState = 2
  863. chapterInfo.PublishTime = publishTime
  864. // 晨报更新指标
  865. tickerList := make([]*models.ReportChapterTicker, 0)
  866. if chapterInfo.ReportType == "day" && len(reqTickerList) > 0 {
  867. for i := 0; i < len(reqTickerList); i++ {
  868. tickerList = append(tickerList, &models.ReportChapterTicker{
  869. ReportChapterId: chapterInfo.ReportChapterId,
  870. Sort: reqTickerList[i].Sort,
  871. Ticker: reqTickerList[i].Ticker,
  872. CreateTime: nowTime,
  873. UpdateTime: nowTime,
  874. })
  875. }
  876. }
  877. if err = models.UpdateChapterAndTicker(chapterInfo, updateCols, tickerList); err != nil {
  878. br.Msg = "发布失败"
  879. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  880. return
  881. }
  882. // 更新章节ES
  883. {
  884. go services.UpdateReportChapterEs(chapterInfo.ReportChapterId)
  885. }
  886. // 同时发布报告
  887. if req.PublishReport == 1 {
  888. if _, e := services.PublishDayWeekReport(chapterInfo.ReportId); e != nil {
  889. br.Msg = "章节发布成功,报告发布失败,请手动发布报告"
  890. br.ErrMsg = "发布晨/周报失败, Err: " + e.Error()
  891. return
  892. }
  893. }
  894. // 处理报告中的音频文件分贝
  895. if needHandleVideo {
  896. go services.HandleVideoDecibel(chapterInfo)
  897. }
  898. br.Ret = 200
  899. br.Success = true
  900. br.Msg = "操作成功"
  901. }
  902. // AuthorizedListReport
  903. // @Title 获取有权限的报告列表接口
  904. // @Description 获取有权限的报告列表接口
  905. // @Param PageSize query int true "每页数据条数"
  906. // @Param CurrentIndex query int true "当前页页码,从1开始"
  907. // @Param Keyword query string true "搜索关键词"
  908. // @Param ClassifyIdFirst query int true "一级分类id"
  909. // @Param ClassifyIdSecond query int true "二级分类id"
  910. // @Param ClassifyIdThird query int true "三级分类id"
  911. // @Success 200 {object} models.ReportListResp
  912. // @router /list/authorized [get]
  913. func (this *ReportController) AuthorizedListReport() {
  914. br := new(models.BaseResponse).Init()
  915. defer func() {
  916. this.Data["json"] = br
  917. this.ServeJSON()
  918. }()
  919. pageSize, _ := this.GetInt("PageSize")
  920. currentIndex, _ := this.GetInt("CurrentIndex")
  921. keyword := this.GetString("Keyword")
  922. classifyIdFirst, _ := this.GetInt("ClassifyIdFirst", 0)
  923. classifyIdSecond, _ := this.GetInt("ClassifyIdSecond", 0)
  924. classifyIdThird, _ := this.GetInt("ClassifyIdThird", 0)
  925. var startSize int
  926. if pageSize <= 0 {
  927. pageSize = utils.PageSize20
  928. }
  929. if currentIndex <= 0 {
  930. currentIndex = 1
  931. }
  932. startSize = utils.StartIndex(currentIndex, pageSize)
  933. var list []*models.ReportList
  934. // 没有输入信息,那就不展示
  935. if keyword == `` && classifyIdFirst <= 0 {
  936. page := paging.GetPaging(currentIndex, pageSize, 0)
  937. resp := new(models.ReportListResp)
  938. resp.Paging = page
  939. resp.List = list
  940. br.Ret = 200
  941. br.Success = true
  942. br.Msg = "获取成功"
  943. br.Data = resp
  944. return
  945. }
  946. // 当前用户有权限的报告id列表
  947. grantReportIdList := make([]int, 0)
  948. {
  949. obj := report.ReportGrant{}
  950. grantList, err := obj.GetGrantListByAdminId(this.SysUser.AdminId)
  951. if err != nil {
  952. br.Msg = "获取失败"
  953. br.ErrMsg = "获取授权报告id失败,Err:" + err.Error()
  954. return
  955. }
  956. for _, v := range grantList {
  957. grantReportIdList = append(grantReportIdList, v.ReportId)
  958. }
  959. }
  960. var condition string
  961. var pars []interface{}
  962. if classifyIdFirst > 0 {
  963. condition += ` AND a.classify_id_first = ? `
  964. pars = append(pars, classifyIdFirst)
  965. }
  966. if classifyIdSecond > 0 {
  967. condition += ` AND a.classify_id_second = ? `
  968. pars = append(pars, classifyIdSecond)
  969. }
  970. if classifyIdThird > 0 {
  971. condition += ` AND a.classify_id_third = ? `
  972. pars = append(pars, classifyIdSecond)
  973. }
  974. if keyword != `` {
  975. condition += ` AND a.title LIKE ? `
  976. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  977. }
  978. var err error
  979. var total int
  980. orCondition := `AND ( (a.is_public_publish = ? AND a.state in (2,6)) or a.admin_id = ? `
  981. pars = append(pars, 1, this.SysUser.AdminId)
  982. // 当前用户有权限的报告id列表
  983. num := len(grantReportIdList)
  984. if num > 0 {
  985. orCondition += ` OR a.id in (` + utils.GetOrmInReplace(num) + `)`
  986. pars = append(pars, grantReportIdList)
  987. }
  988. orCondition += ` ) `
  989. condition += orCondition
  990. total, err = models.GetReportListCountByAuthorized(condition, pars)
  991. if err != nil {
  992. br.Msg = "获取失败"
  993. br.ErrMsg = "获取失败,Err:" + err.Error()
  994. return
  995. }
  996. list, err = models.GetReportListByAuthorized(condition, pars, startSize, pageSize)
  997. if err != nil {
  998. br.Msg = "获取失败"
  999. br.ErrMsg = "获取失败,Err:" + err.Error()
  1000. return
  1001. }
  1002. //for _, item := range list {
  1003. // if item.HasChapter == 1 {
  1004. // item.CanEdit = true
  1005. // } else {
  1006. // markStatus, err := services.UpdateReportEditMark(item.Id, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  1007. // if err != nil {
  1008. // br.Msg = "查询标记状态失败"
  1009. // br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  1010. // return
  1011. // }
  1012. // if markStatus.Status == 0 {
  1013. // item.CanEdit = true
  1014. // } else {
  1015. // item.Editor = markStatus.Editor
  1016. // }
  1017. // }
  1018. //}
  1019. page := paging.GetPaging(currentIndex, pageSize, total)
  1020. resp := new(models.ReportListResp)
  1021. resp.Paging = page
  1022. resp.List = list
  1023. br.Ret = 200
  1024. br.Success = true
  1025. br.Msg = "获取成功"
  1026. br.Data = resp
  1027. }
  1028. // BaseDetail
  1029. // @Title 获取报告基础信息详情接口
  1030. // @Description 获取报告基础信息详情接口
  1031. // @Param request body models.ReportDetailReq true "type json string"
  1032. // @Success 200 {object} models.Report
  1033. // @router /detail/base [get]
  1034. func (this *ReportController) BaseDetail() {
  1035. br := new(models.BaseResponse).Init()
  1036. defer func() {
  1037. this.Data["json"] = br
  1038. this.ServeJSON()
  1039. }()
  1040. /*var req models.ReportDetailReq
  1041. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1042. if err != nil {
  1043. br.Msg = "参数解析异常!"
  1044. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1045. return
  1046. }
  1047. if req.ReportId <= 0 {
  1048. br.Msg = "参数错误"
  1049. return
  1050. }*/
  1051. reportId, err := this.GetInt("ReportId")
  1052. if err != nil {
  1053. br.Msg = "获取参数失败!"
  1054. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  1055. return
  1056. }
  1057. if reportId <= 0 {
  1058. br.Msg = "参数错误"
  1059. return
  1060. }
  1061. reportInfo, err := models.GetReportById(reportId)
  1062. if err != nil {
  1063. if err.Error() == utils.ErrNoRow() {
  1064. br.Msg = "报告已被删除"
  1065. return
  1066. }
  1067. br.Msg = "获取失败"
  1068. br.ErrMsg = "获取失败,Err:" + err.Error()
  1069. return
  1070. }
  1071. // 基础信息就不获取章节信息了
  1072. chapterList := make([]*models.ReportChapter, 0)
  1073. reportInfo.Content = html.UnescapeString(reportInfo.Content)
  1074. reportInfo.ContentSub = html.UnescapeString(reportInfo.ContentSub)
  1075. grandAdminList := make([]models.ReportDetailViewAdmin, 0)
  1076. permissionList := make([]models.ReportDetailViewPermission, 0)
  1077. // 处理报告授权用户列表
  1078. {
  1079. obj := report.ReportGrant{}
  1080. grantList, tmpErr := obj.GetGrantListById(reportId)
  1081. if tmpErr != nil {
  1082. br.Msg = "获取章节id授权用户列表失败"
  1083. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  1084. return
  1085. }
  1086. if len(grantList) > 0 {
  1087. grandAdminIdList := make([]int, 0)
  1088. for _, v := range grantList {
  1089. grandAdminIdList = append(grandAdminIdList, v.AdminId)
  1090. }
  1091. adminList, tmpErr := system.GetAdminListByIdList(grandAdminIdList)
  1092. if tmpErr != nil {
  1093. br.Msg = "获取章节id授权用户列表失败"
  1094. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  1095. return
  1096. }
  1097. for _, v := range adminList {
  1098. grandAdminList = append(grandAdminList, models.ReportDetailViewAdmin{
  1099. AdminId: v.AdminId,
  1100. AdminName: v.RealName,
  1101. })
  1102. }
  1103. }
  1104. }
  1105. // 处理章节id关联品种id列表
  1106. {
  1107. minClassifyId := reportInfo.ClassifyIdThird
  1108. if minClassifyId <= 0 {
  1109. minClassifyId = reportInfo.ClassifyIdSecond
  1110. }
  1111. if minClassifyId <= 0 {
  1112. minClassifyId = reportInfo.ClassifyIdFirst
  1113. }
  1114. if minClassifyId <= 0 {
  1115. br.Msg = "分类异常"
  1116. br.ErrMsg = "分类异常"
  1117. return
  1118. }
  1119. // 获取分类关联的品种id
  1120. classifyPermissionList, tmpErr := models.GetPermission(minClassifyId)
  1121. if tmpErr != nil {
  1122. br.Msg = "获取分类信息失败"
  1123. br.ErrMsg = "获取失败,Err:" + tmpErr.Error()
  1124. return
  1125. }
  1126. if len(classifyPermissionList) > 0 {
  1127. permissionIdList := make([]int, 0)
  1128. for _, v := range classifyPermissionList {
  1129. permissionIdList = append(permissionIdList, v.ChartPermissionId)
  1130. }
  1131. adminList, tmpErr := models.GetChartPermissionByIdList(permissionIdList)
  1132. if tmpErr != nil {
  1133. br.Msg = "获取章节id授权用户列表失败"
  1134. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  1135. return
  1136. }
  1137. for _, v := range adminList {
  1138. permissionList = append(permissionList, models.ReportDetailViewPermission{
  1139. PermissionId: v.ChartPermissionId,
  1140. PermissionName: v.ChartPermissionName,
  1141. })
  1142. }
  1143. }
  1144. }
  1145. resp := &models.ReportDetailView{
  1146. ReportDetail: reportInfo,
  1147. ChapterList: chapterList,
  1148. GrandAdminList: grandAdminList,
  1149. PermissionList: permissionList,
  1150. }
  1151. br.Ret = 200
  1152. br.Success = true
  1153. br.Msg = "获取成功"
  1154. br.Data = resp
  1155. }