123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_mini_crm/models"
- "eta/eta_mini_crm/models/request"
- "eta/eta_mini_crm/models/response"
- "eta/eta_mini_crm/utils"
- "fmt"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- type SysMessageReportController struct {
- BaseAuthController
- }
- // @Title 阅读消息
- // @Description 阅读消息
- // @Param request body system.SysRoleDeleteReq true "type json string"
- // @Success 200 查看成功
- // @router /read [post]
- func (this *SysMessageReportController) Read() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req request.SysMessageReadReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if len(req.SysMessageId) <= 0 {
- br.Msg = "参数异常"
- return
- }
- messages, err := models.GetSysMessageReportListById(req.SysMessageId)
- if err != nil {
- br.Msg = "查询消息出错"
- br.ErrMsg = "查询消息出错,系统错误,Err:" + err.Error()
- return
- }
- for _, msg := range messages {
- msg.IsRead = true
- msg.ModifyTime = time.Now()
- msg.Update([]string{"is_read", "modify_time"})
- }
- br.Msg = "查看成功"
- br.Success = true
- br.Ret = 200
- }
- // List
- // @Title 系统消息列表
- // @Description 系统消息列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} response.SysRoleListResp
- // @router /list [get]
- func (this *SysMessageReportController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- total, err := models.GetSysMessageReportCountBySysUserId(this.SysUser.SysUserId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- fmt.Println(startSize)
- fmt.Println(pageSize)
- list, err := models.GetSysMessageReportBySysUserId(this.SysUser.SysUserId, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(response.SysMessageListResp)
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|