fix:使用模板引擎消息模板
This commit is contained in:
parent
e5fbffe637
commit
57d4d58a7a
|
@ -37,13 +37,13 @@ public enum MessageTypeEnum {
|
||||||
*/
|
*/
|
||||||
String type;
|
String type;
|
||||||
|
|
||||||
String value;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类型说明
|
* 类型说明
|
||||||
*/
|
*/
|
||||||
String note;
|
String note;
|
||||||
|
|
||||||
|
String value;
|
||||||
|
|
||||||
public String getNote() {
|
public String getNote() {
|
||||||
return note;
|
return note;
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,7 @@ public enum MessageTypeEnum {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue() {
|
public String getValue() { return value;}
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取字典数据
|
* 获取字典数据
|
||||||
|
@ -81,12 +79,18 @@ public enum MessageTypeEnum {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MessageTypeEnum typeOf(String type) {
|
public static MessageTypeEnum typeOf(String type) {
|
||||||
for (MessageTypeEnum e : MessageTypeEnum.values()) {
|
for (MessageTypeEnum messageType : MessageTypeEnum.values()) {
|
||||||
if (e.getValue().equals(type)) {
|
if (messageType.getType().equals(type))
|
||||||
return e;
|
return messageType;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MessageTypeEnum valueOf1(String value) {
|
||||||
|
for (MessageTypeEnum messageType : MessageTypeEnum.values()) {
|
||||||
|
if (messageType.getValue().equals(value))
|
||||||
|
return messageType;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,13 @@ public class DataTool {
|
||||||
private final Map<String, Object> data = new HashMap<>();
|
private final Map<String, Object> data = new HashMap<>();
|
||||||
|
|
||||||
public DataTool put(Object value) {
|
public DataTool put(Object value) {
|
||||||
data.put(String.format("${%d}", counter), value);
|
data.put(String.format("p%d", counter), value);
|
||||||
counter++;
|
counter++;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataTool put(String key, Object value) {
|
public DataTool put(String key, Object value) {
|
||||||
data.put(String.format("${%s}", key), value);
|
data.put(key, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,12 @@
|
||||||
package org.jeecg.common.util;
|
package org.jeecg.common.util;
|
||||||
|
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import org.jeecg.common.api.dto.message.MessageDTO;
|
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||||
import org.jeecg.common.constant.RedisConstant;
|
|
||||||
import org.jeecg.common.util.dynamic.db.FreemarkerParseFactory;
|
import org.jeecg.common.util.dynamic.db.FreemarkerParseFactory;
|
||||||
import org.jeecg.modules.base.entity.postgre.SysMessageTemplate;
|
import org.jeecg.modules.base.entity.postgre.SysMessageTemplate;
|
||||||
import org.thymeleaf.TemplateEngine;
|
import org.jeecg.modules.base.service.ISysMessageTemplateService;
|
||||||
import org.thymeleaf.context.Context;
|
|
||||||
import org.thymeleaf.templatemode.TemplateMode;
|
|
||||||
import org.thymeleaf.templateresolver.DefaultTemplateResolver;
|
|
||||||
import org.thymeleaf.templateresolver.StringTemplateResolver;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -19,21 +14,20 @@ import java.util.Map;
|
||||||
* */
|
* */
|
||||||
public class TemplateUtil {
|
public class TemplateUtil {
|
||||||
|
|
||||||
private static final RedisUtil redisUtil;
|
private static final ISysMessageTemplateService templateService;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
redisUtil = SpringContextUtils.getBean(RedisUtil.class);
|
templateService = SpringContextUtils.getBean(ISysMessageTemplateService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MessageDTO parse(String code, Map<String, Object> data){
|
public static MessageDTO parse(String code, Map<String, Object> data){
|
||||||
String key = RedisConstant.PREFIX_TEMPLATE + code;
|
|
||||||
MessageDTO messageDTO = new MessageDTO();
|
MessageDTO messageDTO = new MessageDTO();
|
||||||
if (!redisUtil.hasKey(key))
|
SysMessageTemplate template = templateService.getOne(code);
|
||||||
|
// 如果没有消息模板
|
||||||
|
if(ObjectUtil.isNull(template))
|
||||||
return messageDTO;
|
return messageDTO;
|
||||||
SysMessageTemplate template = (SysMessageTemplate) redisUtil.get(key);
|
|
||||||
String templateName = template.getTemplateName();
|
String templateName = template.getTemplateName();
|
||||||
String templateContent = template.getTemplateContent();
|
String templateContent = template.getTemplateContent();
|
||||||
|
|
||||||
messageDTO.setTitle(templateName);
|
messageDTO.setTitle(templateName);
|
||||||
if (MapUtil.isEmpty(data))
|
if (MapUtil.isEmpty(data))
|
||||||
return messageDTO;
|
return messageDTO;
|
||||||
|
@ -43,15 +37,14 @@ public class TemplateUtil {
|
||||||
return messageDTO;
|
return messageDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MessageDTO parse(String title, String code, Map<String, Object> data){
|
public static MessageDTO parse(String title, String code, Map<String, Object> data) {
|
||||||
String key = RedisConstant.PREFIX_TEMPLATE + code;
|
|
||||||
MessageDTO messageDTO = new MessageDTO();
|
MessageDTO messageDTO = new MessageDTO();
|
||||||
if (!redisUtil.hasKey(key))
|
SysMessageTemplate template = templateService.getOne(code);
|
||||||
|
// 如果没有消息模板
|
||||||
|
if(ObjectUtil.isNull(template))
|
||||||
return messageDTO;
|
return messageDTO;
|
||||||
SysMessageTemplate template = (SysMessageTemplate) redisUtil.get(key);
|
|
||||||
String templateName = template.getTemplateName();
|
String templateName = template.getTemplateName();
|
||||||
String templateContent = template.getTemplateContent();
|
String templateContent = template.getTemplateContent();
|
||||||
|
|
||||||
messageDTO.setTitle(StrUtil.isBlank(title) ? templateName : title);
|
messageDTO.setTitle(StrUtil.isBlank(title) ? templateName : title);
|
||||||
if (MapUtil.isEmpty(data))
|
if (MapUtil.isEmpty(data))
|
||||||
return messageDTO;
|
return messageDTO;
|
||||||
|
|
|
@ -6,7 +6,9 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.jeecg.common.constant.enums.MessageTypeEnum;
|
||||||
import org.jeecg.modules.base.entity.Rule;
|
import org.jeecg.modules.base.entity.Rule;
|
||||||
|
import org.jeecg.modules.base.enums.Enabled;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -109,4 +111,12 @@ public class AlarmRule implements Serializable {
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private Rule rule;
|
private Rule rule;
|
||||||
|
|
||||||
|
/* 数据库表中以下两个属性均有默认值
|
||||||
|
新增规则缓存到Redis中,也为这两个属性设置默认值
|
||||||
|
*/
|
||||||
|
public AlarmRule(){
|
||||||
|
this.enabled = Enabled.ENABLED.getValue();
|
||||||
|
this.notification = MessageTypeEnum.ALL.getValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.jeecg.modules.message.mapper;
|
package org.jeecg.modules.base.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="org.jeecg.modules.message.mapper.SysMessageTemplateMapper">
|
<mapper namespace="org.jeecg.modules.base.mapper.SysMessageTemplateMapper">
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
|
@ -1,4 +1,4 @@
|
||||||
package org.jeecg.modules.message.service;
|
package org.jeecg.modules.base.service;
|
||||||
|
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.common.system.base.service.JeecgService;
|
import org.jeecg.common.system.base.service.JeecgService;
|
||||||
|
@ -21,6 +21,8 @@ public interface ISysMessageTemplateService extends JeecgService<SysMessageTempl
|
||||||
*/
|
*/
|
||||||
List<SysMessageTemplate> selectByCode(String code);
|
List<SysMessageTemplate> selectByCode(String code);
|
||||||
|
|
||||||
|
SysMessageTemplate getOne(String code);
|
||||||
|
|
||||||
Result<?> addOrUpdate(SysMessageTemplate template);
|
Result<?> addOrUpdate(SysMessageTemplate template);
|
||||||
|
|
||||||
Result<?> delById(String id);
|
Result<?> delById(String id);
|
|
@ -1,4 +1,4 @@
|
||||||
package org.jeecg.modules.message.service.impl;
|
package org.jeecg.modules.base.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
@ -7,21 +7,16 @@ import org.jeecg.common.constant.RedisConstant;
|
||||||
import org.jeecg.common.system.base.service.impl.JeecgServiceImpl;
|
import org.jeecg.common.system.base.service.impl.JeecgServiceImpl;
|
||||||
import org.jeecg.common.util.RedisUtil;
|
import org.jeecg.common.util.RedisUtil;
|
||||||
import org.jeecg.modules.base.entity.postgre.SysMessageTemplate;
|
import org.jeecg.modules.base.entity.postgre.SysMessageTemplate;
|
||||||
import org.jeecg.modules.message.mapper.SysMessageTemplateMapper;
|
import org.jeecg.modules.base.mapper.SysMessageTemplateMapper;
|
||||||
import org.jeecg.modules.message.service.ISysMessageTemplateService;
|
import org.jeecg.modules.base.service.ISysMessageTemplateService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
|
||||||
* @Description: 消息模板
|
|
||||||
* @Author: jeecg-boot
|
|
||||||
* @Date: 2019-04-09
|
|
||||||
* @Version: V1.0
|
|
||||||
*/
|
|
||||||
@Service
|
@Service
|
||||||
public class SysMessageTemplateServiceImpl extends JeecgServiceImpl<SysMessageTemplateMapper, SysMessageTemplate> implements ISysMessageTemplateService {
|
public class SysMessageTemplateServiceImpl extends JeecgServiceImpl<SysMessageTemplateMapper, SysMessageTemplate> implements ISysMessageTemplateService {
|
||||||
|
|
||||||
|
@ -35,6 +30,19 @@ public class SysMessageTemplateServiceImpl extends JeecgServiceImpl<SysMessageTe
|
||||||
return baseMapper.selectByCode(code);
|
return baseMapper.selectByCode(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysMessageTemplate getOne(String code) {
|
||||||
|
String key = PREFIX + code;
|
||||||
|
if (redisUtil.hasKey(key))
|
||||||
|
return (SysMessageTemplate) redisUtil.get(key);
|
||||||
|
Optional<SysMessageTemplate> first = selectByCode(code).stream().findFirst();
|
||||||
|
if (!first.isPresent())
|
||||||
|
return null;
|
||||||
|
SysMessageTemplate template = first.get();
|
||||||
|
redisUtil.set(key, template);
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public Result<?> addOrUpdate(SysMessageTemplate template) {
|
public Result<?> addOrUpdate(SysMessageTemplate template) {
|
|
@ -47,16 +47,16 @@ public class TemplateManager {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SystemClient systemClient;
|
private SystemClient systemClient;
|
||||||
|
|
||||||
private final String templateKey = "template";
|
private final String TEMPLATEKEY = "template";
|
||||||
|
|
||||||
private final ConcurrentMap<String, JdbcTemplate> templateMap = new ConcurrentHashMap<>();
|
private final ConcurrentMap<String, JdbcTemplate> templateMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private void setTemplate(JdbcTemplate template){
|
private void setTemplate(JdbcTemplate template){
|
||||||
templateMap.put(templateKey, template);
|
templateMap.put(TEMPLATEKEY, template);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JdbcTemplate getTemplate(){
|
public JdbcTemplate getTemplate(){
|
||||||
return templateMap.get(templateKey);
|
return templateMap.get(TEMPLATEKEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -33,7 +33,6 @@ import org.springframework.data.redis.connection.stream.ObjectRecord;
|
||||||
import org.springframework.data.redis.connection.stream.RecordId;
|
import org.springframework.data.redis.connection.stream.RecordId;
|
||||||
import org.springframework.data.redis.stream.StreamListener;
|
import org.springframework.data.redis.stream.StreamListener;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
import static org.jeecg.common.constant.enums.MessageTypeEnum.*;
|
import static org.jeecg.common.constant.enums.MessageTypeEnum.*;
|
||||||
import static org.jeecg.common.util.TokenUtils.getTempToken;
|
import static org.jeecg.common.util.TokenUtils.getTempToken;
|
||||||
|
@ -59,7 +58,7 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
|
||||||
private AnalysisResultService analysisResultService;
|
private AnalysisResultService analysisResultService;
|
||||||
private IAlarmAnalysisNuclideAvgService nuclideAvgService;
|
private IAlarmAnalysisNuclideAvgService nuclideAvgService;
|
||||||
|
|
||||||
private final String comma = SymbolConstant.COMMA;
|
private final String COMMA = SymbolConstant.COMMA;
|
||||||
|
|
||||||
public AnalysisConsumer(String groupName, String consumerName) {
|
public AnalysisConsumer(String groupName, String consumerName) {
|
||||||
this.groupName = groupName;
|
this.groupName = groupName;
|
||||||
|
@ -127,7 +126,7 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
|
||||||
String nuclidesStr = rule.getNuclides();
|
String nuclidesStr = rule.getNuclides();
|
||||||
if (StrUtil.isBlank(nuclidesStr)) continue;
|
if (StrUtil.isBlank(nuclidesStr)) continue;
|
||||||
Set<String> names = nuclides.keySet();
|
Set<String> names = nuclides.keySet();
|
||||||
List<String> follow = ListUtil.toList(nuclidesStr.split(comma));
|
List<String> follow = ListUtil.toList(nuclidesStr.split(COMMA));
|
||||||
// 推送过来的核素集合与所关注核素集合取交集
|
// 推送过来的核素集合与所关注核素集合取交集
|
||||||
Collection<String> cross = CollectionUtil.intersection(names, follow);
|
Collection<String> cross = CollectionUtil.intersection(names, follow);
|
||||||
if (CollUtil.isEmpty(cross)) continue;
|
if (CollUtil.isEmpty(cross)) continue;
|
||||||
|
@ -150,7 +149,7 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
|
||||||
String conditionStr = info.getConditions();
|
String conditionStr = info.getConditions();
|
||||||
String betaOrGamma = info.getBetaOrGamma();
|
String betaOrGamma = info.getBetaOrGamma();
|
||||||
String datasource = info.getDatasource();
|
String datasource = info.getDatasource();
|
||||||
List<String> conditions = ListUtil.toList(conditionStr.split(comma));
|
List<String> conditions = ListUtil.toList(conditionStr.split(COMMA));
|
||||||
for (String con : conditions) {
|
for (String con : conditions) {
|
||||||
Condition condition = Condition.valueOf1(con);
|
Condition condition = Condition.valueOf1(con);
|
||||||
if (ObjectUtil.isNotNull(condition)){
|
if (ObjectUtil.isNotNull(condition)){
|
||||||
|
@ -158,7 +157,7 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
|
||||||
case FIRST_FOUND: // 首次发现该元素
|
case FIRST_FOUND: // 首次发现该元素
|
||||||
firstDetected = firstDetected(betaOrGamma,datasource,nuclideNames);
|
firstDetected = firstDetected(betaOrGamma,datasource,nuclideNames);
|
||||||
if (CollUtil.isNotEmpty(firstDetected)){
|
if (CollUtil.isNotEmpty(firstDetected)){
|
||||||
String message = "First discovery of nuclides: [" + StrUtil.join(comma,firstDetected) + "]";
|
String message = "First discovery of nuclides: [" + StrUtil.join(COMMA,firstDetected) + "]";
|
||||||
alarmInfo.append(message);
|
alarmInfo.append(message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -169,14 +168,14 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
|
||||||
String nuclide = nuclideInfo.getNuclide();
|
String nuclide = nuclideInfo.getNuclide();
|
||||||
String threshold = nuclideInfo.getThreshold();
|
String threshold = nuclideInfo.getThreshold();
|
||||||
String message = "Nuclide " + nuclide + "is above average: " + threshold;
|
String message = "Nuclide " + nuclide + "is above average: " + threshold;
|
||||||
alarmInfo.append(comma).append(message);
|
alarmInfo.append(COMMA).append(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MEANWHILE: // 同时出现两种及以上核素
|
case MEANWHILE: // 同时出现两种及以上核素
|
||||||
if (nuclideNames.size() >= 2){
|
if (nuclideNames.size() >= 2){
|
||||||
String message = "Simultaneously detecting nuclides: [" + StrUtil.join(comma,nuclideNames) + "]";
|
String message = "Simultaneously detecting nuclides: [" + StrUtil.join(COMMA,nuclideNames) + "]";
|
||||||
alarmInfo.append(comma).append(message);
|
alarmInfo.append(COMMA).append(message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -191,7 +190,7 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
|
||||||
SampleType sampleType = SampleType.typeOf(betaOrGamma);
|
SampleType sampleType = SampleType.typeOf(betaOrGamma);
|
||||||
if (ObjectUtil.isNotNull(sampleType))
|
if (ObjectUtil.isNotNull(sampleType))
|
||||||
logInfo.setSampleType(sampleType.getValue());
|
logInfo.setSampleType(sampleType.getValue());
|
||||||
if (alarmInfo.toString().startsWith(comma))
|
if (alarmInfo.toString().startsWith(COMMA))
|
||||||
alarmInfo = new StringBuilder(StrUtil.sub(alarmInfo.toString(), 1, alarmInfo.length()));
|
alarmInfo = new StringBuilder(StrUtil.sub(alarmInfo.toString(), 1, alarmInfo.length()));
|
||||||
logInfo.setAlarmInfo(alarmInfo.toString());
|
logInfo.setAlarmInfo(alarmInfo.toString());
|
||||||
if (CollUtil.isNotEmpty(moreThanAvg))
|
if (CollUtil.isNotEmpty(moreThanAvg))
|
||||||
|
|
|
@ -2,17 +2,17 @@ package org.jeecg.modules.message;
|
||||||
|
|
||||||
import cn.hutool.core.collection.ListUtil;
|
import cn.hutool.core.collection.ListUtil;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import org.jeecg.common.api.dto.message.MessageDTO;
|
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||||
import org.jeecg.common.config.mqtoken.UserTokenContext;
|
|
||||||
import org.jeecg.common.constant.SymbolConstant;
|
import org.jeecg.common.constant.SymbolConstant;
|
||||||
|
import org.jeecg.common.constant.enums.MessageTypeEnum;
|
||||||
import org.jeecg.common.system.api.ISysBaseAPI;
|
import org.jeecg.common.system.api.ISysBaseAPI;
|
||||||
import org.jeecg.modules.base.entity.postgre.SysUser;
|
import org.jeecg.modules.base.entity.postgre.SysUser;
|
||||||
import org.jeecg.modules.feignclient.AbnormalAlarmClient;
|
import org.jeecg.modules.feignclient.AbnormalAlarmClient;
|
||||||
import org.jeecg.modules.system.service.ISysUserService;
|
import org.jeecg.modules.system.service.ISysUserService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -20,7 +20,6 @@ import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.jeecg.common.constant.enums.MessageTypeEnum.*;
|
import static org.jeecg.common.constant.enums.MessageTypeEnum.*;
|
||||||
import static org.jeecg.common.util.TokenUtils.getTempToken;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息推送 (站内|邮箱|短信)
|
* 消息推送 (站内|邮箱|短信)
|
||||||
|
@ -31,10 +30,10 @@ import static org.jeecg.common.util.TokenUtils.getTempToken;
|
||||||
@Component
|
@Component
|
||||||
public class SendMessage {
|
public class SendMessage {
|
||||||
|
|
||||||
private final String Sms = "Phone";
|
private final String SMS = "Phone";
|
||||||
private final String Email = "Email";
|
private final String EMAIL = "Email";
|
||||||
private final String System = "Username";
|
private final String SYSTEM = "Username";
|
||||||
private final String comma = SymbolConstant.COMMA;
|
private final String COMMA = SymbolConstant.COMMA;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysBaseAPI sysBaseAPI;
|
private ISysBaseAPI sysBaseAPI;
|
||||||
|
@ -51,35 +50,41 @@ public class SendMessage {
|
||||||
*/
|
*/
|
||||||
public void send(MessageDTO messageDTO, String groupId, String notific){
|
public void send(MessageDTO messageDTO, String groupId, String notific){
|
||||||
Map<String, String> contact = getContact(groupId);
|
Map<String, String> contact = getContact(groupId);
|
||||||
if (StrUtil.isBlank(notific))return;
|
if (StrUtil.isBlank(notific)) return;
|
||||||
List<String> ways = ListUtil.toList(notific.split(comma));
|
List<String> ways = ListUtil.toList(StrUtil.split(notific, COMMA));
|
||||||
if (ways.contains(ALL.getValue())){
|
if (ways.contains(ALL.getValue()))
|
||||||
ways = ListUtil.toList(XT.getValue(), YJ.getValue(),SMS.getValue());
|
ways = ListUtil.toList(XT.getValue(), YJ.getValue(), MessageTypeEnum.SMS.getValue());
|
||||||
}
|
|
||||||
for (String way : ways) {
|
for (String way : ways) {
|
||||||
if(way.equals(XT.getValue())){// 1.推送系统消息
|
MessageTypeEnum messageType = valueOf1(way);
|
||||||
String toSys = contact.get(System);
|
if (ObjectUtil.isNotNull(messageType)){
|
||||||
if (StrUtil.isNotBlank(toSys)){
|
switch (messageType){
|
||||||
messageDTO.setToUser(toSys);
|
case XT: // 站内消息
|
||||||
messageDTO.setType(XT.getType());
|
String toSys = contact.get(SYSTEM);
|
||||||
sysBaseAPI.sendMessage(messageDTO);
|
if (StrUtil.isBlank(toSys)) continue;
|
||||||
}
|
messageDTO.setToUser(toSys);
|
||||||
} else if (way.equals(YJ.getValue())) {// 2.推送邮箱
|
messageDTO.setType(XT.getType());
|
||||||
String toEmail = contact.get(Email);
|
sysBaseAPI.sendMessage(messageDTO);
|
||||||
if (StrUtil.isNotBlank(toEmail)){
|
break;
|
||||||
// messageDTO.setToUser(toEmail);
|
case YJ: // 邮箱消息
|
||||||
messageDTO.setType(YJ.getType());
|
String toEmail = contact.get(EMAIL);
|
||||||
Map<String, String> userEmail = new HashMap<>(contact);
|
if (StrUtil.isBlank(toEmail)) continue;
|
||||||
MapUtil.removeAny(userEmail, Sms, Email, System);
|
// messageDTO.setToUser(toEmail);
|
||||||
messageDTO.setUserEmail(userEmail);
|
messageDTO.setType(YJ.getType());
|
||||||
sysBaseAPI.sendMessage(messageDTO);
|
Map<String, String> userEmail = new HashMap<>(contact);
|
||||||
}
|
MapUtil.removeAny(userEmail, SMS, EMAIL, SYSTEM);
|
||||||
} else if (way.equals(SMS.getValue())) {// 3.推送短信
|
messageDTO.setUserEmail(userEmail);
|
||||||
String toSms = contact.get(Sms);
|
sysBaseAPI.sendMessage(messageDTO);
|
||||||
if (StrUtil.isNotBlank(toSms)){
|
break;
|
||||||
messageDTO.setToUser(toSms);
|
case SMS: // 手机短信
|
||||||
messageDTO.setType(SMS.getType());
|
String toSms = contact.get(SMS);
|
||||||
sysBaseAPI.sendMessage(messageDTO);
|
if (StrUtil.isBlank(toSms)) continue;
|
||||||
|
messageDTO.setToUser(toSms);
|
||||||
|
messageDTO.setType(MessageTypeEnum.SMS.getType());
|
||||||
|
sysBaseAPI.sendMessage(messageDTO);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,27 +100,21 @@ public class SendMessage {
|
||||||
// 查询用户信息
|
// 查询用户信息
|
||||||
List<SysUser> sysUsers = sysUserService.listByIds(userIds);
|
List<SysUser> sysUsers = sysUserService.listByIds(userIds);
|
||||||
// 用户名
|
// 用户名
|
||||||
String usernameList = sysUsers.stream()
|
String usernameList = sysUsers.stream().map(SysUser::getUsername).filter(StrUtil::isNotBlank)
|
||||||
.filter(user -> StrUtil.isNotBlank(user.getUsername()))
|
.collect(Collectors.joining(COMMA));
|
||||||
.map(SysUser::getUsername)
|
|
||||||
.collect(Collectors.joining(comma));
|
|
||||||
// 邮箱
|
// 邮箱
|
||||||
String emailList = sysUsers.stream()
|
String emailList = sysUsers.stream().map(SysUser::getEmail).filter(StrUtil::isNotBlank)
|
||||||
.filter(user -> StrUtil.isNotBlank(user.getEmail()))
|
.collect(Collectors.joining(COMMA));
|
||||||
.map(SysUser::getEmail)
|
|
||||||
.collect(Collectors.joining(comma));
|
|
||||||
// 用户名-邮箱Map
|
// 用户名-邮箱Map
|
||||||
Map<String, String> userEmail = sysUsers.stream()
|
Map<String, String> userEmail = sysUsers.stream()
|
||||||
.collect(Collectors.toMap(SysUser::getUsername, SysUser::getEmail));
|
.collect(Collectors.toMap(SysUser::getUsername, SysUser::getEmail));
|
||||||
// 手机号码
|
// 手机号码
|
||||||
String phoneList = sysUsers.stream()
|
String phoneList = sysUsers.stream().map(SysUser::getPhone).filter(StrUtil::isNotBlank)
|
||||||
.filter(user -> StrUtil.isNotBlank(user.getPhone()))
|
.collect(Collectors.joining(COMMA));
|
||||||
.map(SysUser::getPhone)
|
|
||||||
.collect(Collectors.joining(comma));
|
|
||||||
Map<String,String> result = new HashMap<>();
|
Map<String,String> result = new HashMap<>();
|
||||||
result.put(System,usernameList);
|
result.put(SYSTEM, usernameList);
|
||||||
result.put(Email,emailList);
|
result.put(EMAIL, emailList);
|
||||||
result.put(Sms,phoneList);
|
result.put(SMS, phoneList);
|
||||||
result.putAll(userEmail);
|
result.putAll(userEmail);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.jeecg.modules.message.controller;
|
package org.jeecg.modules.message.controller;
|
||||||
|
|
||||||
import cn.hutool.core.collection.ListUtil;
|
import cn.hutool.core.collection.ListUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
@ -16,15 +15,13 @@ import org.jeecg.common.system.query.QueryGenerator;
|
||||||
import org.jeecg.common.util.oConvertUtils;
|
import org.jeecg.common.util.oConvertUtils;
|
||||||
import org.jeecg.modules.message.entity.MsgParams;
|
import org.jeecg.modules.message.entity.MsgParams;
|
||||||
import org.jeecg.modules.base.entity.postgre.SysMessageTemplate;
|
import org.jeecg.modules.base.entity.postgre.SysMessageTemplate;
|
||||||
import org.jeecg.modules.message.service.ISysMessageTemplateService;
|
import org.jeecg.modules.base.service.ISysMessageTemplateService;
|
||||||
import org.jeecg.modules.message.util.PushMsgUtil;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.jeecg.modules.message.entity.SysMessage;
|
||||||
import org.jeecg.modules.base.entity.postgre.SysMessageTemplate;
|
import org.jeecg.modules.base.entity.postgre.SysMessageTemplate;
|
||||||
import org.jeecg.modules.message.handle.enums.SendMsgStatusEnum;
|
import org.jeecg.modules.message.handle.enums.SendMsgStatusEnum;
|
||||||
import org.jeecg.modules.message.service.ISysMessageService;
|
import org.jeecg.modules.message.service.ISysMessageService;
|
||||||
import org.jeecg.modules.message.service.ISysMessageTemplateService;
|
import org.jeecg.modules.base.service.ISysMessageTemplateService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.jeecg.common.api.dto.OnlineAuthDTO;
|
||||||
import org.jeecg.common.api.dto.message.*;
|
import org.jeecg.common.api.dto.message.*;
|
||||||
import org.jeecg.common.aspect.UrlMatchEnum;
|
import org.jeecg.common.aspect.UrlMatchEnum;
|
||||||
import org.jeecg.common.constant.*;
|
import org.jeecg.common.constant.*;
|
||||||
|
import org.jeecg.common.constant.enums.MessageTypeEnum;
|
||||||
import org.jeecg.common.desensitization.util.SensitiveInfoUtil;
|
import org.jeecg.common.desensitization.util.SensitiveInfoUtil;
|
||||||
import org.jeecg.common.exception.JeecgBootException;
|
import org.jeecg.common.exception.JeecgBootException;
|
||||||
import org.jeecg.common.system.api.ISysBaseAPI;
|
import org.jeecg.common.system.api.ISysBaseAPI;
|
||||||
|
@ -35,7 +36,7 @@ import org.jeecg.modules.message.handle.impl.EmailPushMsgHandle;
|
||||||
import org.jeecg.modules.message.handle.impl.EmailSendMsgHandle;
|
import org.jeecg.modules.message.handle.impl.EmailSendMsgHandle;
|
||||||
import org.jeecg.modules.message.handle.impl.SmsSendMsgHandle;
|
import org.jeecg.modules.message.handle.impl.SmsSendMsgHandle;
|
||||||
import org.jeecg.modules.message.handle.impl.SystemSendMsgHandle;
|
import org.jeecg.modules.message.handle.impl.SystemSendMsgHandle;
|
||||||
import org.jeecg.modules.message.service.ISysMessageTemplateService;
|
import org.jeecg.modules.base.service.ISysMessageTemplateService;
|
||||||
import org.jeecg.modules.message.websocket.WebSocket;
|
import org.jeecg.modules.message.websocket.WebSocket;
|
||||||
import org.jeecg.modules.system.mapper.*;
|
import org.jeecg.modules.system.mapper.*;
|
||||||
import org.jeecg.modules.system.service.*;
|
import org.jeecg.modules.system.service.*;
|
||||||
|
@ -1233,7 +1234,6 @@ public class SysBaseApiImpl implements ISysBaseAPI {
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
public void sendTemplateMessage(MessageDTO message) {
|
public void sendTemplateMessage(MessageDTO message) {
|
||||||
String type = message.getType();
|
|
||||||
String title = message.getTitle();
|
String title = message.getTitle();
|
||||||
String code = message.getTemplateCode();
|
String code = message.getTemplateCode();
|
||||||
if(StrUtil.isNotBlank(code)){
|
if(StrUtil.isNotBlank(code)){
|
||||||
|
@ -1252,25 +1252,44 @@ public class SysBaseApiImpl implements ISysBaseAPI {
|
||||||
message.setTitle(title).setContent(content);
|
message.setTitle(title).setContent(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(XT.getType().equals(type)){ // 站内消息
|
|
||||||
systemSendMsgHandle.sendMessage(message);
|
String type = message.getType();
|
||||||
}else if(YJ.getType().equals(type)){ // 邮箱消息
|
MessageTypeEnum messageType = typeOf(type);
|
||||||
emailPushMsgHandle.sendMessage(message);
|
if (ObjectUtil.isNotNull(messageType)){
|
||||||
} else if (SMS.getType().equals(type)) { // 手机短信
|
switch (messageType){
|
||||||
smsSendMsgHandle.sendMessage(message);
|
case XT: // 站内消息
|
||||||
|
systemSendMsgHandle.sendMessage(message);
|
||||||
|
break;
|
||||||
|
case YJ: // 邮箱消息
|
||||||
|
emailPushMsgHandle.sendMessage(message);
|
||||||
|
break;
|
||||||
|
case SMS: // 手机短信
|
||||||
|
smsSendMsgHandle.sendMessage(message);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(MessageDTO message) {
|
public void sendMessage(MessageDTO message) {
|
||||||
String type = message.getType();
|
String type = message.getType();
|
||||||
|
MessageTypeEnum messageType = typeOf(type);
|
||||||
if(XT.getType().equals(type)){ // 站内消息
|
if (ObjectUtil.isNotNull(messageType)){
|
||||||
systemSendMsgHandle.sendMessage(message);
|
switch (messageType){
|
||||||
}else if(YJ.getType().equals(type)){ // 邮箱消息
|
case XT: // 站内消息
|
||||||
emailPushMsgHandle.sendMessage(message);
|
systemSendMsgHandle.sendMessage(message);
|
||||||
} else if (SMS.getType().equals(type)) { // 手机短信
|
break;
|
||||||
smsSendMsgHandle.sendMessage(message);
|
case YJ: // 邮箱消息
|
||||||
|
emailPushMsgHandle.sendMessage(message);
|
||||||
|
break;
|
||||||
|
case SMS: // 手机短信
|
||||||
|
smsSendMsgHandle.sendMessage(message);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user