report_v2.go 53 KB

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