Ver código fonte

Merge branch 'dev' of liubing/wlyy2.0 into dev

liubing 3 anos atrás
pai
commit
f66339faa7

+ 118 - 120
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/security/SecurityMonitoringOrderService.java

@ -1221,141 +1221,139 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
        if (null==result){
            result = new JSONObject();
        }
        if (StringUtils.isNotBlank(topicItem)||StringUtils.isBlank(topicItem)){
            if ("preventLost".equals(topicItem)){
                List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"4");
                if (devicePatientDeviceDos.size()==0){}
                else {
                    DevicePatientDevice device = devicePatientDeviceDos.get(0);
                    result.put("deviceSn",device.getDeviceSn());
                    try {
                        JSONObject response= patientDeviceService.getAqgDeviceInfo(device.getDeviceSn());
                        if (response!=null){
                            //定位信息
                            if (response.containsKey("last_location")&&response.get("last_location")!=null){
                                JSONObject locationTmp = response.getJSONObject("last_location");
                                Double lon = locationTmp.getJSONArray("coordinates").getDouble(0);
                                Double lat = locationTmp.getJSONArray("coordinates").getDouble(1);
                                JSONObject tmp = gpsUtil.gcj02_To_Bd09(lat,lon);
                                tmp.put("city",response.getString("last_city"));
                                tmp.put("province",response.getString("last_province"));
                                tmp.put("address",response.getString("last_address"));
                                result.put("location",tmp);
                            }
                            //围栏信息
                            if (response.containsKey("fences")&&response.get("fences")!=null){
                                JSONArray fencesArr = response.getJSONArray("fences");
                                JSONArray fencesEnables = new JSONArray();
                                for (int i=0;i<fencesArr.size();i++){
                                    JSONObject tmp = fencesArr.getJSONObject(i);
                                    if (tmp.getBooleanValue("enable")){//围栏生效
                                        JSONObject fenceTmp = new JSONObject();
                                        fenceTmp.put("fenceNO",tmp.getInteger("seqid").toString());
                                        fenceTmp.put("name",tmp.getString("name"));
                                        JSONArray fenceLocationTmp = tmp.getJSONObject("safe_area").getJSONArray("coordinates").getJSONArray(0);
                                        JSONArray fenceLocation = new JSONArray();
                                        for (int j=0;j<fenceLocationTmp.size();j++){
                                            Double lon = fenceLocationTmp.getJSONArray(j).getDouble(0);
                                            Double lat = fenceLocationTmp.getJSONArray(j).getDouble(1);
                                            JSONObject positionTmp = gpsUtil.gcj02_To_Bd09(lat,lon);
                                            fenceLocation.add(positionTmp);
                                        }
                                        fenceTmp.put("location",fenceLocation);
                                        fenceTmp.put("inFenceStatus",countDistance.isInPolygon(result.getJSONObject("location").getDouble("lon"),result.getJSONObject("location").getDouble("lat"),fenceLocation));
                                        fencesEnables.add(fenceTmp);
        if ("preventLost".equals(topicItem)||StringUtils.isBlank(topicItem)){
            List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"4");
            if (devicePatientDeviceDos.size()==0){}
            else {
                DevicePatientDevice device = devicePatientDeviceDos.get(0);
                result.put("deviceSn",device.getDeviceSn());
                try {
                    JSONObject response= patientDeviceService.getAqgDeviceInfo(device.getDeviceSn());
                    if (response!=null){
                        //定位信息
                        if (response.containsKey("last_location")&&response.get("last_location")!=null){
                            JSONObject locationTmp = response.getJSONObject("last_location");
                            Double lon = locationTmp.getJSONArray("coordinates").getDouble(0);
                            Double lat = locationTmp.getJSONArray("coordinates").getDouble(1);
                            JSONObject tmp = gpsUtil.gcj02_To_Bd09(lat,lon);
                            tmp.put("city",response.getString("last_city"));
                            tmp.put("province",response.getString("last_province"));
                            tmp.put("address",response.getString("last_address"));
                            result.put("location",tmp);
                        }
                        //围栏信息
                        if (response.containsKey("fences")&&response.get("fences")!=null){
                            JSONArray fencesArr = response.getJSONArray("fences");
                            JSONArray fencesEnables = new JSONArray();
                            for (int i=0;i<fencesArr.size();i++){
                                JSONObject tmp = fencesArr.getJSONObject(i);
                                if (tmp.getBooleanValue("enable")){//围栏生效
                                    JSONObject fenceTmp = new JSONObject();
                                    fenceTmp.put("fenceNO",tmp.getInteger("seqid").toString());
                                    fenceTmp.put("name",tmp.getString("name"));
                                    JSONArray fenceLocationTmp = tmp.getJSONObject("safe_area").getJSONArray("coordinates").getJSONArray(0);
                                    JSONArray fenceLocation = new JSONArray();
                                    for (int j=0;j<fenceLocationTmp.size();j++){
                                        Double lon = fenceLocationTmp.getJSONArray(j).getDouble(0);
                                        Double lat = fenceLocationTmp.getJSONArray(j).getDouble(1);
                                        JSONObject positionTmp = gpsUtil.gcj02_To_Bd09(lat,lon);
                                        fenceLocation.add(positionTmp);
                                    }
                                }
                                if (fencesEnables.size()>0){
                                    result.put("fences",fencesEnables);
                                    fenceTmp.put("location",fenceLocation);
                                    fenceTmp.put("inFenceStatus",countDistance.isInPolygon(result.getJSONObject("location").getDouble("lon"),result.getJSONObject("location").getDouble("lat"),fenceLocation));
                                    fencesEnables.add(fenceTmp);
                                }
                            }
                            if (fencesEnables.size()>0){
                                result.put("fences",fencesEnables);
                            }
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                        result.put("location",null);
                    }
                }catch (Exception e){
                    e.printStackTrace();
                    result.put("location",null);
                }
            }
            if ("preventFall".equals(topicItem)||StringUtils.isBlank(topicItem)){
                List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"12");
                if (devicePatientDeviceDos.size()==0){}
                else{
                    try {
                        DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
                        JSONObject monitorUrl = ysDeviceServicel.getDeviceLiveAddress(patient,deviceDo.getDeviceSn(),1,null);
                        result.put("monitorInfoStatus",monitorUrl.getIntValue(ResponseContant.resultFlag));
                        result.put("patientAddress",deviceDo.getSosAddress());
                        if (monitorUrl.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
                            result.put("monitorInfo",monitorUrl.getString(ResponseContant.resultMsg));
                        }
                        else {
                            result.put("monitorInfo",monitorUrl.getJSONObject(ResponseContant.resultMsg));
                        }
                    }catch (Exception e){
                        e.printStackTrace();
        }
        if ("preventFall".equals(topicItem)||StringUtils.isBlank(topicItem)){
            List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"12");
            if (devicePatientDeviceDos.size()==0){}
            else{
                try {
                    DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
                    JSONObject monitorUrl = ysDeviceServicel.getDeviceLiveAddress(patient,deviceDo.getDeviceSn(),1,null);
                    result.put("monitorInfoStatus",monitorUrl.getIntValue(ResponseContant.resultFlag));
                    result.put("patientAddress",deviceDo.getSosAddress());
                    if (monitorUrl.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
                        result.put("monitorInfo",monitorUrl.getString(ResponseContant.resultMsg));
                    }
                    else {
                        result.put("monitorInfo",monitorUrl.getJSONObject(ResponseContant.resultMsg));
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
            if ("preventOutOfBed".equals(topicItem)||StringUtils.isBlank(topicItem)){
                List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"13");
                if (devicePatientDeviceDos.size()==0){}
                else {
                    DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
                    JSONObject deviceInfo =  patientDeviceService.getSleepDeviceInfo(deviceDo.getDeviceSn());
                    if(deviceInfo.getBooleanValue("success")){
                        result.put("patientAddress",deviceDo.getSosAddress());
                        JSONArray objInfo = deviceInfo.getJSONArray("objs");
                        if (objInfo.size()>0){
                            result.put("sleepStatus",true);
                            JSONObject tmp = objInfo.getJSONObject(0);
                            JSONObject sleepInfo = new JSONObject();
                            sleepInfo.put("online",tmp.getBooleanValue("online"));
                            sleepInfo.put("onbed",tmp.getBooleanValue("onbed"));
                            sleepInfo.put("heartrate",tmp.getString("heartrate"));
                            sleepInfo.put("breathrate",tmp.getString("breathrate"));
                            BasePatientOutBed outBed = outBedDao.findByPatientAndDeviceSnAndStatus(patient,deviceDo.getDeviceSn(),0);
                            if (null!=outBed){
                                String outBedTime = "";
                                Date date = new Date();
                                long millisecondsDiff = date.getTime() - outBed.getCreateTime().getTime();
                                long minutesDiff = millisecondsDiff / TimeUnit.MINUTES.toMillis(1L);
                                long hoursDiff = millisecondsDiff / TimeUnit.HOURS.toMillis(1L);
                                long minuteFieldDiff = minutesDiff - TimeUnit.HOURS.toMinutes(hoursDiff);
                                if (hoursDiff > 0L) {
                                    outBedTime += String.format("%d小时", hoursDiff);
                                }
                                if (minuteFieldDiff>0){
                                    outBedTime +=String.format("%d分钟", minuteFieldDiff);
                                }
                                sleepInfo.put("outBedTime",outBedTime);
                            }else {
                                sleepInfo.put("outBedTime","无");
        }
        if ("preventOutOfBed".equals(topicItem)||StringUtils.isBlank(topicItem)){
            List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"13");
            if (devicePatientDeviceDos.size()==0){}
            else {
                DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
                JSONObject deviceInfo =  patientDeviceService.getSleepDeviceInfo(deviceDo.getDeviceSn());
                if(deviceInfo.getBooleanValue("success")){
                    result.put("patientAddress",deviceDo.getSosAddress());
                    JSONArray objInfo = deviceInfo.getJSONArray("objs");
                    if (objInfo.size()>0){
                        result.put("sleepStatus",true);
                        JSONObject tmp = objInfo.getJSONObject(0);
                        JSONObject sleepInfo = new JSONObject();
                        sleepInfo.put("online",tmp.getBooleanValue("online"));
                        sleepInfo.put("onbed",tmp.getBooleanValue("onbed"));
                        sleepInfo.put("heartrate",tmp.getString("heartrate"));
                        sleepInfo.put("breathrate",tmp.getString("breathrate"));
                        BasePatientOutBed outBed = outBedDao.findByPatientAndDeviceSnAndStatus(patient,deviceDo.getDeviceSn(),0);
                        if (null!=outBed){
                            String outBedTime = "";
                            Date date = new Date();
                            long millisecondsDiff = date.getTime() - outBed.getCreateTime().getTime();
                            long minutesDiff = millisecondsDiff / TimeUnit.MINUTES.toMillis(1L);
                            long hoursDiff = millisecondsDiff / TimeUnit.HOURS.toMillis(1L);
                            long minuteFieldDiff = minutesDiff - TimeUnit.HOURS.toMinutes(hoursDiff);
                            if (hoursDiff > 0L) {
                                outBedTime += String.format("%d小时", hoursDiff);
                            }
                            result.put("sleepInfo",sleepInfo);
                            if (minuteFieldDiff>0){
                                outBedTime +=String.format("%d分钟", minuteFieldDiff);
                            }
                            sleepInfo.put("outBedTime",outBedTime);
                        }else {
                            sleepInfo.put("outBedTime","无");
                        }
                    }else {
                        result.put("sleepStatus",false);
                        result.put("sleepInfo","获取睡眠带数据失败");
                        result.put("sleepInfo",sleepInfo);
                    }
                }else {
                    result.put("sleepStatus",false);
                    result.put("sleepInfo","获取睡眠带数据失败");
                }
                //监控
                devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"12");
                if (devicePatientDeviceDos.size()==0){}
                else{
                    try {
                        DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
                        JSONObject monitorUrl = ysDeviceServicel.getDeviceLiveAddress(patient,deviceDo.getDeviceSn(),1,null);
                        result.put("monitorInfoStatus",monitorUrl.getIntValue(ResponseContant.resultFlag));
                        result.put("patientAddress",deviceDo.getSosAddress());
                        if (monitorUrl.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
                            result.put("monitorInfo",monitorUrl.getString(ResponseContant.resultMsg));
                        }
                        else {
                            result.put("monitorInfo",monitorUrl.getJSONObject(ResponseContant.resultMsg));
                        }
                    }catch (Exception e){
                        e.printStackTrace();
            }
            //监控
            devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"12");
            if (devicePatientDeviceDos.size()==0){}
            else{
                try {
                    DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
                    JSONObject monitorUrl = ysDeviceServicel.getDeviceLiveAddress(patient,deviceDo.getDeviceSn(),1,null);
                    result.put("monitorInfoStatus",monitorUrl.getIntValue(ResponseContant.resultFlag));
                    result.put("patientAddress",deviceDo.getSosAddress());
                    if (monitorUrl.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
                        result.put("monitorInfo",monitorUrl.getString(ResponseContant.resultMsg));
                    }
                    else {
                        result.put("monitorInfo",monitorUrl.getJSONObject(ResponseContant.resultMsg));
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }