report_v2.go 54 KB

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