report_v2.go 54 KB

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