report_v2.go 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/models"
  5. "eta_gn/eta_api/models/report"
  6. "eta_gn/eta_api/models/report_approve"
  7. "eta_gn/eta_api/models/smart_report"
  8. "eta_gn/eta_api/models/system"
  9. "eta_gn/eta_api/services"
  10. "eta_gn/eta_api/services/alarm_msg"
  11. "eta_gn/eta_api/services/data"
  12. "eta_gn/eta_api/utils"
  13. "fmt"
  14. "github.com/rdlucklib/rdluck_tools/paging"
  15. "html"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // ListReport
  21. // @Title 获取报告列表接口
  22. // @Description 获取报告列表
  23. // @Param PageSize query int true "每页数据条数"
  24. // @Param CurrentIndex query int true "当前页页码,从1开始"
  25. // @Param TimeType query string true "筛选的时间类别:publish_time(发布时间),modify_time(更新时间);approve_time(审批时间)"
  26. // @Param StartDate query string true "开始时间"
  27. // @Param EndDate query string true "结束时间"
  28. // @Param Frequency query string true "频度"
  29. // @Param ClassifyIdFirst query int true "一级分类id"
  30. // @Param ClassifyIdSecond query int true "二级分类id"
  31. // @Param ClassifyIdThird query int true "三级分类id"
  32. // @Param State query int true "状态"
  33. // @Param KeyWord query string true "搜索关键词"
  34. // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
  35. // @Param FilterReportType query string true "筛选报告类型,1:公共研报,2:共享研报,3:我的研报"
  36. // @Success 200 {object} models.ReportListResp
  37. // @router /list [get]
  38. func (this *ReportController) ListReport() {
  39. br := new(models.BaseResponse).Init()
  40. defer func() {
  41. this.Data["json"] = br
  42. this.ServeJSON()
  43. }()
  44. pageSize, _ := this.GetInt("PageSize")
  45. currentIndex, _ := this.GetInt("CurrentIndex")
  46. timeType := this.GetString("TimeType")
  47. startDate := this.GetString("StartDate")
  48. endDate := this.GetString("EndDate")
  49. frequency := this.GetString("Frequency")
  50. classifyIdFirst, _ := this.GetInt("ClassifyIdFirst", 0)
  51. classifyIdSecond, _ := this.GetInt("ClassifyIdSecond", 0)
  52. classifyIdThird, _ := this.GetInt("ClassifyIdThird", 0)
  53. state, _ := this.GetInt("State")
  54. keyWord := this.GetString("KeyWord")
  55. msgIsSend, _ := this.GetInt("MsgIsSend")
  56. filterReportType, _ := this.GetInt("FilterReportType", 1)
  57. var startSize int
  58. if pageSize <= 0 {
  59. pageSize = utils.PageSize20
  60. }
  61. if currentIndex <= 0 {
  62. currentIndex = 1
  63. }
  64. startSize = utils.StartIndex(currentIndex, pageSize)
  65. if timeType == "" {
  66. timeType = "publish_time"
  67. }
  68. if timeType != "publish_time" && timeType != "modify_time" && timeType != "approve_time" {
  69. br.Msg = "请选择正确的时间"
  70. br.ErrMsg = "请选择正确的时间"
  71. return
  72. }
  73. var condition string
  74. var pars []interface{}
  75. if keyWord != "" {
  76. condition += ` AND (a.title LIKE ? OR a.admin_real_name LIKE ? ) `
  77. pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  78. }
  79. if startDate != "" {
  80. condition += ` AND a.` + timeType + ` >= ? `
  81. pars = append(pars, startDate)
  82. }
  83. if endDate != "" {
  84. condition += ` AND a.` + timeType + ` <= ? `
  85. pars = append(pars, endDate)
  86. }
  87. if frequency != "" {
  88. condition += ` AND a.frequency = ? `
  89. pars = append(pars, frequency)
  90. }
  91. if classifyIdFirst > 0 {
  92. condition += ` AND a.classify_id_first = ? `
  93. pars = append(pars, classifyIdFirst)
  94. }
  95. if classifyIdSecond > 0 {
  96. condition += ` AND a.classify_id_second = ? `
  97. pars = append(pars, classifyIdSecond)
  98. }
  99. if classifyIdThird > 0 {
  100. condition += ` AND a.classify_id_third = ? `
  101. pars = append(pars, classifyIdThird)
  102. }
  103. if state > 0 {
  104. condition += ` AND a.state = ? `
  105. pars = append(pars, state)
  106. }
  107. // 消息是否已推送 1-未推送; 2-已推送
  108. if msgIsSend == 1 {
  109. condition += ` AND (a.msg_is_send = 0 OR a.ths_msg_is_send = 0) `
  110. }
  111. if msgIsSend == 2 {
  112. condition += ` AND a.msg_is_send = 1 AND a.ths_msg_is_send = 1 `
  113. }
  114. var err error
  115. var total int
  116. var list []*models.ReportList
  117. switch filterReportType {
  118. // 筛选报告类型,1:公共研报,2:共享研报,3:我的研报
  119. case 1:
  120. condition += ` AND a.is_public_publish = ? `
  121. pars = append(pars, 1)
  122. condition += ` AND a.state in (2,6) `
  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([]int, 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, list[i].Id)
  167. if list[i].OldReportId > 0 && list[i].ReportLayout == 1 {
  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. {
  237. grantObj := report.ReportGrant{}
  238. grantList, err := grantObj.GetGrantListByIdList(reportIdArr)
  239. if err != nil {
  240. br.Msg = "获取失败"
  241. br.ErrMsg = "获取报告授权失败,Err:" + err.Error()
  242. return
  243. }
  244. //grantMap := make(map[报告id]map[用户id]bool)
  245. grantMap := make(map[int]map[int]bool)
  246. for _, v := range grantList {
  247. grantUserMap, ok := grantMap[v.ReportId]
  248. if !ok {
  249. grantUserMap = make(map[int]bool)
  250. }
  251. grantUserMap[v.AdminId] = true
  252. grantMap[v.ReportId] = grantUserMap
  253. }
  254. for i, item := range list {
  255. if item.AdminId == this.SysUser.AdminId {
  256. list[i].HasAuth = true
  257. continue
  258. }
  259. // 查找授权
  260. var hasAuth bool
  261. grantUserMap, ok := grantMap[item.Id]
  262. // 如果报告根本没有授权用户,说明没有授权当前用户
  263. if !ok {
  264. continue
  265. }
  266. _, ok = grantUserMap[this.SysUser.AdminId]
  267. list[i].HasAuth = hasAuth
  268. // 如果报告关联用户找到,说明有授权当前用户
  269. if ok {
  270. list[i].HasAuth = true
  271. }
  272. }
  273. }
  274. }
  275. for _, item := range list {
  276. /*key := fmt.Sprint(`crm:report:edit:`, item.Id)
  277. opUserId, _ := utils.Rc.RedisInt(key)
  278. //如果当前没有人操作,获取当前操作人是本人,那么编辑按钮可用
  279. if opUserId <= 0 || (opUserId == this.SysUser.AdminId) || item.ClassifyNameFirst == "周报" || item.ClassifyNameFirst == "晨报" {
  280. item.CanEdit = true
  281. } else {
  282. adminInfo, errAdmin := system.GetSysUserById(opUserId)
  283. if errAdmin != nil {
  284. br.Msg = "获取失败"
  285. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  286. return
  287. }
  288. item.Editor = adminInfo.RealName
  289. }*/
  290. if item.HasChapter == 1 {
  291. item.CanEdit = true
  292. continue
  293. }
  294. markStatus, err := services.UpdateReportEditMark(item.Id, 0, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  295. if err != nil {
  296. br.Msg = "查询标记状态失败"
  297. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  298. return
  299. }
  300. if markStatus.Status == 0 {
  301. item.CanEdit = true
  302. } else {
  303. item.Editor = markStatus.Editor
  304. }
  305. }
  306. page := paging.GetPaging(currentIndex, pageSize, total)
  307. resp := new(models.ReportListResp)
  308. resp.Paging = page
  309. resp.List = list
  310. br.Ret = 200
  311. br.Success = true
  312. br.Msg = "获取成功"
  313. br.Data = resp
  314. }
  315. // Add
  316. // @Title 新增报告接口
  317. // @Description 新增报告(不区分报告类型)
  318. // @Param request body models.AddReq true "type json string"
  319. // @Success 200 {object} models.AddResp
  320. // @router /add [post]
  321. func (this *ReportController) Add() {
  322. br := new(models.BaseResponse).Init()
  323. defer func() {
  324. this.Data["json"] = br
  325. this.ServeJSON()
  326. }()
  327. sysUser := this.SysUser
  328. if sysUser == nil {
  329. br.Msg = "请登录"
  330. br.ErrMsg = "请登录,SysUser Is Empty"
  331. br.Ret = 408
  332. return
  333. }
  334. var req models.AddReq
  335. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  336. if err != nil {
  337. br.Msg = "参数解析异常!"
  338. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  339. return
  340. }
  341. if req.Title == `` {
  342. br.Msg = "标题不能为空"
  343. br.ErrMsg = "标题不能为空"
  344. br.IsSendEmail = false
  345. return
  346. }
  347. if req.ClassifyIdFirst <= 0 {
  348. br.Msg = "分类必填"
  349. br.ErrMsg = "分类必填"
  350. br.IsSendEmail = false
  351. return
  352. }
  353. var contentSub string
  354. if req.Content != "" {
  355. e := utils.ContentXssCheck(req.Content)
  356. if e != nil {
  357. br.Msg = "存在非法标签"
  358. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  359. return
  360. }
  361. content, e := services.FilterReportContentBr(req.Content)
  362. if e != nil {
  363. br.Msg = "内容去除前后空格失败"
  364. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  365. return
  366. }
  367. req.Content = content
  368. contentSub, err = services.GetReportContentSub(req.Content)
  369. if err != nil {
  370. go alarm_msg.SendAlarmMsg("ContentSub 失败,Err:"+err.Error(), 3)
  371. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  372. }
  373. }
  374. // 报告期数
  375. maxStage, err := models.GetReportStage(req.ClassifyIdFirst, req.ClassifyIdSecond, req.ClassifyIdThird)
  376. if err != nil {
  377. br.Msg = "期数获取失败!"
  378. br.ErrMsg = "期数获取失败,Err:" + err.Error()
  379. return
  380. }
  381. // 根据审批开关及审批流判断当前报告状态
  382. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, req.ClassifyIdFirst, req.ClassifyIdSecond, req.ClassifyIdThird, models.ReportOperateAdd)
  383. if e != nil {
  384. br.Msg = "操作失败"
  385. br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
  386. return
  387. }
  388. // 协作方式,1:个人,2:多人协作。默认:1
  389. if req.CollaborateType == 0 {
  390. req.CollaborateType = 1
  391. }
  392. // 报告布局,1:常规布局,2:智能布局。默认:1
  393. if req.ReportLayout == 0 {
  394. req.ReportLayout = 1
  395. }
  396. // 是否公开发布,1:是,2:否
  397. req.IsPublicPublish = 2 // 本地报告固定不公开
  398. //if req.IsPublicPublish == 0 {
  399. // req.IsPublicPublish = 1
  400. //}
  401. classifyItemList, err := models.GetClassifyListByIdList([]int{req.ClassifyIdFirst, req.ClassifyIdSecond, req.ClassifyIdThird})
  402. classifyMap := make(map[int]string)
  403. for _, v := range classifyItemList {
  404. classifyMap[v.Id] = v.ClassifyName
  405. }
  406. item := new(models.Report)
  407. item.AddType = req.AddType
  408. item.ReportVersion = 2
  409. item.ClassifyIdFirst = req.ClassifyIdFirst
  410. item.ClassifyNameFirst = classifyMap[req.ClassifyIdFirst]
  411. item.ClassifyIdSecond = req.ClassifyIdSecond
  412. item.ClassifyNameSecond = classifyMap[req.ClassifyIdSecond]
  413. item.Title = req.Title
  414. item.Abstract = req.Abstract
  415. item.Author = req.Author
  416. item.Frequency = req.Frequency
  417. item.State = state
  418. item.Content = html.EscapeString(req.Content)
  419. item.Stage = maxStage + 1
  420. item.ContentSub = html.EscapeString(contentSub)
  421. if req.CreateTime != `` {
  422. formatDate := utils.FormatDateTime
  423. if !strings.Contains(req.CreateTime, ":") {
  424. formatDate = utils.FormatDate
  425. }
  426. createTime, tmpErr := time.ParseInLocation(formatDate, req.CreateTime, time.Local)
  427. if tmpErr != nil {
  428. br.Msg = "时间解析异常"
  429. br.ErrMsg = "时间解析异常,Err:" + err.Error()
  430. return
  431. }
  432. item.CreateTime = createTime
  433. }
  434. item.ModifyTime = time.Now()
  435. item.ReportVersion = req.ReportVersion
  436. item.AdminId = sysUser.AdminId
  437. item.AdminRealName = sysUser.RealName
  438. item.ClassifyIdThird = req.ClassifyIdThird
  439. item.ClassifyNameThird = classifyMap[req.ClassifyIdThird]
  440. // 产品要求,如果是多人协作,那么就是章节类型的报告
  441. if req.CollaborateType == 2 {
  442. item.HasChapter = 1
  443. item.ChapterType = ""
  444. }
  445. item.LastModifyAdminId = sysUser.AdminId
  446. item.LastModifyAdminName = sysUser.RealName
  447. item.ContentModifyTime = time.Now()
  448. item.NeedSplice = 1
  449. item.ContentStruct = html.EscapeString(req.ContentStruct)
  450. item.HeadImg = req.HeadImg
  451. item.EndImg = req.EndImg
  452. item.CanvasColor = req.CanvasColor
  453. item.HeadResourceId = req.HeadResourceId
  454. item.EndResourceId = req.EndResourceId
  455. item.CollaborateType = req.CollaborateType
  456. item.ReportLayout = req.ReportLayout
  457. item.IsPublicPublish = req.IsPublicPublish
  458. item.ReportCreateTime = time.Now()
  459. item.ReportSource = utils.ReportSourceLocal
  460. err, errMsg := services.AddReportAndChapter(item, req.InheritReportId, req.GrantAdminIdList)
  461. if err != nil {
  462. br.Msg = "保存失败"
  463. if errMsg != "" {
  464. br.Msg = errMsg
  465. }
  466. br.ErrMsg = "保存失败,Err:" + err.Error()
  467. return
  468. }
  469. recordItem := &models.ReportStateRecord{
  470. ReportId: item.Id,
  471. ReportType: 1,
  472. State: 1,
  473. AdminId: this.SysUser.AdminId,
  474. AdminName: this.SysUser.AdminName,
  475. CreateTime: time.Now(),
  476. }
  477. go func() {
  478. _, _ = models.AddReportStateRecord(recordItem)
  479. }()
  480. resp := new(models.AddResp)
  481. resp.ReportId = int64(item.Id)
  482. resp.ReportCode = item.ReportCode
  483. br.Ret = 200
  484. br.Success = true
  485. br.Msg = "保存成功"
  486. br.Data = resp
  487. }
  488. // Edit
  489. // @Title 编辑报告基础信息接口
  490. // @Description 编辑报告基础信息(不区分报告类型)
  491. // @Param request body models.EditReq true "type json string"
  492. // @Success 200 {object} models.EditResp
  493. // @router /edit [post]
  494. func (this *ReportController) Edit() {
  495. br := new(models.BaseResponse).Init()
  496. defer func() {
  497. this.Data["json"] = br
  498. this.ServeJSON()
  499. }()
  500. sysUser := this.SysUser
  501. if sysUser == nil {
  502. br.Msg = "请登录"
  503. br.ErrMsg = "请登录,SysUser Is Empty"
  504. br.Ret = 408
  505. return
  506. }
  507. var req models.EditReq
  508. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  509. if err != nil {
  510. br.Msg = "参数解析异常!"
  511. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  512. return
  513. }
  514. //if req.Content == "" {
  515. // br.Msg = "报告内容不能为空"
  516. // return
  517. //}
  518. //更新标记key
  519. markStatus, err := services.UpdateReportEditMark(int(req.ReportId), 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  520. if err != nil {
  521. br.Msg = err.Error()
  522. return
  523. }
  524. if markStatus.Status == 1 {
  525. br.Msg = markStatus.Msg
  526. //br.Ret = 202 //202 服务器已接受请求,但尚未处理。
  527. return
  528. }
  529. reportInfo, e := models.GetReportByReportId(int(req.ReportId))
  530. if e != nil {
  531. if utils.IsErrNoRow(e) {
  532. br.Msg = "报告已被删除, 请刷新页面"
  533. return
  534. }
  535. br.Msg = "操作失败"
  536. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  537. return
  538. }
  539. if reportInfo.State == models.ReportStatePublished || reportInfo.State == models.ReportStatePass {
  540. br.Msg = "该报告已发布,不允许编辑"
  541. br.ErrMsg = "该报告已发布,不允许编辑"
  542. br.IsSendEmail = false
  543. return
  544. }
  545. // 编辑报告信息
  546. err, errMsg := services.EditReport(reportInfo, req, sysUser)
  547. if err != nil {
  548. br.Msg = "保存失败"
  549. if errMsg != "" {
  550. br.Msg = errMsg
  551. }
  552. br.ErrMsg = "保存失败,Err:" + err.Error()
  553. return
  554. }
  555. reportCode := utils.MD5(strconv.Itoa(int(req.ReportId)))
  556. resp := new(models.EditResp)
  557. resp.ReportId = req.ReportId
  558. resp.ReportCode = reportCode
  559. br.Ret = 200
  560. br.Success = true
  561. br.Msg = "保存成功"
  562. br.Data = resp
  563. }
  564. // Detail
  565. // @Title 获取报告详情接口
  566. // @Description 获取报告详情
  567. // @Param request body models.ReportDetailReq true "type json string"
  568. // @Success 200 {object} models.Report
  569. // @router /detail [get]
  570. func (this *ReportController) Detail() {
  571. br := new(models.BaseResponse).Init()
  572. defer func() {
  573. this.Data["json"] = br
  574. this.ServeJSON()
  575. }()
  576. /*var req models.ReportDetailReq
  577. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  578. if err != nil {
  579. br.Msg = "参数解析异常!"
  580. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  581. return
  582. }
  583. if req.ReportId <= 0 {
  584. br.Msg = "参数错误"
  585. return
  586. }*/
  587. reportId, err := this.GetInt("ReportId")
  588. if err != nil {
  589. br.Msg = "获取参数失败!"
  590. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  591. return
  592. }
  593. if reportId <= 0 {
  594. br.Msg = "参数错误"
  595. return
  596. }
  597. item, err := models.GetReportById(reportId)
  598. if err != nil {
  599. if utils.IsErrNoRow(err) {
  600. br.Msg = "报告已被删除"
  601. return
  602. }
  603. br.Msg = "获取失败"
  604. br.ErrMsg = "获取失败,Err:" + err.Error()
  605. return
  606. }
  607. chapterList := make([]*models.ReportChapter, 0)
  608. if item.HasChapter == 1 {
  609. // 获取章节内容
  610. tmpChapterList, err := models.GetPublishedChapterListByReportId(item.Id)
  611. if err != nil {
  612. br.Msg = "获取失败"
  613. br.ErrMsg = "获取晨/周报章节列表失败, Err: " + err.Error()
  614. return
  615. }
  616. if len(tmpChapterList) > 0 {
  617. // 章节类型的字段赋值
  618. for _, item := range tmpChapterList {
  619. item.Content = html.UnescapeString(item.Content)
  620. item.ContentSub = html.UnescapeString(item.ContentSub)
  621. chapterList = append(chapterList, item)
  622. }
  623. }
  624. //item.Abstract = item.Title
  625. }
  626. item.Content = html.UnescapeString(item.Content)
  627. item.ContentSub = html.UnescapeString(item.ContentSub)
  628. item.ContentStruct = html.UnescapeString(item.ContentStruct)
  629. if item.HeadResourceId > 0 {
  630. headResource, err := smart_report.GetResourceItemById(item.HeadResourceId)
  631. if err != nil {
  632. br.Msg = "操作失败"
  633. br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
  634. return
  635. }
  636. item.HeadImg = headResource.ImgUrl
  637. item.HeadStyle = headResource.Style
  638. }
  639. if item.EndResourceId > 0 {
  640. endResource, err := smart_report.GetResourceItemById(item.EndResourceId)
  641. if err != nil {
  642. br.Msg = "操作失败"
  643. br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
  644. return
  645. }
  646. item.EndImg = endResource.ImgUrl
  647. item.EndStyle = endResource.Style
  648. }
  649. resp := &models.ReportDetailView{
  650. ReportDetail: item,
  651. ChapterList: chapterList,
  652. }
  653. br.Ret = 200
  654. br.Success = true
  655. br.Msg = "获取成功"
  656. br.Data = resp
  657. }
  658. // SaveReportContent
  659. // @Title 保存草稿
  660. // @Description 保存草稿
  661. // @Param request body models.SaveReportContent true "type json string"
  662. // @Success 200 {object} models.ReportAuthorResp
  663. // @router /saveReportContent [post]
  664. func (this *ReportController) SaveReportContent() {
  665. br := new(models.BaseResponse).Init()
  666. br.IsSendEmail = false
  667. defer func() {
  668. this.Data["json"] = br
  669. this.ServeJSON()
  670. }()
  671. sysUser := this.SysUser
  672. if sysUser == nil {
  673. br.Msg = "请登录"
  674. br.ErrMsg = "请登录,SysUser Is Empty"
  675. br.Ret = 408
  676. return
  677. }
  678. var req models.SaveReportContent
  679. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  680. if err != nil {
  681. br.Msg = "参数解析异常!"
  682. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  683. return
  684. }
  685. reportId := req.ReportId
  686. noChangeFlag := req.NoChange
  687. if reportId <= 0 {
  688. resp := new(models.SaveReportContentResp)
  689. resp.ReportId = reportId
  690. br.Ret = 200
  691. br.Success = true
  692. br.Msg = "保存成功"
  693. br.Data = resp
  694. return
  695. }
  696. // 获取报告详情
  697. reportInfo, _ := models.GetReportByReportId(req.ReportId)
  698. if reportInfo != nil && reportInfo.State == 2 {
  699. br.Msg = "该报告已发布,不允许编辑"
  700. br.ErrMsg = "该报告已发布,不允许编辑"
  701. br.IsSendEmail = false
  702. return
  703. }
  704. // 标记更新中
  705. {
  706. markStatus, err := services.UpdateReportEditMark(req.ReportId, 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  707. if err != nil {
  708. br.Msg = err.Error()
  709. return
  710. }
  711. if markStatus.Status == 1 {
  712. br.Msg = markStatus.Msg
  713. return
  714. }
  715. }
  716. // 内容有过修改的话,那么逻辑处理
  717. if noChangeFlag != 1 {
  718. content := req.Content
  719. if content == "" {
  720. content = this.GetString("Content")
  721. }
  722. if content != "" {
  723. e := utils.ContentXssCheck(req.Content)
  724. if e != nil {
  725. br.Msg = "存在非法标签"
  726. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  727. return
  728. }
  729. contentClean, e := services.FilterReportContentBr(req.Content)
  730. if e != nil {
  731. br.Msg = "内容去除前后空格失败"
  732. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  733. return
  734. }
  735. content = contentClean
  736. contentSub, err := services.GetReportContentSub(content)
  737. if err != nil {
  738. go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
  739. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  740. }
  741. reportInfo.Content = html.EscapeString(content)
  742. reportInfo.ContentSub = html.EscapeString(contentSub)
  743. reportInfo.ContentStruct = html.EscapeString(req.ContentStruct)
  744. reportInfo.HeadImg = req.HeadImg
  745. reportInfo.EndImg = req.EndImg
  746. reportInfo.CanvasColor = req.CanvasColor
  747. reportInfo.HeadResourceId = req.HeadResourceId
  748. reportInfo.EndResourceId = req.EndResourceId
  749. reportInfo.ModifyTime = time.Now()
  750. reportInfo.ContentModifyTime = time.Now()
  751. updateCols := []string{"Content", "ContentSub", "ContentStruct", "HeadImg", "EndImg", "CanvasColor", "HeadResourceId", "EndResourceId", "ModifyTime", "ContentModifyTime"}
  752. err = reportInfo.UpdateReport(updateCols)
  753. if err != nil {
  754. br.Msg = "保存失败"
  755. br.ErrMsg = "保存失败,Err:" + err.Error()
  756. return
  757. }
  758. go models.AddReportSaveLog(reportId, this.SysUser.AdminId, reportInfo.Content, reportInfo.ContentSub, reportInfo.ContentStruct, reportInfo.CanvasColor, this.SysUser.AdminName, reportInfo.HeadResourceId, reportInfo.EndResourceId)
  759. }
  760. }
  761. resp := new(models.SaveReportContentResp)
  762. resp.ReportId = reportId
  763. br.Ret = 200
  764. br.Success = true
  765. br.Msg = "保存成功"
  766. br.Data = resp
  767. }
  768. // AuthorizedListReport
  769. // @Title 获取有权限的报告列表接口
  770. // @Description 获取有权限的报告列表接口
  771. // @Param PageSize query int true "每页数据条数"
  772. // @Param CurrentIndex query int true "当前页页码,从1开始"
  773. // @Param Keyword query string true "搜索关键词"
  774. // @Param ClassifyIdFirst query int true "一级分类id"
  775. // @Param ClassifyIdSecond query int true "二级分类id"
  776. // @Param ClassifyIdThird query int true "三级分类id"
  777. // @Success 200 {object} models.ReportListResp
  778. // @router /list/authorized [get]
  779. func (this *ReportController) AuthorizedListReport() {
  780. br := new(models.BaseResponse).Init()
  781. defer func() {
  782. this.Data["json"] = br
  783. this.ServeJSON()
  784. }()
  785. pageSize, _ := this.GetInt("PageSize")
  786. currentIndex, _ := this.GetInt("CurrentIndex")
  787. keyword := this.GetString("Keyword")
  788. classifyIdFirst, _ := this.GetInt("ClassifyIdFirst", 0)
  789. classifyIdSecond, _ := this.GetInt("ClassifyIdSecond", 0)
  790. classifyIdThird, _ := this.GetInt("ClassifyIdThird", 0)
  791. state := this.GetString("State")
  792. var startSize int
  793. if pageSize <= 0 {
  794. pageSize = utils.PageSize20
  795. }
  796. if currentIndex <= 0 {
  797. currentIndex = 1
  798. }
  799. startSize = utils.StartIndex(currentIndex, pageSize)
  800. var list []*models.ReportList
  801. // 没有输入信息,那就不展示
  802. if keyword == `` && classifyIdFirst <= 0 {
  803. page := paging.GetPaging(currentIndex, pageSize, 0)
  804. resp := new(models.ReportListResp)
  805. resp.Paging = page
  806. resp.List = list
  807. br.Ret = 200
  808. br.Success = true
  809. br.Msg = "获取成功"
  810. br.Data = resp
  811. return
  812. }
  813. // 当前用户有权限的报告id列表
  814. grantReportIdList := make([]int, 0)
  815. {
  816. obj := report.ReportGrant{}
  817. grantList, err := obj.GetGrantListByAdminId(this.SysUser.AdminId)
  818. if err != nil {
  819. br.Msg = "获取失败"
  820. br.ErrMsg = "获取授权报告id失败,Err:" + err.Error()
  821. return
  822. }
  823. for _, v := range grantList {
  824. grantReportIdList = append(grantReportIdList, v.ReportId)
  825. }
  826. }
  827. var condition string
  828. var pars []interface{}
  829. if classifyIdFirst > 0 {
  830. condition += ` AND a.classify_id_first = ? `
  831. pars = append(pars, classifyIdFirst)
  832. }
  833. if classifyIdSecond > 0 {
  834. condition += ` AND a.classify_id_second = ? `
  835. pars = append(pars, classifyIdSecond)
  836. }
  837. if classifyIdThird > 0 {
  838. condition += ` AND a.classify_id_third = ? `
  839. pars = append(pars, classifyIdThird)
  840. }
  841. if keyword != `` {
  842. condition += ` AND a.title LIKE ? `
  843. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  844. }
  845. var err error
  846. var total int
  847. orCondition := `AND ( (a.is_public_publish = ? AND a.state in (2,6)) or a.admin_id = ? `
  848. pars = append(pars, 1, this.SysUser.AdminId)
  849. if state != `` {
  850. }
  851. // 当前用户有权限的报告id列表
  852. num := len(grantReportIdList)
  853. if num > 0 {
  854. orCondition += ` OR a.id in (` + utils.GetOrmInReplace(num) + `)`
  855. pars = append(pars, grantReportIdList)
  856. }
  857. orCondition += ` ) `
  858. condition += orCondition
  859. total, err = models.GetReportListCountByAuthorized(condition, pars)
  860. if err != nil {
  861. br.Msg = "获取失败"
  862. br.ErrMsg = "获取失败,Err:" + err.Error()
  863. return
  864. }
  865. list, err = models.GetReportListByAuthorized(condition, pars, startSize, pageSize)
  866. if err != nil {
  867. br.Msg = "获取失败"
  868. br.ErrMsg = "获取失败,Err:" + err.Error()
  869. return
  870. }
  871. //for _, item := range list {
  872. // if item.HasChapter == 1 {
  873. // item.CanEdit = true
  874. // } else {
  875. // markStatus, err := services.UpdateReportEditMark(item.Id, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  876. // if err != nil {
  877. // br.Msg = "查询标记状态失败"
  878. // br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  879. // return
  880. // }
  881. // if markStatus.Status == 0 {
  882. // item.CanEdit = true
  883. // } else {
  884. // item.Editor = markStatus.Editor
  885. // }
  886. // }
  887. //}
  888. page := paging.GetPaging(currentIndex, pageSize, total)
  889. resp := new(models.ReportListResp)
  890. resp.Paging = page
  891. resp.List = list
  892. br.Ret = 200
  893. br.Success = true
  894. br.Msg = "获取成功"
  895. br.Data = resp
  896. }
  897. // BaseDetail
  898. // @Title 获取报告基础信息详情接口
  899. // @Description 获取报告基础信息详情接口
  900. // @Param request body models.ReportDetailReq true "type json string"
  901. // @Success 200 {object} models.Report
  902. // @router /detail/base [get]
  903. func (this *ReportController) BaseDetail() {
  904. br := new(models.BaseResponse).Init()
  905. defer func() {
  906. this.Data["json"] = br
  907. this.ServeJSON()
  908. }()
  909. /*var req models.ReportDetailReq
  910. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  911. if err != nil {
  912. br.Msg = "参数解析异常!"
  913. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  914. return
  915. }
  916. if req.ReportId <= 0 {
  917. br.Msg = "参数错误"
  918. return
  919. }*/
  920. reportId, err := this.GetInt("ReportId")
  921. if err != nil {
  922. br.Msg = "获取参数失败!"
  923. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  924. return
  925. }
  926. if reportId <= 0 {
  927. br.Msg = "参数错误"
  928. return
  929. }
  930. reportInfo, err := models.GetReportById(reportId)
  931. if err != nil {
  932. if utils.IsErrNoRow(err) {
  933. br.Msg = "报告已被删除"
  934. return
  935. }
  936. br.Msg = "获取失败"
  937. br.ErrMsg = "获取失败,Err:" + err.Error()
  938. return
  939. }
  940. fmt.Println(reportInfo)
  941. // 基础信息就不获取章节信息了
  942. chapterList := make([]*models.ReportChapter, 0)
  943. reportInfo.Content = html.UnescapeString(reportInfo.Content)
  944. reportInfo.ContentSub = html.UnescapeString(reportInfo.ContentSub)
  945. grandAdminList := make([]models.ReportDetailViewAdmin, 0)
  946. permissionList := make([]models.ReportDetailViewPermission, 0)
  947. // 处理报告授权用户列表
  948. {
  949. obj := report.ReportGrant{}
  950. grantList, tmpErr := obj.GetGrantListById(reportId)
  951. if tmpErr != nil {
  952. br.Msg = "获取章节id授权用户列表失败"
  953. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  954. return
  955. }
  956. if len(grantList) > 0 {
  957. grandAdminIdList := make([]int, 0)
  958. for _, v := range grantList {
  959. grandAdminIdList = append(grandAdminIdList, v.AdminId)
  960. }
  961. adminList, tmpErr := system.GetAdminListByIdList(grandAdminIdList)
  962. if tmpErr != nil {
  963. br.Msg = "获取章节id授权用户列表失败"
  964. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  965. return
  966. }
  967. for _, v := range adminList {
  968. grandAdminList = append(grandAdminList, models.ReportDetailViewAdmin{
  969. AdminId: v.AdminId,
  970. AdminName: v.RealName,
  971. })
  972. }
  973. }
  974. }
  975. // 处理章节id关联品种id列表
  976. {
  977. minClassifyId := reportInfo.ClassifyIdThird
  978. if minClassifyId <= 0 {
  979. minClassifyId = reportInfo.ClassifyIdSecond
  980. }
  981. if minClassifyId <= 0 {
  982. minClassifyId = reportInfo.ClassifyIdFirst
  983. }
  984. if minClassifyId <= 0 {
  985. br.Msg = "分类异常"
  986. br.ErrMsg = "分类异常"
  987. return
  988. }
  989. // 获取分类关联的品种id
  990. classifyPermissionList, tmpErr := models.GetPermission(minClassifyId)
  991. if tmpErr != nil {
  992. br.Msg = "获取分类信息失败"
  993. br.ErrMsg = "获取失败,Err:" + tmpErr.Error()
  994. return
  995. }
  996. if len(classifyPermissionList) > 0 {
  997. permissionIdList := make([]int, 0)
  998. for _, v := range classifyPermissionList {
  999. permissionIdList = append(permissionIdList, v.ChartPermissionId)
  1000. }
  1001. adminList, tmpErr := models.GetChartPermissionByIdList(permissionIdList)
  1002. if tmpErr != nil {
  1003. br.Msg = "获取章节id授权用户列表失败"
  1004. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  1005. return
  1006. }
  1007. for _, v := range adminList {
  1008. permissionList = append(permissionList, models.ReportDetailViewPermission{
  1009. PermissionId: v.ChartPermissionId,
  1010. PermissionName: v.PermissionName,
  1011. })
  1012. }
  1013. }
  1014. }
  1015. resp := &models.ReportDetailView{
  1016. ReportDetail: reportInfo,
  1017. ChapterList: chapterList,
  1018. GrandAdminList: grandAdminList,
  1019. PermissionList: permissionList,
  1020. }
  1021. br.Ret = 200
  1022. br.Success = true
  1023. br.Msg = "获取成功"
  1024. br.Data = resp
  1025. }
  1026. // EditLayoutImg
  1027. // @Title 版图设置接口
  1028. // @Description 版图设置接口
  1029. // @Param request body models.EditLayoutImgReq true "type json string"
  1030. // @Success 200 {object} models.EditResp
  1031. // @router /layout_img/edit [post]
  1032. func (this *ReportController) EditLayoutImg() {
  1033. br := new(models.BaseResponse).Init()
  1034. defer func() {
  1035. this.Data["json"] = br
  1036. this.ServeJSON()
  1037. }()
  1038. sysUser := this.SysUser
  1039. if sysUser == nil {
  1040. br.Msg = "请登录"
  1041. br.ErrMsg = "请登录,SysUser Is Empty"
  1042. br.Ret = 408
  1043. return
  1044. }
  1045. var req models.EditLayoutImgReq
  1046. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1047. if err != nil {
  1048. br.Msg = "参数解析异常!"
  1049. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1050. return
  1051. }
  1052. //if req.Content == "" {
  1053. // br.Msg = "报告内容不能为空"
  1054. // return
  1055. //}
  1056. //更新标记key
  1057. markStatus, err := services.UpdateReportEditMark(int(req.ReportId), 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  1058. if err != nil {
  1059. br.Msg = err.Error()
  1060. return
  1061. }
  1062. if markStatus.Status == 1 {
  1063. br.Msg = markStatus.Msg
  1064. //br.Ret = 202 //202 服务器已接受请求,但尚未处理。
  1065. return
  1066. }
  1067. reportInfo, e := models.GetReportByReportId(int(req.ReportId))
  1068. if e != nil {
  1069. if utils.IsErrNoRow(e) {
  1070. br.Msg = "报告已被删除, 请刷新页面"
  1071. return
  1072. }
  1073. br.Msg = "操作失败"
  1074. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  1075. return
  1076. }
  1077. if reportInfo.State == models.ReportStatePublished || reportInfo.State == models.ReportStatePass {
  1078. br.Msg = "该报告已发布,不允许编辑"
  1079. br.ErrMsg = "该报告已发布,不允许编辑"
  1080. br.IsSendEmail = false
  1081. return
  1082. }
  1083. // 编辑报告信息
  1084. err, errMsg := services.EditReportLayoutImg(reportInfo, req, sysUser)
  1085. if err != nil {
  1086. br.Msg = "保存失败"
  1087. if errMsg != "" {
  1088. br.Msg = errMsg
  1089. }
  1090. br.ErrMsg = "保存失败,Err:" + err.Error()
  1091. return
  1092. }
  1093. reportCode := utils.MD5(strconv.Itoa(int(req.ReportId)))
  1094. resp := new(models.EditResp)
  1095. resp.ReportId = req.ReportId
  1096. resp.ReportCode = reportCode
  1097. br.Ret = 200
  1098. br.Success = true
  1099. br.Msg = "保存成功"
  1100. br.Data = resp
  1101. }
  1102. // PublishReport
  1103. // @Title 发布报告接口
  1104. // @Description 发布报告
  1105. // @Param request body models.PublishReq true "type json string"
  1106. // @Success 200 Ret=200 发布成功
  1107. // @router /publish [post]
  1108. func (this *ReportController) PublishReport() {
  1109. br := new(models.BaseResponse).Init()
  1110. defer func() {
  1111. this.Data["json"] = br
  1112. this.ServeJSON()
  1113. }()
  1114. var req models.PublishReq
  1115. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1116. if err != nil {
  1117. br.Msg = "参数解析异常!"
  1118. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1119. return
  1120. }
  1121. reportIds := req.ReportIds
  1122. if reportIds == "" {
  1123. br.Msg = "参数错误"
  1124. br.ErrMsg = "参数错误,报告id不可为空"
  1125. return
  1126. }
  1127. // 这里实际上不会批量发布了...
  1128. reportArr := strings.Split(reportIds, ",")
  1129. tips := ""
  1130. for _, v := range reportArr {
  1131. vint, err := strconv.Atoi(v)
  1132. if err != nil {
  1133. br.Msg = "参数错误"
  1134. br.ErrMsg = "参数错误,Err:" + err.Error()
  1135. return
  1136. }
  1137. // 报告的图表刷新状态校验
  1138. refreshResult := data.CheckBatchChartRefreshResult("report", vint, 0)
  1139. if !refreshResult {
  1140. br.Msg = "图表刷新未完成,请稍后操作"
  1141. br.ErrMsg = "图表刷新未完成,请稍后操作"
  1142. br.IsSendEmail = false
  1143. return
  1144. }
  1145. // 报告发布
  1146. tmpTips, err, errMsg := services.PublishReportV2(vint, this.SysUser)
  1147. if err != nil {
  1148. br.Msg = errMsg
  1149. br.ErrMsg = "报告发布失败,Err:" + err.Error()
  1150. return
  1151. }
  1152. tips = tmpTips
  1153. }
  1154. // 发布晨周报部分章节未发布的提示
  1155. if tips != "" {
  1156. br.Data = tips
  1157. }
  1158. br.Ret = 200
  1159. br.Success = true
  1160. br.Msg = "发布成功"
  1161. }
  1162. // PublishCancelReport
  1163. // @Title 取消发布报告接口
  1164. // @Description 取消发布报告
  1165. // @Param request body models.PublishCancelReq true "type json string"
  1166. // @Success 200 Ret=200 取消发布成功
  1167. // @router /publish/cancle [post]
  1168. func (this *ReportController) PublishCancelReport() {
  1169. br := new(models.BaseResponse).Init()
  1170. defer func() {
  1171. this.Data["json"] = br
  1172. this.ServeJSON()
  1173. }()
  1174. var req models.PublishCancelReq
  1175. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1176. if err != nil {
  1177. br.Msg = "参数解析异常!"
  1178. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1179. return
  1180. }
  1181. if req.ReportIds <= 0 {
  1182. br.Msg = "参数错误"
  1183. br.ErrMsg = "参数错误,报告id不可为空"
  1184. return
  1185. }
  1186. publishTimeNullFlag := true
  1187. reportInfo, err := models.GetReportById(req.ReportIds)
  1188. if err != nil {
  1189. br.Msg = "获取报告信息失败"
  1190. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  1191. return
  1192. }
  1193. if reportInfo.MsgIsSend == 1 {
  1194. publishTimeNullFlag = false
  1195. }
  1196. // 根据审批开关及审批流判断当前报告状态
  1197. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, reportInfo.ClassifyIdThird, models.ReportOperateCancelPublish)
  1198. if e != nil {
  1199. br.Msg = "操作失败"
  1200. br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
  1201. return
  1202. }
  1203. err = models.PublishCancelReport(req.ReportIds, state, publishTimeNullFlag, this.SysUser.AdminId, this.SysUser.RealName)
  1204. if err != nil {
  1205. br.Msg = "取消发布失败"
  1206. br.ErrMsg = "取消发布失败,Err:" + err.Error()
  1207. return
  1208. }
  1209. // 更新ES禁用
  1210. {
  1211. go services.UpdateReportEs(req.ReportIds, 1)
  1212. }
  1213. //// 获取审批流设置
  1214. //confKey := "approval_flow"
  1215. //confTmp, e := company.GetConfigDetailByCode(confKey)
  1216. //if e != nil {
  1217. // br.Msg = "获取审批流配置失败"
  1218. // br.ErrMsg = "获取审批流配置失败, Err: " + e.Error()
  1219. // return
  1220. //}
  1221. //if confTmp.ConfigValue == "1" || confTmp.ConfigValue == "2" || confTmp.ConfigValue == "3" {
  1222. // br.Msg = "撤销成功"
  1223. //} else {
  1224. // br.Msg = "取消发布成功"
  1225. //}
  1226. recordItem := &models.ReportStateRecord{
  1227. ReportId: req.ReportIds,
  1228. ReportType: 1,
  1229. State: state,
  1230. AdminId: this.SysUser.AdminId,
  1231. AdminName: this.SysUser.AdminName,
  1232. CreateTime: time.Now(),
  1233. }
  1234. go func() {
  1235. _, _ = models.AddReportStateRecord(recordItem)
  1236. }()
  1237. br.Ret = 200
  1238. br.Success = true
  1239. }
  1240. // PrePublishReport
  1241. // @Title 设置定时发布接口
  1242. // @Description 设置定时发布接口
  1243. // @Param request body models.PrePublishReq true "type json string"
  1244. // @Success 200 Ret=200 发布成功
  1245. // @router /pre_publish [post]
  1246. func (this *ReportController) PrePublishReport() {
  1247. br := new(models.BaseResponse).Init()
  1248. defer func() {
  1249. this.Data["json"] = br
  1250. this.ServeJSON()
  1251. }()
  1252. var req models.PrePublishReq
  1253. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1254. if err != nil {
  1255. br.Msg = "参数解析异常!"
  1256. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1257. return
  1258. }
  1259. reportId := req.ReportId
  1260. if reportId == 0 {
  1261. br.Msg = "参数错误"
  1262. br.ErrMsg = "参数错误,报告id不可为空"
  1263. return
  1264. }
  1265. if req.PrePublishTime == "" {
  1266. br.Msg = "发布时间不能为空"
  1267. return
  1268. }
  1269. if req.PreMsgSend != 0 && req.PreMsgSend != 1 {
  1270. br.Msg = "参数错误"
  1271. br.ErrMsg = "是否发送模版消息标识错误"
  1272. return
  1273. }
  1274. prePublishTime, err := time.ParseInLocation(utils.FormatDateTime, req.PrePublishTime, time.Local)
  1275. if err != nil {
  1276. br.Msg = "发布时间格式错误"
  1277. br.ErrMsg = "发布时间格式错误,Err:" + err.Error()
  1278. return
  1279. }
  1280. if prePublishTime.Before(time.Now()) {
  1281. br.Msg = "发布时间不允许选择过去时间"
  1282. return
  1283. }
  1284. if prePublishTime.Before(time.Now().Add(2 * time.Minute)) {
  1285. br.Msg = "发布时间距离当前时间太近了"
  1286. return
  1287. }
  1288. reportDetail, err := models.GetReportById(reportId)
  1289. if err != nil {
  1290. br.Msg = "获取报告信息失败"
  1291. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  1292. return
  1293. }
  1294. if reportDetail == nil {
  1295. br.Msg = "报告不存在"
  1296. return
  1297. }
  1298. // 如果是章节类型的报告,那么需要确认所有章节已发布
  1299. if reportDetail.HasChapter == 1 {
  1300. chapterList, err := models.GetChapterListByReportId(reportId)
  1301. if err != nil {
  1302. return
  1303. }
  1304. for _, chapter := range chapterList {
  1305. if chapter.PublishState == 1 {
  1306. br.Msg = "还存在未发布的章节"
  1307. br.ErrMsg = "还存在未发布的章节"
  1308. return
  1309. }
  1310. }
  1311. } else {
  1312. if reportDetail.Content == "" {
  1313. br.Msg = "报告内容为空,不可设置定时发布"
  1314. br.ErrMsg = "报告内容为空,不可设置定时发布,report_id:" + strconv.Itoa(reportDetail.Id)
  1315. return
  1316. }
  1317. }
  1318. if reportDetail.State == 2 {
  1319. br.Msg = "报告已发布,不可设置定时发布"
  1320. return
  1321. }
  1322. // 校验是否开启了审批流
  1323. opening, e := services.CheckReportOpenApprove(report_approve.FlowReportTypeChinese, reportDetail.ClassifyIdFirst, reportDetail.ClassifyIdSecond, reportDetail.ClassifyIdThird)
  1324. if e != nil {
  1325. br.Msg = "操作失败"
  1326. br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
  1327. return
  1328. }
  1329. if opening {
  1330. br.Msg = "报告已开启审批流, 不可设置定时发布"
  1331. return
  1332. }
  1333. var tmpErr error
  1334. if tmpErr = models.SetPrePublishReportById(reportDetail.Id, req.PrePublishTime, req.PreMsgSend); tmpErr != nil {
  1335. br.Msg = "设置定时发布失败"
  1336. br.ErrMsg = "设置定时发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(reportDetail.Id)
  1337. return
  1338. }
  1339. // 生成报告pdf和长图
  1340. {
  1341. reportPdfUrl := services.GetGeneralPdfUrl(reportDetail.ReportCode, reportDetail.ClassifyNameFirst, reportDetail.ReportLayout)
  1342. go services.Report2pdfAndJpeg(reportPdfUrl, reportDetail.Id, 1)
  1343. }
  1344. br.Ret = 200
  1345. br.Success = true
  1346. br.Msg = "定时发布成功"
  1347. }
  1348. // SubmitApprove
  1349. // @Title 提交审批
  1350. // @Description 提交审批接口
  1351. // @Param request body models.ReportSubmitApproveReq true "type json string"
  1352. // @Success 200 Ret=200 操作成功
  1353. // @router /approve/submit [post]
  1354. func (this *ReportController) SubmitApprove() {
  1355. br := new(models.BaseResponse).Init()
  1356. defer func() {
  1357. if br.ErrMsg == "" {
  1358. br.IsSendEmail = false
  1359. }
  1360. this.Data["json"] = br
  1361. this.ServeJSON()
  1362. }()
  1363. sysUser := this.SysUser
  1364. if sysUser == nil {
  1365. br.Msg = "请登录"
  1366. br.ErrMsg = "请登录,SysUser Is Empty"
  1367. return
  1368. }
  1369. var req models.ReportSubmitApproveReq
  1370. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1371. br.Msg = "参数有误"
  1372. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  1373. return
  1374. }
  1375. reportId := req.ReportId
  1376. if reportId <= 0 {
  1377. br.Msg = "参数有误"
  1378. br.ErrMsg = fmt.Sprintf("参数有误, ReportId: %d", req.ReportId)
  1379. return
  1380. }
  1381. reportOb := new(models.Report)
  1382. reportItem, e := reportOb.GetItemById(reportId)
  1383. if e != nil {
  1384. if utils.IsErrNoRow(e) {
  1385. br.Msg = "报告已被删除, 请刷新页面"
  1386. return
  1387. }
  1388. br.Msg = "操作失败"
  1389. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  1390. return
  1391. }
  1392. // 如果是章节类型的报告,那么需要确认所有章节已发布
  1393. if reportItem.HasChapter == 1 {
  1394. chapterList, err := models.GetChapterListByReportId(reportId)
  1395. if err != nil {
  1396. return
  1397. }
  1398. for _, chapter := range chapterList {
  1399. if chapter.PublishState == 1 {
  1400. br.Msg = "还存在未发布的章节"
  1401. br.ErrMsg = "还存在未发布的章节"
  1402. return
  1403. }
  1404. }
  1405. } else {
  1406. if reportItem.Content == "" {
  1407. br.Msg = "报告内容为空,不可提交"
  1408. br.ErrMsg = "报告内容为空,不可提交,report_id:" + strconv.Itoa(reportItem.Id)
  1409. return
  1410. }
  1411. }
  1412. // 校验当前审批配置, 返回下一个状态
  1413. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, reportItem.ClassifyIdThird, models.ReportOperateSubmitApprove)
  1414. if e != nil {
  1415. br.Msg = "操作失败"
  1416. br.ErrMsg = "校验报告状态失败, Err: " + e.Error()
  1417. return
  1418. }
  1419. // 下一个状态不为待审批时, 仅更新状态
  1420. if state != models.ReportStateWaitApprove {
  1421. reportItem.State = state
  1422. e = reportItem.UpdateReport([]string{"State"})
  1423. if e != nil {
  1424. br.Msg = "操作失败"
  1425. br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1426. return
  1427. }
  1428. br.Ret = 200
  1429. br.Success = true
  1430. br.Msg = "操作成功"
  1431. return
  1432. }
  1433. // 提交审批
  1434. approveId, e := services.SubmitReportApprove(report_approve.FlowReportTypeChinese, reportItem.Id, reportItem.Title, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, reportItem.ClassifyIdThird, sysUser.AdminId, sysUser.RealName)
  1435. if e != nil {
  1436. br.Msg = "操作失败"
  1437. br.ErrMsg = "提交审批失败, Err: " + e.Error()
  1438. return
  1439. }
  1440. reportItem.ApproveId = approveId
  1441. reportItem.State = models.ReportStateWaitApprove
  1442. reportItem.ModifyTime = time.Now().Local()
  1443. e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"})
  1444. if e != nil {
  1445. br.Msg = "操作失败"
  1446. br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1447. return
  1448. }
  1449. // 报告权限处理
  1450. {
  1451. go services.HandleReportPermission(reportItem)
  1452. }
  1453. br.Ret = 200
  1454. br.Success = true
  1455. br.Msg = "操作成功"
  1456. }
  1457. // CancelApprove
  1458. // @Title 撤销审批
  1459. // @Description 撤销审批
  1460. // @Param request body models.ReportCancelApproveReq true "type json string"
  1461. // @Success 200 Ret=200 操作成功
  1462. // @router /approve/cancel [post]
  1463. func (this *ReportController) CancelApprove() {
  1464. br := new(models.BaseResponse).Init()
  1465. defer func() {
  1466. if br.ErrMsg == "" {
  1467. br.IsSendEmail = false
  1468. }
  1469. this.Data["json"] = br
  1470. this.ServeJSON()
  1471. }()
  1472. sysUser := this.SysUser
  1473. if sysUser == nil {
  1474. br.Msg = "请登录"
  1475. br.ErrMsg = "请登录,SysUser Is Empty"
  1476. return
  1477. }
  1478. var req models.ReportCancelApproveReq
  1479. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1480. br.Msg = "参数有误"
  1481. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  1482. return
  1483. }
  1484. reportId := req.ReportId
  1485. if reportId <= 0 {
  1486. br.Msg = "参数有误"
  1487. br.ErrMsg = fmt.Sprintf("参数有误, ReportId: %d", req.ReportId)
  1488. return
  1489. }
  1490. reportOb := new(models.Report)
  1491. reportItem, e := reportOb.GetItemById(reportId)
  1492. if e != nil {
  1493. if utils.IsErrNoRow(e) {
  1494. br.Msg = "报告已被删除, 请刷新页面"
  1495. return
  1496. }
  1497. br.Msg = "操作失败"
  1498. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  1499. return
  1500. }
  1501. // 校验当前审批配置, 返回下一个状态
  1502. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, reportItem.ClassifyIdThird, models.ReportOperateCancelApprove)
  1503. if e != nil {
  1504. br.Msg = "操作失败"
  1505. br.ErrMsg = "校验报告状态失败, Err: " + e.Error()
  1506. return
  1507. }
  1508. // 下一个状态不为待提交时, 仅更新状态
  1509. if state != models.ReportStateWaitSubmit {
  1510. reportItem.State = state
  1511. e = reportItem.UpdateReport([]string{"State"})
  1512. if e != nil {
  1513. br.Msg = "操作失败"
  1514. br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1515. return
  1516. }
  1517. br.Ret = 200
  1518. br.Success = true
  1519. br.Msg = "操作成功"
  1520. return
  1521. }
  1522. //if reportItem.ApproveId <= 0 {
  1523. // br.Msg = "报告审批不存在"
  1524. // br.ErrMsg = fmt.Sprintf("报告审批不存在, ApproveId: %d", reportItem.ApproveId)
  1525. // return
  1526. //}
  1527. // 撤销审批
  1528. e = services.CancelReportApprove(report_approve.FlowReportTypeChinese, reportItem.Id, reportItem.ApproveId, sysUser.AdminId, sysUser.RealName)
  1529. if e != nil {
  1530. br.Msg = "操作失败"
  1531. br.ErrMsg = "撤销审批失败, Err: " + e.Error()
  1532. return
  1533. }
  1534. //reportItem.ApproveId = 0
  1535. //reportItem.State = models.ReportStateWaitSubmit
  1536. //reportItem.ModifyTime = time.Now().Local()
  1537. //e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"})
  1538. //if e != nil {
  1539. // br.Msg = "操作失败"
  1540. // br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1541. // return
  1542. //}
  1543. br.Ret = 200
  1544. br.Success = true
  1545. br.Msg = "操作成功"
  1546. }
  1547. // MessageList
  1548. // @Title 报告消息列表
  1549. // @Description 报告消息列表
  1550. // @Param PageSize query int true "每页数据条数"
  1551. // @Param CurrentIndex query int true "当前页页码"
  1552. // @Success 200 {object} models.ReportMessageListResp
  1553. // @router /message/list [get]
  1554. func (this *ReportController) MessageList() {
  1555. br := new(models.BaseResponse).Init()
  1556. defer func() {
  1557. if br.ErrMsg == "" {
  1558. br.IsSendEmail = false
  1559. }
  1560. this.Data["json"] = br
  1561. this.ServeJSON()
  1562. }()
  1563. sysUser := this.SysUser
  1564. if sysUser == nil {
  1565. br.Msg = "请登录"
  1566. br.ErrMsg = "请登录,SysUser Is Empty"
  1567. br.Ret = 408
  1568. return
  1569. }
  1570. pageSize, _ := this.GetInt("PageSize")
  1571. pageIndex, _ := this.GetInt("CurrentIndex")
  1572. // 分页
  1573. var startSize int
  1574. if pageSize <= 0 {
  1575. pageSize = utils.PageSize20
  1576. }
  1577. if pageIndex <= 0 {
  1578. pageIndex = 1
  1579. }
  1580. startSize = utils.StartIndex(pageIndex, pageSize)
  1581. resp := new(models.ReportMessageListResp)
  1582. resp.List = make([]*models.ReportMessageItem, 0)
  1583. cond := fmt.Sprintf(` AND %s = ?`, models.ReportMessageCols.ReceiveUserId)
  1584. pars := make([]interface{}, 0)
  1585. pars = append(pars, sysUser.AdminId)
  1586. order := fmt.Sprintf(`%s ASC, %s DESC`, models.ReportMessageCols.IsRead, models.ReportMessageCols.CreateTime)
  1587. messageOb := new(models.ReportMessage)
  1588. total, e := messageOb.GetCountByCondition(cond, pars)
  1589. if e != nil {
  1590. br.Msg = "获取失败"
  1591. br.ErrMsg = "获取消息列表总数失败, Err: " + e.Error()
  1592. return
  1593. }
  1594. list, e := messageOb.GetPageItemsByCondition(cond, pars, []string{}, order, startSize, pageSize)
  1595. if e != nil {
  1596. br.Msg = "获取失败"
  1597. br.ErrMsg = "获取消息列表失败, Err: " + e.Error()
  1598. return
  1599. }
  1600. var reportIds, pptIds []int
  1601. for _, v := range list {
  1602. t := models.FormatReportMessage2Item(v)
  1603. if v.ExtraContent != "" {
  1604. am := new(models.ReportMessageApproveItem)
  1605. if e = json.Unmarshal([]byte(v.ExtraContent), &am); e != nil {
  1606. br.Msg = "获取失败"
  1607. br.ErrMsg = fmt.Sprintf("消息列表审批信息解析失败, %v", e)
  1608. return
  1609. }
  1610. t.ApproveMsg = am
  1611. }
  1612. resp.List = append(resp.List, t)
  1613. // 报告状态,这里动态去获取
  1614. if v.ReportType == utils.ReportTypeDefault {
  1615. reportIds = append(reportIds, v.ReportId)
  1616. }
  1617. if v.ReportType == utils.ReportTypePPT {
  1618. pptIds = append(pptIds, v.ReportId)
  1619. }
  1620. }
  1621. stateReport := make(map[int]int)
  1622. statePpt := make(map[int]int)
  1623. if len(reportIds) > 0 {
  1624. ob := new(models.Report)
  1625. cond := ` AND id IN (?)`
  1626. pars := make([]interface{}, 0)
  1627. pars = append(pars, reportIds)
  1628. items, e := ob.GetItemsByCondition(cond, pars, []string{"id", "state"}, "")
  1629. if e != nil {
  1630. br.Msg = "获取失败"
  1631. br.ErrMsg = fmt.Sprintf("获取报告列表失败, %v", e)
  1632. return
  1633. }
  1634. for _, v := range items {
  1635. stateReport[v.Id] = v.State
  1636. }
  1637. }
  1638. if len(pptIds) > 0 {
  1639. ob := new(models.PptV2)
  1640. cond := ` AND ppt_id IN (?)`
  1641. pars := make([]interface{}, 0)
  1642. pars = append(pars, pptIds)
  1643. items, e := ob.GetItemsByCondition(cond, pars, []string{"ppt_id", "state"}, "")
  1644. if e != nil {
  1645. br.Msg = "获取失败"
  1646. br.ErrMsg = fmt.Sprintf("获取PPT列表失败, %v", e)
  1647. return
  1648. }
  1649. for _, v := range items {
  1650. statePpt[v.PptId] = v.State
  1651. }
  1652. }
  1653. for _, v := range resp.List {
  1654. if v.ReportType == utils.ReportTypeDefault {
  1655. v.ReportState = stateReport[v.ReportId]
  1656. }
  1657. if v.ReportType == utils.ReportTypePPT {
  1658. v.ReportState = statePpt[v.ReportId]
  1659. }
  1660. }
  1661. // 未读消息数
  1662. cond += fmt.Sprintf(` AND %s = ?`, models.ReportMessageCols.IsRead)
  1663. pars = append(pars, 0)
  1664. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  1665. if e != nil {
  1666. br.Msg = "获取失败"
  1667. br.ErrMsg = "获取消息列表总数失败, Err: " + e.Error()
  1668. return
  1669. }
  1670. resp.UnreadTotal = unreadTotal
  1671. page := paging.GetPaging(pageIndex, pageSize, total)
  1672. resp.Paging = page
  1673. br.Data = resp
  1674. br.Ret = 200
  1675. br.Success = true
  1676. br.Msg = "获取成功"
  1677. }
  1678. // MessageRead
  1679. // @Title 消息已读
  1680. // @Description 消息已读
  1681. // @Param request body models.ReportMessageReadReq true "type json string"
  1682. // @Success 200 string "操作成功"
  1683. // @router /message/read [post]
  1684. func (this *ReportController) MessageRead() {
  1685. br := new(models.BaseResponse).Init()
  1686. defer func() {
  1687. if br.ErrMsg == "" {
  1688. br.IsSendEmail = false
  1689. }
  1690. this.Data["json"] = br
  1691. this.ServeJSON()
  1692. }()
  1693. sysUser := this.SysUser
  1694. if sysUser == nil {
  1695. br.Msg = "请登录"
  1696. br.ErrMsg = "请登录,SysUser Is Empty"
  1697. br.Ret = 408
  1698. return
  1699. }
  1700. var req models.ReportMessageReadReq
  1701. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1702. br.Msg = "参数有误"
  1703. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  1704. return
  1705. }
  1706. if req.MessageId <= 0 {
  1707. br.Msg = "参数有误"
  1708. br.ErrMsg = fmt.Sprintf("参数有误, MessageId: %d", req.MessageId)
  1709. return
  1710. }
  1711. messageOb := new(models.ReportMessage)
  1712. messageItem, e := messageOb.GetItemById(req.MessageId)
  1713. if e != nil {
  1714. if utils.IsErrNoRow(e) {
  1715. br.Msg = "消息不存在, 请刷新页面"
  1716. return
  1717. }
  1718. br.Msg = "获取失败"
  1719. br.ErrMsg = "获取消息失败, Err: " + e.Error()
  1720. return
  1721. }
  1722. messageItem.IsRead = 1
  1723. messageItem.ModifyTime = time.Now().Local()
  1724. cols := []string{"IsRead", "ModifyTime"}
  1725. if e = messageItem.Update(cols); e != nil {
  1726. br.Msg = "操作失败"
  1727. br.ErrMsg = "更新消息已读失败, Err: " + e.Error()
  1728. return
  1729. }
  1730. br.Ret = 200
  1731. br.Success = true
  1732. br.Msg = "操作成功"
  1733. }