| 
					
				 | 
			
			
				@ -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()); 
			 |