派生自 projectDept/qhighschool

EricsHu
2023-11-23 bef4f6d51bff03c0512a75f43e79699b7296f1fa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package com.qxueyou.scc.controller;
 
import java.util.List;
import java.util.Map;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.alibaba.druid.util.StringUtils;
import com.qxueyou.scc.base.model.Pager;
import com.qxueyou.scc.base.model.Result;
import com.qxueyou.scc.base.util.CollectionUtils;
import com.qxueyou.scc.base.util.QBeanUtils;
import com.qxueyou.scc.msg.model.MsgInfo;
import com.qxueyou.scc.msg.service.IMsgInfoService;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
 
@Api(tags="消息管理接口")
@Controller
@CrossOrigin(origins="*",maxAge=3600)
@RequestMapping(value = "/msg/msg/")
public class MsgInfoController {
 
    // 分页查询中,默认记录条数和页数
    private static final int DEFAULT_PAGE_SIZE = 10;
    private static final int DEFAULT_PAGE_NUM = 1;
 
    @Autowired
    IMsgInfoService msgInfoService;
    
    /**
     * 消息列表
     */
    @ApiOperation(value = "获取消息列表")
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public @ResponseBody Result list(Short type,Integer pageSize,Integer pageNum) {
        pageSize = pageSize != null && pageSize > 0 ? pageSize : DEFAULT_PAGE_SIZE;
        pageNum = pageNum != null && pageNum > 0 ? pageNum : DEFAULT_PAGE_NUM;
        
        //消息数量
        int totalCount = msgInfoService.listCount(type);
        Pager pager = new Pager(pageSize,pageNum);
        pager.setTotalCount(totalCount);
        
        List<MsgInfo> list = msgInfoService.list(type,pageSize,pageNum);
        
        List<Map<String, Object>> listResult =QBeanUtils.listBean2ListMap(list,
                CollectionUtils.newStringMap("msgId", "msgId", "type", "type", "content", "content",
                        "readFlag","readFlag","createTime", "createTime"));
 
        return new Result(true,"",CollectionUtils.newObjectMap("msgList",listResult,"page",pager));
    }
    
    /**
     *  删除消息
     * @param msgIds
     * @return
     */
    @ApiOperation(value = "删除消息")
    @RequestMapping(value = "delete", method = RequestMethod.GET)
    public @ResponseBody Result deleteUserMsg(String  msgIds){
        if(StringUtils.isEmpty(msgIds)){
            return new Result(false,"参数错误!");
        }
        
        return this.msgInfoService.deleteUserMsg(msgIds.split(","));
    }
 
    /**
     * 清空个人消息
     * 
     * @return
     */
    @ApiOperation(value = "清空消息")
    @RequestMapping(value = "clear", method = RequestMethod.GET)
    public @ResponseBody Result deleteAllUserMsg(Short type){
        return this.msgInfoService.deleteAllUserMsg(type);
    }
    
    /**
     *  修改已读标志位
     * @param msgId
     * @return
     */
    @ApiOperation(value = "更新为已读")
    @RequestMapping(value = "read", method = RequestMethod.GET)
    public @ResponseBody Result updateReadFlag(String msgIds){
        return this.msgInfoService.updateReadStatus(msgIds.split(","));
    }
    
    /**
     *  全部已读
     * @param msgId
     * @return
     */
    @ApiOperation(value = "全部更新为已读")
    @RequestMapping(value = "readall", method = RequestMethod.GET)
    public @ResponseBody Result updateAllUserReadFlag(Short type){
        return this.msgInfoService.updateUserAllReadStatus(type);
    }
    
    
   /**
     *  最近的提醒消息
     * @param msgId
     * @return
     */
   @ApiOperation(value = "最近的一条提醒信息")
   @RequestMapping(value = "last", method = RequestMethod.GET)
   public @ResponseBody Result getLatest(){
       return new Result(true,"",this.msgInfoService.readLastRemindMsg());
   }
    
   
   /**
     *  最近的提醒消息
     * @param msgId
     * @return
     */
   @ApiOperation(value = "按类型获取未读消息的数量")
   @RequestMapping(value = "count", method = RequestMethod.GET)
   public @ResponseBody Result queryUnReadMsgCountByType(){
       return new Result(true,"",this.msgInfoService.queryUnReadMsgCountByType());
   }
   
   /**
     *  查询未读消息总数
     * @param msgId
     * @return
     */
   @ApiOperation(value = "查询用户未读消息总数")
   @RequestMapping(value = "totalcount", method = RequestMethod.GET)
   public @ResponseBody Result queryUnReadTotalCount(){
       return new Result(true,"",CollectionUtils.newObjectMap("totalCount",this.msgInfoService.queryUnReadTotalCount()));
   }
   
}