fix:修复result显示bug

This commit is contained in:
石崇礼 2025-02-08 15:40:47 +08:00
parent 117f293e83
commit f966dd9387
3 changed files with 21 additions and 7 deletions

View File

@ -51,6 +51,11 @@ public class LexMarkResultDTO implements Serializable {
*/
private Param param;
/**
* 详情描述
*/
private String desc;
@Data
@AllArgsConstructor

View File

@ -1,5 +1,6 @@
package com.dpkj.common.utils;
import com.alibaba.fastjson.JSON;
import com.dpkj.common.dto.LexMarkDTO;
import com.dpkj.common.dto.LexMarkResultDTO;
import com.dpkj.common.exception.RRException;
@ -15,6 +16,7 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
/**
* 第三方服务主要是调用打印机等
*
@ -42,15 +44,14 @@ public class ThirdService {
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Content - Type", "application/json");
connection.setRequestProperty("Content-Type", "application/json");
// 将LexMarkDTO对象转换为JSON字符串
ObjectMapper objectMapper = new ObjectMapper();
String jsonInputString = objectMapper.writeValueAsString(lexMarkDTO);
String jsonInputString = JSON.toJSONString(lexMarkDTO);
try (DataOutputStream wr = new DataOutputStream(connection.getOutputStream())) {
byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
wr.write(input, 0, input.length);
log.info(jsonInputString);
}
int responseCode = connection.getResponseCode();
@ -68,10 +69,18 @@ public class ThirdService {
in.close();
// 将响应JSON字符串转换为LexMarkResultDTO对象
ObjectMapper resultMapper = new ObjectMapper();
return resultMapper.readValue(response.toString(), LexMarkResultDTO.class);
LexMarkResultDTO lexMarkResultDTO = JSON.parseObject(response.toString(), LexMarkResultDTO.class);
if( lexMarkResultDTO.getResult() != 0){
log.error("利盟服务请求出错:{}", lexMarkResultDTO);
throw new RRException(lexMarkResultDTO.toString());
}
return lexMarkResultDTO;
}catch (Exception e){
log.error("利盟服务请求失败:{}", lexMarkDTO, e);
if ( e instanceof RRException ){
throw new RRException(((RRException) e).getCode(), e.getMessage());
}
throw new RRException("利盟服务请求失败");
}
}

View File

@ -50,7 +50,7 @@ public class Result<T> implements Serializable {
}
public static <T> Result<T> ok(T data) {
return error("", data);
return ok("", data);
}
public static <T> Result<T> ok(String msg, T data) {