add 动态消息发布时发送系统消息

This commit is contained in:
liao
2023-10-27 15:24:04 +08:00
parent e3bce79660
commit ea3c609159
8 changed files with 64 additions and 37 deletions
@@ -1,4 +1,4 @@
package com.jero.modules.docking.hiwork.dto;
package com.jero.common.api.dto.message;
import lombok.Data;
@@ -0,0 +1,19 @@
package com.jero.common.api.vo;
import com.jero.common.api.dto.message.SendMessageDTO;
/**
* @Author: liao
* @Date: 2023/10/27 15:15
* @Description: 发送消息
*/
public interface SendMessageAPI {
/**
* @Author: liao
* @Date: 2023/10/27 15:13
* @Description: 根据模板发送消息
**/
void sendMessage(SendMessageDTO sendMessageDTO);
}
@@ -1,19 +0,0 @@
package com.jero.modules.docking.hiwork.service;
import com.jero.modules.docking.hiwork.dto.SendMessageDTO;
/**
* @Author: liao
* @Date: 2023/10/17 11:22
* @Description: 发送消息
*/
public interface ISendMessageService {
/**
* @Author: liao
* @Date: 2023/10/17 11:24
* @Description: 根据模板发送消息
**/
void sendMessage(SendMessageDTO sendMessageDTO);
}
@@ -1,17 +1,18 @@
package com.jero.modules.docking.hiwork.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jero.common.api.dto.message.SendMessageDTO;
import com.jero.common.api.vo.SendMessageAPI;
import com.jero.common.exception.JeroBootException;
import com.jero.modules.docking.hiwork.dto.SendMessageDTO;
import com.jero.modules.docking.hiwork.handle.DingDingSendMsgHandle;
import com.jero.modules.docking.hiwork.handle.SystemSendMsgHandle;
import com.jero.modules.docking.hiwork.service.ISendMessageService;
import com.jero.modules.message.entity.SysMessageTemplate;
import com.jero.modules.message.handle.ISendMsgHandle;
import com.jero.modules.message.service.ISysMessageTemplateService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -26,10 +27,12 @@ import java.util.Objects;
*/
@Slf4j
@Service
public class SendMessageServiceImpl implements ISendMessageService {
public class SendMessageServiceImpl implements SendMessageAPI {
@Resource
private ISysMessageTemplateService sysMessageTemplateService;
@Value("${hiwork.isSend}")
private Boolean isSend;
/**
* @Author: liao
@@ -72,8 +75,11 @@ public class SendMessageServiceImpl implements ISendMessageService {
} else {
return;
}
log.info("消息标题:{},消息内容:{}", sysMessageTemplate.getTemplateName(),sysMessageTemplate.getTemplateContent());
if (!isSend) {
return;
}
sendMsgHandle.SendMsg(sendMessageDTO.getToUserId(), sysMessageTemplate.getTemplateName(), sysMessageTemplate.getTemplateContent());
log.info(sysMessageTemplate.getTemplateContent());
} catch (Exception e){
log.error("发送消息异常",e);
throw new JeroBootException("发送消息异常");
@@ -81,7 +81,7 @@ public class LawsNewsFeedController extends JeroController<LawsNewsFeed, ILawsNe
if (!Objects.isNull(lawsNewsFeed.getReleaseTime())) {
lawsNewsFeed.setReleaseTime(new Date());
}
lawsNewsFeedService.add(lawsNewsFeed);
lawsNewsFeedService.add(lawsNewsFeed, "save");
return Result.OK(MessageUtils.getMessage(ResultCommon.OK));
}
@@ -96,7 +96,7 @@ public class LawsNewsFeedController extends JeroController<LawsNewsFeed, ILawsNe
// 不管第几次发布,发布时间都更新
lawsNewsFeed.setReleaseTime(new Date());
lawsNewsFeed.setReleaseStatus(1);
lawsNewsFeedService.add(lawsNewsFeed);
lawsNewsFeedService.add(lawsNewsFeed, "release");
return Result.OK(MessageUtils.getMessage(ResultCommon.OK));
}
@@ -38,7 +38,7 @@ public interface ILawsNewsFeedService extends IService<LawsNewsFeed> {
* @param lawsNewsFeed
* @return
*/
void add(LawsNewsFeed lawsNewsFeed);
void add(LawsNewsFeed lawsNewsFeed, String type);
/**
* 通过id删除
@@ -1,8 +1,8 @@
package com.jero.modules.laws.standard.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jero.common.api.vo.Result;
import com.jero.common.api.dto.message.SendMessageDTO;
import com.jero.common.api.vo.SendMessageAPI;
import com.jero.common.system.vo.LoginUser;
import com.jero.modules.laws.common.constant.FieldCommon;
import com.jero.modules.laws.common.constant.ResultCommon;
@@ -11,7 +11,8 @@ import com.jero.modules.laws.standard.entity.LawsPushRange;
import com.jero.modules.laws.standard.mapper.LawsNewsFeedMapper;
import com.jero.modules.laws.standard.service.ILawsNewsFeedService;
import com.jero.modules.laws.standard.service.ILawsPushRangeService;
import com.jero.modules.system.entity.SysUser;
import com.jero.modules.system.entity.SysDictItem;
import com.jero.modules.system.service.ISysDictItemService;
import com.spire.ms.System.Collections.ArrayList;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@@ -21,15 +22,10 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jero.common.exception.JeroBootException;
import java.util.Arrays;
import java.util.List;
import java.util.Date;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.system.query.QueryGenerator;
import javax.servlet.http.HttpServletRequest;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -48,6 +44,10 @@ public class LawsNewsFeedServiceImpl extends ServiceImpl<LawsNewsFeedMapper, Law
private ILawsPushRangeService lawsPushRangeService;
@Autowired
private LawsNewsFeedMapper lawsNewsFeedMapper;
@Autowired
private SendMessageAPI sendMessageAPI;
@Autowired
private ISysDictItemService sysDictItemService;
/**
* 分页查询
@@ -122,7 +122,7 @@ public class LawsNewsFeedServiceImpl extends ServiceImpl<LawsNewsFeedMapper, Law
*/
@Override
@Transactional
public void add(LawsNewsFeed lawsNewsFeed) {
public void add(LawsNewsFeed lawsNewsFeed, String type) {
if (StringUtils.isBlank(lawsNewsFeed.getDynamicHeading())) {
throw new JeroBootException(ResultCommon.EMPTY_COMMON, "dynamicHeading");
}
@@ -164,6 +164,25 @@ public class LawsNewsFeedServiceImpl extends ServiceImpl<LawsNewsFeedMapper, Law
pushRangeList.add(lawsPushRange);
});
lawsPushRangeService.saveBatch(pushRangeList);
if ("release".equals(type)) {
// 发送消息
SendMessageDTO sendMessageDTO = new SendMessageDTO();
sendMessageDTO.setTemplateCode("laws_news_feed");
sendMessageDTO.setToUserId(pushRange);
Map<String, String> map = new HashMap<>();
map.put("title", lawsNewsFeed.getDynamicHeading());
LambdaQueryWrapper<SysDictItem> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(SysDictItem::getItemValue, lawsNewsFeed.getDynamicClassification());
lambdaQueryWrapper.eq(SysDictItem::getDictId, "1704331613726781442");
SysDictItem sysDictItem = sysDictItemService.getOne(lambdaQueryWrapper);
map.put("type", sysDictItem.getItemText());
map.put("name", loginUser.getRealname());
sendMessageDTO.setMap(map);
sendMessageAPI.sendMessage(sendMessageDTO);
}
}
}
@@ -384,6 +384,8 @@ hiwork:
todoUrl: taskapi/task.basedata/integrationCall/workflowIntegration
# 统一消息集成
messageUrl: taskapi/task.basedata/notice/noticeCalls/send
# 是否发送消息
isSend: false
# 汽车标准数字化平台ASMS
asms: