Browse Source

feat(all): 索菲亚工厂

1 增加索菲亚工厂自定义回传
fix-sign
zhaoqiaobo 5 months ago
parent
commit
ce600ec52b
  1. 81
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/aspect/JobAnnotationAspect.java
  2. 2
      blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/job/AuthPushJob.java

81
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/aspect/JobAnnotationAspect.java

@ -0,0 +1,81 @@
package com.logpm.factorydata.suofeiya.aspect;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import lombok.AllArgsConstructor;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springblade.common.cache.CacheNames;
import org.springblade.common.component.MockLoginService;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.redis.lock.LockType;
import org.springblade.core.redis.lock.RedisLockClient;
import org.springblade.core.tool.utils.ThreadLocalUtil;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpHeaders;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Aspect
@Component
@AllArgsConstructor
public class JobAnnotationAspect {
private final BladeRedis bladeRedis;
private final Environment environment;
private final RedisLockClient redisLockClient;
private final MockLoginService mockLoginService;
@Around("@annotation(com.xxl.job.core.handler.annotation.XxlJob)")
public Object xxlJobAnnotationMethods(ProceedingJoinPoint joinPoint) throws Throwable {
JSONObject jsonObject = mockLogin();
MockHttpServletRequest mockRequest = new MockHttpServletRequest();
mockRequest.addHeader("Blade-Auth", "bearer "+jsonObject.get("access_token"));
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(mockRequest));
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Blade-Auth","bearer "+jsonObject.get("access_token") );
httpHeaders.add( "Authorization", "Basic bG9jYWw6bG9jYWxfc2VjcmV0");
ThreadLocalUtil.put("bladeContext", httpHeaders);
DynamicDataSourceContextHolder.push(jsonObject.getString("tenant_id"));
// 执行原方法
Object result = joinPoint.proceed();
// 在方法执行后,从数据源上下文中移除租户ID
DynamicDataSourceContextHolder.poll();
return result;
}
private JSONObject mockLogin() throws InterruptedException {
String account ="shujutongbu";
String tenantId ="627683";
String key =CacheNames.LOCAL_SERVER_USER+tenantId+":"+account;
String lockKey =key+":lock";
JSONObject data =bladeRedis.get(key);
if(Objects.isNull(data)){
boolean flag = redisLockClient.tryLock(lockKey, LockType.FAIR, 5000, 10000, TimeUnit.MILLISECONDS);
if(flag){
data =bladeRedis.get(key);
if(Objects.isNull(data)){
data = mockLoginService.mockToken(tenantId,account);
bladeRedis.setEx(key,data,2591990L);
redisLockClient.unLock(lockKey, LockType.FAIR);
}
}
}
return data;
}
}

2
blade-service/logpm-factory-data/logpm-factory-data-suofeiya/src/main/java/com/logpm/factorydata/suofeiya/job/AuthPushJob.java

@ -2,7 +2,6 @@ package com.logpm.factorydata.suofeiya.job;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.logpm.factorydata.suofeiya.entity.CustomPushEntity;
import com.logpm.factorydata.suofeiya.service.CustomPushService;
@ -46,7 +45,6 @@ public class AuthPushJob {
.eq(CustomPushEntity::getSendStatus, 0)
.orderByAsc(CustomPushEntity::getNodeCode)
.last("limit 1"));
log.info("回推工厂数据:{}", JSONUtil.toJsonStr(list));
if (CollUtil.isNotEmpty(list)) {
CustomPushEntity customPushEntity = list.get(0);
if (StrUtil.isNotEmpty(customPushEntity.getContent())) {

Loading…
Cancel
Save