flow调msg异步和调log异步
This commit is contained in:
@@ -86,11 +86,11 @@ public class HomeycomClientUserTokenController {
|
|||||||
// 3. 先从缓存中获取token
|
// 3. 先从缓存中获取token
|
||||||
String accessToken = getTokenFromCache(redisKey);
|
String accessToken = getTokenFromCache(redisKey);
|
||||||
// 4. 如果缓存中没有,生成新的token
|
// 4. 如果缓存中没有,生成新的token
|
||||||
if (StringUtils.isEmpty(accessToken)) {
|
// if (StringUtils.isEmpty(accessToken)) {
|
||||||
accessToken = generateAndCacheToken(userId, tenantId, redisKey);
|
accessToken = generateAndCacheToken(userId, tenantId, redisKey);
|
||||||
} else {
|
// } else {
|
||||||
log.info("从缓存中获取用户token,userId: {}, tenantId: {}", userId, tenantId);
|
// log.info("从缓存中获取用户token,userId: {}, tenantId: {}", userId, tenantId);
|
||||||
}
|
// }
|
||||||
ObtainTokenDTO obtainTokenDTO = new ObtainTokenDTO();
|
ObtainTokenDTO obtainTokenDTO = new ObtainTokenDTO();
|
||||||
obtainTokenDTO.setAccess_token(accessToken);
|
obtainTokenDTO.setAccess_token(accessToken);
|
||||||
return R.ok(obtainTokenDTO);
|
return R.ok(obtainTokenDTO);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.honeycombis.honeycom.common.swagger.annotation.EnableOpenApi;
|
|||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author honeycom archetype
|
* @author honeycom archetype
|
||||||
@@ -17,6 +18,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
|||||||
@EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
@EnableHoneycomResourceServer
|
@EnableHoneycomResourceServer
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableAsync
|
||||||
public class HoneycomFlowTaskApplication {
|
public class HoneycomFlowTaskApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import org.apache.commons.compress.utils.Lists;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -401,6 +402,7 @@ public class RemoteServiceImpl implements IRemoteService {
|
|||||||
messageOpenApiDTO.setContent("收到一条" + process.getName() + "审批任务代办,请前往任务中心-代办任务-流程任务审批");
|
messageOpenApiDTO.setContent("收到一条" + process.getName() + "审批任务代办,请前往任务中心-代办任务-流程任务审批");
|
||||||
messageOpenApiDTO.setStaffCode(String.valueOf(processNodeRecordAssignUserParamDto.getUserId()));
|
messageOpenApiDTO.setStaffCode(String.valueOf(processNodeRecordAssignUserParamDto.getUserId()));
|
||||||
messageOpenApiDTO.setTenantCode(String.valueOf(TenantContextHolder.getTenantId()));
|
messageOpenApiDTO.setTenantCode(String.valueOf(TenantContextHolder.getTenantId()));
|
||||||
|
messageOpenApiDTO.setTenantId(TenantContextHolder.getTenantId());
|
||||||
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
jsonObject.put("flowId", processNodeRecordAssignUserParamDto.getFlowId());
|
jsonObject.put("flowId", processNodeRecordAssignUserParamDto.getFlowId());
|
||||||
@@ -410,7 +412,14 @@ public class RemoteServiceImpl implements IRemoteService {
|
|||||||
jsonObject.put("title", process.getName());
|
jsonObject.put("title", process.getName());
|
||||||
messageOpenApiDTO.setBusinessId(JSON.toJSONString(jsonObject));
|
messageOpenApiDTO.setBusinessId(JSON.toJSONString(jsonObject));
|
||||||
log.info("审批节点发送通知消息:{}", JSON.toJSONString(messageOpenApiDTO));
|
log.info("审批节点发送通知消息:{}", JSON.toJSONString(messageOpenApiDTO));
|
||||||
remoteMessageService.pushMessage(messageOpenApiDTO);
|
CompletableFuture.runAsync(() -> {
|
||||||
|
try {
|
||||||
|
log.info("开始异步调用Msg服务...");
|
||||||
|
remoteMessageService.pushMessage(messageOpenApiDTO, Long.valueOf(messageOpenApiDTO.getTenantCode()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("异步调用Msg服务异常: {}", e.getMessage(), e);
|
||||||
|
}
|
||||||
|
});
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,4 +20,6 @@ public class MessageOpenApiDTO {
|
|||||||
|
|
||||||
@Schema(description = "业务id")
|
@Schema(description = "业务id")
|
||||||
private String businessId;
|
private String businessId;
|
||||||
|
|
||||||
|
private Long tenantId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,6 @@ public interface RemoteMessageService {
|
|||||||
|
|
||||||
@Operation(summary = "提供给外围系统发布消息通知", description = "提供给外围系统发布消息通知")
|
@Operation(summary = "提供给外围系统发布消息通知", description = "提供给外围系统发布消息通知")
|
||||||
@PostMapping(value = "/openapi/push")
|
@PostMapping(value = "/openapi/push")
|
||||||
R<Object> pushMessage(@RequestBody MessageOpenApiDTO dto);
|
R<Object> pushMessage(@RequestBody MessageOpenApiDTO dto, @RequestHeader("TENANT-ID") Long tenantId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.honeycombis.honeycom.msg.controller;
|
package com.honeycombis.honeycom.msg.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.honeycombis.honeycom.common.core.exception.ErrorType;
|
import com.honeycombis.honeycom.common.core.exception.ErrorType;
|
||||||
import com.honeycombis.honeycom.common.core.exception.HoneycomException;
|
import com.honeycombis.honeycom.common.core.exception.HoneycomException;
|
||||||
import com.honeycombis.honeycom.common.core.util.R;
|
import com.honeycombis.honeycom.common.core.util.R;
|
||||||
@@ -37,6 +38,7 @@ public class MessageApiController {
|
|||||||
@PostMapping(value = "/push")
|
@PostMapping(value = "/push")
|
||||||
@Inner(value = false)
|
@Inner(value = false)
|
||||||
public R<Object> addByConfigKey(@RequestBody MessageOpenApiDTO dto) {
|
public R<Object> addByConfigKey(@RequestBody MessageOpenApiDTO dto) {
|
||||||
|
log.info("[openapi/push] param:{}", JSON.toJSONString(dto));
|
||||||
if (StringUtils.isBlank(dto.getStaffCode())) {
|
if (StringUtils.isBlank(dto.getStaffCode())) {
|
||||||
log.error("用户ID不能为空!");
|
log.error("用户ID不能为空!");
|
||||||
throw new HoneycomException(ErrorType.PARAM_ERROR.getCode());
|
throw new HoneycomException(ErrorType.PARAM_ERROR.getCode());
|
||||||
|
|||||||
@@ -71,6 +71,12 @@
|
|||||||
<artifactId>honeycom-msg-api</artifactId>
|
<artifactId>honeycom-msg-api</artifactId>
|
||||||
<version>5.4.0</version>
|
<version>5.4.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>5.8.38</version>
|
||||||
|
</dependency>
|
||||||
<!--必备: 操作数据源相关-->
|
<!--必备: 操作数据源相关-->
|
||||||
<!-- <dependency>-->
|
<!-- <dependency>-->
|
||||||
<!-- <groupId>com.honeycombis</groupId>-->
|
<!-- <groupId>com.honeycombis</groupId>-->
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.honeycombis.honeycom.common.feign.annotation.EnableHoneycomFeignClien
|
|||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,6 +17,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||||||
@EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
|
@EnableAsync
|
||||||
public class HoneycomSpdmApplication {
|
public class HoneycomSpdmApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(HoneycomSpdmApplication.class, args);
|
SpringApplication.run(HoneycomSpdmApplication.class, args);
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ package com.honeycombis.honeycom.spdm.controller;
|
|||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.honeycombis.honeycom.common.core.util.R;
|
import com.honeycombis.honeycom.common.core.util.R;
|
||||||
import com.honeycombis.honeycom.spdm.dto.SysLogDto;
|
import com.honeycombis.honeycom.spdm.dto.SysLogDto;
|
||||||
import com.honeycombis.honeycom.spdm.feign.SpdmServiceFeignClient;
|
import com.honeycombis.honeycom.spdm.service.SpdmService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@@ -41,20 +41,17 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class SpdmLogController {
|
public class SpdmLogController {
|
||||||
|
|
||||||
@Resource
|
@Autowired
|
||||||
private SpdmServiceFeignClient spdmServiceFeignClient;
|
private SpdmService spdmService;
|
||||||
|
|
||||||
@Operation(summary = "记录日志")
|
@Operation(summary = "记录日志")
|
||||||
@PostMapping(value = "/saveLog")
|
@PostMapping(value = "/saveLog")
|
||||||
public R<Void> saveLog(@RequestBody SysLogDto sysLogDto) {
|
public R<Void> saveLog(@RequestBody SysLogDto sysLogDto) {
|
||||||
// R<Boolean> r = remoteLogServiceFeign.saveLog(messageDto, SecurityConstants.FROM_IN);
|
log.info("[SpdmLogController] 接收到日志保存请求:{}", JSONUtil.toJsonStr(sysLogDto));
|
||||||
SysLogDto sysLog = new SysLogDto();
|
|
||||||
sysLog.setTitle("登录成功");
|
// 异步执行日志保存
|
||||||
sysLog.setServiceId("simulation-system");
|
spdmService.asyncSaveLog(sysLogDto);
|
||||||
sysLog.setTenantId(sysLogDto.getTenantId());
|
|
||||||
sysLog.setCreateBy(sysLogDto.getCreateBy());
|
|
||||||
log.info("[SpdmLogController] sysLog param:{}", JSONUtil.toJsonStr(sysLog));
|
|
||||||
spdmServiceFeignClient.saveLog(sysLog);
|
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,34 @@
|
|||||||
package com.honeycombis.honeycom.spdm.service;
|
package com.honeycombis.honeycom.spdm.service;
|
||||||
|
|
||||||
public interface SpdmService {
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.honeycombis.honeycom.spdm.dto.SysLogDto;
|
||||||
|
import com.honeycombis.honeycom.spdm.feign.SpdmServiceFeignClient;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class SpdmService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SpdmServiceFeignClient spdmServiceFeignClient;
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public void asyncSaveLog(SysLogDto sysLogDto) {
|
||||||
|
try {
|
||||||
|
SysLogDto sysLog = new SysLogDto();
|
||||||
|
sysLog.setTitle("登录成功");
|
||||||
|
sysLog.setServiceId("simulation-system");
|
||||||
|
sysLog.setTenantId(sysLogDto.getTenantId());
|
||||||
|
sysLog.setCreateBy(sysLogDto.getCreateBy());
|
||||||
|
log.info("[asyncSaveLog] sysLog param:{}", JSONUtil.toJsonStr(sysLog));
|
||||||
|
spdmServiceFeignClient.saveLog(sysLog);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("异步保存日志失败: {}", e.getMessage(), e);
|
||||||
|
// 这里可以添加降级处理,比如保存到本地文件或数据库
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.honeycombis.honeycom.spdm.service.impl;
|
|
||||||
|
|
||||||
import com.honeycombis.honeycom.spdm.service.SpdmService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class SpdmServiceImpl implements SpdmService {
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user