Commit e466910e91f970439f23f3384777abd81f0a2c86
1 parent
3f61ac8088
Exists in
master
and in
6 other branches
逗号改括号
Showing 1 changed file with 16 additions and 10 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodSugarServiceImpl.java
View file @
e466910
... | ... | @@ -244,13 +244,11 @@ |
244 | 244 | } |
245 | 245 | |
246 | 246 | |
247 | + // 周平均 | |
247 | 248 | Date date = new Date(); |
248 | - Map<String, Object> monthAvgMap = new LinkedHashMap<>(); | |
249 | - Map<Integer, Map<String, Object>> monthAvgTemp = new LinkedHashMap<>(); | |
250 | - Map<String, Object> weekAvgMap = new LinkedHashMap<>(); | |
249 | + List<Map<String, Object>> weekAvgMap = new ArrayList<>(); | |
251 | 250 | Map<Integer, Map<String, Object>> weekAvgMapTemp = new LinkedHashMap<>(); |
252 | 251 | Date weekStart = DateUtil.addWeek(date, -1); |
253 | - Date monthStart = DateUtil.addMonth(date, -1); | |
254 | 252 | List<BloodSugar> bloodSugarsWeek = mongoTemplate.find(Query.query(Criteria.where("parentId").is(parentId).and("created").gte(weekStart)).with(new Sort(Sort.Direction.DESC, "created")), BloodSugar.class); |
255 | 253 | for (BloodSugar bloodSugar : bloodSugarsWeek) { |
256 | 254 | if(weekAvgMapTemp.containsKey(bloodSugar.getBloodSugarType())) { |
257 | 255 | |
258 | 256 | |
259 | 257 | |
260 | 258 | |
261 | 259 | |
... | ... | @@ -266,23 +264,28 @@ |
266 | 264 | } |
267 | 265 | } |
268 | 266 | for (BloodSugarEnums bloodSugarEnums : BloodSugarEnums.values()) { |
267 | + Map<String, Object> weekMap = new HashMap<>(); | |
268 | + weekMap.put("name", bloodSugarEnums.getName()); | |
269 | 269 | boolean flag = true; |
270 | 270 | for (Map.Entry<Integer, Map<String, Object>> entry : weekAvgMapTemp.entrySet()) { |
271 | - weekAvgMap.put("name", bloodSugarEnums.getName()); | |
272 | 271 | if(entry.getKey() == bloodSugarEnums.getId()) { |
273 | 272 | Map<String, Object> map = entry.getValue(); |
274 | 273 | Integer dayCount = (Integer) map.get("dayCount"); |
275 | 274 | Double sugarCount = (Double) map.get("sugarCount"); |
276 | - weekAvgMap.put("value", sugarCount / dayCount); | |
275 | + weekMap.put("value", sugarCount / dayCount); | |
277 | 276 | flag = false; |
278 | 277 | } |
279 | 278 | } |
280 | 279 | if(flag) { |
281 | - weekAvgMap.put("value", "--"); | |
280 | + weekMap.put("value", "--"); | |
282 | 281 | } |
282 | + weekAvgMap.add(weekMap); | |
283 | 283 | } |
284 | 284 | |
285 | 285 | // 月平均 |
286 | + List<Map<String, Object>> monthAvgMap = new ArrayList<>(); | |
287 | + Map<Integer, Map<String, Object>> monthAvgTemp = new LinkedHashMap<>(); | |
288 | + Date monthStart = DateUtil.addMonth(date, -1); | |
286 | 289 | List<BloodSugar> bloodSugarsMonth = mongoTemplate.find(Query.query(Criteria.where("parentId").is(parentId).and("created").gte(monthStart)).with(new Sort(Sort.Direction.DESC, "created")), BloodSugar.class); |
287 | 290 | for (BloodSugar bloodSugar : bloodSugarsMonth) { |
288 | 291 | if(monthAvgTemp.containsKey(bloodSugar.getBloodSugarType())) { |
289 | 292 | |
290 | 293 | |
291 | 294 | |
292 | 295 | |
... | ... | @@ -298,20 +301,23 @@ |
298 | 301 | } |
299 | 302 | } |
300 | 303 | for (BloodSugarEnums bloodSugarEnums : BloodSugarEnums.values()) { |
304 | + Map<String, Object> monthMap = new HashMap<>(); | |
305 | + monthMap.put("name", bloodSugarEnums.getName()); | |
301 | 306 | boolean flag = true; |
302 | 307 | for (Map.Entry<Integer, Map<String, Object>> entry : monthAvgTemp.entrySet()) { |
303 | - weekAvgMap.put("name", bloodSugarEnums.getName()); | |
308 | + monthMap.put("name", bloodSugarEnums.getName()); | |
304 | 309 | if(entry.getKey() == bloodSugarEnums.getId()) { |
305 | 310 | Map<String, Object> map = entry.getValue(); |
306 | 311 | Integer dayCount = (Integer) map.get("dayCount"); |
307 | 312 | Double sugarCount = (Double) map.get("sugarCount"); |
308 | - weekAvgMap.put("value", sugarCount / dayCount); | |
313 | + monthMap.put("value", sugarCount / dayCount); | |
309 | 314 | flag = false; |
310 | 315 | } |
311 | 316 | } |
312 | 317 | if(flag) { |
313 | - weekAvgMap.put("value", "--"); | |
318 | + monthMap.put("value", "--"); | |
314 | 319 | } |
320 | + monthAvgMap.add(monthMap); | |
315 | 321 | } |
316 | 322 | |
317 | 323 |