13 changed files with 439 additions and 269 deletions
@ -1,33 +1,33 @@
|
||||
package com.logpm.factory.props; |
||||
|
||||
import lombok.Data; |
||||
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
/** |
||||
* FactoryProperties |
||||
* |
||||
* @author pref |
||||
*/ |
||||
@Data |
||||
@ConfigurationProperties(prefix = "old") |
||||
@Component |
||||
public class OldSystemProperties { |
||||
/** |
||||
* 请求地址 |
||||
*/ |
||||
private String url; |
||||
|
||||
/** |
||||
* 默认账号 |
||||
*/ |
||||
private String pwd; |
||||
|
||||
/** |
||||
* 默认用户 |
||||
*/ |
||||
private String userId; |
||||
|
||||
|
||||
|
||||
} |
||||
//package com.logpm.factory.props;
|
||||
//
|
||||
//import lombok.Data;
|
||||
//import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
///**
|
||||
// * FactoryProperties
|
||||
// *
|
||||
// * @author pref
|
||||
// */
|
||||
//@Data
|
||||
//@ConfigurationProperties(prefix = "old")
|
||||
//@Component
|
||||
//public class OldSystemProperties {
|
||||
// /**
|
||||
// * 请求地址
|
||||
// */
|
||||
// private String url;
|
||||
//
|
||||
// /**
|
||||
// * 默认账号
|
||||
// */
|
||||
// private String pwd;
|
||||
//
|
||||
// /**
|
||||
// * 默认用户
|
||||
// */
|
||||
// private String userId;
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
@ -1,100 +1,100 @@
|
||||
package com.logpm.oldproject.config; |
||||
|
||||
import com.alibaba.nacos.shaded.com.google.common.collect.Maps; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.common.constant.RabbitConstant; |
||||
import org.springframework.amqp.core.*; |
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory; |
||||
import org.springframework.amqp.rabbit.connection.CorrelationData; |
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate; |
||||
import org.springframework.amqp.rabbit.retry.MessageRecoverer; |
||||
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
import java.util.Map; |
||||
|
||||
|
||||
@Slf4j |
||||
@Configuration |
||||
public class RabbitMqConfiguration { |
||||
|
||||
@Bean |
||||
public RabbitTemplate createRabbitTemplate(ConnectionFactory connectionFactory){ |
||||
RabbitTemplate template = new RabbitTemplate(); |
||||
template.setConnectionFactory(connectionFactory); |
||||
template.setMandatory(true); |
||||
template.setConfirmCallback(new RabbitTemplate.ConfirmCallback() { |
||||
@Override |
||||
public void confirm(CorrelationData correlationData, boolean b, String s) { |
||||
System.out.println("确认回调-相关数据:"+correlationData); |
||||
System.out.println("确认回调-确认情况:"+b); |
||||
System.out.println("确认回调-原因:"+s); |
||||
|
||||
} |
||||
}); |
||||
|
||||
template.setReturnsCallback(new RabbitTemplate.ReturnsCallback() { |
||||
@Override |
||||
public void returnedMessage(ReturnedMessage returnedMessage) { |
||||
System.out.println("返回回调-消息:"+returnedMessage.getMessage()); |
||||
System.out.println("返回回调-回应码:"+returnedMessage.getReplyCode()); |
||||
System.out.println("返回回调-回应信息:"+returnedMessage.getReplyText()); |
||||
System.out.println("返回回调-交换机:"+returnedMessage.getExchange()); |
||||
System.out.println("返回回调-路由键:"+returnedMessage.getRoutingKey()); |
||||
} |
||||
}); |
||||
return template; |
||||
} |
||||
|
||||
@Bean |
||||
public DirectExchange errorMessageExchange(){ |
||||
return new DirectExchange(RabbitConstant.ERROR_EXCHANGE); |
||||
} |
||||
@Bean |
||||
public Queue errorQueue(){ |
||||
return new Queue(RabbitConstant.ERROR_QUEUE, true); |
||||
} |
||||
@Bean |
||||
public Binding errorBinding(Queue errorQueue, DirectExchange errorMessageExchange){ |
||||
return BindingBuilder.bind(errorQueue).to(errorMessageExchange).with(RabbitConstant.ERROR_ROUTING); |
||||
} |
||||
|
||||
|
||||
|
||||
@Bean |
||||
public MessageRecoverer republishMessageRecoverer(RabbitTemplate rabbitTemplate){ |
||||
return new RepublishMessageRecoverer(rabbitTemplate, RabbitConstant.ERROR_EXCHANGE, RabbitConstant.ERROR_ROUTING); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Bean |
||||
public Queue orderStatusQueue() { |
||||
return new Queue(RabbitConstant.ORDER_STATUS_QUEUE, true); |
||||
} |
||||
|
||||
|
||||
|
||||
@Bean |
||||
public CustomExchange orderStatusExchange() { |
||||
Map<String, Object> args = Maps.newHashMap(); |
||||
args.put("x-delayed-type", "direct"); |
||||
return new CustomExchange(RabbitConstant.ORDER_STATUS_EXCHANGE, "x-delayed-message", true, false, args); |
||||
} |
||||
|
||||
|
||||
@Bean |
||||
public Binding orderStatusBinding(Queue orderStatusQueue, CustomExchange orderStatusExchange) { |
||||
return BindingBuilder.bind(orderStatusQueue).to(orderStatusExchange).with(RabbitConstant.ORDER_STATUS_ROUTING).noargs(); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
//package com.logpm.oldproject.config;
|
||||
//
|
||||
//import com.alibaba.nacos.shaded.com.google.common.collect.Maps;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springblade.common.constant.RabbitConstant;
|
||||
//import org.springframework.amqp.core.*;
|
||||
//import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
//import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||
//import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
//import org.springframework.amqp.rabbit.retry.MessageRecoverer;
|
||||
//import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//
|
||||
//import java.util.Map;
|
||||
//
|
||||
//
|
||||
//@Slf4j
|
||||
//@Configuration
|
||||
//public class RabbitMqConfiguration {
|
||||
//
|
||||
// @Bean
|
||||
// public RabbitTemplate createRabbitTemplate(ConnectionFactory connectionFactory){
|
||||
// RabbitTemplate template = new RabbitTemplate();
|
||||
// template.setConnectionFactory(connectionFactory);
|
||||
// template.setMandatory(true);
|
||||
// template.setConfirmCallback(new RabbitTemplate.ConfirmCallback() {
|
||||
// @Override
|
||||
// public void confirm(CorrelationData correlationData, boolean b, String s) {
|
||||
// System.out.println("确认回调-相关数据:"+correlationData);
|
||||
// System.out.println("确认回调-确认情况:"+b);
|
||||
// System.out.println("确认回调-原因:"+s);
|
||||
//
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// template.setReturnsCallback(new RabbitTemplate.ReturnsCallback() {
|
||||
// @Override
|
||||
// public void returnedMessage(ReturnedMessage returnedMessage) {
|
||||
// System.out.println("返回回调-消息:"+returnedMessage.getMessage());
|
||||
// System.out.println("返回回调-回应码:"+returnedMessage.getReplyCode());
|
||||
// System.out.println("返回回调-回应信息:"+returnedMessage.getReplyText());
|
||||
// System.out.println("返回回调-交换机:"+returnedMessage.getExchange());
|
||||
// System.out.println("返回回调-路由键:"+returnedMessage.getRoutingKey());
|
||||
// }
|
||||
// });
|
||||
// return template;
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public DirectExchange errorMessageExchange(){
|
||||
// return new DirectExchange(RabbitConstant.ERROR_EXCHANGE);
|
||||
// }
|
||||
// @Bean
|
||||
// public Queue errorQueue(){
|
||||
// return new Queue(RabbitConstant.ERROR_QUEUE, true);
|
||||
// }
|
||||
// @Bean
|
||||
// public Binding errorBinding(Queue errorQueue, DirectExchange errorMessageExchange){
|
||||
// return BindingBuilder.bind(errorQueue).to(errorMessageExchange).with(RabbitConstant.ERROR_ROUTING);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// @Bean
|
||||
// public MessageRecoverer republishMessageRecoverer(RabbitTemplate rabbitTemplate){
|
||||
// return new RepublishMessageRecoverer(rabbitTemplate, RabbitConstant.ERROR_EXCHANGE, RabbitConstant.ERROR_ROUTING);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// @Bean
|
||||
// public Queue orderStatusQueue() {
|
||||
// return new Queue(RabbitConstant.ORDER_STATUS_QUEUE, true);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// @Bean
|
||||
// public CustomExchange orderStatusExchange() {
|
||||
// Map<String, Object> args = Maps.newHashMap();
|
||||
// args.put("x-delayed-type", "direct");
|
||||
// return new CustomExchange(RabbitConstant.ORDER_STATUS_EXCHANGE, "x-delayed-message", true, false, args);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Bean
|
||||
// public Binding orderStatusBinding(Queue orderStatusQueue, CustomExchange orderStatusExchange) {
|
||||
// return BindingBuilder.bind(orderStatusQueue).to(orderStatusExchange).with(RabbitConstant.ORDER_STATUS_ROUTING).noargs();
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
@ -1,21 +1,111 @@
|
||||
package com.logpm.oldproject.feign; |
||||
|
||||
import cn.hutool.http.HttpRequest; |
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.logpm.oldproject.dto.SignPushDataDTO; |
||||
import com.logpm.oldproject.props.OldSystemProperties; |
||||
import jodd.util.StringUtil; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.redis.cache.BladeRedis; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
import springfox.documentation.annotations.ApiIgnore; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@ApiIgnore() |
||||
@RestController |
||||
@AllArgsConstructor |
||||
public class SignPushClient implements ISignPushClient{ |
||||
@Slf4j |
||||
public class SignPushClient implements IOldSystemDataPushClient { |
||||
@Autowired |
||||
private BladeRedis bladeRedis; |
||||
@Autowired |
||||
private OldSystemProperties oldSystemProperties; |
||||
@Override |
||||
public Boolean pushOldSystemSignInfo(SignPushDataDTO signPushDataDTO) { |
||||
|
||||
//todo 这里存在调用老系统的接口 将数据会写给老系统
|
||||
|
||||
String authCode = oldLogin(signPushDataDTO.getWarehouse_id()); |
||||
|
||||
log.info("##################pushOldSystemSignInfo: 请求老系统接口 start map {}", signPushDataDTO); |
||||
|
||||
String url = oldSystemProperties.getUrl() + "openApi/newSystem.OptimsSign/index"; |
||||
|
||||
String data = JSON.toJSONString(signPushDataDTO); |
||||
String body = HttpRequest.post(url).body(data).header("token", authCode).execute().body(); |
||||
log.info("##################pushOldSystemSignInfo: 请求老系统接口,url:{},body:{}", url, body); |
||||
if (StringUtil.isNotBlank(body)) { |
||||
|
||||
JSONObject res = JSON.parseObject(body); |
||||
if ("200".equals(res.getString("code"))) { |
||||
return true; |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public boolean sendPackageData(Map<String, Object> dataMap) { |
||||
// 构建请求头
|
||||
Object o = dataMap.get("warehouse_id"); |
||||
Integer warehouse_id = (Integer) o; |
||||
String authCode = oldLogin(warehouse_id); |
||||
|
||||
log.info("##################sendPackageData: 请求老系统接口 start map {}", dataMap); |
||||
|
||||
String url = oldSystemProperties.getUrl() + "openApi/newSystem.OptimsWarehouseScan/index"; |
||||
String body = HttpRequest.post(url).form(dataMap).header("token", authCode).execute().body(); |
||||
log.info("##################sendPackageData: 请求老系统接口,url:{},body:{}", url, body); |
||||
if (StringUtil.isNotBlank(body)) { |
||||
|
||||
return null; |
||||
JSONObject res = JSON.parseObject(body); |
||||
if ("200".equals(res.getString("code"))) { |
||||
return true; |
||||
} |
||||
|
||||
} |
||||
|
||||
return false; |
||||
|
||||
} |
||||
/** |
||||
* 登录老系统 |
||||
* |
||||
* @param warhouseId 仓库ID |
||||
* @return 成功token |
||||
*/ |
||||
private String oldLogin(Integer warhouseId) { |
||||
String o = bladeRedis.get(oldSystemProperties.getUserId() + "_" + warhouseId); |
||||
if (StringUtil.isBlank(o)) { |
||||
String url = oldSystemProperties.getUrl() + "api/fakeLogin"; |
||||
|
||||
Map<String, Object> map = new HashMap<>(); |
||||
map.put("pwd", oldSystemProperties.getPwd()); |
||||
map.put("user_id", oldSystemProperties.getUserId()); |
||||
map.put("warehouse_id", warhouseId); |
||||
String body = HttpRequest.post(url).form(map).execute().body(); |
||||
log.info("##################opReceivingDataHandler: 请求老系统接口,url:{},body:{}", url, body); |
||||
|
||||
|
||||
JSONObject authCode = JSON.parseObject(body); |
||||
|
||||
if ("200".equals(authCode.getString("code"))) { |
||||
|
||||
o = authCode.getJSONObject("data").getJSONObject("token").getString("token"); |
||||
bladeRedis.setEx(oldSystemProperties.getUserId() + "_" + warhouseId, o, 30 * 60L); |
||||
|
||||
} |
||||
} |
||||
|
||||
return o; |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,33 @@
|
||||
package com.logpm.oldproject.props; |
||||
|
||||
import lombok.Data; |
||||
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
/** |
||||
* FactoryProperties |
||||
* |
||||
* @author pref |
||||
*/ |
||||
@Data |
||||
@ConfigurationProperties(prefix = "old") |
||||
@Component |
||||
public class OldSystemProperties { |
||||
/** |
||||
* 请求地址 |
||||
*/ |
||||
private String url; |
||||
|
||||
/** |
||||
* 默认账号 |
||||
*/ |
||||
private String pwd; |
||||
|
||||
/** |
||||
* 默认用户 |
||||
*/ |
||||
private String userId; |
||||
|
||||
|
||||
|
||||
} |
Loading…
Reference in new issue