| 
					
				 | 
			
			
				@ -4,6 +4,7 @@ package com.yihu.jw.care.service.device; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSON; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.serializer.SerializerFeature; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.config.AqgConfig; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.device.BaseSleepPlanDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.device.DeviceDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.device.DeviceDetailDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.device.PatientDeviceDao; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -15,6 +16,7 @@ import com.yihu.jw.care.util.MyJdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.doctor.dao.BaseDoctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.doctor.BaseDoctorDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.patient.BasePatientDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.BaseSleepPlan; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.Device; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.DeviceDetail; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.DevicePatientDevice; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -87,6 +89,8 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private HttpClientUtil httpClientUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private YsDeviceService ysDeviceService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseSleepPlanDao sleepPlanDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    WeiXinAccessTokenUtils tokenUtils; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -179,13 +183,14 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 保存患者设备 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public boolean saveDevice(DevicePatientDevice devicePatientDevice) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public boolean saveDevice(DevicePatientDevice devicePatientDevice, String safe_area, Integer fenceNO, String name, BaseSleepPlan sleepPlan) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //判断sn码是否被使用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sn = devicePatientDevice.getDeviceSn(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String type = devicePatientDevice.getCategoryCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Long deviceId = devicePatientDevice.getDeviceId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String userType = devicePatientDevice.getUserType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sosAddress = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String url =""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (userType == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            userType = "-1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            devicePatientDevice.setUserType("-1"); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -220,6 +225,12 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (needVerify) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            DevicePatientDevice device = patientDeviceDao.findByDeviceSnAndUserType(sn, userType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (device != null && !device.getId().equals(devicePatientDevice.getId()) && device.getDel() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //V1.0.0    监控器、报警器、燃气传感器 烟雾传感器支持一个设备绑定多个居民 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //监控器 12   报警器 7  14  15 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if ("12".equals(type) || "14".equals(type) || "15".equals(type) || "7".equals(type) ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    System.out.println("此类设备支持多绑定"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                throw new Exception("sn码" + sn + "已被使用!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -229,7 +240,46 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BasePatientDO patient = patientDao.findById(devicePatientDevice.getUser()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        devicePatientDevice.setUserIdcard(patient.getIdcard()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        MultiValueMap<String, String> param = new LinkedMultiValueMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(checkDeviceSn(sn)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //V1.0.0 添加手表的时候需要设置围栏 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if ("4".equals(type)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Device device = deviceDao.findOne(new Long (type)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (device!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if ("X1".equals(device.getModel())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        url = MessageFormat.format(AqgConfig.X1fence_area, sn,fenceNO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                param.add("name", name); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                param.add("freq", "1"); //"0,触发一天;1,每日触发 " 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                param.add("enable","1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                param.add("time_begin", "0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                param.add("time_end", "86400"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                param.add("safe_area", safe_area); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                HttpEntity<com.alibaba.fastjson.JSONObject> response = httpClientUtil.aqgCookieHttp(url, param, HttpMethod.POST, getCookie()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                com.alibaba.fastjson.JSONObject object = response.getBody(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (object.get("success").equals("true")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    System.out.println("围栏地址添加成功"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    System.out.println("添加失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String message = "围栏设置失败"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    throw new Exception(message); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if ("16".equals(type)){ //智能拐杖 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if ("13".equals(type)){ //睡眠带 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (StringUtils.isBlank(sleepPlan.getGetUpTime()) || StringUtils.isBlank(sleepPlan.getNightRestTime())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String message = "请完善睡眠时间规划"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    throw new Exception(message); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                sleepPlanDao.save(sleepPlan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            patientDeviceDao.save(devicePatientDevice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String message = "设备不存在"; 
			 |