Commit e75eff5e483b8dd86ff3b8d781c56d9053b971b2
1 parent
f4a97ab890
Exists in
master
and in
6 other branches
1111
Showing 1 changed file with 55 additions and 7 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodSugarServiceImpl.java
View file @
e75eff5
... | ... | @@ -226,7 +226,7 @@ |
226 | 226 | @Override |
227 | 227 | public BaseResponse wxInfo(String parentId, Integer type) { |
228 | 228 | List<Map<String, Object>> restList = new ArrayList<>(); |
229 | - List<BloodSugar> bloodSugars = mongoTemplate.find(Query.query(Criteria.where("parentId").is(parentId).and("bloodSugarType").is(type)).with(new Sort(Sort.Direction.DESC, "created")), BloodSugar.class); | |
229 | + List<BloodSugar> bloodSugars = mongoTemplate.find(Query.query(Criteria.where("parentId").is(parentId)).with(new Sort(Sort.Direction.DESC, "created")), BloodSugar.class); | |
230 | 230 | Set<String> dayCountSet = new HashSet<>(); |
231 | 231 | Set<String> monthCountSet = new HashSet<>(); |
232 | 232 | for (BloodSugar bloodSugar : bloodSugars) { |
233 | 233 | |
234 | 234 | |
235 | 235 | |
236 | 236 | |
237 | 237 | |
... | ... | @@ -245,22 +245,70 @@ |
245 | 245 | |
246 | 246 | |
247 | 247 | Date date = new Date(); |
248 | - Map<Integer, Object> monthAvgMap = new LinkedHashMap<>(); | |
248 | + Map<String, Object> monthAvgMap = new LinkedHashMap<>(); | |
249 | 249 | Map<Integer, Map<String, Object>> monthAvgTemp = new LinkedHashMap<>(); |
250 | - Map<Integer, Object> weekAvgMap = new LinkedHashMap<>(); | |
250 | + Map<String, Object> weekAvgMap = new LinkedHashMap<>(); | |
251 | 251 | Map<Integer, Map<String, Object>> weekAvgMapTemp = new LinkedHashMap<>(); |
252 | 252 | Date weekStart = DateUtil.addWeek(date, -1); |
253 | 253 | Date monthStart = DateUtil.addMonth(date, -1); |
254 | - List<BloodSugar> bloodSugarsWeek = mongoTemplate.find(Query.query(Criteria.where("parentId").is(parentId).and("bloodSugarType").is(type).and("created").gte(weekStart)).with(new Sort(Sort.Direction.DESC, "created")), BloodSugar.class); | |
254 | + 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 | 255 | for (BloodSugar bloodSugar : bloodSugarsWeek) { |
256 | + if(weekAvgMapTemp.containsKey(bloodSugar.getBloodSugarType())) { | |
257 | + Map<String, Object> temp = weekAvgMapTemp.get(bloodSugar.getBloodSugarType()); | |
258 | + temp.put("dayCount", Integer.parseInt(temp.get("count") + "") + 1); // 总共有记录的天数 | |
259 | + temp.put("sugarCount", Double.parseDouble(temp.get("sugarCount") + "") + Double.parseDouble(bloodSugar.getBloodSugar())); // 总共所有记录的和 | |
260 | + weekAvgMapTemp.put(bloodSugar.getBloodSugarType(), temp); | |
261 | + } else { | |
262 | + Map<String, Object> temp = new HashMap<>(); | |
263 | + temp.put("dayCount", 1); // 总共有记录的天数 | |
264 | + temp.put("sugarCount", bloodSugar.getBloodSugar()); // 总共所有记录的和 | |
265 | + weekAvgMapTemp.put(bloodSugar.getBloodSugarType(), temp); | |
266 | + } | |
267 | + } | |
268 | + for (BloodSugarEnums bloodSugarEnums : BloodSugarEnums.values()) { | |
269 | + for (Map.Entry<Integer, Map<String, Object>> entry : weekAvgMapTemp.entrySet()) { | |
270 | + weekAvgMap.put("name", bloodSugarEnums.getName()); | |
271 | + if(entry.getKey() == bloodSugarEnums.getId()) { | |
272 | + Map<String, Object> map = entry.getValue(); | |
273 | + Integer dayCount = (Integer) map.get("dayCount"); | |
274 | + Double sugarCount = (Double) map.get("sugarCount"); | |
275 | + weekAvgMap.put("value", sugarCount / dayCount); | |
276 | + } else { | |
277 | + weekAvgMap.put("value", "--"); | |
278 | + } | |
279 | + } | |
280 | + } | |
281 | + | |
282 | + // 月平均 | |
283 | + 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); | |
284 | + for (BloodSugar bloodSugar : bloodSugarsMonth) { | |
256 | 285 | if(monthAvgTemp.containsKey(bloodSugar.getBloodSugarType())) { |
257 | 286 | Map<String, Object> temp = monthAvgTemp.get(bloodSugar.getBloodSugarType()); |
258 | 287 | temp.put("dayCount", Integer.parseInt(temp.get("count") + "") + 1); // 总共有记录的天数 |
259 | -// temp.put() | |
260 | -// monthAvgTemp.put(bloodSugar.getBloodSugarType(), ) | |
288 | + temp.put("sugarCount", Double.parseDouble(temp.get("sugarCount") + "") + Double.parseDouble(bloodSugar.getBloodSugar())); // 总共所有记录的和 | |
289 | + monthAvgTemp.put(bloodSugar.getBloodSugarType(), temp); | |
290 | + } else { | |
291 | + Map<String, Object> temp = new HashMap<>(); | |
292 | + temp.put("dayCount", 1); // 总共有记录的天数 | |
293 | + temp.put("sugarCount", bloodSugar.getBloodSugar()); // 总共所有记录的和 | |
294 | + monthAvgTemp.put(bloodSugar.getBloodSugarType(), temp); | |
261 | 295 | } |
262 | 296 | } |
263 | - List<BloodSugar> bloodSugarsMonth = mongoTemplate.find(Query.query(Criteria.where("parentId").is(parentId).and("bloodSugarType").is(type).and("created").gte(monthStart)).with(new Sort(Sort.Direction.DESC, "created")), BloodSugar.class); | |
297 | + for (BloodSugarEnums bloodSugarEnums : BloodSugarEnums.values()) { | |
298 | + for (Map.Entry<Integer, Map<String, Object>> entry : monthAvgTemp.entrySet()) { | |
299 | + weekAvgMap.put("name", bloodSugarEnums.getName()); | |
300 | + if(entry.getKey() == bloodSugarEnums.getId()) { | |
301 | + Map<String, Object> map = entry.getValue(); | |
302 | + Integer dayCount = (Integer) map.get("dayCount"); | |
303 | + Double sugarCount = (Double) map.get("sugarCount"); | |
304 | + weekAvgMap.put("value", sugarCount / dayCount); | |
305 | + } else { | |
306 | + weekAvgMap.put("value", "--"); | |
307 | + } | |
308 | + } | |
309 | + } | |
310 | + | |
311 | + | |
264 | 312 | return RespBuilder.buildSuccess("restList", restList, "count", bloodSugars.size(), "dayCount", dayCountSet.size(), "month", monthCountSet, "monthAvgMap", monthAvgMap, "weekAvgMap", weekAvgMap); |
265 | 313 | } |
266 | 314 |