Browse Source

1.补打托盘数据逻辑更新

dist.1.3.0
zhenghaoyu 8 months ago
parent
commit
b5b107f7de
  1. 3
      blade-service-api/logpm-warehouse-api/src/main/java/com/logpm/warehouse/entity/SyncOldTrayTypeLogEntity.java
  2. 28
      blade-service/logpm-patch/src/main/java/com/logpm/patch/config/InterceptorAdapterConfig.java
  3. 112
      blade-service/logpm-patch/src/main/java/com/logpm/patch/interceptor/LocalServerLoginAccountsInterceptor.java
  4. 2
      blade-service/logpm-patch/src/main/java/com/logpm/patch/jobhandle/SyncOldTrayTypeData.java
  5. 2
      blade-service/logpm-patch/src/main/java/com/logpm/patch/mapper/OldTrayTypeMapper.java
  6. 7
      blade-service/logpm-patch/src/main/java/com/logpm/patch/mapper/OldTrayTypeMapper.xml
  7. 2
      blade-service/logpm-patch/src/main/java/com/logpm/patch/service/IOldTrayTypeService.java
  8. 5
      blade-service/logpm-patch/src/main/java/com/logpm/patch/service/impl/OldTrayTypeServiceImpl.java
  9. 3
      blade-service/logpm-warehouse/src/main/java/com/logpm/warehouse/mapper/WarehouseUpdownTypeMapper.xml
  10. 1
      blade-service/logpm-warehouse/src/main/java/com/logpm/warehouse/receiver/OldTrayTypeListener.java

3
blade-service-api/logpm-warehouse-api/src/main/java/com/logpm/warehouse/entity/SyncOldTrayTypeLogEntity.java

@ -51,4 +51,7 @@ public class SyncOldTrayTypeLogEntity extends TenantEntity {
@ApiModelProperty(value = "同步次数")
private Integer syncNum;
@ApiModelProperty(value = "队列状态")
private Integer mqStatus;
}

28
blade-service/logpm-patch/src/main/java/com/logpm/patch/config/InterceptorAdapterConfig.java

@ -0,0 +1,28 @@
package com.logpm.patch.config;
import com.logpm.patch.interceptor.LocalServerLoginAccountsInterceptor;
import lombok.AllArgsConstructor;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.redis.lock.RedisLockClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@AllArgsConstructor
public class InterceptorAdapterConfig implements WebMvcConfigurer {
private final BladeRedis redis;
private final Environment environment;
private final RedisLockClient redisLockClient;
@Override
public void addInterceptors(InterceptorRegistry interceptorRegistry) {
interceptorRegistry.addInterceptor(new LocalServerLoginAccountsInterceptor(redis,environment,redisLockClient)).addPathPatterns("/**").order(1);
}
}

112
blade-service/logpm-patch/src/main/java/com/logpm/patch/interceptor/LocalServerLoginAccountsInterceptor.java

@ -0,0 +1,112 @@
package com.logpm.patch.interceptor;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springblade.common.cache.CacheNames;
import org.springblade.common.constant.LauncherConstant;
import org.springblade.common.exception.CustomerException;
import org.springblade.common.wrapper.CustomHttpServletRequestWrapper;
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.api.R;
import org.springblade.core.tool.utils.ThreadLocalUtil;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpHeaders;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@Log4j2
@AllArgsConstructor
public class LocalServerLoginAccountsInterceptor extends HandlerInterceptorAdapter {
private final BladeRedis bladeRedis;
private final Environment environment;
private final RedisLockClient redisLockClient;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws CustomerException {
try {
CustomHttpServletRequestWrapper wrappedRequest = new CustomHttpServletRequestWrapper(request);
String account ="shujutongbu";
JSONObject data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account);
if(Objects.isNull(data)){
boolean flag = redisLockClient.tryLock("local_server_user", LockType.FAIR, 5000, 10000, TimeUnit.MILLISECONDS);
if(flag){
data =bladeRedis.get(CacheNames.LOCAL_SERVER_USER+account);
if(Objects.isNull(data)){
String url = "http://"+ LauncherConstant.loginAddr(Objects.requireNonNull(environment.getActiveProfiles()[0]))+"/blade-auth/oauth/token";
HttpRequest urlRequest = HttpRequest.post(url);
urlRequest.header("Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0");
urlRequest.header("Tenant-Id", "627683");
Map<String, Object> params = new HashMap<>();
params.put("grant_type", "local_server");
params.put("scope", "all");
params.put("username", account);
params.put("tenantId", "627683");
HttpResponse execute = urlRequest.form(params).execute();
String body = execute.body();
data = JSONObject.parseObject(body);
bladeRedis.setEx(CacheNames.LOCAL_SERVER_USER+account,data,3200L);
redisLockClient.unLock("local_server_user", LockType.FAIR);
}
}
}
// 修改或添加header
// 发送登录请求
log.info("##########preHandle: request={}", request);
wrappedRequest.addHeader("Blade-Auth", "bearer "+data.getString("access_token"));
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Blade-Auth","bearer "+data.get("access_token") );
httpHeaders.add( "Authorization", "Basic c2FiZXI6c2FiZXJfc2VjcmV0");
ThreadLocalUtil.put("bladeContext", httpHeaders);
// 用包装后的request替换原始request
request = wrappedRequest;
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
return true;
} catch (Exception e) {
returnJson(response, JSONObject.toJSONString(R.fail(500, "服务异常,请联系管理员")));
return false;
}
}
private void returnJson(HttpServletResponse response, String json) {
PrintWriter writer = null;
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");
try {
writer = response.getWriter();
writer.print(json);
} catch (IOException e) {
System.out.println(e.getMessage());
} finally {
if (writer != null) {
writer.close();
}
}
}
}

2
blade-service/logpm-patch/src/main/java/com/logpm/patch/jobhandle/SyncOldTrayTypeData.java

@ -32,6 +32,8 @@ public class SyncOldTrayTypeData {
for (SyncOldTrayTypeLogEntity syncOldTrayTypeLogEntity : ls) {
String args = syncOldTrayTypeLogEntity.getArgs();
Long id = syncOldTrayTypeLogEntity.getId();
syncOldTrayTypeLogEntity.setMqStatus(1);
oldTrayTypeService.updateMqStatus(id, 1);
Integer syncNum = syncOldTrayTypeLogEntity.getSyncNum();
log.info("##############syncOldTrayTypeInfo: 当前同步的数据为 {}",args);
JSONObject jsonObject = JSONObject.parseObject(args);

2
blade-service/logpm-patch/src/main/java/com/logpm/patch/mapper/OldTrayTypeMapper.java

@ -13,4 +13,6 @@ public interface OldTrayTypeMapper {
void updateSyncStatus(@Param("id") Long id, @Param("syncStatus") int syncStatus);
void updateSyncNum(@Param("id") Long id, @Param("syncNum") int syncNum);
void updateMqStatus(@Param("id") Long id, @Param("mqStatus") int mqStatus);
}

7
blade-service/logpm-patch/src/main/java/com/logpm/patch/mapper/OldTrayTypeMapper.xml

@ -7,6 +7,7 @@
from sync_old_tray_type_log
where sync_status = #{syncStatus}
and sync_num &lt; #{syncNum}
and mq_status = 0
</select>
<update id="updateSyncStatus">
@ -21,4 +22,10 @@
where id = #{id}
</update>
<update id="updateMqStatus" >
update sync_old_tray_type_log
set mq_status = #{mqStatus}
where id = #{id}
</update>
</mapper>

2
blade-service/logpm-patch/src/main/java/com/logpm/patch/service/IOldTrayTypeService.java

@ -10,4 +10,6 @@ public interface IOldTrayTypeService {
void updateSyncStatus(Long id, int syncStatus);
void updateSyncNum(Long id, int syncNum);
void updateMqStatus(Long id, int mqStatus);
}

5
blade-service/logpm-patch/src/main/java/com/logpm/patch/service/impl/OldTrayTypeServiceImpl.java

@ -31,4 +31,9 @@ public class OldTrayTypeServiceImpl implements IOldTrayTypeService {
public void updateSyncNum(Long id, int syncNum) {
oldTrayTypeMapper.updateSyncNum(id,syncNum);
}
@Override
public void updateMqStatus(Long id, int mqStatus) {
oldTrayTypeMapper.updateMqStatus(id,mqStatus);
}
}

3
blade-service/logpm-warehouse/src/main/java/com/logpm/warehouse/mapper/WarehouseUpdownTypeMapper.xml

@ -86,7 +86,8 @@
<update id="updateOldTrayTypeInfoNum" >
update sync_old_tray_type_log
set sync_num = sync_num + 1
set sync_num = sync_num + 1,
mq_status = 0
where id = #{oldTrayTypeId}
</update>

1
blade-service/logpm-warehouse/src/main/java/com/logpm/warehouse/receiver/OldTrayTypeListener.java

@ -71,6 +71,7 @@ public class OldTrayTypeListener {
syncOldTrayTypeLogEntity.setArgs(com.alibaba.fastjson.JSONObject.toJSONString(trayInfoDTO));
syncOldTrayTypeLogEntity.setSyncStatus(0);
syncOldTrayTypeLogEntity.setSyncNum(0);
syncOldTrayTypeLogEntity.setMqStatus(0);
syncOldTrayTypeLogService.save(syncOldTrayTypeLogEntity);
}
}

Loading…
Cancel
Save