Browse Source

代码修改 经纬度点到多边形距离计算

liubing 3 years ago
parent
commit
bb1adbb24c

+ 19 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/device/PatientDeviceService.java

@ -14,6 +14,7 @@ import com.yihu.jw.care.service.wechat.WeiXinAccessTokenUtils;
import com.yihu.jw.care.util.ConcealUtil;
import com.yihu.jw.care.util.CountDistance;
import com.yihu.jw.care.util.MyJdbcTemplate;
import com.yihu.jw.care.util.Point;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
@ -101,6 +102,8 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
    WeiXinAccessTokenUtils tokenUtils;
    @Autowired
    private BaseEmergencyWarnLogDao logDao;
    @Autowired
    private PatientSafeAreaDao patientSafeAreaDao;
    //健康问题 高血压
    private static final String gxy = "HP0093";
@ -1420,7 +1423,22 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
                    if ("疑似离开安全区域".equals(orderDO.getServeDesc())){
                        //超出距离
                        info.put("info1","超出距离: 1m");//todo
                        List<PatientSafeAreaDO> patientSafeAreaDOs = patientSafeAreaDao.findByPatient(orderDO.getPatient());
                        if (patientSafeAreaDOs.size()>0){
                            PatientSafeAreaDO patientSafeAreaDO = patientSafeAreaDOs.get(0);
                            List<Point> pointList = new ArrayList<Point>(){};
                            String pointStr = patientSafeAreaDO.getSafeAreaGz();
                            String[] points = pointStr.split(";");
                            for (String tmp:points){
                                String[] lonLat = tmp.split(",");
                                pointList.add(new Point(Double.parseDouble(lonLat[1]) , Double.parseDouble(lonLat[0])));
                            }
                            Point p = new Point(Double.parseDouble(orderDO.getServeLat()) , Double.parseDouble(orderDO.getServeLon()));
                            String dist = countDistance.getPointToEdgeDistance(p,pointList,2);
                            if (org.apache.commons.lang.StringUtils.isNotBlank(dist)){
                                info.put("info1","超出距离: "+dist+"m");
                            }
                        }
                    }
                    if ("超时未起床".equals(orderDO.getServeDesc())){
                        List<BaseSleepPlan> sleepPlan = sleepPlanDao.findByPatient(orderDO.getPatient());

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

@ -27,6 +27,7 @@ import com.yihu.jw.entity.base.im.ConsultDo;
import com.yihu.jw.entity.base.im.ConsultTeamDo;
import com.yihu.jw.entity.base.org.BaseOrgDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.assistance.EmergencyAssistanceDO;
import com.yihu.jw.entity.care.contacts.PatientSosContactsDO;
import com.yihu.jw.entity.care.device.*;
import com.yihu.jw.entity.care.securitymonitoring.*;
@ -1396,6 +1397,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
        result.put("fall",null);
        result.put("sleep",null);
        result.put("deviceSn",null);
        result.put("emeAssistance",false);
        result.put("monitorInfo",null);
        String sql = " select dict.code,count(ord.id) total from base_system_dict_entry dict LEFT JOIN base_security_monitoring_order ord " +
                " on dict.code = ord.topic_item COLLATE utf8_unicode_ci and ord.status="+SecurityMonitoringOrderDO.Status.apply.getType()+" where dict.dict_code='service_item' " +
@ -1437,6 +1439,11 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
                    break;
            }
        }
        sql = " select count(id) from base_emergency_assistance_order  where patient='"+patient+"' and status="+ EmergencyAssistanceDO.Status.apply.getType();
        Integer counnt = jdbcTemplate.queryForObject(sql,Integer.class);
        if (counnt>0){
            result.put("emeAssistance",true);
        }
        result = patientSignTopicInfo(result,patient,topicItem,null);
        return result;
    }

+ 26 - 2
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/third/PatientInfoPlatFormService.java

