Commit d2a5baf48852375b0dee0104082cfea7335adc9d
1 parent
73d52b471b
Exists in
master
and in
6 other branches
update
Showing 4 changed files with 40 additions and 16 deletions
- platform-common/src/main/java/com/lyms/platform/common/utils/JsonUtil.java
- platform-operate-api/src/main/java/com/lyms/hospitalapi/lhxfy/LhxfyService.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java
- platform-operate-api/src/main/resources/config.properties
platform-common/src/main/java/com/lyms/platform/common/utils/JsonUtil.java
View file @
d2a5baf
| 1 | 1 | package com.lyms.platform.common.utils; |
| 2 | 2 | |
| 3 | + | |
| 4 | +import com.fasterxml.jackson.databind.DeserializationFeature; | |
| 5 | +import com.fasterxml.jackson.databind.JavaType; | |
| 6 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
| 3 | 7 | import com.lyms.platform.common.dao.operator.MongoCondition; |
| 4 | 8 | import com.lyms.platform.common.dao.operator.MongoOper; |
| 5 | 9 | import com.lyms.platform.common.dao.operator.MongoQuery; |
| 6 | 10 | |
| 7 | 11 | |
| 8 | 12 | |
| 9 | 13 | |
| 10 | 14 | |
| ... | ... | @@ -7,38 +11,50 @@ |
| 7 | 11 | import net.sf.json.JSONArray; |
| 8 | 12 | import net.sf.json.JSONObject; |
| 9 | 13 | import org.apache.commons.lang.StringUtils; |
| 10 | -import org.codehaus.jackson.map.ObjectMapper; | |
| 11 | -import org.codehaus.jackson.type.TypeReference; | |
| 12 | 14 | import org.springframework.data.mongodb.core.query.Update; |
| 13 | 15 | |
| 14 | 16 | import java.io.IOException; |
| 15 | 17 | import java.util.*; |
| 16 | 18 | |
| 17 | 19 | public class JsonUtil { |
| 18 | - | |
| 19 | - public static <T> T jkstr2Obj(String content, | |
| 20 | - Class<T> cls) { | |
| 21 | - ObjectMapper objectMapper = new ObjectMapper(); | |
| 22 | - objectMapper.setDateFormat(DateUtil.y_m_d_h_m_s); | |
| 20 | + // 定义jackson对象 | |
| 21 | + private static final ObjectMapper MAPPER = new ObjectMapper(); | |
| 22 | + public static List jsonToList(String jsonData, Class beanType) { | |
| 23 | + JavaType javaType = MAPPER.getTypeFactory().constructParametricType(List.class, beanType); | |
| 24 | + //如果是Map类型 MAPPER.getTypeFactory().constructParametricType(HashMap.class,String.class, beanType); | |
| 23 | 25 | try { |
| 24 | - return (T) objectMapper.readValue(content, cls); | |
| 25 | - } catch (IOException e) { | |
| 26 | + //是否强制让非数组模式的json字符串与java集合类型相匹配,默认是false,这里改为true | |
| 27 | + MAPPER.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); | |
| 28 | + List list = MAPPER.readValue(jsonData, javaType); | |
| 29 | + return list; | |
| 30 | + } catch (Exception e) { | |
| 26 | 31 | e.printStackTrace(); |
| 27 | 32 | } |
| 28 | 33 | return null; |
| 29 | 34 | } |
| 30 | - | |
| 31 | - public static <T> T jkstr2List(String content, | |
| 32 | - TypeReference<?> typeReference) { | |
| 35 | + public static <T> T jkstr2Obj(String content, | |
| 36 | + Class<T> cls) { | |
| 33 | 37 | ObjectMapper objectMapper = new ObjectMapper(); |
| 34 | 38 | objectMapper.setDateFormat(DateUtil.y_m_d_h_m_s); |
| 35 | 39 | try { |
| 36 | - return objectMapper.readValue(content,typeReference); | |
| 40 | + return (T) objectMapper.readValue(content, cls); | |
| 37 | 41 | } catch (IOException e) { |
| 38 | 42 | e.printStackTrace(); |
| 39 | 43 | } |
| 40 | 44 | return null; |
| 41 | 45 | } |
| 46 | + | |
| 47 | +// public static <T> T jkstr2List(String content, | |
| 48 | +// TypeReference<?> typeReference) { | |
| 49 | +// ObjectMapper objectMapper = new ObjectMapper(); | |
| 50 | +// objectMapper.setDateFormat(DateUtil.y_m_d_h_m_s); | |
| 51 | +// try { | |
| 52 | +// return objectMapper.readValue(content,typeReference); | |
| 53 | +// } catch (IOException e) { | |
| 54 | +// e.printStackTrace(); | |
| 55 | +// } | |
| 56 | +// return null; | |
| 57 | +// } | |
| 42 | 58 | |
| 43 | 59 | public static String obj2Str( |
| 44 | 60 | Object cls) { |
platform-operate-api/src/main/java/com/lyms/hospitalapi/lhxfy/LhxfyService.java
View file @
d2a5baf
| 1 | 1 | package com.lyms.hospitalapi.lhxfy; |
| 2 | 2 | |
| 3 | +import com.alibaba.druid.support.json.JSONUtils; | |
| 3 | 4 | import com.lyms.platform.biz.service.BasicConfigService; |
| 4 | 5 | import com.lyms.platform.biz.service.ResidentsArchiveService; |
| 5 | 6 | import com.lyms.platform.common.enums.YnEnums; |
| 6 | 7 | |
| ... | ... | @@ -81,10 +82,10 @@ |
| 81 | 82 | { |
| 82 | 83 | Map<String, String> itemParam = new HashMap<>(1); |
| 83 | 84 | itemParam.put("cardNo", cardNo); |
| 84 | - String json = HttpClientUtil.doPost(LHFY_LIS_URL, itemParam,"utf-8"); | |
| 85 | + String json = HttpClientUtil.doGet(LHFY_LIS_URL, itemParam,"utf-8",""); | |
| 85 | 86 | if (StringUtils.isNotEmpty(json)) |
| 86 | 87 | { |
| 87 | - return JsonUtil.toList(json,LisReportModel.class); | |
| 88 | + return JsonUtil.jsonToList(json,LisReportModel.class); | |
| 88 | 89 | } |
| 89 | 90 | return null; |
| 90 | 91 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java
View file @
d2a5baf
| ... | ... | @@ -4645,5 +4645,12 @@ |
| 4645 | 4645 | lhxfyService.syncResidents(); |
| 4646 | 4646 | return "success"; |
| 4647 | 4647 | } |
| 4648 | + | |
| 4649 | + | |
| 4650 | + @RequestMapping(value = "/getLhxfyLis", method = RequestMethod.GET) | |
| 4651 | + @ResponseBody | |
| 4652 | + public List<LisReportModel> getLhxfyLis(String cardNo) { | |
| 4653 | + return lhxfyService.getLhxfyLis(cardNo); | |
| 4654 | + } | |
| 4648 | 4655 | } |