report_v2.go 52 KB

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