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);
|
}
|
}
|
}
|
}
|