From e675c4e3e814d9985d9234bb0aa4444d25353a84 Mon Sep 17 00:00:00 2001 From: liquanyu Date: Thu, 17 Jan 2019 09:48:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=80=E7=B3=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/service/impl/BloodPressureServiceImpl.java | 7 ++ .../web/service/impl/BloodSugarServiceImpl.java | 118 ++++++++++++++++++++- 2 files changed, 124 insertions(+), 1 deletion(-) diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodPressureServiceImpl.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodPressureServiceImpl.java index 59aedca..bb4fc45 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodPressureServiceImpl.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodPressureServiceImpl.java @@ -332,6 +332,13 @@ public class BloodPressureServiceImpl extends BaseServiceImpl implements IBloodP return restList; } + private int bloodPressureExceptionCount() + { + + int count = 0; + return count; + } + @Override public BaseResponse initBloodPressure(Map bloods) { JSONArray array = JSONArray.parseArray(bloods.get("datas")); diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodSugarServiceImpl.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodSugarServiceImpl.java index b2bd3e1..f268eb1 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodSugarServiceImpl.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodSugarServiceImpl.java @@ -26,6 +26,7 @@ import com.lyms.platform.pojo.*; import com.lyms.platform.query.AntExChuQuery; import com.lyms.platform.query.AntExRecordQuery; import com.lyms.platform.query.BloodSugarQuery; +import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.map.HashedMap; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; @@ -446,10 +447,125 @@ public class BloodSugarServiceImpl extends BaseServiceImpl implements IBloodSuga id = blood.getId(); } + int exceptionCount = bloodSugarExceptionCount(pid); + return RespBuilder.buildSuccess("restList", restList, "count", bloodSugars.size(), "dayCount", dayCountSet.size(), "month", monthCountSet3, "monthAvgMap", monthAvgMap, - "weekAvgMap", weekAvgMap,"newBloodVal",newBloodMap,"weightInfo",weightInfo,"isReport",isReport,"id",id); + "weekAvgMap", weekAvgMap,"newBloodVal",newBloodMap,"weightInfo",weightInfo,"isReport",isReport,"id",id,"exceptionCount",exceptionCount); + } + + private Map> sortMapByKey(Map> datas) { + if (MapUtils.isNotEmpty(datas)) { + Map> temp = new TreeMap<>(new Comparator() { + @Override + public int compare(String o1, String o2) { + return o2.compareTo(o1); + } + }); + for (Map.Entry> entry : datas.entrySet()) { + temp.put(entry.getKey(), entry.getValue()); + } + return temp; + } + return datas; + } + /** + * 血糖连续出现异常的次数 + * @param pid + * @return + */ + private int bloodSugarExceptionCount(String pid) + { + Map> maps = new HashMap<>(); + + int count = 0; + List bloodSugars = mongoTemplate.find(Query.query(Criteria.where("pid").is(pid)).with(new Sort(Sort.Direction.DESC, "modified")), BloodSugar.class); + if (CollectionUtils.isNotEmpty(bloodSugars)) + { + for (BloodSugar bloodSugar : bloodSugars) + { + List bss = maps.get(bloodSugar.getCreatYmdDate()); + if (CollectionUtils.isEmpty(bss)) + { + bss = new ArrayList<>(); + } + bss.add(bloodSugar); + maps.put(bloodSugar.getCreatYmdDate(),bss); + } + } + + maps = sortMapByKey(maps); + if (maps.size() > 0) + { + for (String key : maps.keySet()) + { + boolean isBreak = false; + List bss = maps.get(key); + if (CollectionUtils.isNotEmpty(bss)) + { + for (BloodSugar bs : bss) + { + int status = getBloodSugarStatus(bs.getBloodSugarType(),Float.parseFloat(bs.getBloodSugar())); + if (status != 0) + { + isBreak = true; + count++; + break; + } + } + } + if (!isBreak || count >=5) + { + break; + } + } + } + + return count; + } + + + private int getBloodSugarStatus(int type,float bloodVal) + { + Integer status = 0; + if (type == 1) {//1-空腹 + if (3.3f <= bloodVal && bloodVal <= 5.3f) {//正常 + } else if (bloodVal < 3.3f) {//异常 + status = -1; + } else if (bloodVal > 5.3f) {//异常 + status = 1; + } + } else if (type == 2 || type == 4 || type == 6) {//"餐前"2, "餐后"3 "餐后"5, + if (3.3f <= bloodVal && bloodVal <= 5.3f) {//正常 + } else if (bloodVal < 3.3f) {//异常 + status = -1; + } else if (bloodVal > 5.3f) {//异常 + status = 1; + } + } else if (type == 3 || type == 5 || type == 7) {//餐后"3,餐后"5, "餐后"7, + if (4.4f <= bloodVal && bloodVal <= 6.7f) {//正常 + } else if (bloodVal < 4.4f) {//异常 + status = -1; + } else if (bloodVal > 6.7f) {//异常 + status = 1; + } + } else if (type == 8) {// "夜间"8, + if (4.4f <= bloodVal && bloodVal <= 6.7f) {//正常 + } else if (bloodVal < 4.4f) {//异常 + status = -1; + } else if (bloodVal > 6.7f) {//异常 + status = 1; + } + } else if (type == 9) {// "睡前"9, + if (4.4f <= bloodVal && bloodVal <= 6.7f) {//正常 + } else if (bloodVal < 4.4f) {//异常 + status = -1; + } else if (bloodVal > 6.7f) {//异常 + status = 1; + } + } + return status; } -- 1.8.3.1