提交 0b6b2d1c authored 作者: jiangwujie's avatar jiangwujie

feat(sdk):调试sdk调用报错的问题,恢复日期处理代码,看是否还有问题

上级 2d85c1f9
......@@ -74,6 +74,8 @@ import com.clx.user.enums.idcard.IdCardEnum;
import com.clx.user.feign.DocumentFeign;
import com.clx.user.feign.UserClxFeign;
import com.clx.user.param.feign.BatchUpdateDriverAndTruckParam;
import com.clx.user.feign.UserClxFeign;
import com.clx.user.param.feign.BatchUpdateDriverAndTruckParam;
import com.clx.user.vo.feign.DriverTruckInfoFeignVo;
import com.clx.user.vo.feign.OwnerInfoFeignVO;
import com.clx.user.vo.pc.auth.AuthVo;
......@@ -94,6 +96,7 @@ import com.purchase.manage.action.SupplyChainSupervisionLoadTruckAction;
import com.purchase.manage.dto.SupervisionLoadInfoDto;
import com.purchase.manage.dto.SupervisionLoadTruckInfoDto;
import com.scm.lms.manage.action.LmsWeighingSignatureAction;
import com.smart.business.sdk.request.dto.WeighingSignatureDto;
import com.smart.business.sdk.request.dto.WeightChildSignatureDto;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
......@@ -3834,35 +3837,4 @@ public class OrderChildServiceImpl implements OrderChildService {
}
return new WeightChildSignatureDto();
}
public static void main(String[] args) {
// RequestConfig config = new RequestConfig()
// .setAppId("878377421833815")
// .setAppKey("c95ea0fee001aa58b85d3882bf814a38")
// .setGatewayUrl("http://gateway.testclx.cn/lms-manage/external/open/doAction");
//
// LmsWeighingSignatureAction weightAction = new LmsWeighingSignatureAction();
// weightAction.setChildNo("CYD2024082815893659");
// weightAction.setCustomerRelationNo(String.valueOf("1121127465260843077"));
// weightAction.setType(2);
// log.info("job请求电子磅单参数,{}", weightAction);
// Result<WeightChildSignatureDto> weighSignature = OpenClient.doAction(config, weightAction);
// return weighSignature;
//组装配置信息
RequestConfig config = new RequestConfig()
.setAppId("878377421833815")
.setAppKey("c95ea0fee001aa58b85d3882bf814a38")
.setGatewayUrl("http://gateway.testclx.cn/lms-manage/external/open/doAction");
//通过运单号码查询电子磅单图片
LmsWeighingSignatureAction weightAction = new LmsWeighingSignatureAction();
weightAction.setChildNo("CYD2024082815893659");
weightAction.setCustomerRelationNo(String.valueOf("1121127465260843077"));
weightAction.setType(2);
log.info("接口请求电子磅单参数,{}",weightAction);
Result<WeightChildSignatureDto> weighSignature = OpenClient.doAction(config, weightAction);
log.info("接口请求电子磅单返回结果,{}",weighSignature);
}
}
package com.msl.common.open;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.google.common.reflect.TypeToken;
import com.google.gson.*;
import com.msl.common.open.action.Action;
import com.msl.common.open.message.Message;
import com.msl.common.result.Result;
import com.msl.common.utils.EncryptUtil;
import lombok.extern.slf4j.Slf4j;
import java.lang.reflect.Type;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
/**
* @author wanglq
* Date 2024/4/25
* Time 20:31
*/
@Slf4j
@SuppressWarnings("all")
public class OpenClient {
/**
* 执行action
*
* @param action action
* @param <T> 返回类型
* @return 结果
*/
public static <T> Result<T> doAction(RequestConfig config, Action<T> action) {
return doPost(config, action, "Action");
}
/**
* 发送消息
*
* @param message 消息
* @param <T> 返回类型
* @return 结果
*/
public static <T> Result<T> sendMessage(RequestConfig config, Message<T> message) {
return doPost(config, message, "Message");
}
/**
* 返回业务结果转换
*
* @param result 业务结果
* @param targetClass 目标类型
* @param <T> 目标类型
* @return 结果实体
*/
private static <T> Result<T> covertResult(String result, Type targetClass) {
Gson gson = new GsonBuilder()
.registerTypeAdapter(LocalDateTime.class, new CustomLocalDateTimeDeserializer())
.create();
// 使用TypeToken来获取带有泛型信息的Type
Type type = new TypeToken<Result<T>>() {
}.getType();
Result<T> resultObject = gson.fromJson(result, type);
// 如果目标类型不为空,则尝试将data属性转换为目标类型
if (targetClass != null && resultObject.getData() != null) {
T dataObject = gson.fromJson(gson.toJson(resultObject.getData()), targetClass);
resultObject.setData(dataObject);
}
return resultObject;
}
/**
* 执行post请求
*
* @param openDto 请求参数
* @since 1.1.0
*/
private static <T> Result<T> doPost(RequestConfig config, Process<T> process, String type) {
try {
String str = JSON.toJSONString(process);
ProcessId processId = process.processId();
log.info("OpenClient发送 {}<{}> 请求参数:{}", type, processId.show(), str);
//构造加密实体
OpenDto openDto = OpenDto.buildEncrypt(config.getAppId(), str, config.getAppKey(), System.currentTimeMillis())
.setNamespace(processId.namespace())
.setOperate(processId.identity());
//执行请求
return HttpExecutor.post(config.getGatewayUrl(), null,
openDto)
//反序化
.map(r -> JSON.parseObject(r, new TypeReference<OpenDto>() {
}))
//数据解密
.mapTry(dto -> EncryptUtil.decrypt(dto.getData(), config.getAppKey()))
.peek(s -> log.info("{}<{}> 返回结果:{}", type, processId.show(), s))
//业务结果实体转换
.map(s -> {
Result<T> r = covertResult(s, process.returnType());
return r;
}).orElse(Result.fail());
} catch (Exception e) {
throw new RuntimeException("OpenClient请求失败", e);
}
}
public static class CustomLocalDateTimeDeserializer implements JsonDeserializer<LocalDateTime> {
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@Override
public LocalDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
try {
return LocalDateTime.parse(json.getAsString(), formatter);
} catch (DateTimeParseException e) {
throw new JsonParseException("Date parse error", e);
}
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论