| 
					
				 | 
			
			
				@ -1,9 +1,7 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.care.service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSON; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.fasterxml.jackson.databind.ObjectMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.fasterxml.jackson.databind.node.ObjectNode; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.fastdfs.FastDFSUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.config.YsConfig; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -17,16 +15,8 @@ import com.yihu.jw.restmodel.iot.common.UploadVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.common.LatitudeUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.http.HttpClientUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.utils.encode.Base64; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringEscapeUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.HttpEntity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.HttpResponse; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.client.methods.HttpPost; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.entity.ContentType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.entity.mime.MultipartEntityBuilder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.impl.client.CloseableHttpClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.impl.client.HttpClientBuilder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.util.EntityUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.csource.common.MyException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.LoggerFactory; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -44,7 +34,6 @@ import javax.servlet.http.HttpServletRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.net.URL; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.net.URLConnection; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.nio.charset.Charset; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.security.NoSuchAlgorithmException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.security.Security; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.HashMap; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -148,66 +137,85 @@ public class YsDeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (fallFlag){//发起安防工单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String lat = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String lon = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByDeviceSn(deviceSN); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (devicePatientDeviceDos.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    DevicePatientDevice deviceDO = devicePatientDeviceDos.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Map<String, String> json = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (org.apache.commons.lang.StringUtils.isNotBlank(deviceDO.getSosAddress())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        json = LatitudeUtils.getGeocoderLatitude(deviceDO.getSosAddress().replace("G.", "").replace("(糖友网)", "").replace("(高友网)", "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (json != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        lat = json.get("lat").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        lon = json.get("lng").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                result = createOrder(deviceSN,sceneUrl,result,4,"2"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //https://www.yuque.com/u1400669/kb/mlqrm2 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //https://www.yuque.com/u1400669/kb/div5py 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    BasePatientDO patientDO = patientDao.findById(deviceDO.getUser()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String  url = cloudCareUrl+"/cloudCare/noLogin/security/createOrder"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Map map = new HashMap<String, String>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    map = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String sql ="select DISTINCT item.org_code,item.org_name\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            " from base_service_package_sign_record sr,base_service_package_record pr,base_service_package_item item ,base_service_package pack\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "where pr.patient = '"+patientDO.getId()+"' and sr.id = pr.sign_id and pr.service_package_id = item.service_package_id \tand  item.`code`='preventFall'  and item.service_package_id = pack.id \n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "  and pack.del=1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("patient",patientDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("patientName",patientDO.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("patientPhone",patientDO.getMobile()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("serveDesc","疑似跌倒"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("hospital",sqlResult.get(0).get("org_code")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("serveAddress",deviceDO.getSosAddress()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("serveLat",lat); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("serveLon",lon); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("topicItem","preventFall"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("deviceSn",deviceSN); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (StringUtils.isNotBlank(sceneUrl)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        jsonObject.put("sceneImg",sceneUrl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    JSONObject jsonObjectParam = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObjectParam.put("order", jsonObject); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    map.put("jsonData", jsonObjectParam.toJSONString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    map.put("orderSource", 4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    map.put("warnStr", "疑似跌倒"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject createOrder(String deviceSN,String sceneUrl,JSONObject result,Integer orderSource,String dictCode){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String lat = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String lon = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByDeviceSn(deviceSN); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (devicePatientDeviceDos.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                DevicePatientDevice deviceDO = devicePatientDeviceDos.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Map<String, String> json = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (org.apache.commons.lang.StringUtils.isNotBlank(deviceDO.getSosAddress())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    json = LatitudeUtils.getGeocoderLatitude(deviceDO.getSosAddress().replace("G.", "").replace("(糖友网)", "").replace("(高友网)", "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (json != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    lat = json.get("lat").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    lon = json.get("lng").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                BasePatientDO patientDO = patientDao.findById(deviceDO.getUser()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String  url = cloudCareUrl+"/cloudCare/noLogin/security/createOrder"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Map map = new HashMap<String, String>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                map = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String sql ="select DISTINCT item.org_code,item.org_name\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        " from base_service_package_sign_record sr,base_service_package_record pr,base_service_package_item item ,base_service_package pack\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "where pr.patient = '"+patientDO.getId()+"' and sr.id = pr.sign_id and pr.service_package_id = item.service_package_id \tand  item.`code`='preventFall'  and item.service_package_id = pack.id \n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "  and pack.del=1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String serveDesc = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String sqlDesc = "SELECT dict_value from wlyy_hospital_sys_dict WHERE dict_code = '2' and dict_name = 'security_server_dict'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<Map<String,Object>> listTmp = jdbcTemplate.queryForList(sqlDesc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (listTmp!=null&&listTmp.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    serveDesc = listTmp.get(0).get("dict_value")+""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String content = com.alibaba.fastjson.JSONObject.toJSONString(map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String postParams = AesEncryptUtils.agEncrypt(content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String response = httpClientUtil.postBodyRawForm(url,postParams); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    result = com.alibaba.fastjson.JSONObject.parseObject(response); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    JSONObject jsonObjectData =JSONObject.parseObject(AesEncryptUtils.agDecrypt(result.getString("data"))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    System.out.println(jsonObjectData.toJSONString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("patient",patientDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("patientName",patientDO.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("patientPhone",patientDO.getMobile()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("serveDesc",serveDesc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("hospital",sqlResult.get(0).get("org_code")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("serveAddress",deviceDO.getSosAddress()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("serveLat",lat); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("serveLon",lon); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("topicItem","preventFall"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("deviceSn",deviceSN); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (StringUtils.isNotBlank(sceneUrl)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("sceneImg",sceneUrl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject jsonObjectParam = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObjectParam.put("order", jsonObject); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                map.put("jsonData", jsonObjectParam.toJSONString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                map.put("orderSource", orderSource); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                map.put("warnStr", serveDesc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String content = com.alibaba.fastjson.JSONObject.toJSONString(map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String postParams = AesEncryptUtils.agEncrypt(content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String response = httpClientUtil.postBodyRawForm(url,postParams); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                result = com.alibaba.fastjson.JSONObject.parseObject(response); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject jsonObjectData =JSONObject.parseObject(AesEncryptUtils.agDecrypt(result.getString("data"))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                System.out.println(jsonObjectData.toJSONString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //https://www.yuque.com/u1400669/kb/mlqrm2 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //https://www.yuque.com/u1400669/kb/div5py 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 消息解密 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param sSrc 
			 |