liubing %!s(int64=4) %!d(string=hai) anos
pai
achega
0f91bba856

+ 1 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/doctor/CareDoctorService.java

@ -157,7 +157,7 @@ public class CareDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDa
                    "and dh.dept_code = dict.`code` and dh.org_code = dict.org_code and dh.del=1 and dh.org_code='"+org.getCode()+"' GROUP BY doc.id" ;
            List<Map<String,Object>> tmpList = jdbcTemplate.queryForList(sql);
            Map<String,List<Map<String,Object>>> docTmp = tmpList.stream().collect(Collectors.groupingBy(e->e.get("deptCode").toString()));
//          Map<String,String> deptList = tmpList.stream().collect(Collectors.toMap(s->s.get("deptCode").toString(),s->s.get("deptName").toString(),(oldVal, currVal) -> currVal));
          Map<String,String> deptList = tmpList.stream().collect(Collectors.toMap(s->s.get("deptCode").toString(),s->s.get("deptName").toString(),(oldVal, currVal) -> currVal));
            Map<String,Object> tmpMap = new HashMap<>();
            tmpMap.put("orgCode",org.getCode());
            tmpMap.put("orgName",org.getName());

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

@ -5,10 +5,13 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.dao.security.*;
import com.yihu.jw.care.service.device.PatientDeviceService;
import com.yihu.jw.care.service.sign.ServicePackageService;
import com.yihu.jw.care.util.CountDistance;
import com.yihu.jw.care.util.GpsUtil;
import com.yihu.jw.care.util.MessageUtil;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
@ -68,6 +71,10 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
    private BaseDoctorHospitalDao baseDoctorHospitalDao;
    @Autowired
    private PatientDeviceService patientDeviceService;
    @Autowired
    private GpsUtil gpsUtil;
    @Autowired
    private CountDistance countDistance;
    private Logger logger = LoggerFactory.getLogger(SecurityMonitoringOrderService.class);
@ -912,8 +919,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
    public JSONObject patientMonitoringInfo(String patient){
        JSONObject result = new JSONObject();
        result.put("location",null);
        result.put("enclosureStatus",null);
        result.put("enclosurePosition",null);
        result.put("fences",null);
        result.put("smoke",null);
        result.put("fire",null);
        List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"4");
@ -923,28 +929,51 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
        else {
            DevicePatientDevice device = devicePatientDeviceDos.get(0);
            try {
             JSONObject response= patientDeviceService.getDeviceLastLocation(device.getDeviceSn(),null);
             if (response.getBooleanValue("success")){
                JSONObject tmp = response.getJSONObject("obj");
                if (tmp.containsKey("locationdata")&&tmp.get("locationdata")!=null){
                    JSONObject locationTmp = tmp.getJSONObject("locationdata");
                    Double lon = locationTmp.getJSONObject("point").getJSONArray("coordinates").getDouble(0);
                    Double lat = locationTmp.getJSONObject("point").getJSONArray("coordinates").getDouble(1);
                    tmp = new JSONObject();
             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",locationTmp.getString("city"));
                    tmp.put("address",locationTmp.getString("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 (fencesEnables.size()>0){
                         result.put("fences",fencesEnables);
                     }
                 }
             }
            }catch (Exception e){
                e.printStackTrace();
                result.put("location",null);
            }
            result.put("enclosureStatus",null);
            result.put("enclosurePosition",null);
        }
        return result;
    }

+ 51 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/util/CountDistance.java

@ -1,7 +1,13 @@
package com.yihu.jw.care.util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
@Component
public class CountDistance {
    private static double EARTH_RADIUS = 6378.137;// 6378.137赤道半径6378137
@ -32,4 +38,49 @@ public class CountDistance {
        return s;
    }
    /**
     * 判断坐标是否在多边形区域内
     * @param pointLon
     * @param pointLat
     * @param rangePositions 多边形坐标 [{"lon":118.19302036660137,"lat":24.494515439791996},{"lon":118.19401849369201,"lat":24.49606682685256}]
     * @return
     */
    public boolean isInPolygon(double pointLon, double pointLat, JSONArray rangePositions) {
        // 将要判断的横纵坐标组成一个点
        double[] lon =  rangePositions.stream().mapToDouble(item->((JSONObject)item).getDouble("lon")).toArray();
        double[] lat =  rangePositions.stream().mapToDouble(item->((JSONObject)item).getDouble("lat")).toArray();;
        Point2D.Double point = new Point2D.Double(pointLon, pointLat);
        // 将区域各顶点的横纵坐标放到一个点集合里面
        List<Point2D.Double> pointList = new ArrayList<Point2D.Double>();
        double polygonPoint_x = 0.0, polygonPoint_y = 0.0;
        for (int i = 0; i < lon.length; i++) {
            polygonPoint_x = lon[i];
            polygonPoint_y = lat[i];
            Point2D.Double polygonPoint = new Point2D.Double(polygonPoint_x, polygonPoint_y);
            pointList.add(polygonPoint);
        }
        return check(point, pointList);
    }
    private static boolean check(Point2D.Double point, List<Point2D.Double> polygon) {
        java.awt.geom.GeneralPath peneralPath = new java.awt.geom.GeneralPath();
        Point2D.Double first = polygon.get(0);
        // 通过移动到指定坐标(以双精度指定),将一个点添加到路径中
        peneralPath.moveTo(first.x, first.y);
        polygon.remove(0);
        for (Point2D.Double d : polygon) {
            // 通过绘制一条从当前坐标到新指定坐标(以双精度指定)的直线,将一个点添加到路径中。
            peneralPath.lineTo(d.x, d.y);
        }
        // 将几何多边形封闭
        peneralPath.lineTo(first.x, first.y);
        peneralPath.closePath();
        // 测试指定的 Point2D 是否在 Shape 的边界内。
        return peneralPath.contains(point);
    }
}