This commit is contained in:
459816669@qq.com 2021-07-17 21:35:54 +08:00
parent 8413f45788
commit c90d2d6e6a
10 changed files with 140 additions and 34 deletions

View File

@ -93,7 +93,7 @@ public class FlowController extends BaseController {
* 获取我的待办列表
*/
@RequiresPermissions("flow:get:todoList")
@PostMapping("/findTasksByUserId")
@RequestMapping("/findTasksByUserId")
@ResponseBody
public TableDataInfo findTasksByUserId(TaskBaseDTO taskBaseDTO)
{

View File

@ -36,6 +36,11 @@ public class SysMessageCenterController extends BaseController
@Autowired
private ISysMessageTransitionService sysMessageTransitionService;
/**
* 跳转消息中心界面
* @param mmap
* @return
*/
@RequiresPermissions("system:messageCenter:view")
@GetMapping()
public String messageCenter(ModelMap mmap)
@ -47,6 +52,7 @@ public class SysMessageCenterController extends BaseController
sysMessageTransition.setOrderBy("update_time desc");
List<SysMessageTransition> sysMessageTransitions = sysMessageTransitionService.selectSysMessageTransitionList(sysMessageTransition);
//拜访日志tab页数据
if(CollectionUtil.isNotEmpty(sysMessageTransitions)){
List<SysMessageTransition> visitLogsList = sysMessageTransitions.stream().filter(t -> t.getMessageType().equals(MessageEventType.SEND_VISIT_LOG.getCode())).collect(Collectors.toList());
long count = visitLogsList.stream().filter(t -> t.getMessageReadStatus() == 0).count();
@ -62,6 +68,7 @@ public class SysMessageCenterController extends BaseController
mmap.put("emailList",emailList);
}
//待办tab页数据
if(CollectionUtil.isNotEmpty(sysMessageTransitions)){
List<SysMessageTransition> todoTaskList = sysMessageTransitions.stream().filter(t -> t.getMessageType().equals(MessageEventType.INNER_TASK_TODO.getCode())).collect(Collectors.toList());
long count = todoTaskList.stream().filter(t -> t.getMessageReadStatus() == 0).count();
@ -69,6 +76,14 @@ public class SysMessageCenterController extends BaseController
mmap.put("todoTaskList",todoTaskList);
}
//流程完结tab页数据
if(CollectionUtil.isNotEmpty(sysMessageTransitions)){
List<SysMessageTransition> processEndList = sysMessageTransitions.stream().filter(t -> t.getMessageType().equals(MessageEventType.INNER_PROCESS_END.getCode())).collect(Collectors.toList());
long count = processEndList.stream().filter(t -> t.getMessageReadStatus() == 0).count();
mmap.put("processEndCount",count);
mmap.put("processEndList",processEndList);
}
return prefix + "/messageCenter";
}
@ -101,7 +116,7 @@ public class SysMessageCenterController extends BaseController
* @param id
* @return
*/
@PostMapping( "/remarkRead")
@RequestMapping( "/remarkRead")
@ResponseBody
public AjaxResult remarkRead(Long id)
{

View File

@ -123,7 +123,7 @@
</a>
<ul class="dropdown-menu dropdown-alerts">
<li th:each="sysMessages,iterStat:${sysMessageList}" class="mt5">
<a href="javascript:void(0)" th:onclick="messageDetail([[${sysMessages.pcUrl}]]);">
<a href="javascript:void(0)" th:onclick="messageDetail([[${sysMessages.pcUrl}]]);" >
<i th:class="${sysMessages.iconClass}"></i><span class="text-success">[[${sysMessages.producerUser!=null?sysMessages.producerUser.userName:'系统'}]]</span> 发送来一条消息<span class="pull-right text-muted small">[[${sysMessages.spendTime}]]</span>
</a>
</li>
@ -284,7 +284,6 @@ function messageDetail(url){
area : ["70%", "80%"],
content : [url, 'yes']
})
}
function mailDetailAll() {

View File

@ -15,13 +15,20 @@
<a data-toggle="tab" href="#tab-1"> 拜访日志 <span class="label label-info pull-right">[[${visitLogCount}]]</span></a>
</li>
<li class="">
<a data-toggle="tab" href="#tab-2"> 站内邮件 <span class="label label-info pull-right" >[[${emailListCount}]]</span></a>
</li>
<li class="">
<a data-toggle="tab" href="#tab-3"> 流程待办 <span class="label label-info pull-right" >[[${todoTaskCount}]]</span></a>
</li>
<li class="">
<a data-toggle="tab" href="#tab-4"> 流程完结 <span class="label label-info pull-right" >[[${processEndCount}]]</span></a>
</li>
</ul>
<div class="tab-content ">
<div id="tab-1" class="tab-pane active">
@ -103,7 +110,7 @@
<strong th:text="${#dates.format(todoTask.createTime, 'yyyy-MM-dd HH:mm:ss')}"></strong>
</p>
<p >[[${todoTask.messageContent}]]</p>
<a href="javascript:void(0)" class="btn btn-sm btn-success" th:href="${todoTask.pcUrl}"> 查看详情 </a>
<a href="javascript:void(0)" class="btn btn-sm btn-success" th:onclick="messageDetail([[${todoTask.pcUrl}]]);"> 查看详情 </a>
<p>
<!--<small class="badge badge-warning"> <i class="fa fa-clock-o"></i>[[${todoTask.spendTime}]]</small>-->
</p>
@ -113,10 +120,39 @@
</div>
</div>
</div>
<div id="tab-4" class="tab-pane">
<div class="panel-body">
<h3>流程完结</h3>
<div id="vertical-timeline4" class="vertical-container light-timeline" th:each="processEnd,iterStat : ${processEndList}">
<div class="vertical-timeline-block">
<div class="vertical-timeline-icon blue-bg">
<i th:class="${processEnd.iconClass}"></i>
</div>
<div class="vertical-timeline-content">
<p>
<label th:switch="${processEnd.messageReadStatus}">
<span class="label label-danger" th:case="'0'">未读</span>
<span class="label label-success" th:case="'1'">已读</span>
</label>
<strong th:text="${#dates.format(processEnd.createTime, 'yyyy-MM-dd HH:mm:ss')}"></strong>
</p>
<p >[[${processEnd.messageContent}]]</p>
<a href="javascript:void(0)" class="btn btn-sm btn-success" th:onclick="messageDetail([[${processEnd.id}]],[[${processEnd.pcUrl}]]);"> 查看详情 </a>
</div>
<hr>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@ -125,7 +161,10 @@
<script th:inline="javascript">
function messageDetail(url){
function messageDetail(id,url){
//先标记为已读
markRead(id);
//在跳转到页面
layer.open({
type : 2,
shadeClose : true,
@ -135,6 +174,32 @@
})
}
function markRead(id){
var config = {
url: "/system/messageCenter/remarkRead",
type: "post",
dataType: "json",
data: {
"id":id
},
success: function(result) {
if (typeof callback == "function") {
callback(result);
}
if (result.code == web_status.SUCCESS) {
$(".messageReadStatus badge badge-primary").show();
$(".messageReadStatus badge badge-danger").hide();
} else if (result.code == web_status.WARNING) {
$.modal.alertWarning(result.msg)
} else {
$.modal.alertError(result.msg);
}
$.modal.closeLoading();
}
};
$.ajax(config)
}
</script>
</body>
</html>

View File

@ -43,4 +43,8 @@ public class MessageConstants {
public static final String INNER_TASK_CREATED_CODE="1415927384573616128";
/**
* 站内信流程完结模板
*/
public static final String INNER_PROCESS_END_CODE="1416370192572882944";
}

View File

@ -11,6 +11,8 @@ public enum MessageEventType {
INNER_TASK_TODO("INNER_TASK_TODO", "站内信任务待办"),
INNER_PROCESS_END("INNER_PROCESS_END", "站内信流程完结"),
TASK_FINISH("TASK_FINISH", "任务完成"),
SEND_EMAIL("SEND_EMAIL", "发送邮件"),

View File

@ -21,11 +21,13 @@ public class GlobalListenerConfig implements ApplicationListener<ContextRefreshe
private final TaskCreateListener taskCreateListener;
private final ProcessEndListener processEndListener;
@Override
public void onApplicationEvent(@NonNull ContextRefreshedEvent event) {
FlowableEventDispatcher dispatcher = configuration.getEventDispatcher();
// 流程结束事件
// dispatcher.addEventListener(processEndListener, FlowableEngineEventType.PROCESS_COMPLETED);
dispatcher.addEventListener(processEndListener, FlowableEngineEventType.PROCESS_COMPLETED);
//任务创建
dispatcher.addEventListener(taskCreateListener, FlowableEngineEventType.TASK_CREATED);
}

View File

@ -1,24 +1,32 @@
package com.snow.flowable.listener.common;
import cn.hutool.core.date.BetweenFormater;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.snow.common.constant.MessageConstants;
import com.snow.common.enums.MessageEventType;
import com.snow.flowable.common.enums.FlowDefEnum;
import com.snow.flowable.service.FlowableService;
import com.snow.framework.web.domain.common.MessageEventDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Map;
import java.util.Optional;
/**
* @author qimingjin
* @Title:
* @Title: 流程完结监听
* @Description:
* @date 2021/7/16 13:29
*/
@ -30,10 +38,13 @@ public class ProcessEndListener implements FlowableEventListener {
@Resource
private FlowableService flowableService;
@Resource
private ApplicationContext applicationContext;
@Override
public void onEvent(FlowableEvent flowableEvent) {
if (flowableEvent instanceof FlowableEngineEvent) {
FlowableEngineEvent flowableEngineEvent = (FlowableEngineEvent) flowableEvent;
if (flowableEvent instanceof FlowableEngineEntityEvent) {
FlowableEngineEntityEvent flowableEngineEvent = (FlowableEngineEntityEvent) flowableEvent;
ProcessDefinitionEntity processDefinition = flowableService.getProcessDefinition(flowableEngineEvent);
if(ObjectUtil.isNull(processDefinition)){
return;
@ -42,7 +53,9 @@ public class ProcessEndListener implements FlowableEventListener {
for (FlowDefEnum flowDefEnum : flowableService.getAllFlowDefEnumsSet()) {
//在流程中存在的才监听
if (flowDefEnum.getCode().equals(key)) {
HistoricProcessInstance processInstance = flowableService.getHistoricProcessInstanceById(flowableEngineEvent.getProcessInstanceId());
//发送站内信
sendInnerMessage(processInstance);
}
}
@ -51,6 +64,27 @@ public class ProcessEndListener implements FlowableEventListener {
}
private void sendInnerMessage(HistoricProcessInstance processInstance){
MessageEventDTO messageEventDTO=new MessageEventDTO(MessageEventType.INNER_PROCESS_END.getCode());
messageEventDTO.setProducerId(String.valueOf(0));
messageEventDTO.setConsumerIds(Sets.newHashSet(String.valueOf(processInstance.getStartUserId())));
messageEventDTO.setMessageEventType(MessageEventType.INNER_PROCESS_END);
messageEventDTO.setMessageOutsideId(processInstance.getId());
messageEventDTO.setMessageShow(2);
//计算流程用时
String spendTime= DateUtil.formatBetween(processInstance.getStartTime(), processInstance.getEndTime(), BetweenFormater.Level.SECOND);
Map<String,Object> map= Maps.newHashMap();
map.put("businessKey", processInstance.getBusinessKey());
map.put("startTime", DateUtil.formatDateTime(processInstance.getStartTime()));
map.put("processInstance", processInstance.getProcessDefinitionName());
map.put("spendTime", spendTime);
map.put("processInstanceId", processInstance.getId());
messageEventDTO.setParamMap(map);
messageEventDTO.setTemplateCode(MessageConstants.INNER_PROCESS_END_CODE);
applicationContext.publishEvent(messageEventDTO);
}
@Override
public boolean isFailOnException() {
return false;
@ -66,20 +100,4 @@ public class ProcessEndListener implements FlowableEventListener {
return null;
}
/**
* 获取流程定义信息
*
* @param event
* @return
*/
protected ProcessDefinitionEntity getProcessDefinition(FlowableEngineEvent event) {
String processDefinitionId = event.getProcessDefinitionId();
if (processDefinitionId != null) {
CommandContext commandContext = CommandContextUtil.getCommandContext();
if (commandContext != null) {
return CommandContextUtil.getProcessDefinitionEntityManager(commandContext).findById(processDefinitionId);
}
}
return null;
}
}

View File

@ -88,13 +88,13 @@ public class TaskCreateListener implements FlowableEventListener {
messageEventDTO.setProducerId(String.valueOf(0));
messageEventDTO.setConsumerIds(Sets.newHashSet(String.valueOf(toUsers.getUserId())));
messageEventDTO.setMessageEventType(MessageEventType.INNER_TASK_TODO);
messageEventDTO.setMessageOutsideId(processInstance.getId());
messageEventDTO.setMessageOutsideId(entity.getId());
messageEventDTO.setMessageShow(2);
Map<String,Object> map= Maps.newHashMap();
map.put("startUser", startSysUser.getUserName());
map.put("startTime", DateUtil.formatDateTime(processInstance.getStartTime()));
map.put("processInstance", processInstance.getProcessDefinitionName());
//map.put("url", "http://localhost/flow/getMyHistoricProcessInstance");
map.put("taskId", entity.getId());
map.put("taskName", entity.getName());
messageEventDTO.setParamMap(map);
messageEventDTO.setTemplateCode(MessageConstants.INNER_TASK_CREATED_CODE);

View File

@ -39,6 +39,7 @@ public class MessageEventHandler implements ApplicationListener<MessageEventDTO>
case "SEND_VISIT_LOG":
case "REGISTER_ACCOUNT_SUCCESS":
case "INNER_TASK_TODO":
case "INNER_PROCESS_END":
messageEventContext.setMessageEventTypeStrategy(new InnerMessageStrategy());
break;