| 
					
				 | 
			
			
				@ -1,30 +1,37 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.care.service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSON; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.config.AqgConfig; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.device.DevicePatientHealthIndexDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.device.DeviceSosLogDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.device.PatientDeviceDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.patient.BasePatientDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.DevicePatientHealthIndex; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.DevicePatientDevice; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.DeviceSosLogDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.util.AesEncryptUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.patient.dao.BasePatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.common.GpsUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.common.LatitudeUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.date.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.http.HttpClientUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.LoggerFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.data.redis.core.StringRedisTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.http.HttpEntity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.http.HttpHeaders; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.JdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.scheduling.annotation.Async; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.util.LinkedMultiValueMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.util.MultiValueMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import javax.servlet.http.HttpServletRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Date; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.concurrent.TimeUnit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -38,6 +45,8 @@ import java.util.concurrent.TimeUnit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static Logger logger = LoggerFactory.getLogger(DeviceService.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${cloudCare.url}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String cloudCareUrl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private HttpClientUtil httpClientUtil; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -49,6 +58,12 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private DevicePatientHealthIndexDao healthIndexDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BasePatientDao patientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private DeviceSosLogDao sosLogDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private JdbcTemplate jdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private GpsUtil gpsUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取爱牵挂管理员cookie 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -100,12 +115,67 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Async 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void aqgsos(String imei,String label_mac,String time_begin, HttpServletRequest request) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String address= request.getParameter("address"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Double lat= Double.parseDouble(request.getParameter("lat")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Double lon= Double.parseDouble(request.getParameter("lon")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByDeviceSn(imei); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            DevicePatientDevice deviceDO = devicePatientDeviceDos.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            BasePatientDO patientDO = patientDao.findById(deviceDO.getUser()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            DeviceSosLogDO logDO = new DeviceSosLogDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logDO.setPatient(patientDO.getIdcard()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logDO.setPatientName(patientDO.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logDO.setIdcard(patientDO.getIdcard()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logDO.setCategoryCode(deviceDO.getCategoryCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logDO.setDeviceSn(deviceDO.getDeviceSn()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logDO.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (deviceDO.getCategoryCode().equals("4")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject position = gpsUtil.gcj02_To_Bd09(lat,lon); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                logDO.setSosAddress(address); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                logDO.setSosLat(position.getDouble("lat")+""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                logDO.setSosLon(position.getDouble("lon")+""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (deviceDO.getCategoryCode().equals("7")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                logDO.setSosAddress(deviceDO.getSosAddress()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Map<String, String> json = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (StringUtils.isNotBlank(deviceDO.getSosAddress())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    json = LatitudeUtils.getGeocoderLatitude(deviceDO.getSosAddress().replace("G.", "").replace("(糖友网)", "").replace("(高友网)", "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (json != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    logDO.setSosLat(json.get("lat").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    logDO.setSosLon(json.get("lat").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //发送紧急救助 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String sql =" select Distinct item.org_code,item.org_name\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "from base_service_package_sign_record sr INNER JOIN base_service_package_record pr\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "on sr.id = pr.sign_id and sr.status=1 INNER JOIN base_service_package_item item on pr.service_package_id = item.service_package_id and item.del=1 \n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "where item.code='emergencyAssistance' and sr.patient='"+patientDO.getId()+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (sqlResult.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("serveAddress",logDO.getSosAddress()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("serveLon",logDO.getSosLon()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("serveLat",logDO.getSosLat()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("orgCode",sqlResult.get(0).get("org_code").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("orgName",sqlResult.get(0).get("org_name").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("patient",logDO.getPatient()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("patientName",logDO.getPatientName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String url = cloudCareUrl+"cloudCare/noLogin/emergency_assistance/newOrder"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Map map = new HashMap<String, String>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                map.put("patientId", logDO.getPatient()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                map.put("jsonData", jsonObject.toJSONString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String content = com.alibaba.fastjson.JSONObject.toJSONString(map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String postParams = AesEncryptUtils.agEncrypt(content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String response = httpClientUtil.postBodyRawForm(url,postParams); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject result = com.alibaba.fastjson.JSONObject.parseObject(response); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject jsonObjectData =JSONObject.parseObject(AesEncryptUtils.agDecrypt(result.getString("data"))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                logDO.setSosSendStatus(jsonObjectData.getInteger("status").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                logDO.setSosSendMessage(jsonObjectData.getString("message")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sosLogDao.save(logDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }catch(Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 |