@ -3,6 +3,7 @@ package com.yihu.jw.care.service.third;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.care.dao.device.BaseSleepPlanDao;
import com.yihu.jw.care.dao.device.PatientSafeAreaDao;
import com.yihu.jw.care.dao.label.BaseCapacityLabelDao;
import com.yihu.jw.care.dao.label.WlyyPatientLabelDao;
import com.yihu.jw.care.dao.security.BaseEmergencyWarnLogDao;
@ -15,8 +16,11 @@ import com.yihu.jw.care.service.lifeCare.LifeCareOrderService;
import com.yihu.jw.care.service.security.SecurityMonitoringOrderService;
import com.yihu.jw.care.service.sign.CapacityAssessmentRecordService;
import com.yihu.jw.care.service.sign.ServicePackageService;
import com.yihu.jw.care.util.CountDistance;
import com.yihu.jw.care.util.Point;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.device.BaseSleepPlan;
import com.yihu.jw.entity.care.device.PatientSafeAreaDO;
import com.yihu.jw.entity.care.label.BaseCapacityLabelDO;
import com.yihu.jw.entity.care.label.WlyyPatientLabelDO;
import com.yihu.jw.entity.care.securitymonitoring.BaseEmergencyWarnLogDO;
@ -74,6 +78,10 @@ public class PatientInfoPlatFormService {
    private SecurityMonitoringOrderDao securityMonitoringOrderDao;
    @Autowired
    private BaseSleepPlanDao sleepPlanDao;
    @Autowired
    private PatientSafeAreaDao patientSafeAreaDao;
    @Autowired
    private CountDistance countDistance;
    /**
@ -296,8 +304,24 @@ public class PatientInfoPlatFormService {
                SecurityMonitoringOrderDO orderDO = securityMonitoringOrderDao.findOne(orderId);
                if ("疑似离开安全区域".equals(orderDO.getServeDesc())){
                    //超出距离
                    info.put("info1","超出距离: 1m");//todo
                    //超出距离 获取居民
                    List<PatientSafeAreaDO> patientSafeAreaDOs = patientSafeAreaDao.findByPatient(orderDO.getPatient());
                    if (patientSafeAreaDOs.size()>0){
                        PatientSafeAreaDO patientSafeAreaDO = patientSafeAreaDOs.get(0);
                        List<Point> pointList = new ArrayList<Point>(){};
                        String pointStr = patientSafeAreaDO.getSafeAreaGz();
                        String[] points = pointStr.split(";");
                        for (String tmp:points){
                            String[] lonLat = tmp.split(",");
                            pointList.add(new Point(Double.parseDouble(lonLat[1]) , Double.parseDouble(lonLat[0])));
                        }
                        Point p = new Point(Double.parseDouble(orderDO.getServeLat()) , Double.parseDouble(orderDO.getServeLon()));
                        String dist = countDistance.getPointToEdgeDistance(p,pointList,2);
                        if (StringUtils.isNotBlank(dist)){
                            info.put("info1","超出距离: "+dist+"m");
                        }
                    }
                }
                if ("超时未起床".equals(orderDO.getServeDesc())){
                    List<BaseSleepPlan> sleepPlan = sleepPlanDao.findByPatient(orderDO.getPatient());

+ 35 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/util/CountDistance.java

@ -2,6 +2,7 @@ package com.yihu.jw.care.util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.util.date.DateUtil;
import org.springframework.stereotype.Component;
import java.awt.geom.Point2D;
@ -24,7 +25,7 @@ public class CountDistance {
     * @param lngtwo
     * @return
     */
    public  double getDistance(double latone, double lngone, double lattwo, double lngtwo) {
    public double getDistance(double latone, double lngone, double lattwo, double lngtwo) {
        double radlatone = rad(latone);
        double radlattwo = rad(lattwo);
        double a = radlatone - radlattwo;
@ -38,6 +39,39 @@ public class CountDistance {
        return s;
    }
    /**
     * 获取坐标点到多边形边缘最小距离  单位:m
     * 多边形按坐标顺序 切首尾相连 A->B->C->A
     * @param point
     * @param points
     * @param pointIndex 返回小数点位数
     * @return
     */
    public  String getPointToEdgeDistance(Point point, List<Point> points,Integer pointIndex) {
        if (points.size()==0){
            return null;
        }
        double dist = Double.MAX_VALUE;
        for (int i=0,j=1;i<points.size()-1&&j<points.size();){
            Point point1 = points.get(i);
            Point point2 = points.get(j);
            double dis = getDistance(point.getX(),point.getY(), point1.getX(), point1.getY());
            double dis2 = getDistance(point.getX(),point.getY(), point2.getX(), point2.getY());
            //如果dis = dis2 该点与边垂直 判断到边的距离
            if (dis==dis2){
                Point pointCenter = new Point((point1.getX()+point2.getX())/2.0,(point1.getY()+point2.getY())/2.0);
                dis2 = getDistance(point.getX(),point.getY(), pointCenter.getX(), pointCenter.getY());
            }
            double min = dis<dis2?dis:dis2;
            if (min<dist){
                dist = min;
            }
            i++;j++;
        }
        dist = dist*1000;
        return String.format("%."+pointIndex+"f",dist);
    }
    /**

+ 55 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/util/Point.java

@ -0,0 +1,55 @@
package com.yihu.jw.care.util;
public class Point {
    /**
     * x轴坐标
     */
   public double x;
    /**
     * y轴坐标
     */
    public double y;
    public Point setPoint(Point point){
        this.x = point.getX();
        this.y = point.getY();
        return this;
    }
    public Point() {
    }
    public Point(Float[] point){
        this.x = point[0];
        this.y = point[1];
    }
    public Point(Double[] point) {
        this.x = point[0];
        this.y = point[1];
    }
    public Point(double x, double y) {
        this.x = x;
        this.y = y;
    }
    public double getX() {
        return x;
    }
    public void setX(double x) {
        this.x = x;
    }
    public double getY() {
        return y;
    }
    public void setY(double y) {
        this.y = y;
    }
}