diff --git a/xinnengyuan/ruoyi-admin/src/main/resources/application.yml b/xinnengyuan/ruoyi-admin/src/main/resources/application.yml index cba285cf..81fff144 100644 --- a/xinnengyuan/ruoyi-admin/src/main/resources/application.yml +++ b/xinnengyuan/ruoyi-admin/src/main/resources/application.yml @@ -324,6 +324,11 @@ management: sse: enabled: true path: /resource/sse + wait: /task/taskWaiting + copy: /task/taskCopyList + project: /personnel-management/project + violationRecord: /safety-management/ai/violationRecord + --- # websocket websocket: diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/config/SseProperties.java b/xinnengyuan/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/config/SseProperties.java index ce4e1732..ad930e83 100644 --- a/xinnengyuan/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/config/SseProperties.java +++ b/xinnengyuan/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/config/SseProperties.java @@ -18,4 +18,15 @@ public class SseProperties { * 路径 */ private String path; + + private String wait; + + private String copy; + + private String project; + + private String violationRecord; + + + } diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/core/SseEmitterManager.java b/xinnengyuan/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/core/SseEmitterManager.java index 48ccf32b..17c4090f 100644 --- a/xinnengyuan/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/core/SseEmitterManager.java +++ b/xinnengyuan/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/core/SseEmitterManager.java @@ -135,7 +135,7 @@ public class SseEmitterManager { broadcastMessage.setMessage(sseMessageDto.getMessage()); broadcastMessage.setUserIds(sseMessageDto.getUserIds()); broadcastMessage.setRoute(sseMessageDto.getRoute()); - broadcastMessage.setDetailId(sseMessageDto.getDetailId()); + broadcastMessage.setProjectId(sseMessageDto.getProjectId()); RedisUtils.publish(SSE_TOPIC, broadcastMessage, consumer -> { log.info("SSE发送主题订阅消息topic:{} session keys:{} message:{}", SSE_TOPIC, sseMessageDto.getUserIds(), sseMessageDto.getMessage()); diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/dto/SeeMessageContentDto.java b/xinnengyuan/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/dto/SeeMessageContentDto.java new file mode 100644 index 00000000..dd5e90fd --- /dev/null +++ b/xinnengyuan/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/dto/SeeMessageContentDto.java @@ -0,0 +1,25 @@ +package org.dromara.common.sse.dto; + +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +@Data +public class SeeMessageContentDto implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + + /** + * 需要发送的消息 + */ + private String type; + + /** + * 路由 + */ + private String content; + +} diff --git a/xinnengyuan/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/dto/SseMessageDto.java b/xinnengyuan/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/dto/SseMessageDto.java index e5406d13..fa457b05 100644 --- a/xinnengyuan/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/dto/SseMessageDto.java +++ b/xinnengyuan/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/dto/SseMessageDto.java @@ -14,6 +14,10 @@ import java.util.List; @Data public class SseMessageDto implements Serializable { + + + + @Serial private static final long serialVersionUID = 1L; @@ -35,6 +39,6 @@ public class SseMessageDto implements Serializable { /** * 详情 */ - private String detailId; + private Long projectId; } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/land/controller/listener/GenericExcelListener.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/utils/listener/excel/GenericExcelListener.java similarity index 98% rename from xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/land/controller/listener/GenericExcelListener.java rename to xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/utils/listener/excel/GenericExcelListener.java index c774f9ef..a5d4a64f 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/land/controller/listener/GenericExcelListener.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/utils/listener/excel/GenericExcelListener.java @@ -1,11 +1,10 @@ -package org.dromara.land.controller.listener; +package org.dromara.common.utils.listener.excel; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.exception.ExcelDataConvertException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; import java.util.ArrayList; diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/utils/listener/redis/SseMessageDbListener.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/utils/listener/redis/SseMessageDbListener.java new file mode 100644 index 00000000..096c72fe --- /dev/null +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/utils/listener/redis/SseMessageDbListener.java @@ -0,0 +1,54 @@ +package org.dromara.common.utils.listener.redis; + +import cn.hutool.core.collection.CollUtil; +import lombok.extern.slf4j.Slf4j; +import org.dromara.common.sse.core.SseEmitterManager; +import org.dromara.message.domain.MsgNotice; +import org.dromara.message.service.IMsgNoticeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.core.Ordered; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; + +/** + * SSE 消息数据库存储监听器 + */ +@Slf4j +@Component +public class SseMessageDbListener implements ApplicationRunner, Ordered { + + @Autowired + private SseEmitterManager sseEmitterManager; + + @Autowired + private IMsgNoticeService noticeService; // 注入你的数据库服务 + + @Override + public void run(ApplicationArguments args) throws Exception { + sseEmitterManager.subscribeMessage((message) -> { + log.info("SSE主题订阅收到消息session keys={} message={}", message.getUserIds(), message.getMessage()); + if (CollUtil.isNotEmpty(message.getUserIds())) { + ArrayList noticeList = new ArrayList<>(); + for (Long key : message.getUserIds()) { + MsgNotice notice = new MsgNotice(); + notice.setContent(message.getMessage()); + notice.setProjectId(message.getProjectId()); + notice.setRecipientId(key); + noticeList.add(notice); + } + noticeService.saveBatch(noticeList); + } + log.info("SSE消息已存储到数据库: {}", message.getMessage()); + }); + log.info("初始化SSE消息数据库存储监听器成功"); + } + + @Override + public int getOrder() { + return 0; // 可以调整顺序 + } +} + diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesPrelimSchemeServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesPrelimSchemeServiceImpl.java index b55121f2..10302d3d 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesPrelimSchemeServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesPrelimSchemeServiceImpl.java @@ -98,7 +98,7 @@ public class DesPrelimSchemeServiceImpl extends ServiceImpl buildQueryWrapper(DesPrelimSchemeBo bo) { Map params = bo.getParams(); LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); - lqw.orderByAsc(DesPrelimScheme::getOrderNum); + lqw.orderByDesc(DesPrelimScheme::getCreateTime); lqw.orderByDesc(DesPrelimScheme::getId); lqw.eq(bo.getProjectId() != null, DesPrelimScheme::getProjectId, bo.getProjectId()); lqw.eq(bo.getOssId()!= null, DesPrelimScheme::getOssId, bo.getOssId()); @@ -207,38 +207,38 @@ public class DesPrelimSchemeServiceImpl extends ServiceImpl(). - eq(MsgConfig::getProjectId, prelimScheme.getProjectId()). - eq(MsgConfig::getMsgKey, "prelimScheme") - ); - if (msgConfig != null) { - String userId = msgConfig.getUserId(); - List userIdList = Arrays.stream(userId.split(",")) - .map(String::trim) - .map(s -> { - try { - return Long.valueOf(s); - } catch (NumberFormatException e) { - // 处理转换失败的情况 - return null; // 或者根据需求处理 - } - }) - .filter(Objects::nonNull) // 过滤掉转换失败的null值 - .collect(Collectors.toList()); - //发送消息 - SendMsgDto sendMsgDto = new SendMsgDto(); - sendMsgDto.setProjectId(prelimScheme.getProjectId()); - sendMsgDto.setRecipientIds(userIdList); - sendMsgDto.setSenderId(0L); - sendMsgDto.setConfigId(msgConfig.getId()); - sendMsgDto.setDetailId(prelimScheme.getId().toString()); - sendMsgDto.setContent(msgConfig.getMsgContent()); - msgNoticeService.sendMsg(sendMsgDto); - } - } +// if (BusinessStatusEnum.FINISH.getStatus().equals(processEvent.getStatus())) { +// //发送消息 +// MsgConfig msgConfig = msgConfigService.getOne( +// new LambdaQueryWrapper(). +// eq(MsgConfig::getProjectId, prelimScheme.getProjectId()). +// eq(MsgConfig::getMsgKey, "prelimScheme") +// ); +// if (msgConfig != null) { +// String userId = msgConfig.getUserId(); +// List userIdList = Arrays.stream(userId.split(",")) +// .map(String::trim) +// .map(s -> { +// try { +// return Long.valueOf(s); +// } catch (NumberFormatException e) { +// // 处理转换失败的情况 +// return null; // 或者根据需求处理 +// } +// }) +// .filter(Objects::nonNull) // 过滤掉转换失败的null值 +// .collect(Collectors.toList()); +// //发送消息 +// SendMsgDto sendMsgDto = new SendMsgDto(); +// sendMsgDto.setProjectId(prelimScheme.getProjectId()); +// sendMsgDto.setRecipientIds(userIdList); +// sendMsgDto.setSenderId(0L); +// sendMsgDto.setConfigId(msgConfig.getId()); +// sendMsgDto.setDetailId(prelimScheme.getId().toString()); +// sendMsgDto.setContent(msgConfig.getMsgContent()); +// msgNoticeService.sendMsg(sendMsgDto); +// } +// } } /** diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesSchemeServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesSchemeServiceImpl.java index b695ce1c..0b5c5cb6 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesSchemeServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/design/service/impl/DesSchemeServiceImpl.java @@ -93,7 +93,7 @@ public class DesSchemeServiceImpl extends ServiceImpl buildQueryWrapper(DesSchemeBo bo) { Map params = bo.getParams(); LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); - lqw.orderByAsc(DesScheme::getOrderNum); + lqw.orderByDesc(DesScheme::getCreateTime); lqw.orderByDesc(DesScheme::getId); lqw.eq(bo.getProjectId() != null, DesScheme::getProjectId, bo.getProjectId()); lqw.eq(bo.getOssId()!= null, DesScheme::getOssId, bo.getOssId()); diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/facility/service/impl/FacPhotovoltaicPanelPartsServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/facility/service/impl/FacPhotovoltaicPanelPartsServiceImpl.java index 2969d5bc..0332b542 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/facility/service/impl/FacPhotovoltaicPanelPartsServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/facility/service/impl/FacPhotovoltaicPanelPartsServiceImpl.java @@ -12,6 +12,8 @@ import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.satoken.utils.LoginHelper; +import org.dromara.common.sse.config.SseProperties; +import org.dromara.common.sse.dto.SeeMessageContentDto; import org.dromara.common.sse.dto.SseMessageDto; import org.dromara.common.sse.utils.SseMessageUtils; import org.dromara.common.utils.JSTUtil; @@ -46,6 +48,7 @@ import java.util.concurrent.*; import java.util.function.Function; import java.util.stream.Collectors; + /** * @author lilemy * @date 2025/4/21 15:53 @@ -85,6 +88,9 @@ public class FacPhotovoltaicPanelPartsServiceImpl implements IFacPhotovoltaicPan @Resource private FacPhotovoltaicPanelPartsServiceImpl self; // 注入自己 + @Resource + private SseProperties sseProperties; + /** * 查询光伏板(桩点、立柱、支架)列表 * @@ -153,7 +159,10 @@ public class FacPhotovoltaicPanelPartsServiceImpl implements IFacPhotovoltaicPan log.info("已接收第 {} 批数据,共 {} 批", batchNum, totalBatch); Long userId = LoginHelper.getUserId(); SseMessageDto messageDto = new SseMessageDto(); + SeeMessageContentDto contentDto = new SeeMessageContentDto(); + contentDto.setType(sseProperties.getProject()); messageDto.setUserIds(List.of(userId)); + messageDto.setProjectId(projectId); // 如果是最后一批,开始合并 if (batchNum == totalBatch) { List allData = new ArrayList<>(); @@ -169,14 +178,16 @@ public class FacPhotovoltaicPanelPartsServiceImpl implements IFacPhotovoltaicPan // 设置 redis key,防止多次操作 String operationPartsRedisKey = FacRedisKeyConstant.getPartsInOperationByProjectRedisKey(projectId); redisTemplate.opsForValue().set(operationPartsRedisKey, true); - messageDto.setMessage("桩点、立柱、支架数据上传完毕,正在处理中"); + contentDto.setContent("桩点、立柱、支架数据上传完毕,正在处理中"); + messageDto.setMessage(JSONUtil.toJsonStr(contentDto)); SseMessageUtils.publishMessage(messageDto); scheduledExecutorService.execute(() -> { try { // 合并后的数据处理,如入库 this.saveBatch(projectId, allData, userId); } catch (Exception e) { - messageDto.setMessage("桩点、立柱、支架数据处理失败,请联系管理员处理"); + contentDto.setContent("桩点、立柱、支架数据处理失败,请联系管理员处理"); + messageDto.setMessage(JSONUtil.toJsonStr(contentDto)); SseMessageUtils.publishMessage(messageDto); log.error("桩点、立柱、支架数据处理失败", e); throw new ServiceException("桩点、立柱、支架数据处理失败", HttpStatus.ERROR); @@ -188,7 +199,8 @@ public class FacPhotovoltaicPanelPartsServiceImpl implements IFacPhotovoltaicPan } redisTemplate.delete(operationPartsRedisKey); } - messageDto.setMessage("桩点、立柱、支架数据处理完毕"); + contentDto.setContent("桩点、立柱、支架数据处理完毕"); + messageDto.setMessage(JSONUtil.toJsonStr(contentDto)); SseMessageUtils.publishMessage(messageDto); }); return true; diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/facility/service/impl/FacPhotovoltaicPanelServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/facility/service/impl/FacPhotovoltaicPanelServiceImpl.java index 36d7f7b6..868df63e 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/facility/service/impl/FacPhotovoltaicPanelServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/facility/service/impl/FacPhotovoltaicPanelServiceImpl.java @@ -14,6 +14,8 @@ import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.satoken.utils.LoginHelper; +import org.dromara.common.sse.config.SseProperties; +import org.dromara.common.sse.dto.SeeMessageContentDto; import org.dromara.common.sse.dto.SseMessageDto; import org.dromara.common.sse.utils.SseMessageUtils; import org.dromara.common.utils.JSTUtil; @@ -83,6 +85,9 @@ public class FacPhotovoltaicPanelServiceImpl extends ServiceImpl locationFeatures = new ArrayList<>(); @@ -238,7 +246,8 @@ public class FacPhotovoltaicPanelServiceImpl extends ServiceImpl { try { @@ -388,10 +397,12 @@ public class FacPhotovoltaicPanelServiceImpl extends ServiceImpl { try { @@ -311,11 +320,13 @@ public class BusProjectFileServiceImpl extends ServiceImpl(userIds)); for (HseViolationRecord violationRecord : violationRecordList) { - messageDto.setMessage("您有一份重要的违章需要处理!工单号为:" + violationRecord.getId()); + SeeMessageContentDto seeMessageContentDto = new SeeMessageContentDto(); + seeMessageContentDto.setType(sseProperties.getViolationRecord()); + seeMessageContentDto.setContent("您有一份重要的违章需要处理!工单号为:" + violationRecord.getId()); + messageDto.setMessage(JSONUtil.toJsonStr(seeMessageContentDto)); + messageDto.setProjectId(violationRecord.getProjectId()); SseMessageUtils.publishMessage(messageDto); } } diff --git a/xinnengyuan/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/listener/WorkflowGlobalListener.java b/xinnengyuan/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/listener/WorkflowGlobalListener.java index c1ef2622..7584bfcf 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/listener/WorkflowGlobalListener.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/listener/WorkflowGlobalListener.java @@ -143,13 +143,15 @@ public class WorkflowGlobalListener implements GlobalListener { List flowCopyList = (List) variable.get(FlowConstant.FLOW_COPY_LIST); // 添加抄送人 flwTaskService.setCopy(task, flowCopyList); + //发送抄送消息 + flwCommonService.sendCopyMessage(definition.getFlowName(), definition.getFlowCode(), flowCopyList); } if (variable.containsKey(FlowConstant.MESSAGE_TYPE)) { List messageType = (List) variable.get(FlowConstant.MESSAGE_TYPE); String notice = (String) variable.get(FlowConstant.MESSAGE_NOTICE); // 消息通知 if (CollUtil.isNotEmpty(messageType)) { - flwCommonService.sendMessage(definition.getFlowName(), instance.getId(), messageType, notice); + flwCommonService.sendMessage(definition.getFlowName(),definition.getFlowCode(), instance.getId(), messageType, notice); } } FlowInstance ins = new FlowInstance(); diff --git a/xinnengyuan/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/IFlwCommonService.java b/xinnengyuan/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/IFlwCommonService.java index 662d599e..ad5ef2a9 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/IFlwCommonService.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/IFlwCommonService.java @@ -1,5 +1,7 @@ package org.dromara.workflow.service; +import org.dromara.workflow.domain.bo.FlowCopyBo; + import java.util.List; /** @@ -25,7 +27,12 @@ public interface IFlwCommonService { * @param messageType 消息类型 * @param message 消息内容,为空则发送默认配置的消息内容 */ - void sendMessage(String flowName, Long instId, List messageType, String message); + void sendMessage(String flowName,String flowCode, Long instId, List messageType, String message); + + /** + * 发送抄送消息 + */ + void sendCopyMessage(String flowName, String flowCode, List flowCopyList); /** * 申请人节点编码 diff --git a/xinnengyuan/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwCommonServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwCommonServiceImpl.java index e6dc8155..f67f55f5 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwCommonServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/FlwCommonServiceImpl.java @@ -2,13 +2,17 @@ package org.dromara.workflow.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.json.JSONUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.dromara.common.core.domain.R; import org.dromara.common.core.domain.dto.UserDTO; import org.dromara.common.core.utils.SpringUtils; import org.dromara.common.core.utils.StreamUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mail.utils.MailUtils; +import org.dromara.common.sse.config.SseProperties; +import org.dromara.common.sse.dto.SeeMessageContentDto; import org.dromara.common.sse.dto.SseMessageDto; import org.dromara.common.sse.utils.SseMessageUtils; import org.dromara.warm.flow.core.entity.Node; @@ -18,6 +22,7 @@ import org.dromara.warm.flow.core.service.NodeService; import org.dromara.warm.flow.orm.entity.FlowTask; import org.dromara.workflow.common.ConditionalOnEnable; import org.dromara.workflow.common.enums.MessageTypeEnum; +import org.dromara.workflow.domain.bo.FlowCopyBo; import org.dromara.workflow.service.IFlwCommonService; import org.dromara.workflow.service.IFlwTaskAssigneeService; import org.dromara.workflow.service.IFlwTaskService; @@ -40,6 +45,8 @@ import java.util.stream.Collectors; public class FlwCommonServiceImpl implements IFlwCommonService { private final NodeService nodeService; + private final SseProperties properties; + /** * 构建工作流用户 * @@ -68,13 +75,14 @@ public class FlwCommonServiceImpl implements IFlwCommonService { * @param message 消息内容,为空则发送默认配置的消息内容 */ @Override - public void sendMessage(String flowName, Long instId, List messageType, String message) { + public void sendMessage(String flowName,String flowCode, Long instId, List messageType, String message) { IFlwTaskService flwTaskService = SpringUtils.getBean(IFlwTaskService.class); List userList = new ArrayList<>(); List list = flwTaskService.selectByInstId(instId); if (StringUtils.isBlank(message)) { message = "有新的【" + flowName + "】单据已经提交至您,请您及时处理。"; } + for (Task task : list) { List users = flwTaskService.currentTaskAllUser(task.getId()); if (CollUtil.isNotEmpty(users)) { @@ -88,8 +96,20 @@ public class FlwCommonServiceImpl implements IFlwCommonService { switch (messageTypeEnum) { case SYSTEM_MESSAGE: SseMessageDto dto = new SseMessageDto(); + SeeMessageContentDto contentDto = new SeeMessageContentDto(); dto.setUserIds(StreamUtils.toList(userList, UserDTO::getUserId).stream().distinct().collect(Collectors.toList())); - dto.setMessage(message); + contentDto.setType(properties.getWait()); + contentDto.setContent(message); + dto.setMessage(JSONUtil.toJsonStr(contentDto)); + String[] parts = flowCode.split("_"); + String projectCode = parts.length > 0 ? parts[0] : "0"; + try { + Long projectId = Long.valueOf(projectCode); + dto.setProjectId(projectId); + } catch (NumberFormatException e) { + log.warn("项目编码转换为Long类型失败: {}, 使用默认值0", projectCode); + dto.setProjectId(0L); + } SseMessageUtils.publishMessage(dto); break; case EMAIL_MESSAGE: @@ -107,6 +127,29 @@ public class FlwCommonServiceImpl implements IFlwCommonService { } + @Override + public void sendCopyMessage(String flowName, String flowCode, List flowCopyList) { + if(CollUtil.isEmpty(flowCopyList)){ + return; + } + SseMessageDto dto = new SseMessageDto(); + SeeMessageContentDto contentDto = new SeeMessageContentDto(); + dto.setUserIds(StreamUtils.toList(flowCopyList, FlowCopyBo::getUserId).stream().distinct().collect(Collectors.toList())); + contentDto.setType(properties.getCopy()); + contentDto.setContent("有新的【" + flowName + "】单据已经提交至您,请您及时查看。"); + dto.setMessage(JSONUtil.toJsonStr(contentDto)); + String[] parts = flowCode.split("_"); + String projectCode = parts.length > 0 ? parts[0] : "0"; + try { + Long projectId = Long.valueOf(projectCode); + dto.setProjectId(projectId); + } catch (NumberFormatException e) { + log.warn("项目编码转换为Long类型失败: {}, 使用默认值0", projectCode); + dto.setProjectId(0L); + } + SseMessageUtils.publishMessage(dto); + } + /** * 申请人节点编码 *