Commit 79969b562c7d0ed88a08fbdedfdadca82d35da03
1 parent
04d6318bae
Exists in
master
and in
6 other branches
体重管理相关代码
Showing 2 changed files with 49 additions and 45 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/PatientWeightServiceImpl.java
View file @
79969b5
... | ... | @@ -37,23 +37,43 @@ |
37 | 37 | @Autowired |
38 | 38 | private MongoUtil mongoUtil; |
39 | 39 | |
40 | - private Map<Integer, Double> highMap = new HashMap<>(); | |
40 | + private static Map<Integer, Double> highMap = new HashMap<>(); | |
41 | + private static Map<Integer, Double> normalMap = new HashMap<>(); | |
42 | + private static Map<Integer, Double> lowMap = new HashMap<>(); | |
43 | + private static List<Integer> xAxis = new ArrayList<>(); | |
41 | 44 | |
42 | 45 | /** |
43 | 46 | * 最低:0~13 : 0~1.9 13~40 1.9~11.9 |
44 | 47 | * 最高: 0~2.2 2.2~15.9 |
45 | 48 | */ |
46 | 49 | static { |
47 | - Map<Integer, Double> highMap = new HashMap<>(); | |
50 | + for (int i = 0; i <= 40; i++) { | |
51 | + xAxis.add(i); | |
52 | + } | |
53 | + | |
48 | 54 | double avg = 1.9 / 13; |
49 | 55 | for (int i = 0; i <= 13; i++) { |
50 | - highMap.put(i, i * avg); | |
56 | + lowMap.put(i, i * avg); | |
51 | 57 | } |
52 | 58 | |
53 | 59 | double avg2 = 10.0 / 27; |
54 | 60 | for (int i = 1; i <= 27; i++) { |
55 | - highMap.put(13 + i, i * avg2); | |
61 | + lowMap.put(13 + i, 1.9 + i * avg2); | |
56 | 62 | } |
63 | + | |
64 | + double highAvg = 2.2 / 13; | |
65 | + for (int i = 0; i <= 13; i++) { | |
66 | + highMap.put(i, i * highAvg); | |
67 | + } | |
68 | + | |
69 | + double highAvg2 = 13.7 / 27; | |
70 | + for (int i = 1; i <= 27; i++) { | |
71 | + highMap.put(13 + i, 2.2 + i * highAvg2); | |
72 | + } | |
73 | + | |
74 | + for (int i = 0; i <= 40; i++) { | |
75 | + normalMap.put(i, (highMap.get(i) + lowMap.get(i)) / 2); | |
76 | + } | |
57 | 77 | } |
58 | 78 | |
59 | 79 | |
... | ... | @@ -75,8 +95,11 @@ |
75 | 95 | if(weight != null && MapUtils.isNotEmpty(weight.getWeights())) { |
76 | 96 | weights = weight.getWeights(); |
77 | 97 | } |
78 | - weights.put(DateUtil.getWeek(new Date()), nowWeight); | |
79 | - patientWeight.setWeights(weights); | |
98 | + weights.put(DateUtil.getWeek(weight.getLastMenses(), new Date()), nowWeight); | |
99 | + weight.setWeights(weights); | |
100 | + Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(weight)); | |
101 | + mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(weight.getId())), update, PatientWeight.class); | |
102 | + return RespBuilder.buildSuccess(patientWeight.getId()); | |
80 | 103 | } |
81 | 104 | |
82 | 105 | String hospitalId = autoMatchFacade.getHospitalId(userId); |
... | ... | @@ -183,7 +206,7 @@ |
183 | 206 | map.put("bregmatic", BregmaticEnums2.getName(patientWeight.getBregmatic())); |
184 | 207 | map.put("bim", patientWeight.getBmi()); // 体质指数(BMI)=体重(kg)÷身高^2(m) |
185 | 208 | |
186 | - setReport(map, patientWeight.getWeights()); | |
209 | + setReport(map, patientWeight.getWeights(), patientWeight.getBeforeWeight()); | |
187 | 210 | |
188 | 211 | CollectionUtils.removeNullValue(map); |
189 | 212 | return RespBuilder.buildSuccess(map); |
190 | 213 | |
191 | 214 | |
192 | 215 | |
193 | 216 | |
194 | 217 | |
195 | 218 | |
196 | 219 | |
... | ... | @@ -534,46 +557,26 @@ |
534 | 557 | } |
535 | 558 | } |
536 | 559 | |
537 | - public void setReport(Map<String, Object> report, Map<Integer, String> weights) { | |
560 | + public void setReport(Map<String, Object> restMap, Map<Integer, String> weights, String beforeWeight) { | |
538 | 561 | Map<String, Object> reportModel = new HashMap<>(); |
539 | - reportModel.put("xAxis", MapUtils.isNotEmpty(weights) ? weights.keySet() : new ArrayList<>()); | |
562 | + reportModel.put("xAxis", xAxis); | |
540 | 563 | |
541 | - List<Map<String, Object>> series = new ArrayList<>(); | |
542 | - Map<String, Object> port = new HashMap<>(); | |
564 | + Map<String, Object> series = new HashMap<>(); | |
543 | 565 | List<Object> list = new ArrayList<>(); |
544 | 566 | if(MapUtils.isNotEmpty(weights)) { |
545 | 567 | Iterator<Map.Entry<Integer, String>> iterator = weights.entrySet().iterator(); |
546 | - boolean firstFlag = true; | |
547 | - String before = ""; | |
548 | 568 | while (iterator.hasNext()) { |
549 | 569 | Map.Entry<Integer, String> next = iterator.next(); |
550 | - before = next.getValue(); | |
551 | - if(firstFlag) { | |
552 | - firstFlag = false; | |
553 | - list.add(Arrays.asList(next.getKey(), 0)); | |
554 | - } else { | |
555 | - list.add(Arrays.asList(next.getKey(), getDiff(before, next.getValue()))); | |
556 | - } | |
570 | + list.add(Arrays.asList(next.getKey(), getDiff(beforeWeight, next.getValue()))); | |
557 | 571 | } |
558 | 572 | } |
559 | - port.put("portData", list); | |
560 | - series.add(port); | |
573 | + series.put("portData", list); | |
561 | 574 | |
562 | - Map<String, Object> high = new HashMap<>(); | |
563 | - high.put("lowData", Arrays.asList(1,2,3,4)); | |
564 | - series.add(high); | |
565 | - | |
566 | - Map<String, Object> normal = new HashMap<>(); | |
567 | - normal.put("highData", Arrays.asList(3,4,5,6)); | |
568 | - series.add(normal); | |
569 | - | |
570 | - Map<String, Object> low = new HashMap<>(); | |
571 | - low.put("normalData", Arrays.asList(2,3,4,5)); | |
572 | - series.add(low); | |
573 | - | |
575 | + series.put("lowData", CollectionUtils.getValList(lowMap)); | |
576 | + series.put("highData", CollectionUtils.getValList(highMap)); | |
577 | + series.put("normalData", CollectionUtils.getValList(normalMap)); | |
574 | 578 | reportModel.put("series", series); |
575 | - | |
576 | - report.put("reportModel", reportModel); | |
579 | + restMap.put("reportModel", reportModel); | |
577 | 580 | } |
578 | 581 | |
579 | 582 | /** |
... | ... | @@ -584,14 +587,5 @@ |
584 | 587 | Double n = Double.parseDouble(now); |
585 | 588 | return n - b; |
586 | 589 | } |
587 | - | |
588 | - public static void main(String[] args) { | |
589 | - Set<Integer> keySet = new HashSet<>(); | |
590 | - keySet.add(1); | |
591 | - keySet.add(3); | |
592 | - keySet.add(5); | |
593 | - | |
594 | - } | |
595 | - | |
596 | 590 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/CollectionUtils.java
View file @
79969b5
... | ... | @@ -127,6 +127,16 @@ |
127 | 127 | return restList; |
128 | 128 | } |
129 | 129 | |
130 | + public static <T> List<T> getValList(Map<Integer, T> map) { | |
131 | + Assert.notNull(map, "参数不能为null"); | |
132 | + List<T> restList = new ArrayList<>(); | |
133 | + Set<Integer> set = map.keySet(); | |
134 | + for (Integer s : set) { | |
135 | + restList.add(map.get(s)); | |
136 | + } | |
137 | + return restList; | |
138 | + } | |
139 | + | |
130 | 140 | /** |
131 | 141 | * key所对应的值如果=null就设置为0 |
132 | 142 | * @param map |