report_v2.go 54 KB

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