Commit 6d3a59fe47a4edc9b16d9a04e073b544593073d6
1 parent
f83ab9941c
Exists in
master
and in
6 other branches
诊断字段格式化
Showing 2 changed files with 38 additions and 4 deletions
platform-common/src/main/java/com/lyms/platform/common/utils/ReflectionUtils.java
View file @
6d3a59f
1 | 1 | package com.lyms.platform.common.utils; |
2 | 2 | |
3 | +import java.beans.BeanInfo; | |
4 | +import java.beans.Introspector; | |
5 | +import java.beans.PropertyDescriptor; | |
3 | 6 | import java.lang.reflect.Field; |
4 | 7 | import java.lang.reflect.InvocationTargetException; |
5 | 8 | import java.lang.reflect.Method; |
... | ... | @@ -34,6 +37,32 @@ |
34 | 37 | String getterMethodName = "get" + StringUtils.capitalize(propertyName); |
35 | 38 | return invokeMethod(obj, getterMethodName, new Class[] {}, |
36 | 39 | new Object[] {}); |
40 | + } | |
41 | + | |
42 | + public static Map<String, Object> beanToMap(Object obj) { | |
43 | + if(obj == null){ | |
44 | + return null; | |
45 | + } | |
46 | + Map<String, Object> map = new HashMap<String, Object>(); | |
47 | + try { | |
48 | + BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass()); | |
49 | + PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); | |
50 | + for (PropertyDescriptor property : propertyDescriptors) { | |
51 | + String key = property.getName(); | |
52 | + // 过滤class属性 | |
53 | + if (!key.equals("class")) { | |
54 | + // 得到property对应的getter方法 | |
55 | + Method getter = property.getReadMethod(); | |
56 | + Object value = getter.invoke(obj); | |
57 | + | |
58 | + map.put(key, value); | |
59 | + } | |
60 | + } | |
61 | + } catch (Exception e) { | |
62 | + e.printStackTrace(); | |
63 | + } | |
64 | + return map; | |
65 | + | |
37 | 66 | } |
38 | 67 | |
39 | 68 | /** |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/NewbornServiceImpl.java
View file @
6d3a59f
... | ... | @@ -13,6 +13,7 @@ |
13 | 13 | import com.lyms.platform.operate.web.facade.AutoMatchFacade; |
14 | 14 | import com.lyms.platform.operate.web.service.INewbornVisitService; |
15 | 15 | import com.lyms.platform.operate.web.utils.CollectionUtils; |
16 | +import com.lyms.platform.operate.web.utils.FunvCommonUtil; | |
16 | 17 | import com.lyms.platform.operate.web.utils.MongoUtil; |
17 | 18 | import com.lyms.platform.operate.web.utils.ResponseUtil; |
18 | 19 | import com.lyms.platform.permission.dao.master.CouponMapper; |
... | ... | @@ -22,6 +23,7 @@ |
22 | 23 | import com.lyms.platform.pojo.*; |
23 | 24 | import com.lyms.platform.query.DataPermissionsModelQuery; |
24 | 25 | import com.mongodb.WriteResult; |
26 | +import org.apache.commons.collections.map.HashedMap; | |
25 | 27 | import org.apache.commons.lang.StringUtils; |
26 | 28 | import org.springframework.beans.factory.annotation.Autowired; |
27 | 29 | import org.springframework.data.domain.Sort; |
28 | 30 | |
29 | 31 | |
30 | 32 | |
... | ... | @@ -246,15 +248,18 @@ |
246 | 248 | @Override |
247 | 249 | public BaseObjectResponse get(String id) { |
248 | 250 | NewbornVisit newbornVisit = mongoTemplate.findById(id, NewbornVisit.class); |
249 | - Map<String, Object> restMap = new HashMap<>(); | |
250 | - if(newbornVisit != null) {} | |
251 | + Map<String, Object> map = ReflectionUtils.beanToMap(newbornVisit); | |
252 | + List<Map<String, Object>> diagnosisList = new ArrayList<>(); | |
251 | 253 | List<String> diagnosis = newbornVisit.getDiagnosis(); |
252 | 254 | if(CollectionUtils.isNotEmpty(diagnosis)) { |
253 | 255 | for (String s : diagnosis) { |
254 | - restMap.put(s, mongoUtil.findName(s)); | |
256 | + Map<String, Object> tempMap = new HashedMap(); | |
257 | + tempMap.put(s, mongoUtil.findName(s)); | |
258 | + diagnosisList.add(tempMap); | |
255 | 259 | } |
260 | + map.put("diagnosis", diagnosisList); | |
256 | 261 | } |
257 | - return RespBuilder.buildSuccess("newbornVisit", newbornVisit, "diagnosis", restMap); | |
262 | + return RespBuilder.buildSuccess(map); | |
258 | 263 | } |
259 | 264 | |
260 | 265 | @Override |