Pu Zhibing
2025-02-25 a7dc3517b3c028eab02cdde35a57389278217ed2
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
package com.panzhihua.sangeshenbian.api;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.panzhihua.common.controller.BaseController;
import com.panzhihua.common.interfaces.OperLog;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.sangeshenbian.model.entity.MessageNotification;
import com.panzhihua.sangeshenbian.model.entity.SystemUser;
import com.panzhihua.sangeshenbian.service.IMessageNotificationService;
import com.panzhihua.sangeshenbian.service.ISystemUserService;
import com.panzhihua.sangeshenbian.warpper.MessageNotificationList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
 
/**
 * @author zhibing.pu
 * @Date 2025/2/23 3:05
 */
 
@Api
@RestController
@RequestMapping("/messageNotification")
public class MessageNotificationController extends BaseController {
    
    @Resource
    private IMessageNotificationService messageNotificationService;
    
    @Resource
    private ISystemUserService systemUserService;
    
    
    
    @GetMapping("/list")
    @ApiOperation(value = "获取消息通知列表", tags = {"三个身边后台-消息通知"})
    @OperLog(operModul = "三个身边后台",operType = 0, businessType = "获取消息通知列表")
    public R<IPage<MessageNotification>> list(MessageNotificationList query) {
        Integer id = this.getLoginUserInfoSanGeShenBian().getId();
        SystemUser systemUser = systemUserService.getById(id);
        switch (systemUser.getAccountLevel()){
            case 1:
                query.setUserId("510400");
                break;
            case 2:
                query.setUserId(systemUser.getDistrictsCode());
                break;
            case 3:
                query.setUserId(systemUser.getStreetId().toString());
                break;
            case 4:
                query.setUserId(systemUser.getCommunityId().toString());
                break;
            case 5:
                query.setUserId(id.toString());
                break;
        }
        query.setUndertakerType(systemUser.getAccountLevel());
        IPage<MessageNotification> page = messageNotificationService.list(query);
        return R.ok(page);
    }
    
    
    @PutMapping("/read/{id}")
    @ApiOperation(value = "标记为已读", tags = {"三个身边后台-消息通知"})
    @OperLog(operModul = "三个身边后台",operType = 2, businessType = "标记为已读")
    public R read(@PathVariable("id") Integer id) {
        MessageNotification messageNotification = messageNotificationService.getById(id);
        if(messageNotification.getReadStatus()==1){
            return R.fail("不能重复操作");
        }
        messageNotification.setReadStatus(1);
        messageNotificationService.updateById(messageNotification);
        return R.ok();
    }
    
    
    @GetMapping("/unreadCount")
    @ApiOperation(value = "获取未读数量", tags = {"三个身边后台-消息通知"})
    @OperLog(operModul = "三个身边后台",operType = 0, businessType = "获取未读数量")
    public R unreadCount() {
        Integer id = this.getLoginUserInfoSanGeShenBian().getId();
        SystemUser systemUser = systemUserService.getById(id);
        String userId = null;
        switch (systemUser.getAccountLevel()){
            case 1:
                userId = "510400";
                break;
            case 2:
                userId = systemUser.getDistrictsCode();
                break;
            case 3:
                userId = systemUser.getStreetId().toString();
                break;
            case 4:
                userId = systemUser.getCommunityId().toString();
                break;
            case 5:
                userId = id.toString();
                break;
        }
        long count = messageNotificationService.lambdaQuery()
                .eq(MessageNotification::getReadStatus, 0)
                .eq(MessageNotification::getUndertakerType, systemUser.getAccountLevel())
                .eq(MessageNotification::getUndertakerUserId, userId)
                .count();
        return R.ok(count);
    }
}