report_v2.go 52 KB

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