report_v2.go 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924
  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. req.Content = services.HandleReportContentTable(int(req.ReportId), req.Content)
  556. req.ContentStruct = services.HandleReportContentStructTable(int(req.ReportId), req.ContentStruct)
  557. // 编辑报告信息
  558. err, errMsg := services.EditReport(reportInfo, req, sysUser)
  559. if err != nil {
  560. br.Msg = "保存失败"
  561. if errMsg != "" {
  562. br.Msg = errMsg
  563. }
  564. br.ErrMsg = "保存失败,Err:" + err.Error()
  565. return
  566. }
  567. reportCode := utils.MD5(strconv.Itoa(int(req.ReportId)))
  568. resp := new(models.EditResp)
  569. resp.ReportId = req.ReportId
  570. resp.ReportCode = reportCode
  571. br.Ret = 200
  572. br.Success = true
  573. br.Msg = "保存成功"
  574. br.Data = resp
  575. }
  576. // Detail
  577. // @Title 获取报告详情接口
  578. // @Description 获取报告详情
  579. // @Param request body models.ReportDetailReq true "type json string"
  580. // @Success 200 {object} models.Report
  581. // @router /detail [get]
  582. func (this *ReportController) Detail() {
  583. br := new(models.BaseResponse).Init()
  584. defer func() {
  585. this.Data["json"] = br
  586. this.ServeJSON()
  587. }()
  588. /*var req models.ReportDetailReq
  589. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  590. if err != nil {
  591. br.Msg = "参数解析异常!"
  592. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  593. return
  594. }
  595. if req.ReportId <= 0 {
  596. br.Msg = "参数错误"
  597. return
  598. }*/
  599. reportId, err := this.GetInt("ReportId")
  600. if err != nil {
  601. br.Msg = "获取参数失败!"
  602. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  603. return
  604. }
  605. if reportId <= 0 {
  606. br.Msg = "参数错误"
  607. return
  608. }
  609. item, err := models.GetReportById(reportId)
  610. if err != nil {
  611. if utils.IsErrNoRow(err) {
  612. br.Msg = "报告已被删除"
  613. return
  614. }
  615. br.Msg = "获取失败"
  616. br.ErrMsg = "获取失败,Err:" + err.Error()
  617. return
  618. }
  619. chapterList := make([]*models.ReportChapter, 0)
  620. if item.HasChapter == 1 {
  621. // 获取章节内容
  622. tmpChapterList, err := models.GetPublishedChapterListByReportId(item.Id)
  623. if err != nil {
  624. br.Msg = "获取失败"
  625. br.ErrMsg = "获取晨/周报章节列表失败, Err: " + err.Error()
  626. return
  627. }
  628. if len(tmpChapterList) > 0 {
  629. // 章节类型的字段赋值
  630. for _, item := range tmpChapterList {
  631. item.Content = html.UnescapeString(item.Content)
  632. item.ContentSub = html.UnescapeString(item.ContentSub)
  633. chapterList = append(chapterList, item)
  634. }
  635. }
  636. //item.Abstract = item.Title
  637. }
  638. item.Content = html.UnescapeString(item.Content)
  639. item.ContentSub = html.UnescapeString(item.ContentSub)
  640. item.ContentStruct = html.UnescapeString(item.ContentStruct)
  641. if item.HeadResourceId > 0 {
  642. headResource, err := smart_report.GetResourceItemById(item.HeadResourceId)
  643. if err != nil {
  644. br.Msg = "操作失败"
  645. br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
  646. return
  647. }
  648. item.HeadImg = headResource.ImgUrl
  649. item.HeadStyle = headResource.Style
  650. }
  651. if item.EndResourceId > 0 {
  652. endResource, err := smart_report.GetResourceItemById(item.EndResourceId)
  653. if err != nil {
  654. br.Msg = "操作失败"
  655. br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
  656. return
  657. }
  658. item.EndImg = endResource.ImgUrl
  659. item.EndStyle = endResource.Style
  660. }
  661. item.Content = services.HandleReportContentTable(item.Id, item.Content)
  662. item.ContentStruct = services.HandleReportContentStructTable(item.Id, item.ContentStruct)
  663. for _, v := range chapterList {
  664. v.Content = services.HandleReportContentTable(item.Id, v.Content)
  665. v.ContentStruct = services.HandleReportContentStructTable(item.Id, v.ContentStruct)
  666. }
  667. resp := &models.ReportDetailView{
  668. ReportDetail: item,
  669. ChapterList: chapterList,
  670. }
  671. br.Ret = 200
  672. br.Success = true
  673. br.Msg = "获取成功"
  674. br.Data = resp
  675. }
  676. // SaveReportContent
  677. // @Title 保存草稿
  678. // @Description 保存草稿
  679. // @Param request body models.SaveReportContent true "type json string"
  680. // @Success 200 {object} models.ReportAuthorResp
  681. // @router /saveReportContent [post]
  682. func (this *ReportController) SaveReportContent() {
  683. br := new(models.BaseResponse).Init()
  684. br.IsSendEmail = false
  685. defer func() {
  686. this.Data["json"] = br
  687. this.ServeJSON()
  688. }()
  689. sysUser := this.SysUser
  690. if sysUser == nil {
  691. br.Msg = "请登录"
  692. br.ErrMsg = "请登录,SysUser Is Empty"
  693. br.Ret = 408
  694. return
  695. }
  696. var req models.SaveReportContent
  697. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  698. if err != nil {
  699. br.Msg = "参数解析异常!"
  700. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  701. return
  702. }
  703. reportId := req.ReportId
  704. noChangeFlag := req.NoChange
  705. if reportId <= 0 {
  706. resp := new(models.SaveReportContentResp)
  707. resp.ReportId = reportId
  708. br.Ret = 200
  709. br.Success = true
  710. br.Msg = "保存成功"
  711. br.Data = resp
  712. return
  713. }
  714. // 获取报告详情
  715. reportInfo, err := models.GetReportByReportId(req.ReportId)
  716. if err != nil {
  717. if utils.IsErrNoRow(err) {
  718. br.Msg = "该报告不存在"
  719. br.ErrMsg = "该报告不存在, Err: " + err.Error()
  720. return
  721. }
  722. br.Msg = "操作失败"
  723. br.ErrMsg = "获取报告详情失败, Err: " + err.Error()
  724. return
  725. }
  726. if reportInfo.Id > 0 && reportInfo.State == 2 {
  727. br.Msg = "该报告已发布,不允许编辑"
  728. br.ErrMsg = "该报告已发布,不允许编辑"
  729. br.IsSendEmail = false
  730. return
  731. }
  732. // 标记更新中
  733. {
  734. markStatus, err := services.UpdateReportEditMark(req.ReportId, 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  735. if err != nil {
  736. br.Msg = err.Error()
  737. return
  738. }
  739. if markStatus.Status == 1 {
  740. br.Msg = markStatus.Msg
  741. return
  742. }
  743. }
  744. // 内容有过修改的话,那么逻辑处理
  745. if noChangeFlag != 1 || req.IsManualSave {
  746. content := req.Content
  747. if content == "" {
  748. content = this.GetString("Content")
  749. }
  750. if content != "" {
  751. e := utils.ContentXssCheck(req.Content)
  752. if e != nil {
  753. br.Msg = "存在非法标签"
  754. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  755. return
  756. }
  757. contentClean, e := services.FilterReportContentBr(req.Content)
  758. if e != nil {
  759. br.Msg = "内容去除前后空格失败"
  760. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  761. return
  762. }
  763. content = contentClean
  764. contentSub, err := services.GetReportContentSub(content)
  765. if err != nil {
  766. go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
  767. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  768. }
  769. reportInfo.Content = html.EscapeString(content)
  770. reportInfo.ContentSub = html.EscapeString(contentSub)
  771. reportInfo.ContentStruct = html.EscapeString(req.ContentStruct)
  772. reportInfo.HeadImg = req.HeadImg
  773. reportInfo.EndImg = req.EndImg
  774. reportInfo.CanvasColor = req.CanvasColor
  775. reportInfo.HeadResourceId = req.HeadResourceId
  776. reportInfo.EndResourceId = req.EndResourceId
  777. reportInfo.ModifyTime = time.Now()
  778. reportInfo.ContentModifyTime = time.Now()
  779. updateCols := []string{"Content", "ContentSub", "ContentStruct", "HeadImg", "EndImg", "CanvasColor", "HeadResourceId", "EndResourceId", "ModifyTime", "ContentModifyTime"}
  780. err = reportInfo.UpdateReport(updateCols)
  781. if err != nil {
  782. br.Msg = "保存失败"
  783. br.ErrMsg = "保存失败,Err:" + err.Error()
  784. return
  785. }
  786. // 增加版本记录
  787. if req.IsManualSave {
  788. reportHistory := new(models.ReportHistory)
  789. reportHistory.ReportId = req.ReportId
  790. reportHistory.Title = reportInfo.Title
  791. reportHistory.Content = reportInfo.Content
  792. reportHistory.ContentSub = reportInfo.ContentSub
  793. reportHistory.ContentStruct = reportInfo.ContentStruct
  794. reportHistory.CanvasColor = reportInfo.CanvasColor
  795. reportHistory.HeadResourceId = reportInfo.HeadResourceId
  796. reportHistory.EndResourceId = reportInfo.EndResourceId
  797. reportHistory.AdminId = sysUser.AdminId
  798. reportHistory.AdminName = sysUser.AdminName
  799. reportHistory.CreateTime = time.Now()
  800. e = reportHistory.Add()
  801. if e != nil {
  802. br.Msg = "保存失败"
  803. br.ErrMsg = "保存失败,Err:" + e.Error()
  804. return
  805. }
  806. }
  807. go models.AddReportSaveLog(reportId, this.SysUser.AdminId, reportInfo.Content, reportInfo.ContentSub, reportInfo.ContentStruct, reportInfo.CanvasColor, this.SysUser.AdminName, reportInfo.HeadResourceId, reportInfo.EndResourceId)
  808. }
  809. }
  810. resp := new(models.SaveReportContentResp)
  811. resp.ReportId = reportId
  812. br.Ret = 200
  813. br.Success = true
  814. br.Msg = "保存成功"
  815. br.Data = resp
  816. }
  817. // AuthorizedListReport
  818. // @Title 获取有权限的报告列表接口
  819. // @Description 获取有权限的报告列表接口
  820. // @Param PageSize query int true "每页数据条数"
  821. // @Param CurrentIndex query int true "当前页页码,从1开始"
  822. // @Param Keyword query string true "搜索关键词"
  823. // @Param ClassifyIdFirst query int true "一级分类id"
  824. // @Param ClassifyIdSecond query int true "二级分类id"
  825. // @Param ClassifyIdThird query int true "三级分类id"
  826. // @Success 200 {object} models.ReportListResp
  827. // @router /list/authorized [get]
  828. func (this *ReportController) AuthorizedListReport() {
  829. br := new(models.BaseResponse).Init()
  830. defer func() {
  831. this.Data["json"] = br
  832. this.ServeJSON()
  833. }()
  834. pageSize, _ := this.GetInt("PageSize")
  835. currentIndex, _ := this.GetInt("CurrentIndex")
  836. keyword := this.GetString("Keyword")
  837. classifyIdFirst, _ := this.GetInt("ClassifyIdFirst", 0)
  838. classifyIdSecond, _ := this.GetInt("ClassifyIdSecond", 0)
  839. classifyIdThird, _ := this.GetInt("ClassifyIdThird", 0)
  840. var startSize int
  841. if pageSize <= 0 {
  842. pageSize = utils.PageSize20
  843. }
  844. if currentIndex <= 0 {
  845. currentIndex = 1
  846. }
  847. startSize = utils.StartIndex(currentIndex, pageSize)
  848. var list []*models.ReportList
  849. // 没有输入信息,那就不展示
  850. if keyword == `` && classifyIdFirst <= 0 {
  851. page := paging.GetPaging(currentIndex, pageSize, 0)
  852. resp := new(models.ReportListResp)
  853. resp.Paging = page
  854. resp.List = list
  855. br.Ret = 200
  856. br.Success = true
  857. br.Msg = "获取成功"
  858. br.Data = resp
  859. return
  860. }
  861. // 当前用户有权限的报告id列表
  862. grantReportIdList := make([]int, 0)
  863. {
  864. obj := report.ReportGrant{}
  865. grantList, err := obj.GetGrantListByAdminId(this.SysUser.AdminId)
  866. if err != nil {
  867. br.Msg = "获取失败"
  868. br.ErrMsg = "获取授权报告id失败,Err:" + err.Error()
  869. return
  870. }
  871. for _, v := range grantList {
  872. grantReportIdList = append(grantReportIdList, v.ReportId)
  873. }
  874. }
  875. var condition string
  876. var pars []interface{}
  877. if classifyIdFirst > 0 {
  878. condition += ` AND a.classify_id_first = ? `
  879. pars = append(pars, classifyIdFirst)
  880. }
  881. if classifyIdSecond > 0 {
  882. condition += ` AND a.classify_id_second = ? `
  883. pars = append(pars, classifyIdSecond)
  884. }
  885. if classifyIdThird > 0 {
  886. condition += ` AND a.classify_id_third = ? `
  887. pars = append(pars, classifyIdThird)
  888. }
  889. if keyword != `` {
  890. condition += ` AND a.title LIKE ? `
  891. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  892. }
  893. var err error
  894. var total int
  895. noVisibleClassifyIds, err := models.GetNoVisibleClassifyIdByAdminId(this.SysUser.AdminId)
  896. if err != nil {
  897. br.Msg = "获取失败"
  898. br.ErrMsg = "获取不可见分类id失败,Err:" + err.Error()
  899. return
  900. }
  901. if len(noVisibleClassifyIds) > 0 {
  902. 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 (?) `
  903. pars = append(pars, noVisibleClassifyIds)
  904. }
  905. orCondition := `AND ( (a.is_public_publish = ? AND a.state in (2,6)) or a.admin_id = ? `
  906. pars = append(pars, 1, this.SysUser.AdminId)
  907. // 当前用户有权限的报告id列表
  908. num := len(grantReportIdList)
  909. if num > 0 {
  910. orCondition += ` OR a.id in (` + utils.GetOrmInReplace(num) + `)`
  911. pars = append(pars, grantReportIdList)
  912. }
  913. orCondition += ` ) `
  914. condition += orCondition
  915. total, err = models.GetReportListCountByAuthorized(condition, pars)
  916. if err != nil {
  917. br.Msg = "获取失败"
  918. br.ErrMsg = "获取失败,Err:" + err.Error()
  919. return
  920. }
  921. list, err = models.GetReportListByAuthorized(condition, pars, startSize, pageSize)
  922. if err != nil {
  923. br.Msg = "获取失败"
  924. br.ErrMsg = "获取失败,Err:" + err.Error()
  925. return
  926. }
  927. //for _, item := range list {
  928. // if item.HasChapter == 1 {
  929. // item.CanEdit = true
  930. // } else {
  931. // markStatus, err := services.UpdateReportEditMark(item.Id, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  932. // if err != nil {
  933. // br.Msg = "查询标记状态失败"
  934. // br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  935. // return
  936. // }
  937. // if markStatus.Status == 0 {
  938. // item.CanEdit = true
  939. // } else {
  940. // item.Editor = markStatus.Editor
  941. // }
  942. // }
  943. //}
  944. page := paging.GetPaging(currentIndex, pageSize, total)
  945. resp := new(models.ReportListResp)
  946. resp.Paging = page
  947. resp.List = list
  948. br.Ret = 200
  949. br.Success = true
  950. br.Msg = "获取成功"
  951. br.Data = resp
  952. }
  953. // BaseDetail
  954. // @Title 获取报告基础信息详情接口
  955. // @Description 获取报告基础信息详情接口
  956. // @Param request body models.ReportDetailReq true "type json string"
  957. // @Success 200 {object} models.Report
  958. // @router /detail/base [get]
  959. func (this *ReportController) BaseDetail() {
  960. br := new(models.BaseResponse).Init()
  961. defer func() {
  962. this.Data["json"] = br
  963. this.ServeJSON()
  964. }()
  965. /*var req models.ReportDetailReq
  966. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  967. if err != nil {
  968. br.Msg = "参数解析异常!"
  969. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  970. return
  971. }
  972. if req.ReportId <= 0 {
  973. br.Msg = "参数错误"
  974. return
  975. }*/
  976. reportId, err := this.GetInt("ReportId")
  977. if err != nil {
  978. br.Msg = "获取参数失败!"
  979. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  980. return
  981. }
  982. if reportId <= 0 {
  983. br.Msg = "参数错误"
  984. return
  985. }
  986. reportInfo, err := models.GetReportById(reportId)
  987. if err != nil {
  988. if utils.IsErrNoRow(err) {
  989. br.Msg = "报告已被删除"
  990. return
  991. }
  992. br.Msg = "获取失败"
  993. br.ErrMsg = "获取失败,Err:" + err.Error()
  994. return
  995. }
  996. fmt.Println(reportInfo)
  997. // 基础信息就不获取章节信息了
  998. chapterList := make([]*models.ReportChapter, 0)
  999. reportInfo.Content = html.UnescapeString(reportInfo.Content)
  1000. reportInfo.ContentSub = html.UnescapeString(reportInfo.ContentSub)
  1001. grandAdminList := make([]models.ReportDetailViewAdmin, 0)
  1002. permissionList := make([]models.ReportDetailViewPermission, 0)
  1003. // 处理报告授权用户列表
  1004. {
  1005. obj := report.ReportGrant{}
  1006. grantList, tmpErr := obj.GetGrantListById(reportId)
  1007. if tmpErr != nil {
  1008. br.Msg = "获取章节id授权用户列表失败"
  1009. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  1010. return
  1011. }
  1012. if len(grantList) > 0 {
  1013. grandAdminIdList := make([]int, 0)
  1014. for _, v := range grantList {
  1015. grandAdminIdList = append(grandAdminIdList, v.AdminId)
  1016. }
  1017. adminList, tmpErr := system.GetAdminListByIdList(grandAdminIdList)
  1018. if tmpErr != nil {
  1019. br.Msg = "获取章节id授权用户列表失败"
  1020. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  1021. return
  1022. }
  1023. for _, v := range adminList {
  1024. grandAdminList = append(grandAdminList, models.ReportDetailViewAdmin{
  1025. AdminId: v.AdminId,
  1026. AdminName: v.RealName,
  1027. })
  1028. }
  1029. }
  1030. }
  1031. // 处理章节id关联品种id列表
  1032. {
  1033. minClassifyId := reportInfo.ClassifyIdThird
  1034. if minClassifyId <= 0 {
  1035. minClassifyId = reportInfo.ClassifyIdSecond
  1036. }
  1037. if minClassifyId <= 0 {
  1038. minClassifyId = reportInfo.ClassifyIdFirst
  1039. }
  1040. if minClassifyId <= 0 {
  1041. br.Msg = "分类异常"
  1042. br.ErrMsg = "分类异常"
  1043. return
  1044. }
  1045. // 获取分类关联的品种id
  1046. classifyPermissionList, tmpErr := models.GetPermission(minClassifyId)
  1047. if tmpErr != nil {
  1048. br.Msg = "获取分类信息失败"
  1049. br.ErrMsg = "获取失败,Err:" + tmpErr.Error()
  1050. return
  1051. }
  1052. if len(classifyPermissionList) > 0 {
  1053. permissionIdList := make([]int, 0)
  1054. for _, v := range classifyPermissionList {
  1055. permissionIdList = append(permissionIdList, v.ChartPermissionId)
  1056. }
  1057. adminList, tmpErr := models.GetChartPermissionByIdList(permissionIdList)
  1058. if tmpErr != nil {
  1059. br.Msg = "获取章节id授权用户列表失败"
  1060. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  1061. return
  1062. }
  1063. for _, v := range adminList {
  1064. permissionList = append(permissionList, models.ReportDetailViewPermission{
  1065. PermissionId: v.ChartPermissionId,
  1066. PermissionName: v.PermissionName,
  1067. })
  1068. }
  1069. }
  1070. }
  1071. resp := &models.ReportDetailView{
  1072. ReportDetail: reportInfo,
  1073. ChapterList: chapterList,
  1074. GrandAdminList: grandAdminList,
  1075. PermissionList: permissionList,
  1076. }
  1077. br.Ret = 200
  1078. br.Success = true
  1079. br.Msg = "获取成功"
  1080. br.Data = resp
  1081. }
  1082. // EditLayoutImg
  1083. // @Title 版图设置接口
  1084. // @Description 版图设置接口
  1085. // @Param request body models.EditLayoutImgReq true "type json string"
  1086. // @Success 200 {object} models.EditResp
  1087. // @router /layout_img/edit [post]
  1088. func (this *ReportController) EditLayoutImg() {
  1089. br := new(models.BaseResponse).Init()
  1090. defer func() {
  1091. this.Data["json"] = br
  1092. this.ServeJSON()
  1093. }()
  1094. sysUser := this.SysUser
  1095. if sysUser == nil {
  1096. br.Msg = "请登录"
  1097. br.ErrMsg = "请登录,SysUser Is Empty"
  1098. br.Ret = 408
  1099. return
  1100. }
  1101. var req models.EditLayoutImgReq
  1102. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1103. if err != nil {
  1104. br.Msg = "参数解析异常!"
  1105. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1106. return
  1107. }
  1108. //if req.Content == "" {
  1109. // br.Msg = "报告内容不能为空"
  1110. // return
  1111. //}
  1112. //更新标记key
  1113. markStatus, err := services.UpdateReportEditMark(int(req.ReportId), 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  1114. if err != nil {
  1115. br.Msg = err.Error()
  1116. return
  1117. }
  1118. if markStatus.Status == 1 {
  1119. br.Msg = markStatus.Msg
  1120. //br.Ret = 202 //202 服务器已接受请求,但尚未处理。
  1121. return
  1122. }
  1123. reportInfo, e := models.GetReportByReportId(int(req.ReportId))
  1124. if e != nil {
  1125. if utils.IsErrNoRow(e) {
  1126. br.Msg = "报告已被删除, 请刷新页面"
  1127. return
  1128. }
  1129. br.Msg = "操作失败"
  1130. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  1131. return
  1132. }
  1133. if reportInfo.State == models.ReportStatePublished || reportInfo.State == models.ReportStatePass {
  1134. br.Msg = "该报告已发布,不允许编辑"
  1135. br.ErrMsg = "该报告已发布,不允许编辑"
  1136. br.IsSendEmail = false
  1137. return
  1138. }
  1139. // 编辑报告信息
  1140. err, errMsg := services.EditReportLayoutImg(reportInfo, req, sysUser)
  1141. if err != nil {
  1142. br.Msg = "保存失败"
  1143. if errMsg != "" {
  1144. br.Msg = errMsg
  1145. }
  1146. br.ErrMsg = "保存失败,Err:" + err.Error()
  1147. return
  1148. }
  1149. reportCode := utils.MD5(strconv.Itoa(int(req.ReportId)))
  1150. resp := new(models.EditResp)
  1151. resp.ReportId = req.ReportId
  1152. resp.ReportCode = reportCode
  1153. br.Ret = 200
  1154. br.Success = true
  1155. br.Msg = "保存成功"
  1156. br.Data = resp
  1157. }
  1158. // PublishReport
  1159. // @Title 发布报告接口
  1160. // @Description 发布报告
  1161. // @Param request body models.PublishReq true "type json string"
  1162. // @Success 200 Ret=200 发布成功
  1163. // @router /publish [post]
  1164. func (this *ReportController) PublishReport() {
  1165. br := new(models.BaseResponse).Init()
  1166. defer func() {
  1167. this.Data["json"] = br
  1168. this.ServeJSON()
  1169. }()
  1170. var req models.PublishReq
  1171. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1172. if err != nil {
  1173. br.Msg = "参数解析异常!"
  1174. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1175. return
  1176. }
  1177. reportIds := req.ReportIds
  1178. if reportIds == "" {
  1179. br.Msg = "参数错误"
  1180. br.ErrMsg = "参数错误,报告id不可为空"
  1181. return
  1182. }
  1183. // 这里实际上不会批量发布了...
  1184. reportArr := strings.Split(reportIds, ",")
  1185. tips := ""
  1186. for _, v := range reportArr {
  1187. vint, err := strconv.Atoi(v)
  1188. if err != nil {
  1189. br.Msg = "参数错误"
  1190. br.ErrMsg = "参数错误,Err:" + err.Error()
  1191. return
  1192. }
  1193. // 报告的图表刷新状态校验
  1194. refreshResult := data.CheckBatchChartRefreshResult("report", vint, 0)
  1195. if !refreshResult {
  1196. br.Msg = "图表刷新未完成,请稍后操作"
  1197. br.ErrMsg = "图表刷新未完成,请稍后操作"
  1198. br.IsSendEmail = false
  1199. return
  1200. }
  1201. // 报告发布
  1202. tmpTips, err, errMsg := services.PublishReportV2(vint, this.SysUser)
  1203. if err != nil {
  1204. br.Msg = errMsg
  1205. br.ErrMsg = "报告发布失败,Err:" + err.Error()
  1206. return
  1207. }
  1208. tips = tmpTips
  1209. }
  1210. // 发布晨周报部分章节未发布的提示
  1211. if tips != "" {
  1212. br.Data = tips
  1213. }
  1214. br.Ret = 200
  1215. br.Success = true
  1216. br.Msg = "发布成功"
  1217. }
  1218. // PublishCancelReport
  1219. // @Title 取消发布报告接口
  1220. // @Description 取消发布报告
  1221. // @Param request body models.PublishCancelReq true "type json string"
  1222. // @Success 200 Ret=200 取消发布成功
  1223. // @router /publish/cancle [post]
  1224. func (this *ReportController) PublishCancelReport() {
  1225. br := new(models.BaseResponse).Init()
  1226. defer func() {
  1227. this.Data["json"] = br
  1228. this.ServeJSON()
  1229. }()
  1230. var req models.PublishCancelReq
  1231. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1232. if err != nil {
  1233. br.Msg = "参数解析异常!"
  1234. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1235. return
  1236. }
  1237. if req.ReportIds <= 0 {
  1238. br.Msg = "参数错误"
  1239. br.ErrMsg = "参数错误,报告id不可为空"
  1240. return
  1241. }
  1242. publishTimeNullFlag := true
  1243. reportInfo, err := models.GetReportById(req.ReportIds)
  1244. if err != nil {
  1245. br.Msg = "获取报告信息失败"
  1246. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  1247. return
  1248. }
  1249. if reportInfo.MsgIsSend == 1 {
  1250. publishTimeNullFlag = false
  1251. }
  1252. // 根据审批开关及审批流判断当前报告状态
  1253. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, reportInfo.ClassifyIdThird, models.ReportOperateCancelPublish)
  1254. if e != nil {
  1255. br.Msg = "操作失败"
  1256. br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
  1257. return
  1258. }
  1259. err = models.PublishCancelReport(req.ReportIds, state, publishTimeNullFlag, this.SysUser.AdminId, this.SysUser.RealName)
  1260. if err != nil {
  1261. br.Msg = "取消发布失败"
  1262. br.ErrMsg = "取消发布失败,Err:" + err.Error()
  1263. return
  1264. }
  1265. // 更新ES禁用
  1266. {
  1267. go services.UpdateReportEs(req.ReportIds, 1)
  1268. }
  1269. //// 获取审批流设置
  1270. //confKey := "approval_flow"
  1271. //confTmp, e := company.GetConfigDetailByCode(confKey)
  1272. //if e != nil {
  1273. // br.Msg = "获取审批流配置失败"
  1274. // br.ErrMsg = "获取审批流配置失败, Err: " + e.Error()
  1275. // return
  1276. //}
  1277. //if confTmp.ConfigValue == "1" || confTmp.ConfigValue == "2" || confTmp.ConfigValue == "3" {
  1278. // br.Msg = "撤销成功"
  1279. //} else {
  1280. // br.Msg = "取消发布成功"
  1281. //}
  1282. recordItem := &models.ReportStateRecord{
  1283. ReportId: req.ReportIds,
  1284. ReportType: 1,
  1285. State: state,
  1286. AdminId: this.SysUser.AdminId,
  1287. AdminName: this.SysUser.AdminName,
  1288. CreateTime: time.Now(),
  1289. }
  1290. go func() {
  1291. _, _ = models.AddReportStateRecord(recordItem)
  1292. }()
  1293. br.Ret = 200
  1294. br.Success = true
  1295. }
  1296. // PrePublishReport
  1297. // @Title 设置定时发布接口
  1298. // @Description 设置定时发布接口
  1299. // @Param request body models.PrePublishReq true "type json string"
  1300. // @Success 200 Ret=200 发布成功
  1301. // @router /pre_publish [post]
  1302. func (this *ReportController) PrePublishReport() {
  1303. br := new(models.BaseResponse).Init()
  1304. defer func() {
  1305. this.Data["json"] = br
  1306. this.ServeJSON()
  1307. }()
  1308. var req models.PrePublishReq
  1309. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1310. if err != nil {
  1311. br.Msg = "参数解析异常!"
  1312. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1313. return
  1314. }
  1315. reportId := req.ReportId
  1316. if reportId == 0 {
  1317. br.Msg = "参数错误"
  1318. br.ErrMsg = "参数错误,报告id不可为空"
  1319. return
  1320. }
  1321. if req.PrePublishTime == "" {
  1322. br.Msg = "发布时间不能为空"
  1323. return
  1324. }
  1325. if req.PreMsgSend != 0 && req.PreMsgSend != 1 {
  1326. br.Msg = "参数错误"
  1327. br.ErrMsg = "是否发送模版消息标识错误"
  1328. return
  1329. }
  1330. prePublishTime, err := time.ParseInLocation(utils.FormatDateTime, req.PrePublishTime, time.Local)
  1331. if err != nil {
  1332. br.Msg = "发布时间格式错误"
  1333. br.ErrMsg = "发布时间格式错误,Err:" + err.Error()
  1334. return
  1335. }
  1336. if prePublishTime.Before(time.Now()) {
  1337. br.Msg = "发布时间不允许选择过去时间"
  1338. return
  1339. }
  1340. if prePublishTime.Before(time.Now().Add(2 * time.Minute)) {
  1341. br.Msg = "发布时间距离当前时间太近了"
  1342. return
  1343. }
  1344. reportDetail, err := models.GetReportById(reportId)
  1345. if err != nil {
  1346. br.Msg = "获取报告信息失败"
  1347. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  1348. return
  1349. }
  1350. if reportDetail == nil {
  1351. br.Msg = "报告不存在"
  1352. return
  1353. }
  1354. // 如果是章节类型的报告,那么需要确认所有章节已发布
  1355. if reportDetail.HasChapter == 1 {
  1356. chapterList, err := models.GetChapterListByReportId(reportId)
  1357. if err != nil {
  1358. return
  1359. }
  1360. for _, chapter := range chapterList {
  1361. if chapter.PublishState == 1 {
  1362. br.Msg = "还存在未发布的章节"
  1363. br.ErrMsg = "还存在未发布的章节"
  1364. return
  1365. }
  1366. }
  1367. } else {
  1368. if reportDetail.Content == "" {
  1369. br.Msg = "报告内容为空,不可设置定时发布"
  1370. br.ErrMsg = "报告内容为空,不可设置定时发布,report_id:" + strconv.Itoa(reportDetail.Id)
  1371. return
  1372. }
  1373. }
  1374. if reportDetail.State == 2 {
  1375. br.Msg = "报告已发布,不可设置定时发布"
  1376. return
  1377. }
  1378. // 校验是否开启了审批流
  1379. opening, e := services.CheckReportOpenApprove(report_approve.FlowReportTypeChinese, reportDetail.ClassifyIdFirst, reportDetail.ClassifyIdSecond, reportDetail.ClassifyIdThird)
  1380. if e != nil {
  1381. br.Msg = "操作失败"
  1382. br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
  1383. return
  1384. }
  1385. if opening {
  1386. br.Msg = "报告已开启审批流, 不可设置定时发布"
  1387. return
  1388. }
  1389. var tmpErr error
  1390. if tmpErr = models.SetPrePublishReportById(reportDetail.Id, req.PrePublishTime, req.PreMsgSend); tmpErr != nil {
  1391. br.Msg = "设置定时发布失败"
  1392. br.ErrMsg = "设置定时发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(reportDetail.Id)
  1393. return
  1394. }
  1395. // 生成报告pdf和长图
  1396. {
  1397. reportPdfUrl := services.GetGeneralPdfUrl(reportDetail.ReportCode, reportDetail.ClassifyNameFirst, reportDetail.ReportLayout)
  1398. go services.Report2pdfAndJpeg(reportPdfUrl, reportDetail.Id, 1)
  1399. }
  1400. br.Ret = 200
  1401. br.Success = true
  1402. br.Msg = "定时发布成功"
  1403. }
  1404. // SubmitApprove
  1405. // @Title 提交审批
  1406. // @Description 提交审批接口
  1407. // @Param request body models.ReportSubmitApproveReq true "type json string"
  1408. // @Success 200 Ret=200 操作成功
  1409. // @router /approve/submit [post]
  1410. func (this *ReportController) SubmitApprove() {
  1411. br := new(models.BaseResponse).Init()
  1412. defer func() {
  1413. if br.ErrMsg == "" {
  1414. br.IsSendEmail = false
  1415. }
  1416. this.Data["json"] = br
  1417. this.ServeJSON()
  1418. }()
  1419. sysUser := this.SysUser
  1420. if sysUser == nil {
  1421. br.Msg = "请登录"
  1422. br.ErrMsg = "请登录,SysUser Is Empty"
  1423. return
  1424. }
  1425. var req models.ReportSubmitApproveReq
  1426. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1427. br.Msg = "参数有误"
  1428. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  1429. return
  1430. }
  1431. reportId := req.ReportId
  1432. if reportId <= 0 {
  1433. br.Msg = "参数有误"
  1434. br.ErrMsg = fmt.Sprintf("参数有误, ReportId: %d", req.ReportId)
  1435. return
  1436. }
  1437. reportOb := new(models.Report)
  1438. reportItem, e := reportOb.GetItemById(reportId)
  1439. if e != nil {
  1440. if utils.IsErrNoRow(e) {
  1441. br.Msg = "报告已被删除, 请刷新页面"
  1442. return
  1443. }
  1444. br.Msg = "操作失败"
  1445. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  1446. return
  1447. }
  1448. // 如果是章节类型的报告,那么需要确认所有章节已发布
  1449. if reportItem.HasChapter == 1 {
  1450. chapterList, err := models.GetChapterListByReportId(reportId)
  1451. if err != nil {
  1452. return
  1453. }
  1454. for _, chapter := range chapterList {
  1455. if chapter.PublishState == 1 {
  1456. br.Msg = "还存在未发布的章节"
  1457. br.ErrMsg = "还存在未发布的章节"
  1458. return
  1459. }
  1460. }
  1461. } else {
  1462. if reportItem.Content == "" {
  1463. br.Msg = "报告内容为空,不可提交"
  1464. br.ErrMsg = "报告内容为空,不可提交,report_id:" + strconv.Itoa(reportItem.Id)
  1465. return
  1466. }
  1467. }
  1468. // 校验当前审批配置, 返回下一个状态
  1469. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, reportItem.ClassifyIdThird, models.ReportOperateSubmitApprove)
  1470. if e != nil {
  1471. br.Msg = "操作失败"
  1472. br.ErrMsg = "校验报告状态失败, Err: " + e.Error()
  1473. return
  1474. }
  1475. // 下一个状态不为待审批时, 仅更新状态
  1476. if state != models.ReportStateWaitApprove {
  1477. reportItem.State = state
  1478. e = reportItem.UpdateReport([]string{"State"})
  1479. if e != nil {
  1480. br.Msg = "操作失败"
  1481. br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1482. return
  1483. }
  1484. br.Ret = 200
  1485. br.Success = true
  1486. br.Msg = "操作成功"
  1487. return
  1488. }
  1489. // 提交审批
  1490. approveId, e := services.SubmitReportApprove(report_approve.FlowReportTypeChinese, reportItem.Id, reportItem.Title, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, reportItem.ClassifyIdThird, sysUser.AdminId, sysUser.RealName)
  1491. if e != nil {
  1492. br.Msg = "操作失败"
  1493. br.ErrMsg = "提交审批失败, Err: " + e.Error()
  1494. return
  1495. }
  1496. reportItem.ApproveId = approveId
  1497. reportItem.State = models.ReportStateWaitApprove
  1498. reportItem.ModifyTime = time.Now().Local()
  1499. e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"})
  1500. if e != nil {
  1501. br.Msg = "操作失败"
  1502. br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1503. return
  1504. }
  1505. // 报告权限处理
  1506. {
  1507. go services.HandleReportPermission(reportItem)
  1508. }
  1509. br.Ret = 200
  1510. br.Success = true
  1511. br.Msg = "操作成功"
  1512. }
  1513. // CancelApprove
  1514. // @Title 撤销审批
  1515. // @Description 撤销审批
  1516. // @Param request body models.ReportCancelApproveReq true "type json string"
  1517. // @Success 200 Ret=200 操作成功
  1518. // @router /approve/cancel [post]
  1519. func (this *ReportController) CancelApprove() {
  1520. br := new(models.BaseResponse).Init()
  1521. defer func() {
  1522. if br.ErrMsg == "" {
  1523. br.IsSendEmail = false
  1524. }
  1525. this.Data["json"] = br
  1526. this.ServeJSON()
  1527. }()
  1528. sysUser := this.SysUser
  1529. if sysUser == nil {
  1530. br.Msg = "请登录"
  1531. br.ErrMsg = "请登录,SysUser Is Empty"
  1532. return
  1533. }
  1534. var req models.ReportCancelApproveReq
  1535. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1536. br.Msg = "参数有误"
  1537. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  1538. return
  1539. }
  1540. reportId := req.ReportId
  1541. if reportId <= 0 {
  1542. br.Msg = "参数有误"
  1543. br.ErrMsg = fmt.Sprintf("参数有误, ReportId: %d", req.ReportId)
  1544. return
  1545. }
  1546. reportOb := new(models.Report)
  1547. reportItem, e := reportOb.GetItemById(reportId)
  1548. if e != nil {
  1549. if utils.IsErrNoRow(e) {
  1550. br.Msg = "报告已被删除, 请刷新页面"
  1551. return
  1552. }
  1553. br.Msg = "操作失败"
  1554. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  1555. return
  1556. }
  1557. // 校验当前审批配置, 返回下一个状态
  1558. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, reportItem.ClassifyIdThird, models.ReportOperateCancelApprove)
  1559. if e != nil {
  1560. br.Msg = "操作失败"
  1561. br.ErrMsg = "校验报告状态失败, Err: " + e.Error()
  1562. return
  1563. }
  1564. // 下一个状态不为待提交时, 仅更新状态
  1565. if state != models.ReportStateWaitSubmit {
  1566. reportItem.State = state
  1567. e = reportItem.UpdateReport([]string{"State"})
  1568. if e != nil {
  1569. br.Msg = "操作失败"
  1570. br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1571. return
  1572. }
  1573. br.Ret = 200
  1574. br.Success = true
  1575. br.Msg = "操作成功"
  1576. return
  1577. }
  1578. //if reportItem.ApproveId <= 0 {
  1579. // br.Msg = "报告审批不存在"
  1580. // br.ErrMsg = fmt.Sprintf("报告审批不存在, ApproveId: %d", reportItem.ApproveId)
  1581. // return
  1582. //}
  1583. // 撤销审批
  1584. e = services.CancelReportApprove(report_approve.FlowReportTypeChinese, reportItem.Id, reportItem.ApproveId, sysUser.AdminId, sysUser.RealName)
  1585. if e != nil {
  1586. br.Msg = "操作失败"
  1587. br.ErrMsg = "撤销审批失败, Err: " + e.Error()
  1588. return
  1589. }
  1590. //reportItem.ApproveId = 0
  1591. //reportItem.State = models.ReportStateWaitSubmit
  1592. //reportItem.ModifyTime = time.Now().Local()
  1593. //e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"})
  1594. //if e != nil {
  1595. // br.Msg = "操作失败"
  1596. // br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1597. // return
  1598. //}
  1599. br.Ret = 200
  1600. br.Success = true
  1601. br.Msg = "操作成功"
  1602. }
  1603. // MessageList
  1604. // @Title 报告消息列表
  1605. // @Description 报告消息列表
  1606. // @Param PageSize query int true "每页数据条数"
  1607. // @Param CurrentIndex query int true "当前页页码"
  1608. // @Success 200 {object} models.ReportMessageListResp
  1609. // @router /message/list [get]
  1610. func (this *ReportController) MessageList() {
  1611. br := new(models.BaseResponse).Init()
  1612. defer func() {
  1613. if br.ErrMsg == "" {
  1614. br.IsSendEmail = false
  1615. }
  1616. this.Data["json"] = br
  1617. this.ServeJSON()
  1618. }()
  1619. sysUser := this.SysUser
  1620. if sysUser == nil {
  1621. br.Msg = "请登录"
  1622. br.ErrMsg = "请登录,SysUser Is Empty"
  1623. br.Ret = 408
  1624. return
  1625. }
  1626. pageSize, _ := this.GetInt("PageSize")
  1627. pageIndex, _ := this.GetInt("CurrentIndex")
  1628. // 分页
  1629. var startSize int
  1630. if pageSize <= 0 {
  1631. pageSize = utils.PageSize20
  1632. }
  1633. if pageIndex <= 0 {
  1634. pageIndex = 1
  1635. }
  1636. startSize = utils.StartIndex(pageIndex, pageSize)
  1637. resp := new(models.ReportMessageListResp)
  1638. resp.List = make([]*models.ReportMessageItem, 0)
  1639. cond := fmt.Sprintf(` AND %s = ?`, models.ReportMessageCols.ReceiveUserId)
  1640. pars := make([]interface{}, 0)
  1641. pars = append(pars, sysUser.AdminId)
  1642. order := fmt.Sprintf(`%s ASC, %s DESC`, models.ReportMessageCols.IsRead, models.ReportMessageCols.CreateTime)
  1643. messageOb := new(models.ReportMessage)
  1644. total, e := messageOb.GetCountByCondition(cond, pars)
  1645. if e != nil {
  1646. br.Msg = "获取失败"
  1647. br.ErrMsg = "获取消息列表总数失败, Err: " + e.Error()
  1648. return
  1649. }
  1650. list, e := messageOb.GetPageItemsByCondition(cond, pars, []string{}, order, startSize, pageSize)
  1651. if e != nil {
  1652. br.Msg = "获取失败"
  1653. br.ErrMsg = "获取消息列表失败, Err: " + e.Error()
  1654. return
  1655. }
  1656. var reportIds, pptIds []int
  1657. for _, v := range list {
  1658. t := models.FormatReportMessage2Item(v)
  1659. if v.ExtraContent != "" {
  1660. am := new(models.ReportMessageApproveItem)
  1661. if e = json.Unmarshal([]byte(v.ExtraContent), &am); e != nil {
  1662. br.Msg = "获取失败"
  1663. br.ErrMsg = fmt.Sprintf("消息列表审批信息解析失败, %v", e)
  1664. return
  1665. }
  1666. t.ApproveMsg = am
  1667. }
  1668. resp.List = append(resp.List, t)
  1669. // 报告状态,这里动态去获取
  1670. if v.ReportType == utils.ReportTypeDefault {
  1671. reportIds = append(reportIds, v.ReportId)
  1672. }
  1673. if v.ReportType == utils.ReportTypePPT {
  1674. pptIds = append(pptIds, v.ReportId)
  1675. }
  1676. }
  1677. stateReport := make(map[int]int)
  1678. statePpt := make(map[int]int)
  1679. if len(reportIds) > 0 {
  1680. ob := new(models.Report)
  1681. cond := ` AND id IN (?)`
  1682. pars := make([]interface{}, 0)
  1683. pars = append(pars, reportIds)
  1684. items, e := ob.GetItemsByCondition(cond, pars, []string{"id", "state"}, "")
  1685. if e != nil {
  1686. br.Msg = "获取失败"
  1687. br.ErrMsg = fmt.Sprintf("获取报告列表失败, %v", e)
  1688. return
  1689. }
  1690. for _, v := range items {
  1691. stateReport[v.Id] = v.State
  1692. }
  1693. }
  1694. if len(pptIds) > 0 {
  1695. ob := new(models.PptV2)
  1696. cond := ` AND ppt_id IN (?)`
  1697. pars := make([]interface{}, 0)
  1698. pars = append(pars, pptIds)
  1699. items, e := ob.GetItemsByCondition(cond, pars, []string{"ppt_id", "state"}, "")
  1700. if e != nil {
  1701. br.Msg = "获取失败"
  1702. br.ErrMsg = fmt.Sprintf("获取PPT列表失败, %v", e)
  1703. return
  1704. }
  1705. for _, v := range items {
  1706. statePpt[v.PptId] = v.State
  1707. }
  1708. }
  1709. for _, v := range resp.List {
  1710. if v.ReportType == utils.ReportTypeDefault {
  1711. v.ReportState = stateReport[v.ReportId]
  1712. }
  1713. if v.ReportType == utils.ReportTypePPT {
  1714. v.ReportState = statePpt[v.ReportId]
  1715. }
  1716. }
  1717. // 未读消息数
  1718. cond += fmt.Sprintf(` AND %s = ?`, models.ReportMessageCols.IsRead)
  1719. pars = append(pars, 0)
  1720. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  1721. if e != nil {
  1722. br.Msg = "获取失败"
  1723. br.ErrMsg = "获取消息列表总数失败, Err: " + e.Error()
  1724. return
  1725. }
  1726. resp.UnreadTotal = unreadTotal
  1727. page := paging.GetPaging(pageIndex, pageSize, total)
  1728. resp.Paging = page
  1729. br.Data = resp
  1730. br.Ret = 200
  1731. br.Success = true
  1732. br.Msg = "获取成功"
  1733. }
  1734. // MessageRead
  1735. // @Title 消息已读
  1736. // @Description 消息已读
  1737. // @Param request body models.ReportMessageReadReq true "type json string"
  1738. // @Success 200 string "操作成功"
  1739. // @router /message/read [post]
  1740. func (this *ReportController) MessageRead() {
  1741. br := new(models.BaseResponse).Init()
  1742. defer func() {
  1743. if br.ErrMsg == "" {
  1744. br.IsSendEmail = false
  1745. }
  1746. this.Data["json"] = br
  1747. this.ServeJSON()
  1748. }()
  1749. sysUser := this.SysUser
  1750. if sysUser == nil {
  1751. br.Msg = "请登录"
  1752. br.ErrMsg = "请登录,SysUser Is Empty"
  1753. br.Ret = 408
  1754. return
  1755. }
  1756. var req models.ReportMessageReadReq
  1757. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1758. br.Msg = "参数有误"
  1759. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  1760. return
  1761. }
  1762. if req.MessageId <= 0 {
  1763. br.Msg = "参数有误"
  1764. br.ErrMsg = fmt.Sprintf("参数有误, MessageId: %d", req.MessageId)
  1765. return
  1766. }
  1767. messageOb := new(models.ReportMessage)
  1768. messageItem, e := messageOb.GetItemById(req.MessageId)
  1769. if e != nil {
  1770. if utils.IsErrNoRow(e) {
  1771. br.Msg = "消息不存在, 请刷新页面"
  1772. return
  1773. }
  1774. br.Msg = "获取失败"
  1775. br.ErrMsg = "获取消息失败, Err: " + e.Error()
  1776. return
  1777. }
  1778. messageItem.IsRead = 1
  1779. messageItem.ModifyTime = time.Now().Local()
  1780. cols := []string{"IsRead", "ModifyTime"}
  1781. if e = messageItem.Update(cols); e != nil {
  1782. br.Msg = "操作失败"
  1783. br.ErrMsg = "更新消息已读失败, Err: " + e.Error()
  1784. return
  1785. }
  1786. br.Ret = 200
  1787. br.Success = true
  1788. br.Msg = "操作成功"
  1789. }