修改消息中心

This commit is contained in:
jinqiming 2021-06-29 19:58:43 +08:00
parent 16eb5da329
commit 4375ec4e44
11 changed files with 235 additions and 25 deletions

View File

@ -18,11 +18,11 @@ public class PatternUtils {
/**
* 替换消息模板参数
* @param map
* @param map 后面改成freemark模板取值的方式
* @param templateBody
* @return
*/
public static String builderTemplateBody(Map<String,String> map, String templateBody){
public static String builderTemplateBody(Map<String,Object> map, String templateBody){
String re = "(?<=\\$\\{).*?(?=\\})";
Pattern p = Pattern.compile(re);
Matcher m = p.matcher(templateBody);
@ -33,9 +33,8 @@ public class PatternUtils {
continue;
}
//如果为空这取null标识
String value = Optional.ofNullable(map.get(key)).orElse("null");
//todo 可以记录下取到空值的异常情况
message = message.replaceAll("\\$\\{" + key + "\\}", value);
Object value = Optional.ofNullable(map.get(key)).orElse("");
message = message.replaceAll("\\$\\{" + key + "\\}", String.valueOf(value));
}
return message;
}

View File

@ -39,6 +39,9 @@ public class AfterSignUserTaskCmd extends AbstractDynamicInjectionCmd implements
private String taskId;
//表单fromKey
private String fromKey;
@Override
public Void execute(CommandContext commandContext) {
@ -80,12 +83,14 @@ public class AfterSignUserTaskCmd extends AbstractDynamicInjectionCmd implements
addUserTask.setId(id);
addUserTask.setName(signUserTaskBuilder.getName());
addUserTask.setAssignee(signUserTaskBuilder.getAssignee());
addUserTask.setFormKey(fromKey);
process.addFlowElement(addUserTask);
signUserTaskBuilder.setDynamicTaskId(id);
String flowId = "sequenceFlow-"+CommandContextUtil.getProcessEngineConfiguration(commandContext).getIdGenerator().getNextId();
SequenceFlow newSequenceFlow = this.createSequenceFlow(addUserTask.getId(),currentTaskOutSequenceFlow.getTargetFlowElement().getId());
newSequenceFlow.setId(flowId);
//newSequenceFlow.set
process.addFlowElement(newSequenceFlow);
activity.setOutgoingFlows(Collections.singletonList(newSequenceFlow));

View File

@ -204,7 +204,7 @@ public class SendMessageEventLister extends AbstractEventListener {
ExecutionEntity execution = (ExecutionEntity) event.getEntity();
ProcessInstance processInstance = execution.getProcessInstance();
Map<String, String> map = new HashMap<>();
Map<String, Object> map = new HashMap<>();
map.put("toUser", getUserInfo(processInstance.getStartUserId()).getUserName());
map.put("starttime", DateUtil.formatDateTime(processInstance.getStartTime()));
map.put("processInstance", processInstance.getProcessDefinitionName());
@ -244,7 +244,7 @@ public class SendMessageEventLister extends AbstractEventListener {
executor.execute(() ->
flowCandidates.forEach(t -> {
Map<String, String> map = new HashMap<>();
Map<String, Object> map = new HashMap<>();
map.put("toUser", t.getUserName());
map.put("startUser", getUserInfo(processInstance.getStartUserId()).getUserName());
map.put("processInstance", processDefinition.getName());
@ -280,7 +280,7 @@ public class SendMessageEventLister extends AbstractEventListener {
ExecutionEntity execution = (ExecutionEntity) event.getEntity();
ProcessInstance processInstance = execution.getProcessInstance();
Map<String, String> map = new HashMap<>();
Map<String, Object> map = new HashMap<>();
map.put("toUser", getUserInfo(processInstance.getStartUserId()).getUserName());
map.put("starttime", DateUtil.formatDateTime(processInstance.getStartTime()));
map.put("processInstance", processInstance.getProcessDefinitionName());
@ -313,7 +313,7 @@ public class SendMessageEventLister extends AbstractEventListener {
executor.execute(() -> {
HistoricProcessInstance hisProcessInstance = getHisProcessInstance(event.getProcessInstanceId());
Map<String, String> map = buildSendProcessCompletedParam(hisProcessInstance);
Map<String, Object> map = buildSendProcessCompletedParam(hisProcessInstance);
SysSendMessageDTO sysSendMessageDTO = SysSendMessageDTO.builder().templateByCode(MessageConstants.PROCESS_COMPLETED_CODE)
.receiver(getUserInfo(hisProcessInstance.getStartUserId()).getEmail())
.paramMap(map)
@ -338,7 +338,7 @@ public class SendMessageEventLister extends AbstractEventListener {
executor.execute(() -> {
HistoricProcessInstance hisProcessInstance = getHisProcessInstance(event.getProcessInstanceId());
Map<String, String> map = buildSendProcessCompletedParam(hisProcessInstance);
Map<String, Object> map = buildSendProcessCompletedParam(hisProcessInstance);
SysSendMessageDTO sysSendMessageDTO = SysSendMessageDTO.builder().templateByCode(MessageConstants.PROCESS_COMPLETED_CODE)
.receiverSet(Sets.newHashSet(getUserInfo(hisProcessInstance.getStartUserId()).getDingUserId()))
@ -357,8 +357,8 @@ public class SendMessageEventLister extends AbstractEventListener {
*
* @param hisProcessInstance
*/
private Map<String, String> buildSendProcessCompletedParam(HistoricProcessInstance hisProcessInstance) {
Map<String, String> map = new HashMap<>();
private Map<String, Object> buildSendProcessCompletedParam(HistoricProcessInstance hisProcessInstance) {
Map<String, Object> map = new HashMap<>();
map.put("toUser", getUserInfo(hisProcessInstance.getStartUserId()).getUserName());
map.put("starttime", DateUtil.formatDateTime(hisProcessInstance.getStartTime()));
map.put("orderNo", hisProcessInstance.getBusinessKey());

View File

@ -40,7 +40,11 @@
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<!--freemarker-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<!-- 验证码 -->
<dependency>
<groupId>com.github.penggle</groupId>

View File

@ -0,0 +1,30 @@
package com.snow.framework.util;
import freemarker.cache.StringTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import lombok.extern.slf4j.Slf4j;
import java.io.StringWriter;
import java.util.Map;
@Slf4j
public class FreemarkUtils {
public static String process(String templateName,String templateValue,Map<String,Object> model){
Configuration configuration = new Configuration(Configuration.VERSION_2_3_27);
StringTemplateLoader templateLoader = new StringTemplateLoader();
configuration.setTemplateLoader(templateLoader);
configuration.setDefaultEncoding("UTF-8");
StringWriter stringWriter = new StringWriter();
Template template = null;
try {
template = new Template(templateName, templateValue, configuration);
template.process(model, stringWriter);
return stringWriter.toString();
} catch (Exception e) {
log.info("构建模板消息错误",e);
throw new RuntimeException(e);
}
}
}

View File

@ -36,7 +36,7 @@ public class SysSendMessageDTO implements Serializable {
/**
* 参数List
*/
private Map<String,String> paramMap;
private Map<String,Object> paramMap;
/**
* 接收人
@ -45,7 +45,7 @@ public class SysSendMessageDTO implements Serializable {
/**
* 接收人set集合
*/
private Set receiverSet;
private Set<String> receiverSet;
/**
* 抄送人
*/
@ -73,4 +73,14 @@ public class SysSendMessageDTO implements Serializable {
*/
private DingTalkMessageType dingTalkMessageType;
/**
* pc端url
*/
private String pcUrl;
/**
* app端url
*/
private String appUrl;
}

View File

@ -0,0 +1,84 @@
package com.snow.framework.web.service;
import cn.hutool.core.util.ObjectUtil;
import com.snow.common.utils.PatternUtils;
import com.snow.common.utils.StringUtils;
import com.snow.framework.util.FreemarkUtils;
import com.snow.framework.web.domain.common.SysSendMessageDTO;
import com.snow.system.domain.SysMessageTemplate;
import com.snow.system.domain.SysMessageTransition;
import com.snow.system.service.ISysMessageTemplateService;
import com.snow.system.service.ISysMessageTransitionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Set;
/**
* @author qimingjin
* @Title:
* @Description:
* @date 2021/6/29 16:33
*/
@Component
@Slf4j
public class InnerMessageService {
@Resource
private ISysMessageTemplateService sysMessageTemplateService;
@Resource
private ISysMessageTransitionService sysMessageTransitionService;
/**
* 发送站内信息
* @param sysSendMessageDTO
*/
public void sendInnerMessage(SysSendMessageDTO sysSendMessageDTO) {
SysMessageTransition message = new SysMessageTransition();
SysMessageTemplate sysMessageTemplate= sysMessageTemplateService.getSysMessageTemplateByCode(sysSendMessageDTO.getTemplateByCode());
if(ObjectUtil.isNull(sysMessageTemplate)){
log.error("@发送站内信是模板code不正确...");
throw new RuntimeException("模板code不正确");
}
Set<String> receiverSet = sysSendMessageDTO.getReceiverSet();
try {
message.setProducerId(sysSendMessageDTO.getFrom());
message.setTemplateCode(sysMessageTemplate.getTemplateCode());
//组装参数消息体
String messageContext = FreemarkUtils.process(sysMessageTemplate.getTemplateCode(), sysMessageTemplate.getTemplateBody(), sysSendMessageDTO.getParamMap());
if(StringUtils.isNotEmpty(sysMessageTemplate.getPcUrl())){
String pcUrl = FreemarkUtils.process(sysMessageTemplate.getTemplateCode(), sysMessageTemplate.getPcUrl(), sysSendMessageDTO.getParamMap());
message.setPcUrl(pcUrl);
}
if(StringUtils.isNotEmpty(sysMessageTemplate.getAppUrl())){
String appUrl = FreemarkUtils.process(sysMessageTemplate.getTemplateCode(), sysMessageTemplate.getAppUrl(), sysSendMessageDTO.getParamMap());
message.setAppUrl(appUrl);
}
message.setMessageContent(messageContext);
message.setMessageStatus(0L);
message.setIconClass(sysMessageTemplate.getIconClass());
}catch (Exception e){
log.error("调用sendSimpleMail发送邮件失败:{}",e.getMessage());
message.setMessageStatus(1L);
}
if(ObjectUtil.isNotNull(sysSendMessageDTO.getReceiver())){
message.setConsumerId(sysSendMessageDTO.getReceiver());
sysMessageTransitionService.insertSysMessageTransition(message);
}
if(!StringUtils.isEmpty(receiverSet)){
receiverSet.forEach(t->{
message.setConsumerId(t);
sysMessageTransitionService.insertSysMessageTransition(message);
});
}
}
}

View File

@ -41,6 +41,21 @@ public class SysMessageTemplate extends BaseEntity
@Excel(name = "1-钉钉消息2--邮件3--短信,4--站内消息")
private Long templateType;
/**
* 消息pc端url
*/
private String pcUrl;
/**
* 消息app端url
*/
private String appUrl;
/**
* 图标样式
*/
private String iconClass="fa fa-envelope fa-fw";
/** 0--正常1--禁用 */
@Excel(name = "0--正常1--禁用")
private Long templateStatus;

View File

@ -17,39 +17,56 @@ public class SysMessageTransition extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** null */
/** id */
private Long id;
/** 生产者id */
@Excel(name = "生产者id")
private String producerId;
private SysUser producerUser;
/** 消费者id */
@Excel(name = "消费者id")
private String consumerId;
private SysUser consumerUser;
/** 消息类型 */
@Excel(name = "消息类型")
private String messageType;
/** 消息外部id */
@Excel(name = "消息外部id")
private String messageOutsideId;
/**
* 模板code
*/
private String templateCode;
/**
* 消息内容
*/
private String messageContent;
/**
* 消息展示1app端 2pc端 3官网 4后台
*/
private String messageShow;
/**
* 消息pc端url
*/
private String pcUrl;
/**
* 消息app端url
*/
private String appUrl;
/** 0--正常1--禁用 */
@Excel(name = "0--正常1--禁用")
private Long messageStatus;
/** 0--未读1--已读 */
@Excel(name = "0--未读1--已读")
private Long messageReadStatus;
/** 0--正常1--删除 */
@Excel(name = "0--正常1--删除")
private Long isDelete;

View File

@ -11,6 +11,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="templateBody" column="template_body" />
<result property="templateDesc" column="template_desc" />
<result property="templateType" column="template_type" />
<result property="pcUrl" column="pc_url" />
<result property="appUrl" column="app_url" />
<result property="iconClass" column="icon_class" />
<result property="templateStatus" column="template_status" />
<result property="isDelete" column="is_delete" />
<result property="createBy" column="create_by" />
@ -20,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectSysMessageTemplateVo">
select id, template_code, template_name, template_body, template_desc, template_type, template_status, is_delete, create_by, create_time, update_by, update_time from sys_message_template
select id, template_code, template_name, template_body, pc_url,app_url,icon_class,template_desc, template_type, template_status, is_delete, create_by, create_time, update_by, update_time from sys_message_template
</sql>
<select id="selectSysMessageTemplateList" parameterType="SysMessageTemplate" resultMap="SysMessageTemplateResult">
@ -54,6 +57,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="templateBody != null and templateBody != ''">template_body,</if>
<if test="templateDesc != null">template_desc,</if>
<if test="templateType != null">template_type,</if>
<if test="pcUrl != null">pc_url,</if>
<if test="appUrl != null">app_url,</if>
<if test="iconClass != null">icon_class,</if>
<if test="templateStatus != null">template_status,</if>
<if test="isDelete != null">is_delete,</if>
<if test="createBy != null">create_by,</if>
@ -67,6 +73,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="templateBody != null and templateBody != ''">#{templateBody},</if>
<if test="templateDesc != null">#{templateDesc},</if>
<if test="templateType != null">#{templateType},</if>
<if test="pcUrl != null">#{pcUrl},</if>
<if test="appUrl != null">#{appUrl},</if>
<if test="iconClass != null">#{iconClass},</if>
<if test="templateStatus != null">#{templateStatus},</if>
<if test="isDelete != null">#{isDelete},</if>
<if test="createBy != null">#{createBy},</if>
@ -84,7 +93,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="templateBody != null and templateBody != ''">template_body = #{templateBody},</if>
<if test="templateDesc != null">template_desc = #{templateDesc},</if>
<if test="templateType != null">template_type = #{templateType},</if>
<if test="pcUrl != null">pc_url=#{pcUrl},</if>
<if test="appUrl != null">app_url=#{appUrl},</if>
<if test="templateStatus != null">template_status = #{templateStatus},</if>
<if test="iconClass != null">icon_class=#{iconClass},</if>
<if test="isDelete != null">is_delete = #{isDelete},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>

View File

@ -10,6 +10,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="consumerId" column="consumer_id" />
<result property="messageType" column="message_type" />
<result property="messageOutsideId" column="message_outside_id" />
<result property="templateCode" column="template_code" />
<result property="messageContent" column="message_content" />
<result property="messageShow" column="message_show" />
<result property="pcUrl" column="pc_url" />
<result property="appUrl" column="app_url" />
<result property="iconClass" column="icon_class" />
<result property="messageStatus" column="message_status" />
<result property="messageReadStatus" column="message_read_status" />
<result property="isDelete" column="is_delete" />
@ -20,7 +26,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectSysMessageTransitionVo">
select id, producer_id, consumer_id, message_type, message_outside_id, message_status, message_read_status, is_delete, create_by, create_time, update_by, update_time from sys_message_transition
select id, producer_id, consumer_id, message_type, message_outside_id,
template_code,message_content,message_show,pc_url,app_url,icon_class,
message_status, message_read_status, is_delete, create_by, create_time, update_by, update_time from sys_message_transition
</sql>
<select id="selectSysMessageTransitionList" parameterType="SysMessageTransition" resultMap="SysMessageTransitionResult">
@ -36,6 +44,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="messageStatus != null "> and message_status = #{messageStatus}</if>
<if test="messageReadStatus != null "> and message_read_status = #{messageReadStatus}</if>
<if test="isDelete != null "> and is_delete = #{isDelete}</if>
<if test="message_show != null "> and message_show = #{messageShow}</if>
<if test="template_code != null and templateCode != ''"> and template_code = #{templateCode}</if>
</where>
<if test="orderBy != null and orderBy != ''">
order by ${orderBy}
@ -56,6 +66,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="messageOutsideId != null">message_outside_id,</if>
<if test="messageStatus != null">message_status,</if>
<if test="messageReadStatus != null">message_read_status,</if>
<if test="templateCode != null">template_code,</if>
<if test="messageContent != null">message_content,</if>
<if test="messageShow != null">message_show,</if>
<if test="pcUrl != null">pc_url,</if>
<if test="appUrl != null">app_url,</if>
<if test="iconClass != null">icon_class,</if>
<if test="isDelete != null">is_delete,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
@ -69,6 +85,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="messageOutsideId != null">#{messageOutsideId},</if>
<if test="messageStatus != null">#{messageStatus},</if>
<if test="messageReadStatus != null">#{messageReadStatus},</if>
<if test="templateCode != null">#{templateCode},</if>
<if test="messageContent != null">#{messageContent},</if>
<if test="messageShow != null">#{messageShow},</if>
<if test="pcUrl != null">#{pcUrl},</if>
<if test="appUrl != null">#{appUrl},</if>
<if test="iconClass != null">#{iconClass},</if>
<if test="isDelete != null">#{isDelete},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
@ -86,6 +108,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="messageOutsideId != null">message_outside_id = #{messageOutsideId},</if>
<if test="messageStatus != null">message_status = #{messageStatus},</if>
<if test="messageReadStatus != null">message_read_status = #{messageReadStatus},</if>
<if test="templateCode != null">template_code=#{templateCode},</if>
<if test="messageContent != null">message_content=#{messageContent},</if>
<if test="messageShow != null">message_show=#{messageShow},</if>
<if test="pcUrl != null">pc_url=#{pcUrl},</if>
<if test="appUrl != null">app_url=#{appUrl},</if>
<if test="iconClass != null">icon_class=#{iconClass},</if>
<if test="isDelete != null">is_delete = #{isDelete},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
@ -104,6 +132,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="messageOutsideId != null">message_outside_id = #{messageOutsideId},</if>
<if test="messageStatus != null">message_status = #{messageStatus},</if>
<if test="messageReadStatus != null">message_read_status = #{messageReadStatus},</if>
<if test="templateCode != null">template_code=#{templateCode},</if>
<if test="messageContent != null">message_content=#{messageContent},</if>
<if test="messageShow != null">message_show=#{messageShow},</if>
<if test="pcUrl != null">pc_url=#{pcUrl},</if>
<if test="appUrl != null">app_url=#{appUrl},</if>
<if test="iconClass != null">icon_class=#{iconClass},</if>
<if test="isDelete != null">is_delete = #{isDelete},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>