| 
					
				 | 
			
			
				@ -0,0 +1,197 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.care.util; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.fasterxml.jackson.databind.node.ObjectNode; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.fastdfs.FastDFSUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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.DevicePatientDevice; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.DeviceSosLogDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.exception.business.file_upload.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.patient.dao.BasePatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.iot.common.UploadVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.common.LatitudeUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.http.HttpClientUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.NameValuePair; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.http.message.BasicNameValuePair; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.csource.common.MyException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.JdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Component; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.web.multipart.MultipartFile; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.InputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.security.NoSuchAlgorithmException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created by Bing on 2021/8/28. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Component 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class SecurityOrderUtil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${cloudCare.url}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String cloudCareUrl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PatientDeviceDao patientDeviceDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BasePatientDao patientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private JdbcTemplate jdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private HttpClientUtil httpClientUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private FastDFSUtil fastDFSHelper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${fastDFS.fastdfs_file_url}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String fastdfs_file_url; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private DeviceSosLogDao sosLogDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /***创建安防工单***/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject createSecurityOrder(String deviceSN, String sceneUrl, JSONObject result, Integer orderSource, String dictCode, String topicItem, String warnInfo){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        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"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String hospital = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String sql ="select DISTINCT pack.org_code,pack.org_name " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        " from base_service_package_sign_record sr,base_service_package_record pr,base_service_package_item item ,base_service_package pack " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "where pr.patient = '"+patientDO.getId()+"' and sr.id = pr.sign_id and pr.service_package_id = item.service_package_id and  item.`code`='"+topicItem+"'  and item.service_package_id = pack.id " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "  and pack.del=1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(sqlResult.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    hospital = sqlResult.get(0).get("org_code")+""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String serveDesc = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String sqlDesc = "SELECT dict_value from wlyy_hospital_sys_dict WHERE dict_code = '"+dictCode+"' 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")+""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                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",topicItem); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("deviceSn",deviceSN); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObject.put("warnInfo",warnInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (StringUtils.isNotBlank(sceneUrl)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("sceneImg",sceneUrl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject jsonObjectParam = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonObjectParam.put("order", jsonObject); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<NameValuePair> params = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                params.add(new BasicNameValuePair("jsonData", jsonObjectParam.toJSONString())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                params.add(new BasicNameValuePair("warnStr", serveDesc)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                params.add(new BasicNameValuePair("orderSource", orderSource+"")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String response = httpClientUtil.post(url, params,"UTF-8"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                System.out.println(response); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /***创建紧急工单****/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void createEmeOrder(DeviceSosLogDO logDO, String orderSource){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql =" select Distinct pack.org_code,pack.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" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "INNER JOIN base_service_package pack on pr.service_package_id = pack.id where item.code='emergencyAssistance' and sr.patient='"+logDO.getPatient()+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        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()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            jsonObject.put("deviceSn",logDO.getDeviceSn()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String url = cloudCareUrl+"cloudCare/noLogin/emergency_assistance/newOrder"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<NameValuePair> params = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.add(new BasicNameValuePair("jsonData", jsonObject.toJSONString())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.add(new BasicNameValuePair("patientId", logDO.getPatient())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.add(new BasicNameValuePair("orderSource", orderSource));//工单来源工单发起来源状态 1APP 2手环 3居家报警 4拐杖 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String response = httpClientUtil.post(url, params,"UTF-8"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            System.out.println(response); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sosLogDao.save(logDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public UploadVO uploadImg(MultipartFile file)throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String originalFilename = file.getOriginalFilename(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        InputStream inputStream = file.getInputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        UploadVO uploadVO = uploadImg2(inputStream,originalFilename,file.getSize(),fastdfs_file_url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return uploadVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public UploadVO uploadImg2(InputStream inputStream, String originalFileName,long fileSize,String fastdfs_file_url) throws NoSuchAlgorithmException, IOException, MyException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 得到文件的完整名称  xxx.txt 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if( null == inputStream){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new FileInputStreamEmptyException("图片文件流不可为空!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isBlank(originalFileName)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new FileNameEmptyException("图片文件名不可为空!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isBlank(fastdfs_file_url)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new FastfdsFileURLEmptyException("fastdfs url不可为空!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //得到文件类型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String fileType = originalFileName.substring(originalFileName.lastIndexOf(".") + 1).toLowerCase(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isBlank(fileType)||!"jpg,jpeg,png".contains(fileType)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new FileWrongFormatException("图片文件格式不正确,请上传jpg,jpeg,png等任一格式!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        long max = 5*1024*1024; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(fileSize > max){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new FileTooLargeSizeException("图片文件过大,请不要超过5M!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String fileName = originalFileName.substring(0, originalFileName.lastIndexOf(".")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //上传到fastdfs 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ObjectNode objectNode = fastDFSHelper.upload(inputStream, fileType, ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //解析返回的objectNode 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        UploadVO uploadVO = new UploadVO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        uploadVO.setFileName(fileName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        uploadVO.setFileType(fileType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        uploadVO.setFullUri(objectNode.get("fileId").toString().replaceAll("\"", "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fileId").toString().replaceAll("\"", "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return uploadVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |