yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
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
package com.qianwen.smartman.modules.notify.manager;
 
import cn.hutool.json.JSONUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.qianwen.core.notify.provider.internal.message.IInternalMessageServer;
import com.qianwen.core.notify.provider.internal.message.ParsedInternalMessageTemplate;
import com.qianwen.core.tool.jackson.JsonUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.core.tool.utils.SpringUtil;
import com.qianwen.core.websocket.distribute.MessageDO;
import com.qianwen.core.websocket.distribute.RedisMessageDistributor;
import com.qianwen.smartman.modules.notify.entity.NotifySystem;
import com.qianwen.smartman.modules.notify.service.INotifySystemService;
import com.qianwen.smartman.modules.notify.websocket.InternalMessageResponseJsonWebSocketMessage;
import org.springframework.stereotype.Component;
 
@Component
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/notify/manager/DefaultInternalMessageServer.class */
class DefaultInternalMessageServer implements IInternalMessageServer {
    private static final Logger log = LoggerFactory.getLogger(DefaultInternalMessageServer.class);
    private final INotifySystemService notifySystemService;
 
    public DefaultInternalMessageServer(final INotifySystemService notifySystemService) {
        this.notifySystemService = notifySystemService;
    }
 
    public void submitInternalMessage(ParsedInternalMessageTemplate template, List<String> sendTo) {
        if (Func.isNotEmpty(sendTo)) {
            List<NotifySystem> notifySystems = new ArrayList<>(sendTo.size());
            Date now = new Date();
            sendTo.forEach(item -> {
                NotifySystem notifySystem = new NotifySystem();
                notifySystem.setNotifyType(1);
                notifySystem.setNotifyTime(now);
                notifySystem.setMessage(template.getContent());
                notifySystem.setAttachments(JsonUtil.toJson(template.getAttachments()));
                notifySystem.setBusinessName(template.getSubject());
                notifySystem.setNotifyUser(item);
                notifySystem.setStatus(0);
                notifySystems.add(notifySystem);
            });
            this.notifySystemService.saveBatch(notifySystems);
            notifySystems.forEach(o -> {
                RedisMessageDistributor messageDistributor = (RedisMessageDistributor) SpringUtil.getBean(RedisMessageDistributor.class);
                InternalMessageResponseJsonWebSocketMessage internalMessageResponseJsonWebSocketMessage = new InternalMessageResponseJsonWebSocketMessage();
                internalMessageResponseJsonWebSocketMessage.setHaveUnread(true);
                internalMessageResponseJsonWebSocketMessage.setNotifySystemId(String.valueOf(o.getId()));
                internalMessageResponseJsonWebSocketMessage.setNotifyType(1);
                MessageDO messageDO = new MessageDO();
                messageDO.setNeedBroadcast(Boolean.FALSE);
                messageDO.setMessageText(JSONUtil.toJsonStr(internalMessageResponseJsonWebSocketMessage));
                messageDO.setSessionKeys(Arrays.asList(o.getNotifyUser()));
                messageDistributor.distribute(messageDO);
            });
        }
    }
}