Browse Source

紧急救助 实际路线距离

liubing 4 years ago
parent
commit
d491be6c4d

+ 35 - 0
common/common-util/src/main/java/com/yihu/jw/util/http/HttpClientUtil.java

@ -1,5 +1,6 @@
package com.yihu.jw.util.http;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
@ -111,6 +112,40 @@ public class HttpClientUtil {
        return null;
    }
    public  String get(String url,List<NameValuePair> params, String chatSet) {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        try {
            // 创建httpget.
            String entityString = EntityUtils.toString(new UrlEncodedFormEntity(params, Consts.UTF_8));
            HttpGet httpget = new HttpGet(url+"?"+entityString);
            // 执行get请求.
            CloseableHttpResponse response = httpclient.execute(httpget);
            try {
                // 获取响应实体
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    return EntityUtils.toString(entity, chatSet);
                }
            } finally {
                response.close();
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭连接,释放资源
            try {
                httpclient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
    /**
     * http调用方法,(健康之路开放平台)
     *

+ 68 - 29
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/assistance/EmergencyAssistanceService.java

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.netflix.ribbon.proxy.annotation.Http;
import com.yihu.jw.care.dao.assistance.EmergencyAssistanceDao;
import com.yihu.jw.care.dao.sign.ServicePackageSignRecordDao;
import com.yihu.jw.care.dao.team.BaseTeamMemberDao;
@ -19,13 +20,19 @@ import com.yihu.jw.im.util.ImUtil;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.*;
@ -54,6 +61,12 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
    private ImUtil imUtill;
    @Autowired
    private ConsultTeamDao consultTeamDao;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Value("${baiduApi.AK}")
    private String baiduAk;
    @Value("${baiduApi.url}")
    private String baiduUrl;
    /**
     * 新建居民紧急救助
@ -110,21 +123,21 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
            return result;
        }
        //获取距离患者最近的一个医生(默认直线距离最近的医生)
        double distance = 0.0;
        for (BaseDoctorDO doctorDO:doctorDOS){
            if (StringUtils.isBlank(doctorDO.getDoctorLat())||StringUtils.isBlank(doctorDO.getDoctorLon())){
                continue;
            }
            double distanceTmp = countDistance.getDistance(Double.parseDouble(assistanceDO.getServeLat()),Double.parseDouble(assistanceDO.getServeLon()),Double.parseDouble(doctorDO.getDoctorLat()),Double.parseDouble(doctorDO.getDoctorLon()));
            if (distanceTmp>distance){
                distance = distanceTmp;
                assistanceDO.setDoctor(doctorDO.getId());
                assistanceDO.setDoctorName(doctorDO.getName());
                assistanceDO.setDoctorAddress(doctorDO.getDoctorLocateAddress());
                assistanceDO.setDoctorLon(doctorDO.getDoctorLon());
                assistanceDO.setDoctorLat(doctorDO.getDoctorLat());
            }
        }
//        double distance = 0.0;
//        for (BaseDoctorDO doctorDO:doctorDOS){
//            if (StringUtils.isBlank(doctorDO.getDoctorLat())||StringUtils.isBlank(doctorDO.getDoctorLon())){
//                continue;
//            }
//            double distanceTmp = countDistance.getDistance(Double.parseDouble(assistanceDO.getServeLat()),Double.parseDouble(assistanceDO.getServeLon()),Double.parseDouble(doctorDO.getDoctorLat()),Double.parseDouble(doctorDO.getDoctorLon()));
//            if (distanceTmp>distance){
//                distance = distanceTmp;
//                assistanceDO.setDoctor(doctorDO.getId());
//                assistanceDO.setDoctorName(doctorDO.getName());
//                assistanceDO.setDoctorAddress(doctorDO.getDoctorLocateAddress());
//                assistanceDO.setDoctorLon(doctorDO.getDoctorLon());
//                assistanceDO.setDoctorLat(doctorDO.getDoctorLat());
//            }
//        }
        assistanceDO = emergencyAssistanceDao.save(assistanceDO);
        //创建im会话  紧急救助咨询的sessionid  为居民code+(wlyy_consult_team表consult)+20
        JSONObject IMObj = consultTeamService.addServiceConsult(assistanceDO.getId(),patient,null);
@ -167,22 +180,48 @@ public class EmergencyAssistanceService extends BaseJpaService<EmergencyAssistan
        double distance = 0.0;
        JSONArray otherDoctorDistance = new JSONArray();
        JSONObject otherDoctorDistanceObj = new JSONObject();
        for (BaseDoctorDO doctorDO:doctorDOS){
            if (StringUtils.isBlank(doctorDO.getDoctorLat())||StringUtils.isBlank(doctorDO.getDoctorLon())){
                continue;
        if (assistanceDO.getStatus()==1){
            StringBuilder origins = new StringBuilder("");
            for (BaseDoctorDO doctorDO:doctorDOS) {
                if (StringUtils.isBlank(doctorDO.getDoctorLat()) || StringUtils.isBlank(doctorDO.getDoctorLon())) {
                    continue;
                }
                double distanceTmp = countDistance.getDistance(Double.parseDouble(assistanceDO.getServeLat()),Double.parseDouble(assistanceDO.getServeLon()),Double.parseDouble(doctorDO.getDoctorLat()),Double.parseDouble(doctorDO.getDoctorLon()));
                otherDoctorDistanceObj = new JSONObject();
                otherDoctorDistanceObj.put("doctor",doctorDO.getId());
                otherDoctorDistanceObj.put("doctorName",doctorDO.getName());
                otherDoctorDistanceObj.put("doctorAddress",doctorDO.getDoctorLocateAddress());
                otherDoctorDistanceObj.put("doctorLon",doctorDO.getDoctorLon());
                otherDoctorDistanceObj.put("doctorLat",doctorDO.getDoctorLat());
                otherDoctorDistanceObj.put("distance",distanceTmp);//两点距离
                otherDoctorDistance.add(otherDoctorDistanceObj);
                origins.append(doctorDO.getDoctorLat()+","+doctorDO.getDoctorLon()+"|");
            }
            double distanceTmp = countDistance.getDistance(Double.parseDouble(assistanceDO.getServeLat()),Double.parseDouble(assistanceDO.getServeLon()),Double.parseDouble(doctorDO.getDoctorLat()),Double.parseDouble(doctorDO.getDoctorLon()));
            if (doctorDO.getId().equals(assistanceDO.getDoctor())){//服务医生
                assistanceDO.setDistance(distance);
            if (StringUtils.isNotBlank(origins.toString())){
                origins.deleteCharAt(origins.length()-1);
            }
            String destinations = assistanceDO.getServeLat()+","+assistanceDO.getServeLon();
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("origins", origins.toString()));
            params.add(new BasicNameValuePair("destinations", destinations));
            params.add(new BasicNameValuePair("output", "json"));
            params.add(new BasicNameValuePair("ak", baiduAk));
            String url = baiduUrl+"routematrix/v2/driving";
            String response = httpClientUtil.get(url,params,"UTF-8");
            JSONObject responseObj = JSONObject.parseObject(response);
            if (responseObj.getInteger("status")==0){
                JSONArray resultArr = responseObj.getJSONArray("result");
                int length = resultArr.size()>otherDoctorDistance.size()?resultArr.size():otherDoctorDistance.size();
                for (int i=0;i<length;i++){
                    JSONObject disTmp = resultArr.getJSONObject(i);
                    JSONObject docTmp = otherDoctorDistance.getJSONObject(i);
                    docTmp.put("time",disTmp.getJSONObject("duration").getString("text"));
                    docTmp.put("distance",disTmp.getJSONObject("distance").getInteger("value")/1000.0);//实际路线距离
                    docTmp.put("distanceMeter",disTmp.getJSONObject("distance").getInteger("value"));
                }
                otherDoctorDistance.sort(Comparator.comparing(obj -> ((JSONObject) obj).getInteger("distance")));
            }
            otherDoctorDistanceObj = new JSONObject();
            otherDoctorDistanceObj.put("doctor",doctorDO.getId());
            otherDoctorDistanceObj.put("doctorName",doctorDO.getName());
            otherDoctorDistanceObj.put("doctorAddress",doctorDO.getDoctorLocateAddress());
            otherDoctorDistanceObj.put("doctorLon",doctorDO.getDoctorLon());
            otherDoctorDistanceObj.put("doctorLat",doctorDO.getDoctorLat());
            otherDoctorDistanceObj.put("distance",distanceTmp);
            otherDoctorDistance.add(otherDoctorDistanceObj);
        }
        assistanceDO.setOtherDoctorDistance(otherDoctorDistance.toJSONString());
        BasePatientDO patientDO = patientDao.findById(assistanceDO.getPatient());

+ 12 - 0
svr/svr-cloud-care/src/main/resources/application.yml

@ -167,6 +167,10 @@ express:
  sf_url: https://mrds-admin.sf-express.com:443
  sf_code: JKZL
  sf_check_word: QkeIfIvQdheqIv2cVSgAUnBU29lfNbVk
baiduApi:
  AK: 0vjnCSReegE7A47a941ohjv9a07ONiMC
  url: http://api.map.baidu.com/
---
spring:
  profiles: jwtest
@ -259,6 +263,10 @@ express:
  sf_url: http://mrds-admin-ci.sit.sf-express.com:45478
  sf_code: HD000001
  sf_check_word: AAAABBBBCCCCDDDD
baiduApi:
  AK: 0vjnCSReegE7A47a941ohjv9a07ONiMC
  url: http://api.map.baidu.com/
---
spring:
  profiles: jwprod
@ -353,3 +361,7 @@ express:
  sf_url: https://mrds-admin.sf-express.com:443
  sf_code: WH000102
  sf_check_word: TGUQASFNAZyjt9112
baiduApi:
  AK: 0vjnCSReegE7A47a941ohjv9a07ONiMC
  url: http://api.map.baidu.com/