message.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. package data_manage_permission
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/models"
  5. "eta/eta_mobile/models/data_manage/data_manage_permission"
  6. data_manage_permissionServ "eta/eta_mobile/services/data/data_manage_permission"
  7. "eta/eta_mobile/utils"
  8. "fmt"
  9. "github.com/rdlucklib/rdluck_tools/paging"
  10. "time"
  11. )
  12. // MessageList
  13. // @Title 资产消息列表
  14. // @Description 资产消息列表
  15. // @Param PageSize query int true "每页数据条数"
  16. // @Param CurrentIndex query int true "当前页页码"
  17. // @Success 200 {object} data_manage_permission.DataPermissionMessageListResp
  18. // @router /message/list [get]
  19. func (c *DataMangePermissionController) MessageList() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. if br.ErrMsg == "" {
  23. br.IsSendEmail = false
  24. }
  25. c.Data["json"] = br
  26. c.ServeJSON()
  27. }()
  28. sysUser := c.SysUser
  29. if sysUser == nil {
  30. br.Msg = "请登录"
  31. br.ErrMsg = "请登录,SysUser Is Empty"
  32. br.Ret = 408
  33. return
  34. }
  35. // 分页
  36. pageSize, _ := c.GetInt("PageSize")
  37. currentIndex, _ := c.GetInt("CurrentIndex")
  38. var startSize int
  39. if pageSize <= 0 {
  40. pageSize = utils.PageSize20
  41. }
  42. if currentIndex <= 0 {
  43. currentIndex = 1
  44. }
  45. startSize = paging.StartIndex(currentIndex, pageSize)
  46. resp := new(data_manage_permission.DataPermissionMessageListResp)
  47. resp.List = make([]*data_manage_permission.DataPermissionMessageItem, 0)
  48. cond := fmt.Sprintf(` AND %s = ?`, data_manage_permission.DataPermissionMessageCols.ReceiveUserId)
  49. pars := make([]interface{}, 0)
  50. pars = append(pars, sysUser.AdminId)
  51. order := fmt.Sprintf(`%s ASC, %s DESC`, data_manage_permission.DataPermissionMessageCols.IsRead, data_manage_permission.DataPermissionMessageCols.CreateTime)
  52. messageOb := new(data_manage_permission.DataPermissionMessage)
  53. total, e := messageOb.GetCountByCondition(cond, pars)
  54. if e != nil {
  55. br.Msg = "获取失败"
  56. br.ErrMsg = "获取资产消息列表总数失败, Err: " + e.Error()
  57. return
  58. }
  59. list, e := messageOb.GetPageItemsByCondition(cond, pars, []string{}, order, startSize, pageSize)
  60. if e != nil {
  61. br.Msg = "获取失败"
  62. br.ErrMsg = "获取资产消息列表失败, Err: " + e.Error()
  63. return
  64. }
  65. for _, v := range list {
  66. t := data_manage_permission.FormatDataPermissionMessage2Item(v)
  67. resp.List = append(resp.List, t)
  68. }
  69. // 未读消息数
  70. cond += fmt.Sprintf(` AND %s = ?`, data_manage_permission.DataPermissionMessageCols.IsRead)
  71. pars = append(pars, 0)
  72. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  73. if e != nil {
  74. br.Msg = "获取失败"
  75. br.ErrMsg = "获取资产消息列表总数失败, Err: " + e.Error()
  76. return
  77. }
  78. resp.UnreadTotal = unreadTotal
  79. page := paging.GetPaging(currentIndex, pageSize, total)
  80. resp.Paging = page
  81. br.Data = resp
  82. br.Ret = 200
  83. br.Success = true
  84. br.Msg = "获取成功"
  85. }
  86. // MessageRead
  87. // @Title 消息已读
  88. // @Description 消息已读
  89. // @Param request body data_manage_permission.DataPermissionMessageReadReq true "type json string"
  90. // @Success 200 string "操作成功"
  91. // @router /message/read [post]
  92. func (c *DataMangePermissionController) MessageRead() {
  93. br := new(models.BaseResponse).Init()
  94. defer func() {
  95. if br.ErrMsg == "" {
  96. br.IsSendEmail = false
  97. }
  98. c.Data["json"] = br
  99. c.ServeJSON()
  100. }()
  101. sysUser := c.SysUser
  102. if sysUser == nil {
  103. br.Msg = "请登录"
  104. br.ErrMsg = "请登录,SysUser Is Empty"
  105. br.Ret = 408
  106. return
  107. }
  108. var req data_manage_permission.DataPermissionMessageReadReq
  109. if e := json.Unmarshal(c.Ctx.Input.RequestBody, &req); e != nil {
  110. br.Msg = "参数有误"
  111. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  112. return
  113. }
  114. if req.MessageId <= 0 {
  115. br.Msg = "参数有误"
  116. br.ErrMsg = fmt.Sprintf("参数有误, MessageId: %d", req.MessageId)
  117. return
  118. }
  119. messageOb := new(data_manage_permission.DataPermissionMessage)
  120. messageItem, e := messageOb.GetItemById(req.MessageId)
  121. if e != nil {
  122. if e.Error() == utils.ErrNoRow() {
  123. br.Msg = "消息不存在, 请刷新页面"
  124. return
  125. }
  126. br.Msg = "获取失败"
  127. br.ErrMsg = "获取审批消息失败, Err: " + e.Error()
  128. return
  129. }
  130. // 不等于0的时候,说明已经操作过了,就不重复操作了
  131. if messageItem.IsRead != 0 {
  132. br.Ret = 200
  133. br.Success = true
  134. br.Msg = "操作成功"
  135. return
  136. }
  137. if messageItem.ReceiveUserId != int32(sysUser.AdminId) {
  138. br.Msg = "标记已读失败,不是本人消息"
  139. br.ErrMsg = "标记已读失败,不是本人消息 "
  140. br.IsSendEmail = false
  141. return
  142. }
  143. messageItem.IsRead = 1
  144. messageItem.ModifyTime = time.Now().Local()
  145. cols := []string{"IsRead", "ModifyTime"}
  146. if e = messageItem.Update(cols); e != nil {
  147. br.Msg = "操作失败"
  148. br.ErrMsg = "更新消息已读失败, Err: " + e.Error()
  149. return
  150. }
  151. br.Ret = 200
  152. br.Success = true
  153. br.Msg = "操作成功"
  154. }
  155. // MessageDetail
  156. // @Title 资产消息详情
  157. // @Description 资产消息详情
  158. // @Param MessageId query int true "消息ID"
  159. // @Param PageSize query int true "每页数据条数"
  160. // @Param CurrentIndex query int true "当前页页码,从1开始"
  161. // @Param Source query int false "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格"
  162. // @Param SubSource query int false "子来源 :目前作用于ETA表格,2024-3-26 14:12:09"
  163. // @Success 200 {object} data_manage_permission.MessageDetailListResp
  164. // @router /message/detail [get]
  165. func (c *DataMangePermissionController) MessageDetail() {
  166. br := new(models.BaseResponse).Init()
  167. defer func() {
  168. if br.ErrMsg == "" {
  169. br.IsSendEmail = false
  170. }
  171. c.Data["json"] = br
  172. c.ServeJSON()
  173. }()
  174. sysUser := c.SysUser
  175. if sysUser == nil {
  176. br.Msg = "请登录"
  177. br.ErrMsg = "请登录,SysUser Is Empty"
  178. br.Ret = 408
  179. return
  180. }
  181. messageId, _ := c.GetInt("MessageId", 0)
  182. if messageId <= 0 {
  183. br.Msg = "请选择消息"
  184. br.ErrMsg = "请选择消息"
  185. br.IsSendEmail = false
  186. return
  187. }
  188. source, _ := c.GetInt("Source")
  189. // 子来源(目前作用于ETA表格,2024-3-26 14:12:09)
  190. subSource, _ := c.GetInt("SubSource")
  191. pageSize, _ := c.GetInt("PageSize")
  192. currentIndex, _ := c.GetInt("CurrentIndex")
  193. var startSize int
  194. if pageSize <= 0 {
  195. pageSize = utils.PageSize20
  196. }
  197. if currentIndex <= 0 {
  198. currentIndex = 1
  199. }
  200. startSize = paging.StartIndex(currentIndex, pageSize)
  201. resp := data_manage_permission.MessageDetailListResp{}
  202. var total int
  203. page := paging.GetPaging(currentIndex, pageSize, total)
  204. messageOb := new(data_manage_permission.DataPermissionMessage)
  205. messageItem, e := messageOb.GetItemById(messageId)
  206. if e != nil {
  207. if e.Error() == utils.ErrNoRow() {
  208. br.Msg = "消息不存在, 请刷新页面"
  209. return
  210. }
  211. br.Msg = "获取失败"
  212. br.ErrMsg = "获取审批消息失败, Err: " + e.Error()
  213. return
  214. }
  215. total, list, err := data_manage_permissionServ.GetMessageDetail(messageItem, source, subSource, startSize, pageSize)
  216. if err != nil {
  217. //br.Success = true
  218. br.Msg = "获取失败"
  219. br.ErrMsg = "获取失败,Err:" + err.Error()
  220. return
  221. }
  222. page = paging.GetPaging(currentIndex, pageSize, total)
  223. resp.Paging = page
  224. resp.List = list
  225. br.Ret = 200
  226. br.Success = true
  227. br.Msg = "获取成功"
  228. br.IsAddLog = false
  229. br.Data = resp
  230. }