From d2a5baf48852375b0dee0104082cfea7335adc9d Mon Sep 17 00:00:00 2001 From: liquanyu Date: Thu, 8 Jul 2021 18:15:43 +0800 Subject: [PATCH] update --- .../com/lyms/platform/common/utils/JsonUtil.java | 42 +++++++++++++++------- .../com/lyms/hospitalapi/lhxfy/LhxfyService.java | 5 +-- .../operate/web/controller/TestController.java | 7 ++++ .../src/main/resources/config.properties | 2 +- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/platform-common/src/main/java/com/lyms/platform/common/utils/JsonUtil.java b/platform-common/src/main/java/com/lyms/platform/common/utils/JsonUtil.java index 9c13ac9..48b3cb3 100644 --- a/platform-common/src/main/java/com/lyms/platform/common/utils/JsonUtil.java +++ b/platform-common/src/main/java/com/lyms/platform/common/utils/JsonUtil.java @@ -1,5 +1,9 @@ package com.lyms.platform.common.utils; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.ObjectMapper; import com.lyms.platform.common.dao.operator.MongoCondition; import com.lyms.platform.common.dao.operator.MongoOper; import com.lyms.platform.common.dao.operator.MongoQuery; @@ -7,39 +11,51 @@ import com.lyms.platform.common.pojo.SyncDataModel; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.apache.commons.lang.StringUtils; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.type.TypeReference; import org.springframework.data.mongodb.core.query.Update; import java.io.IOException; import java.util.*; public class JsonUtil { - - public static T jkstr2Obj(String content, - Class cls) { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.setDateFormat(DateUtil.y_m_d_h_m_s); + // 定义jackson对象 + private static final ObjectMapper MAPPER = new ObjectMapper(); + public static List jsonToList(String jsonData, Class beanType) { + JavaType javaType = MAPPER.getTypeFactory().constructParametricType(List.class, beanType); + //如果是Map类型 MAPPER.getTypeFactory().constructParametricType(HashMap.class,String.class, beanType); try { - return (T) objectMapper.readValue(content, cls); - } catch (IOException e) { + //是否强制让非数组模式的json字符串与java集合类型相匹配,默认是false,这里改为true + MAPPER.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); + List list = MAPPER.readValue(jsonData, javaType); + return list; + } catch (Exception e) { e.printStackTrace(); } return null; } - - public static T jkstr2List(String content, - TypeReference typeReference) { + public static T jkstr2Obj(String content, + Class cls) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setDateFormat(DateUtil.y_m_d_h_m_s); try { - return objectMapper.readValue(content,typeReference); + return (T) objectMapper.readValue(content, cls); } catch (IOException e) { e.printStackTrace(); } return null; } +// public static T jkstr2List(String content, +// TypeReference typeReference) { +// ObjectMapper objectMapper = new ObjectMapper(); +// objectMapper.setDateFormat(DateUtil.y_m_d_h_m_s); +// try { +// return objectMapper.readValue(content,typeReference); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// return null; +// } + public static String obj2Str( Object cls) { try { diff --git a/platform-operate-api/src/main/java/com/lyms/hospitalapi/lhxfy/LhxfyService.java b/platform-operate-api/src/main/java/com/lyms/hospitalapi/lhxfy/LhxfyService.java index e4234dc..6b14683 100644 --- a/platform-operate-api/src/main/java/com/lyms/hospitalapi/lhxfy/LhxfyService.java +++ b/platform-operate-api/src/main/java/com/lyms/hospitalapi/lhxfy/LhxfyService.java @@ -1,5 +1,6 @@ package com.lyms.hospitalapi.lhxfy; +import com.alibaba.druid.support.json.JSONUtils; import com.lyms.platform.biz.service.BasicConfigService; import com.lyms.platform.biz.service.ResidentsArchiveService; import com.lyms.platform.common.enums.YnEnums; @@ -81,10 +82,10 @@ public class LhxfyService { { Map itemParam = new HashMap<>(1); itemParam.put("cardNo", cardNo); - String json = HttpClientUtil.doPost(LHFY_LIS_URL, itemParam,"utf-8"); + String json = HttpClientUtil.doGet(LHFY_LIS_URL, itemParam,"utf-8",""); if (StringUtils.isNotEmpty(json)) { - return JsonUtil.toList(json,LisReportModel.class); + return JsonUtil.jsonToList(json,LisReportModel.class); } return null; } diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java index eccb1da..ab604f2 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java @@ -4645,4 +4645,11 @@ public class TestController extends BaseController { lhxfyService.syncResidents(); return "success"; } + + + @RequestMapping(value = "/getLhxfyLis", method = RequestMethod.GET) + @ResponseBody + public List getLhxfyLis(String cardNo) { + return lhxfyService.getLhxfyLis(cardNo); + } } diff --git a/platform-operate-api/src/main/resources/config.properties b/platform-operate-api/src/main/resources/config.properties index 9c965ac..fab49de 100644 --- a/platform-operate-api/src/main/resources/config.properties +++ b/platform-operate-api/src/main/resources/config.properties @@ -54,4 +54,4 @@ area_url=http://localhost:8082 #隆化妇幼同步his的地址 lhfy_his_url= #隆化妇幼获取lis的url -lhfy_lis_url= \ No newline at end of file +lhfy_lis_url=https://lhfy-chengde-api.healthbaby.com.cn:12356/lis/getLhLisById \ No newline at end of file -- 1.8.3.1