liujie
2023-08-16 db7fa6a91b9534ac90e219b6f554c54c43c83a5a
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
144
145
146
147
148
149
150
151
152
package com.supersavedriving.driver.modular.system.api;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.supersavedriving.driver.core.common.annotion.ServiceLog;
import com.supersavedriving.driver.core.util.ToolUtil;
import com.supersavedriving.driver.modular.system.model.SystemBulletin;
import com.supersavedriving.driver.modular.system.model.SystemBulletinUser;
import com.supersavedriving.driver.modular.system.model.SystemMessage;
import com.supersavedriving.driver.modular.system.service.IDriverService;
import com.supersavedriving.driver.modular.system.service.ISystemBulletinService;
import com.supersavedriving.driver.modular.system.service.ISystemBulletinUserService;
import com.supersavedriving.driver.modular.system.service.ISystemMessageService;
import com.supersavedriving.driver.modular.system.util.ResultUtil;
import com.supersavedriving.driver.modular.system.warpper.ResponseWarpper;
import com.supersavedriving.driver.modular.system.warpper.SystemMessageWarpper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import java.util.List;
 
/**
* 系统消息
* @author pzb
* @Date 2023/2/10 15:35
*/
@RestController
@RequestMapping("")
public class SystemMessageController {
 
    @Autowired
    private ISystemMessageService systemMessageService;
 
    @Autowired
    private IDriverService driverService;
 
    @Autowired
    private ISystemBulletinService systemBulletinService;
 
    @Autowired
    private ISystemBulletinUserService systemBulletinUserService;
 
 
 
 
    @ResponseBody
    @PostMapping("/api/systemMessage/querySystemMessageList")
//    @ServiceLog(name = "获取系统消息列表", url = "/api/systemMessage/querySystemMessageList")
    @ApiOperation(value = "获取系统消息列表", tags = {"司机端-首页"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"),
            @ApiImplicitParam(value = "页条数", name = "size", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper<List<SystemMessageWarpper>> querySystemMessageList(Integer pageNum, Integer size){
        if(ToolUtil.isEmpty(pageNum)){
            return ResponseWarpper.success(ResultUtil.paranErr("pageNum"));
        }
        if(ToolUtil.isEmpty(size)){
            return ResponseWarpper.success(ResultUtil.paranErr("size"));
        }
        try {
            Integer uid = driverService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.tokenErr();
            }
            List<SystemMessageWarpper> systemMessageWarppers = systemMessageService.querySystemMessageList(uid, pageNum, size);
            return ResponseWarpper.success(systemMessageWarppers);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/systemMessage/readSystems")
//    @ServiceLog(name = "阅读系统消息", url = "/api/systemMessage/readSystems")
    @ApiOperation(value = "阅读系统消息", tags = {"司机端-首页"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "消息id,多个逗号分隔", name = "ids", required = true, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper readSystems(String ids){
        if(ToolUtil.isEmpty(ids)){
            return ResponseWarpper.success(ResultUtil.paranErr("ids"));
        }
        try {
            Integer uid = driverService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.tokenErr();
            }
            systemMessageService.readSystems(uid, ids);
            return ResponseWarpper.success();
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/systemMessage/clearSystemMessage")
//    @ServiceLog(name = "清空系统消息和公告", url = "/api/systemMessage/clearSystemMessage")
    @ApiOperation(value = "清空系统消息和公告", tags = {"司机端-首页"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper clearSystemMessage(){
        try {
            Integer uid = driverService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.tokenErr();
            }
            systemMessageService.clearSystemMessage(uid);
            systemBulletinService.clearSystemBulletinUser(uid);
            return ResponseWarpper.success();
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/systemMessage/queryUnreadQuantity")
//    @ServiceLog(name = "获取未读消息数量", url = "/api/systemMessage/queryUnreadQuantity")
    @ApiOperation(value = "获取未读消息数量", tags = {"司机端-首页"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper<Integer> queryUnreadQuantity(){
        try {
            Integer uid = driverService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.tokenErr();
            }
            int count = systemMessageService.selectCount(new EntityWrapper<SystemMessage>().eq("userType", 2).eq("userId", uid).eq("isRead", 0).eq("status", 1));
            int count1 = systemBulletinUserService.selectCount(new EntityWrapper<SystemBulletinUser>().eq("userType", 2).eq("userId", uid).eq("isRead", 0).eq("status", 1));
            return ResponseWarpper.success(count + count1);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
}