report_v2.go 53 KB

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