Browse Source

[feat]

1、修改工作流消息推送
pull/1/head
杨威 4 months ago
parent
commit
068a09241f
  1. 2
      dk-common/common-sse/src/main/java/org/dromara/common/sse/config/SseAutoConfiguration.java
  2. 10
      dk-common/common-sse/src/main/java/org/dromara/common/sse/controller/SseController.java
  3. 1
      dk-common/common-sse/src/main/java/org/dromara/common/sse/listener/SseTopicListener.java
  4. 20
      dk-modules/business/src/main/java/org/dromara/business/controller/BusinessPatrolAreasController.java
  5. 53
      dk-modules/workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskServiceImpl.java

2
dk-common/common-sse/src/main/java/org/dromara/common/sse/config/SseAutoConfiguration.java

@ -14,7 +14,7 @@ import org.springframework.context.annotation.Bean;
* @author Lion Li * @author Lion Li
*/ */
@AutoConfiguration @AutoConfiguration
@ConditionalOnProperty(value = "sse.enabled", havingValue = "true") //@ConditionalOnProperty(value = "sse.enabled", havingValue = "true")
@EnableConfigurationProperties(SseProperties.class) @EnableConfigurationProperties(SseProperties.class)
public class SseAutoConfiguration { public class SseAutoConfiguration {

10
dk-common/common-sse/src/main/java/org/dromara/common/sse/controller/SseController.java

@ -21,7 +21,7 @@ import java.util.List;
* @author Lion Li * @author Lion Li
*/ */
@RestController @RestController
@ConditionalOnProperty(value = "sse.enabled", havingValue = "true") //@ConditionalOnProperty(value = "sse.enabled", havingValue = "true")
@RequiredArgsConstructor @RequiredArgsConstructor
public class SseController implements DisposableBean { public class SseController implements DisposableBean {
@ -30,7 +30,7 @@ public class SseController implements DisposableBean {
/** /**
* 建立 SSE 连接 * 建立 SSE 连接
*/ */
@GetMapping(value = "${sse.path}", produces = MediaType.TEXT_EVENT_STREAM_VALUE) @GetMapping(value = "/sse", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter connect() { public SseEmitter connect() {
String tokenValue = StpUtil.getTokenValue(); String tokenValue = StpUtil.getTokenValue();
Long userId = LoginHelper.getUserId(); Long userId = LoginHelper.getUserId();
@ -40,7 +40,7 @@ public class SseController implements DisposableBean {
/** /**
* 关闭 SSE 连接 * 关闭 SSE 连接
*/ */
@GetMapping(value = "${sse.path}/close") @GetMapping(value = "/sse/close")
public R<Void> close() { public R<Void> close() {
String tokenValue = StpUtil.getTokenValue(); String tokenValue = StpUtil.getTokenValue();
Long userId = LoginHelper.getUserId(); Long userId = LoginHelper.getUserId();
@ -54,7 +54,7 @@ public class SseController implements DisposableBean {
* @param userId 目标用户的 ID * @param userId 目标用户的 ID
* @param msg 要发送的消息内容 * @param msg 要发送的消息内容
*/ */
@GetMapping(value = "${sse.path}/send") @GetMapping(value = "/sse/send")
public R<Void> send(Long userId, String msg) { public R<Void> send(Long userId, String msg) {
SseMessageDto dto = new SseMessageDto(); SseMessageDto dto = new SseMessageDto();
dto.setUserIds(List.of(userId)); dto.setUserIds(List.of(userId));
@ -68,7 +68,7 @@ public class SseController implements DisposableBean {
* *
* @param msg 要发送的消息内容 * @param msg 要发送的消息内容
*/ */
@GetMapping(value = "${sse.path}/sendAll") @GetMapping(value = "/sse/sendAll")
public R<Void> send(String msg) { public R<Void> send(String msg) {
sseEmitterManager.publishAll(msg); sseEmitterManager.publishAll(msg);
return R.ok(); return R.ok();

1
dk-common/common-sse/src/main/java/org/dromara/common/sse/listener/SseTopicListener.java

@ -15,7 +15,6 @@ import org.springframework.stereotype.Component;
* @author Lion Li * @author Lion Li
*/ */
@Slf4j @Slf4j
@Component
public class SseTopicListener implements ApplicationRunner, Ordered { public class SseTopicListener implements ApplicationRunner, Ordered {
@Autowired @Autowired

20
dk-modules/business/src/main/java/org/dromara/business/controller/BusinessPatrolAreasController.java

@ -1,8 +1,6 @@
package org.dromara.business.controller; package org.dromara.business.controller;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.dromara.business.domain.BusinessPatrolAreas; import org.dromara.business.domain.BusinessPatrolAreas;
import org.dromara.business.domain.bo.BusinessPatrolAreasBo; import org.dromara.business.domain.bo.BusinessPatrolAreasBo;
@ -75,11 +73,7 @@ public class BusinessPatrolAreasController extends BaseController {
*/ */
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
public R<?> edit(@RequestBody BusinessPatrolAreas patrolAreas) { public R<?> edit(@RequestBody BusinessPatrolAreas patrolAreas) {
boolean flag = patrolAreasService.updatePatrolAreas(patrolAreas); return patrolAreasService.updatePatrolAreas(patrolAreas)?R.ok("添加成功!"):R.fail("添加失败");
if(flag){
return R.ok("添加成功!");
}
return R.fail("新增失败");
} }
/** /**
* 巡查区域-禁用/启用 * 巡查区域-禁用/启用
@ -89,11 +83,7 @@ public class BusinessPatrolAreasController extends BaseController {
*/ */
@RequestMapping(value = "/isDisable", method = {RequestMethod.PUT,RequestMethod.POST}) @RequestMapping(value = "/isDisable", method = {RequestMethod.PUT,RequestMethod.POST})
public R<?> isDisable(@RequestBody BusinessPatrolAreas patrolAreas) { public R<?> isDisable(@RequestBody BusinessPatrolAreas patrolAreas) {
boolean flag = patrolAreasService.updateById(patrolAreas); return patrolAreasService.updateById(patrolAreas)?R.ok("修改成功!"):R.fail("修改失败");
if(flag){
return R.ok("修改成功!");
}
return R.fail("操作失败");
} }
/** /**
* 巡查区域-删除 * 巡查区域-删除
@ -103,11 +93,7 @@ public class BusinessPatrolAreasController extends BaseController {
*/ */
@DeleteMapping(value = "/delete") @DeleteMapping(value = "/delete")
public R<?> delete(String id) { public R<?> delete(String id) {
boolean flag = patrolAreasService.removeById(id); return patrolAreasService.removeById(id)?R.ok("删除成功!"):R.fail("删除失败!");
if(flag){
return R.ok("删除成功!");
}
return R.fail("删除失败!");
} }
/** /**
* 导出excel * 导出excel

53
dk-modules/workflow/src/main/java/org/dromara/workflow/service/impl/FlwTaskServiceImpl.java

@ -187,8 +187,8 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
// 执行任务跳转,并根据返回的处理人设置下一步处理人 // 执行任务跳转,并根据返回的处理人设置下一步处理人
Instance instance = taskService.skip(taskId, flowParams); Instance instance = taskService.skip(taskId, flowParams);
this.setHandler(instance, flowTask, flowCopyList); this.setHandler(instance, flowTask, flowCopyList);
// 消息通知 // 待办消息通知
sendMessage(definition.getFlowName(), ins.getId(), messageType, notice); WorkflowUtils.sendMessage(definition.getFlowName(), ins.getId(), messageType, notice);
return true; return true;
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
@ -430,7 +430,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
Instance instance = insService.getById(inst.getId()); Instance instance = insService.getById(inst.getId());
this.setHandler(instance, task, null); this.setHandler(instance, task, null);
// 消息通知 // 消息通知
sendMessage(definition.getFlowName(), instance.getId(), messageType, notice); WorkflowUtils.sendMessage(definition.getFlowName(), instance.getId(), messageType, notice);
return true; return true;
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
@ -733,51 +733,4 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
service.completeTask(completeTaskBo); service.completeTask(completeTaskBo);
} }
/**
* 发送消息
* @param flowName
* @param instId
* @param messageType
* @param message
*/
private void sendMessage(String flowName, Long instId, List<String> messageType, String message) {
List<RemoteUserVo> userList = new ArrayList<>();
List<FlowTask> list = this.selectByInstId(instId);
if (StringUtils.isBlank(message)) {
message = "有新的【" + flowName + "】单据已经提交至您,请您及时处理。";
}
for (Task task : list) {
List<RemoteUserVo> users = this.currentTaskAllUser(task.getId());
if (CollUtil.isNotEmpty(users)) {
userList.addAll(users);
}
}
if (CollUtil.isNotEmpty(userList)) {
for (String code : messageType) {
MessageTypeEnum messageTypeEnum = MessageTypeEnum.getByCode(code);
if (ObjectUtil.isNotEmpty(messageTypeEnum)) {
switch (messageTypeEnum) {
case SYSTEM_MESSAGE:
SseMessageDto dto = new SseMessageDto();
dto.setUserIds(StreamUtils.toList(userList, RemoteUserVo::getUserId).stream().distinct().collect(Collectors.toList()));
dto.setMessage(message);
dto.getUserIds().forEach(userId -> {
remoteMessageService.publishMessage(userId,dto.getMessage());
});
break;
case EMAIL_MESSAGE:
MailUtils.sendText(StreamUtils.join(userList, RemoteUserVo::getEmail), "单据审批提醒", message);
break;
case SMS_MESSAGE:
//todo 短信发送
break;
default:
throw new IllegalStateException("Unexpected value: " + messageTypeEnum);
}
}
}
}
}
} }

Loading…
Cancel
Save