yangys
2024-04-02 6bed83e92f67954cd2135071133329f2205efe4f
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
package com.qianwen.smartman.modules.notify.controller;
 
import java.util.Arrays;
import java.util.List;
import java.util.Map;
 
import javax.validation.Valid;
 
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.qianwen.core.boot.ctrl.BladeController;
import com.qianwen.core.mp.support.Condition;
import com.qianwen.core.mp.support.Query;
import com.qianwen.core.scanner.modular.annotation.PostResource;
import com.qianwen.core.secure.BladeUser;
import com.qianwen.core.secure.utils.AuthUtil;
import com.qianwen.core.tool.api.R;
import com.qianwen.core.websocket.distribute.MessageDO;
import com.qianwen.core.websocket.distribute.RedisMessageDistributor;
import com.qianwen.smartman.modules.notify.convert.NotifySystemConvert;
import com.qianwen.smartman.modules.notify.entity.NotifySystem;
import com.qianwen.smartman.modules.notify.service.INotifySystemService;
import com.qianwen.smartman.modules.notify.vo.NotifySystemSelectVO;
import com.qianwen.smartman.modules.notify.vo.NotifySystemUnreadVO;
import com.qianwen.smartman.modules.notify.vo.NotifySystemVO;
import com.qianwen.smartman.modules.notify.websocket.InternalMessageResponseJsonWebSocketMessage;
 
import cn.hutool.json.JSONUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import springfox.documentation.annotations.ApiIgnore;
 
@Api(value = "通知公告表管理", tags = {"通知公告表管理"})
@RequestMapping({"blade-notify/notify-system"})
@RestController
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/notify/controller/NotifySystemController.class */
public class NotifySystemController extends BladeController {
    private INotifySystemService notifySystemService;
    private RedisMessageDistributor messageDistributor;
 
 
    public NotifySystemController(final INotifySystemService notifySystemService, final RedisMessageDistributor messageDistributor) {
        this.notifySystemService = notifySystemService;
        this.messageDistributor = messageDistributor;
    }
 
    @ApiOperationSupport(order = 1)
    @GetMapping({"/get/{id}"})
    @ApiOperation(value = "通知公告表详情", notes = "传入notifySystem")
    public R<NotifySystemVO> detail(@PathVariable String id) {
        return R.data(this.notifySystemService.detail(id));
    }
 
    @ApiOperationSupport(order = 2)
    @GetMapping({"/list"})
    @ApiOperation(value = "通知公告表列表", notes = "传入map")
    public R<List<NotifySystemVO>> list(@RequestParam @ApiIgnore Map<String, Object> params) {
        List<NotifySystem> list = this.notifySystemService.list(Condition.getQueryWrapper(params, NotifySystem.class));
        return R.data(NotifySystemConvert.INSTANCE.convert(list));
    }
 
    @ApiOperationSupport(order = 2)
    @GetMapping({"/count"})
    @ApiOperation(value = "通知公告表统计值", notes = "传入map")
    public R<Long> count(@RequestParam @ApiIgnore Map<String, Object> params) {
        long count = this.notifySystemService.count(Condition.getQueryWrapper(params, NotifySystem.class));
        return R.data(Long.valueOf(count));
    }
 
    @ApiOperationSupport(order = 3)
    @GetMapping({"/page"})
    @ApiOperation(value = "通知公告表分页", notes = "传入map")
    public R<IPage<NotifySystemVO>> page(NotifySystemSelectVO notifySystemSelectVO, Query query) {
        return R.data(this.notifySystemService.pageNotifySystem(notifySystemSelectVO, Condition.getPage(query)));
    }
 
    @PostMapping({"/insert"})
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "通知公告表新增", notes = "传入notifySystemVO")
    public R<NotifySystemVO> insert(@Valid @RequestBody NotifySystemVO notifySystemVO) {
        NotifySystem notifySystem = NotifySystemConvert.INSTANCE.convert(notifySystemVO);
        this.notifySystemService.save(notifySystem);
        return R.data(NotifySystemConvert.INSTANCE.convert(notifySystem));
    }
 
    @DeleteMapping({"/remove"})
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "通知公告表删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键", required = true) @RequestBody List<Long> ids) {
        if (ids.isEmpty()) {
            return R.status(false);
        }
        return R.status(this.notifySystemService.removeByIds(ids));
    }
 
    @ApiOperationSupport(order = 7)
    @PostResource({"/{state}"})
    @ApiOperation("修改通知状态")
    public R<String> changeState(@RequestBody List<String> idList, @PathVariable("state") Integer state, BladeUser bladeUser) {
        LambdaUpdateWrapper<NotifySystem> updateWrapper = Wrappers.<NotifySystem>update().lambda()
                .set(NotifySystem::getStatus, state)
                .eq(NotifySystem::getNotifyUser, bladeUser.getUserId()).in(NotifySystem::getId, idList);
        boolean flag = this.notifySystemService.update(updateWrapper);
        /*
        boolean flag = this.notifySystemService.update((LambdaUpdateWrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) Wrappers.update().lambda().set((v0) -> {
            return v0.getStatus();
        }, state)).eq((v0) -> {
            return v0.getNotifyUser();
        }, bladeUser.getUserId())).in((v0) -> {
            return v0.getId();
        }, idList));*/
        InternalMessageResponseJsonWebSocketMessage internalMessageResponseJsonWebSocketMessage = new InternalMessageResponseJsonWebSocketMessage();
        long unNotificationCount = this.notifySystemService.count(Wrappers.<NotifySystem>lambdaQuery()
                .ne(NotifySystem::getStatus, 1)
                .eq(NotifySystem::getNotifyUser, AuthUtil.getUserId()));
        /*
        long unNotificationCount = this.notifySystemService.count((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().ne((v0) -> {
            return v0.getStatus();
        }, 1)).eq((v0) -> {
            return v0.getNotifyUser();
        }, AuthUtil.getUserId()));*/
        internalMessageResponseJsonWebSocketMessage.setHaveUnread(unNotificationCount > 0);
        MessageDO messageDO = new MessageDO();
        messageDO.setNeedBroadcast(Boolean.FALSE);
        messageDO.setMessageText(JSONUtil.toJsonStr(internalMessageResponseJsonWebSocketMessage));
        messageDO.setSessionKeys(Arrays.asList(AuthUtil.getUserId()));
        this.messageDistributor.distribute(messageDO);
        return R.status(flag);
    }
 
    @ApiOperationSupport(order = 3)
    @GetMapping({"/getUnreadList"})
    @ApiOperation(value = "获取未读通知-铃铛", notes = "传入map")
    public R<NotifySystemUnreadVO> getUnreadList() {
        NotifySystemUnreadVO result = this.notifySystemService.getUnreadList();
        return R.data(result);
    }
}