提交 3d9cf8f5 authored 作者: liruixin's avatar liruixin

performance-sdk

上级 482d0bb0
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.clx.cy</groupId>
<artifactId>performance-sdk</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>performance-sdk</name>
<parent>
<groupId>com.msl</groupId>
<artifactId>msl-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath/>
</parent>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
<dependency>
<groupId>com.msl</groupId>
<artifactId>msl-common</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>com.msl</groupId>
<artifactId>convertor-spring-boot-starter</artifactId>
</dependency>
<!-- gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Releases</name>
<url>http://139.129.222.24:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-releases</id>
<name>Snapshot</name>
<url>http://139.129.222.24:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package com.clx.performance.sdk.callback.message;
public interface Message {
String topic();
}
package com.clx.performance.sdk.callback.message;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import static com.clx.performance.sdk.constant.MessageConstants.QUOTATION_INFO_SYNC;
/**
* @ClassName Quotation
* @Description 同步调价
* @Author kavin
* @Date 2023/10/14 17:56
* @Version 1.0
*/
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class QuotationUpdateMessage implements Message{
@ApiModelProperty(value = "订单编号")
private String orderNo;
@ApiModelProperty(value = "平台报价价格")
private BigDecimal platformFreightQuotation;
@ApiModelProperty(value = "报价超时时间")
private LocalDateTime quotationTimeoutTime;
@Override
public String topic() {
return QUOTATION_INFO_SYNC;
}
}
package com.clx.performance.sdk.constant;
public class ActionConstants {
public static final String ORDER_INFO_SYNC = "order.info.save";
}
package com.clx.performance.sdk.constant;
public class MessageConstants {
public static final String QUOTATION_INFO_SYNC = "quotation.info.sync";
}
package com.clx.performance.sdk.request;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.clx.performance.sdk.request.action.Action;
import com.google.gson.Gson;
import com.msl.common.dto.HttpDTO;
import com.msl.common.result.Result;
import com.msl.common.utils.EncryptUtil;
import com.msl.common.utils.HttpUtil;
import lombok.extern.slf4j.Slf4j;
/**
* @author wanglq
* Date 2023/8/5
* Time 16:50
*/
@Slf4j
public class PerformanceRequestClient {
private String gatewayUrl;
private String appNo;
private String appSecret;
public PerformanceRequestClient(String gatewayUrl, String appNo, String appSecret) {
this.gatewayUrl = gatewayUrl;
this.appNo = appNo;
this.appSecret = appSecret;
}
public <T> Result<T> doAction(Action<T> action) {
try {
HttpDTO httpDTO = EncryptUtil.buildDTO(appNo, JSON.toJSONString(action), appSecret, System.currentTimeMillis());
httpDTO.setAction(action.action());
return HttpUtil.post(gatewayUrl, null,
httpDTO)
.map(r -> JSON.parseObject(r, new TypeReference<HttpDTO>() {
}))
.mapTry(dto -> EncryptUtil.decrypt(dto.getData(), appSecret))
.mapWithObj(new TypeReference<Result<T>>() {
}, this::covertResult)
.get();
} catch (Exception e) {
throw new RuntimeException("http请求失败", e);
}
}
private <T> Result<T> covertResult(String result, TypeReference<Result<T>> reference) {
return new Gson().fromJson(result, reference.getType());
}
}
package com.clx.performance.sdk.request.action;
/**
* @author wanglq
* Date 2023/8/5
* Time 18:19
*/
public interface Action<T> {
String action();
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论