|  | @ -15,6 +15,9 @@ import com.yihu.wlyy.repository.patient.PatientDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.patient.PatientDeviceDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.patient.PatientDeviceLogDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.BaseService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.app.device.DeviceDetailService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.app.device.PatientDeviceLogService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.app.device.PatientDeviceService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.common.account.PatientService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.third.kit.JyKitService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.DateUtil;
 | 
	
	
		
			
				|  | @ -61,6 +64,12 @@ public class KitService extends BaseService {
 | 
	
		
			
				|  |  |     private JdbcTemplate jdbcTemplate;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PatientDeviceLogDao patientDeviceLogDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PatientDeviceService patientDeviceService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PatientDeviceLogService patientDeviceLogService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private DeviceDetailService deviceDetailService;
 | 
	
		
			
				|  |  |     private String format = "yyyy-MM-dd HH:mm";
 | 
	
		
			
				|  |  |     private String format2 = "HH:mm" ;
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -75,6 +84,7 @@ public class KitService extends BaseService {
 | 
	
		
			
				|  |  |         Patient patient = patientService.findByCode(patientCode);
 | 
	
		
			
				|  |  |         JSONObject dataJSONStr = jyKitService.kitBinding(deviceSn,patient.getMobile(),type);
 | 
	
		
			
				|  |  |         PatientDevice patientDevice = null;
 | 
	
		
			
				|  |  |         String typeTemp = type;
 | 
	
		
			
				|  |  |         if("1".equals(type)){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //绑定成功,设备添加到device库
 | 
	
	
		
			
				|  | @ -109,35 +119,45 @@ public class KitService extends BaseService {
 | 
	
		
			
				|  |  |             patientDevice.setUserType("-1");
 | 
	
		
			
				|  |  |             patientDevice.setUserIdcard(patient.getIdcard());
 | 
	
		
			
				|  |  |             patientDevice.setCzrq(new Date());
 | 
	
		
			
				|  |  |             if("1".equals(type)){
 | 
	
		
			
				|  |  |                 type="0";
 | 
	
		
			
				|  |  |             }else if("2".equals(type)){
 | 
	
		
			
				|  |  |                 type="1";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             patientDevice.setDel(Integer.valueOf(type));
 | 
	
		
			
				|  |  |             patientDeviceDao.save(patientDevice);
 | 
	
		
			
				|  |  |             //由于PatientDevice绑定关系是物理删除,所以添加PatientDeviceLog绑定记录
 | 
	
		
			
				|  |  |             PatientDeviceLog patientDeviceLog = new PatientDeviceLog();
 | 
	
		
			
				|  |  |             patientDeviceLog.setDeviceId(7L);//dm_device设备类型表的id
 | 
	
		
			
				|  |  |             patientDeviceLog.setPatient(patientDevice.getUser());
 | 
	
		
			
				|  |  |             patientDeviceLog.setCategoryCode(patientDevice.getCategoryCode());
 | 
	
		
			
				|  |  |             patientDeviceLog.setDeviceName(patientDevice.getDeviceName());
 | 
	
		
			
				|  |  |             patientDeviceLog.setDeviceSn(patientDevice.getDeviceSn());
 | 
	
		
			
				|  |  |             patientDeviceLog.setRole(2);
 | 
	
		
			
				|  |  |             patientDeviceLog.setOperateCode(Integer.valueOf(typeTemp));
 | 
	
		
			
				|  |  |             patientDeviceLog.setAgreementPhoto(patientDevice.getAgreementPhoto());
 | 
	
		
			
				|  |  |             patientDeviceLog.setCreateTime(new Date());
 | 
	
		
			
				|  |  |             patientDeviceLog.setIsDel(1);
 | 
	
		
			
				|  |  |             patientDeviceLogDao.save(patientDeviceLog);
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             if("1".equals(typeTemp)){
 | 
	
		
			
				|  |  |                 typeTemp="0";
 | 
	
		
			
				|  |  |             }else if("2".equals(typeTemp)){
 | 
	
		
			
				|  |  |                 typeTemp="1";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             List<PatientDevice> list = patientDeviceDao.findByDeviceSn(deviceSn);
 | 
	
		
			
				|  |  |             if(list.size()>0){
 | 
	
		
			
				|  |  |                 patientDevice = list.get(0);
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 throw new Exception(" 数据库中没有该设备!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             patientDeviceService.deleteDevices(deviceSn,typeTemp,null);
 | 
	
		
			
				|  |  |             //全部解绑后去判断就更新设备表中是否绑定字段
 | 
	
		
			
				|  |  |             patientDeviceLogService.savePatientDeviceLog(patientDevice,deviceSn,2,2);
 | 
	
		
			
				|  |  |             deviceDetailService.unBindUpdateIsBinding(deviceSn);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String typeTemp = type;
 | 
	
		
			
				|  |  |         if("1".equals(type)){
 | 
	
		
			
				|  |  |             type="0";
 | 
	
		
			
				|  |  |         }else if("2".equals(type)){
 | 
	
		
			
				|  |  |             type="1";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         patientDevice.setDel(Integer.valueOf(type));
 | 
	
		
			
				|  |  |         patientDeviceDao.save(patientDevice);
 | 
	
		
			
				|  |  |         //由于PatientDevice绑定关系是物理删除,所以添加PatientDeviceLog绑定记录
 | 
	
		
			
				|  |  |         PatientDeviceLog patientDeviceLog = new PatientDeviceLog();
 | 
	
		
			
				|  |  |         patientDeviceLog.setDeviceId(7L);//dm_device设备类型表的id
 | 
	
		
			
				|  |  |         patientDeviceLog.setPatient(patientDevice.getUser());
 | 
	
		
			
				|  |  |         patientDeviceLog.setCategoryCode(patientDevice.getCategoryCode());
 | 
	
		
			
				|  |  |         patientDeviceLog.setDeviceName(patientDevice.getDeviceName());
 | 
	
		
			
				|  |  |         patientDeviceLog.setDeviceSn(patientDevice.getDeviceSn());
 | 
	
		
			
				|  |  |         patientDeviceLog.setRole(2);
 | 
	
		
			
				|  |  |         patientDeviceLog.setOperateCode(Integer.valueOf(typeTemp));
 | 
	
		
			
				|  |  |         patientDeviceLog.setAgreementPhoto(patientDevice.getAgreementPhoto());
 | 
	
		
			
				|  |  |         patientDeviceLog.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         patientDeviceLog.setIsDel(1);
 | 
	
		
			
				|  |  |         patientDeviceLogDao.save(patientDeviceLog);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 |