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
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.service.impl;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qianwen.core.mp.base.BaseServiceImpl;
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.common.constant.DictConstant;
import com.qianwen.smartman.common.utils.Lambda;
import com.qianwen.smartman.modules.notify.convert.NoticeConvert;
import com.qianwen.smartman.modules.notify.entity.Notice;
import com.qianwen.smartman.modules.notify.entity.NotifySystem;
import com.qianwen.smartman.modules.notify.mapper.NoticeMapper;
import com.qianwen.smartman.modules.notify.service.INoticeService;
import com.qianwen.smartman.modules.notify.service.INotifySystemService;
import com.qianwen.smartman.modules.notify.vo.NoticeAddVO;
import com.qianwen.smartman.modules.notify.vo.NoticeSelectVO;
import com.qianwen.smartman.modules.notify.vo.NoticeUpdateVO;
import com.qianwen.smartman.modules.notify.vo.NoticeVO;
import com.qianwen.smartman.modules.notify.websocket.InternalMessageResponseJsonWebSocketMessage;
import com.qianwen.smartman.modules.system.entity.Dict;
import com.qianwen.smartman.modules.system.entity.User;
import com.qianwen.smartman.modules.system.service.IDictService;
import com.qianwen.smartman.modules.system.service.IUserService;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/notify/service/impl/NoticeServiceImpl.class */
public class NoticeServiceImpl extends BaseServiceImpl<NoticeMapper, Notice> implements INoticeService {
    @Autowired
    private IUserService userService;
    @Autowired
    @Lazy
    private INotifySystemService notifySystemService;
    @Autowired
    private IDictService dictService;
 
    @Override // org.springblade.modules.notify.service.INoticeService
    public IPage<NoticeVO> selectNoticePage(IPage<NoticeVO> page, NoticeSelectVO selectVO) {
        String typeId = selectVO.getCategory();
        if (Func.isNotEmpty(typeId)) {
            int[] ids = StrUtil.splitToInt(typeId, ",");
            List<Integer> typeIds = Convert.toList(Integer.class, ids);
            selectVO.setCategoryIds(typeIds);
        }
        return ((NoticeMapper) this.baseMapper).selectNoticePage(page, selectVO);
    }
 
    @Override // org.springblade.modules.notify.service.INoticeService
    public NoticeVO saveNotice(NoticeAddVO vo) {
        Notice notice = NoticeConvert.INSTANCE.convert(vo);
        save(notice);
        sentMessage(notice);
        Integer category = notice.getCategory();
        NoticeVO convert = NoticeConvert.INSTANCE.convert(notice);
        Dict dict = this.dictService.getOne(Lambda.<Dict>create()
                .eq(Dict::getCode, DictConstant.NOTICE_CODE)
                .eq(Dict::getDictKey, category.toString())
                .limit());
        /*
        Dict dict = (Dict) this.dictService.getOne(((ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) Lambda.create().eq((v0) -> {
            return v0.getCode();
        }, DictConstant.NOTICE_CODE)).eq((v0) -> {
            return v0.getDictKey();
        }, category.toString())).limit());*/
        if (Func.isNotEmpty(dict)) {
            String dictValue = dict.getDictValue();
            convert.setCategoryName(dictValue);
        }
        return convert;
    }
 
    @Override // org.springblade.modules.notify.service.INoticeService
    public NoticeVO updateNotice(NoticeUpdateVO vo) {
        Notice notice = NoticeConvert.INSTANCE.convert(vo);
        updateById(notice);
        sentMessage(notice);
        Integer category = notice.getCategory();
        NoticeVO convert = NoticeConvert.INSTANCE.convert(notice);
        Dict dict = this.dictService.getOne(Lambda.<Dict>create()
                .eq(Dict::getCode, DictConstant.NOTICE_CODE)
                .eq(Dict::getDictKey, category.toString())
                .limit());
        /*
        Dict dict = (Dict) this.dictService.getOne(((ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) Lambda.create().eq((v0) -> {
            return v0.getCode();
        }, DictConstant.NOTICE_CODE)).eq((v0) -> {
            return v0.getDictKey();
        }, category.toString())).limit());*/
        if (Func.isNotEmpty(dict)) {
            String dictValue = dict.getDictValue();
            convert.setCategoryName(dictValue);
        }
        return convert;
    }
 
    private void sentMessage(Notice notice) {
        Long id = notice.getId();
        List<User> users = this.userService.list(Wrappers.<User>lambdaQuery().select(User::getId ));
        /*
        List<User> users = this.userService.list(Wrappers.lambdaQuery().select(new SFunction[]{(v0) -> {
            return v0.getId();
        }}));*/
        List<Long> usersIds = users.stream().map((v0) -> {
            return v0.getId();
        }).collect(Collectors.toList());
        List<NotifySystem> notifySystems = new ArrayList<>();
        Date date = new Date();
        if (Func.isNotEmpty(usersIds)) {
            for (Long userId : usersIds) {
                NotifySystem notifySystem = new NotifySystem();
                notifySystem.setNotifyType(2);
                notifySystem.setNotifyTime(date);
                notifySystem.setSourceId(Func.toStr(id));
                notifySystem.setBusinessName(notice.getTitle());
                notifySystem.setNotifyUser(Func.toStr(userId));
                notifySystem.setStatus(0);
                notifySystems.add(notifySystem);
            }
            this.notifySystemService.saveBatch(notifySystems);
            for (NotifySystem notifySystem2 : notifySystems) {
                RedisMessageDistributor messageDistributor = (RedisMessageDistributor) SpringUtil.getBean(RedisMessageDistributor.class);
                MessageDO messageDO = new MessageDO();
                messageDO.setNeedBroadcast(Boolean.FALSE);
                messageDO.setSessionKeys(CollUtil.newArrayList(new Object[]{notifySystem2.getNotifyUser()}));
                InternalMessageResponseJsonWebSocketMessage internalMessageResponseJsonWebSocketMessage = new InternalMessageResponseJsonWebSocketMessage();
                internalMessageResponseJsonWebSocketMessage.setHaveUnread(true);
                internalMessageResponseJsonWebSocketMessage.setNotifySystemId(String.valueOf(notifySystem2.getId()));
                internalMessageResponseJsonWebSocketMessage.setNotifyType(2);
                messageDO.setMessageText(JSONUtil.toJsonStr(internalMessageResponseJsonWebSocketMessage));
                messageDistributor.distribute(messageDO);
            }
        }
    }
}